Skip to content

Commit 24ec9dc

Browse files
author
Lucas
committed
Add specs to Iugu::Customer#save
1 parent da14488 commit 24ec9dc

File tree

3 files changed

+228
-1
lines changed

3 files changed

+228
-1
lines changed

lib/iugu/api_save.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module Iugu
22
module APISave
33
def save
4-
copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request(is_new? ? "POST" : "PUT", self.class.url(self.attributes), modified_attributes))
4+
method = is_new? ? 'POST' : 'PUT'
5+
copy Iugu::Factory.create_from_response(self.class.object_type,
6+
APIRequest.request(method,
7+
self.class.url(self.attributes),
8+
modified_attributes))
59
self.errors = nil
610
true
711
rescue Iugu::RequestWithErrors => ex

spec/cassettes/Iugu_Customer/_save/should_save_the_customer.yml

Lines changed: 188 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/customer_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,39 @@
7474
expect(customer.name).to eq('John Snow')
7575
end
7676
end
77+
78+
describe '.save', :vcr do
79+
it 'should save the customer' do
80+
customer = Iugu::Customer.create(email: '[email protected]',
81+
name: 'John Snow',
82+
cpf_cnpj: '648.144.103-01',
83+
cc_emails: '[email protected]',
84+
zip_code: '29190560',
85+
number: '8',
86+
street: 'Rua dos Bobos',
87+
city: 'São Paulo',
88+
state: 'SP',
89+
district: 'Mooca',
90+
complement: '123C')
91+
92+
customer.name = 'John Targaryen'
93+
customer.cnpj = '24.357.272/7919-90'
94+
customer.cc_emails = '[email protected]'
95+
customer.zip_code = '13058676'
96+
customer.number = '+9000'
97+
customer.street = 'Rua Rio Palmital'
98+
customer.district = 'Tatuapé'
99+
customer.complement = '321A'
100+
101+
customer.save
102+
103+
new_customer = Iugu::Customer.fetch(id: customer.id)
104+
105+
expect(new_customer.zip_code).to eq('13058676')
106+
expect(new_customer.number).to eq('+9000')
107+
expect(new_customer.street).to eq('Rua Rio Palmital')
108+
expect(new_customer.district).to eq('Tatuapé')
109+
expect(new_customer.complement).to eq('321A')
110+
end
111+
end
77112
end

0 commit comments

Comments
 (0)