0

我不斷收到測試f不能打的DB,通過集成測試與MINITEST

「User.count」沒有通過1

改變,即使我不應該(因爲SessionsController#create已經可以工作了)。

測試代碼是這樣的:

- [重構/更新] - 我也下車在模型中的所有驗證,只是爲了看看......但沒有

class UsersSignupTest < ActionDispatch::IntegrationTest 

    test "valid signup information" do 

    OmniAuth.config.test_mode = false 

    get signup_path 
    assert_difference 'User.count', 1 do 
     get '/auth/identity/register', params: { 
     user: { name: "Example User", 
       email: "[email protected]", 
       password_digest: "password", 
       identities: { user_id: 1, 
           provider: "identity", 
           uid: "1"}}} 
    end 

    OmniAuth.config.test_mode = true 
    end 
end 

的全輸出:

UsersSignupTest#test_valid_signup_information = 0.69 s = F 


Failure: 
UsersSignupTest#test_valid_signup_information [/home/lsoave/rails5/gitwatcher/test/integration/users_signup_test.rb:19]: 
"User.count" didn't change by 1. 
Expected: 5 
    Actual: 4 

tail -f log/test.log我得到如下:

---------------------------------------------- 
UsersSignupTest: test_valid_signup_information 
---------------------------------------------- 
Started GET "/signup" for 127.0.0.1 at 2016-03-07 15:17:16 +0100 
Processing by UsersController#new as HTML 
    Rendered users/new.html.erb within layouts/application (37.7ms) 
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1 [["LIMIT", 1]] 
    Rendered layouts/_navigation.html.erb (3.6ms) 
    Rendered layouts/_signup-modal.html.erb (2.6ms) 
    Rendered layouts/_messages.html.erb (0.4ms) 
    Rendered layouts/_footer.html.erb (0.2ms) 
Completed 200 OK in 265ms (Views: 250.3ms | ActiveRecord: 0.6ms) 
    (0.4ms) SELECT COUNT(*) FROM "users" 
Started GET "/auth/identity/register?user[name]=Example+User&user[email]=user%40example.com&user[password_digest]=[FILTERED]&user[identities][user_id]=1&user[identities][provider]=identity&user[identities][uid]=1" for 127.0.0.1 at 2016-03-07 15:17:16 +0100 
    (0.3ms) SELECT COUNT(*) FROM "users" 
    (0.2ms) ROLLBACK 

更新注意:

真正的模型用戶的has_many標識/身份belong_to用戶的關係,我不知道它是正確的表示:

... 
params: { 
      user: { name: "Example User", 
        email: "[email protected]", 
        password_digest: "password", 
        identities: { user_id: 1, 
            provider: "identity", 
            uid: "1"}}} 
... 
+0

也許您的用戶模型的某個驗證未通過。 – GabrieleF

+0

@gabrielef我也放棄了模型中的所有驗證,只是爲了看......但沒有 –

回答

1

嘗試更換身份:一塊類似於:

identities_attributes: { '0': {provider: "identity", uid: "1"}} 

and ch埃克您的用戶模型包含:

accepts_nested_attributes_for :identities 

無需處理自己與分配USER_ID的相關模型,這就是Rails是擅長。