File tree Expand file tree Collapse file tree 7 files changed +16
-16
lines changed
Expand file tree Collapse file tree 7 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ def slug
114114
115115 # Checks if the attachment is restricted, because it is attached on restricted pages only
116116 def restricted?
117- pages . any? && pages . not_restricted . blank?
117+ related_pages . any? && related_pages . not_restricted . blank?
118118 end
119119
120120 # File name
Original file line number Diff line number Diff line change @@ -236,7 +236,7 @@ def has_convertible_format?
236236 # even if it is also assigned on a restricted page.
237237 #
238238 def restricted?
239- pages . any? && pages . not_restricted . blank?
239+ related_pages . any? && related_pages . not_restricted . blank?
240240 end
241241
242242 def image_file_name
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ module RelatableResource
1515 foreign_key : "related_object_id" ,
1616 as : :related_object
1717
18- has_many :elements , through : :related_ingredients
19- has_many :pages , through : :elements
18+ has_many :related_elements , through : :related_ingredients , source : :element
19+ has_many :related_pages , through : :related_elements , source : :page
2020 end
2121
2222 # Returns true if object is not assigned to any ingredient.
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module Alchemy
4- # If the model has a +elements + association,
4+ # If the model has a +related_elements + association,
55 # it updates all their timestamps after save.
66 #
77 # Should only be used on bottom to top relations,
@@ -16,9 +16,9 @@ def self.included(base)
1616 private
1717
1818 def touch_elements
19- return unless respond_to? ( :elements )
19+ return unless respond_to? ( :related_elements )
2020
21- elements . touch_all
21+ related_elements . touch_all
2222 end
2323 end
2424end
Original file line number Diff line number Diff line change 11RSpec . shared_examples_for "a relatable resource" do |args |
22 it { is_expected . to have_many ( :related_ingredients ) }
3- it { is_expected . to have_many ( :elements ) . through ( :related_ingredients ) }
4- it { is_expected . to have_many ( :pages ) . through ( :elements ) }
3+ it { is_expected . to have_many ( :related_elements ) . through ( :related_ingredients ) }
4+ it { is_expected . to have_many ( :related_pages ) . through ( :related_elements ) }
55
66 describe ".deletable" do
77 subject { described_class . deletable }
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ module Alchemy
8282 end
8383
8484 it "touches elements" do
85- expect { attachment . update ( name : "image with spaces" ) } . to change { attachment . elements . reload . first . updated_at }
85+ expect { attachment . update ( name : "image with spaces" ) } . to change { attachment . related_elements . reload . first . updated_at }
8686 end
8787 end
8888 end
@@ -382,7 +382,7 @@ module Alchemy
382382 before do
383383 pages = double ( any? : true )
384384 expect ( pages ) . to receive ( :not_restricted ) . and_return ( [ ] )
385- expect ( attachment ) . to receive ( :pages ) . twice . and_return ( pages )
385+ expect ( attachment ) . to receive ( :related_pages ) . twice . and_return ( pages )
386386 end
387387
388388 it { is_expected . to be_truthy }
@@ -394,7 +394,7 @@ module Alchemy
394394 before do
395395 pages = double ( any? : true )
396396 expect ( pages ) . to receive ( :not_restricted ) . and_return ( [ page ] )
397- expect ( attachment ) . to receive ( :pages ) . twice . and_return ( pages )
397+ expect ( attachment ) . to receive ( :related_pages ) . twice . and_return ( pages )
398398 end
399399
400400 it { is_expected . to be_falsey }
Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ module Alchemy
330330 context "is assigned on pages" do
331331 context "that are all restricted" do
332332 before do
333- expect ( picture ) . to receive ( :pages ) . at_least ( :once ) do
333+ expect ( picture ) . to receive ( :related_pages ) . at_least ( :once ) do
334334 double (
335335 not_restricted : double ( blank? : true ) ,
336336 any? : true
@@ -343,7 +343,7 @@ module Alchemy
343343
344344 context "that are not all restricted" do
345345 before do
346- expect ( picture ) . to receive ( :pages ) . at_least ( :once ) do
346+ expect ( picture ) . to receive ( :related_pages ) . at_least ( :once ) do
347347 double (
348348 not_restricted : double ( blank? : false ) ,
349349 any? : true
@@ -357,7 +357,7 @@ module Alchemy
357357
358358 context "is not assigned on any page" do
359359 before do
360- expect ( picture ) . to receive ( :pages ) . and_return double ( any? : false )
360+ expect ( picture ) . to receive ( :related_pages ) . and_return double ( any? : false )
361361 end
362362
363363 it { is_expected . to be_falsey }
@@ -510,7 +510,7 @@ module Alchemy
510510 end
511511
512512 it "touches elements" do
513- expect { picture . save } . to change { picture . elements . reload . first . updated_at }
513+ expect { picture . save } . to change { picture . related_elements . reload . first . updated_at }
514514 end
515515 end
516516 end
You can’t perform that action at this time.
0 commit comments