-
-
Notifications
You must be signed in to change notification settings - Fork 909
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
Add prefix and suffix to define enum for #1077
Conversation
end | ||
|
||
def record_with_array_values(column_type: :integer) | ||
def record_with_array_values( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid parameter lists longer than 5 parameters. [6/5]
end | ||
end | ||
|
||
context 'if the attribute was defined with the same prefix and suffix' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [83/80]
end | ||
|
||
message = <<-MESSAGE | ||
Expected Example to define :attr as an enum, backed by an integer, using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a heredoc by using <<~ instead of <<-.
with_suffix(:whatever) | ||
end | ||
|
||
message = <<-MESSAGE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation detected.
end | ||
|
||
message = <<-MESSAGE | ||
Expected Example to define :attr as an enum, backed by an integer, using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a heredoc by using <<~ instead of <<-.
values: ['open', 'closed'], | ||
) | ||
message = <<-MESSAGE | ||
Expected Example to define :attr as an enum, backed by a string, with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a heredoc by using <<~ instead of <<-.
column_type: :integer, | ||
) | ||
message = <<-MESSAGE | ||
Expected Example to define :attr as an enum, backed by a string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a heredoc by using <<~ instead of <<-.
attribute_name: :attr, | ||
) | ||
message = <<-MESSAGE | ||
Expected Example to define :non_existent as an enum, backed by an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a heredoc by using <<~ instead of <<-.
values: { active: 0, archived: 1 }, | ||
) | ||
message = <<-MESSAGE | ||
Expected Example to define :attr as an enum, backed by an integer, with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 spaces for indentation in a heredoc by using <<~ instead of <<-.
end | ||
|
||
it "accepts a record where the attribute is defined as an enum but the enum values do not match" do | ||
message = %{Expected #{record_with_hash_values.class} to define :#{enum_attribute} as an enum with {:active=>5, :archived=>10} and store the value in a column of type integer} | ||
it 'rejects a record where the attribute is defined as an enum but the enum values do not match' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [107/80]
4221597
to
a6739e0
Compare
end | ||
|
||
def record_with_hash_values | ||
def build_record( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid parameter lists longer than 5 parameters. [6/5]
end | ||
|
||
def non_enum_attribute | ||
:condition | ||
def build_record_with_array_values( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid parameter lists longer than 5 parameters. [6/5]
c8b3c7a
to
457d306
Compare
) | ||
model.enum(enum_attribute => ['published', 'unpublished', 'draft']) | ||
model.new | ||
def build_record_with_enum_attribute( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid parameter lists longer than 5 parameters. [6/5]
def enum_attribute | ||
:status | ||
end | ||
def build_record_with_array_values( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid parameter lists longer than 5 parameters. [6/5]
end | ||
end | ||
|
||
context 'if the attribute was defined with the same prefix and suffix' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
|
||
message = "Expected #{model} to define :statuses as an enum and store the value in a column of type integer" | ||
context 'if a method to hold enum values exists on the model but was not created via the enum macro' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [105/80]
def self.inspect_hash(hash) | ||
output = '‹{' | ||
|
||
output << hash.map { |key, value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using {...} for multi-line blocks.
def hashify(value) | ||
if value.nil? | ||
return {} | ||
def enum_value_methods_exist? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [19/10]
Perceived complexity for enum_value_methods_exist? is too high. [8/7]
|
||
description << ' a suffix of ' | ||
|
||
description << "#{options[:expected_suffix].inspect}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to_s over string interpolation.
end | ||
|
||
if options[:expected_suffix] | ||
if options[:expected_prefix] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the return of the conditional for variable assignment and comparison.
|
||
if options[:expected_prefix] | ||
description << ', using a prefix of ' | ||
description << "#{options[:expected_prefix].inspect}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to_s over string interpolation.
end | ||
|
||
def with(expected_enum_values) | ||
def description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for description is too high. [28.3/15]
Method has too many lines. [22/10]
d7c36c5
to
9e1680d
Compare
|
||
expect(model.new).to allow_value(1).for(:status) | ||
context 'given an ActiveRecord model' do | ||
context 'where the attribute under test is an enum and the given value is a value in that enum' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [102/80]
9e1680d
to
8669078
Compare
it 'rejects with an appropriate failure message' do | ||
record = build_record_validating_scoped_uniqueness_with_enum( | ||
enum_scope: :scope1, | ||
additional_scopes: [:scope2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last parameter of a multiline method call.
enum_scope: :scope | ||
enum_scope: :scope1, | ||
additional_scopes: [:scope2], | ||
additional_attributes: [:other] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last parameter of a multiline method call.
context 'when one of the scoped attributes is an enum' do | ||
it 'accepts' do | ||
record = build_record_validating_scoped_uniqueness_with_enum( | ||
enum_scope: :scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last parameter of a multiline method call.
8669078
to
8c0e13d
Compare
* Break up long test names into contexts * Make tests more isolated by reducing "global" scope (always use keyword argument to specify attribute name instead of a "global" method) * Simplify how failure messages are tested by removing interpolation in favor of explicitness
The `enum` macro was introduced in Rails 4.1, which shoulda-matchers no longer supports, so we can always assume that enum is available.
We'll need to introduce some other `with_*` qualifiers and it won't look right to have one qualifier called `with` and other qualifiers called `with_something_else`.
8c0e13d
to
386a773
Compare
If a subtest fails, explain why. We're going to be adding another subtest later, and so without this extra information, users will most definitely be confused.
In Rails 5, the `enum` macro received two new options: `_prefix` and `_suffix`. These options change the names of the methods that are generated from the given enum values. This commit adds qualifiers to the `define_enum_for` matcher so that they can be tested.
386a773
to
147ac48
Compare
In Rails 5, the
enum
macro received two new options:_prefix
and_suffix
. These options change the names of the methods that aregenerated from the given enum values. This commit adds qualifiers to the
define_enum_for
matcher so that they can be tested.Closes #961.