I’m new in rails developing and I’m just writing my first application.
I already created some controllers and models and it works.
But now I want to write some tests for my application, but I got
problems.
I wrote one unit test for one model:
test “test_should_create_a_component” do
assert Component.create(:project_id => 1, :category_id => 1, :text
=> ‘Test’)
end
When I run “rake test” I get this message:
D:/Programme/InstantRails-2.0/ruby/bin/ruby.exe -I"lib;test" “D:/
Programme/InstantRails-2.0/ruby/lib/rubygems1.8/gems/rake-0.8.7/lib/
rake/rake_test_loader.rb” “test/unit/component_test.rb”
Loaded suite D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
rake-0.8.
7/lib/rake/rake_test_loader
Started
E
Finished in 0.453 seconds.
Error:
test_test_should_create_a_component(ComponentTest):
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ‘integer’
in ‘field list’: INSERT INTO brands (integer, id, string)
VALUES (NULL, 996332877, NULL)
(…after that the lines of the code trace)
There is definitely no column integer or string in the model. Why does
rails ask for this columns?
I don’t know where to look for the problem…
To check wether it is an problem of my application or of my rails
environment I created another demo application with only one model and
one test and there I get another error without description, only this:
D:\Programme\InstantRails-2.0\rails_apps\home>rake test
(in D:/Programme/InstantRails-2.0/rails_apps/home)
D:/Programme/InstantRails-2.0/ruby/bin/ruby.exe -I"lib;test" “D:/
Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/
rake/rake_test_loader.rb”
D:/Programme/InstantRails-2.0/ruby/bin/ruby.exe -I"lib;test" “D:/
Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/
rake/rake_test_loader.rb”
I am not sure but could this be an error in your test fixture file? It
could be trying to load the test database from the fixture and failing
because the syntax of your fixture yml file is wrong.
I did not look carefully enough at the output, I see now that it has
actually started the test and is in test_test_should_create_a_component.
You should be able to see from the trace where in your application it
generated the faulty sql, though sometimes you have to examine the trace
carefully to find the bits that are in your code and the bits that are
in
Rails. This might give you a clue. If you can’t work it out post the
trace.
It would also be worth having a look at db/schema.rb just to check what
it
thinks the tables should look like. Post that also if necessary.