From 57021251756c9e59d0dff13ab0e78d8ed06cda5f Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 14 Aug 2010 00:19:59 -0300 Subject: [PATCH] Tidy up previous commit --- lib/simple_form/components/errors.rb | 8 ++------ test/components/error_test.rb | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/simple_form/components/errors.rb b/lib/simple_form/components/errors.rb index f540eaf5..ed32d6e6 100644 --- a/lib/simple_form/components/errors.rb +++ b/lib/simple_form/components/errors.rb @@ -24,7 +24,7 @@ module SimpleForm protected def has_errors? - object && errors.present? + object && object.respond_to?(:errors) && errors.present? end def errors @@ -32,11 +32,7 @@ module SimpleForm end def errors_on_attribute - if object.respond_to?(:errors) - object.errors[attribute_name] - else - [] - end + object.errors[attribute_name] end def errors_on_association diff --git a/test/components/error_test.rb b/test/components/error_test.rb index 3a165fc8..dec605b8 100644 --- a/test/components/error_test.rb +++ b/test/components/error_test.rb @@ -24,12 +24,11 @@ class ErrorTest < ActionView::TestCase end test "error should not generate messages when object doesn't respond to errors method" do - @user.instance_eval {undef errors} + @user.instance_eval { undef errors } with_error_for @user, :name, :string assert_no_select 'span.error' end - test 'error should generate messages for attribute with single error' do with_error_for @user, :name, :string assert_select 'span.error', "can't be blank"