-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from ivanovv/httpparty-options
Make HTTParty options configurable
- Loading branch information
Showing
6 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "Bamboozled::API::Base" do | ||
it "takes HTTParty options as a constructor parameter" do | ||
expect { Bamboozled::API::Base.new("x", "x", { log_format: :curl }) }.not_to raise_error | ||
end | ||
|
||
it "uses passed HTTParty options" do | ||
response = double("response", code: 200, body: "{}", to_str: "{}") | ||
|
||
expect(HTTParty).to receive(:get). | ||
with("https://api.bamboohr.com/api/gateway.php/x/v1/test", hash_including(log_format: :curl)). | ||
and_return(response) | ||
|
||
base = Bamboozled::API::Base.new("x", "x", { log_format: :curl }) | ||
base.send(:request, :get, "test") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "Bamboozled::Base" do | ||
let(:base) { Bamboozled::Base.new(subdomain: "x", api_key: "x", httparty_options: {log_format: :curl}) } | ||
|
||
it "passes HTTParty options to Bamboozled::API::Employee constructor" do | ||
expect(Bamboozled::API::Employee).to receive(:new).with("x", "x", { log_format: :curl }) | ||
base.employee | ||
end | ||
it "passes HTTParty options to Bamboozled::API::Report constructor" do | ||
expect(Bamboozled::API::Report).to receive(:new).with("x", "x", { log_format: :curl }) | ||
base.report | ||
end | ||
it "passes HTTParty options to Bamboozled::API::Meta constructor" do | ||
expect(Bamboozled::API::Meta).to receive(:new).with("x", "x", { log_format: :curl }) | ||
base.meta | ||
end | ||
it "passes HTTParty options to Bamboozled::API::TimeOff constructor" do | ||
expect(Bamboozled::API::TimeOff).to receive(:new).with("x", "x", { log_format: :curl }) | ||
base.time_off | ||
end | ||
it "passes HTTParty options to Bamboozled::API::TimeTracking constructor" do | ||
expect(Bamboozled::API::TimeTracking).to receive(:new).with("x", "x", { log_format: :curl }) | ||
base.time_tracking | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "Bamboozled" do | ||
it "takes HTTParty options as a parameter" do | ||
expect(Bamboozled::Base).to receive(:new).with(subdomain: "x", api_key: "x", httparty_options: { log_format: :curl }) | ||
Bamboozled.client(subdomain: "x", api_key: "x", httparty_options: { log_format: :curl }) | ||
end | ||
|
||
it "throws no errors if no HTTParty options were provided (they are optional)" do | ||
expect { Bamboozled.client(subdomain: "x", api_key: "x") }.not_to raise_error | ||
end | ||
|
||
it "passes HTTParty params to HTTParty" do | ||
logger = double("logger") | ||
allow(Time).to receive_message_chain(:now, :strftime).and_return("Time.now") | ||
expect(logger).to receive(:info).with('[HTTParty] [Time.now] 200 "GET https://api.bamboohr.com/api/gateway.php/x/v1/employees/1234?fields=" - ') | ||
|
||
client = Bamboozled.client(subdomain: "x", api_key: "x", httparty_options: { log_format: :apache, logger: logger }) | ||
response = File.new("spec/fixtures/one_employee.json") | ||
stub_request(:any, /.*api\.bamboohr\.com.*/).to_return(response) | ||
|
||
employee = client.employee.find(1234) | ||
end | ||
|
||
it "works without HTTParty options provided" do | ||
client = Bamboozled.client(subdomain: "x", api_key: "x") | ||
response = File.new("spec/fixtures/one_employee.json") | ||
stub_request(:any, /.*api\.bamboohr\.com.*/).to_return(response) | ||
|
||
employee = client.employee.find(1234) | ||
expect(employee["firstName"]).to eq "John" | ||
end | ||
end |