Skip to content

Commit

Permalink
message-specific API key rename
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTVsFrank authored and dgoerlich committed Apr 11, 2016
1 parent 2e821d1 commit 2363e48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ def prepare_additional_mail_headers_from mail
end

def prepare_api_headers_from sparkpost_data
if sparkpost_data.has_key?(:subaccount_api_key)
api_key = sparkpost_data[:subaccount_api_key]
if sparkpost_data.has_key?(:api_key)
api_key = sparkpost_data[:api_key]
else
api_key = SparkPostRails.configuration.api_key
end
Expand Down
10 changes: 5 additions & 5 deletions spec/subaccount_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
@delivery_method = SparkPostRails::DeliveryMethod.new
end

context "Subaccount API Key" do
it "uses supplied subaccount key instead of default API key" do
context "Message-Specific API Key" do
it "uses supplied API key instead of default" do
SparkPostRails.configure do |c|
c.api_key = 'NEW_DEFAULT_API_KEY'
end

test_email = Mailer.test_email sparkpost_data: {subaccount_api_key: 'SUBACCOUNT_API_KEY'}
test_email = Mailer.test_email sparkpost_data: {api_key: 'SUBACCOUNT_API_KEY'}
@delivery_method.deliver!(test_email)

expect(@delivery_method.headers).to include("Authorization" => "SUBACCOUNT_API_KEY")
end

it "uses default API if no subaccount API key applied" do
it "uses default API if no message-specific API key applied" do
SparkPostRails.configure do |c|
c.api_key = 'NEW_DEFAULT_API_KEY'
end
Expand Down Expand Up @@ -58,7 +58,7 @@
SparkPostRails.configure do |c|
c.subaccount = 123
end

test_email = Mailer.test_email sparkpost_data: {subaccount: 456}
@delivery_method.deliver!(test_email)

Expand Down

0 comments on commit 2363e48

Please sign in to comment.