OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Chore: Fix describe/context block warnings
Aaron Contreras7b5cc89f9a15
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex 833420cf159..e24d3344897 100644--- a/spec/controllers/account_controller_spec.rb+++ b/spec/controllers/account_controller_spec.rb@@ -58,7 +58,7 @@ RSpec.describe AccountController,hook.reset!end- context 'GET #login' do+ describe 'GET #login' dolet(:setup) {}let(:params) { {} }@@ -128,7 +128,7 @@ RSpec.describe AccountController,endend- context 'POST #login' do+ describe 'POST #login' doshared_let(:admin) { create(:admin) }describe 'wrong password' do@@ -312,7 +312,7 @@ RSpec.describe AccountController,endend- context 'GET #logout' do+ describe 'GET #logout' doshared_let(:admin) { create(:admin) }it 'calls reset_session' do@@ -578,7 +578,7 @@ RSpec.describe AccountController,endend- context 'GET #register' do+ describe 'GET #register' docontext 'with self registration on',with_settings: { self_registration: Setting::SelfRegistration.automatic } docontext 'and password login enabled' do@@ -633,7 +633,7 @@ RSpec.describe AccountController,end# See integration/account_test.rb for the full test- context 'POST #register' do+ describe 'POST #register' docontext 'with self registration on automatic',with_settings: { self_registration: Setting::SelfRegistration.automatic } dobefore do@@ -938,48 +938,106 @@ RSpec.describe AccountController,endend- context 'POST activate' do- let!(:admin) { create(:admin) }- let(:user) { create(:user, status:) }- let(:status) { -1 }+ describe 'POST #activate' do+ describe 'account activation' do+ shared_examples 'account activation' do+ let(:token) { Token::Invitation.create user: }++ let(:activation_params) do+ {+ token: token.value+ }+ end- let(:token) { Token::Invitation.create!(user_id: user.id) }+ context 'with an expired token' do+ before do+ token.update_column :expires_on, 1.day.ago- before do- allow(OpenProject::Enterprise).to receive(:user_limit_reached?).and_return(true)+ post :activate, params: activation_params+ end- post :activate, params: { token: token.value }- end+ it 'fails and shows an expiration warning' do+ expect(subject).to redirect_to('/')+ expect(flash[:warning]).to include 'expired'+ end- shared_examples "activation is blocked due to user limit" do- it "does not activate the user" do- expect(user.reload).not_to be_active- end+ it 'deletes the old token and generates a new one' do+ old_token = Token::Invitation.find_by(id: token.id)+ new_token = Token::Invitation.find_by(user_id: token.user.id)++ expect(old_token).to be_nil+ expect(new_token).to be_present- it "redirects back to the login page and shows the user limit error" do- expect(response).to redirect_to(signin_path)- expect(flash[:error]).to match /user limit reached.*contact.*admin/i+ expect(new_token).not_to be_expired+ end++ it 'sends out a new activation email' do+ new_token = Token::Invitation.find_by(user_id: token.user.id)++ perform_enqueued_jobs++ mail = ActionMailer::Base.deliveries.last+ expect(mail.parts.first.body.raw_source).to include "activate?token=#{new_token.value}"+ end+ endend- it "notifies the admins about the issue" do- perform_enqueued_jobs+ context 'with an invited user' do+ it_behaves_like 'account activation' do+ let(:user) { create(:user, status: 4) }+ end+ end- mail = ActionMailer::Base.deliveries.detect { |mail| mail.to.first == admin.mail }- expect(mail).to be_present- expect(mail.subject).to match /limit reached/+ context 'with a registered user' do+ it_behaves_like 'account activation' do+ let(:user) { create(:user, status: 2) }+ endendend- context 'registered user' do- let(:status) { User.statuses[:registered] }+ describe 'user limit' do+ let!(:admin) { create(:admin) }+ let(:user) { create(:user, status:) }+ let(:status) { -1 }- it_behaves_like "activation is blocked due to user limit"- end+ let(:token) { Token::Invitation.create!(user_id: user.id) }- context 'invited user' do- let(:status) { User.statuses[:invited] }+ before do+ allow(OpenProject::Enterprise).to receive(:user_limit_reached?).and_return(true)- it_behaves_like "activation is blocked due to user limit"+ post :activate, params: { token: token.value }+ end++ shared_examples "activation is blocked due to user limit" do+ it "does not activate the user" do+ expect(user.reload).not_to be_active+ end++ it "redirects back to the login page and shows the user limit error" do+ expect(response).to redirect_to(signin_path)+ expect(flash[:error]).to match /user limit reached.*contact.*admin/i+ end++ it "notifies the admins about the issue" do+ perform_enqueued_jobs++ mail = ActionMailer::Base.deliveries.detect { |m| m.to.first == admin.mail }+ expect(mail).to be_present+ expect(mail.subject).to match /limit reached/+ end+ end++ context 'with an invited user' do+ let(:status) { User.statuses[:invited] }++ it_behaves_like "activation is blocked due to user limit"+ end++ context 'with a registered user' do+ let(:status) { User.statuses[:registered] }++ it_behaves_like "activation is blocked due to user limit"+ endendend@@ -1057,60 +1115,4 @@ RSpec.describe AccountController,endendend-- describe 'POST #activate' do- shared_examples 'account activation' do- let(:token) { Token::Invitation.create user: }-- let(:activation_params) do- {- token: token.value- }- end-- context 'with an expired token' do- before do- token.update_column :expires_on, 1.day.ago-- post :activate, params: activation_params- end-- it 'fails and shows an expiration warning' do- expect(subject).to redirect_to('/')- expect(flash[:warning]).to include 'expired'- end-- it 'deletes the old token and generates a new one' do- old_token = Token::Invitation.find_by(id: token.id)- new_token = Token::Invitation.find_by(user_id: token.user.id)-- expect(old_token).to be_nil- expect(new_token).to be_present-- expect(new_token).not_to be_expired- end-- it 'sends out a new activation email' do- new_token = Token::Invitation.find_by(user_id: token.user.id)-- perform_enqueued_jobs-- mail = ActionMailer::Base.deliveries.last- expect(mail.parts.first.body.raw_source).to include "activate?token=#{new_token.value}"- end- end- end-- context 'with an invited user' do- it_behaves_like 'account activation' do- let(:user) { create(:user, status: 4) }- end- end-- context 'with an registered user' do- it_behaves_like 'account activation' do- let(:user) { create(:user, status: 2) }- end- end- endend