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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix with_routing test helper to make it work with api-only controllers #27371

Merged
merged 1 commit into from Dec 29, 2016

Conversation

yukideluxe
Copy link
Contributor

@yukideluxe yukideluxe commented Dec 15, 2016

Hi again! 馃憢

I found another regression while migrating my api-only app to Rails 5 (I'm on fire 馃敟) The with_routing test helper doesn't work for controllers that inherit from ActionController::API because the ActionView::Rendering module is not longer included as it was in the rails-api gem https://github.com/rails-api/rails-api/blob/master/lib/rails-api/action_controller/api.rb#L128

Hope you like the fix! 鉂わ笍

@maclover7
Copy link
Contributor

Build failures are unrelated to this PR.

@yukideluxe yukideluxe force-pushed the with-routing-api-only branch 3 times, most recently from 754cb89 to ee52160 Compare December 21, 2016 16:09
Copy link
Contributor

@kaspth kaspth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the 馃敟, @yukideluxe

@spastorino you're the API person, what do you think of the fix?

@@ -170,6 +176,16 @@ def test_string_constraint
end
end

def test_with_routing_works_with_api_only_controllers
@controller = ApiOnlyController.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, I think we could skip the ApiOnlyController class with: @controller = Class.new(ActionController::Api).new

@spastorino
Copy link
Contributor

Cool thanks for your work @ yukideluxe.

@kaspth seems OK to me at least for now. Maybe at some point in several places we could structure the code a bit differently. Perhaps in a lot of cases for API only we could have classes or modules with the basic functionality and for regular controllers we could reuse that code and enhance in subclasses or with extra modules or something like that I think would be better than having a lot of if statements.

@yukideluxe
Copy link
Contributor Author

Thanks for the feedback! @kaspth I've updated the test with your suggestion 鉁岋笍

with_routing do |set|
set.draw do
get "wow", to: "action_pack_assertions#nothing"
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I've changed the test so it does the same as the one you put as example :)
I didn't do the assertion before because the test was failing by just using with_routing

@kaspth
Copy link
Contributor

kaspth commented Dec 29, 2016

@spastorino yup, agreed about the future improvements.

@yukideluxe looks good! Can you squash your commits and add an entry in the Action Pack changelog? 馃榿

@yukideluxe yukideluxe changed the title fix with_routing assertion to make it work with api-only controllers fix with_routing test helper to make it work with api-only controllers Dec 29, 2016
@yukideluxe
Copy link
Contributor Author

@kaspth done! 馃挭 馃帀 鉂わ笍

@kaspth kaspth merged commit 8990f76 into rails:master Dec 29, 2016
kaspth added a commit that referenced this pull request Dec 29, 2016
fix with_routing test helper to make it work with api-only controllers
@kaspth
Copy link
Contributor

kaspth commented Dec 29, 2016

@yukideluxe BOOM! 馃帺鉂わ笍馃挭

Backported to 5-0-stable: c484e21

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

Successfully merging this pull request may close these issues.

None yet

4 participants