-
-
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
Closed
brendanthomas1
wants to merge
4
commits into
thoughtbot:master
from
brendanthomas1:add-index-errors-association-matcher
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,6 +524,25 @@ 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. | ||
# | ||
# class Player < ActiveRecord::Base | ||
# has_many :games, index_errors: true | ||
# end | ||
# | ||
# # RSpec | ||
# RSpec.describe Player, type: :model do | ||
# it { should have_many(:games).index_errors(true) } | ||
# end | ||
# | ||
# # Minitest (Shoulda) | ||
# class PlayerTest < ActiveSupport::TestCase | ||
# should have_many(:games).index_errors(true) | ||
# end | ||
# | ||
# ##### inverse_of | ||
# | ||
# Use `inverse_of` to assert that the `:inverse_of` option was specified. | ||
|
@@ -1022,6 +1041,11 @@ def autosave(autosave) | |
self | ||
end | ||
|
||
def index_errors(index_errors) | ||
@options[:index_errors] = index_errors | ||
self | ||
end | ||
|
||
def class_name(class_name) | ||
@options[:class_name] = class_name | ||
self | ||
|
@@ -1096,6 +1120,7 @@ def matches?(subject) | |
class_name_correct? && | ||
join_table_correct? && | ||
autosave_correct? && | ||
index_errors_correct? && | ||
conditions_correct? && | ||
validate_correct? && | ||
touch_correct? && | ||
|
@@ -1257,6 +1282,20 @@ def autosave_correct? | |
end | ||
end | ||
|
||
def index_errors_correct? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This is down to 10 lines now 🙂 |
||
return true unless options.key?(:index_errors) | ||
|
||
if option_verifier.correct_for_boolean?( | ||
:index_errors, options[:index_errors] | ||
) | ||
true | ||
else | ||
@missing = "#{name} should have index_errors set to "\ | ||
"#{options[:index_errors]}" | ||
false | ||
end | ||
end | ||
|
||
def conditions_correct? | ||
if options.key?(:conditions) | ||
if option_verifier.correct_for_relation_clause?(:conditions, options[:conditions]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,9 @@ def rails_gte_4_2? | |
def rails_lt_5? | ||
rails_version < 5 | ||
end | ||
|
||
def rails_5_x? | ||
rails_version =~ '~> 5.0' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]