Skip to content

Commit e3cf03e

Browse files
committed
Merge pull request #331 from stim371/bounty_454
BUG: ActiveRecord::StatementInvalid: PG::NumericValueOutOfRange
2 parents 7f11eb6 + 3b60b7f commit e3cf03e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/controllers/teams_controller.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,18 @@ def team_from_params(opts)
256256
if opts[:slug].present?
257257
Team.where(slug: opts[:slug].downcase).first
258258
else
259-
Team.find(opts[:id])
259+
if valid_id?(opts[:id])
260+
Team.find(opts[:id])
261+
else
262+
nil
263+
end
260264
end
261265
end
262266

267+
def valid_id?(id)
268+
id.to_i.to_s == id && id.to_i < 2147483647
269+
end
270+
263271
def replace_section(section_name)
264272
section_name = section_name.tr('-', '_')
265273
"$('##{section_name}').replaceWith('#{escape_javascript(render(:partial => section_name))}');"

spec/controllers/teams_controller_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
get :show, slug: team.slug, job_id: 'not-a-real-job-slug'
6060
expect(assigns(:job_page)).to eq(false)
6161
end
62+
63+
context 'when searching by an out of bounds or non-integer id' do
64+
it 'should render 404' do
65+
get :show, id: '54209333547a9e5'
66+
expect(response).to have_http_status(404)
67+
end
68+
end
6269
end
6370

6471
describe '#create' do

0 commit comments

Comments
 (0)