Skip to content

Commit

Permalink
Merge pull request #7323 from fjordllc/feature/apply-rubocop-rule-6
Browse files Browse the repository at this point in the history
Style/HashSyntaxを10個のファイルに適用
  • Loading branch information
komagata authored Feb 15, 2024
2 parents 9c0bfed + ce25f74 commit 96088c2
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 43 deletions.
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,3 @@ Style/HashSyntax:
- 'test/models/category_test.rb'
- 'test/models/discord/times_channel_test.rb'
- 'test/models/event_test.rb'
- 'test/models/product_test.rb'
- 'test/models/question_test.rb'
- 'test/models/regular_event/participants_creator.rb'
- 'test/models/regular_event/participants_watcher_test.rb'
- 'test/models/regular_event_test.rb'
- 'test/models/user_test.rb'
- 'test/notifiers/discord_notifier_test.rb'
- 'test/supports/api_helper.rb'
- 'test/supports/tag_helper.rb'
- 'test/system/announcements_test.rb'
12 changes: 6 additions & 6 deletions test/models/product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProductTest < ActiveSupport::TestCase
test 'delete associated notification' do
user = users(:kimura)
practice = practices(:practice5)
product = Product.create!(practice: practice, user: user, body: 'test')
product = Product.create!(practice:, user:, body: 'test')
product.destroy
assert_not Notification.where(link: "/products/#{product.id}").exists?
end
Expand All @@ -18,7 +18,7 @@ class ProductTest < ActiveSupport::TestCase
product = Product.new(
body: 'test',
user: trainee,
practice: practice
practice:
)
product.save!
assert_not_nil Watch.find_by(user: adviser, watchable: product)
Expand All @@ -31,7 +31,7 @@ class ProductTest < ActiveSupport::TestCase
product = Product.new(
body: 'test',
user: trainee,
practice: practice,
practice:,
wip: true
)
product.save!
Expand All @@ -49,13 +49,13 @@ class ProductTest < ActiveSupport::TestCase
practice = practices(:practice5)
product = Product.create!(
body: 'test',
user: user,
practice: practice
user:,
practice:
)

status = :complete
product.change_learning_status(status)
assert Learning.find_by(user: user, practice: practice, status: :complete)
assert Learning.find_by(user:, practice:, status: :complete)
end

test '#category' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/question_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class QuestionTest < ActiveSupport::TestCase
first_answer = Answer.create!(
description: '最初の回答',
user: answerer,
question: question,
question:,
created_at: '2022-11-01',
updated_at: '2022-11-01'
)

last_answer = Answer.create!(
description: '最後の回答',
user: answerer,
question: question,
question:,
created_at: '2022-11-02',
updated_at: '2022-11-02'
)
Expand Down
4 changes: 2 additions & 2 deletions test/models/regular_event/participants_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ParticipantsCreatorTest < ActiveSupport::TestCase
test '.call' do
regular_event = regular_events(:regular_event3)
target = User.students_and_trainees.ids
RegularEvent::ParticipantsCreator.call(regular_event: regular_event, target: target)
RegularEvent::ParticipantsCreator.call(regular_event:, target:)

assert_equal regular_event.regular_event_participations.count, target.count
end
Expand All @@ -15,7 +15,7 @@ class ParticipantsCreatorTest < ActiveSupport::TestCase
regular_event = regular_events(:regular_event3)
target = User.students_and_trainees.ids
date_time = Time.current.end_of_day.floor
RegularEvent::ParticipantsCreator.call(regular_event: regular_event, target: target, date_time: date_time)
RegularEvent::ParticipantsCreator.call(regular_event:, target:, date_time:)

assert_equal regular_event.regular_event_participations.count, target.count
assert_equal regular_event.regular_event_participations.first.created_at, date_time
Expand Down
4 changes: 2 additions & 2 deletions test/models/regular_event/participants_watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ParticipantsWatcherTest < ActiveSupport::TestCase
test '.call' do
regular_event = regular_events(:regular_event3)
target = User.students_and_trainees.ids - regular_event.watches.pluck(:user_id)
RegularEvent::ParticipantsWatcher.call(regular_event: regular_event, target: target)
RegularEvent::ParticipantsWatcher.call(regular_event:, target:)

assert_equal regular_event.watches.count, target.count
end
Expand All @@ -15,7 +15,7 @@ class ParticipantsWatcherTest < ActiveSupport::TestCase
regular_event = regular_events(:regular_event3)
target = User.students_and_trainees.ids - regular_event.watches.pluck(:user_id)
date_time = Time.current.end_of_day.floor
RegularEvent::ParticipantsWatcher.call(regular_event: regular_event, target: target, date_time: date_time)
RegularEvent::ParticipantsWatcher.call(regular_event:, target:, date_time:)

assert_equal regular_event.watches.count, target.count
assert_equal regular_event.watches.first.created_at, date_time
Expand Down
2 changes: 1 addition & 1 deletion test/models/regular_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class RegularEventTest < ActiveSupport::TestCase
user = users(:kimura)
assert_not regular_event.watched_by?(user)

watch = Watch.new(user: user, watchable: regular_event)
watch = Watch.new(user:, watchable: regular_event)
watch.save
assert regular_event.watched_by?(user)
end
Expand Down
24 changes: 12 additions & 12 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ class UserTest < ActiveSupport::TestCase
today = Time.zone.today

Learning.create!(
user: user,
user:,
practice: practice1,
status: :complete,
created_at: (today - 2.weeks).to_formatted_s(:db),
updated_at: (today - 2.weeks).to_formatted_s(:db)
)

Learning.create!(
user: user,
user:,
practice: practice2,
status: :complete,
created_at: (today - (2.weeks + 1.day)).to_formatted_s(:db),
Expand All @@ -411,7 +411,7 @@ class UserTest < ActiveSupport::TestCase
today = Time.zone.today

Learning.create!(
user: user,
user:,
practice: Practice.first,
status: :complete,
created_at: (today - (2.weeks - 1.day)).to_formatted_s(:db),
Expand All @@ -429,7 +429,7 @@ class UserTest < ActiveSupport::TestCase
today = Time.zone.today

Learning.create!(
user: user,
user:,
practice: practice1,
status: :complete,
created_at: (today - 2.weeks).to_formatted_s(:db),
Expand Down Expand Up @@ -680,26 +680,26 @@ class UserTest < ActiveSupport::TestCase
allowed_targets = %w[student_and_trainee mentor graduate adviser trainee year_end_party]

# target引数とdefault_target引数に関して、targetとscope名が一致しているケースと一致していないケースを順にテストする
assert_equal User.mentor, User.users_role('mentor', allowed_targets: allowed_targets, default_target: 'student_and_trainee')
assert_equal User.graduated, User.users_role('graduate', allowed_targets: allowed_targets, default_target: 'student_and_trainee')
assert_equal User.mentor, User.users_role('mentor', allowed_targets:, default_target: 'student_and_trainee')
assert_equal User.graduated, User.users_role('graduate', allowed_targets:, default_target: 'student_and_trainee')

assert_equal User.year_end_party, User.users_role('', allowed_targets: allowed_targets, default_target: 'year_end_party')
assert_equal User.students_and_trainees, User.users_role('', allowed_targets: allowed_targets, default_target: 'student_and_trainee')
assert_equal User.year_end_party, User.users_role('', allowed_targets:, default_target: 'year_end_party')
assert_equal User.students_and_trainees, User.users_role('', allowed_targets:, default_target: 'student_and_trainee')
end

test '.users_role returns default_target when invalid target is passed' do
allowed_targets = %w[student_and_trainee mentor graduate adviser trainee year_end_party]
not_allowed_target = 'retired'
assert_equal User.students_and_trainees, User.users_role(not_allowed_target, allowed_targets: allowed_targets, default_target: 'student_and_trainee')
assert_equal User.students_and_trainees, User.users_role(not_allowed_target, allowed_targets:, default_target: 'student_and_trainee')
not_scope_name = 'destroy_all'
assert_equal User.students_and_trainees, User.users_role(not_scope_name, allowed_targets: allowed_targets, default_target: 'student_and_trainee')
assert_empty User.users_role(not_scope_name, allowed_targets: allowed_targets)
assert_equal User.students_and_trainees, User.users_role(not_scope_name, allowed_targets:, default_target: 'student_and_trainee')
assert_empty User.users_role(not_scope_name, allowed_targets:)
end

test '#delete_and_assign_new_organizer' do
user = users(:hajime)

assert_changes -> { Organizer.where(user: user).exists? }, from: true, to: false do
assert_changes -> { Organizer.where(user:).exists? }, from: true, to: false do
user.delete_and_assign_new_organizer
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/notifiers/discord_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ class DiscordNotifierTest < ActiveSupport::TestCase
TEXT

params = {
comment: comment,
body: body,
comment:,
body:,
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}

expected = {
body: body,
body:,
name: 'ピヨルド',
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}
Expand Down Expand Up @@ -225,7 +225,7 @@ class DiscordNotifierTest < ActiveSupport::TestCase
URL: http://localhost:3000/reports/819157022
TEXT
expected = {
body: body,
body:,
name: 'ピヨルド',
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}
Expand Down
2 changes: 1 addition & 1 deletion test/supports/api_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module APIHelper
def create_token(login_name, password)
post api_session_url, params: { login_name: login_name, password: password }
post api_session_url, params: { login_name:, password: }
JSON.parse(body)['token']
end
end
2 changes: 1 addition & 1 deletion test/supports/tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def find_tags(taggable_name)
WHERE
taggings.taggable_type = :taggable_name
SQL
ActsAsTaggableOn::Tag.find_by_sql([sql, { taggable_name: taggable_name }]).pluck(:name).sort
ActsAsTaggableOn::Tag.find_by_sql([sql, { taggable_name: }]).pluck(:name).sort
end
end
4 changes: 2 additions & 2 deletions test/system/announcements_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class AnnouncementsTest < ApplicationSystemTestCase
user = users(:komagata)
Announcement.delete_all
26.times do
Announcement.create(title: 'test', description: 'test', user: user)
Announcement.create(title: 'test', description: 'test', user:)
end
visit_with_auth '/announcements', 'kimura'
assert_selector 'nav.pagination', count: 2
end

test 'show WIP message' do
user = users(:komagata)
Announcement.create(title: 'test', description: 'test', user: user, wip: true)
Announcement.create(title: 'test', description: 'test', user:, wip: true)
visit_with_auth '/announcements', 'kimura'
assert_selector '.a-list-item-badge'
assert_text 'お知らせ作成中'
Expand Down

0 comments on commit 96088c2

Please sign in to comment.