2016-09-30 3 views
3

Ubuntu 16.04 amd64サーバーのhttps://gorails.com/setup/ubuntu/16.04の指示に従ってRailsをインストールしました。私は他のオプションの代わりに 'rbenv'を使用しました。統合テスト中に、逆にログにもかかわらず、ActionController :: ParameterMissingが表示されます

「testapp」という名前の新しいアプリケーションを作成しました。

Iは、次に実行される:

$ rails generate scaffold Test name:string age:integer 

そして、私が実行:次に

require 'test_helper' 

class TestsPostTest < ActionDispatch::IntegrationTest 

    test "can create an item" do 
    get "/tests/new" 
    assert_response :success 
    post "/tests", 
     params: { test: { name: 'Micky Mouse', age: 120 } } 
    assert_response :redirect 
    follow_redirect! 
    assert_response :success 
    end 
end 

そして次のように私は読み取るためのテスト/統合/ tests_post_test.rb修飾

$ bin/rails generate integration_test tests_post 

を私は実行した:

rake test 

これは私に次のエラー得られます。しかし、

Run options: --seed 24994 

# Running: 

.......E 

Finished in 0.247049s, 32.3822 runs/s, 56.6689 assertions/s. 

    1) Error: 
TestsPostTest#test_can_create_an_item: 
ActionController::ParameterMissing: param is missing or the value is empty: test 
    app/controllers/tests_controller.rb:72:in `test_params' 
    app/controllers/tests_controller.rb:27:in `create' 
    test/integration/tests_post_test.rb:8:in `block in <class:TestsPostTest>' 

8 runs, 14 assertions, 0 failures, 1 errors, 0 skips 

を、関連するログは次のことを示しています

開発では、生産における
-------------------------------------- 
TestsPostTest: test_can_create_an_item 
-------------------------------------- 
Started GET "/tests/new" for 127.0.0.1 at 2016-09-30 07:50:18 -0400 
Processing by TestsController#new as HTML 
    Rendered tests/_form.html.erb (13.6ms) 
    Rendered tests/new.html.erb within layouts/application (16.4ms) 
Completed 200 OK in 170ms (Views: 161.1ms | ActiveRecord: 0.0ms) 
Started POST "/tests" for 127.0.0.1 at 2016-09-30 07:50:19 -0400 
Processing by TestsController#create as HTML 
    Parameters: {"params"=>{"test"=>{"name"=>"Mickey Mouse", "age"=>"120"}}} 
Completed 400 Bad Request in 0ms (ActiveRecord: 0.0ms) 

、これが唯一のテストで、エラーを与えません。私は他のプロジェクトでオンラインで見た例を見ていますが、ここでは特に何もしていないことはわかりません。これらの具体的な手順を作成して問題をできるだけ簡単に示しました。これを正しく動作させる方法は?このバージョンのレーキ(11.3.0)にバグはありますか?

+0

あなたの 'TestController'には、特に72行目に何がありますか? –

+0

params.require(:test).permit(:name、:age)ですが、これはこの問題の性質ではありません。 Alexandre Angelimはそれを持っていました...私がテストでparamsを指定した方法を変更するだけでした。 –

+0

これらの問題をデバッグする方法は、このような特定の解決方法を記憶するのではなく、その行の上に 'binding.pry'を置いて、' params'の現在の値を検査するだけですソリューションはかなり明らかです。 –

答えて

2

あなたはおそらくRails 4を使用しています(以下のインストールチュートリアルを参照)。 Rails 4では、統合テストを投稿するときにパラメータをラップする必要はありません。

post "/tests", params: { test: { name: 'Micky Mouse', age: 120 } } 

post "/tests", { test: { name: 'Micky Mouse', age: 120 } } 

に、あなたは大丈夫:行を変更します。

+0

"ラップする必要はありません" - レールを使用しているので、5 –

+0

ありがとう@SergioTulentsev。私は答えを更新します。 –

+0

それは答えです。私は4.2を使用しています。明らかに私が調べてきたすべてのサンプルは5.0用です。ありがとうございました! –

関連する問題