Skip to content

Commit

Permalink
only run specs for >= rails 5
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanthomas1 committed Mar 9, 2018
1 parent 0ab8115 commit f8abd89
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
5 changes: 3 additions & 2 deletions lib/shoulda/matchers/active_record/association_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,9 @@ def autosave_correct?

def index_errors_correct?
if options.key?(:index_errors)
if option_verifier.correct_for_boolean?(:index_errors,
options[:index_errors])
if option_verifier.correct_for_boolean?(
:index_errors, options[:index_errors]
)
true
else
@missing = "#{name} should have index_errors set to "\
Expand Down
4 changes: 4 additions & 0 deletions spec/support/unit/helpers/rails_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -801,27 +801,29 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {})
}.to fail_with_message(message)
end

context 'index_errors' do
it 'accepts an association with a matching :index_errors option' do
define_model :child, parent_id: :integer
define_model :parent do
has_many :children, index_errors: true
if rails_5_x?
context 'index_errors' do
it 'accepts an association with a matching :index_errors option' do
define_model :child, parent_id: :integer
define_model :parent do
has_many :children, index_errors: true
end
expect(Parent.new).to have_many(:children).index_errors(true)
end
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
define_model :child, parent_id: :integer
define_model :parent do
has_many :children, autosave: false
end
it 'rejects an association with a non-matching :index_errors option '\
'and returns the correct message' do
define_model :child, parent_id: :integer
define_model :parent do
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)'
expect do
expect(Parent.new).to have_many(:children).index_errors(true)
end.to fail_with_message(message)
message = 'Expected Parent to have a has_many association called '\
'children (children should have index_errors set to true)'
expect do
expect(Parent.new).to have_many(:children).index_errors(true)
end.to fail_with_message(message)
end
end
end

Expand Down

0 comments on commit f8abd89

Please sign in to comment.