summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/controller_extension/errors.rb3
-rw-r--r--app/controllers/v1/identities_controller.rb6
-rw-r--r--test/functional/v1/identities_controller_test.rb4
3 files changed, 12 insertions, 1 deletions
diff --git a/app/controllers/controller_extension/errors.rb b/app/controllers/controller_extension/errors.rb
index 2b68955..3d919b0 100644
--- a/app/controllers/controller_extension/errors.rb
+++ b/app/controllers/controller_extension/errors.rb
@@ -6,16 +6,19 @@ module ControllerExtension::Errors
def access_denied
render_error :not_authorized, :forbidden, home_url
end
+ alias_method :render_access_denied, :access_denied
def login_required
# Warden will intercept the 401 response and call
# SessionController#unauthenticated instead.
render_error :not_authorized_login, :unauthorized, login_url
end
+ alias_method :render_login_required, :login_required
def not_found(msg=nil, url=nil)
render_error(msg || :not_found, :not_found, url || home_url)
end
+ alias_method :render_not_found, :not_found
private
diff --git a/app/controllers/v1/identities_controller.rb b/app/controllers/v1/identities_controller.rb
index 1d8c542..4efd1f5 100644
--- a/app/controllers/v1/identities_controller.rb
+++ b/app/controllers/v1/identities_controller.rb
@@ -5,7 +5,11 @@ module V1
def show
@identity = Identity.find_by_address(params[:id])
- respond_with @identity
+ if @identity
+ respond_with @identity
+ else
+ render_not_found
+ end
end
end
diff --git a/test/functional/v1/identities_controller_test.rb b/test/functional/v1/identities_controller_test.rb
index 3e88402..6410c44 100644
--- a/test/functional/v1/identities_controller_test.rb
+++ b/test/functional/v1/identities_controller_test.rb
@@ -8,9 +8,13 @@ class V1::IdentitiesControllerTest < ActionController::TestCase
get :show, :id => identity.address, :format => 'json'
assert_response :success
assert_equal identity, assigns(:identity)
+
+ get :show, :id => "blahblahblah", :format => 'json'
+ assert_response :not_found
end
end
+
test "anonymous cannot fetch identity" do
identity = FactoryGirl.create :identity
get :show, :id => identity.address, :format => 'json'