Skip to content

Commit

Permalink
Constantize if proc/method returns a string for fetch_constant
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Mar 21, 2024
1 parent beb4100 commit 5d559b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/noticed/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def deliver
end

def fetch_constant(name)
option = config[name]
option.is_a?(String) ? option.constantize : evaluate_option(option)
option = evaluate_option(name)
option.is_a?(String) ? option.constantize : option
end

def evaluate_option(name)
Expand Down
8 changes: 7 additions & 1 deletion test/delivery_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ class DeliveryMethodTest < ActiveSupport::TestCase
class InheritedDeliveryMethod < Noticed::DeliveryMethods::ActionCable
end

test "fetch_constant looks up constants" do
test "fetch_constant looks up constants from String" do
@delivery_method = Noticed::DeliveryMethod.new
set_config(mailer: "UserMailer")
assert_equal UserMailer, @delivery_method.fetch_constant(:mailer)
end

test "fetch_constant looks up constants from proc that returns String" do
@delivery_method = Noticed::DeliveryMethod.new
set_config(mailer: ->{ "UserMailer" })
assert_equal UserMailer, @delivery_method.fetch_constant(:mailer)
end

test "delivery methods inherit required options" do
assert_equal [:message], InheritedDeliveryMethod.required_option_names
end
Expand Down

0 comments on commit 5d559b5

Please sign in to comment.