Permalink
Browse files

Caching fails for a given tagging context that ends with an 's' when …

…singular (ex. 'status')
  • Loading branch information...
jeffreyiacono committed Aug 21, 2011
1 parent 4df3f37 commit ade541b5893a57034a465b3f49a3518da399a5fc
Showing with 67 additions and 4 deletions.
  1. +62 −1 spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
  2. +2 −2 spec/models.rb
  3. +3 −1 spec/schema.rb
@@ -208,7 +208,7 @@
}.should_not raise_error
end
end
-
+
describe 'Caching' do
before(:each) do
@taggable = CachedModel.new(:name => "Bob Jones")
@@ -277,6 +277,67 @@
end
end
+ # note: ActsAsTaggableOn::Core#tag_list_cache_on is passed a context that is
+ # singular via ActsAsTaggableOn::Cache#save_cached_tag_list, which
+ # then calls singularize again on the context.
+ #
+ # ActiveSupport::Inflector#singularize, not knowing any better, will
+ # re-signularize an already singularized string, so:
+ # "status".singularize => "statu"
+ #
+ # see: https://github.com/rails/rails/issues/2608
+ #
+ # This causes a bad instance variable to be set (@status_list vs
+ # @statu_list to continue with the above example) and a cached column
+ # will be set to ""
+ #
+ # Thus, any tagging context that ends w/ "s" when singular will not
+ # cache properly
+ context 'when tagging context ends in an "s" when singular (ex. "status", "glass", etc.)' do
+ describe 'caching' do
+ before { @taggable = OtherCachedModel.new(:name => "John Smith") }
+ subject { @taggable }
+
+ it { should respond_to(:save_cached_tag_list) }
+ its(:cached_language_list) { should be_blank }
+ its(:cached_status_list) { should be_blank }
+ its(:cached_glass_list) { should be_blank }
+
+ context 'language taggings cache after update' do
+ before { @taggable.update_attributes(:language_list => 'ruby, .net') }
+ subject { @taggable }
+
+ its(:language_list) { should == ['ruby', '.net']}
+ its(:cached_language_list) { should == 'ruby, .net' } # passes
+ its(:instance_variables) { should include('@language_list') }
+ end
+
+ context 'status taggings cache after update' do
+ before { @taggable.update_attributes(:status_list => 'happy, married') }
+ subject { @taggable }
+
+ its(:status_list) { should == ['happy', 'married'] }
+ its(:cached_status_list) { should == 'happy, married' } # fails
+ its(:cached_status_list) { should_not == '' } # fails, is blank
+ its(:instance_variables) { should include('@status_list') }
+ its(:instance_variables) { should_not include('@statu_list') } # fails, note: one "s"
+ end
+
+ context 'glass taggings cache after update' do
+ before do
+ @taggable.update_attributes(:glass_list => 'rectangle, aviator')
+ end
+
+ subject { @taggable }
+ its(:glass_list) { should == ['rectangle', 'aviator'] }
+ its(:cached_glass_list) { should == 'rectangle, aviator' } # fails
+ its(:cached_glass_list) { should_not == '' } # fails, is blank
+ its(:instance_variables) { should include('@glass_list') }
+ its(:instance_variables) { should_not include('@glas_list') } # fails, note: one "s"
+ end
+ end
+ end
+
describe "taggings" do
before(:each) do
@taggable = TaggableModel.new(:name => "Art Kram")
View
@@ -11,7 +11,7 @@ class CachedModel < ActiveRecord::Base
end
class OtherCachedModel < ActiveRecord::Base
- acts_as_taggable_on :languages
+ acts_as_taggable_on :languages, :statuses, :glasses
end
class OtherTaggableModel < ActiveRecord::Base
@@ -32,4 +32,4 @@ class TaggableUser < ActiveRecord::Base
class UntaggableModel < ActiveRecord::Base
belongs_to :taggable_model
-end
+end
View
@@ -35,7 +35,9 @@
create_table :other_cached_models, :force => true do |t|
t.column :name, :string
t.column :type, :string
- t.column :cached_language_list, :string
+ t.column :cached_language_list, :string
+ t.column :cached_status_list, :string
+ t.column :cached_glass_list, :string
end
create_table :taggable_users, :force => true do |t|

0 comments on commit ade541b

Please sign in to comment.