Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Generate message #56

Closed
wants to merge 2 commits into from

3 participants

@t3hpr1m3

I probably should have mentioned this in the pull request as well, but in #49, I pointed out that the tests I would write were already written in clemenshelm@662b674cf4e67c0af428c694a46e4a9d2060cb7f. Not sure what to do at this point.

@jferris
Admin

If you want to merge his tests into your pull request and fix them so that they don't create a global method or mix shoulda's modules into Kernel, I'll take a look.

@jferris jferris closed this
@t3hpr1m3

Understood. I'll get to work.

@gabebw
Admin

@t3hpr1m3: Any progress with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 lib/shoulda/matchers/active_model/allow_value_matcher.rb
@@ -36,10 +36,10 @@ def with_message(message)
def matches?(instance)
@instance = instance
+ @instance.send("#{@attribute}=", @value)
if Symbol === @expected_message
- @expected_message = default_error_message(@expected_message, :model_name => @instance.class.to_s.underscore, :attribute => @attribute)
+ @expected_message = default_error_message(@expected_message, :attribute => @attribute)
end
- @instance.send("#{@attribute}=", @value)
!errors_match?
end
View
2  lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb
@@ -96,11 +96,13 @@ def matches?(subject)
def translate_messages!
if Symbol === @short_message
@short_message = default_error_message(@short_message,
+ :attribute => @attribute,
:count => @minimum)
end
if Symbol === @long_message
@long_message = default_error_message(@long_message,
+ :attribute => @attribute,
:count => @maximum)
end
end
View
10 lib/shoulda/matchers/active_model/helpers.rb
@@ -16,17 +16,11 @@ def pretty_error_messages(obj) # :nodoc:
# default_error_message(:blank)
# default_error_message(:too_short, :count => 5)
# default_error_message(:too_long, :count => 60)
- # default_error_message(:blank, :model_name => 'user', :attribute => 'name')
+ # default_error_message(:blank, :attribute => 'name')
def default_error_message(key, options = {})
- model_name = options.delete(:model_name)
attribute = options.delete(:attribute)
if Object.const_defined?(:I18n) # Rails >= 2.2
- I18n.translate( :"activerecord.errors.models.#{model_name}.attributes.#{attribute}.#{key}", {
- :default => [ :"activerecord.errors.models.#{model_name}.#{key}",
- :"activerecord.errors.messages.#{key}",
- :"errors.attributes.#{attribute}.#{key}",
- :"errors.messages.#{key}"
- ]}.merge(options))
+ (@instance || @subject).errors.generate_message(attribute, key, options)
else # Rails <= 2.1.x
::ActiveRecord::Errors.default_error_messages[key] % options[:count]
end
Something went wrong with that request. Please try again.