From eac4f6e1d0e28d224020c777fa4987492c3ca1b4 Mon Sep 17 00:00:00 2001 From: UYO123 Date: Thu, 4 Mar 2021 11:15:49 +0900 Subject: [PATCH 1/2] =?UTF-8?q?add:=20=E3=82=BF=E3=82=B9=E3=82=AF=E4=B8=80?= =?UTF-8?q?=E8=A6=A7=E3=82=92=E4=BD=9C=E6=88=90=E6=97=A5=E6=99=82=E3=81=AE?= =?UTF-8?q?=E9=A0=86=E7=95=AA=E3=81=A7=E4=B8=A6=E3=81=B3=E6=9B=BF=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yaraneba/.rubocop.yml | 4 ++++ yaraneba/app/controllers/tasks_controller.rb | 2 +- yaraneba/app/views/tasks/index.html.erb | 14 ++++++++------ yaraneba/config/locales/views/ja.yml | 1 + yaraneba/spec/factories/tasks.rb | 1 + yaraneba/spec/system/tasks_spec.rb | 10 ++++++++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/yaraneba/.rubocop.yml b/yaraneba/.rubocop.yml index 419e08c7ef..6fb7d530ee 100644 --- a/yaraneba/.rubocop.yml +++ b/yaraneba/.rubocop.yml @@ -2,6 +2,10 @@ inherit_gem: fablicop: - "config/.base_rubocop.yml" +Rails/DynamicFindBy: + Whitelist: + - find_by_id + Style/FrozenStringLiteralComment: Exclude: - 'db/**/*' diff --git a/yaraneba/app/controllers/tasks_controller.rb b/yaraneba/app/controllers/tasks_controller.rb index c9c3094002..f9329f8e51 100644 --- a/yaraneba/app/controllers/tasks_controller.rb +++ b/yaraneba/app/controllers/tasks_controller.rb @@ -5,7 +5,7 @@ class TasksController < ApplicationController # GET /tasks or /tasks.json def index - @tasks = Task.all + @tasks = Task.all.order(created_at: 'DESC') end # GET /tasks/1 or /tasks/1.json diff --git a/yaraneba/app/views/tasks/index.html.erb b/yaraneba/app/views/tasks/index.html.erb index 0289791e08..b53c85aeb9 100644 --- a/yaraneba/app/views/tasks/index.html.erb +++ b/yaraneba/app/views/tasks/index.html.erb @@ -10,18 +10,20 @@ <%= I18n.t('tasks.common.status') %> <%= I18n.t('tasks.common.priority') %> <%= I18n.t('tasks.common.end_date') %> + <%= I18n.t('tasks.common.created_at') %> - <% @tasks.each do |task| %> + <% @tasks.each_with_index do |task, i| %> - <%= task.title %> - <%= task.detail %> - <%= task.status %> - <%= task.priority %> - <%= task.end_date %> + <%= task.title %> + <%= task.detail %> + <%= task.status %> + <%= task.priority %> + <%= task.end_date %> + <%= task.created_at%> <%= link_to I18n.t('tasks.common.show'), task %> <%= link_to I18n.t('tasks.common.edit'), edit_task_path(task) %> <%= link_to I18n.t('tasks.common.destroy'), task, method: :delete, data: { confirm: I18n.t('tasks.index.confirm') } %> diff --git a/yaraneba/config/locales/views/ja.yml b/yaraneba/config/locales/views/ja.yml index d35d7f2d3e..b696a20063 100644 --- a/yaraneba/config/locales/views/ja.yml +++ b/yaraneba/config/locales/views/ja.yml @@ -6,6 +6,7 @@ ja: status: 'ステータス' priority: '優先順位' end_date: '終了予定日' + created_at: '作成日時' show: '詳細' edit: '編集' destroy: '削除' diff --git a/yaraneba/spec/factories/tasks.rb b/yaraneba/spec/factories/tasks.rb index 069dfff005..77479502a9 100644 --- a/yaraneba/spec/factories/tasks.rb +++ b/yaraneba/spec/factories/tasks.rb @@ -6,5 +6,6 @@ status { '1' } end_date { Date.yesterday } deleted_at { nil } + sequence(:created_at) { |n| Time.zone.now.since(n.day) } end end diff --git a/yaraneba/spec/system/tasks_spec.rb b/yaraneba/spec/system/tasks_spec.rb index ce4c58090d..36e515a9bc 100644 --- a/yaraneba/spec/system/tasks_spec.rb +++ b/yaraneba/spec/system/tasks_spec.rb @@ -3,7 +3,17 @@ require 'rails_helper' RSpec.describe 'Tasks', type: :system do + let!(:task) { create_list(:task, 10) } + describe '#task' do + it 'index task' do + visit root_path + + 9.times do |i| + expect(page.find_by_id("created_at-#{i}").text).to be > page.find_by_id("created_at-#{i + 1}").text + end + end + it 'create task' do visit new_task_path fill_in 'task_title', with: 'title' From 09937cae956644988f7f3f14623dbb78f2ed65fa Mon Sep 17 00:00:00 2001 From: UYO123 Date: Thu, 4 Mar 2021 12:20:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E4=BA=8B=E9=A0=85=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yaraneba/.rubocop.yml | 4 ++-- yaraneba/app/controllers/tasks_controller.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yaraneba/.rubocop.yml b/yaraneba/.rubocop.yml index 6fb7d530ee..0feb553e28 100644 --- a/yaraneba/.rubocop.yml +++ b/yaraneba/.rubocop.yml @@ -3,8 +3,8 @@ inherit_gem: - "config/.base_rubocop.yml" Rails/DynamicFindBy: - Whitelist: - - find_by_id + Exclude: + - 'spec/system/*' Style/FrozenStringLiteralComment: Exclude: diff --git a/yaraneba/app/controllers/tasks_controller.rb b/yaraneba/app/controllers/tasks_controller.rb index f9329f8e51..064f98566f 100644 --- a/yaraneba/app/controllers/tasks_controller.rb +++ b/yaraneba/app/controllers/tasks_controller.rb @@ -5,7 +5,7 @@ class TasksController < ApplicationController # GET /tasks or /tasks.json def index - @tasks = Task.all.order(created_at: 'DESC') + @tasks = Task.all.order(created_at: :desc) end # GET /tasks/1 or /tasks/1.json