From 5fdd0e80a4db778268e80435b471090cb14f7229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 31 Dec 2009 13:44:15 +0100 Subject: Be sure to convert namespaced names to we have 'Parrots name' instead of 'Parrots.name' in error messages. --- activemodel/lib/active_model/errors.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index e8bb62953d..262a1ef22b 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -97,13 +97,14 @@ module ActiveModel full_messages = [] each do |attribute, messages| - messages = Array.wrap(messages) + messages = Array(messages) next if messages.empty? if attribute == :base messages.each {|m| full_messages << m } else - attr_name = @base.class.human_attribute_name(attribute) + attr_name = attribute.to_s.gsub('.', '_').humanize + attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) options = { :default => ' ', :scope => @base.class.i18n_scope } prefix = attr_name + I18n.t(:"errors.format.separator", options) -- cgit v1.2.3 From 7cc0a4cfa1d18c011d6e41f57d25eb10ed018eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 31 Dec 2009 14:14:29 +0100 Subject: Use activerecord.errors.format as in Rails 2.3.5. --- activemodel/lib/active_model/errors.rb | 6 +++--- activemodel/lib/active_model/locale/en.yml | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 262a1ef22b..abc084a74b 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -105,11 +105,11 @@ module ActiveModel else attr_name = attribute.to_s.gsub('.', '_').humanize attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) - options = { :default => ' ', :scope => @base.class.i18n_scope } - prefix = attr_name + I18n.t(:"errors.format.separator", options) + options = { :default => "{{attribute}} {{message}}", :attribute => attr_name, + :scope => @base.class.i18n_scope } messages.each do |m| - full_messages << "#{prefix}#{m}" + full_messages << I18n.t(:"errors.format", options.merge(:message => m)) end end end diff --git a/activemodel/lib/active_model/locale/en.yml b/activemodel/lib/active_model/locale/en.yml index 0c2cf9ea33..1cdb897f13 100644 --- a/activemodel/lib/active_model/locale/en.yml +++ b/activemodel/lib/active_model/locale/en.yml @@ -1,6 +1,9 @@ en: activemodel: errors: + # model.errors.full_messages format. + format: "{{attribute}} {{message}}" + # The values :model, :attribute and :value are always available for interpolation # The value :count is available when applicable. Can be used for pluralization. messages: -- cgit v1.2.3 From 653fa4c10c3e4a34cfe0fe93a2612ed178ca4455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 31 Dec 2009 14:19:30 +0100 Subject: Add naming to AMo::Lint --- activemodel/lib/active_model/lint.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 1c2347adbf..0be82aa180 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -41,6 +41,20 @@ module ActiveModel assert_boolean model.destroyed?, "destroyed?" end + # naming + # ------ + # + # Model.model_name must returns a string with some convenience methods as + # :human and :partial_path. Check ActiveModel::Naming for more information. + # + def test_model_naming + assert model.class.respond_to?(:model_name), "The model should respond to model_name" + model_name = model.class.model_name + assert_kind_of String, model_name + assert_kind_of String, model_name.human + assert_kind_of String, model_name.partial_path + end + # errors # ------ # -- cgit v1.2.3 From 4796be33a464a4587d0e22dfef113aca597c91c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 3 Jan 2010 16:58:33 +0100 Subject: Add missing tests to Validators. --- activemodel/lib/active_model/validator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 8c9f9c7fb3..01695cb73a 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -72,7 +72,8 @@ module ActiveModel #:nodoc: attr_reader :attributes def initialize(options) - @attributes = options.delete(:attributes) + @attributes = Array(options.delete(:attributes)) + raise ":attributes cannot be blank" if @attributes.empty? super check_validity! end -- cgit v1.2.3