I have a has_many / belongs_to polymorphic relationship between two models, PointModifier and ManualPoints.
# ManualPoints Model
has_many :point_modifiers, as: :modifier
# PointModifier Model
belongs_to :modifier, polymorphic: true
I recently started seeing this error in my tests - NameError: wrong constant name - after adding ActiveModel::Serializer into my project. It does not appear to be related to AMS, and I've never seen this error before.
A little sleuthing revealed that this error appears to be related to constants.
http://ruby-doc.org/core-1.9.3/NameError.html
Some more digging and I realized that the issue was related to my fixtures.
# PointModifiers Fixture
one:
points: 2
user_id: 1
modifier_type: manual_points
modifier_id: 1
The issue was that I had incorrectly used snake_case for the polymorphic relationship in the fixture. The solution is to use CamelCase, like this:
# PointModifiers Fixture
one:
points: 2
user_id: 1
modifier_type: ManualPoints
modifier_id: 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With