Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112018-03-07T17:35:06ZRuby Issue Tracking System
Redmine Ruby master - Bug #14583 (Closed): #method() is reporting the wrong self in exceptionhttps://bugs.ruby-lang.org/issues/145832018-03-07T17:35:06Zkrainboltgreene (Kurtis Rainbolt-Greene)kurtis@rainbolt-greene.online
<p>This is hard to explain but I'll do my best:</p>
<p>When running an rspec test I get this exception:</p>
<pre><code> Failure/Error: resource_class.write_attributes_via_call(model, attributes.select(&resource.method(:valid_attribute?)))
NameError:
undefined method `valid_attribute?' for class `PhotoRealizer'
Did you mean? alias_attribute
</code></pre>
<p>This is unequivocally wrong, so I go to prove it:</p>
<pre><code> 13: def call
14: resource.model.tap do |model|
15: resource_class.write_attributes_via_call(model, {id: id}) if id
=> 16: binding.pry
17: resource_class.write_attributes_via_call(model, attributes.select(&resource.method(:valid_attribute?)))
18: resource_class.write_attributes_via_call(model, relationships.select(&resource.method(:valid_relationship?)).transform_values(&resource.method(:as_relationship)))
19: resource_class.save_via_call(model)
20: end
21: end
[1] pry(#<JSONAPI::Realizer::Action::Create>)> resource
=> #<PhotoRealizer:0x00007fa16d608c98 @model=#<Photo:0x00007fa16d608d38 @id="550e8400-e29b-41d4-a716-446655440000">>
[2] pry(#<JSONAPI::Realizer::Action::Create>)> resource.class
=> PhotoRealizer
[3] pry(#<JSONAPI::Realizer::Action::Create>)> resource.class.valid_attribute?
ArgumentError: wrong number of arguments (given 0, expected 2)
</code></pre>
<p>Turns out however, that I'm being silly and calling <code>method()</code> on an instance, so I exit out of my pry:</p>
<pre><code> Failure/Error: resource_class.write_attributes_via_call(model, attributes.select(&resource.method(:valid_attribute?)))
NameError:
undefined method `valid_attribute?' for class `#<Class:#<PhotoRealizer:0x00007fa16d608c98>>'
Did you mean? alias_attribute
</code></pre>
<p>Wait, what? How could this be? A different error now that I've observed?</p>