1

最初に、レール、キュウリ、われわれなどではなく、組み込みの組み込みテストスイートを使用しています。マスター別のテストに切り替える前に組み込みスイートスイート。レール統合テストではうまく動作しません

devise 1.4.2とレール3.1を使用しています。

とにかく、アカウントのサインアップ、アカウントの確認、ログインの再入力、フォームの記入をシミュレートする統合テストを作成しています。これは物事が南に向いているようだ。私が言うことができるものから、私のコントローラーに問題があるDeviseは行動を作成し、deviseに関するこれらの問題のために、current_userはゼロです。ここに抜粋です:

require 'test_helper' 

class SignupTest < ActionDispatch::IntegrationTest 

test "new signup and application" do 

    go_to_signup_page 
    create_new_account :user => {:email => "[email protected]", :user_name => "dfdfdf",  
    :password => "dfdfdfdfdfdf", :password_confirmation => "dfdfdfdfdfdf"} 
    confirm_account_creation 
    go_to_signin_page 
    log_in 
    go_to_form 
    submit_form 
end 

.....他のテスト....

def go_to_form 
    get "/applications/new" 
    assert_response :success 
    assert_template "applications/new" 
    assert_equal 'Please fill out this application', flash[:notice] 
end 


def submit_form 
    post "/applications", :application => {.....} 
    assert_response :redirect 
    assert_equal 'Application Successful ', flash[:notice] 
end 

そして、私のコントローラで私はDEF」、私が決める何より

before_filter :authenticate_user! 

を持っていますgo_to_form "は大丈夫です。しかし、私は "def submit_form"でPOSTしようとすると、まだログインしていないときに関数にアクセスしようとすると、 "最初にログインしてサインアップ"する必要があると伝えます。 私はこの問題がcurrent_userにnilを引き起こしていることに気付きました。

私はbefore_filterを削除すると、私は投稿しますが、current_userはまだNILです。

ここで何が起こっているのか説明できません。他のすべてのアクションは、このCREATEアクションを除いてフライングカラーで渡されます。

答えて

1

これは作業用コードです。FactoryGirlを使用しています。このコードを使用すると、正常にログインできます。正確な電子メールとパスワードを入力してください。しかし、Devise宝石のテストケースもそこにあります。

setup do 
    @user = FactoryGirl.create(:user) 
    end 

    def do_login 
    visit '/' 
    click_link "Sign in" 
    fill_in 'user_email', :with => '[email protected]' 
    fill_in 'user_password', :with => 'xxxx' 
    click_on('sign_in') 
    end 

    test 'should go to section index' do 
    do_login 
    assert page.has_content?('Signed in successfully.') 
    end 

これは工場です:

FactoryGirl.define do 
    factory :user do 

    email "[email protected]" 
    password "xxxx" 
    password_confirmation "xxxx" 
    :user_name "admin" 
    confirmed_at "#{Time.now }" 
    end 
end 
関連する問題