开发者

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

开发者 https://www.devze.com 2023-02-15 18:44 出处:网络
I run: ruby -I test test/unit/job_test.rb from my application root directory, and I get: Loaded suite test/unit/job_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

精彩评论

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