acts-as-taggable-on 2.4.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -4
  3. data/Appraisals +8 -4
  4. data/CHANGELOG.md +47 -0
  5. data/Gemfile +7 -1
  6. data/README.md +21 -11
  7. data/Rakefile +21 -3
  8. data/UPGRADING +7 -0
  9. data/acts-as-taggable-on.gemspec +5 -5
  10. data/{lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb → db/migrate/1_acts_as_taggable_on_migration.rb} +0 -0
  11. data/db/migrate/2_add_missing_unique_indices.rb +21 -0
  12. data/gemfiles/{rails_3.gemfile → rails_3.2.gemfile} +1 -2
  13. data/gemfiles/rails_4.0.gemfile +7 -0
  14. data/gemfiles/rails_4.1.gemfile +7 -0
  15. data/lib/acts-as-taggable-on.rb +9 -13
  16. data/lib/acts_as_taggable_on.rb +6 -0
  17. data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +49 -20
  18. data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +42 -32
  19. data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +1 -1
  20. data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +24 -13
  21. data/lib/acts_as_taggable_on/engine.rb +6 -0
  22. data/lib/acts_as_taggable_on/tag.rb +27 -7
  23. data/lib/acts_as_taggable_on/taggable.rb +6 -6
  24. data/lib/acts_as_taggable_on/tagger.rb +6 -6
  25. data/lib/acts_as_taggable_on/tags_helper.rb +1 -1
  26. data/lib/acts_as_taggable_on/version.rb +1 -1
  27. data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +4 -71
  28. data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +19 -19
  29. data/spec/acts_as_taggable_on/caching_spec.rb +77 -0
  30. data/spec/acts_as_taggable_on/tags_helper_spec.rb +10 -10
  31. data/spec/schema.rb +25 -21
  32. data/spec/spec_helper.rb +9 -25
  33. metadata +40 -56
  34. data/gemfiles/rails_4.gemfile +0 -8
  35. data/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +0 -39
  36. data/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb +0 -22
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Acts As Taggable On" do
4
+
5
+ before(:each) do
6
+ clean_database!
7
+ end
8
+
9
+ describe 'Caching' do
10
+ before(:each) do
11
+ @taggable = CachedModel.new(:name => "Bob Jones")
12
+ @another_taggable = OtherCachedModel.new(:name => "John Smith")
13
+ end
14
+
15
+ it "should add saving of tag lists and cached tag lists to the instance" do
16
+ @taggable.should respond_to(:save_cached_tag_list)
17
+ @another_taggable.should respond_to(:save_cached_tag_list)
18
+
19
+ @taggable.should respond_to(:save_tags)
20
+ end
21
+
22
+ it "should add cached tag lists to the instance if cached column is not present" do
23
+ TaggableModel.new(:name => "Art Kram").should_not respond_to(:save_cached_tag_list)
24
+ end
25
+
26
+ it "should generate a cached column checker for each tag type" do
27
+ CachedModel.should respond_to(:caching_tag_list?)
28
+ OtherCachedModel.should respond_to(:caching_language_list?)
29
+ end
30
+
31
+ it 'should not have cached tags' do
32
+ @taggable.cached_tag_list.should be_blank
33
+ @another_taggable.cached_language_list.should be_blank
34
+ end
35
+
36
+ it 'should cache tags' do
37
+ @taggable.update_attributes(:tag_list => 'awesome, epic')
38
+ @taggable.cached_tag_list.should == 'awesome, epic'
39
+
40
+ @another_taggable.update_attributes(:language_list => 'ruby, .net')
41
+ @another_taggable.cached_language_list.should == 'ruby, .net'
42
+ end
43
+
44
+ it 'should keep the cache' do
45
+ @taggable.update_attributes(:tag_list => 'awesome, epic')
46
+ @taggable = CachedModel.find(@taggable)
47
+ @taggable.save!
48
+ @taggable.cached_tag_list.should == 'awesome, epic'
49
+ end
50
+
51
+ it 'should update the cache' do
52
+ @taggable.update_attributes(:tag_list => 'awesome, epic')
53
+ @taggable.update_attributes(:tag_list => 'awesome')
54
+ @taggable.cached_tag_list.should == 'awesome'
55
+ end
56
+
57
+ it 'should remove the cache' do
58
+ @taggable.update_attributes(:tag_list => 'awesome, epic')
59
+ @taggable.update_attributes(:tag_list => '')
60
+ @taggable.cached_tag_list.should be_blank
61
+ end
62
+
63
+ it 'should have a tag list' do
64
+ @taggable.update_attributes(:tag_list => 'awesome, epic')
65
+ @taggable = CachedModel.find(@taggable.id)
66
+ @taggable.tag_list.sort.should == %w(awesome epic).sort
67
+ end
68
+
69
+ it 'should keep the tag list' do
70
+ @taggable.update_attributes(:tag_list => 'awesome, epic')
71
+ @taggable = CachedModel.find(@taggable.id)
72
+ @taggable.save!
73
+ @taggable.tag_list.sort.should == %w(awesome epic).sort
74
+ end
75
+ end
76
+
77
+ end
@@ -3,40 +3,40 @@ require 'spec_helper'
3
3
  describe ActsAsTaggableOn::TagsHelper do
4
4
  before(:each) do
5
5
  clean_database!
6
-
6
+
7
7
  @bob = TaggableModel.create(:name => "Bob Jones", :language_list => "ruby, php")
8
8
  @tom = TaggableModel.create(:name => "Tom Marley", :language_list => "ruby, java")
9
9
  @eve = TaggableModel.create(:name => "Eve Nodd", :language_list => "ruby, c++")
10
-
10
+
11
11
  @helper = class Helper
12
12
  include ActsAsTaggableOn::TagsHelper
13
13
  end.new
14
14
  end
15
-
16
- it "should yield the proper css classes" do
15
+
16
+ it "should yield the proper css classes" do
17
17
  tags = { }
18
-
18
+
19
19
  @helper.tag_cloud(TaggableModel.tag_counts_on(:languages), ["sucky", "awesome"]) do |tag, css_class|
20
20
  tags[tag.name] = css_class
21
21
  end
22
-
22
+
23
23
  tags["ruby"].should == "awesome"
24
24
  tags["java"].should == "sucky"
25
25
  tags["c++"].should == "sucky"
26
26
  tags["php"].should == "sucky"
27
27
  end
28
-
28
+
29
29
  it "should handle tags with zero counts (build for empty)" do
30
30
  bob = ActsAsTaggableOn::Tag.create(:name => "php")
31
31
  tom = ActsAsTaggableOn::Tag.create(:name => "java")
32
32
  eve = ActsAsTaggableOn::Tag.create(:name => "c++")
33
-
33
+
34
34
  tags = { }
35
-
35
+
36
36
  @helper.tag_cloud(ActsAsTaggableOn::Tag.all, ["sucky", "awesome"]) do |tag, css_class|
37
37
  tags[tag.name] = css_class
38
38
  end
39
-
39
+
40
40
  tags["java"].should == "sucky"
41
41
  tags["c++"].should == "sucky"
42
42
  tags["php"].should == "sucky"
@@ -1,59 +1,63 @@
1
1
  ActiveRecord::Schema.define :version => 0 do
2
- create_table "taggings", :force => true do |t|
3
- t.integer "tag_id", :limit => 11
4
- t.integer "taggable_id", :limit => 11
5
- t.string "taggable_type"
6
- t.string "context"
7
- t.datetime "created_at"
8
- t.integer "tagger_id", :limit => 11
9
- t.string "tagger_type"
2
+ create_table :tags, :force => true do |t|
3
+ t.string :name
10
4
  end
11
5
 
12
- add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
13
- add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
6
+ create_table :taggings, :force => true do |t|
7
+ t.references :tag
14
8
 
15
- create_table "tags", :force => true do |t|
16
- t.string "name"
9
+ # You should make sure that the column created is
10
+ # long enough to store the required class names.
11
+ t.references :taggable, :polymorphic => true
12
+ t.references :tagger, :polymorphic => true
13
+
14
+ # Limit is created to prevent MySQL error on index
15
+ # length for MyISAM table type: http://bit.ly/vgW2Ql
16
+ t.string :context, :limit => 128
17
+
18
+ t.datetime :created_at
17
19
  end
18
-
20
+ # above copied from
21
+ # generators/acts_as_taggable_on/migration/migration_generator
22
+
19
23
  create_table :taggable_models, :force => true do |t|
20
24
  t.column :name, :string
21
25
  t.column :type, :string
22
26
  end
23
-
27
+
24
28
  create_table :non_standard_id_taggable_models, :primary_key => "an_id", :force => true do |t|
25
29
  t.column :name, :string
26
30
  t.column :type, :string
27
31
  end
28
-
32
+
29
33
  create_table :untaggable_models, :force => true do |t|
30
34
  t.column :taggable_model_id, :integer
31
35
  t.column :name, :string
32
36
  end
33
-
37
+
34
38
  create_table :cached_models, :force => true do |t|
35
39
  t.column :name, :string
36
40
  t.column :type, :string
37
41
  t.column :cached_tag_list, :string
38
42
  end
39
-
43
+
40
44
  create_table :other_cached_models, :force => true do |t|
41
45
  t.column :name, :string
42
46
  t.column :type, :string
43
- t.column :cached_language_list, :string
47
+ t.column :cached_language_list, :string
44
48
  t.column :cached_status_list, :string
45
49
  t.column :cached_glass_list, :string
46
50
  end
47
-
51
+
48
52
  create_table :users, :force => true do |t|
49
53
  t.column :name, :string
50
54
  end
51
-
55
+
52
56
  create_table :other_taggable_models, :force => true do |t|
53
57
  t.column :name, :string
54
58
  t.column :type, :string
55
59
  end
56
-
60
+
57
61
  create_table :ordered_taggable_models, :force => true do |t|
58
62
  t.column :name, :string
59
63
  t.column :type, :string
@@ -1,23 +1,7 @@
1
1
  $LOAD_PATH << "." unless $LOAD_PATH.include?(".")
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
3
  require 'logger'
3
4
 
4
- begin
5
- require "rubygems"
6
- require "bundler"
7
-
8
- if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
9
- raise RuntimeError, "Your bundler version is too old." +
10
- "Run `gem install bundler` to upgrade."
11
- end
12
-
13
- # Set up load paths for all bundled gems
14
- Bundler.setup
15
- rescue Bundler::GemNotFound
16
- raise RuntimeError, "Bundler couldn't find some gems." +
17
- "Did you run \`bundlee install\`?"
18
- end
19
-
20
- Bundler.require
21
5
  require File.expand_path('../../lib/acts-as-taggable-on', __FILE__)
22
6
  require 'ammeter/init'
23
7
 
@@ -38,39 +22,39 @@ database_yml = File.expand_path('../database.yml', __FILE__)
38
22
 
39
23
  if File.exists?(database_yml)
40
24
  active_record_configuration = YAML.load_file(database_yml)
41
-
25
+
42
26
  ActiveRecord::Base.configurations = active_record_configuration
43
27
  config = ActiveRecord::Base.configurations[db_name]
44
-
28
+
45
29
  begin
46
30
  ActiveRecord::Base.establish_connection(db_name)
47
31
  ActiveRecord::Base.connection
48
32
  rescue
49
33
  case db_name
50
- when /mysql/
34
+ when /mysql/
51
35
  ActiveRecord::Base.establish_connection(config.merge('database' => nil))
52
36
  ActiveRecord::Base.connection.create_database(config['database'], {:charset => 'utf8', :collation => 'utf8_unicode_ci'})
53
37
  when 'postgresql'
54
38
  ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
55
39
  ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
56
40
  end
57
-
41
+
58
42
  ActiveRecord::Base.establish_connection(config)
59
43
  end
60
-
44
+
61
45
  logger = ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
62
46
  ActiveRecord::Base.default_timezone = :utc
63
-
47
+
64
48
  begin
65
49
  old_logger_level, logger.level = logger.level, ::Logger::ERROR
66
50
  ActiveRecord::Migration.verbose = false
67
-
51
+
68
52
  load(File.dirname(__FILE__) + '/schema.rb')
69
53
  load(File.dirname(__FILE__) + '/models.rb')
70
54
  ensure
71
55
  logger.level = old_logger_level
72
56
  end
73
-
57
+
74
58
  else
75
59
  raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
76
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2014-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -32,35 +32,35 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5'
34
34
  - !ruby/object:Gem::Dependency
35
- name: rspec-rails
35
+ name: sqlite3
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.13.0
40
+ version: '0'
41
41
  type: :development
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 2.13.0
47
+ version: '0'
48
48
  - !ruby/object:Gem::Dependency
49
- name: rspec
49
+ name: mysql2
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '2.6'
54
+ version: 0.3.7
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '2.6'
61
+ version: 0.3.7
62
62
  - !ruby/object:Gem::Dependency
63
- name: ammeter
63
+ name: pg
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '>='
@@ -74,63 +74,35 @@ dependencies:
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  - !ruby/object:Gem::Dependency
77
- name: sqlite3
77
+ name: rspec-rails
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.13.0
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 2.13.0
90
90
  - !ruby/object:Gem::Dependency
91
- name: mysql2
91
+ name: rspec
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 0.3.7
96
+ version: '2.6'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: 0.3.7
104
- - !ruby/object:Gem::Dependency
105
- name: pg
106
- requirement: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- type: :development
112
- prerelease: false
113
- version_requirements: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- - !ruby/object:Gem::Dependency
119
- name: guard
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- type: :development
126
- prerelease: false
127
- version_requirements: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
103
+ version: '2.6'
132
104
  - !ruby/object:Gem::Dependency
133
- name: guard-rspec
105
+ name: ammeter
134
106
  requirement: !ruby/object:Gem::Requirement
135
107
  requirements:
136
108
  - - '>='
@@ -156,15 +128,21 @@ files:
156
128
  - .rspec
157
129
  - .travis.yml
158
130
  - Appraisals
131
+ - CHANGELOG.md
159
132
  - Gemfile
160
133
  - Guardfile
161
134
  - LICENSE.md
162
135
  - README.md
163
136
  - Rakefile
137
+ - UPGRADING
164
138
  - acts-as-taggable-on.gemspec
165
- - gemfiles/rails_3.gemfile
166
- - gemfiles/rails_4.gemfile
139
+ - db/migrate/1_acts_as_taggable_on_migration.rb
140
+ - db/migrate/2_add_missing_unique_indices.rb
141
+ - gemfiles/rails_3.2.gemfile
142
+ - gemfiles/rails_4.0.gemfile
143
+ - gemfiles/rails_4.1.gemfile
167
144
  - lib/acts-as-taggable-on.rb
145
+ - lib/acts_as_taggable_on.rb
168
146
  - lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
169
147
  - lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
170
148
  - lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb
@@ -172,6 +150,7 @@ files:
172
150
  - lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
173
151
  - lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
174
152
  - lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
153
+ - lib/acts_as_taggable_on/engine.rb
175
154
  - lib/acts_as_taggable_on/tag.rb
176
155
  - lib/acts_as_taggable_on/tag_list.rb
177
156
  - lib/acts_as_taggable_on/taggable.rb
@@ -180,10 +159,9 @@ files:
180
159
  - lib/acts_as_taggable_on/tags_helper.rb
181
160
  - lib/acts_as_taggable_on/utils.rb
182
161
  - lib/acts_as_taggable_on/version.rb
183
- - lib/generators/acts_as_taggable_on/migration/migration_generator.rb
184
- - lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
185
162
  - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
186
163
  - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
164
+ - spec/acts_as_taggable_on/caching_spec.rb
187
165
  - spec/acts_as_taggable_on/related_spec.rb
188
166
  - spec/acts_as_taggable_on/single_table_inheritance_spec.rb
189
167
  - spec/acts_as_taggable_on/tag_list_spec.rb
@@ -195,7 +173,6 @@ files:
195
173
  - spec/acts_as_taggable_on/utils_spec.rb
196
174
  - spec/bm.rb
197
175
  - spec/database.yml.sample
198
- - spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb
199
176
  - spec/models.rb
200
177
  - spec/schema.rb
201
178
  - spec/spec_helper.rb
@@ -203,7 +180,14 @@ homepage: https://github.com/mbleigh/acts-as-taggable-on
203
180
  licenses:
204
181
  - MIT
205
182
  metadata: {}
206
- post_install_message:
183
+ post_install_message: |
184
+ When upgrading
185
+
186
+ Re-run the migrations generator
187
+
188
+ rake railties:install:migrations FROM=acts_as_taggable_on_engine db:migrate
189
+
190
+ It will create any new migrations and skip existing ones
207
191
  rdoc_options: []
208
192
  require_paths:
209
193
  - lib
@@ -219,13 +203,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
203
  version: '0'
220
204
  requirements: []
221
205
  rubyforge_project:
222
- rubygems_version: 2.0.0
206
+ rubygems_version: 2.1.11
223
207
  signing_key:
224
208
  specification_version: 4
225
209
  summary: Advanced tagging for Rails.
226
210
  test_files:
227
211
  - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
228
212
  - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
213
+ - spec/acts_as_taggable_on/caching_spec.rb
229
214
  - spec/acts_as_taggable_on/related_spec.rb
230
215
  - spec/acts_as_taggable_on/single_table_inheritance_spec.rb
231
216
  - spec/acts_as_taggable_on/tag_list_spec.rb
@@ -237,7 +222,6 @@ test_files:
237
222
  - spec/acts_as_taggable_on/utils_spec.rb
238
223
  - spec/bm.rb
239
224
  - spec/database.yml.sample
240
- - spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb
241
225
  - spec/models.rb
242
226
  - spec/schema.rb
243
227
  - spec/spec_helper.rb