From 6c0736da74b2a51d6eb0aab774cea03d6fba9c8c Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 3 May 2015 22:42:15 +0000 Subject: [PATCH] Allow unauthenticated requests to API ping --- app/controllers/api/application_controller.rb | 2 +- spec/integration/api/application_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/application_controller.rb b/app/controllers/api/application_controller.rb index 2961396..6cb0377 100644 --- a/app/controllers/api/application_controller.rb +++ b/app/controllers/api/application_controller.rb @@ -3,7 +3,7 @@ module API rescue_from ActiveRecord::RecordNotFound, with: :not_found skip_before_filter :verify_authenticity_token - skip_before_filter :authenticate!, only: :cor_preflight + skip_before_filter :authenticate!, only: %i[cor_preflight ping] before_filter :cor_filter before_filter :json_filter!, except: :cor_preflight diff --git a/spec/integration/api/application_spec.rb b/spec/integration/api/application_spec.rb index 7f69dad..283a3ad 100644 --- a/spec/integration/api/application_spec.rb +++ b/spec/integration/api/application_spec.rb @@ -1,8 +1,6 @@ describe 'API application' do include AcceptanceHelpers - before { api_sign_in } - describe 'ping endpoint' do before { get api_ping_path, format: :json } @@ -12,6 +10,8 @@ describe 'API application' do end describe 'formats handling' do + before { api_sign_in } + it 'responds with a 406 when request format is not JSON' do get api_ping_path, format: :xml expect(response.status).to be 406 @@ -21,6 +21,8 @@ describe 'API application' do end describe 'not found' do + before { api_sign_in } + it 'responds with a 404 when route does not exist' do get '/api/not_found', format: :json expect(response.status).to be 404