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 enum attribute name verification #641

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/shoulda/matchers/active_record/define_enum_for_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,12 @@ def expected_enum_values
hashify(options[:expected_enum_values]).with_indifferent_access
end

def enum_method
attribute_name.to_s.pluralize
end

def actual_enum_values
model.class.send(enum_method)
model.class.send(attribute_name.to_s.pluralize)
end

def enum_defined?
model.class.respond_to?(enum_method)
model.defined_enums.keys.include?(attribute_name.to_s)
end

def enum_values_match?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

describe Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher, type: :model do
if active_record_supports_enum?
it "rejects a record when checking for enum's plural attribute name" do
message = "Expected #{record_with_array_values.class} to define :#{enum_attribute.to_s.pluralize} as an enum"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [115/80]


expect do
expect(record_with_array_values).to define_enum_for(enum_attribute.to_s.pluralize)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]

end.to fail_with_message(message)
end

describe "with only the attribute name specified" do
it "accepts a record where the attribute is defined as an enum" do
expect(record_with_array_values).to define_enum_for(enum_attribute)
Expand Down