Skip to content

Commit

Permalink
Bug fix: the development mode was raising an exception when shipping …
Browse files Browse the repository at this point in the history
…wasn't present. Closes issue #6.
  • Loading branch information
fnando committed Oct 16, 2010
1 parent fa89ba3 commit 96be75e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 434 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spec/support/tmp/**/*
spec/support/log/*.log
pkg
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
source :rubygems

gem "rails", "3.0.0"
gem "rails", "3.0.1"
gem "fakeweb"
gem "rspec-rails", "2.0.0.beta.20"
gem "rspec-rails", "2.0.1"
gem "faker"
gem "ruby-debug19", :require => false
gem "nokogiri"
gem "sqlite3-ruby"
80 changes: 42 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (= 3.0.0)
actionmailer (3.0.1)
actionpack (= 3.0.1)
mail (~> 2.2.5)
actionpack (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
actionpack (3.0.1)
activemodel (= 3.0.1)
activesupport (= 3.0.1)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4.1)
rack (~> 1.2.1)
rack-mount (~> 0.6.12)
rack-test (~> 0.5.4)
tzinfo (~> 0.3.23)
activemodel (3.0.0)
activesupport (= 3.0.0)
activemodel (3.0.1)
activesupport (= 3.0.1)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
activerecord (3.0.1)
activemodel (= 3.0.1)
activesupport (= 3.0.1)
arel (~> 1.0.0)
tzinfo (~> 0.3.23)
activeresource (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
activeresource (3.0.1)
activemodel (= 3.0.1)
activesupport (= 3.0.1)
activesupport (3.0.1)
archive-tar-minitar (0.5.2)
arel (1.0.1)
activesupport (~> 3.0.0)
Expand All @@ -41,7 +41,7 @@ GEM
i18n (0.4.1)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
mail (2.2.5)
mail (2.2.7)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
Expand All @@ -51,32 +51,34 @@ GEM
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-test (0.5.4)
rack-test (0.5.6)
rack (>= 1.0)
rails (3.0.0)
actionmailer (= 3.0.0)
actionpack (= 3.0.0)
activerecord (= 3.0.0)
activeresource (= 3.0.0)
activesupport (= 3.0.0)
rails (3.0.1)
actionmailer (= 3.0.1)
actionpack (= 3.0.1)
activerecord (= 3.0.1)
activeresource (= 3.0.1)
activesupport (= 3.0.1)
bundler (~> 1.0.0)
railties (= 3.0.0)
railties (3.0.0)
actionpack (= 3.0.0)
activesupport (= 3.0.0)
railties (= 3.0.1)
railties (3.0.1)
actionpack (= 3.0.1)
activesupport (= 3.0.1)
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
rspec (2.0.0.beta.20)
rspec-core (= 2.0.0.beta.20)
rspec-expectations (= 2.0.0.beta.20)
rspec-mocks (= 2.0.0.beta.20)
rspec-core (2.0.0.beta.20)
rspec-expectations (2.0.0.beta.20)
rspec (2.0.0)
rspec-core (= 2.0.0)
rspec-expectations (= 2.0.0)
rspec-mocks (= 2.0.0)
rspec-core (2.0.0)
rspec-expectations (2.0.0)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.20)
rspec-rails (2.0.0.beta.20)
rspec (= 2.0.0.beta.20)
rspec-mocks (2.0.0)
rspec-core (= 2.0.0)
rspec-expectations (= 2.0.0)
rspec-rails (2.0.1)
rspec (~> 2.0.0)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
Expand All @@ -87,7 +89,8 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
thor (0.14.0)
sqlite3-ruby (1.3.1)
thor (0.14.3)
treetop (1.4.8)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
Expand All @@ -99,6 +102,7 @@ DEPENDENCIES
faker
fakeweb
nokogiri
rails (= 3.0.0)
rspec-rails (= 2.0.0.beta.20)
rails (= 3.0.1)
rspec-rails (= 2.0.1)
ruby-debug19
sqlite3-ruby
11 changes: 8 additions & 3 deletions lib/pagseguro/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,20 @@ def run
count
end

# Replace all products
to_price = lambda {|s| s.gsub(/^(.*?)(.{2})$/, '\1,\2') }
to_price = proc do |price|
if price.to_s =~ /^(.*?)(.{2})$/
"#{$1},#{$2}"
else
"0,00"
end
end

for index in (1..order["NumItens"])
order["ProdID_#{index}"] = order.delete("item_id_#{index}")
order["ProdDescricao_#{index}"] = order.delete("item_descr_#{index}")
order["ProdValor_#{index}"] = to_price.call(order.delete("item_valor_#{index}"))
order["ProdQuantidade_#{index}"] = order.delete("item_quant_#{index}")
order["ProdFrete_#{index}"] = order["item_frete_#{index}"] == "0" ? "0,00" : to_price.call(order.delete("item_frete_#{index}"))
order["ProdFrete_#{index}"] = to_price.call(order.delete("item_frete_#{index}"))
order["ProdExtras_#{index}"] = "0,00"
end

Expand Down
15 changes: 11 additions & 4 deletions spec/pagseguro/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def self.post_form(uri, params)
FileUtils.cp @origin, @destiny

# Stub Digest::MD5#hexdigest to always return THEHASH
Digest::MD5.stub!(:hexdigest).and_return("THEHASH")
Digest::MD5.stub :hexdigest => "THEHASH"

# Stub the URI#parse to return a mock
@uri = mock("URI").as_null_object
URI.stub!(:parse).and_return(@uri)
URI.stub :parse => @uri

# Load the pagseguro-test.yml file to
# set some variables in order to compare it
Expand Down Expand Up @@ -55,7 +55,7 @@ def self.post_form(uri, params)
end

it "should set number of items" do
params["NumItens"].should == 3
params["NumItens"].should == 4
end

it "should set note" do
Expand All @@ -72,7 +72,7 @@ def self.post_form(uri, params)

it "should set transaction date" do
now = Time.now
Time.stub!(:now).and_return(now)
Time.stub :now => now

PagSeguro::Rake.run
params["DataTransacao"].should == now.strftime("%d/%m/%Y %H:%M:%S")
Expand Down Expand Up @@ -103,6 +103,13 @@ def self.post_form(uri, params)
params["ProdQuantidade_3"].should == "2"
params["ProdExtras_3"].should == "0,00"
params["ProdFrete_3"].should == "2,50"

params["ProdID_4"].should == "4"
params["ProdDescricao_4"].should == "Ruby Mug"
params["ProdValor_4"].should == "15,99"
params["ProdQuantidade_4"].should == "1"
params["ProdExtras_4"].should == "0,00"
params["ProdFrete_4"].should == "0,00"
end

it "should set client info" do
Expand Down
File renamed without changes.
Loading

0 comments on commit 96be75e

Please sign in to comment.