Coder Social home page Coder Social logo

ohbarye / route_mechanic Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 4.0 60 KB

RouteMechanic detects broken routes with ease :train:

Home Page: https://rubygems.org/gems/route_mechanic

License: MIT License

Ruby 99.51% Shell 0.49%
rspec minitest ruby rails testing automation

route_mechanic's Issues

Should this gem stop using assertions provided by Rails?

Problem

First, this gem internally runs 2 checks.

  1. The gem's original aggregation of missing routes.
  2. Assertions provided by Rails

The main check process is done by 1, and it runs the 2 just in case. But the 2 causes some problems like #7 #9, and even if the 2 is skipped it can correctly report missing routes.

Therefore, I'm wondering if this gem should stop using assertions provided by Rails so that its behavior gets stable.

If parameter expects not `1`, it fails

Problem

If there's a path that expects a parameter to be a specific format, it fails.

e.g.

scope ':locale', locale: /en|ja/ do
  get '/locale_test' => 'users#index'
end
  • It expects /en|ja/,
  • But route_mechanic always gives 1 as a parameter in the path.

memo.merge({ required_part => '1' }) # '1' is pseudo id

Solution

I came up with 2 ideas as follow.

  1. Use https://github.com/tom-lord/regexp-examples and generate an example parameter that meets requirements.
  2. Remove assert_routes since it's not the main work of this gem.

I kinda want to choose the 2nd option because assert_* cause some problems like this and #7.


Thank you @pocke for reporting.

It doesn't work with constraints

Hi. Thanks for the great gem!

I'm trying to use this gem in my Rails application, but it raises an error with constraints.

We can reproduce the problem with the simple patch to this repository.

diff --git a/fixtures/fake_app/rails_app.rb b/fixtures/fake_app/rails_app.rb
index 09e13d7..c2b1e3d 100644
--- a/fixtures/fake_app/rails_app.rb
+++ b/fixtures/fake_app/rails_app.rb
@@ -8,6 +8,10 @@ FakeApp.config.root = File.dirname(__FILE__)
 FakeApp.initialize!
 
 FakeApp.routes.draw do
+  constraints subdomain: /\A[0-9a-z-]+\z/ do
+    get '/constraints_test' => 'users#index'
+  end
+
   resources :users do
     get 'friends', to: :friends
   end
$ bundle exec rake
# Running:

...F

Failure:
RouteMechanicTestingMethodsTest#test_that_fake_app_has_missing_routes [/home/pocke/ghq/github.com/ohbarye/route_mechanic/test/testing/methods_test.rb:63]:
--- expected
+++ actual
@@ -1,12 +1 @@
-"[Route Mechanic]
-  No route matches to the controllers and action methods below
-    UsersController#unknown
-  No controller and action matches to the routes below
-    GET    /users/:user_id/friends(.:format) users#friends
-    GET    /users(.:format)                  users#index
-    GET    /users/new(.:format)              users#new
-    GET    /users/:id/edit(.:format)         users#edit
-    GET    /users/:id(.:format)              users#show
-    DELETE /users/:id(.:format)              users#destroy
-
-"
+"No route matches \"/constraints_test\""



rails test /home/pocke/ghq/github.com/ohbarye/route_mechanic/test/testing/methods_test.rb:44

it prints No route matches "/constraints_test", but I think it is not an intentional error.


It is raised during the assert_routing method call.

assert_routing({ path: url, method: wrapper.verb }, expected_options)

All public methods in controllers are treated as action methods

Issue

If there's a public method in a controller, route_mechanic treats it as an action method that should have routes.

e.g.

# If we have a method like below,
class UsersController
  def foo_helper
  end
end

# it expects `users#foo_helper` to exist in routes

Solution

TBA ๐Ÿค”
Should users be able to ignore any action methods?

Unused route failures for actions from Rails Engines

If a Rails project contains an engine, and that engine introduces both routes and matching actions into your application, then RouteMechanic will successfully see the routes, but fail the have_no_unused_routes assertion incorrectly, because it cannot see the action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.