gotqn
gotqn

Reputation: 43636

Rails - rake test fails

Using the following statement:

rails generate scaffold Product title:string description:text image_url:string price:decimal

and editing a little bit the generated migration I've got the following migration:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :title
      t.text :description
      t.string :image_url
      t.decimal :price, precision: 8, scale: 2

      t.timestamps
    end
  end
end

After that, I have run successfully the following command:

rake db:migrate

and connect to my database and check that truly the table have been created. Then, I run

rake test

and got a lot of errors, and the source of the issue I believe, is that the rails is not able to found the "products" table:

 1) Error:
test_should_create_product(ProductsControllerTest):
ActiveRecord::JDBCError: Table products does not exist
    arjdbc/jdbc/RubyJdbcConnection.java:115:in `columns'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/db2/adapter.rb:514:in `columns'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:660:in `column_names'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:651:in `timestamp_column_names'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:585:in `table_rows'
    org/jruby/RubyHash.java:1257:in `each'
    org/jruby/RubyEnumerable.java:718:in `map'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:579:in `table_rows'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:494:in `create_fixtures'
    org/jruby/RubyArray.java:1613:in `each'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:492:in `create_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:491:in `create_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:168:in `disable_referential_integrity'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:476:in `create_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:895:in `load_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:849:in `setup_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:432:in `_run__858744690__setup__1004892786__callbacks'
    org/jruby/RubyBasicObject.java:1659:in `__send__'
    org/jruby/RubyKernel.java:2086:in `send'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:390:in `_run_setup_callbacks'
    org/jruby/RubyBasicObject.java:1659:in `__send__'
    org/jruby/RubyKernel.java:2086:in `send'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

As far as I've understand, when test are made, my "test" database is erased and migrations of "development" database are apply to it. Because, I am using "IBM DB2 Express 10.1" database I suppose I need to perform some changes on the files responsible for testing.

Could you help me on solving this?

Below, I have displayed more information about the whole situation:

  1. Using "IBM DB2 Express" version 10.1
  2. Using jRuby 1.7.2
  3. Using Rails version 3.2.12
  4. Using Ubuntu 10.04 LTC
  5. This is how my "database.yml" file looks:
development:
    adapter: jdbc
    driver: com.ibm.db2.jcc.DB2Driver
    url: jdbc:db2://localhost:50000/ddevelop
    host: localhost
    port: 50000
    database: ddevelop
    username: db2inst1
    password: pass

test:
    adapter: jdbc
    driver: com.ibm.db2.jcc.DB2Driver
    url: jdbc:db2://localhost:50000/dtest
    host: localhost
    port: 50000
    database: dtest
    username: db2inst1
    password: pass

Note: The "dtest" database have been already created.

Upvotes: 0

Views: 340

Answers (1)

Billy Chan
Billy Chan

Reputation: 24815

The test database has not been updated yet. You need to run rake db:test:prepare after rake db:migration. You can run it now and try again.

Upvotes: 1

Related Questions