rails_test_params_backport 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d105588f6ab616839e9b84ad62d9e1c039f4721b
4
+ data.tar.gz: 5826b7b8e752141093bcc3366be8c87b033aa905
5
+ SHA512:
6
+ metadata.gz: fef89b5939892d95ac67f938fa67e3d06c860a4d1bc9ffa7ad597104d57033d081e905637695b9e1cd2cb0584975b85d6e66a90ac1ba711e109ad1eee56a622e
7
+ data.tar.gz: 140039083ef4d824cc7093e1261b83fa607b2b3dfc1973374c5c5d3726879e106ca81f3400d4162f38d228b591806ee742de592d71cbcd86b3f8c0455615930e
@@ -0,0 +1,36 @@
1
+ require 'rails_test_params_backport/version'
2
+ require 'active_support'
3
+ require 'action_dispatch'
4
+
5
+ module RailsTestParamsBackport
6
+ ERROR_MESSAGE = <<-EOS
7
+ Test HTTP request methods will accept only
8
+ the following keyword arguments in future Rails versions:
9
+ params, headers, env
10
+ Examples:
11
+ get '/profile',
12
+ params: { id: 1 },
13
+ headers: { 'X-Extra-Header' => '123' },
14
+ env: { 'action_dispatch.custom' => 'custom' }
15
+ Please change your arguments to reflect this change.
16
+ EOS
17
+
18
+ class << self
19
+ attr_accessor :raise_on_offence
20
+
21
+ def verify_parameters(parameters)
22
+ offensive_parameters = parameters.keys - %i(params headers env)
23
+ return unless offensive_parameters.any?
24
+ raise RailsTestParamsBackport::ParameterError, ERROR_MESSAGE
25
+ end
26
+ end
27
+
28
+ class ParameterError < RuntimeError
29
+ end
30
+ end
31
+
32
+ require 'rails_test_params_backport/rails3' if ActiveSupport::VERSION::MAJOR == 3
33
+ require 'rails_test_params_backport/rails4' if ActiveSupport::VERSION::MAJOR == 4
34
+
35
+ ActionController::TestCase::Behavior.prepend(RailsTestParamsBackport::TestCaseParamsBackport)
36
+ ActionDispatch::Integration::Session.prepend(RailsTestParamsBackport::IntegrationSessionParamsBackport)
@@ -0,0 +1,29 @@
1
+ module RailsTestParamsBackport
2
+ module TestCaseParamsBackport
3
+ def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
4
+ parameters = parameters.to_h
5
+
6
+ RailsTestParamsBackport.verify_parameters(parameters)
7
+
8
+ headers = parameters.fetch(:headers, {})
9
+ env = parameters.fetch(:env, {})
10
+ session = headers.merge(env)
11
+
12
+ super(action, parameters[:params], session, flash, http_method)
13
+ end
14
+ end
15
+
16
+ module IntegrationSessionParamsBackport
17
+ def process(method, path, parameters = nil, rack_env = nil)
18
+ parameters = parameters.to_h
19
+
20
+ RailsTestParamsBackport.verify_parameters(parameters)
21
+
22
+ headers = parameters.fetch(:headers, {})
23
+ env = parameters.fetch(:env, {})
24
+ rack_env = headers.merge(env)
25
+
26
+ super(method, path, parameters[:params], rack_env)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module RailsTestParamsBackport
2
+ module TestCaseParamsBackport
3
+ def process(action, http_method = 'GET', *args)
4
+ parameters = args[0].to_h
5
+
6
+ RailsTestParamsBackport.verify_parameters(parameters)
7
+
8
+ headers = parameters.fetch(:headers, {})
9
+ env = parameters.fetch(:env, {})
10
+ session = headers.merge(env)
11
+
12
+ super(action, http_method, parameters[:params], session)
13
+ end
14
+ end
15
+
16
+ module IntegrationSessionParamsBackport
17
+ def process(method, path, parameters = nil, headers_or_env = nil)
18
+ parameters = parameters.to_h
19
+
20
+ RailsTestParamsBackport.verify_parameters(parameters)
21
+
22
+ headers = parameters.fetch(:headers, {})
23
+ env = parameters.fetch(:env, {})
24
+ headers_or_env = headers.merge(env)
25
+
26
+ super(method, path, parameters[:params], headers_or_env)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module RailsTestParamsBackport
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_test_params_backport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pierre Schambacher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-04 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: 3.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: actionpack
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.2.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.2.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.4'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.4'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec-rails
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: bump
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: wwtd
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: byebug
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ description: Backports the :params, :headers and :env options introduced in Rails
152
+ 5 to older versions of Rails.
153
+ email:
154
+ - pschambacher@zendesk.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - lib/rails_test_params_backport.rb
160
+ - lib/rails_test_params_backport/rails3.rb
161
+ - lib/rails_test_params_backport/rails4.rb
162
+ - lib/rails_test_params_backport/version.rb
163
+ homepage: https://github.com/zendesk/rails_test_params_backport
164
+ licenses: []
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.5.1
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Write Rails 5 style tests in your Rails 3 or Rails 4 application.
186
+ test_files: []