From 84e20b8b51c59c0b7c5f9599fd2810128a2493d3 Mon Sep 17 00:00:00 2001 From: Dani Donisa Date: Mon, 16 Dec 2024 16:58:51 +0100 Subject: [PATCH] Refactor webui package requests controller specs --- .../packages/bs_requests_controller_spec.rb | 59 ++++--------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/src/api/spec/controllers/webui/packages/bs_requests_controller_spec.rb b/src/api/spec/controllers/webui/packages/bs_requests_controller_spec.rb index d9265e70aec..7c93b8e27c8 100644 --- a/src/api/spec/controllers/webui/packages/bs_requests_controller_spec.rb +++ b/src/api/spec/controllers/webui/packages/bs_requests_controller_spec.rb @@ -20,6 +20,13 @@ context 'when the user has the request_index feature flag enabled' do let!(:user) { create(:confirmed_user, login: 'king') } + let(:params) { base_params.merge(context_params) } + + before do + login user + Flipper.enable(:request_index, user) + get :index, params: params, format: :html + end context 'when looking at the target_package requests' do let(:target_project) { create(:project_with_package) } @@ -38,32 +45,19 @@ source_package: target_package, target_package: create(:project)) end + let(:base_params) { { project: target_project, package: target_package, format: :json } } context 'and the direction parameters is "incoming"' do - let(:base_params) { { project: target_project, package: target_package, format: :json } } let(:context_params) { { direction: 'incoming' } } - let(:params) { base_params.merge(context_params) } - - before do - login user - Flipper.enable(:request_index, user) - get :index, params: params, format: :html - end + it { expect(response).to have_http_status(:success) } + it { expect(subject).to render_template(:index) } it { expect(assigns[:bs_requests]).to include(incoming_request) } it { expect(assigns[:bs_requests]).not_to include(outgoing_request) } end context 'and the direction parameters is "outgoing"' do - let(:base_params) { { project: target_project, package: target_package, format: :json } } let(:context_params) { { direction: 'outgoing' } } - let(:params) { base_params.merge(context_params) } - - before do - login user - Flipper.enable(:request_index, user) - get :index, params: params, format: :html - end it { expect(response).to have_http_status(:success) } it { expect(subject).to render_template(:index) } @@ -72,15 +66,7 @@ end context 'and the direction parameters is "all"' do - let(:base_params) { { project: target_project, package: target_package, format: :json } } let(:context_params) { { direction: 'all' } } - let(:params) { base_params.merge(context_params) } - - before do - login user - Flipper.enable(:request_index, user) - get :index, params: params, format: :html - end it { expect(response).to have_http_status(:success) } it { expect(subject).to render_template(:index) } @@ -106,17 +92,10 @@ source_package: source_package, target_package: create(:project)) end + let(:base_params) { { project: source_project, package: source_package, format: :json } } context 'and the direction parameters is "incoming"' do - let(:base_params) { { project: source_project, package: source_package, format: :json } } let(:context_params) { { direction: 'incoming' } } - let(:params) { base_params.merge(context_params) } - - before do - login user - Flipper.enable(:request_index, user) - get :index, params: params, format: :html - end it { expect(response).to have_http_status(:success) } it { expect(subject).to render_template(:index) } @@ -125,15 +104,7 @@ end context 'and the direction parameters is "outgoing"' do - let(:base_params) { { project: source_project, package: source_package, format: :json } } let(:context_params) { { direction: 'outgoing' } } - let(:params) { base_params.merge(context_params) } - - before do - login user - Flipper.enable(:request_index, user) - get :index, params: params, format: :html - end it { expect(response).to have_http_status(:success) } it { expect(subject).to render_template(:index) } @@ -142,15 +113,7 @@ end context 'and the direction parameters is "all"' do - let(:base_params) { { project: source_project, package: source_package, format: :json } } let(:context_params) { { direction: 'all' } } - let(:params) { base_params.merge(context_params) } - - before do - login user - Flipper.enable(:request_index, user) - get :index, params: params, format: :html - end it { expect(response).to have_http_status(:success) } it { expect(subject).to render_template(:index) }