spec/constantcontact/services/contact_service_spec.rb in constantcontact-2.2.1 vs spec/constantcontact/services/contact_service_spec.rb in constantcontact-3.0.0
- old
+ new
@@ -7,20 +7,21 @@
require 'spec_helper'
describe ConstantContact::Services::ContactService do
before(:each) do
@request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
+ @client = ConstantContact::Api.new('explicit_api_key', "access_token")
end
describe "#get_contacts" do
it "returns an array of contacts" do
json = load_file('contacts_response.json')
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
response = RestClient::Response.create(json, net_http_resp, {}, @request)
RestClient.stub(:get).and_return(response)
- contacts = ConstantContact::Services::ContactService.get_contacts()
+ contacts = ConstantContact::Services::ContactService.new(@client).get_contacts()
contact = contacts.results[0]
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
contact.should be_kind_of(ConstantContact::Components::Contact)
end
@@ -31,11 +32,11 @@
json = load_file('contact_response.json')
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
response = RestClient::Response.create(json, net_http_resp, {}, @request)
RestClient.stub(:get).and_return(response)
- contact = ConstantContact::Services::ContactService.get_contact(1)
+ contact = ConstantContact::Services::ContactService.new(@client).get_contact(1)
contact.should be_kind_of(ConstantContact::Components::Contact)
end
end
@@ -45,11 +46,11 @@
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
response = RestClient::Response.create(json, net_http_resp, {}, @request)
RestClient.stub(:post).and_return(response)
new_contact = ConstantContact::Components::Contact.create(JSON.parse(json))
- contact = ConstantContact::Services::ContactService.add_contact(new_contact)
+ contact = ConstantContact::Services::ContactService.new(@client).add_contact(new_contact)
contact.should be_kind_of(ConstantContact::Components::Contact)
contact.status.should eq('ACTIVE')
end
end
@@ -60,11 +61,11 @@
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
response = RestClient::Response.create('', net_http_resp, {}, @request)
RestClient.stub(:delete).and_return(response)
- result = ConstantContact::Services::ContactService.delete_contact(contact_id)
+ result = ConstantContact::Services::ContactService.new(@client).delete_contact(contact_id)
result.should be_true
end
end
describe "#delete_contact_from_lists" do
@@ -73,11 +74,11 @@
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
response = RestClient::Response.create('', net_http_resp, {}, @request)
RestClient.stub(:delete).and_return(response)
- result = ConstantContact::Services::ContactService.delete_contact_from_lists(contact_id)
+ result = ConstantContact::Services::ContactService.new(@client).delete_contact_from_lists(contact_id)
result.should be_true
end
end
describe "#delete_contact_from_list" do
@@ -87,11 +88,11 @@
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
response = RestClient::Response.create('', net_http_resp, {}, @request)
RestClient.stub(:delete).and_return(response)
- result = ConstantContact::Services::ContactService.delete_contact_from_list(contact_id, list_id)
+ result = ConstantContact::Services::ContactService.new(@client).delete_contact_from_list(contact_id, list_id)
result.should be_true
end
end
describe "#update_contact" do
@@ -100,10 +101,10 @@
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
response = RestClient::Response.create(json, net_http_resp, {}, @request)
RestClient.stub(:put).and_return(response)
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
- result = ConstantContact::Services::ContactService.update_contact(contact)
+ result = ConstantContact::Services::ContactService.new(@client).update_contact(contact)
result.should be_kind_of(ConstantContact::Components::Contact)
result.status.should eq('ACTIVE')
end
end
\ No newline at end of file