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,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe PagSeguro do
4
4
  it "should have a version" do
5
- PagSeguro::VERSION.should_not be_empty
5
+ expect(PagSeguro::VERSION).not_to be_empty
6
6
  end
7
7
  end
@@ -2,11 +2,11 @@ require 'simplecov'
2
2
  SimpleCov.start do
3
3
  add_filter "spec/"
4
4
  end
5
-
5
+ require 'rspec/its'
6
6
  require 'yaml'
7
7
  require File.dirname(__FILE__) + "/../lib/pag_seguro"
8
8
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
9
- require 'shoulda-matchers'
9
+ require 'shoulda/matchers'
10
10
  require 'factory_girl'
11
11
 
12
12
  include FactoryGirl::Syntax::Methods
@@ -26,4 +26,4 @@ RSpec::Matchers.define :have_attribute_accessor do |attribute|
26
26
  description do
27
27
  "have attr_accessor :#{attribute}"
28
28
  end
29
- end
29
+ end
@@ -2,213 +2,232 @@
2
2
  shared_examples_for "a transaction" do
3
3
  let(:transaction_xml){ File.open( File.expand_path( File.dirname(__FILE__) + '/../fixtures/transaction.xml') ) }
4
4
  let(:transaction_data){ Nokogiri::XML(transaction_xml) }
5
-
6
- it "should have an id" do
7
- transaction.id.should == "REF1234"
8
- end
9
-
10
- it "should have a reference" do
11
- transaction.reference.should == "REF1234"
12
- end
13
-
14
- it "should have a transaction id" do
15
- transaction.transaction_id.should == "9E884542-81B3-4419-9A75-BCC6FB495EF1"
16
- end
17
-
18
- it "should have a gross amount" do
19
- transaction.gross_amount.should be_present
20
- transaction.gross_amount.should match(/^\d+\.\d{2}$/)
21
- end
22
-
23
- it "should have a discount amount" do
24
- transaction.discount_amount.should be_present
25
- transaction.discount_amount.should match(/^\d+\.\d{2}$/)
26
- end
27
5
 
28
- it "should have a fee amount" do
29
- transaction.fee_amount.should be_present
30
- transaction.fee_amount.should match(/^\d+\.\d{2}$/)
31
- end
32
-
33
- it "should have a net amount" do
34
- transaction.net_amount.should be_present
35
- transaction.net_amount.should match(/^\d+\.\d{2}$/)
36
- end
6
+ context "sandbox" do
7
+ before do
8
+ PagSeguro::Url.environment=:sandbox
9
+ end
37
10
 
38
- it "should have an extra amount" do
39
- transaction.extra_amount.should be_present
40
- transaction.extra_amount.should match(/^\d+\.\d{2}$/)
11
+ it "transactions url" do
12
+ expect(PagSeguro::Transaction.transactions_url).to eq "https://ws.sandbox.pagseguro.uol.com.br/v2/transactions"
13
+ end
41
14
  end
42
15
 
43
- it "should have an installment count" do
44
- transaction.installment_count.should be_present
45
- transaction.installment_count.should be_an_integer
46
- end
47
-
48
- it "should have an item count" do
49
- transaction.item_count.should be_present
50
- transaction.item_count.should be_an_integer
51
- transaction.item_count.should == transaction.items.count
52
- end
53
-
54
- it "should be approved in this case" do
55
- transaction.should be_approved
56
- end
57
-
58
- it "should have a sender" do
59
- @sender = transaction.sender
60
- @sender.name.should == "José Comprador"
61
- @sender.email.should == "comprador@uol.com.br"
62
- @sender.phone_ddd.should == "11"
63
- @sender.phone_number == "56273440"
64
- end
65
-
66
- it "should have a date" do
67
- transaction.date.should be_present
68
- transaction.date.should be_an_instance_of(DateTime)
69
- transaction.date.year.should == 2011
70
- transaction.date.month.should == 2
71
- transaction.date.day.should == 10
72
- end
73
-
74
- it "should have a shipping" do
75
- @shipping = transaction.shipping
76
- @shipping.type.should == 1
77
- @shipping.cost.should == "21.50"
78
- @shipping.state.should == "SP"
79
- @shipping.city.should == "Sao Paulo"
80
- @shipping.postal_code.should == "01452002"
81
- @shipping.district.should == "Jardim Paulistano"
82
- @shipping.street.should == "Av. Brig. Faria Lima"
83
- @shipping.number.should == "1384"
84
- @shipping.complement.should == "5o andar"
85
- end
86
-
87
- it "should have a payment method" do
88
- @payment_method = transaction.payment_method
89
- @payment_method.code.should == 101
90
- @payment_method.type.should == 1
91
- end
92
-
93
- it "should have items" do
94
- @items = transaction.items
95
- @items.size.should == 2
96
-
97
- @items[0].id.should == "0001"
98
- @items[0].description.should == "Notebook Prata"
99
- @items[0].quantity.should == "1"
100
- @items[0].amount.should == "24300.00"
101
-
102
- @items[1].id.should == "0002"
103
- @items[1].description.should == "Notebook Rosa"
104
- @items[1].quantity.should == "1"
105
- @items[1].amount.should == "25600.00"
106
- end
107
-
108
- describe "status" do
109
- it "should have a status" do
110
- transaction.status.should == 3
16
+ context "production" do
17
+ before do
18
+ PagSeguro::Url.environment=:production
111
19
  end
112
-
113
- it "should be processing if its status is 1" do
114
- transaction.stub(:status){ 1 }
115
- transaction.should be_processing
20
+ describe "transactions url" do
21
+ it {expect(PagSeguro::Transaction.transactions_url).to eq "https://ws.pagseguro.uol.com.br/v2/transactions"}
116
22
  end
117
23
 
118
- it "should be in analysis if its status is 2" do
119
- transaction.stub(:status){ 2 }
120
- transaction.should be_in_analysis
24
+ it "should have an id" do
25
+ expect(transaction.id).to eq("REF1234")
121
26
  end
122
27
 
123
- it "should be approved if its status is 3" do
124
- transaction.stub(:status){ 3 }
125
- transaction.should be_approved
28
+ it "should have a reference" do
29
+ expect(transaction.reference).to eq("REF1234")
126
30
  end
127
31
 
128
- it "should be available if its status is 4" do
129
- transaction.stub(:status){ 4 }
130
- transaction.should be_available
32
+ it "should have a transaction id" do
33
+ expect(transaction.transaction_id).to eq("9E884542-81B3-4419-9A75-BCC6FB495EF1")
131
34
  end
132
35
 
133
- it "should be disputed if its status is 5" do
134
- transaction.stub(:status){ 5 }
135
- transaction.should be_disputed
36
+ it "should have a gross amount" do
37
+ expect(transaction.gross_amount).to be_present
38
+ expect(transaction.gross_amount).to match(/^\d+\.\d{2}$/)
136
39
  end
137
40
 
138
- it "should be disputed if its status is 5" do
139
- transaction.stub(:status){ 5 }
140
- transaction.should be_disputed
41
+ it "should have a discount amount" do
42
+ expect(transaction.discount_amount).to be_present
43
+ expect(transaction.discount_amount).to match(/^\d+\.\d{2}$/)
141
44
  end
142
45
 
143
- it "should be returned if its status is 6" do
144
- transaction.stub(:status){ 6 }
145
- transaction.should be_returned
46
+ it "should have a fee amount" do
47
+ expect(transaction.fee_amount).to be_present
48
+ expect(transaction.fee_amount).to match(/^\d+\.\d{2}$/)
146
49
  end
147
50
 
148
- it "should be cancelled if its status is 7" do
149
- transaction.stub(:status){ 7 }
150
- transaction.should be_cancelled
151
- end
152
- end
153
-
154
- describe "type" do
155
- it "should have a type" do
156
- transaction.type.should == 1
157
- end
158
-
159
- it "should be payment if type is 1" do
160
- transaction.stub(:type){ 1 }
161
- transaction.should be_payment
51
+ it "should have a net amount" do
52
+ expect(transaction.net_amount).to be_present
53
+ expect(transaction.net_amount).to match(/^\d+\.\d{2}$/)
162
54
  end
163
55
 
164
- it "should be transfer if type is 2" do
165
- transaction.stub(:type){ 2 }
166
- transaction.should be_transfer
56
+ it "should have an extra amount" do
57
+ expect(transaction.extra_amount).to be_present
58
+ expect(transaction.extra_amount).to match(/^\d+\.\d{2}$/)
167
59
  end
168
60
 
169
- it "should be addition of funds if type is 3" do
170
- transaction.stub(:type){ 3 }
171
- transaction.should be_addition_of_funds
61
+ it "should have an installment count" do
62
+ expect(transaction.installment_count).to be_present
63
+ expect(transaction.installment_count).to be_an_integer
172
64
  end
173
65
 
174
- it "should be charge if type is 4" do
175
- transaction.stub(:type){ 4 }
176
- transaction.should be_charge
66
+ it "should have an item count" do
67
+ expect(transaction.item_count).to be_present
68
+ expect(transaction.item_count).to be_an_integer
69
+ expect(transaction.item_count).to eq(transaction.items.count)
177
70
  end
178
71
 
179
- it "should be bonus if type is 5" do
180
- transaction.stub(:type){ 5 }
181
- transaction.should be_bonus
72
+ it "should be approved in this case" do
73
+ expect(transaction).to be_approved
182
74
  end
183
- end
184
75
 
185
- describe "::status_for" do
186
- it "should return :processing for 1" do
187
- subject.status_for(1).should == :processing
76
+ it "should have a sender" do
77
+ @sender = transaction.sender
78
+ expect(@sender.name).to eq("José Comprador")
79
+ expect(@sender.email).to eq("comprador@uol.com.br")
80
+ expect(@sender.phone_ddd).to eq("11")
81
+ @sender.phone_number == "56273440"
188
82
  end
189
83
 
190
- it "should return :in_analysis for 2" do
191
- subject.status_for(2).should == :in_analysis
84
+ it "should have a date" do
85
+ expect(transaction.date).to be_present
86
+ expect(transaction.date).to be_an_instance_of(DateTime)
87
+ expect(transaction.date.year).to eq(2011)
88
+ expect(transaction.date.month).to eq(2)
89
+ expect(transaction.date.day).to eq(10)
192
90
  end
193
91
 
194
- it "should return :approved for 3" do
195
- subject.status_for(3).should == :approved
92
+ it "should have a shipping" do
93
+ @shipping = transaction.shipping
94
+ expect(@shipping.type).to eq(1)
95
+ expect(@shipping.cost).to eq("21.50")
96
+ expect(@shipping.state).to eq("SP")
97
+ expect(@shipping.city).to eq("Sao Paulo")
98
+ expect(@shipping.postal_code).to eq("01452002")
99
+ expect(@shipping.district).to eq("Jardim Paulistano")
100
+ expect(@shipping.street).to eq("Av. Brig. Faria Lima")
101
+ expect(@shipping.number).to eq("1384")
102
+ expect(@shipping.complement).to eq("5o andar")
196
103
  end
197
104
 
198
- it "should return :available for 4" do
199
- subject.status_for(4).should == :available
105
+ it "should have a payment method" do
106
+ @payment_method = transaction.payment_method
107
+ expect(@payment_method.code).to eq(101)
108
+ expect(@payment_method.type).to eq(1)
200
109
  end
201
110
 
202
- it "should return :disputed for 5" do
203
- subject.status_for(5).should == :disputed
204
- end
111
+ it "should have items" do
112
+ @items = transaction.items
113
+ expect(@items.size).to eq(2)
205
114
 
206
- it "should return :returned for 6" do
207
- subject.status_for(6).should == :returned
115
+ expect(@items[0].id).to eq("0001")
116
+ expect(@items[0].description).to eq("Notebook Prata")
117
+ expect(@items[0].quantity).to eq("1")
118
+ expect(@items[0].amount).to eq("24300.00")
119
+
120
+ expect(@items[1].id).to eq("0002")
121
+ expect(@items[1].description).to eq("Notebook Rosa")
122
+ expect(@items[1].quantity).to eq("1")
123
+ expect(@items[1].amount).to eq("25600.00")
208
124
  end
209
125
 
210
- it "should return :cancelled for 7" do
211
- subject.status_for(7).should == :cancelled
126
+ describe "status" do
127
+ it "should have a status" do
128
+ expect(transaction.status).to eq(3)
129
+ end
130
+
131
+ it "should be processing if its status is 1" do
132
+ allow(transaction).to receive(:status){ 1 }
133
+ expect(transaction).to be_processing
134
+ end
135
+
136
+ it "should be in analysis if its status is 2" do
137
+ allow(transaction).to receive(:status){ 2 }
138
+ expect(transaction).to be_in_analysis
139
+ end
140
+
141
+ it "should be approved if its status is 3" do
142
+ allow(transaction).to receive(:status){ 3 }
143
+ expect(transaction).to be_approved
144
+ end
145
+
146
+ it "should be available if its status is 4" do
147
+ allow(transaction).to receive(:status){ 4 }
148
+ expect(transaction).to be_available
149
+ end
150
+
151
+ it "should be disputed if its status is 5" do
152
+ allow(transaction).to receive(:status){ 5 }
153
+ expect(transaction).to be_disputed
154
+ end
155
+
156
+ it "should be disputed if its status is 5" do
157
+ allow(transaction).to receive(:status){ 5 }
158
+ expect(transaction).to be_disputed
159
+ end
160
+
161
+ it "should be returned if its status is 6" do
162
+ allow(transaction).to receive(:status){ 6 }
163
+ expect(transaction).to be_returned
164
+ end
165
+
166
+ it "should be cancelled if its status is 7" do
167
+ allow(transaction).to receive(:status){ 7 }
168
+ expect(transaction).to be_cancelled
169
+ end
170
+ end
171
+
172
+ describe "type" do
173
+ it "should have a type" do
174
+ expect(transaction.type).to eq(1)
175
+ end
176
+
177
+ it "should be payment if type is 1" do
178
+ allow(transaction).to receive(:type){ 1 }
179
+ expect(transaction).to be_payment
180
+ end
181
+
182
+ it "should be transfer if type is 2" do
183
+ allow(transaction).to receive(:type){ 2 }
184
+ expect(transaction).to be_transfer
185
+ end
186
+
187
+ it "should be addition of funds if type is 3" do
188
+ allow(transaction).to receive(:type){ 3 }
189
+ expect(transaction).to be_addition_of_funds
190
+ end
191
+
192
+ it "should be charge if type is 4" do
193
+ allow(transaction).to receive(:type){ 4 }
194
+ expect(transaction).to be_charge
195
+ end
196
+
197
+ it "should be bonus if type is 5" do
198
+ allow(transaction).to receive(:type){ 5 }
199
+ expect(transaction).to be_bonus
200
+ end
201
+ end
202
+
203
+ describe "::status_for" do
204
+ it "should return :processing for 1" do
205
+ expect(subject.status_for(1)).to eq(:processing)
206
+ end
207
+
208
+ it "should return :in_analysis for 2" do
209
+ expect(subject.status_for(2)).to eq(:in_analysis)
210
+ end
211
+
212
+ it "should return :approved for 3" do
213
+ expect(subject.status_for(3)).to eq(:approved)
214
+ end
215
+
216
+ it "should return :available for 4" do
217
+ expect(subject.status_for(4)).to eq(:available)
218
+ end
219
+
220
+ it "should return :disputed for 5" do
221
+ expect(subject.status_for(5)).to eq(:disputed)
222
+ end
223
+
224
+ it "should return :returned for 6" do
225
+ expect(subject.status_for(6)).to eq(:returned)
226
+ end
227
+
228
+ it "should return :cancelled for 7" do
229
+ expect(subject.status_for(7)).to eq(:cancelled)
230
+ end
212
231
  end
213
232
  end
214
233
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pag_seguro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Diem Benatti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-20 00:00:00.000000000 Z
11
+ date: 2015-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: haml
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '!='
45
+ - - "!="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.1.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '!='
52
+ - - "!="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.1.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.6.7
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.6.7
83
83
  description:
@@ -87,8 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
90
+ - ".gitignore"
91
+ - ".rspec"
92
92
  - Gemfile
93
93
  - Guardfile
94
94
  - README.md
@@ -109,6 +109,7 @@ files:
109
109
  - lib/pag_seguro/sender.rb
110
110
  - lib/pag_seguro/shipping.rb
111
111
  - lib/pag_seguro/transaction.rb
112
+ - lib/pag_seguro/url.rb
112
113
  - lib/pag_seguro/version.rb
113
114
  - lib/pagseguro_decimal_validator.rb
114
115
  - pag_seguro.gemspec
@@ -134,6 +135,7 @@ files:
134
135
  - spec/pag_seguro/sender_spec.rb
135
136
  - spec/pag_seguro/shipping_spec.rb
136
137
  - spec/pag_seguro/transaction_spec.rb
138
+ - spec/pag_seguro/url_spec.rb
137
139
  - spec/pag_seguro/version_spec.rb
138
140
  - spec/spec_helper.rb
139
141
  - spec/support/transaction_shared_examples.rb
@@ -146,17 +148,17 @@ require_paths:
146
148
  - lib
147
149
  required_ruby_version: !ruby/object:Gem::Requirement
148
150
  requirements:
149
- - - '>='
151
+ - - ">="
150
152
  - !ruby/object:Gem::Version
151
153
  version: 1.9.2
152
154
  required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  requirements:
154
- - - '>='
156
+ - - ">="
155
157
  - !ruby/object:Gem::Version
156
158
  version: '0'
157
159
  requirements: []
158
160
  rubyforge_project:
159
- rubygems_version: 2.0.0
161
+ rubygems_version: 2.2.2
160
162
  signing_key:
161
163
  specification_version: 4
162
164
  summary: A ruby gem to handle PagSeguro's API version 2
@@ -183,6 +185,7 @@ test_files:
183
185
  - spec/pag_seguro/sender_spec.rb
184
186
  - spec/pag_seguro/shipping_spec.rb
185
187
  - spec/pag_seguro/transaction_spec.rb
188
+ - spec/pag_seguro/url_spec.rb
186
189
  - spec/pag_seguro/version_spec.rb
187
190
  - spec/spec_helper.rb
188
191
  - spec/support/transaction_shared_examples.rb