route_mechanic 0.1.1 → 0.1.2
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/README.md +1 -1
- data/lib/route_mechanic/rspec/matchers.rb +3 -3
- data/lib/route_mechanic/testing/methods.rb +19 -7
- data/lib/route_mechanic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edfa9dd2a475e94ffb5131cfb367f430a838ecc12d001e45414955b1f0d84ec5
|
4
|
+
data.tar.gz: '039c3bbbc1f86d16336db76fb1e6b0879ee3e2d2b8bc8f64731988c64301c48c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae134daadd7209a3d67e5e3c9b7e2615b168693f034d3abd34915568de2333b5ef0955f0b7f57a76734c0e06d56145cc8bf861f156567f9437ed5bd02199e1fd
|
7
|
+
data.tar.gz: 97d0c73f8d437837742470795f4f9414c73af178f911d27e49eb5c5edbba5ebf51a9f7e0b0d1155e66f1f348a1aaf8ba1333513d48de6c41fe36afe8c0ac0e7f
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Just add a test file which has only one test case using `have_valid_routes` matc
|
|
33
33
|
```ruby
|
34
34
|
RSpec.describe 'Rails.application', type: :routing do
|
35
35
|
it "fails if application does not have valid routes" do
|
36
|
-
expect(Rails.application
|
36
|
+
expect(Rails.application).to have_valid_routes
|
37
37
|
end
|
38
38
|
end
|
39
39
|
```
|
@@ -8,7 +8,7 @@ module RouteMechanic
|
|
8
8
|
include ::RSpec::Matchers::Composable
|
9
9
|
include RouteMechanic::Testing::Methods
|
10
10
|
|
11
|
-
# @param [
|
11
|
+
# @param [Rails::Application] expected
|
12
12
|
def initialize(expected)
|
13
13
|
@expected = expected
|
14
14
|
end
|
@@ -42,8 +42,8 @@ module RouteMechanic
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def have_valid_routes(
|
46
|
-
HaveValidRoutes.new(
|
45
|
+
def have_valid_routes(application=Rails.application)
|
46
|
+
HaveValidRoutes.new(application)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -10,12 +10,10 @@ module RouteMechanic
|
|
10
10
|
include MinitestAssertionAdapter if defined?(RSpec)
|
11
11
|
include ActionDispatch::Assertions
|
12
12
|
|
13
|
-
# @param [
|
13
|
+
# @param [Rails::Application] application
|
14
14
|
# @raise [Minitest::Assertion]
|
15
|
-
def assert_all_routes(
|
16
|
-
|
17
|
-
# If user already defines @routes, do not override
|
18
|
-
@routes ||= routes
|
15
|
+
def assert_all_routes(application=Rails.application)
|
16
|
+
@application = application
|
19
17
|
|
20
18
|
# Instead of including ActionController::TestCase::Behavior, set up
|
21
19
|
# https://github.com/rails/rails/blob/5b6aa8c20a3abfd6274c83f196abf73cacb3400b/actionpack/lib/action_controller/test_case.rb#L519-L520
|
@@ -29,6 +27,20 @@ module RouteMechanic
|
|
29
27
|
|
30
28
|
private
|
31
29
|
|
30
|
+
def routes
|
31
|
+
# assert_routing expect @routes to exists as like this class inherits ActionController::TestCase.
|
32
|
+
# If user already defines @routes, do not override
|
33
|
+
@routes ||= @application.routes
|
34
|
+
|
35
|
+
return @routes if @routes.routes.size > 0
|
36
|
+
|
37
|
+
# If routes setting is not loaded when running test, it automatically loads config/routes as Rails does.
|
38
|
+
load_path = "#{Rails.root.join('config/routes.rb')}"
|
39
|
+
@application.routes_reloader.paths << load_path unless @application.routes_reloader.paths.include? load_path
|
40
|
+
@application.reload_routes!
|
41
|
+
@routes
|
42
|
+
end
|
43
|
+
|
32
44
|
# @param [RouteMechanic::Testing::RouteWrapper] wrapper
|
33
45
|
# @raise [Minitest::Assertion]
|
34
46
|
def assert_routes(wrapper)
|
@@ -37,7 +49,7 @@ module RouteMechanic
|
|
37
49
|
end
|
38
50
|
|
39
51
|
base_option = { controller: wrapper.controller, action: wrapper.action }
|
40
|
-
url =
|
52
|
+
url = routes.url_helpers.url_for(
|
41
53
|
base_option.merge({ only_path: true }).merge(required_parts))
|
42
54
|
expected_options = base_option.merge(required_parts)
|
43
55
|
|
@@ -62,7 +74,7 @@ module RouteMechanic
|
|
62
74
|
|
63
75
|
# @return [Array<ActionDispatch::Journey::Route>]
|
64
76
|
def target_routes
|
65
|
-
|
77
|
+
routes.routes.reject do |journey_route|
|
66
78
|
# Skip internals, endpoints that Rails adds by default
|
67
79
|
# Also Engines should be skipped since Engine's tests should be done in Engine
|
68
80
|
wrapper = RouteWrapper.new(journey_route)
|