7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails5の勉強: unknown keyword: idについて

Posted at

#注意:この記事はガチの初心者がとりあえずの解決法を書いてるだけです.参考にはなりませんからね

いつもの.
なにか「間違えたこと書かないでくれ」な点がありましたら教えていただけると幸いです...

#1. 今回のエラー
前回言ってた「もう一個のエラー」なのです.コントローラのテストをする際のエラーです.

とりあえず問題のコード

articles_controller_test.rb
require 'test_helper'

class ArticlesControllerTest < ActionController::TestCase
  #中略
  
  test "show" do
    article = FactoryGirl.create(:article, expired_at: nil)
    get :show, id: article
    assert_response :success
  end

end

前回と同じくテストをしてみる.

実行したコマンド
bin/rake test TEST=test/controllers/articles_controller_test.rb

返答

DEPRECATION WARNING: Using a dynamic :action segment in a route is deprecated and will be removed in Rails 6.0. (called from block in <main> at /Users/xxx/Rails/myapp/config/routes.rb:4)
Run options: --seed 54319

# Running:

.E

Error:
ArticlesControllerTest#test_show:
ArgumentError: unknown keyword: id
    test/controllers/articles_controller_test.rb:12:in `block in <class:ArticlesControllerTest>'


bin/rails test test/controllers/articles_controller_test.rb:10



Finished in 0.387560s, 5.1605 runs/s, 5.1605 assertions/s.
2 runs, 2 assertions, 0 failures, 1 errors, 0 skips

idなんか知らんって言われてる...

#2. 原因
(多分)バージョンによる違いだと思う.
自信ないです,スンマセン...

#3. 変更
ここを参考に修正.

articles_controller_test.rb
require 'test_helper'

class ArticlesControllerTest < ActionController::TestCase
  #中略
  
  test "show" do
    article = FactoryGirl.create(:article, expired_at: nil)
    get :show, params: { id: article.id }
    assert_response :success
  end

end

#4. 結果
無事にエラーは消えました.同じように
xx: yy
と表記してるところはすべて
params: { xx: yy.xx }
に直してます.これで今のところは大丈夫そう...?_

7
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?