前提・実現したいこと
Rails tutorial 10章 10.3.3 にてエラーが発生しました。
リスト10.48 ページネーションを含めたUserIndexのテストにて、
以前までパスできていたテストがパスしなくなりました。
User.ymlを編集後にエラーが発生するようになったので、原因はUser.ymlの可能性が高いとみております。
発生している問題・エラーメッセージ
FAIL["test_successful_edit_with_friendly_forwarding", UsersEditTest, 0.8996056399992085] test_successful_edit_with_friendly_forwarding#UsersEditTest (0.90s) Expected response to be a redirect to <http://www.example.com/users/762146111> but was a redirect to <http://www.example.com/>. Expected "http://www.example.com/users/762146111" to be === "http://www.example.com/". test/integration/users_edit_test.rb:32:in `block in <class:UsersEditTest>' FAIL["test_unsuccessful_edit", UsersEditTest, 0.9178885359997366] test_unsuccessful_edit#UsersEditTest (0.92s) expecting <"users/edit"> but rendering with <[]> test/integration/users_edit_test.rb:12:in `block in <class:UsersEditTest>'
該当のソースコード
require 'test_helper' class UsersEditTest < ActionDispatch::IntegrationTest def setup @user = users(:michael) end test "unsuccessful edit" do log_in_as(@user) get edit_user_path(@user) **assert_template 'users/edit'** #ここでエラー patch user_path(@user),params:{user:{name:"", email:"foo@invalid", password: "foo", password_confirmation: "bar"}} assert_template 'users/edit' assert_select "div.alert",count:1 end test "successful edit with friendly forwarding" do get edit_user_path(@user) log_in_as(@user) assert_redirected_to edit_user_url(@user) name = "Foo Bar" email = "foo@bar.com" patch user_path(@user),params:{user:{name:name, email:email, password: "", password_confirmation: ""}} assert_not flash.empty? **assert_redirected_to @user** #ここでエラー @user.reload assert_equal name,@user.name assert_equal email,@user.email end end
users.yml michael: name: Michael Example email: michael@example.com password_digest: <%= User.digest('password') %> admin: true activated: true activated_at: <%= Time.zone.now %> archer: name: Sterling Archer email: duchess@example.gov password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> lana: name: Lana Kane email: hands@example.gov password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> malory: name: Malory Archer email: boss@example.gov password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> <% 30.times do |n| %> user_<%= n %>: name: <%= "User #{n}" %> email: <%= "user-#{n}@example.com" %> password_digest: <%= User.digest('password') %> activated: true activated_at: <%= Time.zone.now %> <% end %>
試したこと
エラーはusers.ymlを編集した後から発生しているので、複数パターンを試しました。
users.ymlにmichaelとarcherしかない場合は以前までのテストはパスしました。
<% 30.times do |n| %> user_<%= n %>: name: <%= "User #{n}" %> email: <%= "user-#{n}@example.com" %> password_digest: <%= User.digest('password') %> <% end %>
のコードを加えると今回のエラーメッセージが表示されるようになりました。
lana: name: Lana Kane email: hands@example.gov password_digest: <%= User.digest('password') %> malory: name: Malory Archer email: boss@example.gov password_digest: <%= User.digest('password') %>
だけをmichaelとarcherの後に追加しても同様のエラーが発生致します。
かなりの時間このエラーと格闘しておりますが、解決せず…
以下が、log/test.logとなります。
UsersEditTest: test_successful_edit_with_friendly_forwarding ------------------------------------------------------------ [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 762146111], ["LIMIT", 1]] Started GET "/users/762146111/edit" for 127.0.0.1 at 2019-10-14 07:11:42 +0000 Processing by UsersController#edit as HTML Parameters: {"id"=>"762146111"} Redirected to http://www.example.com/login Filter chain halted as :logged_in_user rendered or redirected Completed 302 Found in 0ms (ActiveRecord: 0.0ms) Started POST "/login" for 127.0.0.1 at 2019-10-14 07:11:42 +0000 Processing by SessionsController#create as HTML Parameters: {"session"=>{"email"=>"michael@example.com", "password"=>"[FILTERED]", "remember_me"=>"1"}} [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ?[0m [["email", "michael@example.com"], ["LIMIT", 1]] [1m[35m (0.1ms)[0m [1m[35mSAVEPOINT active_record_1[0m [1m[35mSQL (0.7ms)[0m [1m[33mUPDATE "users" SET "remember_digest" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["remember_digest", "$2a$04$juX6Kq62d8GXIB/UwY6sWuY/h8/S7PPNhuIYM7VhMyc1P/58cVrfq"], ["updated_at", "2019-10-14 07:11:42.396379"], ["id", 762146111]] [1m[35m (0.1ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m Redirected to http://www.example.com/users/762146111/edit Completed 302 Found in 6ms (ActiveRecord: 0.9ms) Started PATCH "/users/762146111" for 127.0.0.1 at 2019-10-14 07:11:42 +0000 Processing by UsersController#update as HTML Parameters: {"user"=>{"name"=>"Foo Bar", "email"=>"foo@bar.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "id"=>"762146111"} [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 762146111], ["LIMIT", 1]] [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE (762146111) LIMIT ?[0m [["LIMIT", 1]] Redirected to http://www.example.com/ Filter chain halted as :correct_user rendered or redirected Completed 302 Found in 2ms (ActiveRecord: 0.2ms) [1m[35m (1.1ms)[0m [1m[31mrollback transaction[0m [1m[35m (0.0ms)[0m [1m[36mbegin transaction[0m
------------------------------------- UsersEditTest: test_unsuccessful_edit ------------------------------------- [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 762146111], ["LIMIT", 1]] Started POST "/login" for 127.0.0.1 at 2019-10-14 07:11:42 +0000 Processing by SessionsController#create as HTML Parameters: {"session"=>{"email"=>"michael@example.com", "password"=>"[FILTERED]", "remember_me"=>"1"}} [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ?[0m [["email", "michael@example.com"], ["LIMIT", 1]] [1m[35m (0.1ms)[0m [1m[35mSAVEPOINT active_record_1[0m [1m[35mSQL (0.7ms)[0m [1m[33mUPDATE "users" SET "remember_digest" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["remember_digest", "$2a$04$r1N4U0sSl5psnpSZYHEK/Oou4UtteAodY.tYAsJGVLl07e8qaEqKa"], ["updated_at", "2019-10-14 07:11:42.420147"], ["id", 762146111]] [1m[35m (0.1ms)[0m [1m[35mRELEASE SAVEPOINT active_record_1[0m Redirected to http://www.example.com/users/762146111 Completed 302 Found in 8ms (ActiveRecord: 0.9ms) Started GET "/users/762146111/edit" for 127.0.0.1 at 2019-10-14 07:11:42 +0000 Processing by UsersController#edit as HTML Parameters: {"id"=>"762146111"} [1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 762146111], ["LIMIT", 1]] [1m[36mUser Load (0.9ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE (762146111) LIMIT ?[0m [["LIMIT", 1]] Redirected to http://www.example.com/ Filter chain halted as :correct_user rendered or redirected Completed 302 Found in 3ms (ActiveRecord: 1.0ms) [1m[35m (1.1ms)[0m [1m[31mrollback transaction[0m [1m[35m (0.0ms)[0m [1m[36mbegin transaction[0m
補足情報(FW/ツールのバージョンなど)
AWS Cloud9