Skip to content

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

Fix multiline #describe text in specs

Christophe Bliard051fb27915dc
diff --git a/.rubocop.yml b/.rubocop.yml
index 84d80a62f12..2a5fd5ed434 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -239,6 +239,7 @@ RSpec/ContextWording:
Prefixes:
- and
- as
+ - even
- for
- having
- if
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index d567fb5319d..e9cbfdcaf8e 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -107,97 +107,77 @@ RSpec.describe UsersController do
end
describe 'GET deletion_info' do
- describe "WHEN the current user is the requested user
- WHEN the setting users_deletable_by_self is set to true" do
- let(:params) { { 'id' => user.id.to_s } }
+ let(:params) { { 'id' => user.id.to_s } }
- before do
- allow(Setting).to receive(:users_deletable_by_self?).and_return(true)
+ context 'when the current user is the requested user' do
+ current_user { user }
- as_logged_in_user user do
+ context "when the setting users_deletable_by_self is set to true",
+ with_settings: { users_deletable_by_self: true } do
+ before do
get :deletion_info, params:
end
- end
- it do
- expect(response).to be_successful
- end
+ it { expect(response).to have_http_status(:success) }
- it do
- expect(assigns(:user)).to eq(user)
- end
-
- it { expect(response).to render_template('deletion_info') }
- end
-
- describe "WHEN the current user is the requested user
- WHEN the setting users_deletable_by_self is set to false" do
- let(:params) { { 'id' => user.id.to_s } }
+ it 'assigns @user to requested user' do
+ expect(assigns(:user)).to eq(user)
+ end
- before do
- allow(Setting).to receive(:users_deletable_by_self?).and_return(false)
+ it { expect(response).to render_template('deletion_info') }
+ end
- as_logged_in_user user do
+ context "when the setting users_deletable_by_self is set to false",
+ with_settings: { users_deletable_by_self: false } do
+ before do
get :deletion_info, params:
end
- end
- it { expect(response.response_code).to eq(404) }
+ it { expect(response).to have_http_status(:not_found) }
+ end
end
- describe 'WHEN the current user is the anonymous user' do
- let(:params) { { 'id' => anonymous.id.to_s } }
+ context 'when the current user is the anonymous user' do
+ current_user { anonymous }
before do
- as_logged_in_user anonymous do
- get :deletion_info, params:
- end
+ get :deletion_info, params:
end
it {
expect(response).to redirect_to(controller: 'account',
action: 'login',
- back_url: @controller.url_for(controller: 'users',
- action: 'deletion_info'))
+ back_url: controller.url_for(controller: 'users',
+ action: 'deletion_info'))
}
end
- describe "WHEN the current user is admin
- WHEN the setting users_deletable_by_admins is set to true" do
- let(:params) { { 'id' => user.id.to_s } }
-
- before do
- allow(Setting).to receive(:users_deletable_by_admins?).and_return(true)
+ context "when the current user is admin" do
+ current_user { admin }
- as_logged_in_user admin do
+ context "when the setting users_deletable_by_admins is set to true",
+ with_settings: { users_deletable_by_admins: true } do
+ before do
get :deletion_info, params:
end
- end
-
- it do
- expect(response).to be_successful
- end
-
- it do
- expect(assigns(:user)).to eq(user)
- end
- it { expect(response).to render_template('deletion_info') }
- end
+ it { expect(response).to have_http_status(:success) }
- describe "WHEN the current user is admin
- WHEN the setting users_deletable_by_admins is set to false" do
- let(:params) { { 'id' => user.id.to_s } }
+ it 'assigns @user to requested user' do
+ expect(assigns(:user)).to eq(user)
+ end
- before do
- allow(Setting).to receive(:users_deletable_by_admins?).and_return(false)
+ it { expect(response).to render_template('deletion_info') }
+ end
- as_logged_in_user admin do
+ context "when the setting users_deletable_by_admins is set to false",
+ with_settings: { users_deletable_by_admins: false } do
+ before do
get :deletion_info, params:
end
- end
- it { expect(response.response_code).to eq(404) }
+ it { expect(response).to have_http_status(:not_found) }
+ end
end
end
@@ -269,9 +249,12 @@ RSpec.describe UsersController do
describe 'POST destroy' do
let(:base_params) { { 'id' => user.id.to_s, back_url: my_account_path } }
- context 'WHEN the password confirmation is missing' do
+ before do
+ disable_flash_sweep
+ end
+
+ context 'when the password confirmation is missing' do
before do
- disable_flash_sweep
allow(Setting).to receive(:users_deletable_by_self?).and_return(true)
as_logged_in_user user do
@@ -286,112 +269,88 @@ RSpec.describe UsersController do
it { expect(flash[:error]).to eq(I18n.t(:notice_password_confirmation_failed)) }
end
- context 'WHEN password confirmation is present' do
- let(:base_params) do
- { 'id' => user.id.to_s, :_password_confirmation => user_password, back_url: my_account_path }
+ context 'when password confirmation is present' do
+ let(:params) do
+ base_params.merge(_password_confirmation: user_password)
end
- describe "WHEN the current user is the requested one
- WHEN the setting users_deletable_by_self is set to true" do
- before do
- disable_flash_sweep
- allow(Setting).to receive(:users_deletable_by_self?).and_return(true)
+ context 'when the current user is the requested one' do
+ current_user { user }
- as_logged_in_user user do
- post :destroy, params: base_params
+ context "when the setting users_deletable_by_self is set to true",
+ with_settings: { users_deletable_by_self: true } do
+ before do
+ post :destroy, params:
end
- end
-
- it do
- expect(response).to redirect_to(controller: 'account', action: 'login')
- end
-
- it { expect(flash[:notice]).to eq(I18n.t('account.deletion_pending')) }
- end
- describe "WHEN the current user is the requested one
- WHEN the setting users_deletable_by_self is set to false" do
- before do
- disable_flash_sweep
- allow(Setting).to receive(:users_deletable_by_self?).and_return(false)
-
- as_logged_in_user user do
- post :destroy, params: base_params
+ it do
+ expect(response).to redirect_to(controller: 'account', action: 'login')
end
- end
-
- it { expect(response.response_code).to eq(404) }
- end
- describe "WHEN the current user is the anonymous user
- EVEN when the setting login_required is set to false" do
- before do
- allow(@controller).to receive(:find_current_user).and_return(anonymous)
- allow(Setting).to receive(:login_required?).and_return(false)
+ it { expect(flash[:notice]).to eq(I18n.t('account.deletion_pending')) }
+ end
- as_logged_in_user anonymous do
- post :destroy, params: base_params.merge(id: anonymous.id.to_s)
+ context 'when the setting users_deletable_by_self is set to false',
+ with_settings: { users_deletable_by_self: false } do
+ before do
+ post :destroy, params:
end
- end
- # redirecting post is not possible for now
- it { expect(response.response_code).to eq(403) }
+ it { expect(response).to have_http_status(:not_found) }
+ end
end
- describe "WHEN the current user is the admin
- WHEN the given password does not match
- WHEN the setting users_deletable_by_admins is set to true" do
- shared_let(:admin) { create(:admin) }
-
- before do
- disable_flash_sweep
- allow(Setting).to receive(:users_deletable_by_admins?).and_return(true)
+ context 'when the current user is the anonymous user' do
+ current_user { anonymous }
- as_logged_in_user admin do
- post :destroy, params: base_params
+ context 'even when the setting login_required is set to false and users_deletable_by_self is set to true',
+ with_settings: { login_required: false, users_deletable_by_self: true } do
+ before do
+ post :destroy, params: params.merge(id: anonymous.id.to_s)
end
- end
- it 'redirects with error' do
- expect(response).to redirect_to(controller: 'my', action: 'account')
- expect(flash[:notice]).to be_nil
- expect(flash[:error]).to eq(I18n.t(:notice_password_confirmation_failed))
+ # redirecting post is not possible for now
+ it { expect(response).to have_http_status(:forbidden) }
end
end
- describe "WHEN the current user is the admin
- WHEN the given password does match
- WHEN the setting users_deletable_by_admins is set to true" do
- before do
- disable_flash_sweep
- allow(Setting).to receive(:users_deletable_by_admins?).and_return(true)
+ context 'when the current user is the admin' do
+ current_user { admin }
- as_logged_in_user admin do
- post :destroy, params: base_params.merge(_password_confirmation: 'adminADMIN!')
+ context "when the given password does NOT match and the setting users_deletable_by_admins is set to true",
+ with_settings: { users_deletable_by_admins: true } do
+ before do
+ post :destroy, params:
end
- end
- it do
- expect(response).to redirect_to(controller: 'users', action: 'index')
+ it 'redirects with error' do
+ expect(response).to redirect_to(controller: 'my', action: 'account')
+ expect(flash[:notice]).to be_nil
+ expect(flash[:error]).to eq(I18n.t(:notice_password_confirmation_failed))
+ end
end
- it { expect(flash[:notice]).to eq(I18n.t('account.deletion_pending')) }
- end
+ context "when the given password does match and the setting users_deletable_by_admins is set to true",
+ with_settings: { users_deletable_by_admins: true } do
+ before do
+ post :destroy, params: params.merge(_password_confirmation: 'adminADMIN!')
+ end
- describe "WHEN the current user is the admin
- WHEN the setting users_deletable_by_admins is set to false" do
- shared_let(:admin) { create(:admin) }
+ it do
+ expect(response).to redirect_to(controller: 'users', action: 'index')
+ end
- before do
- disable_flash_sweep
- allow(Setting).to receive(:users_deletable_by_admins).and_return(false)
+ it { expect(flash[:notice]).to eq(I18n.t('account.deletion_pending')) }
+ end
- as_logged_in_user admin do
- post :destroy, params: base_params
+ context "when the setting users_deletable_by_admins is set to false",
+ with_settings: { users_deletable_by_admins: false } do
+ before do
+ post :destroy, params:
end
- end
- it { expect(response.response_code).to eq(404) }
+ it { expect(response).to have_http_status(:not_found) }
+ end
end
end
end
@@ -523,7 +482,7 @@ RSpec.describe UsersController do
it 'assigns users' do
expect(assigns(:users))
- .to match_array([user, admin])
+ .to contain_exactly(user, admin)
end
context 'with a name filter' do
@@ -531,7 +490,7 @@ RSpec.describe UsersController do
it 'assigns users' do
expect(assigns(:users))
- .to match_array([user])
+ .to contain_exactly(user)
end
end
@@ -544,7 +503,7 @@ RSpec.describe UsersController do
it 'assigns users' do
expect(assigns(:users))
- .to match_array([user])
+ .to contain_exactly(user)
end
end
end
@@ -716,7 +675,7 @@ RSpec.describe UsersController do
mail = ActionMailer::Base.deliveries.last
expect(mail.to)
- .to match_array [user.mail]
+ .to contain_exactly(user.mail)
expect(mail.body.encoded)
.to include('newpassPASS!')
@@ -973,7 +932,7 @@ RSpec.describe UsersController do
mail = ActionMailer::Base.deliveries.last
expect(mail.to)
- .to match_array [params[:user][:mail]]
+ .to contain_exactly(params[:user][:mail])
activation_link = Regexp.new(
"http://#{Setting.host_name}/account/activate\\?token=[a-f0-9]+",