diff options
Diffstat (limited to 'activemodel/test/cases/errors_test.rb')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 9d31ed0a99..d66d6ceff0 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -482,6 +482,27 @@ class ErrorsTest < ActiveModel::TestCase assert_nil person.errors.as_json.default_proc end + test "full_messages doesn't require the base object to respond to `:errors" do + model = Class.new do + def initialize + @errors = ActiveModel::Errors.new(self) + @errors.add(:name, "bar") + end + + def self.human_attribute_name(attr, options = {}) + "foo" + end + + def call + error_wrapper = Struct.new(:model_errors) + + error_wrapper.new(@errors) + end + end + + assert_equal(["foo bar"], model.new.call.model_errors.full_messages) + end + test "full_messages creates a list of error messages with the attribute name included" do person = Person.new person.errors.add(:name, "cannot be blank") |