Skip to content

Commit

Permalink
refactor: Refactor tagging support for modern Ruby versions
Browse files Browse the repository at this point in the history
Updated instance variable checks and refactored taggable class attribute setup for better compatibility with modern Ruby versions. Removed version-specific logic now that support for Ruby versions below 1.9 is unnecessary.
  • Loading branch information
seuros committed Aug 22, 2024
1 parent bdb86da commit a54cc54
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/acts-as-taggable-on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def base_class=(base_class)
ActiveSupport.on_load(:active_record) do
extend ActsAsTaggableOn::Taggable
include ActsAsTaggableOn::Tagger

end
ActiveSupport.on_load(:action_view) do
include ActsAsTaggableOn::TagsHelper
Expand Down
12 changes: 6 additions & 6 deletions lib/acts-as-taggable-on/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def taggable_on(preserve_tag_order, *tag_types)
self.tag_types = (self.tag_types + tag_types).uniq
self.preserve_tag_order = preserve_tag_order
else
class_attribute :tag_types
self.tag_types = tag_types
class_attribute :preserve_tag_order
self.preserve_tag_order = preserve_tag_order
class_attribute :tenant_column

class_eval do
class_attribute :tag_types
class_attribute :preserve_tag_order
class_attribute :tenant_column
self.tag_types = tag_types
self.preserve_tag_order = preserve_tag_order

has_many :taggings, as: :taggable, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
has_many :base_tags, through: :taggings, source: :tag, class_name: '::ActsAsTaggableOn::Tag'

Expand Down
15 changes: 5 additions & 10 deletions spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@

its(:language_list) { should == ['ruby', '.net']}
its(:cached_language_list) { should == 'ruby, .net' } # passes
its(:instance_variables) { should include((RUBY_VERSION < '1.9' ? '@language_list' : :@language_list)) }
its(:instance_variables) { should include(:@language_list) }
end

context 'status taggings cache after update' do
Expand All @@ -207,8 +207,8 @@
its(:status_list) { should == ['happy', 'married'] }
its(:cached_status_list) { should == 'happy, married' } # fails
its(:cached_status_list) { should_not == '' } # fails, is blank
its(:instance_variables) { should include((RUBY_VERSION < '1.9' ? '@status_list' : :@status_list)) }
its(:instance_variables) { should_not include((RUBY_VERSION < '1.9' ? '@statu_list' : :@statu_list)) } # fails, note: one "s"
its(:instance_variables) { should include(:@status_list) }
its(:instance_variables) { should_not include(:@statu_list) } # fails, note: one "s"

end

Expand All @@ -221,13 +221,8 @@
its(:glass_list) { should == ['rectangle', 'aviator'] }
its(:cached_glass_list) { should == 'rectangle, aviator' } # fails
its(:cached_glass_list) { should_not == '' } # fails, is blank
if RUBY_VERSION < '1.9'
its(:instance_variables) { should include('@glass_list') }
its(:instance_variables) { should_not include('@glas_list') } # fails, note: one "s"
else
its(:instance_variables) { should include(:@glass_list) }
its(:instance_variables) { should_not include(:@glas_list) } # fails, note: one "s"
end
its(:instance_variables) { should include(:@glass_list) }
its(:instance_variables) { should_not include(:@glas_list) } # fails, note: one "s"

end
end
Expand Down

0 comments on commit a54cc54

Please sign in to comment.