Permalink
Browse files

Errors added to "base" should not have "base" in the message

  • Loading branch information...
1 parent 874b51a commit 0c99ee64f9ea1f994d50916a46159b8058059f1a @eugenebolshakov eugenebolshakov committed with Daniel Haran Apr 27, 2009
Showing with 17 additions and 2 deletions.
  1. +5 −1 lib/active_presenter/base.rb
  2. +6 −0 test/base_test.rb
  3. +6 −1 test/test_helper.rb
@@ -223,7 +223,11 @@ def attribute_prefix(type)
def merge_errors(presented_inst, type)
presented_inst.errors.each do |att,msg|
- errors.add(attribute_prefix(type)+att, msg)
+ if att == 'base'
+ errors.add(type, msg)
+ else
+ errors.add(attribute_prefix(type)+att, msg)
+ end
end
end
View
@@ -69,6 +69,12 @@
s.errors.on(:user_login)
end
+ expect ['User Password can not be blank'] do
+ s = SignupPresenter.new(:user_login => 'login')
+ s.valid?
+ s.errors.full_messages
+ end
+
expect ActiveRecord::Base.to.receive(:transaction) do
s = SignupPresenter.new
s.save
View
@@ -31,9 +31,14 @@
end
class User < ActiveRecord::Base
- validates_presence_of :login, :password
+ validates_presence_of :login
+ validate :presence_of_password
attr_accessible :login, :password, :birthday
attr_accessor :password_confirmation
+
+ def presence_of_password
+ errors.add_to_base('Password can not be blank') if password.blank?
+ end
end
class Account < ActiveRecord::Base; end
class Address < ActiveRecord::Base; end

0 comments on commit 0c99ee6

Please sign in to comment.