Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some specs

  • Loading branch information...
commit 58c2083e3c9d462ba780147acb706814354a7071 1 parent c6a01f6
@nov authored
View
1  Gemfile
@@ -1 +1,2 @@
+source 'http://rubygems.org'
gemspec
View
2  Rakefile
@@ -6,7 +6,7 @@ RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.rcov = true
- spec.rcov_opts = ['--exclude spec,gems']
+ spec.rcov_opts = ['-Ilib -Ispec --exclude spec,gems']
end
task :default => :spec
View
5 lib/paypal.rb
@@ -1,4 +1,4 @@
-require "logger"
+require 'logger'
require 'active_support/core_ext'
require 'attr_required'
require 'attr_optional'
@@ -22,7 +22,7 @@ def self.logger=(logger)
@@logger = logger
end
@@logger = Logger.new(STDERR)
- @@logger.progname = "Paypal::Express"
+ @@logger.progname = 'Paypal::Express'
def self.sandbox?
@@sandbox
@@ -49,7 +49,6 @@ def self.sandbox=(boolean)
require 'paypal/payment/response/amount'
require 'paypal/payment/response/info'
require 'paypal/payment/response/payer'
-require 'paypal/payment/response/recurring'
require 'paypal/payment/response/ship_to'
require 'paypal/payment/recurring'
require 'paypal/payment/recurring/activation'
View
2  lib/paypal/util.rb
@@ -5,7 +5,7 @@ def self.formatted_amount(amount)
if amount.to_f == amount.to_i
"#{amount.to_i}.00"
else
- "#{amount.to_i}.#{((amount.to_f - amount.to_i) * 100).to_i}"
+ "#{amount.to_i}.#{(amount * 100).to_s.split(".").first.to_i % 100}"
end
end
View
10 paypal-express.gemspec
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
s.authors = ["nov matake"]
s.description = %q{Rugy Gem for PayPal Express Checkout API}
- s.summary = %q{Rugy Gem for PayPal Express Checkout API}
+ s.summary = %q{PayPal Express Checkout API Client Supporting Both Instant and Recurring Payment}
s.email = "nov@matake.jp"
s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
s.rdoc_options = ["--charset=UTF-8"]
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.add_runtime_dependency "activesupport", ">= 2.3"
- s.add_runtime_dependency "i18n"
- s.add_runtime_dependency "rest-client", ">= 1.4"
- s.add_runtime_dependency "attr_required", ">= 0.0.3"
+ s.add_dependency "activesupport", ">= 2.3"
+ s.add_dependency "i18n"
+ s.add_dependency "rest-client", ">= 1.4"
+ s.add_dependency "attr_required", ">= 0.0.3"
s.add_development_dependency "rake", ">= 0.8"
s.add_development_dependency "rcov", ">= 0.9"
s.add_development_dependency "rspec", ">= 2"
View
4 spec/paypal/express/request_spec.rb
@@ -20,7 +20,7 @@
end
lambda do
Paypal::Express::Request.new insufficient_attributes
- end.should raise_error Paypal::AttrMissing
+ end.should raise_error AttrRequired::AttrMissing
end
end
end
@@ -29,7 +29,7 @@
it 'should succeed' do
lambda do
Paypal::Express::Request.new required_params
- end.should_not raise_error Paypal::AttrMissing
+ end.should_not raise_error AttrRequired::AttrMissing
end
end
View
4 spec/paypal/nvp/request_spec.rb
@@ -18,7 +18,7 @@
end
lambda do
Paypal::NVP::Request.new insufficient_attributes
- end.should raise_error Paypal::AttrMissing
+ end.should raise_error AttrRequired::AttrMissing
end
end
end
@@ -27,7 +27,7 @@
it 'should succeed' do
lambda do
Paypal::NVP::Request.new required_params
- end.should_not raise_error Paypal::AttrMissing
+ end.should_not raise_error AttrRequired::AttrMissing
end
it 'should setup endpoint and version' do
View
37 spec/paypal/payment/response/amount_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper.rb'
+
+describe Paypal::Payment::Response::Amount, '.new' do
+ let(:attributes) do
+ {}
+ end
+ let(:keys) do
+ Paypal::Payment::Response::Amount.optional_attributes
+ end
+
+ it 'should not allow nil for attributes' do
+ amount = Paypal::Payment::Response::Amount.new attributes
+ keys.each do |key|
+ amount.send(key).should == 0
+ end
+ end
+
+ it 'should treat all attributes as Numeric' do
+ # Integer
+ keys.each do |key|
+ attributes[key] = "100"
+ end
+ amount = Paypal::Payment::Response::Amount.new attributes
+ keys.each do |key|
+ amount.send(key).should == 100
+ end
+
+ # Float
+ keys.each do |key|
+ attributes[key] = "10.25"
+ end
+ amount = Paypal::Payment::Response::Amount.new attributes
+ keys.each do |key|
+ amount.send(key).should == 10.25
+ end
+ end
+end
View
5 spec/paypal/payment/response/info_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper.rb'
+
+describe Paypal::Payment::Response::Info, '.new' do
+ # TODO
+end
View
27 spec/paypal/payment/response/payer_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper.rb'
+
+describe Paypal::Payment::Response::Payer, '.new' do
+ let(:attributes) do
+ {}
+ end
+ let(:keys) do
+ Paypal::Payment::Response::Payer.optional_attributes
+ end
+
+ it 'should allow nil for attributes' do
+ payer = Paypal::Payment::Response::Payer.new attributes
+ keys.each do |key|
+ payer.send(key).should be_nil
+ end
+ end
+
+ it 'should treat all attributes as String' do
+ keys.each do |key|
+ attributes[key] = "xyz"
+ end
+ payer = Paypal::Payment::Response::Payer.new attributes
+ keys.each do |key|
+ payer.send(key).should == "xyz"
+ end
+ end
+end
View
27 spec/paypal/payment/response/ship_to_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper.rb'
+
+describe Paypal::Payment::Response::ShipTo, '.new' do
+ let(:attributes) do
+ {}
+ end
+ let(:keys) do
+ Paypal::Payment::Response::ShipTo.optional_attributes
+ end
+
+ it 'should allow nil for attributes' do
+ payer = Paypal::Payment::Response::ShipTo.new attributes
+ keys.each do |key|
+ payer.send(key).should be_nil
+ end
+ end
+
+ it 'should treat all attributes as String' do
+ keys.each do |key|
+ attributes[key] = "xyz"
+ end
+ payer = Paypal::Payment::Response::ShipTo.new attributes
+ keys.each do |key|
+ payer.send(key).should == "xyz"
+ end
+ end
+end
View
24 spec/paypal/util_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper.rb'
+
+describe Paypal::Util, '.formatted_amount' do
+ it 'should return String in "xx.yy" format' do
+ Paypal::Util.formatted_amount(nil).should == '0.00'
+ Paypal::Util.formatted_amount(10).should == '10.00'
+ Paypal::Util.formatted_amount(10.2).should == '10.20'
+ Paypal::Util.formatted_amount(10.24).should == '10.24'
+ Paypal::Util.formatted_amount(10.255).should == '10.25'
+ end
+end
+
+describe Paypal::Util, '.numeric_amount' do
+ it 'should return Numeric' do
+ Paypal::Util.numeric_amount('0').should == 0
+ Paypal::Util.numeric_amount('0.00').should == 0
+ Paypal::Util.numeric_amount('10').should == 10
+ Paypal::Util.numeric_amount('10.00').should == 10
+ Paypal::Util.numeric_amount('10.2').should == 10.2
+ Paypal::Util.numeric_amount('10.20').should == 10.2
+ Paypal::Util.numeric_amount('10.24').should == 10.24
+ Paypal::Util.numeric_amount('10.25').should == 10.25
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.