pag_seguro 0.4.1 → 0.5.1

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.
Files changed (36) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +5 -2
  3. data/README.md +71 -6
  4. data/lib/pag_seguro/checkout.xml.haml +24 -5
  5. data/lib/pag_seguro/convert_field_to_digit.rb +15 -0
  6. data/lib/pag_seguro/day_of_year.rb +35 -0
  7. data/lib/pag_seguro/item.rb +9 -11
  8. data/lib/pag_seguro/notification.rb +1 -1
  9. data/lib/pag_seguro/payment.rb +26 -19
  10. data/lib/pag_seguro/pre_approval.rb +84 -0
  11. data/lib/pag_seguro/query.rb +27 -1
  12. data/lib/pag_seguro/sender.rb +2 -2
  13. data/lib/pag_seguro/shipping.rb +2 -2
  14. data/lib/pag_seguro/transaction.rb +1 -1
  15. data/lib/pag_seguro/version.rb +1 -1
  16. data/lib/pag_seguro.rb +9 -1
  17. data/lib/pagseguro_decimal_validator.rb +9 -0
  18. data/pag_seguro.gemspec +1 -0
  19. data/spec/factories.rb +137 -0
  20. data/spec/fixtures/transaction_history.xml +40 -0
  21. data/spec/pag_seguro/checkout_xml_spec.rb +142 -159
  22. data/spec/pag_seguro/convert_field_to_digit_spec.rb +68 -0
  23. data/spec/pag_seguro/day_of_year_spec.rb +49 -0
  24. data/spec/pag_seguro/integration/checkout_spec.rb +34 -67
  25. data/spec/pag_seguro/integration/config.yml +4 -4
  26. data/spec/pag_seguro/integration/query_spec.rb +56 -34
  27. data/spec/pag_seguro/item_spec.rb +46 -72
  28. data/spec/pag_seguro/payment_method_spec.rb +58 -63
  29. data/spec/pag_seguro/payment_spec.rb +150 -123
  30. data/spec/pag_seguro/pre_approval_spec.rb +112 -0
  31. data/spec/pag_seguro/query_spec.rb +111 -4
  32. data/spec/pag_seguro/sender_spec.rb +50 -62
  33. data/spec/pag_seguro/shipping_spec.rb +36 -51
  34. data/spec/spec_helper.rb +11 -20
  35. data/spec/support/transaction_shared_examples.rb +7 -7
  36. metadata +32 -3
@@ -2,81 +2,69 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe PagSeguro::Sender do
5
- context "instance" do
6
- before { @sender = PagSeguro::Sender.new }
5
+ context "instance" do
6
+ it { should have_attribute_accessor(:email) }
7
+ it { should have_attribute_accessor(:name) }
8
+ it { should have_attribute_accessor(:phone_ddd) }
9
+ it { should have_attribute_accessor(:phone_number) }
7
10
 
8
- it "should have an email accessor" do
9
- @sender.should have_attribute_accessor(:email)
11
+ context "initialized with all attributes" do
12
+ subject { PagSeguro::Sender.new attributes_for(:sender) }
13
+ its(:name){ should == "Stefano Diem Benatti" }
14
+ its(:email){ should == "stefano@heavenstudio.com.br" }
15
+ its(:phone_ddd){ should == 11 }
16
+ its(:phone_number){ should == 993430994 }
10
17
  end
11
18
 
12
- it "should have a name accessor" do
13
- @sender.should have_attribute_accessor(:name)
19
+ context "with invalid e-mail" do
20
+ subject { build :sender, email: "nothing" }
21
+ its(:email){ should be_nil }
14
22
  end
15
23
 
16
- it "should have a phone_ddd accessor" do
17
- @sender.should have_attribute_accessor(:phone_ddd)
24
+ context "with nil name" do
25
+ subject { build :sender, name: nil }
26
+ it { should_not be_a_valid_name }
27
+ its(:name){ should be_nil }
18
28
  end
19
29
 
20
- it "should have a phone_number" do
21
- @sender.should have_attribute_accessor(:phone_number)
30
+ context "with name Joao" do
31
+ subject { build :sender, name: "Joao" }
32
+ it { should_not be_a_valid_name }
33
+ its(:name){ should be_nil }
22
34
  end
23
-
24
- it "should be able to initialize with all attributes" do
25
- sender = PagSeguro::Sender.new(name: "Stefano Diem Benatti", email: "stefano@heavenstudio.com.br", phone_ddd: "11", phone_number: "93430994")
26
- sender.name.should == "Stefano Diem Benatti"
27
- sender.email.should == "stefano@heavenstudio.com.br"
28
- sender.phone_ddd.should == "11"
29
- sender.phone_number.should == "93430994"
30
- end
31
-
32
- it "should tell valid e-mail appart" do
33
- @sender.email = "nothing"
34
- @sender.should_not be_a_valid_email
35
- @sender.email = ("a" * 50) + "waytoolongemail@mail.com"
36
- @sender.should_not be_a_valid_email
37
- @sender.email = "stefano@heavenstudio.com.br"
38
- @sender.should be_a_valid_email
39
- end
40
-
41
- it "should not show invalid e-mail" do
42
- @sender.email = "nothing"
43
- @sender.email.should be_nil
44
- end
45
-
46
- it "should not have a valid name unless name has two distict character sequences" do
47
- @sender.name = nil
48
- @sender.should_not be_a_valid_name
49
- @sender.name = "Joao"
50
- @sender.should_not be_a_valid_name
51
- @sender.name = "Joao Paulo"
52
- @sender.should be_a_valid_name
53
- @sender.name = "José Álvez"
54
- @sender.should be_a_valid_name
35
+
36
+ context "with name Joao Paulo" do
37
+ subject { build :sender, name: "Joao Paulo" }
38
+ it { should be_a_valid_name }
39
+ its(:name){ should == "Joao Paulo" }
55
40
  end
56
-
57
- it "should not show invalid names" do
58
- @sender.name = "Joao"
59
- @sender.name.should be_nil
41
+
42
+ context "with name João Paulo" do
43
+ subject { build :sender, name: "João Paulo" }
44
+ it { should be_a_valid_name }
45
+ its(:name){ should == "João Paulo" }
60
46
  end
61
-
62
- it "should crop the name if it is too big" do
63
- @sender.name = "a" * 50 + " b" * 10
64
- @sender.name.should == "a" * 50
47
+
48
+ context "with very big name" do
49
+ subject { build :sender, name: ("a" * 50)+" "+("b" * 10) }
50
+ it { should be_a_valid_name }
51
+ its(:name){ should == "a" * 50 }
65
52
  end
66
-
67
- it "should crop spaces (because double spaces raises errors on pagseguro)" do
68
- @sender.name = "Stefano Benatti"
69
- @sender.name.should == "Stefano Benatti"
53
+
54
+ context "with double spaces in name" do
55
+ subject { build :sender, name: "Stefano Benatti" }
56
+ it { should be_a_valid_name }
57
+ its(:name){ should == "Stefano Benatti" }
70
58
  end
71
-
72
- it "should not show invalid phone ddd's" do
73
- @sender.phone_ddd = "111"
74
- @sender.phone_ddd.should be_nil
59
+
60
+ context "with invalid phone ddd" do
61
+ subject { build :sender, phone_ddd: "111" }
62
+ its(:phone_ddd){ should be_nil }
75
63
  end
76
-
77
- it "should not show invalid phone number" do
78
- @sender.phone_number = "1234567"
79
- @sender.phone_number.should be_nil
64
+
65
+ context "with invalid phone number" do
66
+ subject { build :sender, phone_number: "1234567" }
67
+ its(:phone_number){ should be_nil }
80
68
  end
81
69
  end
82
70
  end
@@ -1,61 +1,46 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
3
 
4
- valid_attributes = {
5
- type: PagSeguro::Shipping::SEDEX,
6
- state: "SP",
7
- city: "São Paulo",
8
- postal_code: "05363000",
9
- district: "Jd. PoliPoli",
10
- street: "Av. Otacilio Tomanik",
11
- number: "775",
12
- complement: "apto. 92",
13
- cost: "12.13"
14
- }
15
-
16
4
  describe PagSeguro::Shipping do
17
- context "instance" do
18
- before { @shipping = PagSeguro::Shipping.new }
19
- it { @shipping.should have_attribute_accessor(:type) }
20
- it { @shipping.should have_attribute_accessor(:state) }
21
- it { @shipping.should have_attribute_accessor(:city) }
22
- it { @shipping.should have_attribute_accessor(:postal_code) }
23
- it { @shipping.should have_attribute_accessor(:district) }
24
- it { @shipping.should have_attribute_accessor(:street) }
25
- it { @shipping.should have_attribute_accessor(:number) }
26
- it { @shipping.should have_attribute_accessor(:complement) }
27
- it { @shipping.should have_attribute_accessor(:cost) }
28
-
29
- describe "types" do
30
- it "should be pac if type is 1" do
31
- @shipping.stub( :type ){ 1 }
32
- @shipping.should be_pac
33
- end
34
-
35
- it "should be sedex if type is 2" do
36
- @shipping.stub( :type ){ 2 }
37
- @shipping.should be_sedex
38
- end
39
-
40
- it "should be unidentified if type is 3" do
41
- @shipping.stub( :type ){ 3 }
42
- @shipping.should be_unidentified
43
- end
5
+ let(:shipping){ PagSeguro::Shipping.new }
6
+
7
+ it { should have_attribute_accessor(:type) }
8
+ it { should have_attribute_accessor(:state) }
9
+ it { should have_attribute_accessor(:city) }
10
+ it { should have_attribute_accessor(:postal_code) }
11
+ it { should have_attribute_accessor(:district) }
12
+ it { should have_attribute_accessor(:street) }
13
+ it { should have_attribute_accessor(:number) }
14
+ it { should have_attribute_accessor(:complement) }
15
+ it { should have_attribute_accessor(:cost) }
16
+
17
+ its(:type){ should == PagSeguro::Shipping::UNIDENTIFIED }
18
+
19
+ describe "instance" do
20
+ subject{ build(:shipping) }
21
+
22
+ it { should be_valid }
23
+ its(:cost){ should == "12.13" }
24
+ its(:postal_code){ should == "05363000" }
25
+
26
+ context "with invalid postal_code" do
27
+ subject{ build(:shipping, postal_code: 1234567) }
28
+ its(:postal_code){ should be_blank }
44
29
  end
45
- end
46
30
 
47
- describe "#cost" do
48
- it "should return the same specified cost" do
49
- PagSeguro::Shipping.new(valid_attributes).cost.should == "12.13"
31
+ context "with type 1" do
32
+ subject{ build(:shipping, type: 1) }
33
+ it { should be_pac }
50
34
  end
51
- end
52
35
 
53
- it "should be able to initialize all attributes" do
54
- PagSeguro::Shipping.new(valid_attributes).should be_valid
55
- end
36
+ context "with type 2" do
37
+ subject{ build(:shipping, type: 2) }
38
+ it { should be_sedex }
39
+ end
56
40
 
57
- it "should not show postal code unless valid" do
58
- PagSeguro::Shipping.new(valid_attributes).postal_code.should == "05363000"
59
- PagSeguro::Shipping.new(valid_attributes.merge(postal_code: 1234567)).postal_code.should be_blank
41
+ context "with type 3" do
42
+ subject{ build(:shipping, type: 3) }
43
+ it { should be_unidentified }
44
+ end
60
45
  end
61
- end
46
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,11 @@ end
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'
10
+ require 'factory_girl'
11
+
12
+ include FactoryGirl::Syntax::Methods
13
+ FactoryGirl.find_definitions
9
14
 
10
15
  config = YAML.load_file(File.dirname(__FILE__) + "/pag_seguro/integration/config.yml")
11
16
  EMAIL = config["email"]
@@ -13,26 +18,12 @@ TOKEN = config["token"]
13
18
  NOTIFICATION_CODE = config["notification_code"]
14
19
  TRANSACTION_ID = config["transaction_id"]
15
20
 
16
- class HaveAttributeAccessor
17
- def initialize(attribute)
18
- @attribute = attribute
19
- end
20
-
21
- def matches?(target)
22
- @target = target
23
- @target.respond_to?(:"#{@attribute}").should == true
24
- @target.respond_to?(:"#{@attribute}=").should == true
25
- end
26
-
27
- def failure_message
28
- "expected #{@target.inspect} to have '#{@expected}' attribute accessor"
21
+ RSpec::Matchers.define :have_attribute_accessor do |attribute|
22
+ match do |actual|
23
+ actual.respond_to?(attribute) && actual.respond_to?("#{attribute}=")
29
24
  end
30
-
31
- def negative_failure_message
32
- "expected #{@target.inspect} not to have '#{@expected}' attribute accessor"
33
- end
34
- end
35
25
 
36
- def have_attribute_accessor(attribute)
37
- HaveAttributeAccessor.new(attribute)
26
+ description do
27
+ "have attr_accessor :#{attribute}"
28
+ end
38
29
  end
@@ -179,31 +179,31 @@ shared_examples_for "a transaction" do
179
179
  end
180
180
 
181
181
  describe "::status_for" do
182
- it "should return :processing when 1" do
182
+ it "should return :processing for 1" do
183
183
  subject.status_for(1).should == :processing
184
184
  end
185
185
 
186
- it "should return :in_analysis when 2" do
186
+ it "should return :in_analysis for 2" do
187
187
  subject.status_for(2).should == :in_analysis
188
188
  end
189
189
 
190
- it "should return :approved when 3" do
190
+ it "should return :approved for 3" do
191
191
  subject.status_for(3).should == :approved
192
192
  end
193
193
 
194
- it "should return :available when 4" do
194
+ it "should return :available for 4" do
195
195
  subject.status_for(4).should == :available
196
196
  end
197
197
 
198
- it "should return :disputed when 5" do
198
+ it "should return :disputed for 5" do
199
199
  subject.status_for(5).should == :disputed
200
200
  end
201
201
 
202
- it "should return :returned when 6" do
202
+ it "should return :returned for 6" do
203
203
  subject.status_for(6).should == :returned
204
204
  end
205
205
 
206
- it "should return :cancelled when 7" do
206
+ it "should return :cancelled for 7" do
207
207
  subject.status_for(7).should == :cancelled
208
208
  end
209
209
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pag_seguro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-26 00:00:00.000000000 Z
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: haml
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +106,8 @@ files:
90
106
  - Rakefile
91
107
  - lib/pag_seguro.rb
92
108
  - lib/pag_seguro/checkout.xml.haml
109
+ - lib/pag_seguro/convert_field_to_digit.rb
110
+ - lib/pag_seguro/day_of_year.rb
93
111
  - lib/pag_seguro/errors/invalid_data.rb
94
112
  - lib/pag_seguro/errors/unauthorized.rb
95
113
  - lib/pag_seguro/errors/unknown_error.rb
@@ -97,14 +115,20 @@ files:
97
115
  - lib/pag_seguro/notification.rb
98
116
  - lib/pag_seguro/payment.rb
99
117
  - lib/pag_seguro/payment_method.rb
118
+ - lib/pag_seguro/pre_approval.rb
100
119
  - lib/pag_seguro/query.rb
101
120
  - lib/pag_seguro/sender.rb
102
121
  - lib/pag_seguro/shipping.rb
103
122
  - lib/pag_seguro/transaction.rb
104
123
  - lib/pag_seguro/version.rb
124
+ - lib/pagseguro_decimal_validator.rb
105
125
  - pag_seguro.gemspec
126
+ - spec/factories.rb
106
127
  - spec/fixtures/transaction.xml
128
+ - spec/fixtures/transaction_history.xml
107
129
  - spec/pag_seguro/checkout_xml_spec.rb
130
+ - spec/pag_seguro/convert_field_to_digit_spec.rb
131
+ - spec/pag_seguro/day_of_year_spec.rb
108
132
  - spec/pag_seguro/errors/invalid_data_spec.rb
109
133
  - spec/pag_seguro/errors/unauthorized_spec.rb
110
134
  - spec/pag_seguro/errors/unknown_error_spec.rb
@@ -116,6 +140,7 @@ files:
116
140
  - spec/pag_seguro/notification_spec.rb
117
141
  - spec/pag_seguro/payment_method_spec.rb
118
142
  - spec/pag_seguro/payment_spec.rb
143
+ - spec/pag_seguro/pre_approval_spec.rb
119
144
  - spec/pag_seguro/query_spec.rb
120
145
  - spec/pag_seguro/sender_spec.rb
121
146
  - spec/pag_seguro/shipping_spec.rb
@@ -148,8 +173,12 @@ signing_key:
148
173
  specification_version: 3
149
174
  summary: A ruby gem to handle PagSeguro's API version 2
150
175
  test_files:
176
+ - spec/factories.rb
151
177
  - spec/fixtures/transaction.xml
178
+ - spec/fixtures/transaction_history.xml
152
179
  - spec/pag_seguro/checkout_xml_spec.rb
180
+ - spec/pag_seguro/convert_field_to_digit_spec.rb
181
+ - spec/pag_seguro/day_of_year_spec.rb
153
182
  - spec/pag_seguro/errors/invalid_data_spec.rb
154
183
  - spec/pag_seguro/errors/unauthorized_spec.rb
155
184
  - spec/pag_seguro/errors/unknown_error_spec.rb
@@ -161,6 +190,7 @@ test_files:
161
190
  - spec/pag_seguro/notification_spec.rb
162
191
  - spec/pag_seguro/payment_method_spec.rb
163
192
  - spec/pag_seguro/payment_spec.rb
193
+ - spec/pag_seguro/pre_approval_spec.rb
164
194
  - spec/pag_seguro/query_spec.rb
165
195
  - spec/pag_seguro/sender_spec.rb
166
196
  - spec/pag_seguro/shipping_spec.rb
@@ -168,4 +198,3 @@ test_files:
168
198
  - spec/pag_seguro/version_spec.rb
169
199
  - spec/spec_helper.rb
170
200
  - spec/support/transaction_shared_examples.rb
171
- has_rdoc: false