1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model/errors.rb
2014-06-20 16:41:27 -06:00

52 lines
1.3 KiB
Ruby

module Shoulda
module Matchers
module ActiveModel
# @private
class CouldNotDetermineValueOutsideOfArray < RuntimeError; end
# @private
class NonNullableBooleanError < Shoulda::Matchers::Error
def self.create(attribute)
super(attribute: attribute)
end
attr_accessor :attribute
def message
<<-EOT.strip
You have specified that your model's #{attribute} should ensure inclusion of nil.
However, #{attribute} is a boolean column which does not allow null values.
Hence, this test will fail and there is no way to make it pass.
EOT
end
end
# @private
class CouldNotSetPasswordError < Shoulda::Matchers::Error
def self.create(model)
super(model: model)
end
attr_accessor :model
def message
<<-EOT.strip
The validation failed because your #{model_name} model declares `has_secure_password`, and
`validate_presence_of` was called on a #{record_name} which has `password` already set to a value.
Please use a #{record_name} with an empty `password` instead.
EOT
end
private
def model_name
model.name
end
def record_name
model_name.humanize.downcase
end
end
end
end
end