2013-06-30 56 views
0

我使用Mongoid與Rails的,但所有已生成的功能測試都與類似的錯誤失敗:Rails的功能測試失敗的MongoDB用ActiveRecord/sqlite3的錯誤

test_should_get_new(PostsControllerTest): 
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: comments: DELETE FROM "comments" 

這些都是測試生成的:

require 'test_helper' 

class PostsControllerTest < ActionController::TestCase 
    setup do 
    @post = posts(:one) 
    end 

    test "should get index" do 
    get :index 
    assert_response :success 
    assert_not_nil assigns(:posts) 
    end 

    test "should get new" do 
    get :new 
    assert_response :success 
    end 

    [...] 
end 

我應該改變測試嗎?或刪除對ActiveRecord或Sqlite的一些引用? (我仍然有源碼在我的Gemfile,因爲我不得不刪除它的問題和我仍然不確定,因爲我不使用它的任何東西如何徹底從應用程序中刪除)

回答

1

config/application.rb,刪除require "rails/all"並添加

require "action_controller/railtie" 
require "action_mailer/railtie" 
require "active_resource/railtie" 
require "rails/test_unit/railtie" 
require "sprockets/railtie" 

config/development.rb註釋/刪除以下內容:

config.active_record.mass_assignment_sanitizer = :strict 
config.active_record.auto_explain_threshold_in_seconds = 0.5 

config/test.rb註釋/刪除以下:

config.active_record.mass_assignment_sanitizer = :strict 

如果不起作用,您能告訴我您的spec_helper.rb嗎?

0

如果鍵入

rails --help 

然後跳過活動記錄的選項列

-O, [--skip-active-record]  # Skip Active Record files 

我建議你創建一個新的Rails項目使用此選項刪除活動記錄的所有痕跡,包括Pierre-Louis提到的所有部分,以及測試裝置等其他部分,然後重新創建/重新導入模型和測試代碼。