about summary refs log tree commit diff
diff options
context:
space:
mode:
authoralpaca-tc <alpaca-tc@alpaca.tc>2017-05-07 06:06:52 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-06 23:06:52 +0200
commit74036a2c9dba8fad553f13669f265340cd67279a (patch)
treee6c868a1d1cff2719732c09f6cde46704d5f1580
parent05b72368ed56f23e247d28c2798789f91bb096c5 (diff)
Hotfix convert string from symbol (#2856)
* Convert key to string from symbol

* Prefer :public_send instead of
-rw-r--r--app/services/notify_service.rb4
-rw-r--r--spec/services/notify_service_spec.rb38
2 files changed, 40 insertions, 2 deletions
diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb
index 00f7cbd00..9c7eb26ef 100644
--- a/app/services/notify_service.rb
+++ b/app/services/notify_service.rb
@@ -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
index 000000000..86848e1ff
--- /dev/null
+++ b/spec/services/notify_service_spec.rb
@@ -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