Update rubocop to 2.3.1.

This commit is contained in:
Guo Xiang Tan
2020-07-24 17:19:21 +08:00
parent a9905ef7e5
commit c6202af005
24 changed files with 360 additions and 210 deletions
+66 -22
View File
@@ -5,6 +5,7 @@ require 'rails_helper'
describe NotificationEmailer do
before do
freeze_time
NotificationEmailer.enable
end
@@ -24,37 +25,65 @@ describe NotificationEmailer do
shared_examples "enqueue" do
it "enqueues a job for the email" do
Jobs.expects(:enqueue_in).with(delay, :user_email, NotificationEmailer::EmailUser.notification_params(notification, type))
NotificationEmailer.process_notification(notification)
expect_enqueued_with(
job: :user_email,
args: NotificationEmailer::EmailUser.notification_params(notification, type),
at: Time.zone.now + delay
) do
NotificationEmailer.process_notification(notification)
end
end
context "inactive user" do
before { notification.user.active = false }
it "doesn't enqueue a job" do
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
NotificationEmailer.process_notification(notification)
expect_not_enqueued_with(job: :user_email, args: { type: type }) do
NotificationEmailer.process_notification(notification)
end
end
it "enqueues a job if the user is staged for non-linked and non-quoted types" do
notification.user.staged = true
if type == :user_linked || type == :user_quoted
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
expect_not_enqueued_with(
job: :user_email,
args: { type: type }
) do
NotificationEmailer.process_notification(notification)
end
else
Jobs.expects(:enqueue_in).with(delay, :user_email, NotificationEmailer::EmailUser.notification_params(notification, type))
expect_enqueued_with(
job: :user_email,
args: NotificationEmailer::EmailUser.notification_params(notification, type),
at: Time.zone.now + delay
) do
NotificationEmailer.process_notification(notification)
end
end
NotificationEmailer.process_notification(notification)
end
it "enqueues a job if the user is staged even if site requires user approval for non-linked and non-quoted typed" do
notification.user.staged = true
SiteSetting.must_approve_users = true
if type == :user_linked || type == :user_quoted
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
expect_not_enqueued_with(
job: :user_email,
args: { type: type }
) do
NotificationEmailer.process_notification(notification)
end
else
Jobs.expects(:enqueue_in).with(delay, :user_email, NotificationEmailer::EmailUser.notification_params(notification, type))
expect_enqueued_with(
job: :user_email,
args: NotificationEmailer::EmailUser.notification_params(notification, type),
at: Time.zone.now + delay
) do
NotificationEmailer.process_notification(notification)
end
end
NotificationEmailer.process_notification(notification)
end
end
@@ -66,8 +95,9 @@ describe NotificationEmailer do
end
it "doesn't enqueue a job" do
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
NotificationEmailer.process_notification(notification)
expect_not_enqueued_with(job: :user_email, args: { type: type }) do
NotificationEmailer.process_notification(notification)
end
end
end
@@ -75,8 +105,10 @@ describe NotificationEmailer do
it "doesn't enqueue a job" do
Post.any_instance.expects(:post_type).returns(Post.types[:small_action])
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
NotificationEmailer.process_notification(notification)
expect_not_enqueued_with(job: :user_email, args: { type: type }) do
NotificationEmailer.process_notification(notification)
end
end
end
@@ -88,8 +120,10 @@ describe NotificationEmailer do
it "doesn't enqueue a job if the user has mention emails disabled" do
notification.user.user_option.update_columns(email_level: UserOption.email_level_types[:never])
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
NotificationEmailer.process_notification(notification)
expect_not_enqueued_with(job: :user_email, args: { type: type }) do
NotificationEmailer.process_notification(notification)
end
end
end
@@ -98,8 +132,10 @@ describe NotificationEmailer do
it "doesn't enqueue a job if the user has private message emails disabled" do
notification.user.user_option.update_columns(email_messages_level: UserOption.email_level_types[:never])
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
NotificationEmailer.process_notification(notification)
expect_not_enqueued_with(job: :user_email, args: { type: type }) do
NotificationEmailer.process_notification(notification)
end
end
end
@@ -113,8 +149,14 @@ describe NotificationEmailer do
it "enqueue a delayed job for users that are online" do
notification.user.last_seen_at = 1.minute.ago
Jobs.expects(:enqueue_in).with(delay, :user_email, NotificationEmailer::EmailUser.notification_params(notification, type))
NotificationEmailer.process_notification(notification)
expect_enqueued_with(
job: :user_email,
args: NotificationEmailer::EmailUser.notification_params(notification, type),
at: Time.zone.now + delay
) do
NotificationEmailer.process_notification(notification)
end
end
end
@@ -160,8 +202,10 @@ describe NotificationEmailer do
it "doesn't enqueue a job for a small action" do
notification.data_hash["original_post_type"] = Post.types[:small_action]
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
NotificationEmailer.process_notification(notification)
expect_not_enqueued_with(job: :user_email, args: { type: type }) do
NotificationEmailer.process_notification(notification)
end
end
end
+15 -7
View File
@@ -11,8 +11,9 @@ describe UserActivator do
user = Fabricate(:user)
activator = EmailActivator.new(user, nil, nil, nil)
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: user.email_tokens.first.token))
activator.activate
expect_enqueued_with(job: :critical_user_email, args: { type: :signup, email_token: user.email_tokens.first.token }) do
activator.activate
end
end
it 'creates and send new email token if the existing token expired' do
@@ -24,12 +25,19 @@ describe UserActivator do
email_token.update_column(:created_at, 48.hours.ago)
activator = EmailActivator.new(user, nil, nil, nil)
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: email_token.token)).never
activator.activate
expect_not_enqueued_with(job: :critical_user_email, args: { type: :signup, user_id: user.id, email_token: email_token.token }) do
activator.activate
end
user.reload
expect(user.email_tokens.last.created_at).to eq_time(now)
email_token = user.reload.email_tokens.last
expect(job_enqueued?(job: :critical_user_email, args: {
type: :signup,
user_id: user.id,
email_token: email_token.token
})).to eq(true)
expect(email_token.created_at).to eq_time(now)
end
end