Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix caching_tag_list_on? bug (#432) #806

Merged
merged 3 commits into from
May 3, 2017

Conversation

ProGM
Copy link
Contributor

@ProGM ProGM commented Feb 20, 2017

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:

NoMethodError: undefined method `caching_tag_list_on?' for #<Class:0x007ff6aabcbb98>

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 throws NoMethodError.

Instead, calling ModelName.columns before this call, it generates no error.

This is because the ModelName.columns injects the ActsAsTaggableOn::Taggable::Cache::InstanceMethods in runtime.

Check out here:

_add_tags_caching_methods if _has_tags_cache_columns?(db_columns)

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 ;)

@rbritom
Copy link
Contributor

rbritom commented May 2, 2017

LGTM @seuros

@seuros seuros merged commit 0590d4b into mbleigh:master May 3, 2017
@ProGM ProGM deleted the fix-caching-tag-list-on-bug branch May 5, 2017 10:25
@ProGM ProGM restored the fix-caching-tag-list-on-bug branch May 5, 2017 10:25
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this pull request Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined method `caching_tag_list_on?'
3 participants