开发者

Rails 3: Why Rails tries to insert values to database when running a simple test?

I run:

ruby -I test test/unit/job_test.rb

from my application root directory, and I get:

Loaded suite test/unit/job_test
Started
E
Finished in 2.046875 seconds.

1) Error:
   test_My_First_Test(JobTest):
   ActiveRec开发者_JAVA技巧ord::RecordNotUnique: Mysql2::Error: Duplicate entry '' 
   for key 'name':
   INSERT INTO `ac_buyers` (`created_at`, `updated_at`, `id`) VALUES 
   ('2011-03-10 06:04:06', '2011-03-10 06:04:06', 298486374)

What's going on here ?

Why Rails tries to insert values to database ?

Here is test/unit/job_test.rb:

require 'test_helper'
class JobTest < ActiveSupport::TestCase
  test "My First Test" do
    assert false
  end
end


It seems like this is Rails fixtures. Look in test/fixtures and you will see some files generated by rails to seed your test database w/ data to test against. When you run your tests rails will insert them in your test DB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜