Permalink
Browse files

Supermodel gets confused by Integer/String changes in id

  • Loading branch information...
1 parent ff1948c commit f6a18b56c10fb8555542364a09690f0ae0f6a581 @ijcd committed Apr 6, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −0 TODO
  2. +7 −2 lib/hoodwink/data_store.rb
View
1 TODO
@@ -4,3 +4,4 @@
# TODO: custom mocks
# TODO: REST validation
# TODO: Convert "You can stub this request with the following snippet:" from WebMock into something we can do
+# TODO: allow matching tail segment as action name: stub_request(:get, "/^https?:\/\/(.*@)?serve.offerengine.com:3001(?-mix:\/api\/v2\/coupons\/(?<coupon_id>[^\/]+)\/(?<dothis>[^\/]+))(\?(?<params>.*))?$/")
@@ -52,9 +52,14 @@ def model_for(sym)
end
end
+ # try as original, then as integer
def find(model_name, id)
- id = Integer(id) rescue id
- model_for(model_name).find(id)
+ begin
+ model_for(model_name).find(id)
+ rescue SuperModel::UnknownRecord => e
+ id = Integer(id) rescue id
+ model_for(model_name).find(id)
+ end
rescue SuperModel::UnknownRecord => e
raise RecordNotFound, e.message
end

0 comments on commit f6a18b5

Please sign in to comment.