rbraspag 0.0.19 → 0.1.0

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.
@@ -1,105 +1,118 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
 
4
4
  describe Braspag::Order do
5
- let!(:braspag_url) { "https://homologacao.pagador.com.br" }
6
- let!(:braspag_query_url) { "https://homologacao.pagador.com.br/pagador/webservice/pedido.asmx" }
7
-
8
- describe "#status" do
9
- it "should raise an error when no order_id is given" do
10
- expect {
11
- Braspag::Order.status(nil)
12
- }.to raise_error(Braspag::InvalidOrderId)
13
- end
14
-
15
- it "should raise an error when order_id is empty" do
16
- expect {
17
- Braspag::Order.status("")
18
- }.to raise_error(Braspag::InvalidOrderId)
19
- end
5
+ let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
6
+ let(:braspag_production_url) { "https://transaction.pagador.com.br" }
7
+ let(:merchant_id) { "um id qualquer" }
20
8
 
21
- it "should raise an error when order_id is more than 50 characters" do
22
- expect {
23
- Braspag::Order.status("1" * 51)
24
- }.to raise_error(Braspag::InvalidOrderId)
25
- end
9
+ before do
10
+ @connection = mock(:merchant_id => merchant_id)
11
+ Braspag::Connection.stub(:instance => @connection)
12
+ end
26
13
 
27
- it "should raise an error for incorrect data" do
28
- xml = <<-EOXML
29
- <?xml version="1.0" encoding="utf-8"?>
30
- <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
32
- xsi:nil="true"
33
- xmlns="http://www.pagador.com.br/" />
34
- EOXML
14
+ describe ".status" do
15
+ let(:order_id) { "um order id qualquer" }
16
+ let(:status_url) { "http://foo.com/bar/baz/assererre" }
17
+
18
+ context "with invalid order id" do
19
+ let(:invalid_xml) do
20
+ <<-EOXML
21
+ <?xml version="1.0" encoding="utf-8"?>
22
+ <DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
24
+ xsi:nil="true"
25
+ xmlns="http://www.pagador.com.br/" />
26
+ EOXML
27
+ end
35
28
 
36
- FakeWeb.register_uri(:post, "#{braspag_query_url}/GetDadosPedido",
37
- :body => xml)
29
+ it "should raise an error when order id is not valid" do
30
+ Braspag::PaymentMethod.should_receive(:valid_order_id?)
31
+ .with(order_id)
32
+ .and_return(false)
38
33
 
39
- expect {
40
- Braspag::Order.status("sadpoakjspodqdouq09wduwq")
41
- }.to raise_error(Braspag::Order::InvalidData)
34
+ expect {
35
+ Braspag::Order.status(order_id)
36
+ }.to raise_error(Braspag::InvalidOrderId)
37
+ end
42
38
 
39
+ it "should raise an error when Braspag returns an invalid xml" do
40
+ FakeWeb.register_uri(:post, status_url, :body => invalid_xml)
43
41
 
44
- expect {
45
- Braspag::Order.status("asdnasdniousa")
46
- }.to raise_error(Braspag::Order::InvalidData)
42
+ Braspag::Order.should_receive(:status_url)
43
+ .and_return(status_url)
47
44
 
48
- FakeWeb.clean_registry
45
+ expect {
46
+ Braspag::Order.status(order_id)
47
+ }.to raise_error(Braspag::Order::InvalidData)
48
+ end
49
49
  end
50
50
 
51
- context "with correct data" do
52
-
53
- let(:order_info) {
54
- xml = <<-EOXML
55
- <?xml version="1.0" encoding="utf-8"?>
56
- <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
58
- xmlns="http://www.pagador.com.br/">
59
- <CodigoAutorizacao>885796</CodigoAutorizacao>
60
- <CodigoPagamento>18</CodigoPagamento>
61
- <FormaPagamento>American Express 2P</FormaPagamento>
62
- <NumeroParcelas>1</NumeroParcelas>
63
- <Status>3</Status>
64
- <Valor>0.01</Valor>
65
- <DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
66
- <DataPedido>7/8/2011 1:06:06 PM</DataPedido>
67
- <TransId>398591</TransId>
68
- <BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
69
- </DadosPedido>
51
+ context "with valid order id" do
52
+ let(:valid_xml) do
53
+ <<-EOXML
54
+ <?xml version="1.0" encoding="utf-8"?>
55
+ <DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
57
+ xmlns="http://www.pagador.com.br/">
58
+ <CodigoAutorizacao>885796</CodigoAutorizacao>
59
+ <CodigoPagamento>18</CodigoPagamento>
60
+ <FormaPagamento>American Express 2P</FormaPagamento>
61
+ <NumeroParcelas>1</NumeroParcelas>
62
+ <Status>3</Status>
63
+ <Valor>0.01</Valor>
64
+ <DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
65
+ <DataPedido>7/8/2011 1:06:06 PM</DataPedido>
66
+ <TransId>398591</TransId>
67
+ <BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
68
+ </DadosPedido>
70
69
  EOXML
70
+ end
71
71
 
72
- FakeWeb.register_uri(:post, "#{braspag_query_url}/GetDadosPedido",
73
- :body => xml)
74
- order_info = Braspag::Order.status("12345")
75
- FakeWeb.clean_registry
76
- order_info
77
- }
72
+ before do
73
+ Braspag::Order.should_receive(:status_url)
74
+ .and_return(status_url)
78
75
 
79
- it "should return a Hash" do
80
- order_info.should be_kind_of Hash
76
+ FakeWeb.register_uri(:post, status_url, :body => valid_xml)
77
+ @response = Braspag::Order.status(order_id)
81
78
  end
82
79
 
83
- {
84
- :authorization => "885796",
85
- :error_code => nil,
86
- :error_message => nil,
87
- :payment_method => "18",
88
- :payment_method_name => "American Express 2P",
89
- :installments => "1",
90
- :status => "3",
91
- :amount => "0.01",
92
- :cancelled_at => nil,
93
- :paid_at => "7/8/2011 1:19:38 PM",
94
- :order_date => "7/8/2011 1:06:06 PM",
95
- :transaction_id => "398591",
96
- :tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
97
- }.each do |key, value|
98
-
99
- it "should return a Hash with :#{key.to_s} key" do
100
- order_info[key].should == value
101
- end
80
+ it "should return a Hash" do
81
+ @response.should be_kind_of Hash
82
+ @response.should == {
83
+ :authorization => "885796",
84
+ :error_code => nil,
85
+ :error_message => nil,
86
+ :payment_method => "18",
87
+ :payment_method_name => "American Express 2P",
88
+ :installments => "1",
89
+ :status => "3",
90
+ :amount => "0.01",
91
+ :cancelled_at => nil,
92
+ :paid_at => "7/8/2011 1:19:38 PM",
93
+ :order_date => "7/8/2011 1:06:06 PM",
94
+ :transaction_id => "398591",
95
+ :tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
96
+ }
102
97
  end
103
98
  end
104
99
  end
100
+
101
+ describe ".status_url" do
102
+ it "should return the correct info url when connection environment is homologation" do
103
+ @connection.stub(:braspag_url => braspag_homologation_url)
104
+ @connection.should_receive(:production?)
105
+ .and_return(false)
106
+
107
+ Braspag::Order.status_url.should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosPedido"
108
+ end
109
+
110
+ it "should return the correct info url when connection environment is production" do
111
+ @connection.stub(:braspag_url => braspag_production_url)
112
+ @connection.should_receive(:production?)
113
+ .and_return(true)
114
+
115
+ Braspag::Order.status_url.should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosPedido"
116
+ end
117
+ end
105
118
  end
@@ -6,6 +6,10 @@ ENV["RACK_ENV"] ||= "test"
6
6
 
7
7
  RSpec.configure do |config|
8
8
  config.mock_with :rspec
9
+ config.after(:each) do
10
+ FakeWeb.clean_registry
11
+ end
9
12
 
10
13
  HTTPI.log = false
11
- end
14
+ FakeWeb.allow_net_connect = false
15
+ end
@@ -1,26 +1,47 @@
1
- #encoding: utf-8
2
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
2
 
4
3
  describe Braspag::Utils do
5
- it '.convert_decimal_to_string' do
6
- Braspag::Utils.convert_decimal_to_string(10.80).should == "10,80"
4
+ describe ".convert_decimal_to_string" do
5
+ it "should convert decimal to string with comma as decimal separator" do
6
+ Braspag::Utils.convert_decimal_to_string(10).should == "10,00"
7
+ Braspag::Utils.convert_decimal_to_string(1).should == "1,00"
8
+ Braspag::Utils.convert_decimal_to_string(0.1).should == "0,10"
9
+ Braspag::Utils.convert_decimal_to_string(0.01).should == "0,01"
10
+ Braspag::Utils.convert_decimal_to_string(9.99999).should == "10,00" # round up
11
+ Braspag::Utils.convert_decimal_to_string(10.9).should == "10,90"
12
+ Braspag::Utils.convert_decimal_to_string(9.1111).should == "9,11"
13
+ end
7
14
  end
8
15
 
9
- it '.convert_decimal_to_string' do
10
- Braspag::Utils.convert_decimal_to_string(10.00).should == "10,00"
11
- end
12
-
13
- it '.convert_decimal_to_string' do
14
- Braspag::Utils.convert_decimal_to_string(1).should == "1,00"
15
- end
16
-
17
- it '.convert_decimal_to_string' do
18
- Braspag::Utils.convert_decimal_to_string(1.00).should == "1,00"
19
- end
16
+ describe ".convert_to_map" do
17
+ let(:document) do
18
+ <<-XML
19
+ <root>
20
+ <foo>blabla</foo>
21
+ <bar>bleble</bar>
22
+ <baz></baz>
23
+ </root>
24
+ XML
25
+ end
26
+
27
+ context "basic document and keys" do
28
+ it "should return a Hash" do
29
+ keys = { :foo => nil, :meu_elemento => "bar", :outro_elemento => "baz" }
30
+ expected = { :foo => "blabla", :meu_elemento => "bleble", :outro_elemento => nil }
31
+
32
+ Braspag::Utils::convert_to_map(document, keys).should == expected
33
+ end
34
+ end
35
+
36
+ context "keys with a Proc" do
37
+ it "should return a Hash" do
38
+ proc = Proc.new { "value returned by Proc" }
39
+
40
+ keys = { :foo => proc, :meu_elemento => "bar", :outro_elemento => "baz" }
41
+ expected = { :foo => "value returned by Proc", :meu_elemento => "bleble", :outro_elemento => nil }
20
42
 
21
- it '.convert_decimal_to_string' do
22
- Braspag::Utils.convert_decimal_to_string(0.90).should == "0,90"
43
+ Braspag::Utils::convert_to_map(document, keys).should == expected
44
+ end
45
+ end
23
46
  end
24
-
25
- pending "convert_to_map"
26
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbraspag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,11 +14,11 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-01-05 00:00:00.000000000Z
17
+ date: 2012-01-09 00:00:00.000000000Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: cs-httpi
21
- requirement: &70280110585040 !ruby/object:Gem::Requirement
21
+ requirement: &70228358717520 !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
24
  - - ! '>='
@@ -26,10 +26,10 @@ dependencies:
26
26
  version: 0.9.5.2
27
27
  type: :runtime
28
28
  prerelease: false
29
- version_requirements: *70280110585040
29
+ version_requirements: *70228358717520
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: json
32
- requirement: &70280110582040 !ruby/object:Gem::Requirement
32
+ requirement: &70228358716620 !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
@@ -37,21 +37,21 @@ dependencies:
37
37
  version: 1.6.1
38
38
  type: :runtime
39
39
  prerelease: false
40
- version_requirements: *70280110582040
40
+ version_requirements: *70228358716620
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
- requirement: &70280110574920 !ruby/object:Gem::Requirement
43
+ requirement: &70228358715680 !ruby/object:Gem::Requirement
44
44
  none: false
45
45
  requirements:
46
46
  - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
- version: 1.5.0
48
+ version: 1.4.7
49
49
  type: :runtime
50
50
  prerelease: false
51
- version_requirements: *70280110574920
51
+ version_requirements: *70228358715680
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: rake
54
- requirement: &70280110572880 !ruby/object:Gem::Requirement
54
+ requirement: &70228358715120 !ruby/object:Gem::Requirement
55
55
  none: false
56
56
  requirements:
57
57
  - - ! '>='
@@ -59,10 +59,10 @@ dependencies:
59
59
  version: '0'
60
60
  type: :development
61
61
  prerelease: false
62
- version_requirements: *70280110572880
62
+ version_requirements: *70228358715120
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rspec
65
- requirement: &70280110560300 !ruby/object:Gem::Requirement
65
+ requirement: &70228358714000 !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
68
68
  - - ! '>='
@@ -70,10 +70,10 @@ dependencies:
70
70
  version: '0'
71
71
  type: :development
72
72
  prerelease: false
73
- version_requirements: *70280110560300
73
+ version_requirements: *70228358714000
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: fakeweb
76
- requirement: &70280110545760 !ruby/object:Gem::Requirement
76
+ requirement: &70228358713380 !ruby/object:Gem::Requirement
77
77
  none: false
78
78
  requirements:
79
79
  - - ! '>='
@@ -81,10 +81,10 @@ dependencies:
81
81
  version: '0'
82
82
  type: :development
83
83
  prerelease: false
84
- version_requirements: *70280110545760
84
+ version_requirements: *70228358713380
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: shoulda-matchers
87
- requirement: &70280110543940 !ruby/object:Gem::Requirement
87
+ requirement: &70228358712540 !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
90
90
  - - ! '>='
@@ -92,10 +92,10 @@ dependencies:
92
92
  version: '0'
93
93
  type: :development
94
94
  prerelease: false
95
- version_requirements: *70280110543940
95
+ version_requirements: *70228358712540
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: guard-rspec
98
- requirement: &70280110538180 !ruby/object:Gem::Requirement
98
+ requirement: &70228358711900 !ruby/object:Gem::Requirement
99
99
  none: false
100
100
  requirements:
101
101
  - - ! '>='
@@ -103,10 +103,10 @@ dependencies:
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
- version_requirements: *70280110538180
106
+ version_requirements: *70228358711900
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: guard-bundler
109
- requirement: &70280110533400 !ruby/object:Gem::Requirement
109
+ requirement: &70228358711220 !ruby/object:Gem::Requirement
110
110
  none: false
111
111
  requirements:
112
112
  - - ! '>='
@@ -114,10 +114,10 @@ dependencies:
114
114
  version: '0'
115
115
  type: :development
116
116
  prerelease: false
117
- version_requirements: *70280110533400
117
+ version_requirements: *70228358711220
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: ruby-debug19
120
- requirement: &70280110529600 !ruby/object:Gem::Requirement
120
+ requirement: &70228358710580 !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
123
  - - ! '>='
@@ -125,7 +125,7 @@ dependencies:
125
125
  version: '0'
126
126
  type: :development
127
127
  prerelease: false
128
- version_requirements: *70280110529600
128
+ version_requirements: *70228358710580
129
129
  description: rbraspag gem to use Braspag gateway
130
130
  email:
131
131
  - tinorj@gmail.com
@@ -141,7 +141,6 @@ files:
141
141
  - .gitignore
142
142
  - .rspec
143
143
  - Gemfile
144
- - Gemfile.lock
145
144
  - Guardfile
146
145
  - README.md
147
146
  - Rakefile
@@ -1,63 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rbraspag (0.0.18)
5
- cs-httpi (>= 0.9.5.2)
6
- json (>= 1.6.1)
7
- nokogiri (>= 1.5.0)
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- archive-tar-minitar (0.5.2)
13
- columnize (0.3.3)
14
- cs-httpi (0.9.5.2)
15
- rack
16
- diff-lcs (1.1.2)
17
- fakeweb (1.3.0)
18
- guard (0.4.2)
19
- thor (~> 0.14.6)
20
- guard-bundler (0.1.3)
21
- bundler (>= 1.0.0)
22
- guard (>= 0.2.2)
23
- guard-rspec (0.4.0)
24
- guard (>= 0.4.0)
25
- json (1.6.4)
26
- linecache19 (0.5.12)
27
- ruby_core_source (>= 0.1.4)
28
- nokogiri (1.5.0)
29
- rack (1.4.0)
30
- rake (0.9.2)
31
- rspec (2.6.0)
32
- rspec-core (~> 2.6.0)
33
- rspec-expectations (~> 2.6.0)
34
- rspec-mocks (~> 2.6.0)
35
- rspec-core (2.6.4)
36
- rspec-expectations (2.6.0)
37
- diff-lcs (~> 1.1.2)
38
- rspec-mocks (2.6.0)
39
- ruby-debug-base19 (0.11.25)
40
- columnize (>= 0.3.1)
41
- linecache19 (>= 0.5.11)
42
- ruby_core_source (>= 0.1.4)
43
- ruby-debug19 (0.11.6)
44
- columnize (>= 0.3.1)
45
- linecache19 (>= 0.5.11)
46
- ruby-debug-base19 (>= 0.11.19)
47
- ruby_core_source (0.1.5)
48
- archive-tar-minitar (>= 0.5.2)
49
- shoulda-matchers (1.0.0.beta2)
50
- thor (0.14.6)
51
-
52
- PLATFORMS
53
- ruby
54
-
55
- DEPENDENCIES
56
- fakeweb
57
- guard-bundler
58
- guard-rspec
59
- rake
60
- rbraspag!
61
- rspec
62
- ruby-debug19
63
- shoulda-matchers