rails-forward_compatible_controller_tests 2.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c14737488ec9d88e466310f7b7c6df11426a25df
4
+ data.tar.gz: 8dcde00c075180b1905c20848ebf57ef79b59ea8
5
+ SHA512:
6
+ metadata.gz: 9d76badb16031b39c287245791052be7d460c284cd15dba5870bd3557bbd0e17b84fc021905c8dc407423fc2e4f0abeee666346c5a102ecb3e7f150ce1eb00de
7
+ data.tar.gz: 2a30af7fccd62babe9255b419836c39b59aae0b0e05a8efb44cdc6807e602aa0aae5319db91b1f6cb83c71539a87529a4571eeb271efe78ff574e105f703d97d
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 AppFolio, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Rails::ForwardCompatibleControllerTests
2
+
3
+ Backport Rails 5 style controller/integration testing syntax using kwargs to Rails 4
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rails-forward_compatible_controller_tests', require: false
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rails-forward_compatible_controller_tests
20
+
21
+ At the appropriate spot in your `test_helper.rb`, `spec_helper.rb`, or similar file add the following line:
22
+
23
+ ```ruby
24
+ require 'rails/forward_compatible_controller_tests'
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Allows you to simultaneously use the old and new syntax while making HTTP calls to your controllers
30
+ in your test suite. So both:
31
+
32
+ ```ruby
33
+ get #{url_or_action}, params, headers
34
+ xhr :post, #{url_or_action}, params, headers
35
+ ```
36
+
37
+ and
38
+
39
+ ```ruby
40
+ get #{url_or_action}, params: params, headers: headers
41
+ get #{url_or_action}, xhr: true, params: params, headers: headers
42
+ ```
43
+
44
+ should work while you transition your test suite.
45
+
46
+ ## Modes of Operation
47
+
48
+ Deprecation warnings will appear by default when executing statements that
49
+ utilize the old method. Deprecation warnings can be disabled by adding the
50
+ following to your appropriate test helper:
51
+
52
+ ```ruby
53
+ Rails::ForwardCompatibleControllerTests.ignore
54
+ ```
55
+
56
+ The above is useful if you simply want to support the Rails 5 syntax. If
57
+ instead you want to prevent new uses of the old syntax, add the following:
58
+
59
+ ```ruby
60
+ Rails::ForwardCompatibleControllerTests.raise_exception
61
+ ```
62
+
63
+ The above is useful when you're done coverting the syntax but are not yet ready
64
+ to make the switch to Rails 5.
65
+
66
+ ## Development
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
+
70
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/appfolio/rails-forward_compatible_controller_tests.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
79
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,90 @@
1
+ require "rails/forward_compatible_controller_tests/version"
2
+ require "rails/test_help"
3
+
4
+ module Rails
5
+ module ForwardCompatibleControllerTests
6
+ ERROR_MESSAGE = 'Please use Rails 5 syntax. See: https://github.com/appfolio/rails-forward_compatible_controller_tests'
7
+
8
+ class <<self
9
+ @action = :deprecation_warning
10
+
11
+ attr_reader :action
12
+
13
+ def deprecate
14
+ @action = :deprecation_warning
15
+ end
16
+
17
+ def deprecated?
18
+ @action == :deprecation_warning
19
+ end
20
+
21
+ def ignore
22
+ @action = nil
23
+ end
24
+
25
+ def raise_exception
26
+ @action = :raise_exceptioon
27
+ end
28
+
29
+ def raise_exception?
30
+ @action == :raise_exceptioon
31
+ end
32
+
33
+ private
34
+
35
+ def with_ignore
36
+ previous_action = @action
37
+ @action = nil
38
+ begin
39
+ yield
40
+ ensure
41
+ @action = previous_action
42
+ end
43
+ end
44
+ end
45
+
46
+ %i[get post patch put head delete].each do |method|
47
+ define_method(method) do |action, *args|
48
+ request_params = args[0]&.dup
49
+ request_headers = args[1]&.dup
50
+
51
+ old_method = false
52
+ xhr = false
53
+ if request_params && request_params.is_a?(Hash)
54
+ xhr = request_params.delete(:xhr)
55
+ if request_params[:params].is_a?(Hash)
56
+ request_params.merge!(request_params.delete(:params) || {})
57
+ request_headers = request_params.delete(:headers) || request_headers
58
+ elsif request_params.key?(:params)
59
+ request_headers = request_params[:headers]
60
+ request_params = request_params[:params]
61
+ elsif request_params.key?(:headers)
62
+ request_headers = request_params[:headers]
63
+ request_params = nil
64
+ elsif !xhr
65
+ old_method = true
66
+ end
67
+ elsif request_headers.is_a?(Hash)
68
+ old_method = true
69
+ end
70
+
71
+ raise Exception, ERROR_MESSAGE if ForwardCompatibleControllerTests.raise_exception? && old_method
72
+ ActiveSupport::Deprecation.warn(ERROR_MESSAGE) if ForwardCompatibleControllerTests.deprecated? && old_method
73
+
74
+ ForwardCompatibleControllerTests.send(:with_ignore) do
75
+ return xhr(method, action, request_params, request_headers)
76
+ end if xhr
77
+ super(action, request_params, request_headers)
78
+ end
79
+ end
80
+
81
+ def xhr(request_method, action, parameters = nil, *args)
82
+ raise Exception ERROR_MESSAGE if ForwardCompatibleControllerTests.raise_exception?
83
+ ActiveSupport::Deprecation.warn(ERROR_MESSAGE) if ForwardCompatibleControllerTests.deprecated?
84
+ super(request_method, action, parameters, *args)
85
+ end
86
+ end
87
+ end
88
+
89
+ ActionController::TestCase.prepend(Rails::ForwardCompatibleControllerTests)
90
+ ActionDispatch::IntegrationTest.prepend(Rails::ForwardCompatibleControllerTests)
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module ForwardCompatibleControllerTests
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-forward_compatible_controller_tests
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chad Shaffer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: actionpack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
83
+ description: Makes upgrading to Rails 5 from Rails 4 easier
84
+ email:
85
+ - chad.shaffer@mycase.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - lib/rails/forward_compatible_controller_tests.rb
94
+ - lib/rails/forward_compatible_controller_tests/version.rb
95
+ homepage: https://github.com/appfolio/rails-forward_compatible_controller_tests
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.6.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Back-porting Rails 5 controller & integration tests into Rails 4
119
+ test_files: []