From 838eddeb4cbe9f7ca93098d7d9c1271e1641a034 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Thu, 3 Apr 2014 11:20:16 -0300 Subject: [PATCH] Use ActiveModel::Errors to build the errors on the test models. --- test/support/models.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/support/models.rb b/test/support/models.rb index fa8eb481..4d86a9e7 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -129,7 +129,7 @@ class User Column.new(attribute, column_type, limit) end - def self.human_attribute_name(attribute) + def self.human_attribute_name(attribute, options = {}) case attribute when 'name' 'Super User Name!' @@ -138,7 +138,7 @@ class User when 'company' 'Company Human Name!' else - attribute.humanize + attribute.to_s.humanize end end @@ -163,14 +163,14 @@ class User def errors @errors ||= begin - hash = Hash.new { |h,k| h[k] = [] } - hash.merge!( - name: ["can't be blank"], - description: ["must be longer than 15 characters"], - age: ["is not a number", "must be greater than 18"], - company: ["company must be present"], - company_id: ["must be valid"] - ) + errors = ActiveModel::Errors.new(self) + errors.add(:name, "can't be blank") + errors.add(:description, 'must be longer than 15 characters') + errors.add(:age, 'is not a number') + errors.add(:age, 'must be greater than 18') + errors.add(:company, 'company must be present') + errors.add(:company_id, 'must be valid') + errors end end