|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require "rails_helper" |
| 4 | +require "alchemy/test_support/relatable_resource_examples" |
4 | 5 |
|
5 | 6 | RSpec.describe Spree::Product, type: :model do |
6 | 7 | it { is_expected.to have_many(:alchemy_ingredients) } |
7 | 8 |
|
8 | | - describe "cache invalidation" do |
9 | | - let(:page) { create(:alchemy_page) } |
10 | | - let(:page_version) { create(:alchemy_page_version, page: page) } |
11 | | - let(:element) { create(:alchemy_element, page_version: page_version) } |
12 | | - let(:product) { create(:product) } |
13 | | - |
14 | | - context "if assigned to ingredient spree product" do |
15 | | - let!(:ingredient) { Alchemy::Ingredients::SpreeProduct.create!(element: element, role: "product", related_object: product) } |
16 | | - |
17 | | - it "invalidates the cache on update" do |
18 | | - expect { |
19 | | - product.update!(name: "New name") |
20 | | - }.to enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeProduct", product.id) |
21 | | - end |
22 | | - |
23 | | - it "invalidates the cache on touch" do |
24 | | - expect { |
25 | | - product.touch |
26 | | - }.to enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeProduct", product.id) |
27 | | - end |
28 | | - end |
29 | | - |
30 | | - context "if assigned to taxon that is assigned to ingredient spree taxon" do |
31 | | - let(:taxon) { create(:taxon) } |
32 | | - let!(:product) { create(:product, taxons: [taxon]) } |
33 | | - |
34 | | - let!(:ingredient) { Alchemy::Ingredients::SpreeTaxon.create!(element: element, role: "taxon", related_object: taxon) } |
35 | | - |
36 | | - it "touches ingredient spree taxons elements" do |
37 | | - expect { |
38 | | - product.touch |
39 | | - }.to enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeTaxon", taxon.id).and( |
40 | | - enqueue_job(Alchemy::Solidus::InvalidateElementsCacheJob).with("SpreeProduct", product.id) |
41 | | - ) |
42 | | - end |
43 | | - end |
44 | | - end |
| 9 | + it_behaves_like "a relatable resource", |
| 10 | + resource_factory_name: "product", |
| 11 | + ingredient_factory_name: "alchemy_ingredient_spree_product" |
45 | 12 | end |
0 commit comments