route_mechanic 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2378e095ad88def369adb3b2b271a9e324a853b535670e3b1be95f4e98d2ee0
4
- data.tar.gz: 12f172bb4021e0c56e4ea740a269d10e41a2c67d2f3f040137882dc414ffe448
3
+ metadata.gz: edfa9dd2a475e94ffb5131cfb367f430a838ecc12d001e45414955b1f0d84ec5
4
+ data.tar.gz: '039c3bbbc1f86d16336db76fb1e6b0879ee3e2d2b8bc8f64731988c64301c48c'
5
5
  SHA512:
6
- metadata.gz: 3ee458593e8f2e095c11cb2ce1f36095c50d53eacab10e72032429b4514641d1afe676a37082121c629ba7c23e1ede37362a3ee0ce563caf35f76bf0760bb2ae
7
- data.tar.gz: 3079f7b95a27e7c2c3bddd735352283f85cd6f83e362398406c70206160783dba53a83cfe35daf42ab2965857b445dac148d53cbf1cff29fbbb338443c9f7bde
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.routes).to have_valid_routes
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 [ActionDispatch::Routing::RouteSet] expected
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(routes=Rails.application.routes)
46
- HaveValidRoutes.new(routes)
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 [ActionDispatch::Routing::RouteSet] routes
13
+ # @param [Rails::Application] application
14
14
  # @raise [Minitest::Assertion]
15
- def assert_all_routes(routes=Rails.application.routes)
16
- # assert_routing expect @routes to exists as like this class inherits ActionController::TestCase.
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 = @routes.url_helpers.url_for(
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
- @routes.routes.reject do |journey_route|
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)
@@ -1,3 +1,3 @@
1
1
  module RouteMechanic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_mechanic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ohbarye