veritrans 2.0.3 → 2.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 475b7547ae66a6a1fc61a1a702ee15fba0c2e8a9
4
- data.tar.gz: 15500b497283f54efe37798f4d31b404e1bdcbd4
3
+ metadata.gz: 9c82962a7ae8c6e0cd05dd1f71ad62168d9bce06
4
+ data.tar.gz: 8eebb1f2a1a600177b130c488548d722cf4adec0
5
5
  SHA512:
6
- metadata.gz: 0abfa400ffdbe8f3369d07bd0e52c2ab53ffff2db76b22e98d26466e8121001d6c4c0370a7e8e978e13ac280c03bc155749c18ca3460e7568d1fb0ebe5eff6c5
7
- data.tar.gz: e40f6d85251bf6b73d03d1437eda9a03990e2dce871a0618d33924e54e16a2cd95aa05ffe53f7fbf3fd598bec72cb244074e21c713f418ebd2b2d51257088fad
6
+ metadata.gz: a80453ff8b48a43fa466500f51e91f4fccbe0a0fc1e572b0219b8fcee3bfd9b4d25ffbe719dfecf06862f341c956d1d6c35b92abecfc81e0cdc99281122dc8ed
7
+ data.tar.gz: dae263f5c272b89bb291af5c315ea8de61b34134a3a99df66b13458dae44324e42d4044a33ae202c9ab4a50446c6ab958cca742a2fd31e1febd855d28c70384a
@@ -1,3 +1,8 @@
1
+ ### Version 2.0.4 (date: 30 Nov 2015)
2
+
3
+ * Show warning when can not find section in veritrans.yml
4
+ * Test with different versions of rails
5
+
1
6
  ### Version 2.0.3 (date: 19 Jun 2015)
2
7
 
3
8
  * Implement expire api call
@@ -144,7 +144,7 @@ PLATFORMS
144
144
  DEPENDENCIES
145
145
  poltergeist (~> 1.6)
146
146
  rails (~> 4.2)
147
- rspec (~> 2.9, >= 2.9.0)
147
+ rspec (~> 2.14)
148
148
  vcr (~> 2.9)
149
149
  veritrans!
150
150
  webmock (~> 1.20)
@@ -1,5 +1,5 @@
1
1
  Veritrans.setup do
2
- config.load_config Rails.root.join("config/veritrans.yml")
2
+ config.load_config Rails.root.join("config/veritrans.yml"), Rails.env
3
3
 
4
4
  # Or set it manually...
5
5
  # config.server_key = ""
@@ -92,14 +92,34 @@ module Veritrans
92
92
  # config.load_yml "#{Rails.root.to_s}/config/veritrans.yml#development"
93
93
  # end
94
94
  #
95
- def load_config(filename)
96
- yml_file, yml_section = filename.to_s.split('#')
95
+ def load_config(filename, yml_section = nil)
96
+ yml_file, file_yml_section = filename.to_s.split('#')
97
97
  config_data = YAML.load(File.read(yml_file))
98
98
 
99
+ yml_section ||= file_yml_section
99
100
  if defined?(Rails) && !yml_section
100
101
  yml_section = Rails.env.to_s
101
102
  end
102
103
 
104
+ if yml_section && !config_data.has_key?(yml_section)
105
+ STDERR.puts "Veritrans: Can not find section #{yml_section.inspect} in file #{yml_file}"
106
+ STDERR.puts " Available sections: #{config_data.keys}"
107
+
108
+ if config_data['development'] && config_data['development']['server_key']
109
+ new_section = 'development'
110
+ end
111
+
112
+ first_key = config_data.keys.first
113
+ if config_data[first_key]['server_key']
114
+ new_section = first_key
115
+ end
116
+
117
+ if new_section
118
+ STDERR.puts "Veritrans: Using first section #{new_section.inspect}"
119
+ yml_section = new_section
120
+ end
121
+ end
122
+
103
123
  apply(yml_section ? config_data[yml_section] : config_data)
104
124
  end
105
125
 
@@ -1,3 +1,3 @@
1
1
  module Veritrans
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -6,10 +6,12 @@ require 'socket'
6
6
  describe "Rails plugin", vcr: false do
7
7
  include Capybara::DSL
8
8
 
9
- RAILS_VER = "4.1.9"
9
+ MAIN_RAILS_VER = "4.1.9"
10
10
  APP_DIR = "plugin_test"
11
11
  PLUGIN_DIR = File.expand_path("..", File.dirname(__FILE__))
12
12
 
13
+ RAILS_VERSIONS = ["4.0.13", "4.1.14", "4.2.5"]
14
+
13
15
  before :all do
14
16
  FileUtils.mkdir_p("#{PLUGIN_DIR}/tmp")
15
17
  #Capybara::Screenshot.instance_variable_set(:@capybara_root, "#{PLUGIN_DIR}/tmp")
@@ -44,37 +46,37 @@ describe "Rails plugin", vcr: false do
44
46
  return stdout_str
45
47
  end
46
48
 
47
- def install_rails_in_tmp
49
+ def install_rails_in_tmp(rails_version = MAIN_RAILS_VER)
48
50
  @rails_dir = Dir.mktmpdir()
49
51
  @app_abs_path = "#{@rails_dir}/#{APP_DIR}"
50
52
 
51
53
  Dir.chdir(@rails_dir) do
52
54
  Bundler.with_clean_env do
53
55
  ENV["RAILS_ENV"] = "development"
54
- find_or_install_rails
55
- generate_rails_app
56
+ find_or_install_rails(rails_version)
57
+ generate_rails_app(rails_version)
56
58
  generate_plugin_things
57
59
  end
58
60
  end
59
61
  end
60
62
 
61
- def find_or_install_rails
63
+ def find_or_install_rails(rails_version)
62
64
  response = run_cmd('gem list \^rails\$ -q')
63
- if response =~ /[^\d]#{RAILS_VER}[^\d]/
65
+ if response =~ /[^\d]#{rails_version}[^\d]/
64
66
  return true
65
67
  else
66
- run_cmd("gem install rails -v #{RAILS_VER} --no-ri --no-rdoc")
68
+ run_cmd("gem install rails -v #{rails_version} --no-ri --no-rdoc")
67
69
  end
68
70
  end
69
71
 
70
- def generate_rails_app
71
- gen = "rails _#{RAILS_VER}_ new #{APP_DIR} -B -G --skip-spring -d sqlite3 --skip-turbolinks --skip-test-unit --no-rc"
72
+ def generate_rails_app(rails_version)
73
+ gen = "rails _#{rails_version}_ new #{APP_DIR} -B -G --skip-spring -d sqlite3 --skip-turbolinks --skip-test-unit --no-rc"
72
74
  run_cmd(gen)
73
75
 
74
76
  gemfile_content = "
75
77
  source 'https://rubygems.org'
76
78
 
77
- gem 'rails', '#{RAILS_VER}'
79
+ gem 'rails', '#{rails_version}'
78
80
  gem 'sqlite3'
79
81
  gem 'turbolinks'
80
82
  gem 'jquery-rails'
@@ -150,63 +152,85 @@ development:
150
152
  FileUtils.remove_entry_secure(@rails_dir) if @rails_dir
151
153
  end
152
154
 
153
- it "should tests plugin" do
154
- # PREPARE APP
155
- install_rails_in_tmp
156
- run_rails_app
155
+ RAILS_VERSIONS.each do |rails_version|
156
+ it "should tests plugin (Rails #{rails_version})" do
157
+ # PREPARE APP
158
+ install_rails_in_tmp(rails_version)
159
+ run_rails_app
157
160
 
158
- # CREATE PAYMENT 1
159
- visit "/payments/new"
161
+ # CREATE PAYMENT 1
162
+ visit "/payments/new"
160
163
 
161
- click_button "Pay via VT-Direct"
164
+ click_button "Pay via VT-Direct"
162
165
 
163
- # Waiting for get token request in javascript...
164
- Timeout.timeout(30.seconds) do
165
- loop do
166
- break if current_path != "/payments/new"
167
- sleep 0.1
166
+ # Waiting for get token request in javascript...
167
+ Timeout.timeout(30.seconds) do
168
+ loop do
169
+ break if current_path != "/payments/new"
170
+ sleep 0.1
171
+ end
168
172
  end
169
- end
170
173
 
171
- Timeout.timeout(10.seconds) do
172
- loop do
173
- break if page.body =~ /<body>/
174
- sleep 0.1
174
+ Timeout.timeout(10.seconds) do
175
+ loop do
176
+ break if page.body =~ /<body>/
177
+ sleep 0.1
178
+ end
175
179
  end
176
- end
177
180
 
178
- if page.body =~ /too many transactions/
179
- page.should have_content("Merchant has sent too many transactions to the same card number")
180
- else
181
- page.should have_content("Success, Credit Card transaction is successful")
182
- end
181
+ if page.body =~ /too many transactions/
182
+ page.should have_content("Merchant has sent too many transactions to the same card number")
183
+ else
184
+ page.should have_content("Success, Credit Card transaction is successful")
185
+ end
183
186
 
184
- created_order_id = ActiveSupport::JSON.decode(find("pre").text)["order_id"]
185
- #Capybara::Screenshot.screenshot_and_open_image
187
+ created_order_id = ActiveSupport::JSON.decode(find("pre").text)["order_id"]
188
+ #Capybara::Screenshot.screenshot_and_open_image
186
189
 
187
- # CREATE PAYMENT 2
188
- visit "/payments/new"
189
- click_link "Pay via VT-Web"
190
+ # CREATE PAYMENT 2
191
+ visit "/payments/new"
192
+ click_link "Pay via VT-Web"
190
193
 
191
- page.should have_content("Payment is securely processed by Veritrans")
192
- #Capybara::Screenshot.screenshot_and_open_image
194
+ page.should have_content("Payment is securely processed by Veritrans")
195
+ #Capybara::Screenshot.screenshot_and_open_image
193
196
 
194
- # TEST CALLBACK FOR WRONG DATA
195
- stub_const("CONFIG", {})
196
- result1 = capture_stdout do
197
- Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
198
- end
197
+ # TEST CALLBACK FOR WRONG DATA
198
+ stub_const("CONFIG", {})
199
+ result1 = capture_stdout do
200
+ Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
201
+ end
199
202
 
200
- result1.should =~ /status: 404/
203
+ result1.should =~ /status: 404/
201
204
 
202
- # TEST CALLBACK FOR CORRECT DATA
203
- stub_const("CONFIG", {order: created_order_id, config_path: "#{@app_abs_path}/config/veritrans.yml"})
204
- result2 = capture_stdout do
205
- Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
206
- end
205
+ # TEST CALLBACK FOR CORRECT DATA
206
+ stub_const("CONFIG", {order: created_order_id, config_path: "#{@app_abs_path}/config/veritrans.yml"})
207
+ result2 = capture_stdout do
208
+ Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
209
+ end
207
210
 
208
- result2.should =~ /status: 200/
209
- result2.should =~ /body: ok/
211
+ result2.should =~ /status: 200/
212
+ result2.should =~ /body: ok/
213
+ end
210
214
  end
211
215
 
216
+ it "should print message if running in staging" do
217
+ # PREPARE APP
218
+ install_rails_in_tmp
219
+ File.open("#{@app_abs_path}/config/database.yml", 'a') {|f|
220
+ f.puts
221
+ f.puts("staging:")
222
+ f.puts(" adapter: sqlite3")
223
+ f.puts(" database: ':memory:'")
224
+ }
225
+
226
+ Bundler.with_clean_env do
227
+ ENV["RAILS_ENV"] = "staging"
228
+ Dir.chdir(@app_abs_path) do
229
+ stdout_str, stderr_str, status = Open3.capture3(%{./bin/rails r 'p :started'})
230
+ stderr_str.should include('Veritrans: Can not find section "staging"')
231
+ stderr_str.should include('Available sections: ["development"]')
232
+ stderr_str.should include('Veritrans: Using first section "development"')
233
+ end
234
+ end
235
+ end
212
236
  end
@@ -13,6 +13,14 @@ require 'vcr'
13
13
  require 'capybara/rspec'
14
14
  require 'capybara/poltergeist'
15
15
 
16
+ Capybara.register_driver :poltergeist do |app|
17
+ Capybara::Poltergeist::Driver.new(app,
18
+ # phantomjs don't much like ssl of cloudfront.net
19
+ phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any'],
20
+ # logger: STDOUT
21
+ )
22
+ end
23
+
16
24
  Capybara.configure do |config|
17
25
  config.javascript_driver = :poltergeist
18
26
  config.default_driver = :poltergeist
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_runtime_dependency "excon", "~> 0.20"
21
21
 
22
- s.add_development_dependency "rspec", '~> 2.9', '>= 2.9.0'
22
+ s.add_development_dependency "rspec", '~> 2.14'
23
23
  s.add_development_dependency "rails", '~> 4.2'
24
24
  s.add_development_dependency 'webmock', '~> 1.20'
25
25
  s.add_development_dependency 'vcr', '~> 2.9'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veritrans
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Veritrans Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-19 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.9'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.9.0
33
+ version: '2.14'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '2.9'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.9.0
40
+ version: '2.14'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rails
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -191,9 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
185
  version: '0'
192
186
  requirements: []
193
187
  rubyforge_project:
194
- rubygems_version: 2.4.4
188
+ rubygems_version: 2.4.5
195
189
  signing_key:
196
190
  specification_version: 4
197
191
  summary: Veritrans ruby library
198
192
  test_files: []
199
- has_rdoc: