test/createsend_test.rb in createsend-6.0.0 vs test/createsend_test.rb in createsend-6.1.0
- old
+ new
@@ -13,34 +13,34 @@
auth = {
:access_token => @access_token,
:refresh_token => @refresh_token
}
cs = CreateSend::CreateSend.new auth
- cs.auth_details.should == auth
+ cs.auth_details.should be == auth
end
should "authenticate using an api key" do
auth = {:api_key => @api_key}
cs = CreateSend::CreateSend.new auth
- cs.auth_details.should == auth
+ cs.auth_details.should be == auth
end
should "get the authorization url without state included" do
client_id = 8998879
redirect_uri = 'http://example.com/auth'
scope = 'ViewReports,CreateCampaigns,SendCampaigns'
url = CreateSend::CreateSend.authorize_url(client_id, redirect_uri, scope)
- url.should == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns"
+ url.should be == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns"
end
should "get the authorization url with state included" do
client_id = 8998879
redirect_uri = 'http://example.com/auth'
scope = 'ViewReports,CreateCampaigns,SendCampaigns'
state = 89879287
url = CreateSend::CreateSend.authorize_url(client_id, redirect_uri, scope, state)
- url.should == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns&state=89879287"
+ url.should be == "https://api.createsend.com/oauth?client_id=8998879&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&scope=ViewReports%2CCreateCampaigns%2CSendCampaigns&state=89879287"
end
should "exchange an OAuth token for an access token, 'expires in' value, and refresh token" do
client_id = 8998879
client_secret = 'iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd'
@@ -51,14 +51,14 @@
:content_type => "application/json; charset=utf-8" }
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
access_token, expires_in, refresh_token = CreateSend::CreateSend.exchange_token(
client_id, client_secret, redirect_uri, code)
- FakeWeb.last_request.body.should == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=jdiwouo8uowi9o9o"
- access_token.should == "SlAV32hkKG"
- expires_in.should == 1209600
- refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
+ FakeWeb.last_request.body.should be == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=jdiwouo8uowi9o9o"
+ access_token.should be == "SlAV32hkKG"
+ expires_in.should be == 1209600
+ refresh_token.should be == "tGzv3JOkF0XG5Qx2TlKWIA"
end
should "raise an error when an attempt to exchange an OAuth token for an access token fails" do
client_id = 8998879
client_secret = 'iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd'
@@ -66,40 +66,40 @@
code = 'invalidcode'
options = {
:body => fixture_file("oauth_exchange_token_error.json"),
:content_type => "application/json; charset=utf-8" }
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
- lambda { access_token, expires_in, refresh_token = CreateSend::CreateSend.exchange_token(
+ lambda { CreateSend::CreateSend.exchange_token(
client_id, client_secret, redirect_uri, code) }.should raise_error(
Exception, 'Error exchanging code for access token: invalid_grant - Specified code was invalid or expired')
- FakeWeb.last_request.body.should == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=invalidcode"
+ FakeWeb.last_request.body.should be == "grant_type=authorization_code&client_id=8998879&client_secret=iou0q9wud0q9wd0q9wid0q9iwd0q9wid0q9wdqwd&redirect_uri=http%3A%2F%2Fexample.com%2Fauth&code=invalidcode"
end
should "refresh an access token given a refresh token" do
refresh_token = 'ASP95S4aR+9KsgfHB0dapTYxNA=='
options = {
:body => fixture_file("refresh_oauth_token.json"),
:content_type => "application/json; charset=utf-8" }
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
new_access_token, new_expires_in, new_refresh_token = CreateSend::CreateSend.refresh_access_token refresh_token
- FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
- new_access_token.should == "SlAV32hkKG2e12e"
- new_expires_in.should == 1209600
- new_refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
+ FakeWeb.last_request.body.should be == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
+ new_access_token.should be == "SlAV32hkKG2e12e"
+ new_expires_in.should be == 1209600
+ new_refresh_token.should be == "tGzv3JOkF0XG5Qx2TlKWIA"
end
should "raise an error when an attempt to refresh an access token fails" do
refresh_token = 'ASP95S4aR+9KsgfHB0dapTYxNA=='
options = {
:body => fixture_file("oauth_refresh_token_error.json"),
:content_type => "application/json; charset=utf-8" }
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
- lambda { access_token, expires_in, refresh_token = CreateSend::CreateSend.refresh_access_token(
+ lambda { CreateSend::CreateSend.refresh_access_token(
refresh_token) }.should raise_error(
Exception, 'Error refreshing access token: invalid_grant - Specified refresh_token was invalid or expired')
- FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
+ FakeWeb.last_request.body.should be == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(refresh_token)}"
end
end
context "when an api caller is authenticated using oauth" do
@@ -118,156 +118,156 @@
:content_type => "application/json; charset=utf-8" }
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
cs = CreateSend::CreateSend.new @auth
new_access_token, new_expires_in, new_refresh_token = cs.refresh_token
- FakeWeb.last_request.body.should == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(@auth[:refresh_token])}"
- new_access_token.should == "SlAV32hkKG2e12e"
- new_expires_in.should == 1209600
- new_refresh_token.should == "tGzv3JOkF0XG5Qx2TlKWIA"
- cs.auth_details.should == {
+ FakeWeb.last_request.body.should be == "grant_type=refresh_token&refresh_token=#{ERB::Util.url_encode(@auth[:refresh_token])}"
+ new_access_token.should be == "SlAV32hkKG2e12e"
+ new_expires_in.should be == 1209600
+ new_refresh_token.should be == "tGzv3JOkF0XG5Qx2TlKWIA"
+ cs.auth_details.should be == {
:access_token => new_access_token,
:refresh_token => new_refresh_token
}
end
should "raise an error when an attempt to refresh the access token is made but refresh token is nil" do
cs = CreateSend::CreateSend.new :access_token => 'any token', :refresh_token => nil
- lambda { new_access_token, new_refresh_token = cs.refresh_token }.should raise_error(
+ lambda { cs.refresh_token }.should raise_error(
Exception, '@auth_details[:refresh_token] does not contain a refresh token.')
end
should "raise an error when an attempt to refresh the access token is made but no there was no refresh token passed in" do
cs = CreateSend::CreateSend.new :access_token => 'any token'
- lambda { new_access_token, new_refresh_token = cs.refresh_token }.should raise_error(
+ lambda { cs.refresh_token }.should raise_error(
Exception, '@auth_details[:refresh_token] does not contain a refresh token.')
end
should "raise an error when an attempt to refresh the access token is made but no there was no auth hash passed in" do
cs = CreateSend::CreateSend.new
- lambda { new_access_token, new_refresh_token = cs.refresh_token }.should raise_error(
+ lambda { cs.refresh_token }.should raise_error(
Exception, '@auth_details[:refresh_token] does not contain a refresh token.')
end
should "raise an error when an attempt to refresh the access token is made but the refresh token is invalid" do
refresh_token = 'ASP95S4aR+9KsgfHB0dapTYxNA=='
cs = CreateSend::CreateSend.new :access_token => 'any token', :refresh_token => refresh_token
options = {
:body => fixture_file("oauth_refresh_token_error.json"),
:content_type => "application/json; charset=utf-8" }
FakeWeb.register_uri(:post, "https://api.createsend.com/oauth/token", options)
- lambda { access_token, expires_in, refresh_token = cs.refresh_token }.should raise_error(
+ lambda { refresh_token = cs.refresh_token }.should raise_error(
Exception, 'Error refreshing access token: invalid_grant - Specified refresh_token was invalid or expired')
end
should "raise a CreateSend::InvalidOAuthToken error when an access token is invalid" do
cs = CreateSend::CreateSend.new @auth
stub_get(@auth, "countries.json", "invalid_oauth_token_api_error.json", ["401", "Unauthorized"])
- lambda { c = cs.countries }.should raise_error(CreateSend::InvalidOAuthToken)
+ lambda { cs.countries }.should raise_error(CreateSend::InvalidOAuthToken)
end
should "raise a CreateSend::ExpiredOAuthToken error when an access token is expired" do
cs = CreateSend::CreateSend.new @auth
stub_get(@auth, "countries.json", "expired_oauth_token_api_error.json", ["401", "Unauthorized"])
- lambda { c = cs.countries }.should raise_error(CreateSend::ExpiredOAuthToken)
+ lambda { cs.countries }.should raise_error(CreateSend::ExpiredOAuthToken)
end
should "raise a CreateSend::RevokedOAuthToken error when an access token is revoked" do
cs = CreateSend::CreateSend.new @auth
stub_get(@auth, "countries.json", "revoked_oauth_token_api_error.json", ["401", "Unauthorized"])
- lambda { c = cs.countries }.should raise_error(CreateSend::RevokedOAuthToken)
+ lambda { cs.countries }.should raise_error(CreateSend::RevokedOAuthToken)
end
end
multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do
setup do
@cs = CreateSend::CreateSend.new @auth
end
should "include the correct user agent string when making a call" do
- CreateSend::CreateSend.headers["User-Agent"].should ==
+ CreateSend::CreateSend.headers["User-Agent"].should be ==
"createsend-ruby-#{CreateSend::VERSION}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}-#{RUBY_PLATFORM}"
stub_get(@auth, "clients.json", "clients.json")
clients = @cs.clients
- clients.size.should == 2
+ clients.size.should be == 2
end
should "allow a custom user agent string to be set when making a call" do
CreateSend::CreateSend.user_agent "custom user agent"
- CreateSend::CreateSend.headers["User-Agent"].should == "custom user agent"
+ CreateSend::CreateSend.headers["User-Agent"].should be == "custom user agent"
stub_get(@auth, "clients.json", "clients.json")
clients = @cs.clients
- clients.size.should == 2
+ clients.size.should be == 2
CreateSend::CreateSend.user_agent nil
end
should "get all clients" do
stub_get(@auth, "clients.json", "clients.json")
clients = @cs.clients
- clients.size.should == 2
- clients.first.ClientID.should == '4a397ccaaa55eb4e6aa1221e1e2d7122'
- clients.first.Name.should == 'Client One'
+ clients.size.should be == 2
+ clients.first.ClientID.should be == '4a397ccaaa55eb4e6aa1221e1e2d7122'
+ clients.first.Name.should be == 'Client One'
end
should "get billing details" do
stub_get(@auth, "billingdetails.json", "billingdetails.json")
bd = @cs.billing_details
- bd.Credits.should == 3021
+ bd.Credits.should be == 3021
end
should "get all countries" do
stub_get(@auth, "countries.json", "countries.json")
countries = @cs.countries
- countries.size.should == 245
+ countries.size.should be == 245
assert countries.include? "Australia"
end
should "get system date" do
stub_get(@auth, "systemdate.json", "systemdate.json")
systemdate = @cs.systemdate.SystemDate
- systemdate.should == "2010-10-15 09:27:00"
+ systemdate.should be == "2010-10-15 09:27:00"
end
should "get all timezones" do
stub_get(@auth, "timezones.json", "timezones.json")
timezones = @cs.timezones
- timezones.size.should == 97
+ timezones.size.should be == 97
assert timezones.include? "(GMT+12:00) Fiji"
end
should "get all administrators" do
stub_get(@auth, "admins.json", "administrators.json")
administrators = @cs.administrators
- administrators.size.should == 2
- administrators.first.EmailAddress.should == "admin1@blackhole.com"
- administrators.first.Name.should == 'Admin One'
- administrators.first.Status.should == 'Active'
+ administrators.size.should be == 2
+ administrators.first.EmailAddress.should be == "admin1@blackhole.com"
+ administrators.first.Name.should be == 'Admin One'
+ administrators.first.Status.should be == 'Active'
end
should "set primary contact" do
email = 'admin@blackhole.com'
stub_put(@auth, "primarycontact.json?email=#{ERB::Util.url_encode(email)}", 'admin_set_primary_contact.json')
result = @cs.set_primary_contact email
- result.EmailAddress.should == email
+ result.EmailAddress.should be == email
end
should "get primary contact" do
stub_get(@auth, "primarycontact.json", 'admin_get_primary_contact.json')
result = @cs.get_primary_contact
- result.EmailAddress.should == 'admin@blackhole.com'
+ result.EmailAddress.should be == 'admin@blackhole.com'
end
should "get an external session url" do
email = "exammple@example.com"
chrome = "None"
url = "/subscribers"
integrator_id = "qw989q8wud98qwyd"
client_id = "9q8uw9d8u9wud"
stub_put(@auth, "externalsession.json", "external_session.json")
result = @cs.external_session_url email, chrome, url, integrator_id, client_id
- result.SessionUrl.should == "https://external1.createsend.com/cd/create/ABCDEF12/DEADBEEF?url=FEEDDAD1"
+ result.SessionUrl.should be == "https://external1.createsend.com/cd/create/ABCDEF12/DEADBEEF?url=FEEDDAD1"
end
end
context "when the CreateSend API responds with an error" do
@@ -285,10 +285,10 @@
["500", "Server Error"] => CreateSend::ServerError
}.each do |status, exception|
context "#{status.first}, a get" do
should "raise a #{exception.name} error" do
stub_get(@auth, "countries.json", (status.first == '400' or status.first == '401') ? 'custom_api_error.json' : nil, status)
- lambda { c = @cs.countries }.should raise_error(exception)
+ lambda { @cs.countries }.should raise_error(exception)
end
end
context "#{status.first}, a post" do
should "raise a #{exception.name} error" do