質問編集履歴
2
User.rbを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -171,3 +171,145 @@
|
|
171
171
|
|
172
172
|
|
173
173
|
・チュートリアルの内容を所々参考にして抜き出して使用しているので、順当に最初からチュートリアルに従って作成した場合には出なかったエラーなのかもしれません。
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
### 情報の追加
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
/insta-clone/app/models/user.rb
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
class User < ApplicationRecord
|
186
|
+
|
187
|
+
# Include default devise modules. Others available are:
|
188
|
+
|
189
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
190
|
+
|
191
|
+
devise :database_authenticatable, :registerable,
|
192
|
+
|
193
|
+
:recoverable, :rememberable, :validatable, :omniauthable
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
validates :name, presence: true, uniqueness: { case_sensitive: :false }, length: { maximum: 50 }
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
has_many :posts, dependent: :destroy
|
202
|
+
|
203
|
+
has_many :likes
|
204
|
+
|
205
|
+
has_many :comments
|
206
|
+
|
207
|
+
has_many :active_relationships, class_name: "Relationship",
|
208
|
+
|
209
|
+
foreign_key: "follower_id",
|
210
|
+
|
211
|
+
dependent: :destroy
|
212
|
+
|
213
|
+
has_many :passive_relationships, class_name: "Relationship",
|
214
|
+
|
215
|
+
foreign_key: "followed_id",
|
216
|
+
|
217
|
+
dependent: :destroy
|
218
|
+
|
219
|
+
has_many :following, through: :active_relationships, source: :followed
|
220
|
+
|
221
|
+
has_many :followers, through: :passive_relationships, source: :follower
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
def self.from_omniauth(auth)
|
226
|
+
|
227
|
+
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
228
|
+
|
229
|
+
user.email = auth.info.email
|
230
|
+
|
231
|
+
user.password = Devise.friendly_token[0,20]
|
232
|
+
|
233
|
+
user.name = auth.info.name # assuming the user model has a name
|
234
|
+
|
235
|
+
user.image = auth.info.image # assuming the user model has an image
|
236
|
+
|
237
|
+
# If you are using confirmable and the provider(s) you use validate emails,
|
238
|
+
|
239
|
+
# uncomment the line below to skip the confirmation emails.
|
240
|
+
|
241
|
+
# user.skip_confirmation!
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
def update_without_current_password(params, *options)
|
250
|
+
|
251
|
+
params.delete(:current_password)
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
if params[:password].blank? && params[:password_confirmation].blank?
|
256
|
+
|
257
|
+
params.delete(:password)
|
258
|
+
|
259
|
+
params.delete(:password_confirmation)
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
result = update_attributes(params, *options)
|
266
|
+
|
267
|
+
clean_up_passwords
|
268
|
+
|
269
|
+
result
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
def User.digest(string)
|
276
|
+
|
277
|
+
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
|
278
|
+
|
279
|
+
BCrypt::Engine.cost
|
280
|
+
|
281
|
+
BCrypt::Password.create(string, cost: cost)
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
def follow(other_user)
|
288
|
+
|
289
|
+
following << other_user
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
def unfollow(other_user)
|
296
|
+
|
297
|
+
active_relationships.find_by(followed_id: other_user.id).destroy
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
def following?(other_user)
|
304
|
+
|
305
|
+
following.include?(other_user)
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
```
|
1
やろうとしていること、を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
どこをどう直せばいいのでしょうか。どなたか教えていただけると幸いです。
|
4
4
|
|
5
5
|
|
6
|
+
|
7
|
+
### やろうとしていること
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
アドミンではないユーザーがアドミン属性をwebからいじれないかどうかを確かめるテストをしようとしています。
|
12
|
+
|
13
|
+
テストコード自体はrailsチュートリアルの通りです。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
ユーザーやユーザーの属性に関してテストをやろうとしているのに、何故photos.imageでのエラーが出るんだろう??というレベルです。。すみません。。
|
6
18
|
|
7
19
|
|
8
20
|
|