Closed yutokyokutyo closed 7 years ago
user.ymlにinvalidのユーザーを書いてしまうとページネーションテストで引っかかってしまう。 打開策を考えねば...。
FAIL["test_index_as_admin_including_pagination_and_delete_links", UsersIndexTest, 1.5785890580009436]
test_index_as_admin_including_pagination_and_delete_links#UsersIndexTest (1.58s)
Expected at least 1 element matching "a[href="/users/771240128"]", found 0..
Expected 0 to be >= 1.
test/integration/users_index_test.rb:18:in `block (2 levels) in <class:UsersIndexTest>'
test/integration/users_index_test.rb:17:in `block in <class:UsersIndexTest>'
->
assert_template`
テスト通った!
% rails t (git)-[Exercises-11.3.3]
Running via Spring preloader in process 85612
Started with run options --seed 23218
44/44: [=======================================================================================================] 100% Time: 00:00:04, Time: 00:00:04
Finished in 4.31082s
44 tests, 193 assertions, 0 failures, 0 errors, 0 skips
@komukomo こちらレビューをお願いします 🙏 ✨
activated:falseを表示するように戻した時にREDになることも確認してみましょう。 このときbaikinmanは1ページ目にきているでしょうか?(where句がない状態でbaikinmanが1ページ目にきていない場合、where句を書かなくてもGREENになっていまいます。) ユーザの順序はどうなっていますか? 順序の指定方法は後のセクションで学ぶので今は確認だけで大丈夫です。 (railstutorial風)
これが確認できたらOKだと思います!リダイレクトのテストもいいと思います!
railstutorial風だw よーし!
% git diff (git)-[Exercises-11.3.3]
diff --git a/test/integration/users_index_test.rb b/test/integration/users_index_test.rb
index e4ab7e4..39976b6 100644
--- a/test/integration/users_index_test.rb
+++ b/test/integration/users_index_test.rb
@@ -13,7 +13,8 @@ class UsersIndexTest < ActionDispatch::IntegrationTest
get users_path
assert_template 'users/index'
assert_select 'div.pagination'
- first_page_of_users = User.where(activated: true).paginate(page: 1)
+ first_page_of_users = User.paginate(page: 1)
+ binding.pry
first_page_of_users.each do |user|
assert_select 'a[href=?]', user_path(user), text: user.name
unless user == @admin
テスト実行すると失敗する。
FAIL["test_index_as_admin_including_pagination_and_delete_links", UsersIndexTest, 64.81731915098499]
test_index_as_admin_including_pagination_and_delete_links#UsersIndexTest (64.82s)
Expected at least 1 element matching "a[href="/users/771240128"]", found 0..
Expected 0 to be >= 1.
test/integration/users_index_test.rb:19:in `block (2 levels) in <class:UsersIndexTest>'
test/integration/users_index_test.rb:18:in `block in <class:UsersIndexTest>'
44/44: [=======================================================================================================] 100% Time: 00:01:08, Time: 00:01:08
Finished in 68.09224s
44 tests, 185 assertions, 1 failures, 0 errors, 0 skips
pryが起動させてコーンソール上で確認すると Baikin Man
いた!
[2] pry(#<UsersIndexTest>)> User.paginate(page: 1).find_by(name: 'Baikin Man')
=> #<User:0x007f9a5a0e2dc8
id: 771240128,
name: "Baikin Man",
email: "baikinman@example.gov",
created_at: Thu, 27 Apr 2017 00:16:59 UTC +00:00,
updated_at: Thu, 27 Apr 2017 00:16:59 UTC +00:00,
password_digest: "$2a$04$KEKbLt5W3fS2fBnKqt1vK.KGasbo0gC3ymUkP8tBm7VgvP01uxfYq",
remember_digest: nil,
admin: false,
activation_digest: nil,
activated: false,
activated_at: Thu, 27 Apr 2017 00:16:59 UTC +00:00>
で、変更点を元に戻すとテストがGREEN!良さそう!
% rails t (git)-[Exercises-11.3.3]
Running via Spring preloader in process 35293
Started with run options --seed 21412
44/44: [=======================================================================================================] 100% Time: 00:00:04, Time: 00:00:04
Finished in 4.59954s
@komukomo 確認できたのでマージします!ありがとうございました ❤️
スーパー学びを得たExercisesでした!