質問編集履歴

1

ファイルの追加

2020/06/25 02:28

投稿

oqqu
oqqu

スコア7

test CHANGED
@@ -1 +1 @@
1
- cookieを保存するログインテスト
1
+ cookieを保存せずにログインするテスト
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- ### 該当のソースコード
7
+ ### test/integration/user_login_test.rb
8
8
 
9
9
 
10
10
 
@@ -27,3 +27,75 @@
27
27
  end
28
28
 
29
29
  ```
30
+
31
+ ### test/test_helper.rb
32
+
33
+ ```ruby
34
+
35
+ ENV['RAILS_ENV'] ||= 'test'
36
+
37
+ require_relative '../config/environment'
38
+
39
+ require 'rails/test_help'
40
+
41
+ require "minitest/reporters"
42
+
43
+ Minitest::Reporters.use!
44
+
45
+
46
+
47
+ class ActiveSupport::TestCase
48
+
49
+ # Run tests in parallel with specified workers
50
+
51
+ parallelize(workers: :number_of_processors)
52
+
53
+
54
+
55
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
56
+
57
+ fixtures :all
58
+
59
+ include ApplicationHelper
60
+
61
+
62
+
63
+ # Add more helper methods to be used by all tests here...
64
+
65
+ def is_logged_in?
66
+
67
+ !session[:user_id].nil?
68
+
69
+ end
70
+
71
+
72
+
73
+ def log_in_as(user)
74
+
75
+ session[:user_id] = user.id
76
+
77
+ end
78
+
79
+ end
80
+
81
+
82
+
83
+ class ActionDispatch::IntegrationTest
84
+
85
+
86
+
87
+ def log_in_as(user, password: 'password', remember_me: '1')
88
+
89
+ post login_path, params: { session: { email: user.email,
90
+
91
+ password: password,
92
+
93
+ remember_me: remember_me }}
94
+
95
+ end
96
+
97
+ end
98
+
99
+
100
+
101
+ ```