Skip to content

Commit

Permalink
Add tests for Notifiable#notification_action_cable_api_allowed?
Browse files Browse the repository at this point in the history
  • Loading branch information
simukappu committed Feb 3, 2020
1 parent e8b5682 commit bd6e5e2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions spec/concerns/models/notifiable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,70 @@ def custom_notification_action_cable_allowed?(target, key)
end
end

describe "#notification_action_cable_api_allowed?" do
context "without any configuration" do
it "returns ActivityNotification.config.action_cable_api_enabled" do
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key'))
.to eq(ActivityNotification.config.action_cable_api_enabled)
end

it "returns false as default" do
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to be_falsey
end
end

context "configured with overridden method" do
it "returns specified value" do
module AdditionalMethods
def notification_action_cable_api_allowed_for_users?(target, key)
true
end
end
test_instance.extend(AdditionalMethods)
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
end
end

context "configured with a field" do
it "returns specified value" do
described_class._notification_action_cable_api_allowed[:users] = true
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
end

it "returns specified symbol without arguments" do
module AdditionalMethods
def custom_notification_action_cable_api_allowed?
true
end
end
test_instance.extend(AdditionalMethods)
described_class._notification_action_cable_api_allowed[:users] = :custom_notification_action_cable_api_allowed?
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
end

it "returns specified symbol with target and key arguments" do
module AdditionalMethods
def custom_notification_action_cable_api_allowed?(target, key)
true
end
end
test_instance.extend(AdditionalMethods)
described_class._notification_action_cable_api_allowed[:users] = :custom_notification_action_cable_api_allowed?
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
end

it "returns specified lambda with single notifiable argument" do
described_class._notification_action_cable_api_allowed[:users] = ->(notifiable){ true }
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
end

it "returns specified lambda with notifiable, target and key arguments" do
described_class._notification_action_cable_api_allowed[:users] = ->(notifiable, target, key){ true }
expect(test_instance.notification_action_cable_api_allowed?(test_target, 'dummy_key')).to eq(true)
end
end
end

describe "#notifiable_path" do
context "without any configuration" do
it "raises NotImplementedError" do
Expand Down

0 comments on commit bd6e5e2

Please sign in to comment.