testing chapter: agile web dev withrails

I am working my way through Agile web development with rails and I'm in
the testing chapter.
when I run the following test(or any other test)
I'm new and not sure where to start looking.

require 'test_helper'

class ProductTest < ActiveSupport::TestCase
  # Replace this with your real tests.
  test "the truth" do
    assert true
  end
end

I always get

ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has
no column named image_url: INSERT INTO "users" ("created_at",
"image_url", "title", "updated_at", "id", "description") VALUES
('2010-12-06 16:04:02', 'MyString', 'MyString', '2010-12-06 16:04:02',
298486374, 'MyText')

John Sayeau wrote in post #966558:

I am working my way through Agile web development with rails and I'm in
the testing chapter.
when I run the following test(or any other test)
I'm new and not sure where to start looking.

Read the error message! It tells you what you need to know.

Bonus tip: once you finish the testing tutorial, check out RSpec as a
replacement for Test::Unit and factories (Machinist or FactoryGirl) as a
replacement for fixtures. They're much nicer tools than the ones
provided by the core team.

require 'test_helper'

class ProductTest < ActiveSupport::TestCase
  # Replace this with your real tests.
  test "the truth" do
    assert true
  end
end

I always get

ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has
no column named image_url: INSERT INTO "users" ("created_at",
"image_url", "title", "updated_at", "id", "description") VALUES
('2010-12-06 16:04:02', 'MyString', 'MyString', '2010-12-06 16:04:02',
298486374, 'MyText')

Best,

I get that the error says that it's trying to insert inappropriate data
into the users table. It looks like I just need to find out why it's
picking the users table instead of the products table. I don't know
where the insert is coming from.

Please quote when replying.

John Sayeau wrote in post #966562:

I get that the error says that it's trying to insert inappropriate data
into the users table. It looks like I just need to find out why it's
picking the users table instead of the products table. I don't know
where the insert is coming from.

Rails always gives a line number as part of its stack trace when errors
are generated. If looking there is not sufficient, then perhaps you
should use the debugger to step through your code and find out. Or
write more tests to figure out where the failure is.

Best,

So *does* your test database have such a column? Have you maybe
created a migration previously to add it, but not run migrations on your
test db?

If the error occurs before it actually starts running the tests and
happens whatever test you are running it may be an issue with loading
the fixtures into the test database. Have you got fixtures for the
users table (probably test/fixtures/users.yml)? Have you got
image_url specified in the fixture but not in the database?

Once you have worked through the tutorial then I would advise
forgetting about fixtures and using Factories instead.

Colin

Colin Law wrote in post #966572:
[...]

Once you have worked through the tutorial then I would advise
forgetting about fixtures and using Factories instead.

Amen to that. Fixtures are evil, so much so that I no longer believe
that *any* test environment using fixtures can be considered a proper
testing environment.

Colin

Best,

Colin Law wrote in post #966572:

If the error occurs before it actually starts running the tests and
happens whatever test you are running it may be an issue with loading
the fixtures into the test database. Have you got fixtures for the
users table (probably test/fixtures/users.yml)? Have you got
image_url specified in the fixture but not in the database?

Once you have worked through the tutorial then I would advise
forgetting about fixtures and using Factories instead.

Colin

pretty sure this is the problem. For some reason the generated users.yml
and the generated products.yml file are the same. Just started this
chapter about an hour ago so I don't exactly understand what these files
are for yet...thanks. I'll just try editing the users.yml file to get it
to reflect the columns in the table.

Maybe Because I'm running rails 2.3.5 and the book uses something lower
I have something different fixtures. I swapped in the ones from the
book's source and now it works. I hope I get an explanation as to
fixtures use as I go on in the book...thanks.

This is what was in my users.yml file:

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
  title: MyString
  description: MyText
  image_url: MyString

two:
  title: MyString
  description: MyText
  image_url: MyString

I looked at the source code from the book and for users.yml, it is this:

<% SALT = "NaCl" unless defined?(SALT) %>

dave:
  name: dave
  salt: <%= SALT %>
  hashed_password: <%= User.encrypted_password('secret', SALT) %>

Maybe Because I'm running rails 2.3.5 and the book uses something lower
I have something different fixtures. I swapped in the ones from the
book's source and now it works. I hope I get an explanation as to
fixtures use as I go on in the book...thanks.

This is what was in my users.yml file:

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
title: MyString
description: MyText
image_url: MyString

two:
title: MyString
description: MyText
image_url: MyString

I would have expected the fixtures to have been generated when you
generated the model. Are you sure you put the right fields in when
you generated the user model? Check back in your source control
system and see when you created it. The fixtures should match the
migration created at the same time. If you are not using a source
control system then install git and start using it. The few hours
learning curve (if you do not already use it) will be recovered many
times over.

Colin

I would have expected the fixtures to have been generated when you
generated the model. Are you sure you put the right fields in when
you generated the user model?

That makes sense except the user model looks correct. Unless I made a
mistake the first time I generated the model and then fixed it and then
forgot that I fixed it...?
I think to fix it, though, I would have regenerated the model which I
would have thought would regenerate the fixture. I'll have to experiment
and see...