guest
#1
Hi,
I have a simple model and written a testcase.
class Product < ActiveRecord::Base
validates_presense_of :name
end
class ProductTest < Test::Unit::TestCase
fixtures :products
def test_invalid
product = Product.new
assert !product.valid?
end
end
The testcase fails with a message,
is not true.
What is wrong with the testcase? I can see it ruby console that
“product.valid?” returns false…so “assert !product.valid?” should
return true…
Any clues what is wrong?
Thanks.
guest
#2
The test case is telling you that product.valid? is returning true.
Have you actually checked the return value?
Cheers,
Pete Y.
http://9cays.com/
guest
#3
Hi,
“assert_valid product” passes…meaning the product.valid? is returning
“true” in the test case. 
But if I check this in ruby console, product.valid? returns “false” and
I can see all “invalid” errors…but something is weird!
Any ideas what else I should check?
Thanks.
Chris C. wrote:
Guest wrote:
Hi,
I have a simple model and written a testcase.
class Product < ActiveRecord::Base
validates_presense_of :name
end
class ProductTest < Test::Unit::TestCase
fixtures :products
def test_invalid
product = Product.new
assert !product.valid?
end
end
The testcase fails with a message,
is not true.
Hi,
I think you need to have it read
product = Product.create
not
product = Product.new
Chris
ruby -e ‘$=[1667523425, 1920230770, 539828333, 1634956389, 1914728294,
543387502, 1667591796, 1918989417, 1869509492, 1969514863, 1932419951,
109];$/="";11.times{$/<<78.chr};1.times{$/<<99.chr};puts$.pack($/)’
guest
#4
Guest wrote:
Hi,
I have a simple model and written a testcase.
class Product < ActiveRecord::Base
validates_presense_of :name
end
class ProductTest < Test::Unit::TestCase
fixtures :products
def test_invalid
product = Product.new
assert !product.valid?
end
end
The testcase fails with a message,
is not true.
Hi,
I think you need to have it read
product = Product.create
not
product = Product.new
Chris
ruby -e ‘$=[1667523425, 1920230770, 539828333, 1634956389, 1914728294,
543387502, 1667591796, 1918989417, 1869509492, 1969514863, 1932419951,
109];$/="";11.times{$/<<78.chr};1.times{$/<<99.chr};puts$.pack($/)’
guest
#5
Strangely I have this behavior only in the “product” model, the “user”
model works as expected!