Skip to content

Commit

Permalink
Merge pull request #7809 from fjordllc/bug/mismatch_complete_practice…
Browse files Browse the repository at this point in the history
…_size

修了したプラクティスを重複して計算してしまう不具合を修正
  • Loading branch information
komagata authored Jun 24, 2024
2 parents c296f83 + 4e46230 commit 6f436ce
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def cached_completed_percentage
end

def completed_fraction
"修了: #{completed_practices.size} (必須: #{completed_practices_include_progress.size}/#{practices_include_progress.size})"
"修了: #{completed_practices.size} (必須: #{completed_practices_include_progress_size}/#{practices_include_progress.pluck(:id).uniq.size})"
end

def completed_fraction_in_metas
"#{completed_practices.size} (必須:#{completed_practices_include_progress.size})"
"#{completed_practices.size} (必須:#{completed_practices_include_progress_size})"
end

def customer_url
Expand Down
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def away?
end

def completed_percentage
completed_practices_include_progress.size.to_f / practices_include_progress.size * MAX_PERCENTAGE
completed_practices_include_progress_size.to_f / practices_include_progress.pluck(:id).uniq.size * MAX_PERCENTAGE
end

def completed_practices_size_by_category
Expand All @@ -504,9 +504,9 @@ def completed_practices_size_by_category
.count('DISTINCT practices.id')
end

def completed_practices_include_progress
def completed_practices_include_progress_size
practices_include_progress.joins(:learnings)
.merge(Learning.complete.where(user_id: id))
.merge(Learning.complete.where(user_id: id)).pluck(:id).uniq.size
end

def active?
Expand Down
5 changes: 5 additions & 0 deletions db/fixtures/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ category22:
name: "就職活動"
slug: "job-hunting"
description: "就職に向けての準備に入ります。"

category23:
name: "Ruby on Rails(Rails 6.1版)"
slug: "ruby-on-rails"
description: "まずはここからはじめましょう。ここでの学習の進め方を学びます。"
19 changes: 19 additions & 0 deletions db/fixtures/categories_practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,23 @@ categories_practice63:
categories_practice64:
practice: practice64
category: category10

categories_practice111_1:
practice: practice111
category: category6
position: 14

categories_practice111_2:
practice: practice111
category: category23
position: 2

categories_practice112_1:
practice: practice112
category: category6
position: 15

categories_practice112_2:
practice: practice112
category: category23
position: 3
5 changes: 5 additions & 0 deletions db/fixtures/courses_categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ courses_category26:
course: course4
category: category10
position: 18

courses_category27:
course: course1
category: category23
position: 19
14 changes: 13 additions & 1 deletion db/fixtures/learnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ learning<%= i + 18 %>:

learning23:
user: harikirio
practice: practice1
practice: practice5
status: "complete"
completion_message_displayed: false

Expand All @@ -129,3 +129,15 @@ learning24:
practice: practice61
status: "complete"
completion_message_displayed: false

learning25:
user: harikirio
practice: practice111
status: "complete"
completion_message_displayed: false

learning26:
user: harikirio
practice: practice112
status: "complete"
completion_message_displayed: false
15 changes: 15 additions & 0 deletions db/fixtures/practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,19 @@ practice110:
summary: "概要です"
description: "概要欄(概要文&OGP画像)を表示します"
goal: "goal..."

practice111:
title: "複数カテゴリに所属するプラクティス1"
summary: "概要です"
description: "複数のカテゴリに所属しているプラクティスです(必修ではありません)"
goal: "goal..."
include_progress: false
memo: "memo for mentors..."

practice112:
title: "複数カテゴリに所属するプラクティス2"
summary: "概要です"
description: "複数のカテゴリに所属しているプラクティスです(必修です)"
goal: "goal..."
include_progress: true
memo: "memo for mentors..."
16 changes: 8 additions & 8 deletions test/decorators/user_decorator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,34 @@ class UserDecoratorTest < ActiveDecoratorTestCase

test '#completed_fraction don\'t calculate practice that include_progress: false' do
user = @admin_mentor_user
old_fraction = user.completed_practices_include_progress.size
old_fraction = user.completed_practices_include_progress_size
user.completed_practices << practices(:practice5)

assert_not_equal old_fraction, user.completed_fraction

old_fraction = user.completed_practices_include_progress.size
old_fraction = user.completed_practices_include_progress_size
user.completed_practices << practices(:practice53)

assert_equal old_fraction, user.completed_practices_include_progress.size
assert_equal old_fraction, user.completed_practices_include_progress_size
end

test '#completed_fraction don\'t calculate practice unrelated cource' do
old_fraction = @admin_mentor_user.completed_practices_include_progress.size
old_fraction = @admin_mentor_user.completed_practices_include_progress_size
@admin_mentor_user.completed_practices << practices(:practice5)

assert_not_equal old_fraction, @admin_mentor_user.completed_practices_include_progress.size
assert_not_equal old_fraction, @admin_mentor_user.completed_practices_include_progress_size

old_fraction = @admin_mentor_user.completed_practices_include_progress.size
old_fraction = @admin_mentor_user.completed_practices_include_progress_size
@admin_mentor_user.completed_practices << practices(:practice55)

assert_equal old_fraction, @admin_mentor_user.completed_practices_include_progress.size
assert_equal old_fraction, @admin_mentor_user.completed_practices_include_progress_size
end

test '#completed_fraction_in_metas' do
fraction_in_metas = '2 (必須:1)'
@non_required_subject_completed_user.completed_practices = []
@non_required_subject_completed_user.completed_practices << practices(:practice5)
@non_required_subject_completed_user.completed_practices << practices(:practice61)

assert_equal fraction_in_metas, @non_required_subject_completed_user.completed_fraction_in_metas
end
end
10 changes: 10 additions & 0 deletions test/fixtures/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ category21:
name: "ゲームのテスト"
slug: "game-test"
description: "まずはここからはじめましょう。ここでの学習の進め方を学びます。"

category22:
name: "就職活動"
slug: "job-hunting"
description: "就職に向けての準備に入ります。"

category23:
name: "Ruby on Rails(Rails 6.1版)"
slug: "ruby-on-rails"
description: "まずはここからはじめましょう。ここでの学習の進め方を学びます。"
25 changes: 25 additions & 0 deletions test/fixtures/categories_practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,28 @@ categories_practice57:
practice: practice57
category: category2
position: 3

categories_practice61:
practice: practice61
category: category22
position: 1

categories_practice62_1:
practice: practice62
category: category6
position: 14

categories_practice62_2:
practice: practice62
category: category23
position: 1

categories_practice63_1:
practice: practice63
category: category6
position: 15

categories_practice63_2:
practice: practice63
category: category23
position: 2
10 changes: 10 additions & 0 deletions test/fixtures/courses_categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ courses_category24:
course: course3
category: category15
position: 3

courses_category25:
course: course1
category: category22
position: 17

courses_category26:
course: course1
category: category23
position: 18
25 changes: 25 additions & 0 deletions test/fixtures/learnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,28 @@ learning<%= i + 18 %>:
created_at: <%= (today - (2.weeks - 1.day) - i.day).to_formatted_s(:db) %>
updated_at: <%= (today - (2.weeks - 1.day) - i.day).to_formatted_s(:db) %>
<% end %>


learning23:
user: harikirio
practice: practice5
status: "complete"
completion_message_displayed: false

learning24:
user: harikirio
practice: practice61
status: "complete"
completion_message_displayed: false

learning25:
user: harikirio
practice: practice62
status: "complete"
completion_message_displayed: false

learning26:
user: harikirio
practice: practice63
status: "complete"
completion_message_displayed: false
16 changes: 16 additions & 0 deletions test/fixtures/practices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,19 @@ practice61:
goal: "goal..."
include_progress: false
memo: "memo for mentors..."

practice62:
title: "複数カテゴリに所属するプラクティス1"
summary: "概要です"
description: "複数のカテゴリに所属しているプラクティスです(必修ではありません)"
goal: "goal..."
include_progress: false
memo: "memo for mentors..."

practice63:
title: "複数カテゴリに所属するプラクティス2"
summary: "概要です"
description: "複数のカテゴリに所属しているプラクティスです(必修です)"
goal: "goal..."
include_progress: true
memo: "memo for mentors..."
16 changes: 8 additions & 8 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@ class UserTest < ActiveSupport::TestCase

test '#completed_percentage don\'t calculate practice that include_progress: false' do
user = users(:komagata)
old_percentage = user.completed_practices_include_progress.size
old_percentage = user.completed_percentage
user.completed_practices << practices(:practice5)

assert_not_equal old_percentage, user.completed_practices_include_progress.size
assert_not_equal old_percentage, user.completed_percentage

old_percentage = user.completed_practices_include_progress.size
old_percentage = user.completed_percentage
user.completed_practices << practices(:practice53)

assert_equal old_percentage, user.completed_practices_include_progress.size
assert_equal old_percentage, user.completed_percentage
end

test '#completed_percentage don\'t calculate practice unrelated cource' do
user = users(:komagata)
old_percentage = user.completed_practices_include_progress.size
old_percentage = user.completed_percentage
user.completed_practices << practices(:practice5)

assert_not_equal old_percentage, user.completed_practices_include_progress.size
assert_not_equal old_percentage, user.completed_percentage

old_percentage = user.completed_practices_include_progress.size
old_percentage = user.completed_percentage
user.completed_practices << practices(:practice55)

assert_equal old_percentage, user.completed_practices_include_progress.size
assert_equal old_percentage, user.completed_percentage
end

test '#depressed?' do
Expand Down
1 change: 0 additions & 1 deletion test/system/mentor/categories/practices_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Mentor::Categories::PracticesTest < ApplicationSystemTestCase
visit_with_auth course_practices_path(courses(:course1)), 'kimura'
assert_equal all('span.category-practices-item__title-link-label')[0].text, practices(:practice1).title
assert_equal all('span.category-practices-item__title-link-label')[1].text, practices(:practice3).title

visit_with_auth mentor_category_practices_path(categories(:category2)), 'komagata'
source = all('.js-grab')[0] # practice1
target = all('.js-grab')[2] # practice3
Expand Down
8 changes: 4 additions & 4 deletions test/system/reports_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class ReportsTest < ApplicationSystemTestCase
report_practices = page.all('.choices__item--choice').map(&:text)
current_user = users(:komagata)
category_ids = current_user.course.category_ids
assert_equal report_practices.count, Practice.joins(:categories).merge(Category.where(id: category_ids)).count
assert_equal report_practices.count, Practice.joins(:categories).merge(Category.where(id: category_ids)).distinct.count
assert_match(/OS X Mountain Lionをクリーンインストールする/, first('.choices__item--choice').text)
assert_match(/sslの基礎を理解する/, all('.choices__item--choice').last.text)
assert_match(/企業研究/, all('.choices__item--choice').last.text)
end

test 'equal practices order in practices and edit report' do
Expand All @@ -125,9 +125,9 @@ class ReportsTest < ApplicationSystemTestCase
report_practices = page.all('.choices__item--choice').map(&:text)
current_user = users(:komagata)
category_ids = current_user.course.category_ids
assert_equal report_practices.count, Practice.joins(:categories).merge(Category.where(id: category_ids)).count
assert_equal report_practices.count, Practice.joins(:categories).merge(Category.where(id: category_ids)).distinct.count
assert_match(/OS X Mountain Lionをクリーンインストールする/, first('.choices__item--choice').text)
assert_match(/sslの基礎を理解する/, all('.choices__item--choice').last.text)
assert_match(/企業研究/, all('.choices__item--choice').last.text)
end

test 'issue #360 duplicate' do
Expand Down
6 changes: 4 additions & 2 deletions test/system/user/meta_data_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
class User::MetaDataTest < ApplicationSystemTestCase
test 'show progress percentage and click to check the number of completions' do
user = users(:harikirio)
user.completed_practices << practices(:practice5)
user.completed_practices = []
user.completed_practices << practices(:practice61)
user.completed_practices << practices(:practice62)
user.completed_practices << practices(:practice63)
visit_with_auth "/users/#{users(:harikirio).id}", 'harikirio'
assert_text '1%'
find('.completed-practices-progress__percentage').click
assert_text '修了: 2 (必須: 1/51)'
assert_text '修了: 3 (必須: 1/52)'
end
end

0 comments on commit 6f436ce

Please sign in to comment.