diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb b/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb index be7336afd..72d359a67 100644 --- a/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +++ b/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb @@ -53,6 +53,7 @@ def tags_on(context, options = {}) # * :order - A piece of SQL to order by. Eg 'tags.count desc' or 'taggings.created_at desc' # * :on - Scope the find to only include a certain context def all_tags(options = {}) + options = options.dup options.assert_valid_keys :start_at, :end_at, :conditions, :order, :limit, :on ## Generate conditions: @@ -87,6 +88,7 @@ def all_tags(options = {}) # * :at_most - Exclude tags with a frequency greater than the given value # * :on - Scope the find to only include a certain context def all_tag_counts(options = {}) + options = options.dup options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit, :on, :id ## Generate conditions: diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb b/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb index 59b0c9780..dcf02a4a8 100644 --- a/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +++ b/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb @@ -83,6 +83,7 @@ def grouped_column_names_for(object) # User.tagged_with("awesome", "cool", :owned_by => foo ) # Users that are tagged with just awesome and cool by 'foo' def tagged_with(tags, options = {}) tag_list = ActsAsTaggableOn::TagList.from(tags) + options = options.dup empty_result = where('1 = 0') return empty_result if tag_list.empty? diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb b/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb index 153bd57bb..9346fd6f6 100644 --- a/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +++ b/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb @@ -41,7 +41,7 @@ def matching_contexts_for(search_context, result_context, klass, options = {}) end def related_tags_for(context, klass, options = {}) - tags_to_ignore = Array.wrap(options.delete(:ignore)).map(&:to_s) || [] + tags_to_ignore = Array.wrap(options[:ignore]).map(&:to_s) || [] tags_to_find = tags_on(context).map { |t| t.name }.reject { |t| tags_to_ignore.include? t } related_where(klass, ["#{exclude_self(klass, id)} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?)", tags_to_find]) end diff --git a/spec/acts_as_taggable_on/taggable_spec.rb b/spec/acts_as_taggable_on/taggable_spec.rb index 887a925d7..13f48c590 100644 --- a/spec/acts_as_taggable_on/taggable_spec.rb +++ b/spec/acts_as_taggable_on/taggable_spec.rb @@ -494,6 +494,12 @@ end end + it 'should options key not be deleted' do + options = {:exclude => true} + TaggableModel.tagged_with("foo", options) + expect(options).to eq({:exclude => true}) + end + context 'Duplicates' do context 'should not create duplicate taggings' do let(:bob) { TaggableModel.create(name: 'Bob') }