summaryrefslogtreecommitdiff
path: root/spec/controllers/application_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/application_controller_spec.rb')
-rw-r--r--spec/controllers/application_controller_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index bad7a28556c..421ab006792 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -56,6 +56,57 @@ describe ApplicationController do
end
end
+ describe '#add_gon_variables' do
+ before do
+ Gon.clear
+ sign_in user
+ end
+
+ let(:json_response) { JSON.parse(response.body) }
+
+ controller(described_class) do
+ def index
+ render json: Gon.all_variables
+ end
+ end
+
+ shared_examples 'setting gon variables' do
+ it 'sets gon variables' do
+ get :index, format: format
+
+ expect(json_response.size).not_to be_zero
+ end
+ end
+
+ shared_examples 'not setting gon variables' do
+ it 'does not set gon variables' do
+ get :index, format: format
+
+ expect(json_response.size).to be_zero
+ end
+ end
+
+ context 'with html format' do
+ let(:format) { :html }
+
+ it_behaves_like 'setting gon variables'
+
+ context 'for peek requests' do
+ before do
+ request.path = '/-/peek'
+ end
+
+ it_behaves_like 'not setting gon variables'
+ end
+ end
+
+ context 'with json format' do
+ let(:format) { :json }
+
+ it_behaves_like 'not setting gon variables'
+ end
+ end
+
describe "#authenticate_user_from_personal_access_token!" do
before do
stub_authentication_activity_metrics(debug: false)