-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Quote table_ and column_name for sorting #3652
Quote table_ and column_name for sorting #3652
Conversation
f5f7d8a
to
51cf5a4
Compare
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq(sort: 'players.team_id', sort_reverse: true) | ||
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.?players.?\..?team_id.?/, sort_reverse: true) | ||
end | ||
end | ||
|
||
context 'using active_record, supporting joins', active_record: true do | ||
it 'gives back the local column' do | ||
controller.params = {sort: 'team', model_name: 'players'} | ||
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq(sort: 'teams.name', sort_reverse: true) | ||
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.?teams.?\..?name.?/, sort_reverse: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should also add a regression spec with a model with capitalized fields? Where would I put it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere around here will be good, as this fix is about #get_sort_hash
.
Also you can create RDBMS-specific test cases like:
rails_admin/spec/rails_admin/support/csv_converter_spec.rb
Lines 69 to 75 in 0e12e5b
case connection_config[:adapter] | |
when 'postgresql' | |
@connection = ActiveRecord::Base.connection.instance_variable_get(:@connection) | |
@connection.set_client_encoding('latin1') | |
when 'mysql2' | |
ActiveRecord::Base.connection.execute('SET NAMES latin1;') | |
end |
Any update on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I've made some comments.
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq(sort: 'players.team_id', sort_reverse: true) | ||
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.?players.?\..?team_id.?/, sort_reverse: true) | ||
end | ||
end | ||
|
||
context 'using active_record, supporting joins', active_record: true do | ||
it 'gives back the local column' do | ||
controller.params = {sort: 'team', model_name: 'players'} | ||
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq(sort: 'teams.name', sort_reverse: true) | ||
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.?teams.?\..?name.?/, sort_reverse: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere around here will be good, as this fix is about #get_sort_hash
.
Also you can create RDBMS-specific test cases like:
rails_admin/spec/rails_admin/support/csv_converter_spec.rb
Lines 69 to 75 in 0e12e5b
case connection_config[:adapter] | |
when 'postgresql' | |
@connection = ActiveRecord::Base.connection.instance_variable_get(:@connection) | |
@connection.set_client_encoding('latin1') | |
when 'mysql2' | |
ActiveRecord::Base.connection.execute('SET NAMES latin1;') | |
end |
51cf5a4
to
68299c0
Compare
Great job, thank you! |
Ah sorry I forgot about that. I think I didn't add the regression test or RDBMS-specific test cases. |
I'll handle that when I have time 👍 |
Add a test case to ensure the table and column names are quoted
Fixes #1631.