]> cat aescling's git repositories - mastodon.git/commitdiff
Hotfix convert string from symbol (#2856)
authoralpaca-tc <alpaca-tc@alpaca.tc>
Sat, 6 May 2017 21:06:52 +0000 (06:06 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 6 May 2017 21:06:52 +0000 (23:06 +0200)
* Convert key to string from symbol

* Prefer :public_send instead of

app/services/notify_service.rb
spec/services/notify_service_spec.rb [new file with mode: 0644]

index 00f7cbd00cb95598cfc87fcc39c3992a5835f78a..9c7eb26ef489e73796c537b668889051f1cac4d8 100644 (file)
@@ -54,10 +54,10 @@ class NotifyService < BaseService
   end
 
   def send_email
-    NotificationMailer.send(@notification.type, @recipient, @notification).deliver_later
+    NotificationMailer.public_send(@notification.type, @recipient, @notification).deliver_later
   end
 
   def email_enabled?
-    @recipient.user.settings.notification_emails[@notification.type]
+    @recipient.user.settings.notification_emails[@notification.type.to_s]
   end
 end
diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb
new file mode 100644 (file)
index 0000000..86848e1
--- /dev/null
@@ -0,0 +1,38 @@
+require 'rails_helper'
+
+RSpec.describe NotifyService do
+  subject do
+    -> { described_class.new.call(recipient, activity) }
+  end
+
+  let(:user) { Fabricate(:user) }
+  let(:recipient) { user.account }
+  let(:activity) { Fabricate(:follow, target_account: recipient) }
+
+  it { is_expected.to change(Notification, :count).by(1) }
+
+  describe 'email' do
+    before do
+      ActionMailer::Base.deliveries.clear
+
+      notification_emails = user.settings.notification_emails
+      user.settings.notification_emails = notification_emails.merge('follow' => enabled)
+    end
+
+    context 'when email notification is enabled' do
+      let(:enabled) { true }
+
+      it 'sends email' do
+        is_expected.to change(ActionMailer::Base.deliveries, :count).by(1)
+      end
+    end
+
+    context 'when email notification is disabled' do
+      let(:enabled) { false }
+
+      it "doesn't send email" do
+        is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
+      end
+    end
+  end
+end