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

Prevent user seeing field length SQL error when creating a search track #2859

Merged
merged 5 commits into from
Oct 28, 2015

Conversation

lizconlan
Copy link

New migration to extend the length of the track_things.track_query field from 255 chars to 500

Validates that the query fits within the 500 char limit to avoid the user seeing a database error if they exceed the field length

Fixes #937

@lizconlan lizconlan changed the title Prevent user from seeing field length SQL error when creating a search track Prevent user seeing field length SQL error when creating a search track Oct 20, 2015
@@ -70,6 +70,13 @@
track_thing = TrackThing.create_track_for_search_query('fancy dog', 'bodies')
expect(track_thing.track_query).to match(/variety:authority/)
end

it "will check that the query isn't too long to store" do
long_query = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit consequat enim, sit amet facilisis lorem bibendum in. Pellentesque cursus pretium tristique. Mauris nec venenatis justo. Nam facilisis, lectus et blandit eleifend, felis arcu massa nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis blandit consequat enim, sit amet facilisis lorem bibendum in. Pellentesque cursus pretium tristique. Mauris nec venenatis justo. Nam facilisis, lectus et blandit eleifend, felis arcu massa nunc."
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just "Lorem " * 100?

Copy link
Author

Choose a reason for hiding this comment

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

oh yes, that's much less horrible - thanks!

let(:ir) { FactoryGirl.create(:info_request,
:title => 'My request',
:url_title => 'myrequest') }
let(:track_thing) { FactoryGirl.create(:request_update_track,

Choose a reason for hiding this comment

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

Avoid using {...} for multi-line blocks.

@lizconlan lizconlan force-pushed the 937-long-track-query-errors branch 3 times, most recently from e0c6805 to 83ed3c0 Compare October 22, 2015 12:07
end

describe TrackController, "when making a search track" do
let(:track_thing) { FactoryGirl.create(:search_track,

Choose a reason for hiding this comment

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

Avoid using {...} for multi-line blocks.

@crowbot
Copy link
Member

crowbot commented Oct 23, 2015

Nice work on cleaning up the specs. Now that the validation error is displayed in the UI, I can see that there are two things still to fix up here - errors.full_messages appends the attribute name to the error message making it a bit garbled. I think we want to define a custom message on the validation so that we can translate the error message with a _() call and present a complete clear string - so the track_controller code could be:

-flash[:error] = @track_thing.errors.full_messages.join(", ")
+flash[:error] = @track_thing.errors.map{ |attr,message| message }.join(", ")

It's always worth checking the results of a PR in a browser before submitting it for review.

@lizconlan
Copy link
Author

bah, I was hoping (from a too-quick read of the docs) to get a humanized version of the message e.g. "Track query is too long" rather than just the message ("is too long") or the unexpected actual outcome "TrackThing|Track query is too long" which is pretty nasty :(

@lizconlan lizconlan force-pushed the 937-long-track-query-errors branch 3 times, most recently from 2dbaa1f to 4584689 Compare October 23, 2015 17:07
it "should send localised alerts" do
# set the time the comment event happened at to within the last week
ire = info_request_events(:silly_comment_event)
ire.created_at = Time.now - 3.days

Choose a reason for hiding this comment

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

Do not use Time.now without zone. Use one of Time.zone.now, Time.now.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.to_i, Time.now.to_f instead.

response.headers['Expires'].should == '0'
end
describe "when making a search track" do
let(:track_thing) { FactoryGirl.create(:search_track,

Choose a reason for hiding this comment

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

Avoid using {...} for multi-line blocks.

Copy link
Author

Choose a reason for hiding this comment

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

I think there's an exemption for this rubocop/rubocop#376

Copy link
Member

Choose a reason for hiding this comment

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

I don't disagree with the rule as it happens – you can still do:

let(:blah) do
  # ...
end

If you rebase on develop you should get the updated config that disables hound checks by default, other than the ones we've explicitly enabled though :)

it "should send localised alerts" do
# set the time the comment event happened at to within the last week
ire = info_request_events(:silly_comment_event)
ire.created_at = Time.now - 3.days

Choose a reason for hiding this comment

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

Do not use Time.now without zone. Use one of Time.zone.now, Time.now.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.to_i, Time.now.to_f instead.

@lizconlan lizconlan force-pushed the 937-long-track-query-errors branch from 610bb1e to e26a9f8 Compare October 27, 2015 14:47
@garethrees
Copy link
Member

Looks good to me other than the minor comment (#2859 (comment)) – :shipit: 🚢

@lizconlan lizconlan force-pushed the 937-long-track-query-errors branch from c5be6ad to 928b7ed Compare October 28, 2015 10:48
@garethrees
Copy link
Member

Could also do with a changelog entry btw! :)

@lizconlan lizconlan merged commit a1f814a into develop Oct 28, 2015
@lizconlan lizconlan deleted the 937-long-track-query-errors branch October 28, 2015 11:10
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