[Rails] Re: model validates twice in tests, produces duplicate error

Sam S - M samsm at mindspring.com
Fri Apr 7 23:38:25 GMT 2006


I'm also having a problem similar to this. I a using the current Rails 
gems, 1.1.1.

It seems the number of errors is double in the test, but not in the 
console. Any suggestions?

Here's the evidence:

  def test_parent_validation
    # new stepTypes require parent
    st = StepType.new(:name => 'Test', :parent_id => 'soup' )
    assert !st.save
    assert_equal 1, st.errors.count, st.errors.full_messages # 
st.errors.on(:parent_id)
  end

yields ...

  1) Failure:
test_parent_validation(StepTypeTest) [test/unit/step_type_test.rb:74]:
Parent is not a numberParent is not a number.
<1> expected but was
<2>.

But in script/console test ...

Loading test environment.
>> st = StepType.new(:name => 'Test', :parent_id => 'soup' )
=> #<StepType:0x3e1a070 @attributes={"class_name"=>nil, "name"=>"Test", 
"parent_
id"=>"soup"}, @new_record=true>
>> !st.save
=> true
>> st.errors.count
=> 1
>> st.errors.full_messages
=> ["Parent is not a number"]

Nate Clark wrote:
> What is really strange, and driving me crazy, is that in the unit
> tests, it seems like the save method is causing my validations to
> execute twice, and produce duplicate error messages. 

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list