-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathproduct_spec.rb
More file actions
53 lines (42 loc) · 1.86 KB
/
Copy pathproduct_spec.rb
File metadata and controls
53 lines (42 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
require "rails_helper"
RSpec.describe Spree::Product, type: :model do
it { is_expected.to have_many(:alchemy_ingredients) }
describe "#url_path" do
let(:product) { create(:product) }
it "returns the product path" do
expect(product.url_path).to eq(Spree::Core::Engine.routes.url_helpers.product_path(product))
end
end
describe "cache invalidation" do
let(:page) { create(:alchemy_page) }
let(:page_version) { create(:alchemy_page_version, page: page) }
let(:element) { create(:alchemy_element, page_version: page_version) }
let(:product) { create(:product) }
context "if assigned to ingredient spree product" do
let!(:ingredient) { Alchemy::Ingredients::SpreeProduct.create!(element: element, role: "product", related_object: product) }
it "invalidates the cache on update" do
expect {
product.update!(name: "New name")
}.to enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeProduct", product.id)
end
it "invalidates the cache on touch" do
expect {
product.touch
}.to enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeProduct", product.id)
end
end
context "if assigned to taxon that is assigned to ingredient spree taxon" do
let(:taxon) { create(:taxon) }
let!(:product) { create(:product, taxons: [taxon]) }
let!(:ingredient) { Alchemy::Ingredients::SpreeTaxon.create!(element: element, role: "taxon", related_object: taxon) }
it "touches ingredient spree taxons elements" do
expect {
product.touch
}.to enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeTaxon", taxon.id).and(
enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeProduct", product.id)
)
end
end
end
end