Skip to content
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
2 changes: 1 addition & 1 deletion app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create
set_wip
update_published_at
if @product.save
Newspaper.publish(:product_create, { product: @product })
ActiveSupport::Notifications.instrument('product.create', product: @product)
Newspaper.publish(:product_save, { product: @product })
redirect_to Redirection.determin_url(self, @product), notice: notice_message(@product, :create)
else
Expand Down
4 changes: 2 additions & 2 deletions app/models/product_author_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class ProductAuthorWatcher
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
product = payload[:product]
Watch.create!(user: product.user, watchable: product)
Watch.find_or_create_by!(user: product.user, watchable: product)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カスタムクエリで安全性が高まっていいなと思いました👍

end
end
2 changes: 1 addition & 1 deletion app/models/product_notifier_for_colleague.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ProductNotifierForColleague
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
product = payload[:product]
return if product.wip

Expand Down
2 changes: 1 addition & 1 deletion app/models/product_notifier_for_practice_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ProductNotifierForPracticeWatcher
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
product = payload[:product]
return if product.wip

Expand Down
3 changes: 3 additions & 0 deletions config/initializers/active_support_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
ActiveSupport::Notifications.subscribe('article.create', ArticleNotifier.new)
ActiveSupport::Notifications.subscribe('article.destroy', ArticleNotificationDestroyer.new)
ActiveSupport::Notifications.subscribe('work.create', WorkNotifier.new)
ActiveSupport::Notifications.subscribe('product.create', ProductAuthorWatcher.new)
ActiveSupport::Notifications.subscribe('product.create', ProductNotifierForColleague.new)
ActiveSupport::Notifications.subscribe('product.create', ProductNotifierForPracticeWatcher.new)
end
6 changes: 0 additions & 6 deletions config/initializers/newspaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

Newspaper.subscribe(:comeback_update, ComebackNotifier.new)

Newspaper.subscribe(:product_create, ProductAuthorWatcher.new)

learning_status_updater = LearningStatusUpdater.new
Newspaper.subscribe(:check_create, learning_status_updater)
Newspaper.subscribe(:product_save, learning_status_updater)
Expand All @@ -36,10 +34,6 @@
Newspaper.subscribe(:page_create, page_notifier)
Newspaper.subscribe(:page_update, page_notifier)

Newspaper.subscribe(:product_save, ProductNotifierForColleague.new)

Newspaper.subscribe(:product_save, ProductNotifierForPracticeWatcher.new)

mentors_watch_for_question_creator = MentorsWatchForQuestionCreator.new
Newspaper.subscribe(:question_create, mentors_watch_for_question_creator)
Newspaper.subscribe(:question_update, mentors_watch_for_question_creator)
Expand Down
9 changes: 8 additions & 1 deletion test/models/product_notifier_for_practice_watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ class ProductNotifierForPracticeWatcherTest < ActiveSupport::TestCase
)
product.save!

payload = { product: }
perform_enqueued_jobs do
ProductNotifierForPracticeWatcher.new.call({ product: })
ProductNotifierForPracticeWatcher.new.call(
'product_create',
Time.current,
Time.current,
'unique_id',
payload
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使わない引数でも、nilを使わずにラベリングすると可読性が高くなりますね!💡

end
assert Notification.where(user_id: watch.user_id, sender_id: product.user_id,
message: "#{product.user.login_name}さんが「#{product.practice.title}」の提出物を提出しました。").exists?
Expand Down