acts-as-taggable-on 1.1.9 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,65 +6,65 @@ describe Tag do
6
6
  @tag = Tag.new
7
7
  @user = TaggableModel.create(:name => "Pablo")
8
8
  end
9
-
9
+
10
10
  describe "named like any" do
11
11
  before(:each) do
12
12
  Tag.create(:name => "awesome")
13
13
  Tag.create(:name => "epic")
14
14
  end
15
-
15
+
16
16
  it "should find both tags" do
17
17
  Tag.named_like_any(["awesome", "epic"]).should have(2).items
18
18
  end
19
19
  end
20
-
20
+
21
21
  describe "find or create by name" do
22
22
  before(:each) do
23
23
  @tag.name = "awesome"
24
24
  @tag.save
25
25
  end
26
-
26
+
27
27
  it "should find by name" do
28
28
  Tag.find_or_create_with_like_by_name("awesome").should == @tag
29
29
  end
30
-
30
+
31
31
  it "should find by name case insensitive" do
32
32
  Tag.find_or_create_with_like_by_name("AWESOME").should == @tag
33
33
  end
34
-
34
+
35
35
  it "should create by name" do
36
36
  lambda {
37
37
  Tag.find_or_create_with_like_by_name("epic")
38
38
  }.should change(Tag, :count).by(1)
39
39
  end
40
40
  end
41
-
41
+
42
42
  describe "find or create all by any name" do
43
43
  before(:each) do
44
44
  @tag.name = "awesome"
45
45
  @tag.save
46
46
  end
47
-
47
+
48
48
  it "should find by name" do
49
49
  Tag.find_or_create_all_with_like_by_name("awesome").should == [@tag]
50
50
  end
51
-
51
+
52
52
  it "should find by name case insensitive" do
53
53
  Tag.find_or_create_all_with_like_by_name("AWESOME").should == [@tag]
54
54
  end
55
-
55
+
56
56
  it "should create by name" do
57
57
  lambda {
58
58
  Tag.find_or_create_all_with_like_by_name("epic")
59
59
  }.should change(Tag, :count).by(1)
60
60
  end
61
-
61
+
62
62
  it "should find or create by name" do
63
63
  lambda {
64
64
  Tag.find_or_create_all_with_like_by_name("awesome", "epic").map(&:name).should == ["awesome", "epic"]
65
- }.should change(Tag, :count).by(1)
65
+ }.should change(Tag, :count).by(1)
66
66
  end
67
-
67
+
68
68
  it "should return an empty array if no tags are specified" do
69
69
  Tag.find_or_create_all_with_like_by_name([]).should == []
70
70
  end
@@ -72,33 +72,33 @@ describe Tag do
72
72
 
73
73
  it "should require a name" do
74
74
  @tag.valid?
75
- @tag.errors.on(:name).should == "can't be blank"
75
+ @tag.errors[:name].should == ["can't be blank"]
76
76
  @tag.name = "something"
77
77
  @tag.valid?
78
- @tag.errors.on(:name).should be_nil
78
+ @tag.errors[:name].should == []
79
79
  end
80
-
80
+
81
81
  it "should equal a tag with the same name" do
82
82
  @tag.name = "awesome"
83
83
  new_tag = Tag.new(:name => "awesome")
84
84
  new_tag.should == @tag
85
85
  end
86
-
86
+
87
87
  it "should return its name when to_s is called" do
88
88
  @tag.name = "cool"
89
89
  @tag.to_s.should == "cool"
90
90
  end
91
-
91
+
92
92
  it "have named_scope named(something)" do
93
93
  @tag.name = "cool"
94
94
  @tag.save!
95
95
  Tag.named('cool').should include(@tag)
96
96
  end
97
-
97
+
98
98
  it "have named_scope named_like(something)" do
99
99
  @tag.name = "cool"
100
100
  @tag.save!
101
101
  @another_tag = Tag.create!(:name => "coolip")
102
102
  Tag.named_like('cool').should include(@tag, @another_tag)
103
103
  end
104
- end
104
+ end
@@ -14,7 +14,7 @@ describe "Taggable" do
14
14
  end
15
15
 
16
16
  it "should have tag_counts_on" do
17
- TaggableModel.tag_counts_on(:tags).should be_empty
17
+ TaggableModel.tag_counts_on(:tags).all.should be_empty
18
18
 
19
19
  @taggable.tag_list = ["awesome", "epic"]
20
20
  @taggable.save
@@ -64,26 +64,17 @@ describe "Taggable" do
64
64
  it "should be able to find by tag" do
65
65
  @taggable.skill_list = "ruby, rails, css"
66
66
  @taggable.save
67
- TaggableModel.find_tagged_with("ruby").first.should == @taggable
68
- end
69
67
 
70
- it "should be able to find by tag with context" do
71
- @taggable.skill_list = "ruby, rails, css"
72
- @taggable.tag_list = "bob, charlie"
73
- @taggable.save
74
- TaggableModel.find_tagged_with("ruby").first.should == @taggable
75
- TaggableModel.find_tagged_with("bob", :on => :skills).first.should_not == @taggable
76
- TaggableModel.find_tagged_with("bob", :on => :tags).first.should == @taggable
68
+ TaggableModel.tagged_with("ruby").first.should == @taggable
77
69
  end
78
70
 
79
- it "should be able to use the tagged_with named scope" do
71
+ it "should be able to find by tag with context" do
80
72
  @taggable.skill_list = "ruby, rails, css"
81
73
  @taggable.tag_list = "bob, charlie"
82
74
  @taggable.save
83
75
 
84
76
  TaggableModel.tagged_with("ruby").first.should == @taggable
85
77
  TaggableModel.tagged_with("ruby, css").first.should == @taggable
86
- TaggableModel.tagged_with("ruby, nonexistingtag").should be_empty
87
78
  TaggableModel.tagged_with("bob", :on => :skills).first.should_not == @taggable
88
79
  TaggableModel.tagged_with("bob", :on => :tags).first.should == @taggable
89
80
  end
@@ -93,15 +84,15 @@ describe "Taggable" do
93
84
  frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
94
85
 
95
86
  Tag.find(:all).size.should == 1
96
- TaggableModel.find_tagged_with("ruby").should == TaggableModel.find_tagged_with("Ruby")
87
+ TaggableModel.tagged_with("ruby").all.should == TaggableModel.tagged_with("Ruby").all
97
88
  end
98
89
 
99
90
  it "should be able to get tag counts on model as a whole" do
100
91
  bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
101
92
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
102
93
  charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
103
- TaggableModel.tag_counts.should_not be_empty
104
- TaggableModel.skill_counts.should_not be_empty
94
+ TaggableModel.tag_counts.all.should_not be_empty
95
+ TaggableModel.skill_counts.all.should_not be_empty
105
96
  end
106
97
 
107
98
  it "should be able to get all tag counts on model as whole" do
@@ -109,7 +100,7 @@ describe "Taggable" do
109
100
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
110
101
  charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
111
102
 
112
- TaggableModel.all_tag_counts.should_not be_empty
103
+ TaggableModel.all_tag_counts.all.should_not be_empty
113
104
  TaggableModel.all_tag_counts.first.count.should == 3 # ruby
114
105
  end
115
106
 
@@ -150,9 +141,9 @@ describe "Taggable" do
150
141
  frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
151
142
  steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
152
143
 
153
- TaggableModel.find_tagged_with("ruby", :order => 'taggable_models.name').should == [bob, frank, steve]
154
- TaggableModel.find_tagged_with("ruby, rails", :order => 'taggable_models.name').should == [bob, frank]
155
- TaggableModel.find_tagged_with(["ruby", "rails"], :order => 'taggable_models.name').should == [bob, frank]
144
+ TaggableModel.tagged_with("ruby", :order => 'taggable_models.name').all.should == [bob, frank, steve]
145
+ TaggableModel.tagged_with("ruby, rails", :order => 'taggable_models.name').all.should == [bob, frank]
146
+ TaggableModel.tagged_with(["ruby", "rails"], :order => 'taggable_models.name').all.should == [bob, frank]
156
147
  end
157
148
 
158
149
  it "should be able to find tagged with any tag" do
@@ -160,9 +151,9 @@ describe "Taggable" do
160
151
  frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
161
152
  steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
162
153
 
163
- TaggableModel.find_tagged_with(["ruby", "java"], :order => 'taggable_models.name', :any => true).should == [bob, frank, steve]
164
- TaggableModel.find_tagged_with(["c++", "fitter"], :order => 'taggable_models.name', :any => true).should == [bob, steve]
165
- TaggableModel.find_tagged_with(["depressed", "css"], :order => 'taggable_models.name', :any => true).should == [bob, frank]
154
+ TaggableModel.tagged_with(["ruby", "java"], :order => 'taggable_models.name', :any => true).all.should == [bob, frank, steve]
155
+ TaggableModel.tagged_with(["c++", "fitter"], :order => 'taggable_models.name', :any => true).all.should == [bob, steve]
156
+ TaggableModel.tagged_with(["depressed", "css"], :order => 'taggable_models.name', :any => true).all.should == [bob, frank]
166
157
  end
167
158
 
168
159
  it "should be able to find tagged on a custom tag context" do
@@ -170,7 +161,8 @@ describe "Taggable" do
170
161
  bob.set_tag_list_on(:rotors, "spinning, jumping")
171
162
  bob.tag_list_on(:rotors).should == ["spinning","jumping"]
172
163
  bob.save
173
- TaggableModel.find_tagged_with("spinning", :on => :rotors).should == [bob]
164
+
165
+ TaggableModel.tagged_with("spinning", :on => :rotors).all.should == [bob]
174
166
  end
175
167
 
176
168
  it "should be able to use named scopes to chain tag finds" do
@@ -190,7 +182,7 @@ describe "Taggable" do
190
182
  frank = TaggableModel.create(:name => "Frank", :tag_list => "fitter, happier, inefficient")
191
183
  steve = TaggableModel.create(:name => 'Steve', :tag_list => "fitter, happier")
192
184
 
193
- TaggableModel.find_tagged_with("fitter, happier", :match_all => true).should == [steve]
185
+ TaggableModel.tagged_with("fitter, happier", :match_all => true).all.should == [steve]
194
186
  end
195
187
 
196
188
  it "should be able to find tagged with some excluded tags" do
@@ -198,7 +190,7 @@ describe "Taggable" do
198
190
  frank = TaggableModel.create(:name => "Frank", :tag_list => "happier")
199
191
  steve = TaggableModel.create(:name => 'Steve', :tag_list => "happier")
200
192
 
201
- TaggableModel.find_tagged_with("lazy", :exclude => true).should == [frank, steve]
193
+ TaggableModel.tagged_with("lazy", :exclude => true).all.should == [frank, steve]
202
194
  end
203
195
 
204
196
  it "should not create duplicate taggings" do
@@ -209,21 +201,10 @@ describe "Taggable" do
209
201
  bob.save
210
202
  }.should change(Tagging, :count).by(1)
211
203
  end
212
-
213
- describe "Associations" do
214
- before(:each) do
215
- @taggable = TaggableModel.create(:tag_list => "awesome, epic")
216
- end
217
-
218
- it "should not remove tags when creating associated objects" do
219
- @taggable.untaggable_models.create!
220
- @taggable.reload
221
- @taggable.tag_list.should have(2).items
222
- end
223
- end
224
-
204
+
225
205
  describe "Single Table Inheritance" do
226
206
  before do
207
+ [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
227
208
  @taggable = TaggableModel.new(:name => "taggable")
228
209
  @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
229
210
  @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
@@ -232,20 +213,20 @@ describe "Taggable" do
232
213
  it "should be able to save tags for inherited models" do
233
214
  @inherited_same.tag_list = "bob, kelso"
234
215
  @inherited_same.save
235
- InheritingTaggableModel.find_tagged_with("bob").first.should == @inherited_same
216
+ InheritingTaggableModel.tagged_with("bob").first.should == @inherited_same
236
217
  end
237
218
 
238
219
  it "should find STI tagged models on the superclass" do
239
220
  @inherited_same.tag_list = "bob, kelso"
240
221
  @inherited_same.save
241
- TaggableModel.find_tagged_with("bob").first.should == @inherited_same
222
+ TaggableModel.tagged_with("bob").first.should == @inherited_same
242
223
  end
243
224
 
244
225
  it "should be able to add on contexts only to some subclasses" do
245
226
  @inherited_different.part_list = "fork, spoon"
246
227
  @inherited_different.save
247
- InheritingTaggableModel.find_tagged_with("fork", :on => :parts).should be_empty
248
- AlteredInheritingTaggableModel.find_tagged_with("fork", :on => :parts).first.should == @inherited_different
228
+ InheritingTaggableModel.tagged_with("fork", :on => :parts).should be_empty
229
+ AlteredInheritingTaggableModel.tagged_with("fork", :on => :parts).first.should == @inherited_different
249
230
  end
250
231
 
251
232
  it "should have different tag_counts_on for inherited models" do
@@ -258,14 +239,14 @@ describe "Taggable" do
258
239
  AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
259
240
  TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
260
241
  end
261
-
242
+
262
243
  it 'should store same tag without validation conflict' do
263
244
  @taggable.tag_list = 'one'
264
245
  @taggable.save!
265
-
246
+
266
247
  @inherited_same.tag_list = 'one'
267
248
  @inherited_same.save!
268
-
249
+
269
250
  @inherited_same.update_attributes! :name => 'foo'
270
251
  end
271
252
  end
@@ -33,22 +33,6 @@ describe "Tagger" do
33
33
  @taggable.all_tags_list_on(:tags).sort.should == %w(ruby scheme java python lisp).sort
34
34
  @taggable.all_tags_on(:tags).size.should == 6
35
35
  end
36
-
37
- it "should not lose tags" do
38
- @taggable.update_attributes(:tag_list => 'ruby')
39
- @user.tag(@taggable, :with => 'ruby, scheme', :on => :tags)
40
-
41
- [@taggable, @user].each(&:reload)
42
- @taggable.tag_list.should == %w(ruby)
43
- @taggable.all_tags_list.sort.should == %w(ruby scheme).sort
44
-
45
- lambda {
46
- @taggable.update_attributes(:tag_list => "")
47
- }.should change(Tagging, :count).by(-1)
48
-
49
- @taggable.tag_list.should == []
50
- @taggable.all_tags_list.sort.should == %w(ruby scheme).sort
51
- end
52
36
 
53
37
  it "is tagger" do
54
38
  @user.is_tagger?.should(be_true)
@@ -5,22 +5,22 @@ describe Tagging do
5
5
  clean_database!
6
6
  @tagging = Tagging.new
7
7
  end
8
-
8
+
9
9
  it "should not be valid with a invalid tag" do
10
10
  @tagging.taggable = TaggableModel.create(:name => "Bob Jones")
11
11
  @tagging.tag = Tag.new(:name => "")
12
12
  @tagging.context = "tags"
13
13
 
14
14
  @tagging.should_not be_valid
15
- @tagging.errors.on(:tag_id).should == "can't be blank"
15
+ @tagging.errors[:tag_id].should == ["can't be blank"]
16
16
  end
17
-
17
+
18
18
  it "should not create duplicate taggings" do
19
19
  @taggable = TaggableModel.create(:name => "Bob Jones")
20
20
  @tag = Tag.create(:name => "awesome")
21
-
21
+
22
22
  lambda {
23
23
  2.times { Tagging.create(:taggable => @taggable, :tag => @tag, :context => 'tags') }
24
24
  }.should change(Tagging, :count).by(1)
25
25
  end
26
- end
26
+ end
@@ -19,10 +19,7 @@ ActiveRecord::Schema.define :version => 0 do
19
19
  create_table :taggable_models, :force => true do |t|
20
20
  t.column :name, :string
21
21
  t.column :type, :string
22
- t.column :cached_tag_list, :string
23
- end
24
- create_table :untaggable_models, :force => true do |t|
25
- t.column :taggable_model_id, :integer
22
+ #t.column :cached_tag_list, :string
26
23
  end
27
24
  create_table :taggable_users, :force => true do |t|
28
25
  t.column :name, :string
@@ -30,5 +27,6 @@ ActiveRecord::Schema.define :version => 0 do
30
27
  create_table :other_taggable_models, :force => true do |t|
31
28
  t.column :name, :string
32
29
  t.column :type, :string
30
+ #t.column :cached_tag_list, :string
33
31
  end
34
32
  end
@@ -1,3 +1,2 @@
1
1
  --colour
2
- --reverse
3
- --backtrace
2
+ --backtrace
@@ -1,9 +1,7 @@
1
- # require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
2
- require 'rubygems'
3
- require 'active_record'
4
- require 'spec'
1
+ require File.expand_path('../../lib/acts-as-taggable-on', __FILE__)
2
+ Bundler.require :test
5
3
 
6
- module Spec::Example::ExampleGroupMethods
4
+ module Rspec::Core::ExampleGroupSubject
7
5
  alias :context :describe
8
6
  end
9
7
 
@@ -22,7 +20,7 @@ ActiveRecord::Base.establish_connection(
22
20
  "adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
23
21
  )
24
22
 
25
- ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
23
+ Rails.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
26
24
 
27
25
  ActiveRecord::Base.silence do
28
26
  ActiveRecord::Migration.verbose = false
@@ -30,14 +28,12 @@ ActiveRecord::Base.silence do
30
28
  end
31
29
 
32
30
  $: << File.join(File.dirname(__FILE__), '..', 'lib')
33
- require File.join(File.dirname(__FILE__), '..', 'init')
34
31
 
35
32
  class TaggableModel < ActiveRecord::Base
36
33
  acts_as_taggable
37
34
  acts_as_taggable_on :languages
38
35
  acts_as_taggable_on :skills
39
36
  acts_as_taggable_on :needs, :offerings
40
- has_many :untaggable_models
41
37
  end
42
38
 
43
39
  class OtherTaggableModel < ActiveRecord::Base
@@ -57,13 +53,13 @@ class TaggableUser < ActiveRecord::Base
57
53
  end
58
54
 
59
55
  class UntaggableModel < ActiveRecord::Base
60
- belongs_to :taggable_model, :touch => true
61
56
  end
62
57
 
63
58
  def clean_database!
59
+ $debug = false
64
60
  models = [Tag, Tagging, TaggableModel, OtherTaggableModel, InheritingTaggableModel,
65
61
  AlteredInheritingTaggableModel, TaggableUser]
66
62
  models.each do |model|
67
63
  model.destroy_all
68
64
  end
69
- end
65
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ prerelease: true
5
+ segments:
6
+ - 2
7
+ - 0
8
+ - 0
9
+ - pre1
10
+ version: 2.0.0.pre1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Michael Bleigh
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-03-22 00:00:00 +01:00
18
+ date: 2010-03-08 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -23,12 +29,11 @@ extra_rdoc_files:
23
29
  - README.rdoc
24
30
  files:
25
31
  - CHANGELOG
32
+ - Gemfile
26
33
  - MIT-LICENSE
27
34
  - README.rdoc
28
35
  - Rakefile
29
36
  - VERSION
30
- - generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb
31
- - generators/acts_as_taggable_on_migration/templates/migration.rb
32
37
  - lib/acts-as-taggable-on.rb
33
38
  - lib/acts_as_taggable_on/acts_as_taggable_on.rb
34
39
  - lib/acts_as_taggable_on/acts_as_tagger.rb
@@ -37,7 +42,8 @@ files:
37
42
  - lib/acts_as_taggable_on/tag_list.rb
38
43
  - lib/acts_as_taggable_on/tagging.rb
39
44
  - lib/acts_as_taggable_on/tags_helper.rb
40
- - rails/init.rb
45
+ - lib/generators/acts_as_taggable_on/migration/migration_generator.rb
46
+ - lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
41
47
  - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
42
48
  - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
43
49
  - spec/acts_as_taggable_on/group_helper_spec.rb
@@ -63,18 +69,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
69
  requirements:
64
70
  - - ">="
65
71
  - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
66
74
  version: "0"
67
- version:
68
75
  required_rubygems_version: !ruby/object:Gem::Requirement
69
76
  requirements:
70
- - - ">="
77
+ - - ">"
71
78
  - !ruby/object:Gem::Version
72
- version: "0"
73
- version:
79
+ segments:
80
+ - 1
81
+ - 3
82
+ - 1
83
+ version: 1.3.1
74
84
  requirements: []
75
85
 
76
86
  rubyforge_project:
77
- rubygems_version: 1.3.5
87
+ rubygems_version: 1.3.6
78
88
  signing_key:
79
89
  specification_version: 3
80
90
  summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.