Forum: Ruby on Rails Problems with testing/Wrong table columns

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
krani (Guest)
on 2009-05-20 00:24
(Received via mailing list)
Hello,

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.

1) 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"

Errors running test:units!

I'm confused, can you help me?
Thanks in advance :-)

bye
krani
Colin L. (Guest)
on 2009-05-20 00:36
(Received via mailing list)
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.

Colin

2009/5/19 krani <removed_email_address@domain.invalid>
krani (Guest)
on 2009-05-20 19:40
(Received via mailing list)
Hi,

thanks for your reply

I don't think that there is a problem with my fixtures. I have only
one:

one:
  project_id:1
  category_id:1
  name:
  text:KN Airintake Kit
  created_at:
  updated_at:

regards
krani
Colin L. (Guest)
on 2009-05-20 20:29
(Received via mailing list)
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.

Colin

2009/5/20 krani <removed_email_address@domain.invalid>
krani (Guest)
on 2009-05-24 22:20
(Received via mailing list)
Hi

thanks for your help :)

The complete trace:

D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
abstract_adapter.rb:188:in `log'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
mysql_adapter.rb:309:in `execute'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/abstract/
database_statements.rb:147:in `insert_fixture'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:640:in
`insert_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:577:in `each'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:577:in
`insert_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:520:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:520:in `each'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:520:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/abstract/
database_statements.rb:66:in `transaction'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:518:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
mysql_adapter.rb:254:in `disable_referential_integrity'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:509:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/base.rb:1398:in `silence'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:508:in
`create_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:964:in
`load_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/fixtures.rb:930:in
`setup_fixtures'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:178:in `send'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:178:in
`evaluate_method'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:166:in `call'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `each'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `send'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:277:in
`run_callbacks'
D:/Programme/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:
58:in `run'

Unfortunately I don't understand what rails want to tell me with this
trace...

I don't think that there is a problem in schema.rb. This is the
definition for the component model:

  create_table "components", :force => true do |t|
    t.integer  "project_id"
    t.integer  "category_id"
    t.string   "name"
    t.text     "text"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

bye
krani
Frederick C. (Guest)
on 2009-05-24 22:25
(Received via mailing list)
On May 24, 7:19 pm, krani <removed_email_address@domain.invalid> wrote:

>     t.text     "text"
>     t.datetime "created_at"
>     t.datetime "updated_at"
>   end
>

The error occurs when loading the fixtures for brand. You should
probably look at the fixtures file or schema for that table.

Fred
krani (Guest)
on 2009-05-24 23:01
(Received via mailing list)
Thank you!

For whatever reason there were faulty definitions in the fixtures of
other models.

Now it works :)

Thanks everybody who tried to help me!
This topic is locked and can not be replied to.