Reduce factory creation across controllers/admin
specs (#33752)
This commit is contained in:
parent
93f3c724ae
commit
8a2d764d34
4 changed files with 18 additions and 66 deletions
|
@ -68,11 +68,9 @@ RSpec.describe Admin::RolesController do
|
|||
let(:selected_position) { 1 }
|
||||
let(:selected_permissions_as_keys) { %w(manage_roles) }
|
||||
|
||||
it 'redirects to roles page' do
|
||||
it 'redirects to roles page and creates role' do
|
||||
expect(response).to redirect_to(admin_roles_path)
|
||||
end
|
||||
|
||||
it 'creates new role' do
|
||||
expect(UserRole.find_by(name: 'Bar')).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
@ -81,11 +79,9 @@ RSpec.describe Admin::RolesController do
|
|||
let(:selected_position) { 100 }
|
||||
let(:selected_permissions_as_keys) { %w(manage_roles) }
|
||||
|
||||
it 'renders new template' do
|
||||
it 'renders new template and does not create role' do
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
|
||||
it 'does not create new role' do
|
||||
expect(UserRole.find_by(name: 'Bar')).to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -94,11 +90,9 @@ RSpec.describe Admin::RolesController do
|
|||
let(:selected_position) { 1 }
|
||||
let(:selected_permissions_as_keys) { %w(manage_roles manage_users manage_reports) }
|
||||
|
||||
it 'renders new template' do
|
||||
it 'renders new template and does not create role' do
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
|
||||
it 'does not create new role' do
|
||||
expect(UserRole.find_by(name: 'Bar')).to be_nil
|
||||
end
|
||||
end
|
||||
|
@ -109,11 +103,9 @@ RSpec.describe Admin::RolesController do
|
|||
let(:selected_position) { 1 }
|
||||
let(:selected_permissions_as_keys) { %w(manage_roles manage_users manage_reports) }
|
||||
|
||||
it 'redirects to roles page' do
|
||||
it 'redirects to roles page and creates new role' do
|
||||
expect(response).to redirect_to(admin_roles_path)
|
||||
end
|
||||
|
||||
it 'creates new role' do
|
||||
expect(UserRole.find_by(name: 'Bar')).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
@ -166,11 +158,9 @@ RSpec.describe Admin::RolesController do
|
|||
end
|
||||
|
||||
context 'when user does not have permission to manage roles' do
|
||||
it 'returns http forbidden' do
|
||||
it 'returns http forbidden and does not update role' do
|
||||
expect(response).to have_http_status(403)
|
||||
end
|
||||
|
||||
it 'does not update the role' do
|
||||
expect(role.reload.name).to eq 'Bar'
|
||||
end
|
||||
end
|
||||
|
@ -179,11 +169,9 @@ RSpec.describe Admin::RolesController do
|
|||
let(:permissions) { UserRole::FLAGS[:manage_roles] }
|
||||
|
||||
context 'when role has permissions the user doesn\'t' do
|
||||
it 'renders edit template' do
|
||||
it 'renders edit template and does not update role' do
|
||||
expect(response).to render_template(:edit)
|
||||
end
|
||||
|
||||
it 'does not update the role' do
|
||||
expect(role.reload.name).to eq 'Bar'
|
||||
end
|
||||
end
|
||||
|
@ -192,11 +180,9 @@ RSpec.describe Admin::RolesController do
|
|||
let(:permissions) { UserRole::FLAGS[:manage_roles] | UserRole::FLAGS[:manage_users] }
|
||||
|
||||
context 'when user outranks the role' do
|
||||
it 'redirects to roles page' do
|
||||
it 'redirects to roles page and updates role' do
|
||||
expect(response).to redirect_to(admin_roles_path)
|
||||
end
|
||||
|
||||
it 'updates the role' do
|
||||
expect(role.reload.name).to eq 'Baz'
|
||||
end
|
||||
end
|
||||
|
@ -204,11 +190,9 @@ RSpec.describe Admin::RolesController do
|
|||
context 'when role outranks user' do
|
||||
let(:role_position) { current_role.position + 1 }
|
||||
|
||||
it 'returns http forbidden' do
|
||||
it 'returns http forbidden and does not update role' do
|
||||
expect(response).to have_http_status(403)
|
||||
end
|
||||
|
||||
it 'does not update the role' do
|
||||
expect(role.reload.name).to eq 'Bar'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue