Conversation
Gemfile
Outdated
|
|
||
|
|
||
| gem 'rails', '~> 5.1.2' | ||
| gem 'bcrypt', '3.1.11' |
There was a problem hiding this comment.
Gemfile
Outdated
| gem 'uglifier', '3.2.0' | ||
| gem 'coffee-rails', '4.2.2' | ||
| gem 'turbolinks', '5.0.1' | ||
| gem 'jbuilder', '2.7.0' |
There was a problem hiding this comment.
依存解決のためにbundlerを使っているので、ここまでバージョンを決め打ちする必要はありません。
OSSのGemfileなどを参考にしてみてください。
~> 5.1.2 と書くと、 5.1.x 系の例えば、マイナーバージョンアップされた、 5.1.3 などがリリースされたとき、それがインストールされます。bundlerの取り扱いは、基本的な知識なので理解しないと厳しそうです。
|
commitの問題を指摘します。趣味ならば何でも良いと思うのですが、一応、業務想定としてマジレスしておきます。おそらく業務であれば、研修でない限り、通過しないPRになっています。
なお、Gitの使い方に慣れていないと思うので、まずそれを慣れた方がよさそうです。
これらはできると思うのですが、それに加えて下記を覚えないと厳しそうです。
|
| t.datetime "created_at", null: false | ||
| t.datetime "updated_at", null: false | ||
| t.index ["email"], name: "index_users_on_email" | ||
| end |
There was a problem hiding this comment.
modelでuniquenessを保証するのであれば、通常は、table定義時でもそれを行う必要があります。
この2つは、reviewしてもらうときの前提なので、必ず確認するようにしましょう。 |
f2ca6f3 to
1f8bff6
Compare
| gem 'sqlite3', '1.3.11' | ||
| gem 'byebug', '9.0.0', platform: :mri | ||
| gem 'sqlite3' | ||
| gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] |
There was a problem hiding this comment.
修正不要ですが、このオプション指定は下記との勘違い?(あ、でもjrubyがないか)
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
There was a problem hiding this comment.
あーすみませんデフォルトですね。失礼。
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
| t.string :email | ||
| t.string :password_digest | ||
|
|
||
| t.timestamps |
There was a problem hiding this comment.
- テーブルの作成・更新・削除など、DBに関する変更は、すべてmigrationに書きます。
schema.rbは、rails db:migrateすると自動生成されるので、手作業で修正してはなりません。- Modelに
presence: trueと必須であることを保証する場合は、 テーブル定義でもt.string :user_name, null: falseと「Nullを許容しませんよ」という定義が必要です。 - インデックスを張るときも、migrationで行います。ユニークであることもここで保証できます。
| @@ -0,0 +1,15 @@ | |||
| class User < ApplicationRecord | |||
| before_save { email.downcase! } | |||
There was a problem hiding this comment.
- validationを通過した後なので、save前にdowncaseする必要はなさそう。
- もしもdowncaseを強制したいなら、before_validation あたりでもよさそう。
- 値を破壊的変更をする
email.downcase!よりもself.email = email.downcaseと書く方が一般的です。
| end | ||
|
|
||
| test "ユーザー名:存在性" do | ||
| @user.user_name = " " |
There was a problem hiding this comment.
モデルの名前が User なので、その名前を表す属性は name でよいのでは?(とここで思いました)
| get '/contact', to: 'static_pages#contact' | ||
| get '/signup' , to: 'users#new' | ||
| post '/signup', to: 'users#create' | ||
| resources :users |
There was a problem hiding this comment.
修正しなくてもよいのですが、routingは、controllerが実装されてはじめて使えるようになるので、コミット順序からしたら、コントローラの実装の後でよいかと思います。
| assert_select "a[href=?]", root_path | ||
| assert_select "a[href=?]", about_path | ||
| assert_select "a[href=?]", contact_path | ||
| assert_select "a[href=?]", signup_path, count: 2 |
| <% end %> | ||
| </ul> | ||
| </div> | ||
| <% end %> |
There was a problem hiding this comment.
修正するまでもないですが、パーシャルから、アサインされた変数を参照する場合、直接インスタンス変数を呼ばずに、 render "shared/error_messages", user: @user といった感じで、必要な変数をbindして、渡す方が望ましいです。なお、 shared なパーシャルであれば、 render "shared/error_message", resource: @user といった感じで渡して、汎用的にした方がよいかなと思いました。
| <%= form_for(@user, url: signup_path) do |f| %> | ||
| <%= render "shared/error_messages" %> | ||
|
|
||
| <%= f.label :user_name, "ユーザー名" %> |
There was a problem hiding this comment.
i18nを設定すれば、 <%= f.label :user_name %> だけで十分なので、覚えてみてもよいかもしれませんね。
| <div class="row"> | ||
| <aside class="col-md-4"> | ||
| <section class="user_info"> | ||
| <%= gravatar_for @user, size: 180 %> |
There was a problem hiding this comment.
- provideもgravatar_forも、メソッドの名前から何を返すのか想像できませんでした。修正不要ですが、実際のチーム作業のときは恐らくNGになるかと思います。
- 理想を言うと、コードを読まなくてもメソッド名を見て、どういう結果が返されるのかが分かること、となります。
|
|
||
| private | ||
|
|
||
| #ストロングパラメーター |
There was a problem hiding this comment.
自分用かもしれませんが、上のコメントもそうですが、コメントも保守の対象なので、何を残すかは精査したいところですね(修正不要です)
| assert_template "users/show" | ||
| assert_not flash.empty? | ||
| assert_match "ユーザー登録が完了しました!", response.body | ||
| end |
There was a problem hiding this comment.
内容的には、コントローラのテストっぽいので、コントローラでテストしてもよさそう。
|
以降の方針として、今回の目的をアプリケーションを作ることに焦点をあてて、テストコードは一切書かずに モンキーテストのみ でもよいかなと思いました(もちろん、どういうやり方をするかはおまかせします)テストは今回の要件に含めずに、 RSpecやCapybaraと共に学習してみる方が効率良いかなと思いました。 |
fix #1