Skip to content
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

Merged
merged 22 commits into from
Jun 6, 2019
Merged

Masahikokawai step12 #340

merged 22 commits into from
Jun 6, 2019

Conversation

@masahikokawai masahikokawai self-assigned this Jun 3, 2019
@masahikokawai masahikokawai force-pushed the masahikokawai-step12 branch 4 times, most recently from 3abbab7 to cd3184b Compare June 4, 2019 05:12
@masahikokawai masahikokawai changed the title [WIP] Masahikokawai step12 Masahikokawai step12 Jun 4, 2019
@kenkaton
Copy link

kenkaton commented Jun 5, 2019

私もこちら( #339 (comment) )と同じエラーが出たので、今後新規でbundle installする方は皆さん引っかかっちゃうかもしれないですね。
5月中旬あたりに対応されたものの影響のようです。

@masahikokawai
Copy link
Author

@kenkaton
#340 (comment)

了解です。
Gemfile.lock 修正したのpush しますね!

@masahikokawai
Copy link
Author

@kenkaton
#340 (comment)
Gemfile.lock 修正したのpushしました。
8306573

Copy link

@kenkaton kenkaton left a 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

@@ -4,7 +4,19 @@ class TasksController < ApplicationController
before_action :set_task, only: %i[show edit update destroy]

def index
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index内の条件分岐が多くなってきているので行数が長くなり、Rubocopでも引っかかっているようです。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはrubocop対象外とさせてください。

Copy link

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]での条件分岐を||で行う

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コードありがとうございます!!

ただ、個人的にはrubocop先生が全てではないですし、
メンテする我々が見やすいコードが優先されたほうが良いのでは?
と思ってます。(元のコードのが良いとも言っているわけでは決してないです)

ですので、横に長いのならこのままで行きたいです。。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、確かにメンテのしやすいコードがいいと思います!
ラクマのコードも全てrubocopに引っかからないわけではないそうですし、臨機応変に書くのがいいですね。
こちらはこのままでオッケーです!

あと、私のコードだと初期表示のソートが変わっちゃいますね…
完全に読み間違えてました:scream:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ワンライナーにしちゃうと、プルリクの差分的にもわかりにくいんですよね。。

@@ -16,7 +28,7 @@ def create

respond_to do |format|
Copy link

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|関連のコードは不要かもしれないですね。

Copy link
Author

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? }
Copy link

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' %>
Copy link

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" %>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ヘッダー内のリンク先が指定されていないので(root_path等になるのかな?)指定していただけるといいなと思います!

Copy link
Author

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

検索機能では少なくとも以下のパターンはテストした方がいいと思いました。

  • タスク名で検索できること(実装済)
  • ステータスで検索できること(実装済)
  • タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
  • タスク名が入力済みでステータスも選択済みのとき、正しく絞り込まれること(未実装)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec に次のケースを足しました。
900cd64

  • タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
  • タスク名が入力済みでステータスも選択済みのとき、正しく絞り込まれること(未実装)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec に次のケースを足しました。
900cd64

  • タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)
  • タスク名が入力済みでステータスも選択済みのとき、正しく絞り込まれること(未実装)

すみません、ちょっと説明不足でした。

  • タスク名が未入力でステータスが未選択のとき、全件表示されること(未実装)

こちらのケースは 両方とも未入力の状態で検索ボタンを押した ときです。
あまりないケースだとは思いますが、タスク一覧画面表示直後にそのまま検索ボタンを押した時にエラーが起こっていないかの確認です。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何も入力値なしの検索のケース追加しました。
21177e5


<br>

<%= link_to t('buttons.new'), new_task_path %>
<%= link_to t('buttons.new'), new_task_path, class: "btn btn-primary pull-right" %>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと個人的な意見になるんですが、タスクの新規作成ボタンはタスクの一覧表より上に表示したほうがUIとしてはいいように感じました!(対応するかどうかはお任せします)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

画面上部、右に配置するようにしました。
013c0c0

総件数: <%= @tasks.total_count %>

<div class="table-responsive">
<table border="table table-striped table-bordered table-hover">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bootstrapのtable関連クラスが反映されていないので、修正お願いします:pray:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今更ですが、反映されてないですね。。
確認します。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f752151
にて修正しました。

<br>

<%= paginate @tasks %>
ページ: <%= @tasks.current_page %>/<%= @tasks.total_pages %>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おおー、こういったちょっとした工夫はすごくいいですね:tada:
ちょっと英語になっちゃいますが、kaminariのtotal_pagesメソッド関連だとこことか読むとなかなか面白いかも?

Copy link
Author

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を返すようになるかもしれないですね!
勉強になりました!

@masahikokawai
Copy link
Author

  • ステップ12の終了期限は…追加しましょう😭w

ソートするのが目的ならと思ったのですが、、追加しますね!

  • せっかくI18nを利用しているので、view内の日本語表記は基本的に書き換えたほうがいいと思います🙏

こちらも修正します!

  • タスクにステータスを追加したので、model specに追記してテストしましょう(正常系だけでなく、異常系もテストするといいかも)💪

本PRに含まれてないので恐縮ですが、1つ前のPRでmodel spec に追加してます。
https://github.com/Fablic/training/pull/339/files#diff-ffb5b5242cf0ba53067d359c8b8ead99R45

あと、次回からでいいのですが、プルリクはある程度まとまりのある粒度で出したほうがやっぱりいいかもしれないですね。
今回でいうと、step12、step13、step14/15の3つくらいに分けたほうがよかったかも?
様々な変更点を一つのPRにまとめてしまうと、レビュアーの確認すべき箇所が分散してしまって抜け漏れが多くなっちゃいそうです😭
ただ、step16/17のような関係が深いstepは同時にPR出しちゃってもいいと思うのでなかなか難しいのですがw

おっしゃる通りですね!見る方も負担になりますしね。。
次回からある程度のまとまりでPR出すようにします!

@kenkaton
Copy link

kenkaton commented Jun 5, 2019

  • タスクにステータスを追加したので、model specに追記してテストしましょう(正常系だけでなく、異常系もテストするといいかも)💪

本PRに含まれてないので恐縮ですが、1つ前のPRでmodel spec に追加してます。
https://github.com/Fablic/training/pull/339/files#diff-ffb5b5242cf0ba53067d359c8b8ead99R45

なるほど。
上記PRがmaster(masahikokawai)ブランチにmerge済みのようなので、こちらのブランチ(masahikokawai-step12)にも反映するのが良さそうですね。
PRの粒度もですが、commitの粒度も適切なものになっていると、git cherry-pickコマンドで特定のcommitのみ別ブランチにも反映させるということができるので便利かもしれません:+1:

@masahikokawai
Copy link
Author

上記PRがmaster(masahikokawai)ブランチにmerge済みのようなので、こちらのブランチ(masahikokawai-step12)にも反映するのが良さそうですね。
PRの粒度もですが、commitの粒度も適切なものになっていると、git cherry-pickコマンドで特定のcommitのみ別ブランチにも反映させるということができるので便利かもしれません👍

rebase して取り込みましたー

@kenkaton
Copy link

kenkaton commented Jun 6, 2019

もしかしたら私の環境だけかもしれないんですが、bundle installした時にMysql2関連でエラーが出てしまうようです。
その場合には下記コマンドを実行すればインストールできるようになるみたいなので、今後のPRに注記として書いておくと良いかもしれませんね。
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

@masahikokawai
Copy link
Author

masahikokawai commented Jun 6, 2019

@kenkaton
#340 (comment)
了解です、ありがとうございます!

エラーの内容も貼っておいてもらえると助かりますー

@@ -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" %>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、ここもパスを通しちゃいましょうか

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一旦、同じくタスクのroot_pathにしてしまいますね。

Copy link
Author

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この辺りは登録日ではなく、終了期限でソートされてますね

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちなみにそう思った理由って聞いてもいいですか?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

はっ!
私のコードの読み間違い&勘違いでした…
修正すべき箇所は以下のみでした
#340 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#340 (comment)
にてメッセージ直しました。

@kenkaton
Copy link

kenkaton commented Jun 6, 2019

@kenkaton
#340 (comment)
了解です、ありがとうございます!

エラーの内容も貼っておいてもらえると助かりますー

エラー遡っても消えちゃってたんですが、こんな感じですー

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/Users/user_name/path/to/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/user_name/path/to/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2 for inspection.
Results logged to
/Users/user_name/path/to/vendor/bundle/ruby/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mysql2

expect(tds[8]).to have_content 'task2'
end

scenario '一覧のソート順が登録日の昇順/降順と切り替わること' do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

終了期限でソートされるのはこちらだけでした…

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにー
作成日から終了期限に変更しているのにメッセージ修正漏れてましたorz
修正します!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

登録日 から終了期限に変更しました。
ebc7910

@kenkaton
Copy link

kenkaton commented Jun 6, 2019

LGTMです!
lgtm

@masahikokawai
Copy link
Author

@kenkaton
確認ありがとうございました!!
(量多くてすみませんでした。。)

@masahikokawai masahikokawai merged commit 151aa36 into masahikokawai Jun 6, 2019
@masahikokawai masahikokawai deleted the masahikokawai-step12 branch June 6, 2019 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants