Rails3: model: Member: errors must be set on existing attributes
On Rails 3.0, test fails with following error. <pre> Error: test_validate(MemberTest): NoMethodError: undefined method `role' for #<Member:0x7f73caf8cd08> app/models/member.rb:87:in `validate_role' test/unit/member_test.rb:76:in `test_validate' </pre> Contributed by Sylvain Utard. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8124 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
c585d224d8
commit
d9699adce5
|
@ -84,7 +84,7 @@ class Member < ActiveRecord::Base
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def validate_role
|
def validate_role
|
||||||
errors.add_on_empty :role if member_roles.empty? && roles.empty?
|
errors.add_on_empty :roles if member_roles.empty? && roles.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -74,6 +74,7 @@ class MemberTest < ActiveSupport::TestCase
|
||||||
assert user.save
|
assert user.save
|
||||||
member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
|
member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
|
||||||
assert !member.save
|
assert !member.save
|
||||||
|
assert_equal I18n.translate('activerecord.errors.messages.empty'), member.errors[:roles].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validate_member_role
|
def test_validate_member_role
|
||||||
|
|
Loading…
Reference in New Issue