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

Handle zero plural resource names #1407

Merged
merged 1 commit into from
Apr 12, 2018

Conversation

dbwinger
Copy link
Contributor

@dbwinger dbwinger commented Apr 9, 2018

Fixes issue where 'zero plural' (same word for singular and plural) resource model names can't be routed correctly by ActionDispatch::Routing::PolymorphicRoutes.polymorphic_url using just Resource#namespaced_resources_name name, because the plural and singular are the same. In this case, sending Resource#namespaced_resources_name to polymorphic_url routes to the singular #show path instead of the expected #index. This changes it to use the resource model's class instead, which will reliably route to the #index path in all cases.

end

context 'with zero plural noun model name' do
let!(:peter) { create(:series, name: 'Peter')}

Choose a reason for hiding this comment

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

Layout/SpaceInsideBlockBraces: Space missing inside }.

post :update, params: {id: peter.id, event: {name: "Hans"}}.merge(params)
expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query")
context 'with regular noun model name' do
let(:peter) { create(:event, name: 'Peter') }

Choose a reason for hiding this comment

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

Layout/ExtraSpacing: Unnecessary spacing detected.

@dbwinger dbwinger force-pushed the zero-plural-resources branch from ef0afc3 to 3a10fb6 Compare April 9, 2018 18:14
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thank you very much. This makes sense.

Please satisfy my picky nits :) Then this can be merged.

@@ -0,0 +1,3 @@
class Admin::SeriesController < Alchemy::Admin::ResourcesController

end
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a new line at the end of the file and remove the empty line inside the class body? I updated the Rubocop settings to also include the dummy app, so would have been catched by HoundCI. Thanks

@@ -0,0 +1,2 @@
class Series < ActiveRecord::Base
end
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a new line at the end of the file? I updated the Rubocop settings to also include the dummy app, so would have been catched by HoundCI. Thanks

expect(controller).to receive(:controller_path) { 'admin/series' }
post :create, params: {series: {name: "Hans"}}.merge(params)
expect(response.redirect_url).to eq("http://test.host/admin/series?page=6&q%5Bname_cont%5D=some_query")
end
Copy link
Member

Choose a reason for hiding this comment

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

I would like to see some newlines between let, it and context. Thanks

@dbwinger dbwinger force-pushed the zero-plural-resources branch from 3a10fb6 to 5db149b Compare April 11, 2018 15:01
expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query")
end
end

Choose a reason for hiding this comment

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

Layout/TrailingWhitespace: Trailing whitespace detected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tvdeyen did I misunderstand your request, add the newline incorrectly, or is Robocop not set up correctly?

Copy link
Member

Choose a reason for hiding this comment

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

@dbwinger Now all looks fine, besides the trailing whitespace that's left in this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tvdeyen Sorry, I was thinking this was reporting a problem with the newline I added at your request to the end of the file, but now I see that's not it. I think I've got it all straightened out now.

expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query")
end
end

Choose a reason for hiding this comment

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

Layout/TrailingWhitespace: Trailing whitespace detected.

@dbwinger dbwinger force-pushed the zero-plural-resources branch from 5db149b to de75144 Compare April 12, 2018 15:32
@@ -76,4 +102,4 @@
expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query")
end
end
end
end

Choose a reason for hiding this comment

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

Layout/TrailingBlankLines: Final newline missing.

@dbwinger dbwinger force-pushed the zero-plural-resources branch from de75144 to 922c5c1 Compare April 12, 2018 15:34
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thanks

@tvdeyen tvdeyen merged commit 73e8fbc into AlchemyCMS:master Apr 12, 2018
@dbwinger
Copy link
Contributor Author

@tvdeyen Can this be merged into the stable branches? I'm currently on 3-6-stable and it would be nice to have it. Should I do separate PRs?

@tvdeyen
Copy link
Member

tvdeyen commented Apr 12, 2018

@dbwinger sure. A separate PR for 3.6-stable and 4.0-stable would be great. Thanks

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.

3 participants