Skip to content

Commit

Permalink
Configuration with defaults now created if initializer file does not …
Browse files Browse the repository at this point in the history
…exist and #configuration is called
  • Loading branch information
BradyBonnette committed Jul 19, 2016
1 parent 2b75265 commit 69805d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/sparkpost_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class << self
attr_accessor :configuration
end

def self.configuration
@configuration ||= Configuration.new
end

def self.configure
self.configuration ||= Configuration.new
yield(configuration)
Expand Down
12 changes: 12 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

describe "SparkPostRails configuration" do
let(:delivery_method) { SparkPostRails::DeliveryMethod.new }

describe "#configuration" do
it "creates a new configuration + defaults if #configure is never called", skip_configure: true do
config = SparkPostRails.configuration
expect(config).to_not be_nil
end
end
end
12 changes: 7 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

RSpec.configure do |config|

config.before(:all) do
SparkPostRails.configure do |c|
c.api_key = "TESTKEY1234"
config.before(:each) do |example|
if example.metadata[:skip_configure]
SparkPostRails.configuration = nil # Reset configuration
else
SparkPostRails.configure do |c|
c.api_key = "TESTKEY1234"
end
end
end

config.before(:each) do
stub_request(:any, "https://api.sparkpost.com/api/v1/transmissions").
to_return(body: "{\"results\":{\"total_rejected_recipients\":0,\"total_accepted_recipients\":1,\"id\":\"00000000000000000\"}}", status: 200)
end
Expand Down

0 comments on commit 69805d6

Please sign in to comment.