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

ステップ10: タスク一覧を作成日時の順番で並び替えましょう #928

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions yaraneba/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ inherit_gem:
fablicop:
- "config/.base_rubocop.yml"

Rails/DynamicFindBy:
Exclude:
- 'spec/system/*'

Style/FrozenStringLiteralComment:
Exclude:
- 'db/**/*'
Expand Down
2 changes: 1 addition & 1 deletion yaraneba/app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions yaraneba/app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
<th><%= I18n.t('tasks.common.status') %></th>
<th><%= I18n.t('tasks.common.priority') %></th>
<th><%= I18n.t('tasks.common.end_date') %></th>
<th><%= I18n.t('tasks.common.created_at') %></th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @tasks.each do |task| %>
<% @tasks.each_with_index do |task, i| %>
<tr>
<td><%= task.title %></td>
<td><%= task.detail %></td>
<td><%= task.status %></td>
<td><%= task.priority %></td>
<td><%= task.end_date %></td>
<td id="title-<%= i %>"><%= task.title %></td>
<td id="detail-<%= i %>"><%= task.detail %></td>
<td id="status-<%= i %>"><%= task.status %></td>
<td id="priority-<%= i %>"><%= task.priority %></td>
<td id="end_date-<%= i %>"><%= task.end_date %></td>
<td id="created_at-<%= i %>"><%= task.created_at%></td>
<td><%= link_to I18n.t('tasks.common.show'), task %></td>
<td><%= link_to I18n.t('tasks.common.edit'), edit_task_path(task) %></td>
<td><%= link_to I18n.t('tasks.common.destroy'), task, method: :delete, data: { confirm: I18n.t('tasks.index.confirm') } %></td>
Expand Down
1 change: 1 addition & 0 deletions yaraneba/config/locales/views/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ja:
status: 'ステータス'
priority: '優先順位'
end_date: '終了予定日'
created_at: '作成日時'
show: '詳細'
edit: '編集'
destroy: '削除'
Expand Down
1 change: 1 addition & 0 deletions yaraneba/spec/factories/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions yaraneba/spec/system/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down