Permalink
Browse files

corrected the relation condition on context_taggings and added tests.…

… tests fail given previous coditions.
  • Loading branch information...
nhessler committed Jul 27, 2010
1 parent 3d707c2 commit 37c954cff46dffe300385f9ea3b4c0f00a75651e
Showing with 19 additions and 2 deletions.
  1. +2 −2 lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
  2. +17 −0 spec/acts_as_taggable_on/taggable_spec.rb
@@ -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
@@ -249,4 +249,4 @@ def save_tags
end
end
end
-end
+end
@@ -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
@@ -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

0 comments on commit 37c954c

Please sign in to comment.