Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix route discovery with api! for Rails 5 (passes tests) #526

Closed
wants to merge 14 commits into from

Conversation

aminariana
Copy link
Contributor

I am building this PR on top of PR #465 from June 8, 2016. That one never made it to master because of bad Gemfile values that later got fixed in master, but never got merged into the PR.

In this PR:

  • I fix the issue with api! route discovery by borrowing @sblackstone fix commit
  • I add test coverage against Ruby 2.3.3
  • I fix the failing tests by merging the latest Gemfile fixes from master into this PR

Travis is passing 100% for me locally.

Fixes Issue #415
Fixes Issue #495
Fixes Issue #510
Distant relationship with Issue #522
Related to PR #465

@iNecas
Copy link
Member

iNecas commented Feb 16, 2017

Hi, I think I have a version that has actually tests passing with rails 5, will push in few minutes

@iNecas
Copy link
Member

iNecas commented Feb 16, 2017

#527, finger crossed

@aminariana
Copy link
Contributor Author

@iNecas My latest changes make it fully compatible with Rails 5.0 and Ruby 2.2.2+. However, I was forced to make it a breaking change, losing Rails <4 and Ruby <2.2. If yours is more compatible, great, if not please consider accepting this one.

@aminariana
Copy link
Contributor Author

@iNecas by the way would be awesome to fix the Rails 5 deprecation warnings.

@iNecas
Copy link
Member

iNecas commented Feb 17, 2017

I managed to keep it compatible in #527 (needed to drop ralis 32, but it was about a time), the deprecation warnings will be addressed separatly, such as here #420

@iNecas
Copy link
Member

iNecas commented Feb 17, 2017

Closed by #527, thanks @aminariana, you helped a lot speeding up the process!

@iNecas iNecas closed this Feb 17, 2017
@jsantos
Copy link
Contributor

jsantos commented Feb 27, 2017

Any hint why after this commit namespaced controllers would stop working?

I got the following error with this commit:

/.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:268:in `const_get': uninitialized constant SurveyorUsersController (NameError)
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:268:in `block in constantize'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:266:in `each'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:266:in `inject'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:266:in `constantize'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:58:in `route_app_controller'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:64:in `block in routes_for_action'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:63:in `select'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:63:in `routes_for_action'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/apipie_module.rb:18:in `method_missing'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/method_description.rb:171:in `api_data'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/method_description.rb:26:in `initialize'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:87:in `new'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:87:in `block in define_method_description'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:79:in `each'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/application.rb:79:in `define_method_description'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/apipie_module.rb:18:in `method_missing'
  from /.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/apipie-rails-d3519c357caf/lib/apipie/dsl_definition.rb:408:in `method_added'
  from /.../my_rails_app/app/controllers/api/sms/surveyor_users_controller.rb:46:in `<class:SurveyorUsersController>'
  from /.../my_rails_app/app/controllers/api/sms/surveyor_users_controller.rb:1:in `<top (required)>'

It claims not to be able to find SurveyorUsersController, that in fact is Api::Sms::SurveyorUsersController.

@iNecas
Copy link
Member

iNecas commented Feb 27, 2017

@jsantos
Copy link
Contributor

jsantos commented Feb 27, 2017

@iNecas That's my best guess.

I'm just wondering if there's anything wrong on my end, but before this commit (and on Rails 4.2.x) everything was running smooth. I was on the middle of the transition to Rails 5 and after upgrading apipie-rails to 0.4.0 I bumped on this.

@iNecas
Copy link
Member

iNecas commented Feb 27, 2017

@jsantos I will not get sooner to sending a fix for this until middle of this week: if you want to give it a try and fix it sooner, I will be more than happy to review.

@jsantos
Copy link
Contributor

jsantos commented Feb 27, 2017

@iNecas Sure, I'll give it a shot 👍

@jsantos
Copy link
Contributor

jsantos commented Feb 28, 2017

@iNecas Looks like this was a problem on our end (there was a route with no controller associated).

Shall we display a more informative error message when this happens?

@iNecas
Copy link
Member

iNecas commented Feb 28, 2017

👍 on that. Will you give it a try: it would be great, as you know what the reproducer was

@kklw
Copy link

kklw commented Mar 30, 2017

Hi, on adding api!, I'm getting NameError - uninitialized constant Api::V1::JobCreationsController: . Did i miss out something?

@jsantos
Copy link
Contributor

jsantos commented Mar 30, 2017

@kklw Check if you have unused routes in your code. Doesn't need to be exactly the one that showed up in your stacktrace, but that was my case.

@kklw
Copy link

kklw commented Mar 30, 2017

@jsantos Thanks! Works perfectly now.

@jsantos
Copy link
Contributor

jsantos commented Mar 30, 2017

@iNecas Regarding this "issue" with non-existent routes: What's the best approach? Shall we present a clearer error message?

Because continuing silently here doesn't look like a good practice, I'd say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants