Implement role authorization

This commit is contained in:
Stella Rouzi 2014-08-12 11:51:59 +03:00
parent 6755328c4c
commit e2fb434dc7
122 changed files with 1386 additions and 751 deletions

View file

@ -3,16 +3,15 @@ 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(:conference) { create(:conference) }
let(:admin) { create(:admin) }
let(:organizer) { create(:organizer) }
let!(:first_user) { create(:user) }
let!(:participant_role) { create(:participant_role) }
let!(:organizer_role) { create(:role, name: 'organizer', resource: conference) }
let(:organizer) { create(:user, role_ids: organizer_role.id, is_admin: true) }
let(:participant) { create(:participant) }
shared_examples 'access as administration or organizer' do
shared_examples 'access as administration' do
describe 'PATCH #update' do
@ -45,8 +44,7 @@ describe Admin::ConferenceController do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, id: conference.short_title, conference:
attributes_for(:conference, start_date: Date.today + 2.days, end_date: Date.today + 4.days)
patch :update, id: conference.short_title#, conference: attributes_for(:conference, start_date: Date.today + 2.days, end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_date_update_mail).and_return(mailer)
end
@ -193,8 +191,12 @@ describe Admin::ConferenceController do
context 'no conferences' do
it 'redirect to new conference' do
Conference.all.each do |c|
c.destroy
end
sign_in create(:admin)
get :index
expect(response).to redirect_to(redirect_to new_admin_conference_path)
expect(response).to redirect_to new_admin_conference_path
end
end
end
@ -215,59 +217,64 @@ 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))
if message
expect(flash[:alert]).to match(/#{message}/)
end
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))
if message
expect(flash[:alert]).to match(/#{message}/)
end
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))
if message
expect(flash[:alert]).to match(/#{message}/)
end
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))
if message
expect(flash[:alert]).to match(/#{message}/)
end
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))
expect(response).to redirect_to(send(path))
if message
expect(flash[:alert]).to match(/#{message}/)
end
end
end
end
@ -277,7 +284,7 @@ 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 area!'
end

View file

@ -1,7 +1,5 @@
require 'spec_helper'
describe Admin::UsersController do
let!(:admin_role) { create(:admin_role) }
let!(:participant_role) { create(:participant_role) }
let(:admin) { create(:admin) }
let(:user) { create(:user) }
before(:each) do
@ -31,13 +29,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

View file

@ -1,7 +1,8 @@
require 'spec_helper'
describe ConferenceController do
let(:conference) { create(:conference) }
let(:conference) { create(:conference, make_conference_public: true) }
describe 'GET #show' do
context 'conference made public' do
it 'assigns the requested conference to conference' do
@ -24,7 +25,7 @@ describe ConferenceController do
it 'renders flash saying conference not ready' do
get :show, id: conference.short_title
expect(flash[:notice]).to eq("Conference not ready yet!!")
expect(flash[:alert]).to eq('You are not authorized to access this page.')
end
end
context 'gallery photos for splash' do

View file

@ -0,0 +1,8 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :commercial do
commercial_type 'YouTube'
commercial_id 'test'
end
end

View file

@ -1,16 +1,18 @@
FactoryGirl.define do
factory :role do
factory :admin_role do
name 'Admin'
factory :participant_role do
name 'participant'
end
factory :organizer_role do
name 'Organizer'
name 'organizer'
end
factory :participant_role do
name 'Participant'
factory :organizer_conference_1_role do
name 'organizer'
resource_type 'Conference'
resource_id 1
end
end
end

View file

@ -19,12 +19,12 @@ FactoryGirl.define do
after(:create) { |user| user.role_ids = create(:participant_role).id }
end
factory :admin do
after(:create) { |user| user.role_ids = create(:admin_role).id }
factory :organizer_conference_1 do
after(:create) { |user| user.role_ids = create(:organizer_conference_1_role).id }
end
factory :organizer do
after(:create) { |user| user.role_ids = create(:organizer_role).id }
factory :admin do
is_admin true
end
end
end

View file

@ -0,0 +1,266 @@
require 'spec_helper'
feature 'Has correct abilities' do
# It is necessary to use bang version of let to build roles before user
let(:conference1) { create(:conference) } # user is organizer
let(:conference2) { create(:conference) } # user is cfp
let(:conference3) { create(:conference) } # user is info_desk
let(:conference4) { create(:conference) } # user is volunteer coordinator
let(:conference5) { create(:conference) } # user has no role
let(:role_organizer) { create(:role, name: 'organizer', resource: conference1) }
let(:role_cfp) { create(:role, name: 'cfp', resource: conference2) }
let(:role_info_desk) { create(:role, name: 'info_desk', resource: conference3) }
let(:role_volunteer_coordinator) { create(:role, name: 'volunteer_coordinator', resource: conference4) }
let(:user) { create(:user, role_ids: [role_organizer.id, role_cfp.id, role_info_desk.id, role_volunteer_coordinator.id]) }
scenario 'when user is organizer' do
sign_in user
visit admin_conference_path(conference1.short_title)
expect(page.has_content?('Settings')).to be true
expect(page.has_content?('Manage')).to be true
expect(page.has_content?('Registrations')).to be true
expect(page.has_content?('Events')).to be true
expect(page.has_content?('Schedule')).to be true
expect(page.has_content?('Campaigns')).to be true
expect(page.has_content?('Targets')).to be true
expect(page.has_content?('Venue')).to be true
expect(page.has_content?('Sponsorship')).to be true
expect(page.has_content?('Supporter Levels')).to be true
expect(page.has_content?('E-Mails')).to be true
expect(page.has_content?('Call for papers')).to be true
expect(page.has_content?('Questions')).to be true
expect(page.has_content?('Commercials')).to be true
visit edit_admin_conference_path(conference1.short_title)
expect(current_path).to eq(edit_admin_conference_path(conference1.short_title))
visit admin_conference_path(conference1.short_title)
expect(current_path).to eq(admin_conference_path(conference1.short_title))
visit admin_conference_registrations_path(conference1.short_title)
expect(current_path).to eq(admin_conference_registrations_path(conference1.short_title))
visit admin_conference_events_path(conference1.short_title)
expect(current_path).to eq(admin_conference_events_path(conference1.short_title))
visit admin_conference_schedule_path(conference1.short_title)
expect(current_path).to eq(admin_conference_schedule_path(conference1.short_title))
visit admin_conference_campaigns_path(conference1.short_title)
expect(current_path).to eq(admin_conference_campaigns_path(conference1.short_title))
visit admin_conference_targets_path(conference1.short_title)
expect(current_path).to eq(admin_conference_targets_path(conference1.short_title))
visit admin_conference_venue_info_path(conference1.short_title)
expect(current_path).to eq(admin_conference_venue_info_path(conference1.short_title))
visit admin_conference_sponsorship_levels_path(conference1.short_title)
expect(current_path).to eq(admin_conference_sponsorship_levels_path(conference1.short_title))
visit admin_conference_supporter_levels_path(conference1.short_title)
expect(current_path).to eq(admin_conference_supporter_levels_path(conference1.short_title))
visit admin_conference_emails_path(conference1.short_title)
expect(current_path).to eq(admin_conference_emails_path(conference1.short_title))
visit admin_conference_callforpapers_path(conference1.short_title)
expect(current_path).to eq(admin_conference_callforpapers_path(conference1.short_title))
visit admin_conference_questions_path(conference1.short_title)
expect(current_path).to eq(admin_conference_questions_path(conference1.short_title))
visit admin_conference_commercials_path(conference1.short_title)
expect(current_path).to eq(admin_conference_commercials_path(conference1.short_title))
end
scenario 'when user is cfp' do
sign_in user
visit admin_conference_path(conference2.short_title)
expect(page.has_content?('Settings')).to be false
expect(page.has_content?('Manage')).to be true
# expect(page.has_content?('Registrations')).to be false
expect(page.has_content?('Events')).to be true
expect(page.has_content?('Schedule')).to be true
# expect(page.has_content?('Campaigns')).to be false
expect(page.has_content?('Targets')).to be false
expect(page.has_content?('Venue')).to be true
expect(page.has_content?('Sponsorship')).to be false
expect(page.has_content?('Supporter Levels')).to be false
expect(page.has_content?('E-Mails')).to be true
expect(page.has_content?('Call for papers')).to be true
expect(page.has_content?('Questions')).to be false
expect(page.has_content?('Commercials')).to be true
visit edit_admin_conference_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_path(conference2.short_title)
expect(current_path).to eq(admin_conference_path(conference2.short_title))
visit admin_conference_registrations_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_events_path(conference2.short_title)
expect(current_path).to eq(admin_conference_events_path(conference2.short_title))
visit admin_conference_schedule_path(conference2.short_title)
expect(current_path).to eq(admin_conference_schedule_path(conference2.short_title))
visit admin_conference_campaigns_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_targets_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_venue_info_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_sponsorship_levels_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_supporter_levels_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_emails_path(conference2.short_title)
expect(current_path).to eq(admin_conference_emails_path(conference2.short_title))
visit admin_conference_callforpapers_path(conference2.short_title)
expect(current_path).to eq(admin_conference_callforpapers_path(conference2.short_title))
visit admin_conference_questions_path(conference2.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_commercials_path(conference3.short_title)
expect(current_path).to eq(admin_conference_commercials_path(conference3.short_title))
end
scenario 'when user is info desk' do
sign_in user
visit admin_conference_path(conference3.short_title)
expect(page.has_content?('Settings')).to be false
expect(page.has_content?('Manage')).to be true
expect(page.has_content?('Registrations')).to be true
expect(page.has_content?('Events')).to be false
expect(page.has_content?('Schedule')).to be false
# expect(page.has_content?('Campaigns')).to be false
expect(page.has_content?('Targets')).to be false
expect(page.has_content?('Venue')).to be false
expect(page.has_content?('Sponsorship')).to be false
expect(page.has_content?('Supporter Levels')).to be false
expect(page.has_content?('E-Mails')).to be false
expect(page.has_content?('Call for papers')).to be false
expect(page.has_content?('Questions')).to be true
expect(page.has_content?('Commercials')).to be true
visit edit_admin_conference_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_path(conference3.short_title)
expect(current_path).to eq(admin_conference_path(conference3.short_title))
visit admin_conference_registrations_path(conference3.short_title)
expect(current_path).to eq(admin_conference_registrations_path(conference3.short_title))
visit admin_conference_events_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_schedule_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_campaigns_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_targets_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_venue_info_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_sponsorship_levels_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_supporter_levels_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_emails_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_callforpapers_path(conference3.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_questions_path(conference3.short_title)
expect(current_path).to eq(admin_conference_questions_path(conference3.short_title))
visit admin_conference_commercials_path(conference3.short_title)
expect(current_path).to eq(admin_conference_commercials_path(conference3.short_title))
end
scenario 'when user is volunteer coordinator' do
sign_in user
visit admin_conference_path(conference4.short_title)
expect(page.has_content?('Settings')).to be false
expect(page.has_content?('Manage')).to be true
# expect(page.has_content?('Registrations')).to be false
expect(page.has_content?('Events')).to be false
expect(page.has_content?('Schedule')).to be false
# expect(page.has_content?('Campaigns')).to be false
expect(page.has_content?('Targets')).to be false
expect(page.has_content?('Venue')).to be false
expect(page.has_content?('Sponsorship')).to be false
expect(page.has_content?('Supporter Levels')).to be false
expect(page.has_content?('E-Mails')).to be false
expect(page.has_content?('Call for papers')).to be false
expect(page.has_content?('Questions')).to be false
expect(page.has_content?('Commercials')).to be true
visit edit_admin_conference_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_path(conference4.short_title)
expect(current_path).to eq(admin_conference_path(conference4.short_title))
visit admin_conference_registrations_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_events_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_schedule_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_campaigns_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_targets_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_venue_info_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_sponsorship_levels_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_supporter_levels_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_emails_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_callforpapers_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_questions_path(conference4.short_title)
expect(current_path).to eq(root_path)
visit admin_conference_commercials_path(conference3.short_title)
expect(current_path).to eq(admin_conference_commercials_path(conference3.short_title))
end
end

View file

@ -3,9 +3,8 @@ require 'spec_helper'
feature Campaign 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'add and update campaign' do |user|
scenario 'adds and update a campaign', feature: true, js: true do
@ -42,7 +41,7 @@ feature Campaign do
expect(Campaign.count).to eq(expected_count)
campaign = Campaign.where('name'=> 'Test Campaign').first
campaign = Campaign.where('name' => 'Test Campaign').first
visit edit_admin_conference_campaign_path(conference.short_title, campaign.id)
fill_in 'campaign_name', with: 'Test Campaign 42'
@ -52,8 +51,7 @@ feature Campaign do
end
end
describe 'admin' do
it_behaves_like 'add and update campaign', :admin
it_behaves_like 'add and update campaign', :organizer
describe 'organizer' do
it_behaves_like 'add and update campaign', :organizer_conference_1
end
end

View file

@ -3,9 +3,8 @@ require 'spec_helper'
feature Conference 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'add and update cfp' do |user|
scenario 'adds a new cfp', feature: true, js: true do
@ -87,8 +86,7 @@ feature Conference do
end
end
describe 'admin' do
it_behaves_like 'add and update cfp', :admin
it_behaves_like 'add and update cfp', :organizer
describe 'organizer' do
it_behaves_like 'add and update cfp', :organizer_conference_1
end
end

View file

@ -2,18 +2,17 @@ require 'spec_helper'
feature Commercial 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!(:conference) { create(:conference) }
let!(:organizer_role) { create(:role, name: 'organizer', resource: conference) }
let!(:organizer) { create(:user, role_ids: [organizer_role.id]) }
shared_examples 'adds and updates a commercial' do |user|
shared_examples 'adds and updates a commercial' do
scenario 'of a conference',
feature: true, js: true do
conference = create(:conference)
expected_count = conference.commercials.count + 1
sign_in create(user)
sign_in organizer
visit admin_conference_commercials_path(conference.short_title)
@ -61,11 +60,7 @@ feature Commercial do
end
end
describe 'admin' do
it_behaves_like 'adds and updates a commercial', :admin
end
describe 'organizer' do
it_behaves_like 'adds and updates a commercial', :organizer
it_behaves_like 'adds and updates a commercial'
end
end

View file

@ -3,9 +3,8 @@ require 'spec_helper'
feature Conference 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'add and update conference' do |user|
scenario 'adds a new conference', feature: true, js: true do
@ -36,7 +35,7 @@ feature Conference do
scenario 'update conference', feature: true, js: true do
conference = create(:conference)
expected_count = Conference.count
sign_in create(user)
sign_in create(:organizer_conference_1)
visit edit_admin_conference_path(conference.short_title)
click_link 'Edit'
@ -65,9 +64,4 @@ feature Conference do
describe 'admin' do
it_behaves_like 'add and update conference', :admin
end
describe 'organizer' do
it_behaves_like 'add and update conference', :organizer
end
end

View file

@ -2,9 +2,8 @@ require 'spec_helper'
feature DifficultyLevel 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'difficulty levels' do |user|
scenario 'adds and updates difficulty level', feature: true, js: true do
@ -50,11 +49,7 @@ feature DifficultyLevel do
end
end
describe 'admin' do
it_behaves_like 'difficulty levels', :admin
end
describe 'organizer' do
it_behaves_like 'difficulty levels', :organizer
it_behaves_like 'difficulty levels', :organizer_conference_1
end
end

View file

@ -2,9 +2,8 @@ require 'spec_helper'
feature EmailSettings 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'email settings' do |user|
scenario 'updates email settings',
@ -91,11 +90,7 @@ feature EmailSettings do
end
end
describe 'admin' do
it_behaves_like 'email settings', :admin
end
describe 'organizer' do
it_behaves_like 'email settings', :organizer
it_behaves_like 'email settings', :organizer_conference_1
end
end

View file

@ -2,18 +2,17 @@ require 'spec_helper'
feature EventType 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'event types' do |user|
scenario 'adds and updates event type', feature: true, js: true do
conference = create(:conference)
sign_in create(user)
visit admin_conference_eventtypes_path(
visit admin_conference_event_types_path(
conference_id: conference.short_title)
expect(page.all('div.nested-fields').count == 2).to be true
expect(page.all('div.nested-fields').count == 2).to be true
# Add event type
click_link 'Add event_type'
expect(page.all('div.nested-fields').count == 3).to be true
@ -55,11 +54,7 @@ feature EventType do
end
end
describe 'admin' do
it_behaves_like 'event types', :admin
end
describe 'organizer' do
it_behaves_like 'event types', :organizer
it_behaves_like 'event types', :organizer_conference_1
end
end

View file

@ -2,9 +2,8 @@ require 'spec_helper'
feature Lodging 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'lodgings' do |user|
scenario 'adds and updates lodgings', feature: true, js: true do
@ -56,11 +55,7 @@ feature Lodging do
end
end
describe 'admin' do
it_behaves_like 'lodgings', :admin
end
describe 'organizer' do
it_behaves_like 'lodgings', :organizer
it_behaves_like 'lodgings', :organizer_conference_1
end
end

View file

@ -2,7 +2,6 @@ require 'spec_helper'
feature Openid do
let!(:participant_role) { create(:participant_role) }
let!(:admin_role) { create(:admin_role) }
shared_examples 'sign in with openid' do

View file

@ -2,16 +2,15 @@ require 'spec_helper'
feature Event 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'proposal workflow' do
scenario 'submitts a proposal, accepts and confirms',
feature: true, js: true do
admin = create(:admin, email: 'admin@example.com')
participant = create(:participant, email: 'participant@example.com', biography: "")
organizer = create(:organizer_conference_1, email: 'admin@example.com')
participant = create(:user, email: 'participant@example.com', biography: '')
expected_count = Event.count + 1
conference = create(:conference)
@ -38,7 +37,7 @@ feature Event do
click_button 'Create Event'
expect(flash).to eq('Event was successfully submitted. You should register for the conference now.')
expect(current_path).to eq(register_conference_path(conference.short_title))
expect(current_path).to eq(conference_register_path(conference.short_title))
expect(Event.count).to eq(expected_count)
@ -99,7 +98,7 @@ feature Event do
expect(event.commercials.count).to eq(expected_count_commercial - 1)
sign_out
sign_in admin
sign_in organizer
# Reject proposal
visit admin_conference_events_path(conference.short_title)

View file

@ -2,9 +2,8 @@ require 'spec_helper'
feature Room 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'rooms' do |user|
scenario 'adds and updates rooms', feature: true, js: true do
@ -43,11 +42,7 @@ feature Room do
end
end
describe 'admin' do
it_behaves_like 'rooms', :admin
end
describe 'organizer' do
it_behaves_like 'rooms', :organizer
it_behaves_like 'rooms', :organizer_conference_1
end
end

View file

@ -2,9 +2,8 @@ require 'spec_helper'
feature Sponsor 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'sponsors' do |user|
scenario 'adds and updates sponsors', feature: true, js: true do
@ -69,11 +68,7 @@ feature Sponsor do
end
end
describe 'admin' do
it_behaves_like 'sponsors', :admin
end
describe 'organizer' do
it_behaves_like 'sponsors', :organizer
it_behaves_like 'sponsors', :organizer_conference_1
end
end

View file

@ -1,10 +1,9 @@
require 'spec_helper'
feature SponsorshipLevel do
# It is necessary to use bang version of let to build roles before user
let!(:organizer_role) { create(:organizer_role) }
# It is necessary to use bang version of let to build roles before user
let!(:participant_role) { create(:participant_role) }
let!(:admin_role) { create(:admin_role) }
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'sponsorship levels' do |user|
scenario 'adds and updates sponsorship level', feature: true, js: true do
@ -36,11 +35,7 @@ feature SponsorshipLevel do
end
end
describe 'admin' do
it_behaves_like 'sponsorship levels', :admin
end
describe 'organizer' do
it_behaves_like 'sponsorship levels', :organizer
it_behaves_like 'sponsorship levels', :organizer_conference_1
end
end

View file

@ -1,17 +1,14 @@
require 'spec_helper'
feature SupporterLevel 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!(:conference) { create(:conference) }
let!(:organizer_role) { create(:organizer_role, resource: conference) }
let!(:user) { create(:user, role_ids: [organizer_role.id]) }
shared_examples 'supporter levels' do |user|
shared_examples 'supporter levels' do
scenario 'adds and updates supporter level', feature: true, js: true do
conference = create(:conference)
sign_in create(user)
visit admin_conference_supporter_levels_path(
conference_id: conference.short_title)
sign_in user
visit admin_conference_supporter_levels_path(conference_id: conference.short_title)
# Add supporter level
click_link 'Add supporter_level'
@ -43,11 +40,7 @@ feature SupporterLevel do
end
end
describe 'admin' do
it_behaves_like 'supporter levels', :admin
end
describe 'organizer' do
it_behaves_like 'supporter levels', :organizer
it_behaves_like 'supporter levels'
end
end

View file

@ -2,9 +2,8 @@ require 'spec_helper'
feature Track 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_conference_1_role) { create(:organizer_conference_1_role) }
shared_examples 'tracks' do |user|
scenario 'adds and updates tracks', feature: true, js: true do
@ -50,11 +49,7 @@ feature Track do
end
end
describe 'admin' do
it_behaves_like 'tracks', :admin
end
describe 'organizer' do
it_behaves_like 'tracks', :organizer
it_behaves_like 'tracks', :organizer_conference_1
end
end

View file

@ -1,14 +1,10 @@
require 'spec_helper'
feature User 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(:admin) { create(:admin) }
shared_examples 'admin ability' do
scenario 'deletes a user', feature: true, js: true do
sign_in(admin)
sign_in(create(:admin))
visit admin_users_path
expected_count = User.count - 1
page.all('btn btn-primary btn-danger') do
@ -20,20 +16,6 @@ feature User do
end
sign_out
end
scenario 'can modify roles', feature: true, js: true do
@user = create(:user)
sign_in(admin)
visit admin_users_path
find("#user-modify-role-#{@user.id}").click
if find("#user-role-selection-#{@user.id}").visible?
page.find('#user_role_ids').find(:xpath, 'option[2]').select_option do
find('#user_submit_action').click
expect(flash).to eq("Updated #{@user.email}")
expect(@user.role_ids).to match_array([2])
end
end
sign_out
end
end
describe 'admin' do

View file

@ -3,9 +3,8 @@ require 'spec_helper'
feature Conference 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_conference_1_role) }
shared_examples 'venue' do |user|
scenario 'adds and updates venue' do
@ -59,12 +58,8 @@ feature Conference do
end
end
describe 'admin' do
it_behaves_like 'venue', :admin
end
describe 'organizer' do
it_behaves_like 'venue', :organizer
it_behaves_like 'venue', :organizer_conference_1
end
end

View file

@ -2,15 +2,14 @@ require 'spec_helper'
feature Conference 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(:admin) { create(:admin) }
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
let(:organizer) { create(:organizer_conference_1) }
let(:conference) { create(:conference) }
shared_examples 'volunteer' do
scenario 'adds and updates vdays', feature: true, js: true do
sign_in(admin)
sign_in(organizer)
visit admin_conference_volunteers_info_path(
conference_id: conference.short_title)
check('Enable Volunteering')
@ -54,7 +53,7 @@ feature Conference do
end
scenario 'adds and updates vpositions', feature: true, js: true do
sign_in(admin)
sign_in(organizer)
visit admin_conference_volunteers_info_path(
conference_id: conference.short_title)
@ -119,10 +118,6 @@ feature Conference do
end
end
describe 'admin' do
it_behaves_like 'volunteer', :admin
end
describe 'organizer' do
it_behaves_like 'volunteer', :organizer
end

View file

@ -1,39 +1,163 @@
require 'spec_helper'
require "cancan/matchers"
require 'cancan/matchers'
describe "User" do
describe "abilities" do
describe 'User' do
describe 'Abilities' do
subject(:ability){ Ability.new(user) }
let!(:first_user) { create(:user) } # automatically becomes admin
let(:user){ nil }
let(:conference_not_public) { create(:conference, make_conference_public: false) }
let(:conference_public) { create(:conference, make_conference_public: true)}
let(:event_confirmed) { create(:event, state: 'confirmed') }
let(:someevent) { create(:event) }
context "when is an admin" do
let!(:user) { create(:admin) }
context 'when user is a guest' do # Test abilities for guest users
it{ should be_able_to(:manage, Event.new) }
it{ should be_able_to(:show, conference_public)}
it{ should_not be_able_to(:show, conference_not_public)}
it{ should be_able_to(:show, event_confirmed)}
it{ should_not be_able_to(:show, someevent)}
it{ should be_able_to(:index, :schedule)}
it{ should_not be_able_to(:create, Event)}
it{ should_not be_able_to(:manage, Event)}
it{ should_not be_able_to(:manage, Conference)}
it{ should_not be_able_to(:manage, :any)}
end
context "when is an participant" do
let(:user) { build(:participant) }
context 'when user is a Signed In User' do # Test abilities for signed in users (without any role)
let(:user) { create(:participant) }
let(:registration1) { create(:registration, conference: conference_public, user: user) }
let(:registration2) { create(:registration, conference: conference_not_public, user: user) }
it{ should be_able_to(:create, Event) }
it{ should be_able_to(:index, Event) }
it{ should_not be_able_to(:manage, Event.new) }
it{ should be_able_to(:create, Event.new) }
it{ should be_able_to(:read, Event.new) }
it{ should be_able_to(:show, event_confirmed) }
it{ should be_able_to(:manage, registration1) }
it{ should be_able_to(:manage, registration2) }
it{ should be_able_to(:show, conference_public)}
it{ should_not be_able_to(:show, conference_not_public)}
it{ should_not be_able_to(:manage, Conference) }
end
context "when is an event owner" do
context 'user #is_admin?' do
let(:user) { create(:admin) }
it{ should be_able_to(:manage, User) }
it{ should be_able_to(:create, Conference) }
end
context 'signed in users can manage their events' do
let(:user) { create(:participant) }
let(:user2) { create(:participant) }
let(:myevent) { create(:event, users: [user]) }
let(:someevent) { create(:event, users: [user2]) }
let(:commercial_myevent) { create(:commercial, commercialable: myevent) }
let(:commercial_someevent) { create(:commercial, commercialable: someevent) }
# Users are able to update and destroy their own events
it{ should be_able_to(:update, myevent) }
it{ should be_able_to(:destroy, myevent) }
it{ should be_able_to(:manage, myevent) }
it{ should be_able_to(:create, myevent.commercials.new) }
it{ should be_able_to(:manage, commercial_myevent) }
# Users are not able to update and destroy other users events
it{ should_not be_able_to(:update, someevent) }
it{ should_not be_able_to(:destroy, someevent) }
it{ should_not be_able_to(:manage, someevent) }
it{ should_not be_able_to(:manage, commercial_someevent) }
end
context 'when user is an organizer' do
let!(:conference1) { create(:conference) }
let!(:conference2) { create(:conference) }
let(:role) { create(:organizer_role, resource: conference1) }
let(:user) { create(:user, role_ids: [role.id]) }
let(:someuser) { create(:user) }
let(:registration1) { create(:registration, user: someuser, conference_id: conference1.id) }
it{ should be_able_to(:manage, conference1) }
it{ should_not be_able_to(:manage, conference2) }
it{ should be_able_to(:manage, registration1) }
it{ should be_able_to(:create, Registration) }
end
context 'when user is part of cfp' do
let!(:conference1) { create(:conference) }
let!(:conference2) { create(:conference) }
let(:role) { create(:role, name: 'cfp', resource: conference1) }
let(:user) { create(:user, role_ids: role.id) }
let(:event) { create(:event, conference_id: conference1.id) }
let(:someevent) { create(:event, conference_id: conference2.id) }
let(:cfp) { create(:call_for_papers, conference: conference1) }
it{ should_not be_able_to(:manage, conference1) }
it{ should_not be_able_to(:manage, conference2) }
it{ should be_able_to(:index, conference1) }
it{ should be_able_to(:show, conference1) }
it{ should be_able_to(:manage, event) }
it{ should_not be_able_to(:manage, someevent) }
it{ should be_able_to(:manage, cfp) }
it{ should be_able_to(:manage, create(:event_type, conference: conference1)) }
end
context 'when user has multiple roles' do
let!(:conference1) { create(:conference) } # user is organizer
let!(:conference2) { create(:conference) } # user is cfp
let!(:conference3) { create(:conference) } # user is info_desk
let!(:conference4) { create(:conference) } # user is volunteer coordinator
let!(:conference5) { create(:conference, make_conference_public: true) } # user has no role
let!(:conference6) { create(:conference, make_conference_public: false) } # user has no role
let(:role_organizer) { create(:role, name: 'organizer', resource: conference1) }
let(:role_cfp) { create(:role, name: 'cfp', resource: conference2) }
let(:role_info_desk) { create(:role, name: 'info_desk', resource: conference3) }
let(:role_volunteer_coordinator) { create(:role, name: 'volunteer_coordinator', resource: conference4) }
let(:user) { create(:user, role_ids: [role_cfp.id, role_organizer.id, role_cfp.id, role_info_desk.id, role_volunteer_coordinator.id]) }
let(:admin) { create(:admin) }
it{ should be_able_to(:manage, conference1) }
it{ should_not be_able_to(:update, conference2) }
it{ should_not be_able_to(:update, conference3) }
it{ should_not be_able_to(:update, conference4) }
it{ should_not be_able_to(:update, conference5) }
it{ should be_able_to(:show, conference1) }
it{ should be_able_to(:show, conference2) }
it{ should be_able_to(:show, conference3) }
it{ should be_able_to(:show, conference4) }
it{ should be_able_to(:show, conference5) }
it{ should be_able_to(:show, conference6) }
it{ should be_able_to(:manage, conference1.venue) }
it{ should_not be_able_to(:manage, conference2.venue) }
it{ should_not be_able_to(:manage, conference3.venue) }
it{ should_not be_able_to(:manage, conference4.venue) }
it{ should_not be_able_to(:manage, conference5.venue) }
it{ should be_able_to(:manage, conference1.registrations.new) }
it{ should_not be_able_to(:manage, conference2.registrations.new) }
it{ should be_able_to(:manage, conference3.registrations.new) }
it{ should_not be_able_to(:manage, conference4.registrations.new) }
it{ should_not be_able_to(:manage, conference5.registrations.new) }
it{ should be_able_to(:manage, conference1.events.new) }
it{ should be_able_to(:manage, conference2.events.new) }
it{ should_not be_able_to(:manage, conference3.events.new) }
it{ should_not be_able_to(:manage, conference4.events.new) }
it{ should_not be_able_to(:manage, conference5.events.new) }
it{ should be_able_to(:manage, Question.new(conference_id: conference1.id)) }
it{ should_not be_able_to(:manage, Question.new(conference_id: conference2.id)) }
it{ should be_able_to(:manage, Question.new(conference_id: conference3.id)) }
it{ should_not be_able_to(:manage, Question.new(conference_id: conference4.id)) }
it{ should_not be_able_to(:manage, Question.new(conference_id: conference5.id)) }
end
end
end

View file

@ -274,9 +274,8 @@ describe Conference do
describe '#get_top_submitter' 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_conference_1_role) { create(:organizer_conference_1_role) }
it 'calculates correct hash with top submitters' do
event = create(:event, conference: subject)
@ -307,7 +306,7 @@ describe Conference do
target = build(:target, target_count: 10, unit: Target.units[:registrations])
subject.targets = [target]
result = {
"10 Registrations by #{target.due_date}" => '0'
"10 Registrations by #{target.due_date}" => '0'
}
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
end
@ -317,7 +316,7 @@ describe Conference do
subject.targets = [target]
subject.registrations = [create(:registration)]
result = {
"10 Registrations by #{target.due_date}" => '10'
"10 Registrations by #{target.due_date}" => '10'
}
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
end
@ -330,7 +329,7 @@ describe Conference do
target = build(:target, target_count: 10, unit: Target.units[:submissions])
subject.targets = [target]
result = {
"10 Submissions by #{target.due_date}" => '0'
"10 Submissions by #{target.due_date}" => '0'
}
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
end
@ -340,7 +339,7 @@ describe Conference do
subject.targets = [target]
subject.events = [create(:event)]
result = {
"10 Submissions by #{target.due_date}" => '10'
"10 Submissions by #{target.due_date}" => '10'
}
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
end
@ -349,7 +348,7 @@ describe Conference do
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
subject.targets = [target]
result = {
"300 Program minutes by #{target.due_date}" => '0'
"300 Program minutes by #{target.due_date}" => '0'
}
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
end
@ -359,7 +358,7 @@ describe Conference do
subject.targets = [target]
subject.events = [create(:event)]
result = {
"300 Program minutes by #{target.due_date}" => '10'
"300 Program minutes by #{target.due_date}" => '10'
}
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
end
@ -897,9 +896,8 @@ describe Conference do
describe 'self#event_distribution' 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_conference_1_role) { create(:organizer_conference_1_role) }
it 'self#event_distribution calculates correct values with user' do
create(:user, last_sign_in_at: Date.today - 3.months) # active
@ -1426,9 +1424,8 @@ describe Conference do
describe '#user_registered?' 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_conference_1_role) { create(:organizer_conference_1_role) }
let(:user) { create(:user) }

View file

@ -3,66 +3,55 @@ require 'spec_helper'
describe User 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!(:admin) { create(:user) }
let!(:admin) { create(:admin) }
let!(:participant) { create(:participant) }
let!(:organizer_conference_1) { create(:organizer_conference_1 ) }
let!(:organizer_conference_1_role) { Role.where(resource_type: 'Conference', resource_id: 1).first }
it 'returns the correct role' do
participant = create(:user, email: 'participant@example.de')
expect(admin.roles.first).to eq(admin_role)
expect(participant.roles.first).to eq(participant_role)
expect(organizer_conference_1.roles.first).to eq(organizer_conference_1_role)
end
it 'returns the correct roles' do
roles = [organizer_role.id, participant_role.id, admin_role.id]
participant_role = create(:participant_role)
roles = [participant_role.id, organizer_conference_1_role.id]
user_with_all_roles = create(:user, email: 'participant@example.de')
user_with_all_roles.role_ids = roles
user_with_all_roles.save
expect(user_with_all_roles.roles.length).to eq(3)
expect(user_with_all_roles.roles.length).to eq(2)
expect(user_with_all_roles.roles[0]).to eq(participant_role)
expect(user_with_all_roles.roles[1]).to eq(organizer_role)
expect(user_with_all_roles.roles[2]).to eq(admin_role)
expect(user_with_all_roles.roles[1]).to eq(organizer_conference_1_role )
end
describe '#role?' do
describe '#has_role?' do
shared_examples '#role?' do |user, role, expected|
it "returns #{expected} for #{role}" do
user_obj = create(user, email: 'e@example.com')
expect(user_obj.role?(role)).to be expected
expect(user_obj.role?(role.downcase)).to be expected
expect(user_obj.role?(role.upcase)).to be expected
expect(user_obj.role?(role.downcase.capitalize)).to be expected
end
end
context 'admin' do
it_behaves_like '#role?', :admin, 'orgAnizer', false
it_behaves_like '#role?', :admin, 'adMin', true
it_behaves_like '#role?', :admin, 'partiCipant', false
it 'assigns first user admin role' do
expect(admin.role?('Admin')).to be true
expect(admin.role_ids).to match_array([admin_role.id])
end
end
context 'participant' do
it_behaves_like '#role?', :participant, 'orgAnizer', false
it_behaves_like '#role?', :participant, 'adMin', false
it_behaves_like '#role?', :participant, 'partiCipant', true
it 'assigns second user participant role' do
participant = create(:user, email: 'participant@example.de')
expect(participant.role_ids).to match_array([participant_role.id])
expect(user_obj.has_role?(role.downcase, :any)).to be expected
end
end
context 'organizer' do
it_behaves_like '#role?', :organizer, 'orgAnizer', true
it_behaves_like '#role?', :organizer, 'adMin', false
it_behaves_like '#role?', :organizer, 'partiCipant', false
it_behaves_like '#role?', :organizer_conference_1, 'organizer', true
it_behaves_like '#role?', :organizer_conference_1, 'participant', false
end
context 'admin' do
it 'assigns first user admin role' do
expect(User.first.is_admin).to be true
expect(admin.is_admin).to eq(true)
end
end
context 'participant' do
it_behaves_like '#role?', :participant, 'adMin', false
it_behaves_like '#role?', :participant, 'participant', true
# it 'assigns second user participant role' do
# participant = create(:user, email: 'participant@example.de')
# expect(participant.role_ids).to match_array([participant_role.id])
# end
end
end
end

View file

@ -2,7 +2,7 @@ module Sidebar
def sidebar
@conference = create(:conference)
assign :conference, @conference
render
render
expect(view).to render_template('admin/conference/_sidebar')
end
end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe 'admin/conference/edit' do
it 'renders conference details which are editable' do
@conference = create(:conference, title: 'OpenSUSE')
@conference = create(:conference, title: 'openSUSE')
assign :conference, @conference
render template: 'admin/conference/edit.html.haml'
expect(rendered).to include('OpenSUSE')

View file

@ -2,9 +2,9 @@ require 'spec_helper'
describe 'admin/conference/index' do
it 'renders all conference names with links' do
assign(:conferences, [create(:conference, title: 'OpenSUSE'), create(:conference)])
assign(:conferences, [create(:conference, title: 'openSUSE'), create(:conference)])
render
expect(rendered).to include('OpenSUSE')
expect(rendered).to include("The dog and pony show")
expect(rendered).to include('openSUSE')
expect(rendered).to include('The dog and pony show')
end
end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe 'admin/conference/show' do
it 'renders conference dashboard' do
conference = create(:conference, title: 'OpenSUSE')
conference = create(:conference, title: 'openSUSE')
assign :conference, conference
assign :conference_progress, conference.get_status
render

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'admin/eventtypes/index' do
describe 'admin/event_types/index' do
it 'renders event types' do
@event_type = create(:event_type)

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe 'admin/social_events/index' do
it 'renders social events' do
it 'renders social events' do
@social_event = create(:social_event)
assign :conference, @social_event.conference
render

View file

@ -1,5 +1,5 @@
require 'spec_helper'
describe "admin/volunteers/show" do
describe 'admin/volunteers/show' do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

@ -68,8 +68,8 @@ describe 'conference/show.html.haml' do
expect(view).to render_template('conference/_social_media')
expect(view.content_for(:splash)).to include('http://www.fbexample.com')
expect(view.content_for(:splash)).to include('http://www.google-example.com')
expect(view.content_for(:splash)).to include("http://instagram.com")
expect(view.content_for(:splash)).to include("http://twitter.com")
expect(view.content_for(:splash)).to include('http://instagram.com')
expect(view.content_for(:splash)).to include('http://twitter.com')
end
it 'renders location partial' do