-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config cleanup with additional test coverage #168
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,12 +107,8 @@ def compare_property_lists(klass, source, target) | |
end | ||
|
||
def with_hapikey(hapikey) | ||
begin | ||
Hubspot.configure(hapikey: hapikey) unless hapikey.blank? | ||
yield if block_given? | ||
ensure | ||
Hubspot.configure(hapikey: ENV['HUBSPOT_API_KEY']) unless hapikey.blank? | ||
end | ||
Hubspot.configure(hapikey: hapikey) | ||
yield if block_given? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating the config to raise when the an authentication approach is not set resulted in a few tests failing because the ensure block is setting the This method currently: I think it's safe to simplify this method to rely on an |
||
end | ||
|
||
private | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,86 @@ | ||
describe Hubspot::Config do | ||
describe "#configure" do | ||
let(:config){ {hapikey: "demo", base_url: "http://api.hubapi.com/v2", portal_id: "62515"} } | ||
subject{ Hubspot::Config.configure(config) } | ||
describe ".configure" do | ||
it "sets the hapikey config" do | ||
hapikey = "demo" | ||
|
||
it "changes the hapikey config" do | ||
expect{ subject }.to change(Hubspot::Config, :hapikey).to("demo") | ||
config = Hubspot::Config.configure(hapikey: hapikey) | ||
|
||
expect(config.hapikey).to eq(hapikey) | ||
end | ||
|
||
it "changes the base_url" do | ||
expect{ subject }.to change(Hubspot::Config, :base_url).to("http://api.hubapi.com/v2") | ||
base_url = "https://api.hubapi.com/v2" | ||
|
||
config = Hubspot::Config.configure( | ||
hapikey: "123abc", | ||
base_url: base_url | ||
) | ||
|
||
expect(config.base_url).to eq(base_url) | ||
end | ||
|
||
it "sets a default value for base_url" do | ||
Hubspot::Config.base_url.should == "https://api.hubapi.com" | ||
config = Hubspot::Config.configure(hapikey: "123abc") | ||
|
||
expect(config.base_url).to eq("https://api.hubapi.com") | ||
end | ||
|
||
it "sets a value for portal_id" do | ||
expect{ subject }.to change(Hubspot::Config, :portal_id).to("62515") | ||
portal_id = "62515" | ||
|
||
config = Hubspot::Config.configure( | ||
hapikey: "123abc", | ||
portal_id: portal_id | ||
) | ||
|
||
expect(config.portal_id).to eq(portal_id) | ||
end | ||
|
||
it "raises when an authentication approach is not provided" do | ||
expect { | ||
Hubspot::Config.configure({}) | ||
}.to raise_error(Hubspot::ConfigurationError) | ||
end | ||
|
||
it "raises when two authentication approaches are provided" do | ||
expect { | ||
Hubspot::Config.configure({ | ||
hapikey: "123abc", | ||
access_token: "456def", | ||
}) | ||
}.to raise_error(Hubspot::ConfigurationError) | ||
end | ||
end | ||
|
||
describe "#reset!" do | ||
let(:config){ {hapikey: "demo", base_url: "http://api.hubapi.com/v2", portal_id: "62515"} } | ||
before{ Hubspot::Config.configure(config) } | ||
subject{ Hubspot::Config.reset! } | ||
it "clears out the config" do | ||
subject | ||
Hubspot::Config.hapikey.should be_nil | ||
Hubspot::Config.base_url.should == "https://api.hubapi.com" | ||
Hubspot::Config.portal_id.should be_nil | ||
describe ".reset!" do | ||
it "resets the config values" do | ||
Hubspot::Config.configure(hapikey: "123abc", portal_id: "456def") | ||
|
||
Hubspot::Config.reset! | ||
|
||
expect(Hubspot::Config.hapikey).to be nil | ||
expect(Hubspot::Config.portal_id).to be nil | ||
end | ||
end | ||
|
||
describe "#ensure!" do | ||
subject{ Hubspot::Config.ensure!(:hapikey, :base_url, :portal_id)} | ||
before{ Hubspot::Config.configure(config) } | ||
describe ".ensure!" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't necessary to update these tests but I opted to update them to remove the calls to
|
||
context "when a specified parameter is missing" do | ||
it "raises an error" do | ||
Hubspot::Config.configure(hapikey: "123abc") | ||
|
||
context "with a missing parameter" do | ||
let(:config){ {hapikey: "demo", base_url: "http://api.hubapi.com/v2"} } | ||
it "should raise an error" do | ||
expect { subject }.to raise_error Hubspot::ConfigurationError | ||
expect { | ||
Hubspot::Config.ensure!(:portal_id) | ||
}.to raise_error(Hubspot::ConfigurationError) | ||
end | ||
end | ||
|
||
context "with all requried parameters" do | ||
let(:config){ {hapikey: "demo", base_url: "http://api.hubapi.com/v2", portal_id: "62515"} } | ||
it "should not raise an error" do | ||
expect { subject }.to_not raise_error | ||
context "when all specified parameters are present" do | ||
it "does not raise an error" do | ||
Hubspot::Config.configure(hapikey: "123abc", portal_id: "456def") | ||
|
||
expect { | ||
Hubspot::Config.ensure!(:portal_id) | ||
}.not_to raise_error | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you feel about adding a newline between this
private
line and the next method definition?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍