simplepay-rails4 0.4.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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/CHANGELOG.md +34 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +104 -0
  6. data/MIT-LICENSE +22 -0
  7. data/README.md +106 -0
  8. data/Rakefile +13 -0
  9. data/app/helpers/rails_helper.rb +38 -0
  10. data/lib/simplepay/authentication.rb +41 -0
  11. data/lib/simplepay/constants.rb +64 -0
  12. data/lib/simplepay/errors.rb +16 -0
  13. data/lib/simplepay/helpers/form_helper.rb +31 -0
  14. data/lib/simplepay/rails.rb +2 -0
  15. data/lib/simplepay/service.rb +133 -0
  16. data/lib/simplepay/services/donation.rb +90 -0
  17. data/lib/simplepay/services/marketplace.rb +88 -0
  18. data/lib/simplepay/services/marketplace_policy.rb +53 -0
  19. data/lib/simplepay/services/standard.rb +58 -0
  20. data/lib/simplepay/services/subscription.rb +95 -0
  21. data/lib/simplepay/support/amount.rb +55 -0
  22. data/lib/simplepay/support/billing_frequency.rb +14 -0
  23. data/lib/simplepay/support/boolean.rb +28 -0
  24. data/lib/simplepay/support/currency.rb +21 -0
  25. data/lib/simplepay/support/epoch.rb +39 -0
  26. data/lib/simplepay/support/field.rb +147 -0
  27. data/lib/simplepay/support/interval.rb +145 -0
  28. data/lib/simplepay/support/simple_amount.rb +37 -0
  29. data/lib/simplepay/support/subscription_period.rb +25 -0
  30. data/lib/simplepay/support.rb +16 -0
  31. data/lib/simplepay/validator.rb +59 -0
  32. data/lib/simplepay/version.rb +3 -0
  33. data/lib/simplepay.rb +29 -0
  34. data/simplepay.gemspec +27 -0
  35. data/test/simplepay/services/test_donation.rb +81 -0
  36. data/test/simplepay/services/test_marketplace.rb +81 -0
  37. data/test/simplepay/services/test_marketplace_policy.rb +48 -0
  38. data/test/simplepay/services/test_standard.rb +71 -0
  39. data/test/simplepay/services/test_subscription.rb +105 -0
  40. data/test/simplepay/support/test_amount.rb +46 -0
  41. data/test/simplepay/support/test_billing_frequency.rb +43 -0
  42. data/test/simplepay/support/test_boolean.rb +17 -0
  43. data/test/simplepay/support/test_epoch.rb +34 -0
  44. data/test/simplepay/support/test_field.rb +99 -0
  45. data/test/simplepay/support/test_interval.rb +92 -0
  46. data/test/simplepay/support/test_simple_amount.rb +28 -0
  47. data/test/simplepay/support/test_subscription_period.rb +49 -0
  48. data/test/simplepay/test_authentication.rb +25 -0
  49. data/test/simplepay/test_service.rb +118 -0
  50. data/test/simplepay/test_validator.rb +32 -0
  51. data/test/test_helper.rb +75 -0
  52. data/test/test_simplepay.rb +11 -0
  53. metadata +145 -0
@@ -0,0 +1,118 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'rexml/document'
3
+ require 'simplepay/service'
4
+
5
+ class TestService < Simplepay::Service
6
+ ENDPOINT_URL = 'http://test.host.url/api'
7
+ SANDBOX_URL = 'http://test.host.url/sandbox'
8
+
9
+ set_submit_tag 'testing'
10
+
11
+ field :field_1
12
+ field :field_2
13
+ required_field :required
14
+ required_field :required2, :value => 'preset'
15
+ end
16
+
17
+ class Simplepay::TestService < ActiveSupport::TestCase
18
+
19
+ context 'Simplepay::Service' do
20
+
21
+ setup do
22
+ @service = ::TestService.new
23
+ end
24
+
25
+ context 'class' do
26
+
27
+ setup do
28
+ @class = @service.class
29
+ end
30
+
31
+ should 'contain the defined fields' do
32
+ fields = @class.fields
33
+ assert_not_nil fields
34
+ assert !fields.empty?
35
+ end
36
+
37
+ should 'contain required field(s)' do
38
+ fields = @class.fields.select { |f| f.required? }
39
+ assert fields.size > 0
40
+ end
41
+
42
+ should 'have different field instances than its service instance' do
43
+ class_fields, instance_fields = @class.fields, @service.fields
44
+ instance_fields.each do |instance_field|
45
+ assert !class_fields.include?(instance_field)
46
+ assert class_fields.any? {|f| instance_field.service_name == f.service_name }
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ should 'return a collection of fields' do
53
+ assert !@service.fields.empty?
54
+ assert @service.fields.all? { |f| f.kind_of?(Simplepay::Support::Field) }
55
+ end
56
+
57
+ should 'use the live endpoint url' do
58
+ assert_equal TestService::ENDPOINT_URL, @service.url(false)
59
+ end
60
+
61
+ should 'use the sandbox url' do
62
+ assert_equal TestService::SANDBOX_URL, @service.url(true)
63
+ end
64
+
65
+ should 'generate an HTML FORM' do
66
+ @service.required = 'set'
67
+ assert_match(/\A<form/i, @service.form)
68
+ assert_match(/<\/form>\Z/i, @service.form)
69
+ end
70
+
71
+ should 'post the form to the endpoint' do
72
+ assert_match(/<form action="#{Regexp.escape('http://test.host.url/sandbox')}" method="post"/, @service.form({:required => 'set'}))
73
+ end
74
+
75
+ should 'generate HIDDEN HTML INPUTs for each non-empty field' do
76
+ @service.required = 'Test Field'
77
+ @service.field_1 = 'Testing'
78
+
79
+ defined_fields = @service.fields.select { |f| !f.value.blank? }
80
+ assert defined_fields.size > 0, "This test cannot be run without defined fields"
81
+ document = REXML::Document.new(@service.form)
82
+ form_inputs = []
83
+ document.root.each_element("//input[@type='hidden']") do |e|
84
+ field = defined_fields.detect { |f| f.service_name == e.attributes['name'] }
85
+ assert field, "#{e} unrecognized"
86
+ form_inputs << e
87
+ end
88
+ assert_equal defined_fields.size, form_inputs.size
89
+ end
90
+
91
+ should 'allow fields to be set through hash' do
92
+ assert_nothing_raised(Simplepay::RequiredFieldMissing) do
93
+ TestService.new.form({:required => 'covered'})
94
+ end
95
+ end
96
+
97
+ should 'raise an error for undefined required fields' do
98
+ assert_raise(Simplepay::RequiredFieldMissing) { @service.form }
99
+ end
100
+
101
+ should 'default to a basic HTML SUBMIT button' do
102
+ document = REXML::Document.new(@service.form({:required => 'set'}))
103
+ assert_not_nil document.root.elements["input[@type='submit']"]
104
+ end
105
+
106
+ should 'allow class definition of the default submit text' do
107
+ document = REXML::Document.new(@service.form({:required => 'set'}))
108
+ assert_not_nil document.root.elements["input[@type='submit' and @value='testing']"]
109
+ end
110
+
111
+ should 'allow the HTML SUBMIT button to be overridden' do
112
+ document = REXML::Document.new(@service.form({:required => 'set'}, Simplepay::Helpers::FormHelper.tag(:input, {:type => 'submit', :value => 'Send It'})))
113
+ assert_not_nil document.root.elements["input[@type='submit' and @value='Send It']"]
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+ require "simplepay/validator"
3
+
4
+ class TestValidatorClass
5
+ include Simplepay::Validator
6
+
7
+ def testing(request_hash = {})
8
+ valid_simplepay_request?(request_hash)
9
+ end
10
+ end
11
+
12
+ class Simplepay::TestValidatorHelper < ActiveSupport::TestCase
13
+
14
+ context 'Simplepay::Validator' do
15
+
16
+ setup do
17
+ @validator = TestValidatorClass.new
18
+ end
19
+
20
+ should 'defer to Simplepay::Authentication.authentic?' do
21
+ #Simplepay::Authentication.expects(:authentic?).with({:test => 'testing'}, 'signed').returns(true)
22
+ #assert @validator.testing({:test => 'testing', :signature => 'signed'})
23
+ end
24
+
25
+ should 'work with string hash keys' do
26
+ #Simplepay::Authentication.expects(:authentic?).with({:test => 'testing'}, 'signed').returns(true)
27
+ #assert @validator.testing({"test" => 'testing', "signature" => 'signed'})
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,75 @@
1
+ require 'minitest/autorun'
2
+ require 'active_support'
3
+ require 'minitest-spec-rails'
4
+ require 'minitest-spec-rails/init/active_support'
5
+ require 'minitest-spec-rails/init/mini_shoulda'
6
+
7
+ require File.dirname(__FILE__) + '/../lib/simplepay'
8
+
9
+ module Simplepay #:nodoc:
10
+ module Macros #:nodoc: all
11
+
12
+ def should_not_have_service_field(*names)
13
+ klass = model_class
14
+
15
+ names.each do |name|
16
+ should "not have a field named #{name.inspect}" do
17
+ assert !klass.fields.any? { |f| f.name == name }
18
+ end
19
+ end
20
+ end
21
+
22
+ def should_have_service_field(*names)
23
+ delegate_class, service_name, required = get_options!(names, :class, :as, :required)
24
+ klass = model_class
25
+
26
+ names.each do |name|
27
+ should "have a field named #{name.inspect}" do
28
+ message = "#{klass} does not have a Field named #{name.inspect}"
29
+ assert klass.fields.any? { |f| f.name == name }, message
30
+ end
31
+
32
+ context "#{name} field" do
33
+ should("delegate to #{delegate_class}") do
34
+ message = "#{klass} field #{name.inspect} failed to delegate to #{delegate_class}"
35
+ field = klass.fields.detect { |f| f.name == name }
36
+ assert_equal delegate_class, field.delegate, message
37
+ end if delegate_class
38
+
39
+ should("not delegate") do
40
+ field = klass.fields.detect { |f| f.name == name }
41
+ message = "#{klass} field #{name.inspect} unexpectedly delegated to #{field.delegate}"
42
+ assert !field.delegated?, message
43
+ end unless delegate_class
44
+
45
+ should("have a #{service_name} service name") do
46
+ message = "#{klass} field #{name.inspect} failed to have expected service name"
47
+ field = klass.fields.detect { |f| f.name == name }
48
+ assert_equal service_name, field.service_name
49
+ end if service_name
50
+
51
+ should("#{"not " unless required}be required") do
52
+ message = "#{klass} field #{name.inspect} was#{" not" if required} required"
53
+ field = klass.fields.detect { |f| f.name == name }
54
+ assert_equal required, field.required?, message
55
+ end
56
+ end
57
+ end
58
+ end unless method_defined?(:should_have_service_field)
59
+
60
+ protected
61
+
62
+ # Returns the values for the entries in the args hash who's keys are listed in the wanted array.
63
+ # Will raise if there are keys in the args hash that aren't listed.
64
+ def get_options!(args, *wanted)
65
+ ret = []
66
+ opts = (args.last.is_a?(Hash) ? args.pop : {})
67
+ wanted.each {|w| ret << opts.delete(w)}
68
+ raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty?
69
+ return *ret
70
+ end unless method_defined?(:get_options!)
71
+
72
+ end
73
+ end
74
+
75
+ ActiveSupport::TestCase.send :extend, Simplepay::Macros
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class TestSimplepay < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplepay-rails4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel E. Bibler
8
+ - Derrick Parkhurst
9
+ - Charles DuBose
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-07-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '4'
29
+ - !ruby/object:Gem::Dependency
30
+ name: nokogiri
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.6'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.6'
43
+ description: Creates buttons to manage paying with amazon payments. Can be used for
44
+ direct payments or merchant payments
45
+ email:
46
+ - gem@nathanielbibler.com
47
+ - gem@dubo.se
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - ".gitignore"
53
+ - CHANGELOG.md
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - MIT-LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - app/helpers/rails_helper.rb
60
+ - lib/simplepay.rb
61
+ - lib/simplepay/authentication.rb
62
+ - lib/simplepay/constants.rb
63
+ - lib/simplepay/errors.rb
64
+ - lib/simplepay/helpers/form_helper.rb
65
+ - lib/simplepay/rails.rb
66
+ - lib/simplepay/service.rb
67
+ - lib/simplepay/services/donation.rb
68
+ - lib/simplepay/services/marketplace.rb
69
+ - lib/simplepay/services/marketplace_policy.rb
70
+ - lib/simplepay/services/standard.rb
71
+ - lib/simplepay/services/subscription.rb
72
+ - lib/simplepay/support.rb
73
+ - lib/simplepay/support/amount.rb
74
+ - lib/simplepay/support/billing_frequency.rb
75
+ - lib/simplepay/support/boolean.rb
76
+ - lib/simplepay/support/currency.rb
77
+ - lib/simplepay/support/epoch.rb
78
+ - lib/simplepay/support/field.rb
79
+ - lib/simplepay/support/interval.rb
80
+ - lib/simplepay/support/simple_amount.rb
81
+ - lib/simplepay/support/subscription_period.rb
82
+ - lib/simplepay/validator.rb
83
+ - lib/simplepay/version.rb
84
+ - simplepay.gemspec
85
+ - test/simplepay/services/test_donation.rb
86
+ - test/simplepay/services/test_marketplace.rb
87
+ - test/simplepay/services/test_marketplace_policy.rb
88
+ - test/simplepay/services/test_standard.rb
89
+ - test/simplepay/services/test_subscription.rb
90
+ - test/simplepay/support/test_amount.rb
91
+ - test/simplepay/support/test_billing_frequency.rb
92
+ - test/simplepay/support/test_boolean.rb
93
+ - test/simplepay/support/test_epoch.rb
94
+ - test/simplepay/support/test_field.rb
95
+ - test/simplepay/support/test_interval.rb
96
+ - test/simplepay/support/test_simple_amount.rb
97
+ - test/simplepay/support/test_subscription_period.rb
98
+ - test/simplepay/test_authentication.rb
99
+ - test/simplepay/test_service.rb
100
+ - test/simplepay/test_validator.rb
101
+ - test/test_helper.rb
102
+ - test/test_simplepay.rb
103
+ homepage: https://github.com/Yakrware/simplepay
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 1.9.3
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Amazon SimplePay helpers for Rails 4
127
+ test_files:
128
+ - test/simplepay/services/test_donation.rb
129
+ - test/simplepay/services/test_marketplace.rb
130
+ - test/simplepay/services/test_marketplace_policy.rb
131
+ - test/simplepay/services/test_standard.rb
132
+ - test/simplepay/services/test_subscription.rb
133
+ - test/simplepay/support/test_amount.rb
134
+ - test/simplepay/support/test_billing_frequency.rb
135
+ - test/simplepay/support/test_boolean.rb
136
+ - test/simplepay/support/test_epoch.rb
137
+ - test/simplepay/support/test_field.rb
138
+ - test/simplepay/support/test_interval.rb
139
+ - test/simplepay/support/test_simple_amount.rb
140
+ - test/simplepay/support/test_subscription_period.rb
141
+ - test/simplepay/test_authentication.rb
142
+ - test/simplepay/test_service.rb
143
+ - test/simplepay/test_validator.rb
144
+ - test/test_helper.rb
145
+ - test/test_simplepay.rb