focused_controller 1.2.1 → 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 +4 -4
- data/.travis.yml +6 -5
- data/Appraisals +4 -13
- data/CHANGELOG.md +8 -0
- data/README.md +0 -28
- data/focused_controller.gemspec +5 -5
- data/gemfiles/rails_4_1.gemfile +0 -1
- data/gemfiles/{rails_3_1.gemfile → rails_4_2.gemfile} +2 -2
- data/lib/focused_controller/route_mapper.rb +44 -18
- data/lib/focused_controller/rspec_helper.rb +7 -27
- data/lib/focused_controller/test_helper.rb +9 -60
- data/lib/focused_controller/version.rb +1 -1
- data/lib/focused_controller.rb +0 -1
- data/test/acceptance/app_test.rb +3 -11
- data/test/app/Gemfile +1 -1
- data/test/app/config/application.rb +1 -0
- data/test/app/config/environments/test.rb +7 -1
- data/test/app/config/initializers/backtrace_silencers.rb +1 -1
- data/test/app/config/secrets.yml +3 -0
- data/test/helper.rb +34 -16
- data/test/unit/functional_test_helper_test.rb +1 -1
- data/test/unit/mixin_test.rb +1 -1
- data/test/unit/route_mapper_test.rb +19 -10
- data/test/unit/rspec_functional_helper.rb +1 -1
- data/test/unit/rspec_helper_test.rb +4 -4
- data/test/unit/test_helper_test.rb +9 -45
- metadata +20 -29
- data/gemfiles/rails_3_2.gemfile +0 -7
- data/gemfiles/rails_4_0.gemfile +0 -7
- data/lib/focused_controller/route.rb +0 -17
- data/test/app/spec/unit/controllers/posts_controller_isolated_spec.rb +0 -68
- data/test/app/test/isolated_test_helper.rb +0 -6
- data/test/app/test/unit/controllers/posts_controller_isolated_test.rb +0 -78
- data/test/unit/route_test.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4520f2d723515817447f6298824b627fd5cd610d
|
4
|
+
data.tar.gz: 5396abeb1c3bd9c627f67ce079bfb9113a660572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59ea160ee59f7fe685cc2f97db55f14c7625f061ccbe9dfe0da5626affce78e65cd6a519234f2161c182d0c86a8b014a035af9d0bc1d60a391dab55247e8e606
|
7
|
+
data.tar.gz: 48429585b521b53d891064926918333a4c8a8a35bf9414e6b0ac758fd496d9cb4db1e8156e4e8cbad52d70592d36cf73b832e6c0c30d3fe99483fb59857247a4
|
data/.travis.yml
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
4
|
+
- 2.2.3
|
3
5
|
- 2.1.2
|
4
6
|
- 2.0.0
|
5
|
-
|
6
|
-
- jruby-19mode
|
7
|
+
|
7
8
|
gemfile:
|
9
|
+
- gemfiles/rails_4_2.gemfile
|
8
10
|
- gemfiles/rails_4_1.gemfile
|
9
|
-
|
10
|
-
|
11
|
-
- gemfiles/rails_3_1.gemfile
|
11
|
+
|
12
|
+
sudo: false
|
data/Appraisals
CHANGED
@@ -1,16 +1,7 @@
|
|
1
|
-
appraise 'rails-4-
|
2
|
-
gem 'rails', '~> 4.
|
3
|
-
gem 'minitest', '~> 5.1.0'
|
4
|
-
end
|
5
|
-
|
6
|
-
appraise 'rails-4-0' do
|
7
|
-
gem 'rails', '~> 4.0.0'
|
1
|
+
appraise 'rails-4-2' do
|
2
|
+
gem 'rails', '~> 4.2.0'
|
8
3
|
end
|
9
4
|
|
10
|
-
appraise 'rails-
|
11
|
-
gem 'rails', '~>
|
12
|
-
end
|
13
|
-
|
14
|
-
appraise 'rails-3-1' do
|
15
|
-
gem 'rails', '~> 3.1.0'
|
5
|
+
appraise 'rails-4-1' do
|
6
|
+
gem 'rails', '~> 4.1.0'
|
16
7
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 2.0.0 ##
|
2
|
+
|
3
|
+
* Rails 3.X and 4.0 no longer supported
|
4
|
+
* Ruby 1.9 no longer officially supported (it may still work)
|
5
|
+
* Isolated unit tests (via `stub_url`) no longer supported. Use the
|
6
|
+
Spring preloader to keep your app warm instead.
|
7
|
+
* Rails 4.2 support added
|
8
|
+
|
1
9
|
## Version 1.2.1 ##
|
2
10
|
|
3
11
|
* Fix gemspec
|
data/README.md
CHANGED
@@ -241,34 +241,6 @@ describe UsersController do
|
|
241
241
|
end
|
242
242
|
```
|
243
243
|
|
244
|
-
## Isolated unit tests ##
|
245
|
-
|
246
|
-
It is possible to completely decouple your focused controller tests from the
|
247
|
-
Rails application. This means you don't have to pay the penalty of starting up
|
248
|
-
Rails every time you want to run a test. This is an advanced feature and your
|
249
|
-
mileage may vary. The benefit this brings will depend on how coupled your
|
250
|
-
controllers/tests are to other dependencies.
|
251
|
-
|
252
|
-
Your `config/routes.rb` file is a dependency. When you use a URL helper
|
253
|
-
you are depending on that file. As this is a common dependency, Focused
|
254
|
-
Controller provides a way to stub out URL helpers:
|
255
|
-
|
256
|
-
``` ruby
|
257
|
-
module UsersController
|
258
|
-
class CreateTest < ActiveSupport::TestCase
|
259
|
-
include FocusedController::TestHelper
|
260
|
-
stub_url :user
|
261
|
-
|
262
|
-
# ...
|
263
|
-
end
|
264
|
-
end
|
265
|
-
```
|
266
|
-
|
267
|
-
The `stub_url` declaration will make the `user_path` and `user_url`
|
268
|
-
methods in your test and your controller return stub objects. These can
|
269
|
-
be compared, so `user_path(user1) == user_path(user1)`, but
|
270
|
-
`user_path(user1) != user_path(user2)`.
|
271
|
-
|
272
244
|
## More examples ##
|
273
245
|
|
274
246
|
The [acceptance
|
data/focused_controller.gemspec
CHANGED
@@ -18,13 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency 'actionpack', '
|
21
|
+
s.add_dependency 'actionpack', '~> 4.1', '< 4.3'
|
22
22
|
|
23
23
|
s.add_development_dependency 'minitest'
|
24
|
-
s.add_development_dependency 'capybara', '~> 2.
|
24
|
+
s.add_development_dependency 'capybara', '~> 2.5'
|
25
25
|
s.add_development_dependency 'capybara_minitest_spec', '~> 1.0'
|
26
|
-
s.add_development_dependency 'poltergeist', '~> 1.
|
27
|
-
s.add_development_dependency 'rspec', '~>
|
28
|
-
s.add_development_dependency 'rspec-rails', '~>
|
26
|
+
s.add_development_dependency 'poltergeist', '~> 1.6'
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
s.add_development_dependency 'rspec-rails', '~> 3.0'
|
29
29
|
s.add_development_dependency 'appraisal', '~> 1.0'
|
30
30
|
end
|
data/gemfiles/rails_4_1.gemfile
CHANGED
@@ -13,13 +13,10 @@ module FocusedController
|
|
13
13
|
options = @options.dup
|
14
14
|
|
15
15
|
if to = to_option
|
16
|
-
options[:to] = FocusedController::Route.new(to)
|
17
|
-
|
18
|
-
# This causes rails to spit out a bit of extra useful information in the case
|
19
|
-
# of a routing error. The :action option is also necessary for the routing to
|
20
|
-
# work on Rails <= 3.1.
|
21
16
|
options[:action] = FocusedController.action_name
|
22
17
|
options[:controller] = to.underscore
|
18
|
+
|
19
|
+
options.delete :to
|
23
20
|
end
|
24
21
|
|
25
22
|
options
|
@@ -34,21 +31,19 @@ module FocusedController
|
|
34
31
|
else
|
35
32
|
@options[:to]
|
36
33
|
end
|
34
|
+
elsif @options[:controller]
|
35
|
+
@options[:controller]
|
37
36
|
elsif @options[:action] && @scope[:controller]
|
38
37
|
stringify_controller_and_action(@scope[:controller], @options[:action])
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
41
|
def stringify_controller_and_action(controller, action)
|
43
|
-
|
44
|
-
name << @scope[:module].camelize << '::' if @scope[:module]
|
45
|
-
name << controller.camelize << 'Controller::'
|
46
|
-
name << action.to_s.camelize
|
47
|
-
name
|
42
|
+
"#{controller.to_s.underscore}_controller/#{action.to_s.underscore}"
|
48
43
|
end
|
49
44
|
end
|
50
45
|
|
51
|
-
|
46
|
+
module RoutingExtensions
|
52
47
|
def focused_controller_routes(&block)
|
53
48
|
prev, @scope[:focused_controller_routes] = @scope[:focused_controller_routes], true
|
54
49
|
yield
|
@@ -56,16 +51,47 @@ module FocusedController
|
|
56
51
|
@scope[:focused_controller_routes] = false
|
57
52
|
end
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
options = FocusedController::RouteMapper.new(scope, options).options
|
63
|
-
end
|
54
|
+
def focused_controller_enabled?
|
55
|
+
@scope[:focused_controller_routes]
|
56
|
+
end
|
64
57
|
|
65
|
-
|
58
|
+
def add_route(action, options)
|
59
|
+
if focused_controller_enabled?
|
60
|
+
super(
|
61
|
+
action,
|
62
|
+
FocusedController::RouteMapper.new(
|
63
|
+
@scope,
|
64
|
+
{ action: action }.merge(options)
|
65
|
+
).options
|
66
|
+
)
|
67
|
+
else
|
68
|
+
super
|
66
69
|
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module RouteDispatcherExtensions
|
74
|
+
private
|
67
75
|
|
68
|
-
|
76
|
+
FOCUSED_CONTROLLER = "_controller/"
|
77
|
+
|
78
|
+
def controller_reference(controller_param)
|
79
|
+
if controller_param.include?(FOCUSED_CONTROLLER)
|
80
|
+
const_name = @controller_class_names[controller_param] ||= controller_param.camelize
|
81
|
+
ActiveSupport::Dependencies.constantize(const_name)
|
82
|
+
else
|
83
|
+
super
|
84
|
+
end
|
69
85
|
end
|
70
86
|
end
|
71
87
|
end
|
88
|
+
|
89
|
+
module ActionDispatch::Routing
|
90
|
+
class Mapper
|
91
|
+
include FocusedController::RoutingExtensions
|
92
|
+
end
|
93
|
+
|
94
|
+
class RouteSet::Dispatcher
|
95
|
+
prepend FocusedController::RouteDispatcherExtensions
|
96
|
+
end
|
97
|
+
end
|
@@ -1,15 +1,6 @@
|
|
1
1
|
require 'focused_controller/test_helper'
|
2
2
|
require 'focused_controller/rspec_controller_class'
|
3
|
-
|
4
|
-
begin
|
5
|
-
# Requiring specific files rather than just 'rspec/rails' because I don't
|
6
|
-
# want to force the configuration that 'rspec/rails' adds on people if they
|
7
|
-
# haven't specifically chosen to receive it.
|
8
|
-
require 'rails/version' unless defined?(Rails)
|
9
|
-
require 'rspec/rails/matchers'
|
10
|
-
require 'rspec/rails/adapters'
|
11
|
-
rescue LoadError
|
12
|
-
end
|
3
|
+
require 'rspec/rails'
|
13
4
|
|
14
5
|
module FocusedController
|
15
6
|
module RSpecHelper
|
@@ -18,27 +9,16 @@ module FocusedController
|
|
18
9
|
# This must get included higher in the ancestor chain than
|
19
10
|
# this module so that inheritance works as desired
|
20
11
|
include FocusedController::TestHelper
|
21
|
-
extend
|
12
|
+
extend FocusedController::RSpecControllerClass
|
13
|
+
|
14
|
+
include RSpec::Rails::RailsExampleGroup
|
15
|
+
include RSpec::Rails::Matchers::RedirectTo
|
16
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
17
|
+
|
22
18
|
subject { controller }
|
23
19
|
end
|
24
20
|
|
25
21
|
super
|
26
22
|
end
|
27
|
-
|
28
|
-
if defined?(RSpec::Rails)
|
29
|
-
include RSpec::Rails::SetupAndTeardownAdapter
|
30
|
-
include RSpec::Rails::TestUnitAssertionAdapter
|
31
|
-
include RSpec::Rails::Matchers
|
32
|
-
include RSpec::Rails::Matchers::RedirectTo
|
33
|
-
include RSpec::Rails::Matchers::RenderTemplate
|
34
|
-
end
|
35
|
-
|
36
|
-
module ClassMethods
|
37
|
-
include FocusedController::RSpecControllerClass
|
38
|
-
|
39
|
-
def stub_url(*helper_names)
|
40
|
-
before { stub_url(*helper_names) }
|
41
|
-
end
|
42
|
-
end
|
43
23
|
end
|
44
24
|
end
|
@@ -11,14 +11,6 @@ module FocusedController
|
|
11
11
|
_process_options(options)
|
12
12
|
@_render_options = options
|
13
13
|
end
|
14
|
-
|
15
|
-
def url_for(options = nil)
|
16
|
-
if options.is_a?(StubbedURL)
|
17
|
-
options
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
14
|
end
|
23
15
|
|
24
16
|
class TestRequest < ActionDispatch::TestRequest
|
@@ -39,35 +31,6 @@ module FocusedController
|
|
39
31
|
class TestResponse < ActionDispatch::TestResponse
|
40
32
|
end
|
41
33
|
|
42
|
-
class StubbedURL
|
43
|
-
attr_reader :helper_name, :args
|
44
|
-
|
45
|
-
def initialize(helper_name, args)
|
46
|
-
@helper_name = helper_name.to_s
|
47
|
-
@args = args
|
48
|
-
end
|
49
|
-
|
50
|
-
def ==(other)
|
51
|
-
other.is_a?(self.class) &&
|
52
|
-
helper_name == other.helper_name &&
|
53
|
-
args == other.args
|
54
|
-
end
|
55
|
-
|
56
|
-
# Deals with _compute_redirect_to_location in action_controller/metal/redirecting
|
57
|
-
# (I don't feel proud about this...)
|
58
|
-
def gsub(*)
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
def delete(*)
|
63
|
-
self
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_s
|
67
|
-
"#{helper_name}(#{args.each(&:to_s).join(', ')})"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
34
|
module TestHelper
|
72
35
|
extend ActiveSupport::Concern
|
73
36
|
include ActionDispatch::Assertions::ResponseAssertions
|
@@ -87,13 +50,11 @@ module FocusedController
|
|
87
50
|
|
88
51
|
def include_routes
|
89
52
|
if controller_class.respond_to?(:_routes) && controller_class._routes
|
90
|
-
|
53
|
+
if mod = controller_class._routes.url_helpers
|
54
|
+
include mod
|
55
|
+
end
|
91
56
|
end
|
92
57
|
end
|
93
|
-
|
94
|
-
def stub_url(*names)
|
95
|
-
setup { stub_url(*names) }
|
96
|
-
end
|
97
58
|
end
|
98
59
|
|
99
60
|
def controller
|
@@ -144,8 +105,12 @@ module FocusedController
|
|
144
105
|
controller.url_for(*args)
|
145
106
|
end
|
146
107
|
|
108
|
+
def _routes_included?
|
109
|
+
defined?(@_routes_included) && @_routes_included
|
110
|
+
end
|
111
|
+
|
147
112
|
def respond_to?(*args)
|
148
|
-
unless
|
113
|
+
unless _routes_included?
|
149
114
|
self.class.include_routes
|
150
115
|
@_routes_included = true
|
151
116
|
end
|
@@ -154,29 +119,13 @@ module FocusedController
|
|
154
119
|
end
|
155
120
|
|
156
121
|
def method_missing(method_name, *args, &block)
|
157
|
-
if respond_to?(method_name)
|
122
|
+
if !_routes_included? && respond_to?(method_name)
|
158
123
|
send(method_name, *args, &block)
|
159
124
|
else
|
160
125
|
super
|
161
126
|
end
|
162
127
|
end
|
163
128
|
|
164
|
-
def stub_url(*names)
|
165
|
-
[self, controller].each do |host|
|
166
|
-
host.singleton_class.class_eval do
|
167
|
-
names.each do |name|
|
168
|
-
define_method("#{name}_url") do |*args|
|
169
|
-
StubbedURL.new("#{name}_url", args)
|
170
|
-
end
|
171
|
-
|
172
|
-
define_method("#{name}_path") do |*args|
|
173
|
-
StubbedURL.new("#{name}_path", args)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
129
|
def optimize_routes_generation?(*)
|
181
130
|
false
|
182
131
|
end
|
data/lib/focused_controller.rb
CHANGED
data/test/acceptance/app_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
require 'capybara'
|
3
3
|
require 'capybara_minitest_spec'
|
4
4
|
require 'capybara/poltergeist'
|
@@ -94,7 +94,7 @@ describe 'acceptance test' do
|
|
94
94
|
|
95
95
|
yield
|
96
96
|
|
97
|
-
Process.kill('
|
97
|
+
Process.kill('QUIT', File.read("tmp/pids/server.pid").to_i)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
@@ -103,7 +103,7 @@ describe 'acceptance test' do
|
|
103
103
|
run_without_bundle_exec "bundle check >/dev/null || bundle update >/dev/null"
|
104
104
|
end
|
105
105
|
|
106
|
-
let(:s) { Capybara::Session.new(:poltergeist
|
106
|
+
let(:s) { Capybara::Session.new(:poltergeist) }
|
107
107
|
|
108
108
|
it 'does basic CRUD actions successfully' do
|
109
109
|
start_server do
|
@@ -144,10 +144,6 @@ describe 'acceptance test' do
|
|
144
144
|
run_command "ruby -Itest test/unit/controllers/posts_controller_test.rb"
|
145
145
|
end
|
146
146
|
|
147
|
-
it 'runs an isolated unit test' do
|
148
|
-
run_command "ruby -Itest test/unit/controllers/posts_controller_isolated_test.rb"
|
149
|
-
end
|
150
|
-
|
151
147
|
it 'runs a functional spec' do
|
152
148
|
run_command "rspec spec/controllers/posts_controller_spec.rb"
|
153
149
|
end
|
@@ -155,8 +151,4 @@ describe 'acceptance test' do
|
|
155
151
|
it 'runs a unit spec' do
|
156
152
|
run_command "rspec spec/unit/controllers/posts_controller_spec.rb"
|
157
153
|
end
|
158
|
-
|
159
|
-
it 'runs an isolated unit spec' do
|
160
|
-
run_command "rspec spec/unit/controllers/posts_controller_isolated_spec.rb"
|
161
|
-
end
|
162
154
|
end
|
data/test/app/Gemfile
CHANGED
@@ -8,7 +8,13 @@ App::Application.configure do
|
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
10
|
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.
|
11
|
+
if config.respond_to?(:serve_static_files)
|
12
|
+
config.serve_static_files = true
|
13
|
+
else
|
14
|
+
# Remove when we drop Rails 4.1
|
15
|
+
config.serve_static_assets = true
|
16
|
+
end
|
17
|
+
|
12
18
|
config.static_cache_control = "public, max-age=3600"
|
13
19
|
|
14
20
|
# Show full error reports and disable caching
|
@@ -4,4 +4,4 @@
|
|
4
4
|
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
5
|
|
6
6
|
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
-
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
data/test/helper.rb
CHANGED
@@ -1,20 +1,38 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
|
7
|
-
require
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
require "rails/all"
|
4
|
+
require "active_support/all"
|
5
|
+
require "yaml"
|
6
|
+
|
7
|
+
require "focused_controller"
|
8
|
+
|
9
|
+
# Remove conditional when we drop Rails 4.1
|
10
|
+
if ActiveSupport.respond_to?(:test_order)
|
11
|
+
ActiveSupport.test_order = :random
|
12
|
+
end
|
13
|
+
|
14
|
+
require "active_support/test_case"
|
15
|
+
|
16
|
+
require "minitest/autorun"
|
17
|
+
require "minitest/spec"
|
18
|
+
|
19
|
+
module Kernel
|
20
|
+
alias minitest_describe describe
|
21
|
+
end
|
22
|
+
|
23
|
+
# Require rspec, but avoid using its 'describe'
|
24
|
+
require "rspec/core"
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.expose_dsl_globally = false
|
27
|
+
end
|
28
|
+
[singleton_class, Module].each do |mod|
|
29
|
+
mod.class_eval { alias describe minitest_describe }
|
30
|
+
end
|
14
31
|
|
15
32
|
TEST_ROOT = File.expand_path('..', __FILE__)
|
16
33
|
|
17
|
-
|
18
|
-
|
19
|
-
|
34
|
+
class RailsApplication < Rails::Application
|
35
|
+
config.root = TEST_ROOT + "/app"
|
36
|
+
config.secret_key_base = "123"
|
37
|
+
config.secret_token = "123"
|
20
38
|
end
|
data/test/unit/mixin_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
# RouteSet is missing some requires
|
4
4
|
require 'active_support/core_ext/uri'
|
@@ -12,16 +12,13 @@ module FocusedController
|
|
12
12
|
method = (environment[:method] || "GET").to_s.upcase
|
13
13
|
env = Rack::MockRequest.env_for(path, {:method => method})
|
14
14
|
req = route_set.request_class.new(env)
|
15
|
-
|
16
|
-
if route_set.respond_to?(:router)
|
17
|
-
router = route_set.router # Rails 3.2+
|
18
|
-
else
|
19
|
-
router = route_set.set # Rails 3.0, 3.1
|
20
|
-
end
|
15
|
+
router = route_set.router
|
21
16
|
|
22
17
|
router.recognize(req) do |route, matches, params|
|
23
18
|
return route
|
24
19
|
end
|
20
|
+
|
21
|
+
raise ArgumentError, "'#{path}' not recognized"
|
25
22
|
end
|
26
23
|
|
27
24
|
it 'creates routes that map to focused controllers' do
|
@@ -32,12 +29,16 @@ module FocusedController
|
|
32
29
|
|
33
30
|
resources :comments do
|
34
31
|
resources :replies
|
32
|
+
|
33
|
+
get 'a/:foo' => 'PostsController::Index', on: :collection
|
34
|
+
get 'b/:foo', action: :index, on: :collection
|
35
35
|
end
|
36
36
|
|
37
37
|
resource :account
|
38
38
|
|
39
39
|
namespace :admin do
|
40
40
|
resources :comments
|
41
|
+
get 'foo' => 'FooController::Show'
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -50,12 +51,14 @@ module FocusedController
|
|
50
51
|
[:put, '/comments/4'] => 'CommentsController::Update',
|
51
52
|
[:get, '/account'] => 'AccountsController::Show',
|
52
53
|
[:get, '/comments/4/replies'] => 'RepliesController::Index',
|
53
|
-
[:get, '/admin/comments'] => 'Admin::CommentsController::Index'
|
54
|
+
[:get, '/admin/comments'] => 'Admin::CommentsController::Index',
|
55
|
+
[:get, '/comments/a/omg'] => 'PostsController::Index',
|
56
|
+
[:get, '/comments/b/omg'] => 'CommentsController::Index',
|
57
|
+
[:get, '/admin/foo'] => 'Admin::FooController::Show',
|
54
58
|
}
|
55
59
|
|
56
60
|
mappings.each do |(method, path), controller|
|
57
61
|
route = recognize(path, :method => method)
|
58
|
-
route.app.name.must_equal controller
|
59
62
|
route.defaults[:action].must_equal FocusedController.action_name
|
60
63
|
route.defaults[:controller].must_equal controller.underscore
|
61
64
|
end
|
@@ -70,7 +73,13 @@ module FocusedController
|
|
70
73
|
get 'posts' => app
|
71
74
|
end
|
72
75
|
end
|
73
|
-
recognize('/posts')
|
76
|
+
route = recognize('/posts')
|
77
|
+
app = route.app
|
78
|
+
|
79
|
+
# Remove this when we drop Rails 4.1
|
80
|
+
app = app.app if app.respond_to?(:app)
|
81
|
+
|
82
|
+
app.must_equal app
|
74
83
|
end
|
75
84
|
|
76
85
|
it "generates a route with url_for" do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
require 'action_controller'
|
3
3
|
require 'focused_controller/rspec_helper'
|
4
4
|
|
@@ -21,13 +21,13 @@ module FocusedController
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
index_spec = RSpec
|
24
|
+
index_spec = RSpec.describe FakePostsController::Index do
|
25
25
|
include FocusedController::RSpecHelper
|
26
26
|
end
|
27
27
|
|
28
28
|
show_spec = nil
|
29
29
|
inner_show_spec = nil
|
30
|
-
RSpec
|
30
|
+
RSpec.describe FakePostsController do
|
31
31
|
show_spec = describe FakePostsController::Show do
|
32
32
|
include FocusedController::RSpecHelper
|
33
33
|
|
@@ -36,7 +36,7 @@ module FocusedController
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
edit_spec = RSpec
|
39
|
+
edit_spec = RSpec.describe "the edit action" do
|
40
40
|
include FocusedController::RSpecHelper
|
41
41
|
self.controller_class = FakePostsController::Edit
|
42
42
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
require 'focused_controller/test_helper'
|
3
3
|
require 'action_controller'
|
4
4
|
|
@@ -23,13 +23,11 @@ module FocusedController
|
|
23
23
|
|
24
24
|
def self._routes
|
25
25
|
OpenStruct.new(
|
26
|
-
:
|
27
|
-
|
28
|
-
|
29
|
-
'/foo'
|
30
|
-
end
|
26
|
+
:url_helpers => Module.new do
|
27
|
+
def foo_path
|
28
|
+
'/foo'
|
31
29
|
end
|
32
|
-
|
30
|
+
end
|
33
31
|
)
|
34
32
|
end
|
35
33
|
end
|
@@ -37,13 +35,11 @@ module FocusedController
|
|
37
35
|
class Show < Action
|
38
36
|
def self._routes
|
39
37
|
OpenStruct.new(
|
40
|
-
:
|
41
|
-
|
42
|
-
|
43
|
-
'/bar'
|
44
|
-
end
|
38
|
+
:url_helpers => Module.new do
|
39
|
+
def bar_path
|
40
|
+
'/bar'
|
45
41
|
end
|
46
|
-
|
42
|
+
end
|
47
43
|
)
|
48
44
|
end
|
49
45
|
end
|
@@ -178,38 +174,6 @@ module FocusedController
|
|
178
174
|
|
179
175
|
subject.cookies[:foo].must_equal 'omg'
|
180
176
|
end
|
181
|
-
|
182
|
-
describe 'url stubbing' do
|
183
|
-
before do
|
184
|
-
subject.stub_url :foo, :bar
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'handles equality' do
|
188
|
-
foo, bar = Object.new, Object.new
|
189
|
-
StubbedURL.new(:foo_path, [foo]).must_equal StubbedURL.new(:foo_path, [foo])
|
190
|
-
StubbedURL.new(:foo_path, [foo, bar]).wont_equal StubbedURL.new(:foo_path, [foo])
|
191
|
-
StubbedURL.new(:foo_path, [bar]).wont_equal StubbedURL.new(:foo_path, [foo])
|
192
|
-
StubbedURL.new(:bar_path, [foo]).wont_equal StubbedURL.new(:foo_path, [foo])
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'has a to_s' do
|
196
|
-
StubbedURL.new(:foo_path, ['omg', 'lol']).to_s.must_equal "foo_path(omg, lol)"
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'creates a stub method on the test and controller instances' do
|
200
|
-
foo = Object.new
|
201
|
-
subject.foo_path(foo).must_equal StubbedURL.new(:foo_path, [foo])
|
202
|
-
subject.controller.foo_path(foo).must_equal StubbedURL.new(:foo_path, [foo])
|
203
|
-
subject.foo_url(foo).must_equal StubbedURL.new(:foo_url, [foo])
|
204
|
-
subject.controller.foo_url(foo).must_equal StubbedURL.new(:foo_url, [foo])
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'works with a controller' do
|
208
|
-
foo = Object.new
|
209
|
-
subject.controller.redirect_to StubbedURL.new(:foo_path, [foo])
|
210
|
-
must_succeed { subject.assert_redirected_to StubbedURL.new(:foo_path, [foo]) }
|
211
|
-
end
|
212
|
-
end
|
213
177
|
end
|
214
178
|
end
|
215
179
|
end
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: focused_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Leighton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '4.
|
22
|
+
version: '4.3'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '4.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '4.
|
32
|
+
version: '4.3'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: minitest
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '2.
|
53
|
+
version: '2.5'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '2.
|
60
|
+
version: '2.5'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: capybara_minitest_spec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,42 +78,42 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '1.
|
81
|
+
version: '1.6'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '1.
|
88
|
+
version: '1.6'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '3.0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '3.0'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rspec-rails
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
109
|
+
version: '3.0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '3.0'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: appraisal
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,15 +144,12 @@ files:
|
|
144
144
|
- README.md
|
145
145
|
- Rakefile
|
146
146
|
- focused_controller.gemspec
|
147
|
-
- gemfiles/rails_3_1.gemfile
|
148
|
-
- gemfiles/rails_3_2.gemfile
|
149
|
-
- gemfiles/rails_4_0.gemfile
|
150
147
|
- gemfiles/rails_4_1.gemfile
|
148
|
+
- gemfiles/rails_4_2.gemfile
|
151
149
|
- lib/focused_controller.rb
|
152
150
|
- lib/focused_controller/action_name.rb
|
153
151
|
- lib/focused_controller/functional_test_helper.rb
|
154
152
|
- lib/focused_controller/mixin.rb
|
155
|
-
- lib/focused_controller/route.rb
|
156
153
|
- lib/focused_controller/route_mapper.rb
|
157
154
|
- lib/focused_controller/rspec_controller_class.rb
|
158
155
|
- lib/focused_controller/rspec_functional_helper.rb
|
@@ -190,6 +187,7 @@ files:
|
|
190
187
|
- test/app/config/initializers/session_store.rb
|
191
188
|
- test/app/config/locales/en.yml
|
192
189
|
- test/app/config/routes.rb
|
190
|
+
- test/app/config/secrets.yml
|
193
191
|
- test/app/db/seeds.rb
|
194
192
|
- test/app/doc/README_FOR_APP
|
195
193
|
- test/app/lib/assets/.gitkeep
|
@@ -207,14 +205,11 @@ files:
|
|
207
205
|
- test/app/spec/controllers/posts_controller_spec.rb
|
208
206
|
- test/app/spec/isolated_spec_helper.rb
|
209
207
|
- test/app/spec/spec_helper.rb
|
210
|
-
- test/app/spec/unit/controllers/posts_controller_isolated_spec.rb
|
211
208
|
- test/app/spec/unit/controllers/posts_controller_spec.rb
|
212
209
|
- test/app/test/functional/.gitkeep
|
213
210
|
- test/app/test/functional/posts_controller_test.rb
|
214
|
-
- test/app/test/isolated_test_helper.rb
|
215
211
|
- test/app/test/test_helper.rb
|
216
212
|
- test/app/test/unit/.gitkeep
|
217
|
-
- test/app/test/unit/controllers/posts_controller_isolated_test.rb
|
218
213
|
- test/app/test/unit/controllers/posts_controller_test.rb
|
219
214
|
- test/app/vendor/assets/javascripts/.gitkeep
|
220
215
|
- test/app/vendor/assets/stylesheets/.gitkeep
|
@@ -223,7 +218,6 @@ files:
|
|
223
218
|
- test/unit/functional_test_helper_test.rb
|
224
219
|
- test/unit/mixin_test.rb
|
225
220
|
- test/unit/route_mapper_test.rb
|
226
|
-
- test/unit/route_test.rb
|
227
221
|
- test/unit/rspec_functional_helper.rb
|
228
222
|
- test/unit/rspec_helper_test.rb
|
229
223
|
- test/unit/test_helper_test.rb
|
@@ -246,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
240
|
version: '0'
|
247
241
|
requirements: []
|
248
242
|
rubyforge_project: focused_controller
|
249
|
-
rubygems_version: 2.
|
243
|
+
rubygems_version: 2.4.5
|
250
244
|
signing_key:
|
251
245
|
specification_version: 4
|
252
246
|
summary: Write Rails controllers with one class per action
|
@@ -282,6 +276,7 @@ test_files:
|
|
282
276
|
- test/app/config/initializers/session_store.rb
|
283
277
|
- test/app/config/locales/en.yml
|
284
278
|
- test/app/config/routes.rb
|
279
|
+
- test/app/config/secrets.yml
|
285
280
|
- test/app/db/seeds.rb
|
286
281
|
- test/app/doc/README_FOR_APP
|
287
282
|
- test/app/lib/assets/.gitkeep
|
@@ -299,14 +294,11 @@ test_files:
|
|
299
294
|
- test/app/spec/controllers/posts_controller_spec.rb
|
300
295
|
- test/app/spec/isolated_spec_helper.rb
|
301
296
|
- test/app/spec/spec_helper.rb
|
302
|
-
- test/app/spec/unit/controllers/posts_controller_isolated_spec.rb
|
303
297
|
- test/app/spec/unit/controllers/posts_controller_spec.rb
|
304
298
|
- test/app/test/functional/.gitkeep
|
305
299
|
- test/app/test/functional/posts_controller_test.rb
|
306
|
-
- test/app/test/isolated_test_helper.rb
|
307
300
|
- test/app/test/test_helper.rb
|
308
301
|
- test/app/test/unit/.gitkeep
|
309
|
-
- test/app/test/unit/controllers/posts_controller_isolated_test.rb
|
310
302
|
- test/app/test/unit/controllers/posts_controller_test.rb
|
311
303
|
- test/app/vendor/assets/javascripts/.gitkeep
|
312
304
|
- test/app/vendor/assets/stylesheets/.gitkeep
|
@@ -315,7 +307,6 @@ test_files:
|
|
315
307
|
- test/unit/functional_test_helper_test.rb
|
316
308
|
- test/unit/mixin_test.rb
|
317
309
|
- test/unit/route_mapper_test.rb
|
318
|
-
- test/unit/route_test.rb
|
319
310
|
- test/unit/rspec_functional_helper.rb
|
320
311
|
- test/unit/rspec_helper_test.rb
|
321
312
|
- test/unit/test_helper_test.rb
|
data/gemfiles/rails_3_2.gemfile
DELETED
data/gemfiles/rails_4_0.gemfile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require "action_dispatch/routing"
|
2
|
-
|
3
|
-
module FocusedController
|
4
|
-
class Route < ActionDispatch::Routing::RouteSet::Dispatcher
|
5
|
-
attr_reader :name
|
6
|
-
|
7
|
-
def initialize(name)
|
8
|
-
@name = name
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
name.constantize.call(env)
|
13
|
-
end
|
14
|
-
|
15
|
-
alias to_s name
|
16
|
-
end
|
17
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'isolated_spec_helper'
|
2
|
-
require APP_ROOT + '/controllers/application_controller'
|
3
|
-
require APP_ROOT + '/controllers/posts_controller'
|
4
|
-
require APP_ROOT + '/models/post'
|
5
|
-
|
6
|
-
describe PostsController do
|
7
|
-
include FocusedController::RSpecHelper
|
8
|
-
stub_url :post, :posts
|
9
|
-
|
10
|
-
before do
|
11
|
-
@post = Post.create(:title => 'Hello', :body => 'Omg')
|
12
|
-
end
|
13
|
-
|
14
|
-
describe PostsController::Index do
|
15
|
-
it "should get index" do
|
16
|
-
subject.call
|
17
|
-
response.should be_success
|
18
|
-
subject.posts.should_not be(:nil)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe PostsController::New do
|
23
|
-
it "should get new" do
|
24
|
-
subject.call
|
25
|
-
response.should be_success
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe PostsController::Create do
|
30
|
-
it "should create post" do
|
31
|
-
subject.params = { :post => @post.attributes }
|
32
|
-
expect { subject.call }.to change(Post, :count).by(1)
|
33
|
-
response.should redirect_to(post_url(subject.post))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe PostsController::Show do
|
38
|
-
it "should show post" do
|
39
|
-
subject.params = { :id => @post.id }
|
40
|
-
subject.call
|
41
|
-
response.should be_success
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe PostsController::Edit do
|
46
|
-
it "should get edit" do
|
47
|
-
subject.params = { :id => @post.id }
|
48
|
-
subject.call
|
49
|
-
response.should be_success
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe PostsController::Update do
|
54
|
-
it "should update post" do
|
55
|
-
subject.params = { :id => @post.id }
|
56
|
-
subject.call
|
57
|
-
response.should redirect_to(post_url(subject.post))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe PostsController::Destroy do
|
62
|
-
it "should destroy post" do
|
63
|
-
subject.params = { :id => @post.id }
|
64
|
-
expect { subject.call }.to change(Post, :count).by(-1)
|
65
|
-
response.should redirect_to(posts_url)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'isolated_test_helper'
|
2
|
-
require APP_ROOT + '/controllers/application_controller'
|
3
|
-
require APP_ROOT + '/controllers/posts_controller'
|
4
|
-
require APP_ROOT + '/models/post'
|
5
|
-
|
6
|
-
module PostsController
|
7
|
-
class TestCase < ActiveSupport::TestCase
|
8
|
-
include FocusedController::TestHelper
|
9
|
-
stub_url :post, :posts
|
10
|
-
|
11
|
-
setup do
|
12
|
-
@post = Post.create(:title => 'Hello', :body => 'Omg')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class IndexTest < TestCase
|
17
|
-
test "should get index" do
|
18
|
-
controller.call
|
19
|
-
assert_response :success
|
20
|
-
assert_not_nil controller.posts
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class NewTest < TestCase
|
25
|
-
test "should get new" do
|
26
|
-
controller.call
|
27
|
-
assert_response :success
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class CreateTest < TestCase
|
32
|
-
test "should create post" do
|
33
|
-
controller.params = { :post => @post.attributes }
|
34
|
-
|
35
|
-
assert_difference('Post.count') do
|
36
|
-
controller.call
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_redirected_to post_url(controller.post)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class ShowTest < TestCase
|
44
|
-
test "should show post" do
|
45
|
-
controller.params = { :id => @post.id }
|
46
|
-
controller.call
|
47
|
-
assert_response :success
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class EditTest < TestCase
|
52
|
-
test "should get edit" do
|
53
|
-
controller.params = { :id => @post.id }
|
54
|
-
controller.call
|
55
|
-
assert_response :success
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class UpdateTest < TestCase
|
60
|
-
test "should update post" do
|
61
|
-
controller.params = { :id => @post.id }
|
62
|
-
controller.call
|
63
|
-
assert_redirected_to post_url(controller.post)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class DestroyTest < TestCase
|
68
|
-
test "should destroy post" do
|
69
|
-
controller.params = { :id => @post.id }
|
70
|
-
|
71
|
-
assert_difference('Post.count', -1) do
|
72
|
-
controller.call
|
73
|
-
end
|
74
|
-
|
75
|
-
assert_redirected_to posts_url
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/test/unit/route_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module FocusedController
|
4
|
-
module Test
|
5
|
-
end
|
6
|
-
|
7
|
-
describe Route do
|
8
|
-
let(:controller) { Object.new }
|
9
|
-
subject { Route.new('FocusedController::Test::RouteTestController') }
|
10
|
-
|
11
|
-
before do
|
12
|
-
Test.const_set(:RouteTestController, controller)
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
Test.send(:remove_const, :RouteTestController)
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#call' do
|
20
|
-
it 'constantizes the name and invokes #call on the constant' do
|
21
|
-
env, resp = Object.new, Object.new
|
22
|
-
|
23
|
-
# Not using MiniTest::Mock for this because it caused problems
|
24
|
-
# with Rubinius
|
25
|
-
controller.singleton_class.send :define_method, :call do |call_env|
|
26
|
-
resp if call_env == env
|
27
|
-
end
|
28
|
-
|
29
|
-
subject.call(env).must_equal resp
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#to_s' do
|
34
|
-
it "returns the the name" do
|
35
|
-
subject.to_s.must_equal 'FocusedController::Test::RouteTestController'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|