rework roles with rolify
This commit is contained in:
parent
f9f840c811
commit
4af0e59ca6
40 changed files with 167 additions and 228 deletions
|
|
@ -3,16 +3,14 @@ require 'spec_helper'
|
|||
describe Admin::ConferenceController do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
let(:conference) { create(:conference) }
|
||||
let(:admin) { create(:admin) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
let(:participant) { create(:participant) }
|
||||
|
||||
shared_examples 'access as administration or organizer' do
|
||||
shared_examples 'access as administration' do
|
||||
|
||||
describe 'PATCH #update' do
|
||||
|
||||
|
|
@ -27,7 +25,7 @@ describe Admin::ConferenceController do
|
|||
it 'changes conference attributes' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con',
|
||||
short_title: 'ExCon')
|
||||
short_title: 'ExCon')
|
||||
|
||||
conference.reload
|
||||
expect(conference.title).to eq('Example Con')
|
||||
|
|
@ -67,7 +65,7 @@ describe Admin::ConferenceController do
|
|||
it 'does not change conference attributes' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con',
|
||||
short_title: nil)
|
||||
short_title: nil)
|
||||
|
||||
conference.reload
|
||||
expect(flash[:alert]).
|
||||
|
|
@ -79,7 +77,7 @@ describe Admin::ConferenceController do
|
|||
it 're-renders the #show template' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con',
|
||||
short_title: nil)
|
||||
short_title: nil)
|
||||
|
||||
expect(flash[:alert]).
|
||||
to eq("Updating conference failed. Short title can't be blank.")
|
||||
|
|
@ -216,59 +214,54 @@ describe Admin::ConferenceController do
|
|||
describe 'administrator access' do
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it_behaves_like 'access as administration or organizer'
|
||||
|
||||
end
|
||||
|
||||
describe 'organizer access' do
|
||||
|
||||
before(:each) do
|
||||
sign_in(organizer)
|
||||
end
|
||||
|
||||
it_behaves_like 'access as administration or organizer'
|
||||
it_behaves_like 'access as administration'
|
||||
|
||||
end
|
||||
|
||||
shared_examples 'access as participant or guest' do |success_path|
|
||||
shared_examples 'access as participant or guest' do |path, message|
|
||||
describe 'GET #show' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
get :show, id: conference.short_title
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
get :index
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
get :new
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
post :create, conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
patch :update, id: conference.short_title,
|
||||
conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -278,13 +271,13 @@ describe Admin::ConferenceController do
|
|||
sign_in(participant)
|
||||
end
|
||||
|
||||
it_behaves_like 'access as participant or guest', :root_path
|
||||
it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this page.'
|
||||
|
||||
end
|
||||
|
||||
describe 'guest access' do
|
||||
|
||||
it_behaves_like 'access as participant or guest', :new_user_session_path
|
||||
it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this page.'
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
require 'spec_helper'
|
||||
describe Admin::UsersController do
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let(:admin) { create(:admin) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
let(:user) { create(:user) }
|
||||
before(:each) do
|
||||
sign_in(admin)
|
||||
sign_in(organizer)
|
||||
end
|
||||
describe 'GET #index' do
|
||||
it 'populates an array of users' do
|
||||
user1 = create(:user, email: 'gopesh.7500@gmail.com')
|
||||
user2 = create(:user, email: 'gopesh_750@gmail.com')
|
||||
get :index
|
||||
expect(assigns(:users)).to match_array([user, admin, user1, user2])
|
||||
expect(assigns(:users)).to match_array([user, organizer, user1, user2])
|
||||
end
|
||||
it 'renders index template' do
|
||||
get :index
|
||||
|
|
@ -31,13 +31,13 @@ describe Admin::UsersController do
|
|||
:user, email: 'example@incoherent.de', id: user.id).email).
|
||||
to eq('example@incoherent.de')
|
||||
end
|
||||
it "redirects to the updated user" do
|
||||
it 'redirects to the updated user' do
|
||||
patch :update, id: user.id
|
||||
expect(response).to redirect_to admin_users_path
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'DELETE #destroy' do
|
||||
describe 'DELETE #destroy' do
|
||||
before :each do
|
||||
@user = create(:user)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue