teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

テストコードを追記しました。

2020/02/28 07:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -91,73 +91,50 @@
91
91
 
92
92
  【追記】
93
93
  ```
94
- 3) ユーザーのテスト 編集のテスト 自分の編集画面への遷移 遷移できる
95
- Failure/Error: expect(current_path).to eq('/users/' + user.id.to_s + '/edit')
96
-
97
- expected: "/users/2/edit"
98
- got: "/users/2"
94
+ system/users_spec.rb
99
-
100
- (compared using ==)
101
-
102
-
103
-
104
- # ./spec/system/users_spec.rb:90:in `block (4 levels) in <top (required)>'
105
95
 
96
+ describe '編集のテスト' do
106
- 4) ユーザーテスト 編集のテスト 表示の確認 名前編集フォームに自分の名前が表示される
97
+ context '自分の編集画面へ遷移' do
98
+ it '遷移できる' do
99
+ visit edit_user_path(user)
100
+ expect(current_path).to eq('/users/' + user.id.to_s + '/edit')
101
+ end
102
+ end
103
+ context '他人の編集画面への遷移' do
104
+ it '遷移できない' do
105
+ visit edit_user_path(test_user2)
107
- Failure/Error: expect(page).to have_field 'user[name]', with: user.name
106
+ expect(current_path).to eq('/users/' + user.id.to_s)
108
- expected to find field "user[name]" that is not disabled but there were no matches
107
+ end
109
-
110
-
111
-
112
- # ./spec/system/users_spec.rb:108:in `block (4 levels) in <top (required)>'
108
+ end
113
109
 
110
+ context '表示の確認' do
111
+ before do
112
+ visit edit_user_path(user)
113
+ end
114
+ it 'User infoと表示される' do
115
+ expect(page).to have_content('User info')
116
+ end
114
- 5) ユーザーのテスト 編集のテスト 表示の確認 画像編集フォームが表示される
117
+ it '名前編集フォームに自分の名前が表示される' do
118
+ expect(page).to have_field 'user[name]', with: user.name
119
+ end
120
+ it '画像編集フォームが表示される' do
115
- Failure/Error: expect(page).to have_field 'user[profile_image]'
121
+ expect(page).to have_field 'user[profile_image]'
116
- expected to find field "user[profile_image]" that is not disabled but there were no matches
122
+ end
117
-
118
-
119
-
120
- # ./spec/system/users_spec.rb:111:in `block (4 levels) in <top (required)>'
121
-
122
- 6) ユーザーのテスト 編集のテスト 表示の確認 自己紹介編集フォームに自分の自己紹介が表示される
123
+ it '自己紹介編集フォームに自分の自己紹介が表示される' do
123
- Failure/Error: expect(page).to have_field 'user[introduction]', with: user.introduction
124
+ expect(page).to have_field 'user[introduction]', with: user.introduction
124
- expected to find field "user[introduction]" that is not disabled but there were no matches
125
+ end
125
-
126
-
127
-
128
- # ./spec/system/users_spec.rb:114:in `block (4 levels) in <top (required)>'
129
-
130
- 7) ユーザーのテスト 編集のテスト 表示の確認 編集に成功する
126
+ it '編集に成功する' do
131
- Failure/Error: click_button 'Update User'
127
+ click_button 'Update User'
132
-
133
- Capybara::ElementNotFound:
128
+ expect(page).to have_content 'successfully'
134
- Unable to find button "Update User" that is not disabled
129
+ expect(current_path).to eq('/users/' + user.id.to_s)
135
-
136
-
137
-
138
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:302:in `block in synced_resolve'
139
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/base.rb:83:in `synchronize'
140
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:291:in `synced_resolve'
141
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:52:in `find'
142
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/actions.rb:58:in `click_button'
143
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
144
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
145
- # ./spec/system/users_spec.rb:117:in `block (4 levels) in <top (required)>'
130
+ end
146
-
147
- 8) ユーザーのテスト 編集のテスト 表示の確認 編集に失敗する
131
+ it '編集に失敗する' do
148
- Failure/Error: fill_in 'user[name]', with: ''
132
+ fill_in 'user[name]', with: ''
149
-
133
+ click_button 'Update User'
150
- Capybara::ElementNotFound:
134
+ expect(page).to have_content 'error'
135
+ #もう少し詳細にエラー文出したい
151
- Unable to find field "user[name]" that is not disabled
136
+ expect(current_path).to eq('/users/' + user.id.to_s)
152
-
153
-
154
-
155
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:302:in `block in synced_resolve'
156
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/base.rb:83:in `synchronize'
157
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:291:in `synced_resolve'
158
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:52:in `find'
159
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/actions.rb:91:in `fill_in'
160
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
161
- # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
162
- # ./spec/system/users_spec.rb:122:in `block (4 levels) in <top (required)>'
137
+ end
138
+ end
139
+ end
163
140
  ```

2

テストコードを追記しました。

2020/02/28 07:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -61,17 +61,9 @@
61
61
  ```
62
62
  ```
63
63
  rake routes
64
+
64
- Prefix Verb URI Pattern Controller#Action
65
+   ~省略~
65
- new_user_session GET /users/sign_in(.:format) users/sessions#new
66
+
66
- user_session POST /users/sign_in(.:format) users/sessions#create
67
- destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy
68
- new_user_password GET /users/password/new(.:format) devise/passwords#new
69
- edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
70
- user_password PATCH /users/password(.:format) devise/passwords#update
71
- PUT /users/password(.:format) devise/passwords#update
72
- POST /users/password(.:format) devise/passwords#create
73
- cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
74
- new_user_registration GET /users/sign_up(.:format) users/registrations#new
75
67
  edit_user_registration GET /users/edit(.:format) users/registrations#edit
76
68
  user_registration PATCH /users(.:format) users/registrations#update
77
69
  PUT /users(.:format) users/registrations#update
@@ -95,100 +87,77 @@
95
87
  PATCH /books/:id(.:format) books#update
96
88
  PUT /books/:id(.:format) books#update
97
89
  DELETE /books/:id(.:format) books#destroy
98
- refile_app /attachments #<Refile::App app_file="/home/ec2-user/.rvm/gems/ruby-2.6.3/bundler/gems/refile-46b4178654e6/lib/refile/app.rb">
99
- rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
100
- rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
101
- rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
102
- update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
103
- rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
104
90
  ```
105
91
 
106
92
  【追記】
107
93
  ```
94
+ 3) ユーザーのテスト 編集のテスト 自分の編集画面への遷移 遷移できる
95
+ Failure/Error: expect(current_path).to eq('/users/' + user.id.to_s + '/edit')
96
+
97
+ expected: "/users/2/edit"
108
- user/edit.html.erb
98
+ got: "/users/2"
99
+
100
+ (compared using ==)
101
+
102
+
103
+
104
+ # ./spec/system/users_spec.rb:90:in `block (4 levels) in <top (required)>'
109
105
 
110
- <div class="user-information">
106
+ 4) ユーザーのテスト 編集のテスト 表示の確認 名前編集フォームに自分の名前が表示される
111
- <div class="user-information-item">
107
+ Failure/Error: expect(page).to have_field 'user[name]', with: user.name
112
-
113
- <h2 class="header-space">User info</h2>
108
+ expected to find field "user[name]" that is not disabled but there were no matches
109
+
110
+
111
+
112
+ # ./spec/system/users_spec.rb:108:in `block (4 levels) in <top (required)>'
114
113
 
115
- <%= form_for(@user) do |f| %>
114
+ 5) ユーザーのテスト 編集のテスト 表示の確認 画像編集フォームが表示される
115
+ Failure/Error: expect(page).to have_field 'user[profile_image]'
116
+ expected to find field "user[profile_image]" that is not disabled but there were no matches
117
+
118
+
119
+
116
- <%= render 'layouts/user_edit_error_messages', model: f.object %>
120
+ # ./spec/system/users_spec.rb:111:in `block (4 levels) in <top (required)>'
117
-
118
- <div class="field user-form user-edit-form">
119
- <%= f.label :Name %><br/>
120
- <%= f.text_field :name, autofocus: true, autocomplete: "name" %>
121
- </div>
122
-
123
- <div class="form-group has-icon user-edit user-form">
124
- <%= f.label :Image %><br/>
125
- <%= f.attachment_field :profile_image, placeholder: "Image" %>
126
- </div>
127
-
128
- <div class="field user-form user-edit-form">
129
- <%= f.label :Introduction, class: "user-introduction" %><br/>
130
- <%= f.text_area :introduction, autofocus: true, autocomplete: "introduction" %>
131
- </div>
132
-
133
- <div class="actions user-form">
134
- <%= f.submit "Update User" %>
135
- </div>
136
-
137
- <% end %>
138
121
 
122
+ 6) ユーザーのテスト 編集のテスト 表示の確認 自己紹介編集フォームに自分の自己紹介が表示される
123
+ Failure/Error: expect(page).to have_field 'user[introduction]', with: user.introduction
124
+ expected to find field "user[introduction]" that is not disabled but there were no matches
125
+
126
+
127
+
139
- </div>
128
+ # ./spec/system/users_spec.rb:114:in `block (4 levels) in <top (required)>'
140
- </div>
141
129
 
130
+ 7) ユーザーのテスト 編集のテスト 表示の確認 編集に成功する
142
- <%= render 'shared/footer' %>
131
+ Failure/Error: click_button 'Update User'
132
+
143
- ```
133
+ Capybara::ElementNotFound:
134
+ Unable to find button "Update User" that is not disabled
135
+
136
+
137
+
138
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:302:in `block in synced_resolve'
139
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/base.rb:83:in `synchronize'
140
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:291:in `synced_resolve'
141
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:52:in `find'
142
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/actions.rb:58:in `click_button'
143
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
144
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
145
+ # ./spec/system/users_spec.rb:117:in `block (4 levels) in <top (required)>'
144
146
 
145
- ```
146
- _devise_create_users.rb
147
-
148
- # frozen_string_literal: true
147
+ 8) ユーザーのテスト 編集のテスト 表示の確認 編集に失敗する
149
-
150
- class DeviseCreateUsers < ActiveRecord::Migration[5.0]
151
- def change
152
- create_table :users do |t|
153
- ## Database authenticatable
154
- t.string :name, null: false, default: ""
155
- t.string :email, null: false, default: ""
156
- t.string :password, null: false, default: ""
148
+ Failure/Error: fill_in 'user[name]', with: ''
157
- t.string :encrypted_password, null: false, default: ""
149
+
158
- ## Recoverable
159
- t.string :reset_password_token
160
- t.datetime :reset_password_sent_at
161
- ## Rememberable
162
- t.datetime :remember_created_at
163
- ## Trackable
164
- t.integer :sign_in_count, default: 0, null: false
165
- t.datetime :current_sign_in_at
150
+ Capybara::ElementNotFound:
166
- t.datetime :last_sign_in_at
167
- t.string :current_sign_in_ip
168
- t.string :last_sign_in_ip
169
- ## Confirmable
170
- # t.string :confirmation_token
171
- # t.datetime :confirmed_at
172
- # t.datetime :confirmation_sent_at
173
- # t.string :unconfirmed_email # Only if using reconfirmable
174
- ## Lockable
175
- # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
176
- # t.string :unlock_token # Only if unlock strategy is :email or :both
177
- # t.datetime :locked_at
178
-
179
- t.timestamps null: false
180
- t.string :name
181
- t.string :introduction
182
- t.string :profile_image_id
183
-
184
-
185
- end
186
-
187
- # add_index :users, :username, unique: true
151
+ Unable to find field "user[name]" that is not disabled
152
+
153
+
154
+
188
- add_index :users, :email, unique: true
155
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:302:in `block in synced_resolve'
189
- add_index :users, :reset_password_token, unique: true
156
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/base.rb:83:in `synchronize'
157
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:291:in `synced_resolve'
190
- # add_index :users, :confirmation_token, unique: true
158
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/finders.rb:52:in `find'
159
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/node/actions.rb:91:in `fill_in'
160
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
161
+ # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/capybara-3.31.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
191
- # add_index :users, :unlock_token, unique: true
162
+ # ./spec/system/users_spec.rb:122:in `block (4 levels) in <top (required)>'
192
- end
193
- end
194
163
  ```

1

コードを追記しました。

2020/02/28 06:50

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -101,4 +101,94 @@
101
101
  rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
102
102
  update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
103
103
  rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
104
+ ```
105
+
106
+ 【追記】
107
+ ```
108
+ user/edit.html.erb
109
+
110
+ <div class="user-information">
111
+ <div class="user-information-item">
112
+
113
+ <h2 class="header-space">User info</h2>
114
+
115
+ <%= form_for(@user) do |f| %>
116
+ <%= render 'layouts/user_edit_error_messages', model: f.object %>
117
+
118
+ <div class="field user-form user-edit-form">
119
+ <%= f.label :Name %><br/>
120
+ <%= f.text_field :name, autofocus: true, autocomplete: "name" %>
121
+ </div>
122
+
123
+ <div class="form-group has-icon user-edit user-form">
124
+ <%= f.label :Image %><br/>
125
+ <%= f.attachment_field :profile_image, placeholder: "Image" %>
126
+ </div>
127
+
128
+ <div class="field user-form user-edit-form">
129
+ <%= f.label :Introduction, class: "user-introduction" %><br/>
130
+ <%= f.text_area :introduction, autofocus: true, autocomplete: "introduction" %>
131
+ </div>
132
+
133
+ <div class="actions user-form">
134
+ <%= f.submit "Update User" %>
135
+ </div>
136
+
137
+ <% end %>
138
+
139
+ </div>
140
+ </div>
141
+
142
+ <%= render 'shared/footer' %>
143
+ ```
144
+
145
+ ```
146
+ _devise_create_users.rb
147
+
148
+ # frozen_string_literal: true
149
+
150
+ class DeviseCreateUsers < ActiveRecord::Migration[5.0]
151
+ def change
152
+ create_table :users do |t|
153
+ ## Database authenticatable
154
+ t.string :name, null: false, default: ""
155
+ t.string :email, null: false, default: ""
156
+ t.string :password, null: false, default: ""
157
+ t.string :encrypted_password, null: false, default: ""
158
+ ## Recoverable
159
+ t.string :reset_password_token
160
+ t.datetime :reset_password_sent_at
161
+ ## Rememberable
162
+ t.datetime :remember_created_at
163
+ ## Trackable
164
+ t.integer :sign_in_count, default: 0, null: false
165
+ t.datetime :current_sign_in_at
166
+ t.datetime :last_sign_in_at
167
+ t.string :current_sign_in_ip
168
+ t.string :last_sign_in_ip
169
+ ## Confirmable
170
+ # t.string :confirmation_token
171
+ # t.datetime :confirmed_at
172
+ # t.datetime :confirmation_sent_at
173
+ # t.string :unconfirmed_email # Only if using reconfirmable
174
+ ## Lockable
175
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
176
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
177
+ # t.datetime :locked_at
178
+
179
+ t.timestamps null: false
180
+ t.string :name
181
+ t.string :introduction
182
+ t.string :profile_image_id
183
+
184
+
185
+ end
186
+
187
+ # add_index :users, :username, unique: true
188
+ add_index :users, :email, unique: true
189
+ add_index :users, :reset_password_token, unique: true
190
+ # add_index :users, :confirmation_token, unique: true
191
+ # add_index :users, :unlock_token, unique: true
192
+ end
193
+ end
104
194
  ```