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

undefined method `macro' for nil:NilClass #3

Open
SteveRedka opened this issue Sep 28, 2018 · 2 comments
Open

undefined method `macro' for nil:NilClass #3

SteveRedka opened this issue Sep 28, 2018 · 2 comments

Comments

@SteveRedka
Copy link

Ruby: 2.4.1
Rails: 5.2.1

Error:

An error occurred while loading ./spec/models/post_spec.rb.
Failure/Error: persistize :average_rating, depending_on: :ratings

NoMethodError:
  undefined method `macro' for nil:NilClass
# /home/how/.rvm/gems/ruby-2.4.1/gems/persistize-0.2.0/lib/persistize.rb:52:in `generate_callback'
# /home/how/.rvm/gems/ruby-2.4.1/gems/persistize-0.2.0/lib/persistize.rb:41:in `block (2 levels) in persistize'
# /home/how/.rvm/gems/ruby-2.4.1/gems/persistize-0.2.0/lib/persistize.rb:40:in `each'
# /home/how/.rvm/gems/ruby-2.4.1/gems/persistize-0.2.0/lib/persistize.rb:40:in `block in persistize'
# /home/how/.rvm/gems/ruby-2.4.1/gems/persistize-0.2.0/lib/persistize.rb:6:in `each'
# /home/how/.rvm/gems/ruby-2.4.1/gems/persistize-0.2.0/lib/persistize.rb:6:in `persistize'
# ./app/models/post.rb:12:in `<class:Post>'
# ./app/models/post.rb:1:in `<main>'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:46:in `block in require_or_load'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:45:in `require_or_load'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `block in load_missing_constant'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
# /home/how/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
# ./spec/models/post_spec.rb:3:in `<top (required)>'

Finished in 0.11779 seconds (files took 4.51 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

I made a branch in my repository where this error happens:

https://github.com/SteveRedka/umbrellio_forum/tree/persistize

@morellan
Copy link

Could you post your model's definition?, it looks like the association is incorrect

@Kukunin
Copy link

Kukunin commented Oct 27, 2018

Got the same error on Rails 4.2.10. The problem is that my model reflections have string keys:

RSS::Post.reflections
=> {"post"=>
  #<ActiveRecord::Reflection::BelongsToReflection:0x007f90eeab6cc0
   @active_record=RSS::Post (call 'RSS::Post.connection' to establish a connection),
   @association_scope_cache={},
   @automatic_inverse_of=nil,
   @constructable=true,
   @foreign_type="post_type",
   @klass=nil,
   @name=:post,
   @options={:class_name=>"::Post"},
   @plural_name="posts",
   @scope=nil,
   @scope_lock=#<Thread::Mutex:0x007f90eeab6270>,
   @type=nil>,
 "rss_feed"=>
  #<ActiveRecord::Reflection::BelongsToReflection:0x007f90ef356880
   @active_record=RSS::Post (call 'RSS::Post.connection' to establish a connection),
   @association_scope_cache={},
   @automatic_inverse_of=nil,
   @constructable=true,
   @foreign_type="rss_feed_type",
   @klass=nil,
   @name=:rss_feed,
   @options={:class_name=>"RSS::Feed", :inverse_of=>:rss_posts},
   @plural_name="rss_feeds",
   @scope=nil,
   @scope_lock=#<Thread::Mutex:0x007f90ef355908>,
   @type=nil>,

so

    persistize :publisher_id, depending_on: 'rss_feed'

works. But there is another error then:

NoMethodError: undefined method `primary_key_name' for #<ActiveRecord::Reflection::BelongsToReflection:0x007f90fc5bfb78>
Did you mean?  primary_key_value
               primary_key_type
from /Users/kukunin/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/persistize-0.2.0/lib/persistize.rb:91:in `generate_belongs_to_callback'

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

No branches or pull requests

3 participants