Skip to content

Commit

Permalink
Merge pull request #535 from akicho8/tagged_with_options_delete_fix
Browse files Browse the repository at this point in the history
[Bug fix] Fix options broken
  • Loading branch information
seuros committed May 16, 2014
2 parents b6b390b + b7809f8 commit ecf219b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/acts_as_taggable_on/taggable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down

0 comments on commit ecf219b

Please sign in to comment.