I have a Page scaffold that I created through rails generate scaffold. I ran rake db:migrate, and viewing the database through SQLite Database Browser reveals that it in fact exists. I can go to the rails console and run:
Page.all.each {|page| puts page.url}
When I run this, it in fact returns the right results (e.g., the value of url for each record of Page.
What I am trying to do is set up an rspec test in my pages controller test to see that each of the routes I've set up in config/routes.rb actually works. So I have a test defined in spec/controllers/pages_controller_spec.rb as follows:
describe PagesController do
Page.all.each do |page|
describe "GET /#{page.url}" do
it "should be able to get at page at #{page.url}" do
get "/#{page.url}"
response.should be_successful
end
end
end
end
This test does not run. Instead, it generates the following message:
C:/Ruby192/lib/ruby/gems/1.9.1/ge开发者_运维问答ms/activerecord-3.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log': SQLite3::SQLException: no such table: pages: SELECT "pages".* FROM "pages" (ActiveRecord::StatementInvalid)
Does anyone know what is going on? Or, in the alternative, does anyone know why this will work in my Rails Console, but not in my rspec tests?
Thank you so much. I am relatively new to Rails, so still learning a lot!
Run rake db:test:prepare
to make sure the database schema is setup in the test environment.
精彩评论