spec/cases/api_spec.rb in koala-1.9.0 vs spec/cases/api_spec.rb in koala-1.10.0rc
- old
+ new
@@ -28,10 +28,25 @@
).and_return(Koala::HTTPService::Response.new(200, "", ""))
service.api('anything')
end
+ it "doesn't add token to received arguments" do
+ token = 'adfadf'
+ service = Koala::Facebook::API.new token
+
+ expect(Koala).to receive(:make_request).with(
+ anything,
+ hash_including('access_token' => token),
+ anything,
+ anything
+ ).and_return(Koala::HTTPService::Response.new(200, "", ""))
+
+ args = {}.freeze
+ service.api('anything', args)
+ end
+
it "has an attr_reader for access token" do
token = 'adfadf'
service = Koala::Facebook::API.new token
expect(service.access_token).to eq(token)
end
@@ -115,21 +130,60 @@
expect(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(200, 'false', {}))
expect(@service.api('anything')).to be_falsey
end
- describe "with regard to leading slashes" do
- it "adds a leading / to the path if not present" do
- path = "anything"
- expect(Koala).to receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
- @service.api(path)
+ describe "path manipulation" do
+ context "leading /" do
+ it "adds a leading / to the path if not present" do
+ path = "anything"
+ expect(Koala).to receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
+ @service.api(path)
+ end
+
+ it "doesn't change the path if a leading / is present" do
+ path = "/anything"
+ expect(Koala).to receive(:make_request).with(path, anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
+ @service.api(path)
+ end
end
- it "doesn't change the path if a leading / is present" do
- path = "/anything"
- expect(Koala).to receive(:make_request).with(path, anything, anything, anything).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
- @service.api(path)
+ context "API versions" do
+ let(:path) { "/anything" }
+
+ it "adds a version if specified by Koala.config" do
+ Koala.config.api_version = "v1000.000"
+ expect(Koala).to receive(:make_request).with(
+ "/#{Koala.config.api_version}#{path}",
+ anything,
+ anything,
+ anything
+ ).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
+ @service.api(path)
+ end
+
+ it "prefers a version set in the options" do
+ Koala.config.api_version = "v1000.000"
+ version = "v2.0"
+ expect(Koala).to receive(:make_request).with(
+ "/#{version}#{path}",
+ anything,
+ anything,
+ anything
+ ).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
+ @service.api(path, {}, "get", api_version: "v2.0")
+ end
+
+ it "doesn't include a version if not specified" do
+ expect(Koala).to receive(:make_request).with(
+ path,
+ anything,
+ anything,
+ anything
+ ).and_return(Koala::HTTPService::Response.new(200, 'true', {}))
+ @service.api(path)
+ end
end
end
describe "with an access token" do
before(:each) do
@@ -171,37 +225,37 @@
describe "with an API access token present" do
describe "and with an appsecret included on API initialization " do
let(:api) { Koala::Facebook::API.new(access_token, appsecret) }
it "will be included by default" do
- Koala.should_receive(:make_request).with(path, token_args.merge(appsecret_proof_args), verb, {}).and_return(response)
+ expect(Koala).to receive(:make_request).with(path, token_args.merge(appsecret_proof_args), verb, {}).and_return(response)
api.api(path, {}, verb, :appsecret_proof => true)
end
end
describe "but without an appsecret included on API initialization" do
it "will not be included" do
- Koala.should_receive(:make_request).with(path, token_args, verb, {}).and_return(response)
+ expect(Koala).to receive(:make_request).with(path, token_args, verb, {}).and_return(response)
api.api(path, {}, verb, :appsecret_proof => true)
end
end
end
describe "but without an API access token present" do
describe "and with an appsecret included on API initialization " do
let(:api) { Koala::Facebook::API.new(nil, appsecret) }
it "will not be included" do
- Koala.should_receive(:make_request).with(path, {}, verb, {}).and_return(response)
+ expect(Koala).to receive(:make_request).with(path, {}, verb, {}).and_return(response)
api.api(path, {}, verb, :appsecret_proof => true)
end
end
describe "but without an appsecret included on API initialization" do
let(:api) { Koala::Facebook::API.new }
it "will not be included" do
- Koala.should_receive(:make_request).with(path, {}, verb, {}).and_return(response)
+ expect(Koala).to receive(:make_request).with(path, {}, verb, {}).and_return(response)
api.api(path, {}, verb, :appsecret_proof => true)
end
end
end
end