acts-as-taggable-on 0.0.0 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -9
- data/README +196 -0
- data/Rakefile +10 -47
- data/VERSION +1 -1
- data/lib/acts-as-taggable-on.rb +6 -30
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +313 -28
- data/lib/acts_as_taggable_on/acts_as_tagger.rb +45 -40
- data/lib/acts_as_taggable_on/tag.rb +6 -48
- data/lib/acts_as_taggable_on/tag_list.rb +29 -31
- data/lib/acts_as_taggable_on/tagging.rb +1 -18
- data/lib/acts_as_taggable_on/tags_helper.rb +2 -8
- data/rails/init.rb +6 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +47 -148
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +4 -46
- data/spec/acts_as_taggable_on/tag_list_spec.rb +0 -29
- data/spec/acts_as_taggable_on/tag_spec.rb +7 -95
- data/spec/acts_as_taggable_on/taggable_spec.rb +48 -178
- data/spec/acts_as_taggable_on/tagger_spec.rb +5 -57
- data/spec/acts_as_taggable_on/tagging_spec.rb +1 -25
- data/spec/schema.rb +2 -12
- data/spec/spec.opts +6 -1
- data/spec/spec_helper.rb +34 -35
- metadata +7 -31
- data/Gemfile +0 -6
- data/README.rdoc +0 -212
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +0 -56
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +0 -97
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +0 -220
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +0 -29
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +0 -101
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +0 -64
- data/lib/acts_as_taggable_on/compatibility/Gemfile +0 -6
- data/lib/acts_as_taggable_on/compatibility/active_record_backports.rb +0 -17
- data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -31
- data/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb +0 -28
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +0 -28
- data/spec/bm.rb +0 -52
- data/spec/models.rb +0 -36
@@ -1,11 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe "acts_as_tagger" do
|
4
|
-
before(:each) do
|
5
|
-
clean_database!
|
6
|
-
end
|
7
|
-
|
8
4
|
context "Tagger Method Generation" do
|
5
|
+
|
9
6
|
before(:each) do
|
10
7
|
@tagger = TaggableUser.new()
|
11
8
|
end
|
@@ -51,23 +48,8 @@ describe "acts_as_tagger" do
|
|
51
48
|
|
52
49
|
it 'should by default create the tag context on-the-fly' do
|
53
50
|
@taggable.tag_list_on(:here_ond_now).should be_empty
|
54
|
-
@tagger.tag(@taggable, :with=>'that', :on
|
55
|
-
@taggable.tag_list_on(:here_ond_now).
|
56
|
-
@taggable.all_tags_list_on(:here_ond_now).should include('that')
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should show all the tag list when both public and owned tags exist" do
|
60
|
-
@taggable.tag_list = 'ruby, python'
|
61
|
-
@tagger.tag(@taggable, :with => 'java, lisp', :on => :tags)
|
62
|
-
@taggable.all_tags_on(:tags).map(&:name).sort.should == %w(ruby python java lisp).sort
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should not add owned tags to the common list" do
|
66
|
-
@taggable.tag_list = 'ruby, python'
|
67
|
-
@tagger.tag(@taggable, :with => 'java, lisp', :on => :tags)
|
68
|
-
@taggable.tag_list.should == %w(ruby python)
|
69
|
-
@tagger.tag(@taggable, :with => '', :on => :tags)
|
70
|
-
@taggable.tag_list.should == %w(ruby python)
|
51
|
+
@tagger.tag(@taggable, :with=>'that', :on=>:here_ond_now)
|
52
|
+
@taggable.tag_list_on(:here_ond_now).should include('that')
|
71
53
|
end
|
72
54
|
|
73
55
|
it "should throw an exception when the default is over-ridden" do
|
@@ -82,33 +64,9 @@ describe "acts_as_tagger" do
|
|
82
64
|
@tagger.tag(@taggable, :with=>'this, and, that', :on=>:foo_boo, :force=>false) rescue
|
83
65
|
@taggable.tag_list_on(:foo_boo).should be_empty
|
84
66
|
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when called by multiple tagger's" do
|
88
|
-
before(:each) do
|
89
|
-
@user_x = TaggableUser.create(:name => "User X")
|
90
|
-
@user_y = TaggableUser.create(:name => "User Y")
|
91
|
-
@taggable = TaggableModel.create(:name => 'acts_as_taggable_on', :tag_list => 'plugin')
|
92
|
-
|
93
|
-
@user_x.tag(@taggable, :with => 'ruby, rails', :on => :tags)
|
94
|
-
@user_y.tag(@taggable, :with => 'ruby, plugin', :on => :tags)
|
95
67
|
|
96
|
-
@user_y.tag(@taggable, :with => '', :on => :tags)
|
97
|
-
@user_y.tag(@taggable, :with => '', :on => :tags)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should delete owned tags" do
|
101
|
-
@user_y.owned_tags.should == []
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should not delete other taggers tags" do
|
105
|
-
@user_x.owned_tags.should have(2).items
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should not delete original tags" do
|
109
|
-
@taggable.all_tags_list_on(:tags).should include('plugin')
|
110
|
-
end
|
111
68
|
end
|
69
|
+
|
112
70
|
end
|
113
71
|
|
114
72
|
end
|
@@ -20,24 +20,6 @@ describe TagList do
|
|
20
20
|
@tag_list.include?("wicked").should be_true
|
21
21
|
end
|
22
22
|
|
23
|
-
it "should be able to add delimited list of words with quoted delimiters" do
|
24
|
-
@tag_list.add("'cool, wicked', \"really cool, really wicked\"", :parse => true)
|
25
|
-
@tag_list.include?("cool, wicked").should be_true
|
26
|
-
@tag_list.include?("really cool, really wicked").should be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should be able to handle other uses of quotation marks correctly" do
|
30
|
-
@tag_list.add("john's cool car, mary's wicked toy", :parse => true)
|
31
|
-
@tag_list.include?("john's cool car").should be_true
|
32
|
-
@tag_list.include?("mary's wicked toy").should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should be able to add an array of words" do
|
36
|
-
@tag_list.add(["cool", "wicked"], :parse => true)
|
37
|
-
@tag_list.include?("cool").should be_true
|
38
|
-
@tag_list.include?("wicked").should be_true
|
39
|
-
end
|
40
|
-
|
41
23
|
it "should be able to remove words" do
|
42
24
|
@tag_list.remove("awesome")
|
43
25
|
@tag_list.include?("awesome").should be_false
|
@@ -48,11 +30,6 @@ describe TagList do
|
|
48
30
|
@tag_list.should be_empty
|
49
31
|
end
|
50
32
|
|
51
|
-
it "should be able to remove an array of words" do
|
52
|
-
@tag_list.remove(["awesome", "radical"], :parse => true)
|
53
|
-
@tag_list.should be_empty
|
54
|
-
end
|
55
|
-
|
56
33
|
it "should give a delimited list of words when converted to string" do
|
57
34
|
@tag_list.to_s.should == "awesome, radical"
|
58
35
|
end
|
@@ -61,10 +38,4 @@ describe TagList do
|
|
61
38
|
@tag_list.add("cool","rad,bodacious")
|
62
39
|
@tag_list.to_s.should == "awesome, radical, cool, \"rad,bodacious\""
|
63
40
|
end
|
64
|
-
|
65
|
-
it "should be able to call to_s on a frozen tag list" do
|
66
|
-
@tag_list.freeze
|
67
|
-
lambda { @tag_list.add("cool","rad,bodacious") }.should raise_error
|
68
|
-
lambda { @tag_list.to_s }.should_not raise_error
|
69
|
-
end
|
70
41
|
end
|
@@ -2,114 +2,26 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe Tag do
|
4
4
|
before(:each) do
|
5
|
-
clean_database!
|
6
5
|
@tag = Tag.new
|
7
|
-
@user = TaggableModel.create(:name => "Pablo")
|
6
|
+
@user = TaggableModel.create(:name => "Pablo")
|
8
7
|
end
|
9
|
-
|
10
|
-
describe "named like any" do
|
11
|
-
before(:each) do
|
12
|
-
Tag.create(:name => "awesome")
|
13
|
-
Tag.create(:name => "epic")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should find both tags" do
|
17
|
-
Tag.named_like_any(["awesome", "epic"]).should have(2).items
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "find or create by name" do
|
22
|
-
before(:each) do
|
23
|
-
@tag.name = "awesome"
|
24
|
-
@tag.save
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should find by name" do
|
28
|
-
Tag.find_or_create_with_like_by_name("awesome").should == @tag
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should find by name case insensitive" do
|
32
|
-
Tag.find_or_create_with_like_by_name("AWESOME").should == @tag
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should create by name" do
|
36
|
-
lambda {
|
37
|
-
Tag.find_or_create_with_like_by_name("epic")
|
38
|
-
}.should change(Tag, :count).by(1)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "find or create all by any name" do
|
43
|
-
before(:each) do
|
44
|
-
@tag.name = "awesome"
|
45
|
-
@tag.save
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should find by name" do
|
49
|
-
Tag.find_or_create_all_with_like_by_name("awesome").should == [@tag]
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should find by name case insensitive" do
|
53
|
-
Tag.find_or_create_all_with_like_by_name("AWESOME").should == [@tag]
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should create by name" do
|
57
|
-
lambda {
|
58
|
-
Tag.find_or_create_all_with_like_by_name("epic")
|
59
|
-
}.should change(Tag, :count).by(1)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should find or create by name" do
|
63
|
-
lambda {
|
64
|
-
Tag.find_or_create_all_with_like_by_name("awesome", "epic").map(&:name).should == ["awesome", "epic"]
|
65
|
-
}.should change(Tag, :count).by(1)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return an empty array if no tags are specified" do
|
69
|
-
Tag.find_or_create_all_with_like_by_name([]).should == []
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
8
|
+
|
73
9
|
it "should require a name" do
|
74
10
|
@tag.valid?
|
75
|
-
|
76
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
77
|
-
@tag.errors[:name].should == ["can't be blank"]
|
78
|
-
else
|
79
|
-
@tag.errors[:name].should == "can't be blank"
|
80
|
-
end
|
81
|
-
|
11
|
+
@tag.errors.on(:name).should == "can't be blank"
|
82
12
|
@tag.name = "something"
|
83
13
|
@tag.valid?
|
84
|
-
|
85
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
86
|
-
@tag.errors[:name].should == []
|
87
|
-
else
|
88
|
-
@tag.errors[:name].should be_nil
|
89
|
-
end
|
14
|
+
@tag.errors.on(:name).should be_nil
|
90
15
|
end
|
91
|
-
|
16
|
+
|
92
17
|
it "should equal a tag with the same name" do
|
93
18
|
@tag.name = "awesome"
|
94
19
|
new_tag = Tag.new(:name => "awesome")
|
95
20
|
new_tag.should == @tag
|
96
21
|
end
|
97
|
-
|
22
|
+
|
98
23
|
it "should return its name when to_s is called" do
|
99
24
|
@tag.name = "cool"
|
100
25
|
@tag.to_s.should == "cool"
|
101
26
|
end
|
102
|
-
|
103
|
-
it "have named_scope named(something)" do
|
104
|
-
@tag.name = "cool"
|
105
|
-
@tag.save!
|
106
|
-
Tag.named('cool').should include(@tag)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "have named_scope named_like(something)" do
|
110
|
-
@tag.name = "cool"
|
111
|
-
@tag.save!
|
112
|
-
@another_tag = Tag.create!(:name => "coolip")
|
113
|
-
Tag.named_like('cool').should include(@tag, @another_tag)
|
114
|
-
end
|
115
|
-
end
|
27
|
+
end
|
@@ -2,58 +2,34 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe "Taggable" do
|
4
4
|
before(:each) do
|
5
|
-
|
5
|
+
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
6
6
|
@taggable = TaggableModel.new(:name => "Bob Jones")
|
7
7
|
end
|
8
|
-
|
9
|
-
it "should have tag types" do
|
10
|
-
[:tags, :languages, :skills, :needs, :offerings].each do |type|
|
11
|
-
TaggableModel.tag_types.should include type
|
12
|
-
end
|
13
|
-
|
14
|
-
@taggable.tag_types.should == TaggableModel.tag_types
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have tag_counts_on" do
|
18
|
-
TaggableModel.tag_counts_on(:tags).all.should be_empty
|
19
|
-
|
20
|
-
@taggable.tag_list = ["awesome", "epic"]
|
21
|
-
@taggable.save
|
22
|
-
|
23
|
-
TaggableModel.tag_counts_on(:tags).length.should == 2
|
24
|
-
@taggable.tag_counts_on(:tags).length.should == 2
|
25
|
-
end
|
26
|
-
|
8
|
+
|
27
9
|
it "should be able to create tags" do
|
28
10
|
@taggable.skill_list = "ruby, rails, css"
|
29
11
|
@taggable.instance_variable_get("@skill_list").instance_of?(TagList).should be_true
|
12
|
+
@taggable.save
|
30
13
|
|
31
|
-
|
32
|
-
@taggable.save
|
33
|
-
}.should change(Tag, :count).by(3)
|
14
|
+
Tag.find(:all).size.should == 3
|
34
15
|
end
|
35
|
-
|
16
|
+
|
36
17
|
it "should be able to create tags through the tag list directly" do
|
37
18
|
@taggable.tag_list_on(:test).add("hello")
|
38
|
-
@taggable.
|
39
|
-
@taggable.tag_list_on(:test).should == ["hello"]
|
40
|
-
|
41
|
-
@taggable.save
|
42
|
-
@taggable.save_tags
|
43
|
-
|
19
|
+
@taggable.save
|
44
20
|
@taggable.reload
|
45
21
|
@taggable.tag_list_on(:test).should == ["hello"]
|
46
22
|
end
|
47
|
-
|
23
|
+
|
48
24
|
it "should differentiate between contexts" do
|
49
25
|
@taggable.skill_list = "ruby, rails, css"
|
50
26
|
@taggable.tag_list = "ruby, bob, charlie"
|
51
27
|
@taggable.save
|
52
28
|
@taggable.reload
|
53
|
-
@taggable.skill_list.
|
54
|
-
@taggable.skill_list.
|
29
|
+
@taggable.skill_list.include?("ruby").should be_true
|
30
|
+
@taggable.skill_list.include?("bob").should be_false
|
55
31
|
end
|
56
|
-
|
32
|
+
|
57
33
|
it "should be able to remove tags through list alone" do
|
58
34
|
@taggable.skill_list = "ruby, rails, css"
|
59
35
|
@taggable.save
|
@@ -64,83 +40,55 @@ describe "Taggable" do
|
|
64
40
|
@taggable.reload
|
65
41
|
@taggable.should have(2).skills
|
66
42
|
end
|
67
|
-
|
43
|
+
|
68
44
|
it "should be able to find by tag" do
|
69
45
|
@taggable.skill_list = "ruby, rails, css"
|
70
46
|
@taggable.save
|
71
|
-
|
72
|
-
TaggableModel.tagged_with("ruby").first.should == @taggable
|
47
|
+
TaggableModel.find_tagged_with("ruby").first.should == @taggable
|
73
48
|
end
|
74
|
-
|
49
|
+
|
75
50
|
it "should be able to find by tag with context" do
|
76
51
|
@taggable.skill_list = "ruby, rails, css"
|
77
52
|
@taggable.tag_list = "bob, charlie"
|
78
53
|
@taggable.save
|
79
|
-
|
80
|
-
TaggableModel.
|
81
|
-
TaggableModel.
|
54
|
+
TaggableModel.find_tagged_with("ruby").first.should == @taggable
|
55
|
+
TaggableModel.find_tagged_with("bob", :on => :skills).first.should_not == @taggable
|
56
|
+
TaggableModel.find_tagged_with("bob", :on => :tags).first.should == @taggable
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be able to use the tagged_with named scope" do
|
60
|
+
@taggable.skill_list = "ruby, rails, css"
|
61
|
+
@taggable.tag_list = "bob, charlie"
|
62
|
+
@taggable.save
|
63
|
+
TaggableModel.tagged_with("ruby", {}).first.should == @taggable
|
82
64
|
TaggableModel.tagged_with("bob", :on => :skills).first.should_not == @taggable
|
83
65
|
TaggableModel.tagged_with("bob", :on => :tags).first.should == @taggable
|
84
66
|
end
|
85
|
-
|
67
|
+
|
86
68
|
it "should not care about case" do
|
87
69
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby")
|
88
70
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
|
89
|
-
|
71
|
+
|
90
72
|
Tag.find(:all).size.should == 1
|
91
|
-
TaggableModel.
|
73
|
+
TaggableModel.find_tagged_with("ruby").should == TaggableModel.find_tagged_with("Ruby")
|
92
74
|
end
|
93
|
-
|
75
|
+
|
94
76
|
it "should be able to get tag counts on model as a whole" do
|
95
77
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
96
78
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
97
79
|
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
98
|
-
TaggableModel.tag_counts.
|
99
|
-
TaggableModel.skill_counts.
|
80
|
+
TaggableModel.tag_counts.should_not be_empty
|
81
|
+
TaggableModel.skill_counts.should_not be_empty
|
100
82
|
end
|
101
|
-
|
102
|
-
it "should be able to get
|
103
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
104
|
-
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
105
|
-
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
106
|
-
|
107
|
-
TaggableModel.all_tag_counts.all.should_not be_empty
|
108
|
-
TaggableModel.all_tag_counts.first.count.should == 3 # ruby
|
109
|
-
end
|
110
|
-
|
111
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
112
|
-
it "should not return read-only records" do
|
113
|
-
TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
114
|
-
TaggableModel.tagged_with("ruby").first.should_not be_readonly
|
115
|
-
end
|
116
|
-
else
|
117
|
-
xit "should not return read-only records" do
|
118
|
-
# apparantly, there is no way to set readonly to false in a scope if joins are made
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should be possible to return writable records" do
|
122
|
-
TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
123
|
-
TaggableModel.tagged_with("ruby").first(:readonly => false).should_not be_readonly
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should be able to get scoped tag counts" do
|
128
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
129
|
-
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
130
|
-
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
131
|
-
|
132
|
-
TaggableModel.tagged_with("ruby").tag_counts.first.count.should == 2 # ruby
|
133
|
-
TaggableModel.tagged_with("ruby").skill_counts.first.count.should == 1 # ruby
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should be able to get all scoped tag counts" do
|
83
|
+
|
84
|
+
it "should be able to get tag counts on an association" do
|
137
85
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
|
138
86
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
139
87
|
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
140
|
-
|
141
|
-
|
88
|
+
bob.tag_counts.first.count.should == 2
|
89
|
+
charlie.skill_counts.first.count.should == 1
|
142
90
|
end
|
143
|
-
|
91
|
+
|
144
92
|
it "should be able to set a custom tag context list" do
|
145
93
|
bob = TaggableModel.create(:name => "Bob")
|
146
94
|
bob.set_tag_list_on(:rotors, "spinning, jumping")
|
@@ -149,83 +97,26 @@ describe "Taggable" do
|
|
149
97
|
bob.reload
|
150
98
|
bob.tags_on(:rotors).should_not be_empty
|
151
99
|
end
|
152
|
-
|
153
|
-
it "should be able to find tagged" do
|
154
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
|
155
|
-
frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
|
156
|
-
steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
|
157
|
-
|
158
|
-
TaggableModel.tagged_with("ruby", :order => 'taggable_models.name').to_a.should == [bob, frank, steve]
|
159
|
-
TaggableModel.tagged_with("ruby, rails", :order => 'taggable_models.name').to_a.should == [bob, frank]
|
160
|
-
TaggableModel.tagged_with(["ruby", "rails"], :order => 'taggable_models.name').to_a.should == [bob, frank]
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should be able to find tagged with any tag" do
|
164
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
|
165
|
-
frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
|
166
|
-
steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
|
167
|
-
|
168
|
-
TaggableModel.tagged_with(["ruby", "java"], :order => 'taggable_models.name', :any => true).to_a.should == [bob, frank, steve]
|
169
|
-
TaggableModel.tagged_with(["c++", "fitter"], :order => 'taggable_models.name', :any => true).to_a.should == [bob, steve]
|
170
|
-
TaggableModel.tagged_with(["depressed", "css"], :order => 'taggable_models.name', :any => true).to_a.should == [bob, frank]
|
171
|
-
end
|
172
|
-
|
100
|
+
|
173
101
|
it "should be able to find tagged on a custom tag context" do
|
174
102
|
bob = TaggableModel.create(:name => "Bob")
|
175
103
|
bob.set_tag_list_on(:rotors, "spinning, jumping")
|
176
104
|
bob.tag_list_on(:rotors).should == ["spinning","jumping"]
|
177
105
|
bob.save
|
178
|
-
|
179
|
-
TaggableModel.tagged_with("spinning", :on => :rotors).to_a.should == [bob]
|
106
|
+
TaggableModel.find_tagged_with("spinning", :on => :rotors).should_not be_empty
|
180
107
|
end
|
181
108
|
|
182
109
|
it "should be able to use named scopes to chain tag finds" do
|
183
110
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
|
184
111
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
|
185
112
|
steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, python')
|
186
|
-
|
113
|
+
|
187
114
|
# Let's only find those productive Rails developers
|
188
|
-
TaggableModel.tagged_with('rails', :on => :skills
|
189
|
-
TaggableModel.tagged_with('happier', :on => :tags
|
190
|
-
TaggableModel.tagged_with('rails', :on => :skills).tagged_with('happier', :on => :tags).
|
191
|
-
TaggableModel.tagged_with('rails').tagged_with('happier', :on => :tags).to_a.should == [bob]
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should be able to find tagged with only the matching tags" do
|
195
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "lazy, happier")
|
196
|
-
frank = TaggableModel.create(:name => "Frank", :tag_list => "fitter, happier, inefficient")
|
197
|
-
steve = TaggableModel.create(:name => 'Steve', :tag_list => "fitter, happier")
|
198
|
-
|
199
|
-
TaggableModel.tagged_with("fitter, happier", :match_all => true).to_a.should == [steve]
|
115
|
+
TaggableModel.tagged_with('rails', :on => :skills).all(:order => 'taggable_models.name').should == [bob, frank]
|
116
|
+
TaggableModel.tagged_with('happier', :on => :tags).all(:order => 'taggable_models.name').should == [bob, steve]
|
117
|
+
TaggableModel.tagged_with('rails', :on => :skills).tagged_with('happier', :on => :tags).should == [bob]
|
200
118
|
end
|
201
|
-
|
202
|
-
it "should be able to find tagged with some excluded tags" do
|
203
|
-
bob = TaggableModel.create(:name => "Bob", :tag_list => "happier, lazy")
|
204
|
-
frank = TaggableModel.create(:name => "Frank", :tag_list => "happier")
|
205
|
-
steve = TaggableModel.create(:name => 'Steve', :tag_list => "happier")
|
206
|
-
|
207
|
-
TaggableModel.tagged_with("lazy", :exclude => true).to_a.should == [frank, steve]
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should not create duplicate taggings" do
|
211
|
-
bob = TaggableModel.create(:name => "Bob")
|
212
|
-
lambda {
|
213
|
-
bob.tag_list << "happier"
|
214
|
-
bob.tag_list << "happier"
|
215
|
-
bob.save
|
216
|
-
}.should change(Tagging, :count).by(1)
|
217
|
-
end
|
218
|
-
|
219
|
-
describe "grouped_column_names_for method" do
|
220
|
-
it "should return all column names joined for Tag GROUP clause" do
|
221
|
-
@taggable.grouped_column_names_for(Tag).should == "tags.id, tags.name"
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should return all column names joined for TaggableModel GROUP clause" do
|
225
|
-
@taggable.grouped_column_names_for(TaggableModel).should == "taggable_models.id, taggable_models.name, taggable_models.type"
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
119
|
+
|
229
120
|
describe "Single Table Inheritance" do
|
230
121
|
before do
|
231
122
|
[TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
|
@@ -233,45 +124,24 @@ describe "Taggable" do
|
|
233
124
|
@inherited_same = InheritingTaggableModel.new(:name => "inherited same")
|
234
125
|
@inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
|
235
126
|
end
|
236
|
-
|
127
|
+
|
237
128
|
it "should be able to save tags for inherited models" do
|
238
129
|
@inherited_same.tag_list = "bob, kelso"
|
239
130
|
@inherited_same.save
|
240
|
-
InheritingTaggableModel.
|
131
|
+
InheritingTaggableModel.find_tagged_with("bob").first.should == @inherited_same
|
241
132
|
end
|
242
|
-
|
133
|
+
|
243
134
|
it "should find STI tagged models on the superclass" do
|
244
135
|
@inherited_same.tag_list = "bob, kelso"
|
245
136
|
@inherited_same.save
|
246
|
-
TaggableModel.
|
137
|
+
TaggableModel.find_tagged_with("bob").first.should == @inherited_same
|
247
138
|
end
|
248
|
-
|
139
|
+
|
249
140
|
it "should be able to add on contexts only to some subclasses" do
|
250
141
|
@inherited_different.part_list = "fork, spoon"
|
251
142
|
@inherited_different.save
|
252
|
-
InheritingTaggableModel.
|
253
|
-
AlteredInheritingTaggableModel.
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should have different tag_counts_on for inherited models" do
|
257
|
-
@inherited_same.tag_list = "bob, kelso"
|
258
|
-
@inherited_same.save!
|
259
|
-
@inherited_different.tag_list = "fork, spoon"
|
260
|
-
@inherited_different.save!
|
261
|
-
|
262
|
-
InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
|
263
|
-
AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
|
264
|
-
TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
|
265
|
-
end
|
266
|
-
|
267
|
-
it 'should store same tag without validation conflict' do
|
268
|
-
@taggable.tag_list = 'one'
|
269
|
-
@taggable.save!
|
270
|
-
|
271
|
-
@inherited_same.tag_list = 'one'
|
272
|
-
@inherited_same.save!
|
273
|
-
|
274
|
-
@inherited_same.update_attributes! :name => 'foo'
|
143
|
+
InheritingTaggableModel.find_tagged_with("fork", :on => :parts).should be_empty
|
144
|
+
AlteredInheritingTaggableModel.find_tagged_with("fork", :on => :parts).first.should == @inherited_different
|
275
145
|
end
|
276
146
|
end
|
277
147
|
end
|