You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to how the code on https://github.com/thoughtbot/shoulda-matchers/blob/c934d7534520d90cf9d17f0cd1745bf95d38cf41/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb#L234 is implemented, if you have a enum which is not backed by a column in your database you'll get an error when trying to run the test.
I've ran into this when creating a enum to match a field I added to my query through SQL only, which in teory is not saved on my database.
To reproduce simply create a enum that has no field on the database with the same name, and you'll get the error.
# frozen_string_literal: true
class Car < ApplicationRecord
enum label: { perfect_match: 0, good_match: 1 }
end
describe Car do
it { is_expected.to define_enum_for :label }
end
1) Car is expected to define :label as an enum backed by an integer
Failure/Error: it { is_expected.to define_enum_for :label }
NoMethodError:
undefined method `type' for nil:NilClass
# /usr/local/bundle/gems/shoulda-matchers-5.0.0/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb:363:in `column_type_matches?'
# /usr/local/bundle/gems/shoulda-matchers-5.0.0/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb:234:in `matches?'
# ./spec/models/car_spec.rb:3:in `block (2 levels) in <main>'
I personally believew the type of the enum should only be checked if backed_by_column_of_type is called.
The text was updated successfully, but these errors were encountered:
Due to how the code on
https://github.com/thoughtbot/shoulda-matchers/blob/c934d7534520d90cf9d17f0cd1745bf95d38cf41/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb#L234
is implemented, if you have a enum which is not backed by a column in your database you'll get an error when trying to run the test.I've ran into this when creating a enum to match a field I added to my query through SQL only, which in teory is not saved on my database.
To reproduce simply create a enum that has no field on the database with the same name, and you'll get the error.
I personally believew the type of the enum should only be checked if
backed_by_column_of_type
is called.The text was updated successfully, but these errors were encountered: