fake_paymill 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f148cafda94a04dab34c1ac622418ce917a7d9e9
4
+ data.tar.gz: 3275d809aef09bc7b8f8863b61e4ffb9d4699249
5
+ SHA512:
6
+ metadata.gz: 90e51991259dc50e4a04029cc76f8ceb046bc85ead2da7deb4c152bb7ce26f9acc97cacaf070a9b713a1e534735428c284ed440d35af990a6d5c49c370b7499c
7
+ data.tar.gz: 932f387344dc6daf70ac85b9c313c66997a5e881d90da94d8480bfaa92d50938597ea59f8fdb362f54e35ffa188a3a4bce90546085fd822ad3ff1ffd77d2d281
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ before_install:
5
+ - gem update --system
6
+ branches:
7
+ only:
8
+ - master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fake-paymill.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Zamith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # FakePaymill
2
+ [![Build Status](https://travis-ci.org/zamith/fake-paymill.png?branch=master)](https://travis-ci.org/zamith/fake-paymill)
3
+
4
+ A Paymill fake so that you can avoid hitting Paymill's servers in tests
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fake_paymill'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fake_paymill
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
31
+
32
+ ## Credits
33
+
34
+ FakePaymill is largely based on thoughtbot's FakeBraintree
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc 'Run specs'
8
+ task :default => [:spec]
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fake_paymill/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fake_paymill"
8
+ spec.version = FakePaymill::VERSION
9
+ spec.authors = ["Zamith"]
10
+ spec.email = ["zamith.28@gmail.com"]
11
+ spec.description = %q{A Paymill fake so that you can avoid hitting Paymill's servers in tests}
12
+ spec.summary = %q{A Paymill fake so that you can avoid hitting Paymill's servers in tests}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'capybara'
23
+ spec.add_dependency 'sinatra'
24
+ spec.add_dependency 'thin'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'digest/md5'
2
+ require 'active_support/gzip'
3
+
4
+ module FakePaymill
5
+ module Helpers
6
+ def gzip(content)
7
+ ActiveSupport::Gzip.compress(content)
8
+ end
9
+
10
+ def gzipped_response(status_code, uncompressed_content)
11
+ [status_code, { 'Content-Encoding' => 'gzip' }, gzip(uncompressed_content)]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module FakePaymill
2
+ class Memory
3
+ attr_accessor :clients
4
+
5
+ def initialize
6
+ clear!
7
+ end
8
+
9
+ def clear!
10
+ @clients = {}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require 'capybara'
2
+ require 'capybara/server'
3
+ require 'rack/handler/thin'
4
+
5
+ module FakePaymill
6
+ class Server
7
+ def boot
8
+ with_thin_runner do
9
+ server = Capybara::Server.new(FakePaymill::SinatraApp)
10
+ server.boot
11
+ ENV['GATEWAY_PORT'] = server.port.to_s
12
+ end
13
+ end
14
+
15
+ private
16
+ def with_thin_runner
17
+ default_server_process = Capybara.server
18
+ Capybara.server do |app, port|
19
+ Rack::Handler::Thin.run(app, Port: port)
20
+ end
21
+ yield
22
+ ensure
23
+ Capybara.server(&default_server_process)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'sinatra/base'
2
+
3
+ module FakePaymill
4
+ class SinatraApp < Sinatra::Base
5
+ set :show_exceptions, false
6
+ set :dump_errors, true
7
+ set :raise_errors, true
8
+ disable :logging
9
+
10
+ include Helpers
11
+
12
+ # Paymill::Client.all
13
+ get "/#{Paymill::Configuration.api_version}/clients/" do
14
+ gzipped_response(200, {
15
+ "data" => [{
16
+ "id" => "dummy_client",
17
+ "email" => "lovely-client@example.com",
18
+ "description" =>"Lovely Client",
19
+ "created_at" => 1342438695,
20
+ "updated_at" => 1342438695,
21
+ }],
22
+ "mode" => "test"
23
+ }.to_json)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module FakePaymill
2
+ VALID_CREDIT_CARDS = %w(
3
+ 4111111111111111 5500000000000004
4
+ 340000000000009 3530111333300000
5
+ 6759000000000000 4973010000000004
6
+ 30000000000004 6011111111111117
7
+ 6240008631401148
8
+ )
9
+
10
+ VALID_CREDIT_CARDS_3DSECURE = %w(
11
+ 4012888888881881 5169147129584558
12
+ )
13
+ end
@@ -0,0 +1,3 @@
1
+ module FakePaymill
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,62 @@
1
+ require 'fileutils'
2
+ require 'logger'
3
+ require 'paymill'
4
+
5
+ require 'fake_paymill/memory'
6
+
7
+ require 'fake_paymill/valid_credit_cards'
8
+ require 'fake_paymill/server'
9
+ require 'fake_paymill/helpers'
10
+ require 'fake_paymill/sinatra_app'
11
+ require 'fake_paymill/version'
12
+
13
+ module FakePaymill
14
+ def self.start!
15
+ reset_log!
16
+ self.logger = Logger.new(log_file_path)
17
+ self.memory = Memory.new
18
+ boot_server
19
+ set_configuration
20
+ end
21
+
22
+ def self.clear!
23
+ reset_log!
24
+ end
25
+
26
+ def self.log_file_path
27
+ 'tmp/log'
28
+ end
29
+
30
+ def self.reset_log!
31
+ FileUtils.mkdir_p(File.dirname(log_file_path))
32
+ File.new(log_file_path, 'w').close
33
+ end
34
+
35
+ def self.boot_server
36
+ Server.new.boot
37
+ end
38
+
39
+ def self.set_configuration
40
+ Paymill::Configuration.api_base = '0.0.0.0'
41
+ Paymill::Configuration.api_port = ENV['GATEWAY_PORT']
42
+ Paymill::Configuration.development = true
43
+ end
44
+
45
+ def self.logger
46
+ @logger
47
+ end
48
+
49
+ def self.logger=(logger)
50
+ @logger = logger
51
+ end
52
+
53
+ def self.memory
54
+ @memory
55
+ end
56
+
57
+ def self.memory=(memory)
58
+ @memory = memory
59
+ end
60
+ end
61
+
62
+ FakePaymill.start!
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakePaymill::Memory do
4
+ it 'is called on start' do
5
+ FakePaymill::Memory.should_receive(:new)
6
+ FakePaymill.start!
7
+ end
8
+ it { should have_hash_accessor_for(:clients) }
9
+
10
+ context '#clear!' do
11
+ it { should clear_hash_when_cleared(:clients) }
12
+ end
13
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakePaymill do
4
+ it 'creates a log file' do
5
+ expect(File.exist?(FakePaymill.log_file_path)).to be_true
6
+ end
7
+
8
+ it 'logs to the correct path' do
9
+ write_to_log
10
+ expect(File.readlines(FakePaymill.log_file_path).last).to include "Boom!"
11
+ end
12
+
13
+ context '.log_file_path' do
14
+ it 'is tmp/log' do
15
+ expect(FakePaymill.log_file_path).to eq "tmp/log"
16
+ end
17
+ end
18
+
19
+ context '.reset_log!' do
20
+ it 'resets the log file' do
21
+ write_to_log
22
+ FakePaymill.reset_log!
23
+ expect(File.read(FakePaymill.log_file_path)).to eq ''
24
+ end
25
+
26
+ it 'is called by clear!' do
27
+ FakePaymill.should_receive(:reset_log!)
28
+ FakePaymill.clear!
29
+ end
30
+ end
31
+
32
+ context 'VALID_CREDIT_CARDS' do
33
+ it 'includes valid regular credit cards for paymill test mode' do
34
+ valid_credit_cards = %w(
35
+ 4111111111111111 5500000000000004
36
+ 340000000000009 3530111333300000
37
+ 6759000000000000 4973010000000004
38
+ 30000000000004 6011111111111117
39
+ 6240008631401148
40
+ )
41
+ expect(FakePaymill::VALID_CREDIT_CARDS.sort).to eq valid_credit_cards.sort
42
+ end
43
+
44
+ it 'includes valid 3-D Secure credit cards for paymill test mode' do
45
+ valid_credit_cards_3dsecure = %w(
46
+ 4012888888881881 5169147129584558
47
+ )
48
+ expect(FakePaymill::VALID_CREDIT_CARDS_3DSECURE.sort).to eq valid_credit_cards_3dsecure.sort
49
+ end
50
+ end
51
+
52
+ def write_to_log
53
+ FakePaymill.logger.info("Boom!")
54
+ end
55
+ end
@@ -0,0 +1,15 @@
1
+ require 'pry'
2
+ require 'fake_paymill'
3
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+
10
+ config.order = 'random'
11
+
12
+ config.before do
13
+ FakePaymill.clear!
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ RSpec::Matchers.define :clear_hash_when_cleared do |property|
2
+ match do |object|
3
+ object.send(property.to_sym)['key'] = 'value'
4
+ object.clear!
5
+ object.send(property.to_sym).should be_empty
6
+ end
7
+
8
+ failure_message_for_should do
9
+ "Expected #{object} to clear #{property} hash after clear!, but it did not."
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ RSpec::Matchers.define :have_hash_accessor_for do |property|
2
+ match do |object|
3
+ object.send(property.to_sym)['key'] = 'value'
4
+ object.send(property.to_sym)['key'].should == 'value'
5
+ end
6
+
7
+ failure_message_for_should do
8
+ "Expected #{object} to have accessor for #{property}, but it did not."
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_paymill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zamith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A Paymill fake so that you can avoid hitting Paymill's servers in tests
126
+ email:
127
+ - zamith.28@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - fake_paymill.gemspec
140
+ - lib/fake_paymill.rb
141
+ - lib/fake_paymill/helpers.rb
142
+ - lib/fake_paymill/memory.rb
143
+ - lib/fake_paymill/server.rb
144
+ - lib/fake_paymill/sinatra_app.rb
145
+ - lib/fake_paymill/valid_credit_cards.rb
146
+ - lib/fake_paymill/version.rb
147
+ - spec/fake_paymill/memory_spec.rb
148
+ - spec/fake_paymill_spec.rb
149
+ - spec/spec_helper.rb
150
+ - spec/support/matchers/clear_hash_when_cleared.rb
151
+ - spec/support/matchers/have_accessor_for.rb
152
+ homepage: ''
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.1.10
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: A Paymill fake so that you can avoid hitting Paymill's servers in tests
176
+ test_files:
177
+ - spec/fake_paymill/memory_spec.rb
178
+ - spec/fake_paymill_spec.rb
179
+ - spec/spec_helper.rb
180
+ - spec/support/matchers/clear_hash_when_cleared.rb
181
+ - spec/support/matchers/have_accessor_for.rb