rework roles with rolify

This commit is contained in:
Stella Rouzi 2014-07-11 18:41:35 +03:00
parent f9f840c811
commit 4af0e59ca6
40 changed files with 167 additions and 228 deletions

View file

@ -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