pag_seguro 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe PagSeguro::DayOfYear do
5
- it { should have_attribute_accessor(:day) }
6
- it { should have_attribute_accessor(:month) }
5
+ it { is_expected.to have_attribute_accessor(:day) }
6
+ it { is_expected.to have_attribute_accessor(:month) }
7
7
 
8
8
  context "initialized with attributes" do
9
9
  subject{ build :day_of_year, month: 10, day: 21 }
@@ -14,10 +14,10 @@ describe PagSeguro::DayOfYear do
14
14
 
15
15
  describe "#to_s" do
16
16
  it "should output format MM-dd" do
17
- build(:day_of_year, month: 11, day: 21).to_s.should == "11-21"
18
- build(:day_of_year, month: 1, day: 21).to_s.should == "01-21"
19
- build(:day_of_year, month: 11, day: 1).to_s.should == "11-01"
20
- build(:day_of_year, month: 1, day: 1).to_s.should == "01-01"
17
+ expect(build(:day_of_year, month: 11, day: 21).to_s).to eq("11-21")
18
+ expect(build(:day_of_year, month: 1, day: 21).to_s).to eq("01-21")
19
+ expect(build(:day_of_year, month: 11, day: 1).to_s).to eq("11-01")
20
+ expect(build(:day_of_year, month: 1, day: 1).to_s).to eq("01-01")
21
21
  end
22
22
 
23
23
  it "should raise error if month is bigger than 13" do
@@ -35,15 +35,15 @@ describe PagSeguro::DayOfYear do
35
35
 
36
36
  describe "comparisons" do
37
37
  it "should be bigger when month is ahead" do
38
- build(:day_of_year, month: 2).should be > build(:day_of_year, month: 1)
38
+ expect(build(:day_of_year, month: 2)).to be > build(:day_of_year, month: 1)
39
39
  end
40
40
 
41
41
  it "should be bigger when day is ahead if month is the same" do
42
- build(:day_of_year, day: 2).should be > build(:day_of_year, day: 1)
42
+ expect(build(:day_of_year, day: 2)).to be > build(:day_of_year, day: 1)
43
43
  end
44
44
 
45
45
  it "should be equal if both day and month are the same" do
46
- build(:day_of_year).should be == build(:day_of_year)
46
+ expect(build(:day_of_year)).to eq(build(:day_of_year))
47
47
  end
48
48
  end
49
49
  end
@@ -17,6 +17,6 @@ end
17
17
 
18
18
  describe PagSeguro::Errors::InvalidData do
19
19
  it "should be able to parse an error xml and raise the error codes" do
20
- lambda { raise PagSeguro::Errors::InvalidData.new(invalid_data_xml) }.should raise_error(PagSeguro::Errors::InvalidData, "404: Not Found\n422: Unauthorized\n")
20
+ expect { raise PagSeguro::Errors::InvalidData.new(invalid_data_xml) }.to raise_error(PagSeguro::Errors::InvalidData, "404: Not Found\n422: Unauthorized\n")
21
21
  end
22
22
  end
@@ -2,6 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe PagSeguro::Errors::Unauthorized do
4
4
  it "should be able to raise an unauthorized error" do
5
- lambda { raise PagSeguro::Errors::Unauthorized.new }.should raise_error(PagSeguro::Errors::Unauthorized, "Credentials provided (e-mail and token) failed to authenticate")
5
+ expect { raise PagSeguro::Errors::Unauthorized.new }.to raise_error(PagSeguro::Errors::Unauthorized, "Credentials provided (e-mail and token) failed to authenticate")
6
6
  end
7
7
  end
@@ -12,6 +12,6 @@ end
12
12
 
13
13
  describe PagSeguro::Errors::UnknownError do
14
14
  it "should be able to raise an unknown error" do
15
- lambda { raise PagSeguro::Errors::UnknownError.new(MockResponse.new) }.should raise_error(PagSeguro::Errors::UnknownError, "Unknown response code (10000):\n error description")
15
+ expect { raise PagSeguro::Errors::UnknownError.new(MockResponse.new) }.to raise_error(PagSeguro::Errors::UnknownError, "Unknown response code (10000):\n error description")
16
16
  end
17
17
  end
@@ -14,11 +14,11 @@ describe PagSeguro::Payment do
14
14
  let(:payment){ build :payment_with_all_fields, email: EMAIL, token: TOKEN }
15
15
  subject { payment }
16
16
 
17
- its('code.size'){ should == 32 }
18
- its(:date){ should be_an_instance_of(DateTime) }
17
+ its('code.size'){ is_expected.to eq(32) }
18
+ its(:date){ is_expected.to be_an_instance_of(DateTime) }
19
19
 
20
20
  it "should give a response code of 200 for the user pagseguro url" do
21
- RestClient.get(payment.checkout_payment_url).code.should == 200
21
+ expect(RestClient.get(payment.checkout_payment_url).code).to eq(200)
22
22
  end
23
23
  end
24
24
 
@@ -26,11 +26,11 @@ describe PagSeguro::Payment do
26
26
  let(:payment){ build :payment_with_item, email: EMAIL, token: TOKEN, pre_approval: build(:minimum_pre_approval) }
27
27
  subject { payment }
28
28
 
29
- its('code.size'){ should == 32 }
30
- its(:date){ should be_an_instance_of(DateTime) }
29
+ its('code.size'){ is_expected.to eq(32) }
30
+ its(:date){ is_expected.to be_an_instance_of(DateTime) }
31
31
 
32
32
  it "should give a response code of 200 for the user pagseguro url" do
33
- RestClient.get(payment.checkout_payment_url).code.should == 200
33
+ expect(RestClient.get(payment.checkout_payment_url).code).to eq(200)
34
34
  end
35
35
  end
36
36
 
@@ -38,11 +38,11 @@ describe PagSeguro::Payment do
38
38
  let(:payment){ build :payment_with_items, email: EMAIL, token: TOKEN }
39
39
  subject { payment }
40
40
 
41
- its('code.size'){ should == 32 }
42
- its(:date){ should be_an_instance_of(DateTime) }
41
+ its('code.size'){ is_expected.to eq(32) }
42
+ its(:date){ is_expected.to be_an_instance_of(DateTime) }
43
43
 
44
44
  it "should give a response code of 200 for the user pagseguro url" do
45
- RestClient.get(payment.checkout_payment_url).code.should == 200
45
+ expect(RestClient.get(payment.checkout_payment_url).code).to eq(200)
46
46
  end
47
47
  end
48
48
 
@@ -1,4 +1,4 @@
1
- email: belbraga@bobags.com.br
2
- token: 4B5637E1C27C4304BFAF2C253C73D1FF
3
- notification_code: DD9500-8AE8FAE8FAC8-7774B44F9384-4CA5DF
4
- transaction_id: 84EFE527-E8FA-4116-8CA7-744530B1B45D
1
+ email: seu_email_cadastrado@nopagseguro.com.br
2
+ token: SEU_TOKEN_GERADO_NO_PAG_SEGURO
3
+ notification_code: SEU_CODIGO_DE_NOTIFICACAO
4
+ transaction_id: UM_CODIGO_DE_TRANSACAO
@@ -14,31 +14,31 @@ describe PagSeguro::Notification do
14
14
  end
15
15
  end
16
16
 
17
- it { @notification.transaction_id.should be_present }
18
- it { @notification.date.should be_present }
19
- it { @notification.id.should be_present }
20
- it { @notification.type.should be_present }
21
- it { @notification.status.should be_present }
22
- it { @notification.payment_method.type.should be_present }
23
- it { @notification.payment_method.code.should be_present }
24
- it { @notification.gross_amount.should be_present }
25
- it { @notification.discount_amount.should be_present }
26
- it { @notification.fee_amount.should be_present }
27
- it { @notification.net_amount.should be_present }
28
- it { @notification.extra_amount.should be_present }
29
- it { @notification.installment_count.should be_present }
30
- it { @notification.item_count.should be_present }
31
- it { @notification.items.should be_present }
17
+ it { expect(@notification.transaction_id).to be_present }
18
+ it { expect(@notification.date).to be_present }
19
+ it { expect(@notification.id).to be_present }
20
+ it { expect(@notification.type).to be_present }
21
+ it { expect(@notification.status).to be_present }
22
+ it { expect(@notification.payment_method.type).to be_present }
23
+ it { expect(@notification.payment_method.code).to be_present }
24
+ it { expect(@notification.gross_amount).to be_present }
25
+ it { expect(@notification.discount_amount).to be_present }
26
+ it { expect(@notification.fee_amount).to be_present }
27
+ it { expect(@notification.net_amount).to be_present }
28
+ it { expect(@notification.extra_amount).to be_present }
29
+ it { expect(@notification.installment_count).to be_present }
30
+ it { expect(@notification.item_count).to be_present }
31
+ it { expect(@notification.items).to be_present }
32
32
 
33
33
  it "should have all required item attributes" do
34
34
  @notification.items.each do |item|
35
- item.id.should be_present
36
- item.description.should be_present
37
- item.amount.should be_present
38
- item.quantity.should be_present
35
+ expect(item.id).to be_present
36
+ expect(item.description).to be_present
37
+ expect(item.amount).to be_present
38
+ expect(item.quantity).to be_present
39
39
  end
40
40
  end
41
41
 
42
- it { @notification.sender.email.should be_present }
43
- it { @notification.shipping.type.should be_present }
42
+ it { expect(@notification.sender.email).to be_present }
43
+ it { expect(@notification.shipping.type).to be_present }
44
44
  end
@@ -15,33 +15,33 @@ describe PagSeguro::Query do
15
15
  end
16
16
  end
17
17
 
18
- it { @query.transaction_id.should be_present }
19
- it { @query.date.should be_present }
20
- it { @query.id.should be_present }
21
- it { @query.type.should be_present }
22
- it { @query.status.should be_present }
23
- it { @query.payment_method.type.should be_present }
24
- it { @query.payment_method.code.should be_present }
25
- it { @query.gross_amount.should be_present }
26
- it { @query.discount_amount.should be_present }
27
- it { @query.fee_amount.should be_present }
28
- it { @query.net_amount.should be_present }
29
- it { @query.extra_amount.should be_present }
30
- it { @query.installment_count.should be_present }
31
- it { @query.item_count.should be_present }
32
- it { @query.items.should be_present }
18
+ it { expect(@query.transaction_id).to be_present }
19
+ it { expect(@query.date).to be_present }
20
+ it { expect(@query.id).to be_present }
21
+ it { expect(@query.type).to be_present }
22
+ it { expect(@query.status).to be_present }
23
+ it { expect(@query.payment_method.type).to be_present }
24
+ it { expect(@query.payment_method.code).to be_present }
25
+ it { expect(@query.gross_amount).to be_present }
26
+ it { expect(@query.discount_amount).to be_present }
27
+ it { expect(@query.fee_amount).to be_present }
28
+ it { expect(@query.net_amount).to be_present }
29
+ it { expect(@query.extra_amount).to be_present }
30
+ it { expect(@query.installment_count).to be_present }
31
+ it { expect(@query.item_count).to be_present }
32
+ it { expect(@query.items).to be_present }
33
33
 
34
34
  it "should have all required item attributes" do
35
35
  @query.items.each do |item|
36
- item.id.should be_present
37
- item.description.should be_present
38
- item.amount.should be_present
39
- item.quantity.should be_present
36
+ expect(item.id).to be_present
37
+ expect(item.description).to be_present
38
+ expect(item.amount).to be_present
39
+ expect(item.quantity).to be_present
40
40
  end
41
41
  end
42
42
 
43
- it { @query.sender.email.should be_present }
44
- it { @query.shipping.type.should be_present }
43
+ it { expect(@query.sender.email).to be_present }
44
+ it { expect(@query.shipping.type).to be_present }
45
45
  end
46
46
 
47
47
  describe "::find" do
@@ -58,8 +58,8 @@ describe PagSeguro::Query do
58
58
 
59
59
  it "should return an array of Transactions" do
60
60
  @transactions.each do |transaction|
61
- transaction.should be_an_instance_of(PagSeguro::Transaction)
62
- transaction.id.should be_present
61
+ expect(transaction).to be_an_instance_of(PagSeguro::Transaction)
62
+ expect(transaction.id).to be_present
63
63
  end
64
64
  end
65
65
  end
@@ -1,55 +1,55 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe PagSeguro::Item do
4
- it { should have_attribute_accessor(:id) }
5
- it { should have_attribute_accessor(:description) }
6
- it { should have_attribute_accessor(:amount) }
7
- it { should have_attribute_accessor(:quantity) }
8
- it { should have_attribute_accessor(:shipping_cost) }
9
- it { should have_attribute_accessor(:weight) }
4
+ it { is_expected.to have_attribute_accessor(:id) }
5
+ it { is_expected.to have_attribute_accessor(:description) }
6
+ it { is_expected.to have_attribute_accessor(:amount) }
7
+ it { is_expected.to have_attribute_accessor(:quantity) }
8
+ it { is_expected.to have_attribute_accessor(:shipping_cost) }
9
+ it { is_expected.to have_attribute_accessor(:weight) }
10
10
 
11
11
  it "should be valid with valid attributes" do
12
- build(:item).should be_valid
12
+ expect(build(:item)).to be_valid
13
13
  end
14
14
 
15
- it { should validate_presence_of :id }
16
- it { should validate_presence_of :description }
17
- it { should validate_presence_of :amount }
18
-
19
- it { should_not allow_value(nil).for(:quantity) }
20
- it { should_not allow_value(0).for(:quantity) }
21
- it { should_not allow_value(1000).for(:quantity) }
22
- it { should allow_value(1).for(:quantity) }
23
- it { should allow_value(999).for(:quantity) }
24
-
25
- it { should_not allow_value("10,50").for(:amount) }
26
- it { should_not allow_value("R$ 10.50").for(:amount) }
27
- it { should_not allow_value("-10.50").for(:amount) }
28
- it { should_not allow_value("10.50\nanything").for(:amount) }
29
- it { should allow_value("10.50").for(:amount) }
30
- it { should allow_value(10).for(:amount) }
31
- it { should allow_value(BigDecimal.new("10.5")).for(:amount) }
32
-
33
- it { should_not allow_value("10,50").for(:shipping_cost) }
34
- it { should_not allow_value("R$ 10.50").for(:shipping_cost) }
35
- it { should_not allow_value("-10.50").for(:shipping_cost) }
36
- it { should_not allow_value("10.50\nanything").for(:shipping_cost) }
37
- it { should allow_value("10.50").for(:shipping_cost) }
38
- it { should allow_value(10).for(:shipping_cost) }
39
- it { should allow_value(BigDecimal.new("10.5")).for(:shipping_cost) }
40
- it { should allow_value(nil).for(:shipping_cost) }
41
-
42
- it { should_not allow_value("1000").for(:quantity) }
43
- it { should_not allow_value("0").for(:quantity) }
44
- it { should_not allow_value("-1").for(:quantity) }
45
- it { should allow_value("1").for(:quantity) }
46
-
47
- it { should_not allow_value("-10").for(:weight) }
48
- it { should_not allow_value("10.5").for(:weight) }
49
- it { should_not allow_value("10,5").for(:weight) }
50
- it { should allow_value("3").for(:weight) }
15
+ it { is_expected.to validate_presence_of :id }
16
+ it { is_expected.to validate_presence_of :description }
17
+ it { is_expected.to validate_presence_of :amount }
18
+
19
+ it { is_expected.not_to allow_value(nil).for(:quantity) }
20
+ it { is_expected.not_to allow_value(0).for(:quantity) }
21
+ it { is_expected.not_to allow_value(1000).for(:quantity) }
22
+ it { is_expected.to allow_value(1).for(:quantity) }
23
+ it { is_expected.to allow_value(999).for(:quantity) }
24
+
25
+ it { is_expected.not_to allow_value("10,50").for(:amount) }
26
+ it { is_expected.not_to allow_value("R$ 10.50").for(:amount) }
27
+ it { is_expected.not_to allow_value("-10.50").for(:amount) }
28
+ it { is_expected.not_to allow_value("10.50\nanything").for(:amount) }
29
+ it { is_expected.to allow_value("10.50").for(:amount) }
30
+ it { is_expected.to allow_value(10).for(:amount) }
31
+ it { is_expected.to allow_value(BigDecimal.new("10.5")).for(:amount) }
32
+
33
+ it { is_expected.not_to allow_value("10,50").for(:shipping_cost) }
34
+ it { is_expected.not_to allow_value("R$ 10.50").for(:shipping_cost) }
35
+ it { is_expected.not_to allow_value("-10.50").for(:shipping_cost) }
36
+ it { is_expected.not_to allow_value("10.50\nanything").for(:shipping_cost) }
37
+ it { is_expected.to allow_value("10.50").for(:shipping_cost) }
38
+ it { is_expected.to allow_value(10).for(:shipping_cost) }
39
+ it { is_expected.to allow_value(BigDecimal.new("10.5")).for(:shipping_cost) }
40
+ it { is_expected.to allow_value(nil).for(:shipping_cost) }
41
+
42
+ it { is_expected.not_to allow_value("1000").for(:quantity) }
43
+ it { is_expected.not_to allow_value("0").for(:quantity) }
44
+ it { is_expected.not_to allow_value("-1").for(:quantity) }
45
+ it { is_expected.to allow_value("1").for(:quantity) }
46
+
47
+ it { is_expected.not_to allow_value("-10").for(:weight) }
48
+ it { is_expected.not_to allow_value("10.5").for(:weight) }
49
+ it { is_expected.not_to allow_value("10,5").for(:weight) }
50
+ it { is_expected.to allow_value("3").for(:weight) }
51
51
 
52
52
  it "should trim description to 100 characters if it has more than 100 characters" do
53
- PagSeguro::Item.new(description: "-" * 101).description.size.should == 100
53
+ expect(PagSeguro::Item.new(description: "-" * 101).description.size).to eq(100)
54
54
  end
55
55
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe PagSeguro::Notification do
6
- before { PagSeguro::Notification.any_instance.stub(transaction_data: transaction_data) }
6
+ before { allow_any_instance_of(PagSeguro::Notification).to receive_messages(transaction_data: transaction_data) }
7
7
  let(:transaction){ PagSeguro::Notification.new("mail", "token", "not_code") }
8
8
  subject{ PagSeguro::Notification }
9
9
 
@@ -2,8 +2,8 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe PagSeguro::PaymentMethod do
5
- it { should have_attribute_accessor(:code) }
6
- it { should have_attribute_accessor(:type) }
5
+ it { is_expected.to have_attribute_accessor(:code) }
6
+ it { is_expected.to have_attribute_accessor(:type) }
7
7
 
8
8
  context "initalized with code and type" do
9
9
  subject { build :payment_method, code: "101", type: "1" }
@@ -17,33 +17,33 @@ describe PagSeguro::PaymentMethod do
17
17
 
18
18
  context "with type 1" do
19
19
  subject { build :payment_method, type: 1 }
20
- it { should be_credit_card }
20
+ it { is_expected.to be_credit_card }
21
21
  end
22
22
 
23
23
  context "with if type 2" do
24
24
  subject { build :payment_method, type: 2 }
25
- it { should be_bank_bill }
25
+ it { is_expected.to be_bank_bill }
26
26
  end
27
27
 
28
28
  context "with if type 3" do
29
29
  subject { build :payment_method, type: 3 }
30
- it { should be_online_debit }
30
+ it { is_expected.to be_online_debit }
31
31
  end
32
32
 
33
33
  context "with if type 4" do
34
34
  subject { build :payment_method, type: 4 }
35
- it { should be_pag_seguro_balance }
35
+ it { is_expected.to be_pag_seguro_balance }
36
36
  end
37
37
 
38
38
  context "with type 5" do
39
39
  subject { build :payment_method, type: 5 }
40
- it { should be_oi_paggo }
40
+ it { is_expected.to be_oi_paggo }
41
41
  end
42
42
  end
43
43
 
44
44
  describe "codes" do
45
45
  def should_have_meaning_for_code(meaning, code)
46
- PagSeguro::PaymentMethod.new(code: code).name.should be == meaning
46
+ expect(PagSeguro::PaymentMethod.new(code: code).name).to eq(meaning)
47
47
  end
48
48
 
49
49
  it { should_have_meaning_for_code("Cartão de crédito Visa", 101) }
@@ -4,202 +4,219 @@ describe PagSeguro::Payment do
4
4
  let(:payment){ PagSeguro::Payment.new }
5
5
  subject{ payment }
6
6
 
7
- it { should have_attribute_accessor(:id) }
8
- it { should have_attribute_accessor(:items) }
9
- it { should have_attribute_accessor(:sender) }
10
- it { should have_attribute_accessor(:shipping) }
11
- it { should have_attribute_accessor(:email) }
12
- it { should have_attribute_accessor(:token) }
13
- it { should have_attribute_accessor(:extra_amount) }
14
- it { should have_attribute_accessor(:redirect_url) }
15
- it { should have_attribute_accessor(:max_uses) }
16
- it { should have_attribute_accessor(:max_age) }
17
- it { should have_attribute_accessor(:response) }
18
- it { should have_attribute_accessor(:pre_approval) }
19
-
20
- it { should respond_to :code }
21
- it { should respond_to :date }
22
-
23
- describe "::CHECKOUT_URL" do
24
- subject { PagSeguro::Payment::CHECKOUT_URL }
25
- it { should == "https://ws.pagseguro.uol.com.br/v2/checkout" }
26
- end
27
-
28
- describe '#date' do
29
- subject{ payment.send(:parse_date) }
30
- before{ payment.stub response: double(:response, body: '<checkout><date>2001-02-03T04:05:06+07:00</date></checkout>') }
31
-
32
- it { should be_an_instance_of(DateTime) }
33
- its(:year){ should == 2001 }
34
- its(:month){ should == 2 }
35
- its(:day){ should == 3 }
36
- end
37
-
38
- describe '#code' do
39
- before{ payment.stub response: double(:response, body: '<checkout><code>EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3</code></checkout>') }
7
+ it { is_expected.to have_attribute_accessor(:id) }
8
+ it { is_expected.to have_attribute_accessor(:items) }
9
+ it { is_expected.to have_attribute_accessor(:sender) }
10
+ it { is_expected.to have_attribute_accessor(:shipping) }
11
+ it { is_expected.to have_attribute_accessor(:email) }
12
+ it { is_expected.to have_attribute_accessor(:token) }
13
+ it { is_expected.to have_attribute_accessor(:extra_amount) }
14
+ it { is_expected.to have_attribute_accessor(:redirect_url) }
15
+ it { is_expected.to have_attribute_accessor(:max_uses) }
16
+ it { is_expected.to have_attribute_accessor(:max_age) }
17
+ it { is_expected.to have_attribute_accessor(:response) }
18
+ it { is_expected.to have_attribute_accessor(:pre_approval) }
19
+
20
+ it { is_expected.to respond_to :code }
21
+ it { is_expected.to respond_to :date }
22
+
23
+ context "sandbox" do
24
+ before do
25
+ PagSeguro::Url.environment= :sandbox
26
+ end
40
27
 
41
- its(:code){ should == 'EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3' }
28
+ describe "checkout url" do
29
+ subject { PagSeguro::Payment.checkout_url }
30
+ it { is_expected.to eq("https://ws.sandbox.pagseguro.uol.com.br/v2/checkout") }
31
+ end
42
32
  end
43
33
 
44
- its(:items){ should be_an_instance_of(Array) }
45
- its(:items){ should be_empty }
46
- its(:sender){ should be_an_instance_of(PagSeguro::Sender) }
47
-
48
- context 'with email and token initialization' do
49
- subject{ build(:payment) }
50
- let(:payment){ subject }
51
- its(:email){ should == 'myemail' }
52
- its(:token){ should == 'mytoken' }
53
-
54
- it { validate_presence_of :email }
55
- it { validate_presence_of :token }
56
-
57
- it { should_not allow_value('10,50').for(:extra_amount) }
58
- it { should_not allow_value('R$ 10.50').for(:extra_amount) }
59
- it { should_not allow_value('-10.50').for(:extra_amount) }
60
- it { should_not allow_value('10.50\nanything').for(:extra_amount) }
61
- it { should allow_value('10.50').for(:extra_amount) }
62
- it { should allow_value(10).for(:extra_amount) }
63
- it { should allow_value(BigDecimal.new('10.5')).for(:extra_amount) }
64
-
65
- it { should_not allow_value('something.com.br').for(:redirect_url)}
66
- it { should allow_value('http://something.com.br').for(:redirect_url)}
67
-
68
- it { should_not allow_value(0).for(:max_uses) }
69
- it { should_not allow_value('0').for(:max_uses) }
70
- it { should allow_value(10).for(:max_uses) }
71
- it { should allow_value('10').for(:max_uses) }
72
-
73
- it { should_not allow_value(29).for(:max_age) }
74
- it { should allow_value(30).for(:max_age) }
75
-
76
- it 'should not be valid if its pre_approval in invalid' do
77
- payment.pre_approval = PagSeguro::PreApproval.new
78
- payment.should_not be_valid
34
+ context "production" do
35
+ before do
36
+ PagSeguro::Url.environment= :production
79
37
  end
80
38
 
81
- it 'should not be valid if one of its items is invalid' do
82
- payment.items = [PagSeguro::Item.new]
83
- payment.should_not be_valid
39
+ describe "checkout url" do
40
+ subject { PagSeguro::Payment.checkout_url }
41
+ it { is_expected.to eq("https://ws.pagseguro.uol.com.br/v2/checkout") }
84
42
  end
85
43
 
86
- context 'without items' do
87
- it { should_not be_valid }
88
- end
44
+ describe '#date' do
45
+ subject{ payment.send(:parse_date) }
46
+ before{ allow(payment).to receive_messages response: double(:response, body: '<checkout><date>2001-02-03T04:05:06+07:00</date></checkout>') }
89
47
 
90
- context 'with items' do
91
- subject { build :payment_with_item }
92
- it { should be_valid }
48
+ it { is_expected.to be_an_instance_of(DateTime) }
49
+ its(:year){ should == 2001 }
50
+ its(:month){ should == 2 }
51
+ its(:day){ should == 3 }
93
52
  end
94
53
 
95
- context 'using reference instead of id' do
96
- subject { build :payment_with_item, id: nil, reference: "REF1234" }
97
- its(:id){ should == "REF1234" }
98
- its(:reference){ should == "REF1234" }
54
+ describe '#code' do
55
+ before{ allow(payment).to receive_messages response: double(:response, body: '<checkout><code>EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3</code></checkout>') }
56
+
57
+ its(:code){ should == 'EE603A-59F0DEF0DAAD-2334FFBF9A1E-3223E3' }
99
58
  end
100
59
 
101
- context 'checking out' do
102
- let(:payment){ build(:payment) }
103
- it 'should generate a checkout url with an external code' do
104
- PagSeguro::Payment.checkout_payment_url('aabbcc').should == 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc'
60
+ its(:items){ should be_an_instance_of(Array) }
61
+ its(:items){ should be_empty }
62
+ its(:sender){ should be_an_instance_of(PagSeguro::Sender) }
63
+
64
+ context 'with email and token initialization' do
65
+ subject{ build(:payment) }
66
+ let(:payment){ subject }
67
+ its(:email){ should == 'myemail' }
68
+ its(:token){ should == 'mytoken' }
69
+
70
+ it { validate_presence_of :email }
71
+ it { validate_presence_of :token }
72
+
73
+ it { is_expected.not_to allow_value('10,50').for(:extra_amount) }
74
+ it { is_expected.not_to allow_value('R$ 10.50').for(:extra_amount) }
75
+ it { is_expected.not_to allow_value('-10.50').for(:extra_amount) }
76
+ it { is_expected.not_to allow_value('10.50\nanything').for(:extra_amount) }
77
+ it { is_expected.to allow_value('10.50').for(:extra_amount) }
78
+ it { is_expected.to allow_value(10).for(:extra_amount) }
79
+ it { is_expected.to allow_value(BigDecimal.new('10.5')).for(:extra_amount) }
80
+
81
+ it { is_expected.not_to allow_value('something.com.br').for(:redirect_url)}
82
+ it { is_expected.to allow_value('http://something.com.br').for(:redirect_url)}
83
+
84
+ it { is_expected.not_to allow_value(0).for(:max_uses) }
85
+ it { is_expected.not_to allow_value('0').for(:max_uses) }
86
+ it { is_expected.to allow_value(10).for(:max_uses) }
87
+ it { is_expected.to allow_value('10').for(:max_uses) }
88
+
89
+ it { is_expected.not_to allow_value(29).for(:max_age) }
90
+ it { is_expected.to allow_value(30).for(:max_age) }
91
+
92
+ it 'should not be valid if its pre_approval in invalid' do
93
+ payment.pre_approval = PagSeguro::PreApproval.new
94
+ expect(payment).not_to be_valid
105
95
  end
106
96
 
107
- it 'should generate a checkout url based on the received response' do
108
- payment.stub code: 'aabbcc'
109
- payment.checkout_payment_url.should == 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc'
97
+ it 'should not be valid if one of its items is invalid' do
98
+ payment.items = [PagSeguro::Item.new]
99
+ expect(payment).not_to be_valid
110
100
  end
111
- end
112
101
 
113
- describe '#parse_checkout_response' do
114
-
115
- it 'should not raise errors if response code is 200' do
116
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 200 }
117
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some body info' }
118
- expect { payment.send(:parse_checkout_response) }.to_not raise_error
102
+ context 'without items' do
103
+ it { is_expected.not_to be_valid }
119
104
  end
120
105
 
121
- it 'should raise PagSeguro::Errors::InvalidData if response code is 400' do
122
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 400 }
123
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some error description' }
124
- expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::InvalidData)
106
+ context 'with items' do
107
+ subject { build :payment_with_item }
108
+ it { is_expected.to be_valid }
125
109
  end
126
110
 
127
- it 'should raise PagSeguro::Errors::Unauthorized if response code is 400' do
128
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 401 }
129
- expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::Unauthorized)
111
+ context 'using reference instead of id' do
112
+ subject { build :payment_with_item, id: nil, reference: "REF1234" }
113
+ its(:id){ should == "REF1234" }
114
+ its(:reference){ should == "REF1234" }
130
115
  end
131
116
 
132
- it 'should raise PagSeguro::Errors::UnknownError if response code is not 200, 400 or 401' do
133
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 300 }
134
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some response body' }
135
- expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::UnknownError)
136
- end
117
+ context 'checking out' do
118
+ let(:payment){ build(:payment) }
119
+ it 'should generate a checkout url with an external code' do
120
+ expect(PagSeguro::Payment.checkout_payment_url('aabbcc')).to eq('https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc')
121
+ end
137
122
 
138
- it 'should set response attribute if code is 200' do
139
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :code){ 200 }
140
- PagSeguro::Payment.any_instance.stub_chain(:send_checkout, :body){ 'some response body' }
141
- expect { payment.send(:parse_checkout_response) }.to change { payment.response }.from(nil).to('some response body')
123
+ it 'should generate a checkout url based on the received response' do
124
+ allow(payment).to receive_messages code: 'aabbcc'
125
+ expect(payment.checkout_payment_url).to eq('https://pagseguro.uol.com.br/v2/checkout/payment.html?code=aabbcc')
126
+ end
142
127
  end
143
128
 
144
- it 'should be able to reset response' do
145
- payment.response = 'something'
146
- expect { payment.reset! }.to change{ payment.response }.from('something').to(nil)
129
+ describe '#parse_checkout_response' do
130
+
131
+ it 'should not raise errors if response code is 200' do
132
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 200 }
133
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some body info' }
134
+ expect { payment.send(:parse_checkout_response) }.to_not raise_error
135
+ end
136
+
137
+ it 'should raise PagSeguro::Errors::InvalidData if response code is 400' do
138
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 400 }
139
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some error description' }
140
+ expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::InvalidData)
141
+ end
142
+
143
+ it 'should raise PagSeguro::Errors::Unauthorized if response code is 400' do
144
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 401 }
145
+ expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::Unauthorized)
146
+ end
147
+
148
+ it 'should raise PagSeguro::Errors::UnknownError if response code is not 200, 400 or 401' do
149
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 300 }
150
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some response body' }
151
+ expect { payment.send(:parse_checkout_response) }.to raise_error(PagSeguro::Errors::UnknownError)
152
+ end
153
+
154
+ it 'should set response attribute if code is 200' do
155
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :code){ 200 }
156
+ allow_any_instance_of(PagSeguro::Payment).to receive_message_chain(:send_checkout, :body){ 'some response body' }
157
+ expect { payment.send(:parse_checkout_response) }.to change { payment.response }.from(nil).to('some response body')
158
+ end
159
+
160
+ it 'should be able to reset response' do
161
+ payment.response = 'something'
162
+ expect { payment.reset! }.to change{ payment.response }.from('something').to(nil)
163
+ end
147
164
  end
148
165
  end
149
- end
150
166
 
151
- describe '#code' do
152
- it 'should call #parse_checkout_response if #response is nil' do
153
- payment.stub(response: nil, parse_code: nil)
154
- payment.should_receive(:parse_checkout_response)
155
- payment.code
156
- end
167
+ describe '#code' do
168
+ it 'should call #parse_checkout_response if #response is nil' do
169
+ allow(payment).to receive_messages(response: nil, parse_code: nil)
170
+ expect(payment).to receive(:parse_checkout_response)
171
+ payment.code
172
+ end
157
173
 
158
- it 'should not call #parse_checkout_response if #response is present' do
159
- payment.stub(response: true, parse_code: nil)
160
- payment.should_not_receive(:parse_checkout_response)
161
- payment.code
162
- end
174
+ it 'should not call #parse_checkout_response if #response is present' do
175
+ allow(payment).to receive_messages(response: true, parse_code: nil)
176
+ expect(payment).not_to receive(:parse_checkout_response)
177
+ payment.code
178
+ end
163
179
 
164
- it 'should call #parse_code' do
165
- payment.stub(response: true)
166
- payment.should_receive(:parse_code)
167
- payment.code
180
+ it 'should call #parse_code' do
181
+ allow(payment).to receive_messages(response: true)
182
+ expect(payment).to receive(:parse_code)
183
+ payment.code
184
+ end
168
185
  end
169
- end
170
186
 
171
- describe '#date' do
172
- it 'should call #parse_checkout_response if #response is nil' do
173
- payment.stub(response: nil, parse_date: nil)
174
- payment.should_receive(:parse_checkout_response)
175
- payment.date
176
- end
187
+ describe '#date' do
188
+ it 'should call #parse_checkout_response if #response is nil' do
189
+ allow(payment).to receive_messages(response: nil, parse_date: nil)
190
+ expect(payment).to receive(:parse_checkout_response)
191
+ payment.date
192
+ end
177
193
 
178
- it 'should not call #parse_checkout_response if #response is present' do
179
- payment.stub(response: true, parse_date: nil)
180
- payment.should_not_receive(:parse_checkout_response)
181
- payment.date
182
- end
194
+ it 'should not call #parse_checkout_response if #response is present' do
195
+ allow(payment).to receive_messages(response: true, parse_date: nil)
196
+ expect(payment).not_to receive(:parse_checkout_response)
197
+ payment.date
198
+ end
183
199
 
184
- it 'should call #parse_code' do
185
- payment.stub(response: true)
186
- payment.should_receive(:parse_date)
187
- payment.date
200
+ it 'should call #parse_code' do
201
+ allow(payment).to receive_messages(response: true)
202
+ expect(payment).to receive(:parse_date)
203
+ payment.date
204
+ end
188
205
  end
189
- end
190
206
 
191
- describe "#send_checkout" do
192
- let(:payment){ PagSeguro::Payment.new "email@mail.com", "sometoken" }
193
- it "should call pagseguro's webservice" do
194
- checkout_xml = double(:checkout_xml)
195
- payment.stub(checkout_xml: checkout_xml)
196
- params = { email: "email@mail.com", token: "sometoken" }
197
- RestClient.should_receive(:post).with(
198
- PagSeguro::Payment::CHECKOUT_URL,
199
- checkout_xml,
200
- params: params,
201
- content_type: "application/xml")
202
- payment.send :send_checkout
207
+ describe "#send_checkout" do
208
+ let(:payment){ PagSeguro::Payment.new "email@mail.com", "sometoken" }
209
+ it "should call pagseguro's webservice" do
210
+ checkout_xml = double(:checkout_xml)
211
+ allow(payment).to receive_messages(checkout_xml: checkout_xml)
212
+ params = { email: "email@mail.com", token: "sometoken", ssl_version: :SSLv3 }
213
+ expect(RestClient).to receive(:post).with(
214
+ PagSeguro::Payment.checkout_url,
215
+ checkout_xml,
216
+ params: params,
217
+ content_type: "application/xml")
218
+ payment.send :send_checkout
219
+ end
203
220
  end
204
221
  end
205
222
  end