small medium large xlarge

Generic-user-small
10 Nov 2010, 00:57
Henrique Barroso (1 post)

Hello Everyone,

First of all, thank you for this amazing book. I’m really enjoying reading. But I’m pretty new to Ruby and specially Rails. However, reading the book about the unit testing I’m a little confused about what output should I be getting.

  # Unique title
  test "product is not valid without a unique title" do

    product = Product.new(:title => products(:ruby).title,
                          :description => "My description",
                          :price => 1,
                          :image_url => 'lala.jpg')
    assert !product.save
    assert_equal I18n.translate('activerecord.errors.messages.taken'), product.errors[:title].join("; ")
  end  

Shouldn’t this give me one failure ? It actually goes without raising none. I even tried to had this:

    product = Product.new(:title => products(:ruby).title,
                          :description => "My description",
                          :price => 1,
                          :image_url => 'lala.jpg')
    product.save

so I knew that it would actually got a duplicated title, but it went fine. I have “validates :title, :uniqueness => true” just so you know.

I’m using OSX Snow, Rails 3.0.1, Ruby 1.9.2p0, rake: 0.8.7

What am I doing wrong here ?

Cheers

Generic-user-small
19 Dec 2010, 15:04
Roy Zinn (3 posts)

Hey,

I have encountered the same problem and posted my own thread (didn’t see this one…) can anyone help?

You must be logged in to comment