-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Masahikokawai step12 #340
Masahikokawai step12 #340
Conversation
3abbab7
to
cd3184b
Compare
私もこちら( #339 (comment) )と同じエラーが出たので、今後新規で |
了解です。 |
@kenkaton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いくつかコメントしましたが、以下も対応お願いします。
- ステップ12の終了期限は…追加しましょう:sob:w
- せっかくI18nを利用しているので、view内の日本語表記は基本的に書き換えたほうがいいと思います:pray:
- タスクにステータスを追加したので、model specに追記してテストしましょう(正常系だけでなく、異常系もテストするといいかも):muscle:
あと、次回からでいいのですが、プルリクはある程度まとまりのある粒度で出したほうがやっぱりいいかもしれないですね。
今回でいうと、step12、step13、step14/15の3つくらいに分けたほうがよかったかも?
様々な変更点を一つのPRにまとめてしまうと、レビュアーの確認すべき箇所が分散してしまって抜け漏れが多くなっちゃいそうです:sob:
ただ、step16/17のような関係が深いstepは同時にPR出しちゃってもいいと思うのでなかなか難しいのですがw
app/controllers/tasks_controller.rb
Outdated
@@ -4,7 +4,19 @@ class TasksController < ApplicationController | |||
before_action :set_task, only: %i[show edit update destroy] | |||
|
|||
def index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index
内の条件分岐が多くなってきているので行数が長くなり、Rubocopでも引っかかっているようです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここはrubocop対象外とさせてください。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここなんですが、以下のようなコードにすれば大丈夫そうです:+1:
@tasks = Task.name_like(params[:name]).status(params[:status]).order(finished_on: params[:sort] || :desc).page(params[:page])
13行を1行にまとめる力技w
ちょっと横にながーーくなるのが気になりますが、改行を入れるなりして見やすく整えると良いかもしれないです:bowtie:
やっていることは以下の2点ですね!
if params[:commit].nil?
で条件分岐をしないscope
で nil か false を返した時は all と同じ扱いになるため
params[:sort]
での条件分岐を||
で行う
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コードありがとうございます!!
ただ、個人的にはrubocop先生が全てではないですし、
メンテする我々が見やすいコードが優先されたほうが良いのでは?
と思ってます。(元のコードのが良いとも言っているわけでは決してないです)
ですので、横に長いのならこのままで行きたいです。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、確かにメンテのしやすいコードがいいと思います!
ラクマのコードも全てrubocopに引っかからないわけではないそうですし、臨機応変に書くのがいいですね。
こちらはこのままでオッケーです!
あと、私のコードだと初期表示のソートが変わっちゃいますね…
完全に読み間違えてました:scream:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ワンライナーにしちゃうと、プルリクの差分的にもわかりにくいんですよね。。
app/controllers/tasks_controller.rb
Outdated
@@ -16,7 +28,7 @@ def create | |||
|
|||
respond_to do |format| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
現状ではhtml形式のレスポンスしか返していないようなので、この辺りのrespond_to do |format|
関連のコードは不要かもしれないですね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTMLのみなので削除しました。
9e90e53
@@ -4,4 +4,7 @@ class Task < ApplicationRecord | |||
enum status: { waiting: 1, work_in_progress: 2, completed: 3 } | |||
|
|||
validates :name, presence: true, length: { maximum: 20 } | |||
|
|||
scope :name_like, -> (name) { where('name like ?', "%#{name}%") if name.present? } | |||
scope :status, -> (status) { where(status: status) if status.present? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scope
を使用していて、とてもいいと思います:+1:
@@ -0,0 +1,3 @@ | |||
<li class="page-item"> | |||
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おお!link_to_unless
メソッドなんてあるんですね!
全然知りませんでした:flushed:
<%= link_to "Rails Training", "#", id: "logo", class: "navbar-brand" %> | ||
<ul class="navbar-nav ml-auto"> | ||
<li class="nav-item"> | ||
<%= link_to "Home", "#", class: "nav-link" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ヘッダー内のリンク先が指定されていないので(root_path
等になるのかな?)指定していただけるといいなと思います!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathを設定しました。
021db0d
end | ||
end | ||
|
||
context '一覧検索' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
検索機能では少なくとも以下のパターンはテストした方がいいと思いました。
- タスク名で検索できること(実装済)
- ステータスで検索できること(実装済)
- タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
- タスク名が入力済みでステータスも選択済みのとき、正しく絞り込まれること(未実装)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec に次のケースを足しました。
900cd64
- タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
- タスク名が入力済みでステータスも選択済みのとき、正しく絞り込まれること(未実装)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec に次のケースを足しました。
900cd64
- タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
- タスク名が入力済みでステータスも選択済みのとき、正しく絞り込まれること(未実装)
すみません、ちょっと説明不足でした。
- タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
こちらのケースは 両方とも未入力の状態で検索ボタンを押した ときです。
あまりないケースだとは思いますが、タスク一覧画面表示直後にそのまま検索ボタンを押した時にエラーが起こっていないかの確認です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
何も入力値なしの検索のケース追加しました。
21177e5
app/views/tasks/index.html.erb
Outdated
|
||
<br> | ||
|
||
<%= link_to t('buttons.new'), new_task_path %> | ||
<%= link_to t('buttons.new'), new_task_path, class: "btn btn-primary pull-right" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ちょっと個人的な意見になるんですが、タスクの新規作成ボタンはタスクの一覧表より上に表示したほうがUIとしてはいいように感じました!(対応するかどうかはお任せします)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
画面上部、右に配置するようにしました。
013c0c0
app/views/tasks/index.html.erb
Outdated
総件数: <%= @tasks.total_count %> | ||
|
||
<div class="table-responsive"> | ||
<table border="table table-striped table-bordered table-hover"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrapのtable
関連クラスが反映されていないので、修正お願いします:pray:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今更ですが、反映されてないですね。。
確認します。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f752151
にて修正しました。
app/views/tasks/index.html.erb
Outdated
<br> | ||
|
||
<%= paginate @tasks %> | ||
ページ: <%= @tasks.current_page %>/<%= @tasks.total_pages %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おおー、こういったちょっとした工夫はすごくいいですね:tada:
ちょっと英語になっちゃいますが、kaminariのtotal_pages
メソッド関連だとこことか読むとなかなか面白いかも?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レコードが0の時、
total_pages: 0
current_page: 1
となるissueですね。
current_pageメソッドは廃止予定にしてparams[:page]を使うように
total_pagesは、1を返すようになるかもしれないですね!
勉強になりました!
ソートするのが目的ならと思ったのですが、、追加しますね!
こちらも修正します!
本PRに含まれてないので恐縮ですが、1つ前のPRでmodel spec に追加してます。
おっしゃる通りですね!見る方も負担になりますしね。。 |
なるほど。 |
$ rails g kaminari:config $ rails g kaminari:views bootstrap4 -e erb
8306573
to
900cd64
Compare
rebase して取り込みましたー |
もしかしたら私の環境だけかもしれないんですが、 |
@kenkaton エラーの内容も貼っておいてもらえると助かりますー |
@@ -10,6 +10,25 @@ | |||
</head> | |||
|
|||
<body> | |||
<%= yield %> | |||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" style="background-color: #71da71;"> | |||
<%= link_to "Rails Training", "#", id: "logo", class: "navbar-brand" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あ、ここもパスを通しちゃいましょうか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一旦、同じくタスクのroot_pathにしてしまいますね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
87cb929
にてセットしました。
end | ||
|
||
scenario '一覧のソート順が登録日の降順であること' do | ||
scenario '一覧の初期表示のソート順が登録日の降順であること' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この辺りは登録日ではなく、終了期限でソートされてますね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ちなみにそう思った理由って聞いてもいいですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
はっ!
私のコードの読み間違い&勘違いでした…
修正すべき箇所は以下のみでした
#340 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#340 (comment)
にてメッセージ直しました。
エラー遡っても消えちゃってたんですが、こんな感じですー
|
spec/system/tasks_spec.rb
Outdated
expect(tds[8]).to have_content 'task2' | ||
end | ||
|
||
scenario '一覧のソート順が登録日の昇順/降順と切り替わること' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
終了期限でソートされるのはこちらだけでした…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かにー
作成日から終了期限に変更しているのにメッセージ修正漏れてましたorz
修正します!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
登録日 から終了期限に変更しました。
ebc7910
@kenkaton |
・ステップ12: 終了期限を追加しよう
cd3184b...569af83
※ 終了日は追加してなく、作成日でそのままソートしてます。。
・ステップ13: ステータスを追加して、検索できるようにしよう
cd3184b
・ステップ14: ページネーションを追加しよう
797d8e3
・ステップ15: デザインを当てよう
1038532