Fix caching_tag_list_on?
bug (#432)
#806
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #432
Description:
On Rails 5 (I can't test on other environments right now), if you try to access to a cached tag list before the model as initialized for the first time, it fails with:
How to replicate:
You need a table with an existing record with a
cached_tag_list
column, populated with a non-null value.Running
ModelName.first.tag_list
-> it throwsNoMethodError
.Instead, calling
ModelName.columns
before this call, it generates no error.This is because the
ModelName.columns
injects theActsAsTaggableOn::Taggable::Cache::InstanceMethods
in runtime.Check out here:
acts-as-taggable-on/lib/acts_as_taggable_on/taggable/cache.rb
Line 38 in 8e64c3d
If you run it manually or initialize a new model (i.e.
ModelName.new
), it gets injected normally.I added a spec to demonstrate the bug and a possible fix.
Let me know if it can be useful ;)