Drop Organization from specs

This commit is contained in:
Henne Vogelsang 2024-06-07 16:31:23 +02:00
parent 275be8c80a
commit 85149dc837
No known key found for this signature in database
GPG key ID: 97DDB66BDAF8D4D6
19 changed files with 14 additions and 959 deletions

View file

@ -5,16 +5,13 @@ require 'spec_helper'
describe Admin::ConferencesController do
# It is necessary to use bang version of let to build roles before user
let!(:organization) { create(:organization, name: 'organization') }
let!(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) }
let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) }
let(:organization_admin) { create(:user, role_ids: organization_admin_role.id) }
let!(:conference) { create(:conference, end_date: Date.new(2014, 05, 26) + 15) }
let(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let!(:organizer) { create(:organizer, resource: conference) }
let!(:organizer2) { create(:organizer, email: 'organizer2@email.osem', resource: conference) }
let(:participant) { create(:user) }
shared_examples 'access as organizer or organization_admin' do
shared_examples 'access as organizer' do
describe 'PATCH #update' do
context 'valid attributes' do
it 'locates the requested conference' do
@ -197,95 +194,6 @@ describe Admin::ConferencesController do
end
end
shared_examples 'access as organization_admin' do
describe 'POST #create' do
context 'with valid attributes' do
it 'saves the conference to the database' do
expected = expect do
post :create, params: { conference:
attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) }
end
expected.to change { Conference.count }.by 1
end
it 'redirects to conference#show' do
post :create, params: { conference:
attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) }
expect(response).to redirect_to admin_conference_path(
assigns[:conference].short_title)
end
it 'creates roles for the conference' do
cfp_role = Role.find_by(name: 'cfp', resource: conference)
info_desk_role = Role.find_by(name: 'info_desk', resource: conference)
volunteers_coordinator_role = Role.find_by(name: 'volunteers_coordinator', resource: conference)
post :create, params: { conference:
attributes_for(:conference, short_title: 'dps15') }
expect(conference.roles.count).to eq 4
expect(conference.roles).to match_array [organizer_role, cfp_role, info_desk_role, volunteers_coordinator_role]
end
end
context 'with invalid attributes' do
it 'does not save the conference to the database' do
expected = expect do
post :create, params: { conference:
attributes_for(:conference, short_title: nil, organization_id: organization.id) }
end
expected.to_not change { Conference.count }
end
it 're-renders the new template' do
post :create, params: { conference:
attributes_for(:conference, short_title: nil, organization_id: organization.id) }
expect(response).to be_successful
end
end
context 'with duplicate conference short title' do
it 'does not save the conference to the database' do
conference
expected = expect do
post :create, params: { conference:
attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) }
end
expected.to_not change { Conference.count }
end
it 're-renders the new template' do
conference
post :create, params: { conference: attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) }
expect(response).to be_successful
end
end
end
describe 'GET #new' do
it 'assigns a new conference to conference' do
get :new
expect(assigns(:conference)).to be_a_new(Conference)
end
it 'renders the :new template' do
get :new
expect(response).to render_template :new
end
end
end
describe 'organization admin access' do
before do
sign_in(organization_admin)
end
it_behaves_like 'access as organizer or organization_admin'
it_behaves_like 'access as organization_admin'
end
shared_examples 'access as organizer, participant or guest' do |path, message|
describe 'GET #new' do
it 'requires organizer privileges' do
@ -299,8 +207,7 @@ describe Admin::ConferencesController do
describe 'POST #create' do
it 'requires organizer privileges' do
post :create, params: { conference: attributes_for(:conference,
short_title: 'ExCon', organization_id: organization.id) }
post :create, params: { conference: attributes_for(:conference, short_title: 'ExCon') }
expect(response).to redirect_to(send(path))
if message
expect(flash[:alert]).to match(/#{message}/)
@ -314,7 +221,7 @@ describe Admin::ConferencesController do
sign_in(organizer)
end
it_behaves_like 'access as organizer or organization_admin'
it_behaves_like 'access as organizer'
it_behaves_like 'access as organizer, participant or guest', :root_path, 'You are not authorized to access this page.'
end

View file

@ -1,200 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
describe Admin::OrganizationsController do
let!(:admin) { create(:admin) }
let!(:organization) { create(:organization) }
let!(:user) { create(:user) }
context 'logged in as user with no role' do
before :each do
sign_in user
end
describe 'GET #new' do
before :each do
get :new
end
it 'redirects to root' do
expect(flash[:alert]).to eq('You are not authorized to access this page.')
expect(response).to redirect_to(root_path)
end
end
describe 'GET #index' do
before :each do
get :index
end
it 'redirects to root' do
expect(flash[:alert]).to eq('You are not authorized to access this page.')
expect(response).to redirect_to(root_path)
end
end
describe 'POST #create' do
it 'does not create new organization' do
expected = expect do
post :create, params: { organization: attributes_for(:organization) }
end
expected.to_not change(Organization, :count)
end
it 'redirects to root' do
post :create, params: { organization: attributes_for(:organization) }
expect(flash[:alert]).to eq('You are not authorized to access this page.')
expect(response).to redirect_to(root_path)
end
end
describe 'PATCH #update' do
it 'does not update and redirects to root' do
old_name = organization.name
patch :update, params: { id: organization.id, organization: attributes_for(:organization, name: 'new name') }
organization.reload
expect(organization.name).to eq(old_name)
expect(flash[:alert]).to eq('You are not authorized to access this page.')
expect(response).to redirect_to(root_path)
end
end
describe 'DELETE #destroy' do
context 'for a valid organization' do
it 'does not destroy a resource' do
expected = expect do
delete :destroy, params: { id: organization.id }
end
expected.to_not change(Organization, :count)
end
it 'redirects to root' do
delete :destroy, params: { id: organization.id }
expect(flash[:alert]).to eq('You are not authorized to access this page.')
expect(response).to redirect_to(root_path)
end
end
end
end
context 'logged in as admin' do
before :each do
sign_in admin
end
describe 'GET #new' do
before do
get :new
end
it { expect(response).to render_template('new') }
end
describe 'GET #index' do
before do
get :index
end
it { expect(response).to render_template('index') }
end
describe 'POST #create' do
context 'with valid attributes' do
it 'creates new organization' do
expected = expect do
post :create, params: { organization: attributes_for(:organization) }
end
expected.to change { Organization.count }.by(1)
end
it 'redirects to index' do
post :create, params: { organization: attributes_for(:organization) }
expect(flash[:notice]).to eq('Organization successfully created')
expect(response).to redirect_to(admin_organizations_path)
end
end
context 'with invalid attributes' do
it 'does not create new organization' do
expected = expect do
post :create, params: { organization: attributes_for(:organization, name: '') }
end
expected.to_not change(Organization, :count)
end
it 'redirects to new' do
post :create, params: { organization: attributes_for(:organization, name: '') }
expect(flash[:error]).to eq("Name can't be blank")
expect(response).to redirect_to(new_admin_organization_path)
end
end
end
describe 'PATCH #update' do
it 'saves and redirects to index when the attributes are valid' do
patch :update, params: { id: organization.id, organization: attributes_for(:organization, name: 'changed name') }
organization.reload
expect(organization.name).to eq('changed name')
expect(flash[:notice]).to eq('Organization successfully updated')
expect(response).to redirect_to(admin_organizations_path)
end
it 'redirects to edit when attributes are invalid' do
patch :update, params: { id: organization.id, organization: attributes_for(:organization, name: '') }
expect(flash[:error]).to eq("Name can't be blank")
expect(response).to redirect_to(edit_admin_organization_path(organization))
end
end
describe 'DELETE #destroy' do
context 'for a valid organization' do
it 'should successfully destroy a resource' do
expected = expect do
delete :destroy, params: { id: organization.id }
end
expected.to change { Organization.count }.by(-1)
end
it 'redirects to index' do
delete :destroy, params: { id: organization.id }
expect(flash[:notice]).to eq('Organization successfully destroyed')
expect(response).to redirect_to(admin_organizations_path)
end
end
end
describe 'POST #assign_org_admins' do
let(:org_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) }
before do
post :assign_org_admins, params: { id: organization.id,
user: { email: user.email } }
end
it 'assigns organization_admin role' do
expect(user.roles).to eq [org_admin_role]
end
end
describe 'DELETE #unassign_org_admins' do
let(:org_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) }
let!(:org_admin_user) { create(:user, role_ids: [org_admin_role.id]) }
before do
delete :unassign_org_admins, params: { id: organization.id,
user: { email: org_admin_user.email } }
end
it 'unassigns organization_admin role' do
expect(org_admin_user.reload.roles).to eq []
end
end
end
end