Skip to content

Commit

Permalink
corrected the relation condition on context_taggings and added tests.…
Browse files Browse the repository at this point in the history
… tests fail given previous coditions.
  • Loading branch information
Nathan Hessler committed Jul 27, 2010
1 parent 3d707c2 commit 37c954c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Expand Up @@ -21,7 +21,7 @@ def initialize_acts_as_taggable_on_core

class_eval do
has_many context_taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging",
:conditions => ["#{ActsAsTaggableOn::Tagging.table_name}.tagger_id IS NULL AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_type]
:conditions => ["#{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.id AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", tags_type]
has_many context_tags, :through => context_taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag"
end

Expand Down Expand Up @@ -249,4 +249,4 @@ def save_tags
end
end
end
end
end
17 changes: 17 additions & 0 deletions spec/acts_as_taggable_on/taggable_spec.rb
Expand Up @@ -4,6 +4,7 @@
before(:each) do
clean_database!
@taggable = TaggableModel.new(:name => "Bob Jones")
@taggables = [@taggable, TaggableModel.new(:name => "John Doe")]
end

it "should have tag types" do
Expand Down Expand Up @@ -68,6 +69,22 @@
@taggable.should have(2).skills
end

it "should be able to select taggables by subset of tags using ActiveRelation methods" do
@taggables[0].tag_list = "bob"
@taggables[1].tag_list = "charlie"
@taggables[0].skill_list = "ruby"
@taggables[1].skill_list = "css"
@taggables.each{|taggable| taggable.save}

@found_taggables_by_tag = TaggableModel.joins(:tags).where(:tags => {:name => ["bob"]})
@found_taggables_by_skill = TaggableModel.joins(:skills).where(:tags => {:name => ["ruby"]})

@found_taggables_by_tag.should include @taggables[0]
@found_taggables_by_tag.should_not include @taggables[1]
@found_taggables_by_skill.should include @taggables[0]
@found_taggables_by_skill.should_not include @taggables[1]
end

it "should be able to find by tag" do
@taggable.skill_list = "ruby, rails, css"
@taggable.save
Expand Down

0 comments on commit 37c954c

Please sign in to comment.