Skip to content

Commit

Permalink
テキストで未アサイン件数を表示する機能を実装、テストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisumi committed Feb 4, 2022
1 parent 6d073d9 commit 425a72c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/api/products/unassigned_text_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class API::Products::UnassignedTextController < API::BaseController
def show
@products = Product
.unassigned
.unchecked
.not_wip
.list
.order_for_not_wip_list
@passed5 = @products.count { |product| product.elapsed_days == 5 }
@passed6 = @products.count { |product| product.elapsed_days == 6 }
@over7 = @products.count { |product| product.elapsed_days >= 7 }
end
end
17 changes: 17 additions & 0 deletions app/views/api/products/unassigned_text/show.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if @passed5 + @passed6 + @over7 > 0 %>
提出されてから日数が経っている提出物の数をお知らせします。

<% if @passed5 > 0 %>
- 5日経過:<%= @passed5 %>
<% end %>
<% if @passed6 > 0 %>
- 6日経過:<%= @passed6 %>
<% end %>
<% if @over7 > 0 %>
- 7日以上経過:<%= @over7 %>
<% end %>

<% else %>
提出されたから5日以上経過している提出物はありません。
メンターの皆様、日々の提出物の確認ありがとうございます。
<% end %>
1 change: 1 addition & 0 deletions config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
namespace :products do
resources :unchecked, only: %i(index)
resources :unassigned, only: %i(index)
resource :unassigned_text, only: %i(show), controller: 'unassigned_text'
resources :self_assigned, only: %i(index)
resource :checker, only: %i(update), controller: 'checker'
resource :passed, only: %i(show), controller: 'passed'
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/products.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ product15:
created_at: <%= 6.day.ago %>
updated_at: <%= 6.day.ago %>
published_at: <%= 6.day.ago %>
checker_id: "<%= ActiveRecord::FixtureSet.identify(:machida) %>"

product16:
practice: practice2
Expand Down
20 changes: 20 additions & 0 deletions test/integration/api/products/unassigned_text_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'test_helper'

class API::Products::UnassignedTextTest < ActionDispatch::IntegrationTest
fixtures :products

test 'GET /api/products/unassigned_text.txt' do
get api_products_unassigned_text_path(format: :text)
assert_response :unauthorized

token = create_token('komagata', 'testtest')
get api_products_unassigned_text_path(format: :text),
headers: { 'Authorization' => "Bearer #{token}" }
assert_response :ok
assert_match '5日経過:1件', response.body
assert_match '6日経過:1件', response.body
assert_match '7日以上経過:6件', response.body
end
end

0 comments on commit 425a72c

Please sign in to comment.