-
-
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 index_errors association matcher #1089
Add index_errors association matcher #1089
Conversation
end | ||
|
||
message = 'Expected Parent to have a has_many association called children (children should have index_errors set to true)' | ||
expect { |
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.
has_many :children, autosave: false | ||
end | ||
|
||
message = 'Expected Parent to have a has_many association called children (children should have index_errors set to true)' |
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. [130/80]
expect(Parent.new).to have_many(:children).index_errors(true) | ||
end | ||
|
||
it 'rejects an association with a non-matching :index_errors option and returns the correct message' 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. [109/80]
if option_verifier.correct_for_boolean?(:index_errors, options[:index_errors]) | ||
true | ||
else | ||
@missing = "#{name} should have index_errors set to #{options[:index_errors]}" |
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. [92/80]
@@ -1257,6 +1281,19 @@ def autosave_correct? | |||
end | |||
end | |||
|
|||
def index_errors_correct? | |||
if options.key?(:index_errors) | |||
if option_verifier.correct_for_boolean?(:index_errors, options[:index_errors]) |
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. [90/80]
@@ -524,6 +524,24 @@ def belong_to(name) | |||
# should have_many(:games).autosave(true) | |||
# end | |||
# | |||
# ##### index_errors | |||
# | |||
# Use `index_errors` to assert that the `:index_errors` option was specified. |
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]
def index_errors_correct? | ||
if options.key?(:index_errors) | ||
if option_verifier.correct_for_boolean?(:index_errors, | ||
options[:index_errors]) |
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 one level of indentation for parameters following the first line of a multi-line method call.
@@ -1257,6 +1282,21 @@ def autosave_correct? | |||
end | |||
end | |||
|
|||
def index_errors_correct? |
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. [12/10]
def index_errors_correct? | ||
if options.key?(:index_errors) | ||
if option_verifier.correct_for_boolean?( | ||
:index_errors, options[:index_errors] |
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 one level of indentation for parameters following the first line of a multi-line method call.
Indent the first parameter one step more than the start of the previous line.
@@ -1257,6 +1282,22 @@ def autosave_correct? | |||
end | |||
end | |||
|
|||
def index_errors_correct? |
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. [13/10]
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.
This is down to 10 lines now 🙂
f8abd89
to
4d1fbae
Compare
I've never seen the |
You can use it with a # Old style
guitar.errors["tuning_pegs.pitch"] = ["is not a number"]
# New style (if defined globally, or set in has_many_relationship)
guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"] The Rails PR is here, and it's in the changelog, but it hasn't made it into the Rails docs yet for some reason 🤷♂️ |
Oh very interesting, okay. Thanks for the clarification! |
Thanks! I've tweaked this a bit for style and merged this as 795ca68. |
Hello! Our team was adding
index_errors
to a couplehas_many
associations and we noticed that there's no matcher for that yet. It looked pretty similar toautosave
since it's just a boolean, so I pretty much copied that 😄