From b72e64b2385767f2b1634322ac2cf97c9a3a3638 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 13 Jun 2017 04:39:47 +0530 Subject: [PATCH 01/11] Introduce organization admins --- app/controllers/admin/base_controller.rb | 2 +- .../admin/organizations_controller.rb | 5 + app/models/ability.rb | 95 +++++++++++-------- app/models/organization.rb | 10 ++ lib/tasks/roles.rake | 4 + spec/models/ability_spec.rb | 21 +++- 6 files changed, 96 insertions(+), 41 deletions(-) diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 638d2ab6..5c71ffdc 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -8,7 +8,7 @@ module Admin return false end unless (current_user.has_role? :organizer, :any) || (current_user.has_role? :cfp, :any) || - (current_user.has_role? :info_desk, :any) || + (current_user.has_role? :info_desk, :any) || (current_user.has_role? :organization_admin, :any) || (current_user.has_role? :volunteers_coordinator, :any) || current_user.is_admin raise CanCan::AccessDenied.new('You are not authorized to access this area!') end diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 087bf7f8..9d0dc78b 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -1,6 +1,7 @@ module Admin class OrganizationsController < Admin::BaseController load_and_authorize_resource :organization + after_action :assign_role, only: :create def index @organizations = Organization.all @@ -45,6 +46,10 @@ module Admin private + def assign_role + current_user.add_role :organization_admin, @organization + end + def organization_params params.require(:organization).permit(:name, :description, :picture) end diff --git a/app/models/ability.rb b/app/models/ability.rb index 6fa8c12f..7d1cf868 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -110,6 +110,7 @@ class Ability # Abilities from not_signed_in and signed_in are also inherited signed_in(user) + signed_in_with_organization_admin_role(user) if user.has_role? :organization_admin, :any signed_in_with_organizer_role(user) if user.has_role? :organizer, :any signed_in_with_cfp_role(user) if user.has_role? :cfp, :any signed_in_with_info_desk_role(user) if user.has_role? :info_desk, :any @@ -146,57 +147,73 @@ class Ability end end - def signed_in_with_organizer_role(user) - # ids of all the conferences for which the user has the 'organizer' role - conf_ids_for_organizer = Conference.with_role(:organizer, user).pluck(:id) + def signed_in_with_organization_admin_role(user) + org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) - can :manage, Resource, conference_id: conf_ids_for_organizer - can [:new, :create], Conference if user.has_role?(:organizer, :any) - can :manage, Conference, id: conf_ids_for_organizer - can :manage, Splashpage, conference_id: conf_ids_for_organizer - can :manage, Contact, conference_id: conf_ids_for_organizer - can :manage, EmailSettings, conference_id: conf_ids_for_organizer - can :manage, Campaign, conference_id: conf_ids_for_organizer - can :manage, Target, conference_id: conf_ids_for_organizer - can :manage, Commercial, commercialable_type: 'Conference', - commercialable_id: conf_ids_for_organizer - can :manage, Registration, conference_id: conf_ids_for_organizer - can :manage, RegistrationPeriod, conference_id: conf_ids_for_organizer - can :manage, Question, conference_id: conf_ids_for_organizer - can :manage, Question do |question| - !(question.conferences.pluck(:id) & conf_ids_for_organizer).empty? + can :manage, Organization, id: org_ids_for_organization_admin + can :manage, Conference, organization_id: org_ids_for_organization_admin + conf_ids_for_organization_admin = [] + org_ids_for_organization_admin.each do |org_id| + conf_ids_for_organization_admin += Organization.find(org_id).conferences.pluck(:id) end - can :manage, Vposition, conference_id: conf_ids_for_organizer - can :manage, Vday, conference_id: conf_ids_for_organizer - can :manage, Program, conference_id: conf_ids_for_organizer - can :manage, Schedule, program: { conference_id: conf_ids_for_organizer } - can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids_for_organizer } } - can :manage, Cfp, program: { conference_id: conf_ids_for_organizer } - can :manage, Event, program: { conference_id: conf_ids_for_organizer} - can :manage, EventType, program: { conference_id: conf_ids_for_organizer} - can :manage, Track, program: { conference_id: conf_ids_for_organizer} - can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_organizer} + can [:index, :show], Role + can [:edit, :update], Role do |role| + role.resource_type == 'Organization' && (org_ids_for_organization_admin.include? role.resource_id) + end + signed_in_with_organizer_role(user, conf_ids_for_organization_admin) + end + + def signed_in_with_organizer_role(user, conf_ids_for_organization_admin = []) + # ids of all the conferences for which the user has the 'organizer' role and + # conferences that belong to organizations for which user is 'organization_admin' + conf_ids_for_organization_admin_and_organizer = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq + can :manage, Resource, conference_id: conf_ids_for_organization_admin_and_organizer + can [:new, :create], Conference if user.has_role?(:organizer, :any) + can :manage, Conference, id: conf_ids_for_organization_admin_and_organizer + can :manage, Splashpage, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Contact, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, EmailSettings, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Campaign, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Target, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Commercial, commercialable_type: 'Conference', + commercialable_id: conf_ids_for_organization_admin_and_organizer + can :manage, Registration, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, RegistrationPeriod, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Question, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Question do |question| + !(question.conferences.pluck(:id) & conf_ids_for_organization_admin_and_organizer).empty? + end + can :manage, Vposition, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Vday, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Program, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Schedule, program: { conference_id: conf_ids_for_organization_admin_and_organizer } + can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids_for_organization_admin_and_organizer } } + can :manage, Cfp, program: { conference_id: conf_ids_for_organization_admin_and_organizer} + can :manage, Event, program: { conference_id: conf_ids_for_organization_admin_and_organizer} + can :manage, EventType, program: { conference_id: conf_ids_for_organization_admin_and_organizer} + can :manage, Track, program: { conference_id: conf_ids_for_organization_admin_and_organizer} + can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_organization_admin_and_organizer} can :manage, Commercial, commercialable_type: 'Event', - commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id) - can :manage, Venue, conference_id: conf_ids_for_organizer + commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id) + can :manage, Venue, conference_id: conf_ids_for_organization_admin_and_organizer can :manage, Commercial, commercialable_type: 'Venue', - commercialable_id: Venue.where(conference_id: conf_ids_for_organizer).pluck(:id) - can :manage, Lodging, conference_id: conf_ids_for_organizer - can :manage, Room, venue: { conference_id: conf_ids_for_organizer} - can :manage, Sponsor, conference_id: conf_ids_for_organizer - can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer - can :manage, Ticket, conference_id: conf_ids_for_organizer + commercialable_id: Venue.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id) + can :manage, Lodging, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Room, venue: { conference_id: conf_ids_for_organization_admin_and_organizer} + can :manage, Sponsor, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, SponsorshipLevel, conference_id: conf_ids_for_organization_admin_and_organizer + can :manage, Ticket, conference_id: conf_ids_for_organization_admin_and_organizer can :index, Comment, commentable_type: 'Event', - commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id) + commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id) # Abilities for Role (Conference resource) can [:index, :show], Role can [:edit, :update, :toggle_user], Role do |role| - role.resource_type == 'Conference' && (conf_ids_for_organizer.include? role.resource_id) + role.resource_type == 'Conference' && (conf_ids_for_organization_admin_and_organizer.include? role.resource_id) end can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version| - version.item_type == 'User' || (conf_ids_for_organizer.include? version.conference_id) + version.item_type == 'User' || (conf_ids_for_organization_admin_and_organizer.include? version.conference_id) end end diff --git a/app/models/organization.rb b/app/models/organization.rb index 60a83fef..0fdbe5f9 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,7 +1,17 @@ class Organization < ActiveRecord::Base + resourcify :roles, dependent: :delete_all + has_many :conferences, dependent: :destroy + after_create :create_roles + validates :name, presence: true mount_uploader :picture, PictureUploader, mount_on: :picture + + private + + def create_roles + Role.where(name: 'organization_admin', resource: self).first_or_create(description: "For the administrators of an organization (who shall have full access to the organization and it's conferences)") + end end diff --git a/lib/tasks/roles.rake b/lib/tasks/roles.rake index 8c817db0..227f9642 100644 --- a/lib/tasks/roles.rake +++ b/lib/tasks/roles.rake @@ -2,6 +2,10 @@ namespace :roles do desc 'Adds back deleted roles to all conferences' task add: :environment do + Organization.all.each do |org| + Role.where(name: 'organization_admin', resource: org).first_or_create(description: "For the administrators of an organization (who shall have full access to the organization and it's conferences)") + end + Conference.all.each do |c| Role.where(name: 'organizer', resource: c).first_or_create(description: 'For the organizers of the conference (who shall have full access)') Role.where(name: 'cfp', resource: c).first_or_create(description: 'For the members of the CfP team') diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 001c7365..980cc194 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -9,7 +9,8 @@ describe 'User' do subject(:ability){ Ability.new(user) } let(:user){ nil } - let!(:my_conference) { create(:full_conference) } + let!(:organization) { create(:organization) } + let!(:my_conference) { create(:full_conference, organization: organization) } let(:my_venue) { my_conference.venue || create(:venue, conference: my_conference) } let(:my_registration) { create(:registration, conference: my_conference, user: admin) } @@ -44,6 +45,7 @@ describe 'User' do let!(:other_event_schedule) { create(:event_schedule, schedule: other_schedule) } # Test abilities for not signed in users context 'when user is not signed in' do + it{ should be_able_to(:index, Organization)} it{ should be_able_to(:index, Conference)} it{ should be_able_to(:show, conference_public)} @@ -138,9 +140,14 @@ describe 'User' do shared_examples 'user with any role' do before do + @other_organization = create(:organization) @other_conference = create(:conference) end + it{ should_not be_able_to(:update, Role.find_by(name: 'organization_admin', resource: @other_organization)) } + it{ should_not be_able_to(:edit, Role.find_by(name: 'organization_admin', resource: @other_organization)) } + it{ should_not be_able_to(:show, Role.find_by(name: 'organization_admin', resource: @other_organization)) } + %w(organizer cfp info_desk volunteers_coordinator).each do |role| it{ should_not be_able_to(:toggle_user, Role.find_by(name: role, resource: @other_conference)) } it{ should_not be_able_to(:update, Role.find_by(name: role, resource: @other_conference)) } @@ -164,6 +171,18 @@ describe 'User' do end end + context 'when user has the role organization_admin' do + let(:role) { Role.find_by(name: 'organization_admin', resource: organization) } + let(:user) { create(:user, role_ids: [role.id]) } + let(:other_conference) { create(:conference) } + + it{ should_not be_able_to(:manage, other_conference) } + it{ should be_able_to(:manage, my_conference) } + it{ should be_able_to(:manage, organization) } + + it_behaves_like 'user with any role' + end + context 'when user has the role organizer' do let(:role) { Role.find_by(name: 'organizer', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } From aa3df0243eff061502050fa0d346f47fc9569789 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 13 Jun 2017 20:57:55 +0530 Subject: [PATCH 02/11] mending permissions and test --- app/models/ability.rb | 22 ++++++++++++++-------- spec/models/ability_spec.rb | 10 +++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 7d1cf868..00a0b291 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -29,6 +29,7 @@ class Ability # Abilities for not signed in users (guests) def not_signed_in + can [:index], Organization can [:index], Conference can [:show], Conference do |conference| conference.splashpage && conference.splashpage.public == true @@ -168,7 +169,6 @@ class Ability # conferences that belong to organizations for which user is 'organization_admin' conf_ids_for_organization_admin_and_organizer = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq can :manage, Resource, conference_id: conf_ids_for_organization_admin_and_organizer - can [:new, :create], Conference if user.has_role?(:organizer, :any) can :manage, Conference, id: conf_ids_for_organization_admin_and_organizer can :manage, Splashpage, conference_id: conf_ids_for_organization_admin_and_organizer can :manage, Contact, conference_id: conf_ids_for_organization_admin_and_organizer @@ -207,7 +207,10 @@ class Ability commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id) # Abilities for Role (Conference resource) - can [:index, :show], Role + can [:index, :show], Role do |role| + role.resource_type == 'Conference' + end + can [:edit, :update, :toggle_user], Role do |role| role.resource_type == 'Conference' && (conf_ids_for_organization_admin_and_organizer.include? role.resource_id) end @@ -239,8 +242,9 @@ class Ability commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id) # Abilities for Role (Conference resource) - can [:index, :show], Role - + can [:index, :show], Role do |role| + role.resource_type == 'Conference' + end # Can add or remove users from role, when user has that same role for the conference # Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP') can :toggle_user, Role do |role| @@ -268,8 +272,9 @@ class Ability end # Abilities for Role (Conference resource) - can [:index, :show], Role - + can [:index, :show], Role do |role| + role.resource_type == 'Conference' + end # Can add or remove users from role, when user has that same role for the conference # Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP') can :toggle_user, Role do |role| @@ -287,8 +292,9 @@ class Ability can :manage, Vday, conference_id: conf_ids_for_volunteers_coordinator # Abilities for Role (Conference resource) - can [:index, :show], Role - + can [:index, :show], Role do |role| + role.resource_type == 'Conference' + end # Can add or remove users from role, when user has that same role for the conference # Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP') can :toggle_user, Role do |role| diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 980cc194..fcf9b384 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -141,7 +141,7 @@ describe 'User' do shared_examples 'user with any role' do before do @other_organization = create(:organization) - @other_conference = create(:conference) + @other_conference = create(:conference, organization: @other_organization) end it{ should_not be_able_to(:update, Role.find_by(name: 'organization_admin', resource: @other_organization)) } @@ -179,8 +179,6 @@ describe 'User' do it{ should_not be_able_to(:manage, other_conference) } it{ should be_able_to(:manage, my_conference) } it{ should be_able_to(:manage, organization) } - - it_behaves_like 'user with any role' end context 'when user has the role organizer' do @@ -199,8 +197,10 @@ describe 'User' do should be_able_to(:destroy, my_venue) end - it{ should be_able_to(:new, Conference) } - it{ should be_able_to(:create, Conference) } + it{ should_not be_able_to(:new, Organization)} + it{ should_not be_able_to(:create, Organization)} + it{ should_not be_able_to(:new, Conference.new) } + it{ should_not be_able_to(:create, Conference.new) } it{ should be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should be_able_to(:manage, my_conference.splashpage) } From ad3d6f2f95bc5d6af98a3056747b63c3ed14bc37 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 14 Jun 2017 20:42:50 +0530 Subject: [PATCH 03/11] modify admin/conference_controller_spec and not authorized error messages --- app/controllers/admin/base_controller.rb | 2 +- .../admin/conferences_controller.rb | 5 +- app/models/ability.rb | 1 + app/views/admin/conferences/new.html.haml | 1 + .../admin/comments_controller_spec.rb | 2 +- .../admin/conferences_controller_spec.rb | 210 +++++++++--------- spec/features/ability_spec.rb | 2 +- spec/features/base_controller_spec.rb | 2 +- 8 files changed, 120 insertions(+), 105 deletions(-) diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 5c71ffdc..85dba43d 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -10,7 +10,7 @@ module Admin unless (current_user.has_role? :organizer, :any) || (current_user.has_role? :cfp, :any) || (current_user.has_role? :info_desk, :any) || (current_user.has_role? :organization_admin, :any) || (current_user.has_role? :volunteers_coordinator, :any) || current_user.is_admin - raise CanCan::AccessDenied.new('You are not authorized to access this area!') + raise CanCan::AccessDenied.new('You are not authorized to access this page.') end end end diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index f8c9ea19..bf1dfdb5 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -72,11 +72,14 @@ module Admin def new @conference = Conference.new + @organizations = {} + Organization.all.each do |organization| + @organizations.store(organization.name, organization.id) if can? :create, Conference.new(organization: organization) + end end def create @conference = Conference.new(conference_params) - @conference.organization = Organization.find_or_create_by(name: 'organization') if @conference.save # user that creates the conference becomes organizer of that conference current_user.add_role :organizer, @conference diff --git a/app/models/ability.rb b/app/models/ability.rb index 00a0b291..6e560a63 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -152,6 +152,7 @@ class Ability org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) can :manage, Organization, id: org_ids_for_organization_admin + can [:new], Conference can :manage, Conference, organization_id: org_ids_for_organization_admin conf_ids_for_organization_admin = [] org_ids_for_organization_admin.each do |org_id| diff --git a/app/views/admin/conferences/new.html.haml b/app/views/admin/conferences/new.html.haml index 014758de..0d2eb4b3 100644 --- a/app/views/admin/conferences/new.html.haml +++ b/app/views/admin/conferences/new.html.haml @@ -6,6 +6,7 @@ input_html: { required: 'required' } = f.input :short_title, hint: "A short and unique handle for your conference, using only letters, numbers, underscores, and dashes. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }, prepend: conferences_url + '/' + = f.input :organization, as: :select, collection: @organizations = f.inputs 'Scheduling' do = f.input :timezone, as: :time_zone, default: Time.zone.name, hint: 'Please select in what time zone your conference will take place.' = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' } diff --git a/spec/controllers/admin/comments_controller_spec.rb b/spec/controllers/admin/comments_controller_spec.rb index 5429dabd..23b6b88a 100644 --- a/spec/controllers/admin/comments_controller_spec.rb +++ b/spec/controllers/admin/comments_controller_spec.rb @@ -51,7 +51,7 @@ describe Admin::CommentsController, type: :controller do comment get :index expect(response).to redirect_to(root_path) - expect(flash[:alert]).to match('You are not authorized to access this area!') + expect(flash[:alert]).to match('You are not authorized to access this page.') end end end diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 74acbb3f..d6133c65 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -3,19 +3,18 @@ require 'spec_helper' describe Admin::ConferencesController do # It is necessary to use bang version of let to build roles before user - let(:conference) { create(:conference, end_date: Date.new(2014, 05, 26) + 15) } + let(:organization) { create(:organization) } + let(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } - + let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } + let(:organization_admin) { create(:user, role_ids: organization_admin_role.id) } let(:organizer) { create(:user, role_ids: organizer_role.id) } let(:organizer2) { create(:user, email: 'organizer2@email.osem', role_ids: organizer_role.id) } let(:participant) { create(:user) } - shared_examples 'access as organizer' do - + shared_examples 'access as organizer or organization_admin' do describe 'PATCH #update' do - context 'valid attributes' do - it 'locates the requested conference' do patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con') expect(assigns(:conference)).to eq(conference) @@ -25,7 +24,6 @@ describe Admin::ConferencesController do patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con', short_title: 'ExCon') - conference.reload expect(conference.title).to eq('Example Con') expect(conference.short_title).to eq('ExCon') @@ -75,72 +73,6 @@ describe Admin::ConferencesController do end end - describe 'POST #create' do - context 'with valid attributes' do - it 'saves the conference to the database' do - expected = expect do - post :create, conference: - attributes_for(:conference, short_title: 'dps15') - end - expected.to change { Conference.count }.by 1 - end - - it 'redirects to conference#show' do - post :create, conference: - attributes_for(:conference, short_title: 'dps15') - - 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, conference: - attributes_for(:conference, short_title: 'dps15') - - expect(conference.roles.count).to eq 4 - - expect(conference.roles).to eq [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, conference: - attributes_for(:conference, short_title: nil) - end - expected.to_not change { Conference.count } - end - - it 're-renders the new template' do - post :create, conference: - attributes_for(:conference, short_title: nil) - expect(response).to be_success - 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, conference: - attributes_for(:conference, short_title: conference.short_title) - end - expected.to_not change { Conference.count } - end - - it 're-renders the new template' do - conference - post :create, conference: attributes_for(:conference, short_title: conference.short_title) - expect(response).to be_success - end - end - end - describe 'GET #edit' do it 'assigns the requested conference to conference' do get :edit, id: conference.short_title @@ -203,6 +135,74 @@ describe Admin::ConferencesController do end end 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, conference: + attributes_for(:conference, short_title: 'dps15', organization: organization) + end + expected.to change { Conference.count }.by 1 + end + + it 'redirects to conference#show' do + post :create, conference: + attributes_for(:conference, short_title: 'dps15', organization: organization) + + 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, conference: + attributes_for(:conference, short_title: 'dps15') + + expect(conference.roles.count).to eq 4 + + expect(conference.roles).to eq [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, conference: + attributes_for(:conference, short_title: nil, organization: organization) + end + expected.to_not change { Conference.count } + end + + it 're-renders the new template' do + post :create, conference: + attributes_for(:conference, short_title: nil, organization: organization) + expect(response).to be_success + 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, conference: + attributes_for(:conference, short_title: conference.short_title, organization: organization) + end + expected.to_not change { Conference.count } + end + + it 're-renders the new template' do + conference + post :create, conference: attributes_for(:conference, short_title: conference.short_title, organization: organization) + expect(response).to be_success + end + end + end describe 'GET #new' do it 'assigns a new conference to conference' do @@ -217,14 +217,45 @@ describe Admin::ConferencesController do end end - describe 'organizer access' do + 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 + get :new + expect(response).to redirect_to(send(path)) + if message + expect(flash[:alert]).to match(/#{message}/) + end + end + end + + describe 'POST #create' do + it 'requires organizer privileges' do + post :create, conference: attributes_for(:conference, + short_title: 'ExCon') + expect(response).to redirect_to(send(path)) + if message + expect(flash[:alert]).to match(/#{message}/) + end + end + end + end + + describe 'organizer access' do before do sign_in(organizer) end - it_behaves_like 'access as organizer' - + it_behaves_like 'access as organizer or organization_admin' + it_behaves_like 'access as organizer, participant or guest', :root_path, 'You are not authorized to access this page.' end shared_examples 'access as participant or guest' do |path, message| @@ -248,27 +279,6 @@ describe Admin::ConferencesController do end end - describe 'GET #new' do - it 'requires organizer privileges' do - get :new - expect(response).to redirect_to(send(path)) - if message - expect(flash[:alert]).to match(/#{message}/) - end - end - end - - describe 'POST #create' do - it 'requires organizer privileges' do - post :create, conference: attributes_for(:conference, - short_title: 'ExCon') - expect(response).to redirect_to(send(path)) - if message - expect(flash[:alert]).to match(/#{message}/) - end - end - end - describe 'PATCH #update' do it 'requires organizer privileges' do patch :update, id: conference.short_title, @@ -287,13 +297,13 @@ describe Admin::ConferencesController do sign_in(participant) end - it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this area!' - + it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this page.' + it_behaves_like 'access as organizer, 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 organizer, participant or guest', :new_user_session_path end end diff --git a/spec/features/ability_spec.rb b/spec/features/ability_spec.rb index fe3a3c36..8ddcb001 100644 --- a/spec/features/ability_spec.rb +++ b/spec/features/ability_spec.rb @@ -22,7 +22,7 @@ feature 'Has correct abilities' do visit admin_conference_path(conference1.short_title) expect(current_path).to eq root_path - expect(flash).to eq 'You are not authorized to access this area!' + expect(flash).to eq 'You are not authorized to access this page.' end scenario 'when user is organizer' do diff --git a/spec/features/base_controller_spec.rb b/spec/features/base_controller_spec.rb index be52c3a9..1f75f81b 100644 --- a/spec/features/base_controller_spec.rb +++ b/spec/features/base_controller_spec.rb @@ -25,7 +25,7 @@ feature 'BaseController' do it 'not an admin it redirects to root_path' do visit admin_conferences_path expect(current_path).to eq root_path - expect(flash).to eq 'You are not authorized to access this area!' + expect(flash).to eq 'You are not authorized to access this page.' end it 'an admin he can access the admin area' do From 8839a928ed83a0fca8b90f9c5a6871f9c7bc946e Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 14 Jun 2017 21:59:58 +0530 Subject: [PATCH 04/11] mending failing tests --- .../admin/conferences_controller.rb | 5 +---- app/models/ability.rb | 2 +- app/views/admin/conferences/new.html.haml | 1 - .../admin/conferences_controller_spec.rb | 18 +++++++++--------- .../admin/organizations_controller_spec.rb | 10 +++++----- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index bf1dfdb5..f8c9ea19 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -72,14 +72,11 @@ module Admin def new @conference = Conference.new - @organizations = {} - Organization.all.each do |organization| - @organizations.store(organization.name, organization.id) if can? :create, Conference.new(organization: organization) - end end def create @conference = Conference.new(conference_params) + @conference.organization = Organization.find_or_create_by(name: 'organization') if @conference.save # user that creates the conference becomes organizer of that conference current_user.add_role :organizer, @conference diff --git a/app/models/ability.rb b/app/models/ability.rb index 6e560a63..37090a49 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -152,7 +152,7 @@ class Ability org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) can :manage, Organization, id: org_ids_for_organization_admin - can [:new], Conference + can :new, Conference can :manage, Conference, organization_id: org_ids_for_organization_admin conf_ids_for_organization_admin = [] org_ids_for_organization_admin.each do |org_id| diff --git a/app/views/admin/conferences/new.html.haml b/app/views/admin/conferences/new.html.haml index 0d2eb4b3..014758de 100644 --- a/app/views/admin/conferences/new.html.haml +++ b/app/views/admin/conferences/new.html.haml @@ -6,7 +6,6 @@ input_html: { required: 'required' } = f.input :short_title, hint: "A short and unique handle for your conference, using only letters, numbers, underscores, and dashes. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }, prepend: conferences_url + '/' - = f.input :organization, as: :select, collection: @organizations = f.inputs 'Scheduling' do = f.input :timezone, as: :time_zone, default: Time.zone.name, hint: 'Please select in what time zone your conference will take place.' = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' } diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index d6133c65..009e40ba 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -3,8 +3,8 @@ 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) } - let(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) } + let!(:organization) { create(:organization, name: 'organization') } + let!(:conference) { create(:conference, organization: organization, end_date: Date.new(2014, 05, 26) + 15) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } let(:organization_admin) { create(:user, role_ids: organization_admin_role.id) } @@ -143,14 +143,14 @@ describe Admin::ConferencesController do it 'saves the conference to the database' do expected = expect do post :create, conference: - attributes_for(:conference, short_title: 'dps15', organization: organization) + 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, conference: - attributes_for(:conference, short_title: 'dps15', organization: organization) + attributes_for(:conference, short_title: 'dps15', organization_id: organization.id) expect(response).to redirect_to admin_conference_path( assigns[:conference].short_title) @@ -174,14 +174,14 @@ describe Admin::ConferencesController do it 'does not save the conference to the database' do expected = expect do post :create, conference: - attributes_for(:conference, short_title: nil, organization: organization) + 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, conference: - attributes_for(:conference, short_title: nil, organization: organization) + attributes_for(:conference, short_title: nil, organization_id: organization.id) expect(response).to be_success end end @@ -191,14 +191,14 @@ describe Admin::ConferencesController do conference expected = expect do post :create, conference: - attributes_for(:conference, short_title: conference.short_title, organization: organization) + 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, conference: attributes_for(:conference, short_title: conference.short_title, organization: organization) + post :create, conference: attributes_for(:conference, short_title: conference.short_title, organization_id: organization.id) expect(response).to be_success end end @@ -240,7 +240,7 @@ describe Admin::ConferencesController do describe 'POST #create' do it 'requires organizer privileges' do post :create, conference: attributes_for(:conference, - short_title: 'ExCon') + short_title: 'ExCon', organization_id: organization.id) expect(response).to redirect_to(send(path)) if message expect(flash[:alert]).to match(/#{message}/) diff --git a/spec/controllers/admin/organizations_controller_spec.rb b/spec/controllers/admin/organizations_controller_spec.rb index a4afc994..abe5005b 100644 --- a/spec/controllers/admin/organizations_controller_spec.rb +++ b/spec/controllers/admin/organizations_controller_spec.rb @@ -16,7 +16,7 @@ describe Admin::OrganizationsController do end it 'redirects to root' do - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -27,7 +27,7 @@ describe Admin::OrganizationsController do end it 'redirects to root' do - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -43,7 +43,7 @@ describe Admin::OrganizationsController do it 'redirects to root' do post :create, organization: attributes_for(:organization) - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -55,7 +55,7 @@ describe Admin::OrganizationsController do organization.reload expect(organization.name).to eq(old_name) - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end @@ -72,7 +72,7 @@ describe Admin::OrganizationsController do it 'redirects to root' do delete :destroy, id: organization.id - expect(flash[:alert]).to eq('You are not authorized to access this area!') + expect(flash[:alert]).to eq('You are not authorized to access this page.') expect(response).to redirect_to(root_path) end end From 7d408ee33cfdac2b35410ac2c78e8c222de7f131 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 14 Jun 2017 22:51:26 +0530 Subject: [PATCH 05/11] suggested changes change description of organization_admin remove assign_role callback --- app/controllers/admin/organizations_controller.rb | 5 ----- app/models/organization.rb | 2 +- lib/tasks/roles.rake | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 9d0dc78b..087bf7f8 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -1,7 +1,6 @@ module Admin class OrganizationsController < Admin::BaseController load_and_authorize_resource :organization - after_action :assign_role, only: :create def index @organizations = Organization.all @@ -46,10 +45,6 @@ module Admin private - def assign_role - current_user.add_role :organization_admin, @organization - end - def organization_params params.require(:organization).permit(:name, :description, :picture) end diff --git a/app/models/organization.rb b/app/models/organization.rb index 0fdbe5f9..de3d4f94 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -12,6 +12,6 @@ class Organization < ActiveRecord::Base private def create_roles - Role.where(name: 'organization_admin', resource: self).first_or_create(description: "For the administrators of an organization (who shall have full access to the organization and it's conferences)") + roles.where(name: 'organization_admin').first_or_create(description: 'For the administrators of an organization and its conferences') end end diff --git a/lib/tasks/roles.rake b/lib/tasks/roles.rake index 227f9642..c29d0e24 100644 --- a/lib/tasks/roles.rake +++ b/lib/tasks/roles.rake @@ -3,7 +3,7 @@ namespace :roles do task add: :environment do Organization.all.each do |org| - Role.where(name: 'organization_admin', resource: org).first_or_create(description: "For the administrators of an organization (who shall have full access to the organization and it's conferences)") + Role.where(name: 'organization_admin', resource: org).first_or_create(description: 'For the administrators of an organization and its conferences') end Conference.all.each do |c| From 21b2e5466f3ed49e0ee78da08ca4ddcb822691f3 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Fri, 16 Jun 2017 03:47:34 +0530 Subject: [PATCH 06/11] refactor features/ability_spec and increase test coverage for organization --- spec/features/ability_spec.rb | 1045 ++++++++++++++-------------- spec/features/organization_spec.rb | 51 ++ 2 files changed, 562 insertions(+), 534 deletions(-) create mode 100644 spec/features/organization_spec.rb diff --git a/spec/features/ability_spec.rb b/spec/features/ability_spec.rb index 8ddcb001..41775de4 100644 --- a/spec/features/ability_spec.rb +++ b/spec/features/ability_spec.rb @@ -1,18 +1,22 @@ 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(:full_conference) } # user is organizer - let(:conference2) { create(:full_conference) } # user is cfp - let(:conference3) { create(:full_conference) } # user is info_desk - let(:conference6) { create(:conference) } # user is organizer, venue is not set by default + let(:organization) { create(:organization) } + # It is necessary to use bang version of let to build roles before user + let(:conference1) { create(:full_conference, organization: organization) } # user is organizer + let(:conference2) { create(:full_conference, organization: organization) } # user is cfp + let(:conference3) { create(:full_conference, organization: organization) } # user is info_desk + let(:conference6) { create(:conference, organization: organization) } # user is organizer, venue is not set by default + + let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) } let(:role_organizer_conf1) { Role.find_by(name: 'organizer', resource: conference1) } let(:role_organizer_conf6) { Role.find_by(name: 'organizer', resource: conference6) } let(:role_cfp) { Role.find_by(name: 'cfp', resource: conference2) } let(:role_info_desk) { Role.find_by(name: 'info_desk', resource: conference3) } let(:user) { create(:user) } + let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) } let(:user_organizer) { create(:user, role_ids: [role_organizer_conf1.id, role_organizer_conf6.id]) } let(:user_cfp) { create(:user, role_ids: [role_cfp.id]) } let(:user_info_desk) { create(:user, role_ids: [role_info_desk.id]) } @@ -25,653 +29,626 @@ feature 'Has correct abilities' do expect(flash).to eq 'You are not authorized to access this page.' end - scenario 'when user is organizer' do - sign_in user_organizer + shared_examples 'correct abilities for organizers and organization_admin' do + scenario 'for conference attributes' do + visit admin_conference_path(conference1.short_title) + expect(current_path).to eq(admin_conference_path(conference1.short_title)) - visit admin_conference_path(conference1.short_title) - expect(current_path).to eq(admin_conference_path(conference1.short_title)) + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to have_link('Basics', href: "/admin/conferences/#{conference1.short_title}/edit") + expect(page).to have_link('Contact', href: "/admin/conferences/#{conference1.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference1.short_title}/commercials") + expect(page).to have_link('Splashpage', href: "/admin/conferences/#{conference1.short_title}/splashpage") + expect(page).to have_link('Venue', href: "/admin/conferences/#{conference1.short_title}/venue") + expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference1.short_title}/venue/rooms") + expect(page).to have_link('Lodgings', href: "/admin/conferences/#{conference1.short_title}/lodgings") + expect(page).to have_link('Program', href: "/admin/conferences/#{conference1.short_title}/program") + expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference1.short_title}/program/cfps") + expect(page).to have_link('Events', href: "/admin/conferences/#{conference1.short_title}/program/events") + expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference1.short_title}/program/tracks") + expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference1.short_title}/program/event_types") + expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference1.short_title}/program/difficulty_levels") + expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference1.short_title}/schedules") + expect(page).to have_link('Reports', href: "/admin/conferences/#{conference1.short_title}/program/reports") + expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference1.short_title}/registrations") + expect(page).to have_link('Registration Period', href: "/admin/conferences/#{conference1.short_title}/registration_period") + expect(page).to have_link('Questions', href: "/admin/conferences/#{conference1.short_title}/questions") + expect(page).to have_text('Donations') + expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference1.short_title}/sponsorship_levels") + expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference1.short_title}/sponsors") + expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference1.short_title}/tickets") + expect(page).to have_text('Objectives') + expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference1.short_title}/campaigns") + expect(page).to have_link('Goals', href: "/admin/conferences/#{conference1.short_title}/targets") + expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference1.short_title}/emails") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference1.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference1.short_title}/resources") - expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') - expect(page).to have_link('Basics', href: "/admin/conferences/#{conference1.short_title}/edit") - expect(page).to have_link('Contact', href: "/admin/conferences/#{conference1.short_title}/contact/edit") - expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference1.short_title}/commercials") - expect(page).to have_link('Splashpage', href: "/admin/conferences/#{conference1.short_title}/splashpage") - expect(page).to have_link('Venue', href: "/admin/conferences/#{conference1.short_title}/venue") - expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference1.short_title}/venue/rooms") - expect(page).to have_link('Lodgings', href: "/admin/conferences/#{conference1.short_title}/lodgings") - expect(page).to have_link('Program', href: "/admin/conferences/#{conference1.short_title}/program") - expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference1.short_title}/program/cfps") - expect(page).to have_link('Events', href: "/admin/conferences/#{conference1.short_title}/program/events") - expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference1.short_title}/program/tracks") - expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference1.short_title}/program/event_types") - expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference1.short_title}/program/difficulty_levels") - expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference1.short_title}/schedules") - expect(page).to have_link('Reports', href: "/admin/conferences/#{conference1.short_title}/program/reports") - expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference1.short_title}/registrations") - expect(page).to have_link('Registration Period', href: "/admin/conferences/#{conference1.short_title}/registration_period") - expect(page).to have_link('Questions', href: "/admin/conferences/#{conference1.short_title}/questions") - expect(page).to have_text('Donations') - expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference1.short_title}/sponsorship_levels") - expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference1.short_title}/sponsors") - expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference1.short_title}/tickets") - expect(page).to have_text('Objectives') - expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference1.short_title}/campaigns") - expect(page).to have_link('Goals', href: "/admin/conferences/#{conference1.short_title}/targets") - expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference1.short_title}/emails") - expect(page).to have_link('Roles', href: "/admin/conferences/#{conference1.short_title}/roles") - expect(page).to have_link('Resources', href: "/admin/conferences/#{conference1.short_title}/resources") + visit admin_conference_path(conference6.short_title) + expect(page).to have_link('Add venue', href: "/admin/conferences/#{conference6.short_title}/venue/new") - visit admin_conference_path(conference6.short_title) - expect(page).to have_link('Add venue', href: "/admin/conferences/#{conference6.short_title}/venue/new") + visit edit_admin_conference_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_path(conference1.short_title)) - visit edit_admin_conference_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_path(conference1.short_title)) + visit edit_admin_conference_contact_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_contact_path(conference1.short_title)) - visit edit_admin_conference_contact_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_contact_path(conference1.short_title)) + visit admin_conference_commercials_path(conference1.short_title) + expect(current_path).to eq(admin_conference_commercials_path(conference1.short_title)) - visit admin_conference_commercials_path(conference1.short_title) - expect(current_path).to eq(admin_conference_commercials_path(conference1.short_title)) + visit new_admin_conference_splashpage_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_splashpage_path(conference1.short_title)) - visit new_admin_conference_splashpage_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_splashpage_path(conference1.short_title)) + visit edit_admin_conference_splashpage_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_splashpage_path(conference1.short_title)) - visit edit_admin_conference_splashpage_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_splashpage_path(conference1.short_title)) + visit new_admin_conference_venue_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_venue_path(conference1.short_title)) - visit new_admin_conference_venue_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_venue_path(conference1.short_title)) + conference1.venue = create(:venue) + visit edit_admin_conference_venue_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_venue_path(conference1.short_title)) - conference1.venue = create(:venue) - visit edit_admin_conference_venue_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_venue_path(conference1.short_title)) + visit admin_conference_venue_rooms_path(conference1.short_title) + expect(current_path).to eq(admin_conference_venue_rooms_path(conference1.short_title)) - visit admin_conference_venue_rooms_path(conference1.short_title) - expect(current_path).to eq(admin_conference_venue_rooms_path(conference1.short_title)) + create(:room, venue: conference1.venue) + visit edit_admin_conference_venue_room_path(conference1.short_title, conference1.venue.rooms.first) + expect(current_path).to eq(edit_admin_conference_venue_room_path(conference1.short_title, conference1.venue.rooms.first)) - create(:room, venue: conference1.venue) - visit edit_admin_conference_venue_room_path(conference1.short_title, conference1.venue.rooms.first) - expect(current_path).to eq(edit_admin_conference_venue_room_path(conference1.short_title, conference1.venue.rooms.first)) + visit admin_conference_lodgings_path(conference1.short_title) + expect(current_path).to eq(admin_conference_lodgings_path(conference1.short_title)) - visit admin_conference_lodgings_path(conference1.short_title) - expect(current_path).to eq(admin_conference_lodgings_path(conference1.short_title)) + visit new_admin_conference_lodging_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_lodging_path(conference1.short_title)) - visit new_admin_conference_lodging_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_lodging_path(conference1.short_title)) + create(:lodging, conference: conference1) + visit edit_admin_conference_lodging_path(conference1.short_title, conference1.lodgings.first) + expect(current_path).to eq(edit_admin_conference_lodging_path(conference1.short_title, conference1.lodgings.first)) - create(:lodging, conference: conference1) - visit edit_admin_conference_lodging_path(conference1.short_title, conference1.lodgings.first) - expect(current_path).to eq(edit_admin_conference_lodging_path(conference1.short_title, conference1.lodgings.first)) + visit new_admin_conference_program_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_program_path(conference1.short_title)) - visit new_admin_conference_program_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_program_path(conference1.short_title)) + visit edit_admin_conference_program_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_program_path(conference1.short_title)) - visit edit_admin_conference_program_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_program_path(conference1.short_title)) + visit new_admin_conference_program_cfp_path(conference1.short_title) + expect(current_path).to eq root_path + + conference1.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference1.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference1.short_title) + create(:cfp, program: conference1.program) + + visit edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp) + expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp)) - visit new_admin_conference_program_cfp_path(conference1.short_title) - expect(current_path).to eq root_path + visit admin_conference_program_events_path(conference1.short_title) + expect(current_path).to eq(admin_conference_program_events_path(conference1.short_title)) - conference1.program.cfp.destroy! - visit new_admin_conference_program_cfp_path(conference1.short_title) - expect(current_path).to eq new_admin_conference_program_cfp_path(conference1.short_title) - create(:cfp, program: conference1.program) + create(:event, program: conference1.program) + visit edit_admin_conference_program_event_path(conference1.short_title, conference1.program.events.first) + expect(current_path).to eq(edit_admin_conference_program_event_path(conference1.short_title, conference1.program.events.first)) - visit edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp) - expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp)) + visit admin_conference_program_event_types_path(conference1.short_title) + expect(current_path).to eq(admin_conference_program_event_types_path(conference1.short_title)) - visit admin_conference_program_events_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_events_path(conference1.short_title)) + visit new_admin_conference_program_event_type_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_program_event_type_path(conference1.short_title)) - create(:event, program: conference1.program) - visit edit_admin_conference_program_event_path(conference1.short_title, conference1.program.events.first) - expect(current_path).to eq(edit_admin_conference_program_event_path(conference1.short_title, conference1.program.events.first)) + visit edit_admin_conference_program_event_type_path(conference1.short_title, conference1.program.event_types.first) + expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference1.short_title, conference1.program.event_types.first)) - visit admin_conference_program_event_types_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_event_types_path(conference1.short_title)) + visit admin_conference_program_difficulty_levels_path(conference1.short_title) + expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference1.short_title)) - visit new_admin_conference_program_event_type_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_program_event_type_path(conference1.short_title)) + visit new_admin_conference_program_difficulty_level_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference1.short_title)) - visit edit_admin_conference_program_event_type_path(conference1.short_title, conference1.program.event_types.first) - expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference1.short_title, conference1.program.event_types.first)) + visit edit_admin_conference_program_difficulty_level_path(conference1.short_title, conference1.program.difficulty_levels.first) + expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference1.short_title, conference1.program.difficulty_levels.first)) - visit admin_conference_program_difficulty_levels_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference1.short_title)) + visit admin_conference_schedules_path(conference1.short_title) + expect(current_path).to eq(admin_conference_schedules_path(conference1.short_title)) - visit new_admin_conference_program_difficulty_level_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference1.short_title)) + create(:schedule, program: conference1.program) + visit admin_conference_schedule_path(conference1.short_title, conference1.program.schedules.first) + expect(current_path).to eq(admin_conference_schedule_path(conference1.short_title, conference1.program.schedules.first)) - visit edit_admin_conference_program_difficulty_level_path(conference1.short_title, conference1.program.difficulty_levels.first) - expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference1.short_title, conference1.program.difficulty_levels.first)) + visit admin_conference_program_reports_path(conference1.short_title) + expect(current_path).to eq(admin_conference_program_reports_path(conference1.short_title)) - visit admin_conference_schedules_path(conference1.short_title) - expect(current_path).to eq(admin_conference_schedules_path(conference1.short_title)) + visit admin_conference_registrations_path(conference1.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference1.short_title)) - create(:schedule, program: conference1.program) - visit admin_conference_schedule_path(conference1.short_title, conference1.program.schedules.first) - expect(current_path).to eq(admin_conference_schedule_path(conference1.short_title, conference1.program.schedules.first)) + create(:registration, user: create(:user), conference: conference1) + visit edit_admin_conference_registration_path(conference1.short_title, conference1.registrations.first) + expect(current_path).to eq(edit_admin_conference_registration_path(conference1.short_title, conference1.registrations.first)) - visit admin_conference_program_reports_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_reports_path(conference1.short_title)) + visit new_admin_conference_registration_period_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_registration_period_path(conference1.short_title)) - visit admin_conference_registrations_path(conference1.short_title) - expect(current_path).to eq(admin_conference_registrations_path(conference1.short_title)) + create(:registration_period, conference: conference1) + visit edit_admin_conference_registration_period_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_registration_period_path(conference1.short_title)) - create(:registration, user: create(:user), conference: conference1) - visit edit_admin_conference_registration_path(conference1.short_title, conference1.registrations.first) - expect(current_path).to eq(edit_admin_conference_registration_path(conference1.short_title, conference1.registrations.first)) + visit admin_conference_questions_path(conference1.short_title) + expect(current_path).to eq(admin_conference_questions_path(conference1.short_title)) - visit new_admin_conference_registration_period_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_registration_period_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)) - create(:registration_period, conference: conference1) - visit edit_admin_conference_registration_period_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_registration_period_path(conference1.short_title)) + visit new_admin_conference_sponsorship_level_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_sponsorship_level_path(conference1.short_title)) - visit admin_conference_questions_path(conference1.short_title) - expect(current_path).to eq(admin_conference_questions_path(conference1.short_title)) + create(:sponsorship_level, conference: conference1) + visit edit_admin_conference_sponsorship_level_path(conference1.short_title, conference1.sponsorship_levels.first) + expect(current_path).to eq(edit_admin_conference_sponsorship_level_path(conference1.short_title, conference1.sponsorship_levels.first)) - 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_sponsors_path(conference1.short_title) + expect(current_path).to eq(admin_conference_sponsors_path(conference1.short_title)) - visit new_admin_conference_sponsorship_level_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_sponsorship_level_path(conference1.short_title)) + visit new_admin_conference_sponsor_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_sponsor_path(conference1.short_title)) - create(:sponsorship_level, conference: conference1) - visit edit_admin_conference_sponsorship_level_path(conference1.short_title, conference1.sponsorship_levels.first) - expect(current_path).to eq(edit_admin_conference_sponsorship_level_path(conference1.short_title, conference1.sponsorship_levels.first)) + create(:sponsor, conference: conference1, sponsorship_level: conference1.sponsorship_levels.first) + visit edit_admin_conference_sponsor_path(conference1.short_title, conference1.sponsors.first) + expect(current_path).to eq(edit_admin_conference_sponsor_path(conference1.short_title, conference1.sponsors.first)) - visit admin_conference_sponsors_path(conference1.short_title) - expect(current_path).to eq(admin_conference_sponsors_path(conference1.short_title)) + visit admin_conference_tickets_path(conference1.short_title) + expect(current_path).to eq(admin_conference_tickets_path(conference1.short_title)) - visit new_admin_conference_sponsor_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_sponsor_path(conference1.short_title)) + visit new_admin_conference_ticket_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_ticket_path(conference1.short_title)) - create(:sponsor, conference: conference1, sponsorship_level: conference1.sponsorship_levels.first) - visit edit_admin_conference_sponsor_path(conference1.short_title, conference1.sponsors.first) - expect(current_path).to eq(edit_admin_conference_sponsor_path(conference1.short_title, conference1.sponsors.first)) + create(:ticket, conference: conference1) + visit edit_admin_conference_ticket_path(conference1.short_title, conference1.tickets.first) + expect(current_path).to eq(edit_admin_conference_ticket_path(conference1.short_title, conference1.tickets.first)) - visit admin_conference_tickets_path(conference1.short_title) - expect(current_path).to eq(admin_conference_tickets_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 new_admin_conference_ticket_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_ticket_path(conference1.short_title)) + visit new_admin_conference_campaign_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_campaign_path(conference1.short_title)) - create(:ticket, conference: conference1) - visit edit_admin_conference_ticket_path(conference1.short_title, conference1.tickets.first) - expect(current_path).to eq(edit_admin_conference_ticket_path(conference1.short_title, conference1.tickets.first)) + create(:campaign, conference: conference1) + visit edit_admin_conference_campaign_path(conference1.short_title, conference1.campaigns.first) + expect(current_path).to eq(edit_admin_conference_campaign_path(conference1.short_title, conference1.campaigns.first)) - 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 new_admin_conference_campaign_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_campaign_path(conference1.short_title)) + visit new_admin_conference_target_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_target_path(conference1.short_title)) - create(:campaign, conference: conference1) - visit edit_admin_conference_campaign_path(conference1.short_title, conference1.campaigns.first) - expect(current_path).to eq(edit_admin_conference_campaign_path(conference1.short_title, conference1.campaigns.first)) + create(:target, conference: conference1) + visit edit_admin_conference_target_path(conference1.short_title, conference1.targets.first) + expect(current_path).to eq(edit_admin_conference_target_path(conference1.short_title, conference1.targets.first)) - visit admin_conference_targets_path(conference1.short_title) - expect(current_path).to eq(admin_conference_targets_path(conference1.short_title)) + visit admin_conference_program_tracks_path(conference1.short_title) + expect(current_path).to eq(admin_conference_program_tracks_path(conference1.short_title)) - visit new_admin_conference_target_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_target_path(conference1.short_title)) + visit admin_conference_roles_path(conference1.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference1.short_title)) - create(:target, conference: conference1) - visit edit_admin_conference_target_path(conference1.short_title, conference1.targets.first) - expect(current_path).to eq(edit_admin_conference_target_path(conference1.short_title, conference1.targets.first)) + visit admin_conference_emails_path(conference1.short_title) + expect(current_path).to eq(admin_conference_emails_path(conference1.short_title)) - visit admin_conference_program_tracks_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_tracks_path(conference1.short_title)) + visit admin_conference_resources_path(conference1.short_title) + expect(current_path).to eq(admin_conference_resources_path(conference1.short_title)) - visit admin_conference_roles_path(conference1.short_title) - expect(current_path).to eq(admin_conference_roles_path(conference1.short_title)) + visit new_admin_conference_resource_path(conference1.short_title) + expect(current_path).to eq(new_admin_conference_resource_path(conference1.short_title)) - visit admin_conference_emails_path(conference1.short_title) - expect(current_path).to eq(admin_conference_emails_path(conference1.short_title)) + create(:resource, conference: conference1) + visit edit_admin_conference_resource_path(conference1.short_title, conference1.resources.first) + expect(current_path).to eq(edit_admin_conference_resource_path(conference1.short_title, conference1.resources.first)) - visit admin_conference_resources_path(conference1.short_title) - expect(current_path).to eq(admin_conference_resources_path(conference1.short_title)) - - visit new_admin_conference_resource_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_resource_path(conference1.short_title)) - - create(:resource, conference: conference1) - visit edit_admin_conference_resource_path(conference1.short_title, conference1.resources.first) - expect(current_path).to eq(edit_admin_conference_resource_path(conference1.short_title, conference1.resources.first)) - - visit admin_revision_history_path - expect(current_path).to eq(admin_revision_history_path) + visit admin_revision_history_path + expect(current_path).to eq(admin_revision_history_path) + end end - scenario 'when user is cfp' do - sign_in user_cfp + context 'when user is organization_admin' do + before do + sign_in user_organization_admin + end - visit admin_conference_path(conference2.short_title) - expect(current_path).to eq(admin_conference_path(conference2.short_title)) + scenario 'can manage organization' do + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) - expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') - expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference2.short_title}/edit") - expect(page).to have_text('Basics') - expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference2.short_title}/contact/edit") - expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference2.short_title}/commercials") - expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference2.short_title}/splashpage") - expect(page).to have_link('Venue', href: "/admin/conferences/#{conference2.short_title}/venue") - expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference2.short_title}/venue/rooms") - expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference2.short_title}/lodgings") - expect(page).to have_link('Program', href: "/admin/conferences/#{conference2.short_title}/program") - expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference2.short_title}/program/cfps") - expect(page).to have_link('Events', href: "/admin/conferences/#{conference2.short_title}/program/events") - expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference2.short_title}/program/tracks") - expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference2.short_title}/program/event_types") - expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference2.short_title}/program/difficulty_levels") - expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference2.short_title}/schedules") - expect(page).to have_link('Reports', href: "/admin/conferences/#{conference2.short_title}/program/reports") - expect(page).to_not have_link('Registrations', href: "/admin/conferences/#{conference2.short_title}/registrations") - expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference2.short_title}/registration_period") - expect(page).to_not have_link('Questions', href: "/admin/conferences/#{conference2.short_title}/questions") - expect(page).to_not have_text('Donations') - expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference2.short_title}/supporter_levels") - expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference2.short_title}/sponsors") - expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference2.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference2.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference2.short_title}/targets") - expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference2.short_title}/emails") - expect(page).to have_link('Roles', href: "/admin/conferences/#{conference2.short_title}/roles") - expect(page).to have_link('Resources', href: "/admin/conferences/#{conference2.short_title}/resources") + visit edit_admin_organization_path(organization) + expect(current_path).to eq(edit_admin_organization_path(organization)) - visit edit_admin_conference_path(conference2.short_title) - expect(current_path).to eq(root_path) + visit new_admin_organization_path + expect(current_path).to eq(root_path) + end - visit edit_admin_conference_contact_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_commercials_path(conference2.short_title) - expect(current_path).to eq(admin_conference_commercials_path(conference2.short_title)) - - visit new_admin_conference_splashpage_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit edit_admin_conference_splashpage_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_venue_path(conference2.short_title) - expect(current_path).to eq(root_path) - - conference2.venue = create(:venue) - visit edit_admin_conference_venue_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_venue_rooms_path(conference2.short_title) - expect(current_path).to eq(admin_conference_venue_rooms_path(conference2.short_title)) - create(:room, venue: conference2.venue) - visit edit_admin_conference_venue_room_path(conference2.short_title, conference2.venue.rooms.first) - expect(current_path).to eq(edit_admin_conference_venue_room_path(conference2.short_title, conference2.venue.rooms.first)) - - visit admin_conference_lodgings_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_lodging_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:lodging, conference: conference2) - visit edit_admin_conference_lodging_path(conference2.short_title, conference2.lodgings.first) - expect(current_path).to eq(root_path) - - visit new_admin_conference_program_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_path(conference2.short_title)) - - visit edit_admin_conference_program_path(conference2.short_title) - expect(current_path).to eq(edit_admin_conference_program_path(conference2.short_title)) - - visit new_admin_conference_program_cfp_path(conference2.short_title) - expect(current_path).to eq root_path - - conference2.program.cfp.destroy! - visit new_admin_conference_program_cfp_path(conference2.short_title) - expect(current_path).to eq new_admin_conference_program_cfp_path(conference2.short_title) - create(:cfp, program: conference2.program) - - visit edit_admin_conference_program_cfp_path(conference2.short_title, conference2.program.cfp) - expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference2.short_title, conference2.program.cfp)) - - visit admin_conference_program_events_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_events_path(conference2.short_title)) - - create(:event, program: conference2.program) - visit edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first) - expect(current_path).to eq(edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first)) - - visit admin_conference_program_event_types_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_event_types_path(conference2.short_title)) - - visit new_admin_conference_program_event_type_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_event_type_path(conference2.short_title)) - - visit edit_admin_conference_program_event_type_path(conference2.short_title, conference2.program.event_types.first) - expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference2.short_title, conference2.program.event_types.first)) - - visit admin_conference_program_difficulty_levels_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference2.short_title)) - - visit new_admin_conference_program_difficulty_level_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference2.short_title)) - - visit edit_admin_conference_program_difficulty_level_path(conference2.short_title, conference2.program.difficulty_levels.first) - expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference2.short_title, conference2.program.difficulty_levels.first)) - - visit admin_conference_schedules_path(conference2.short_title) - expect(current_path).to eq(admin_conference_schedules_path(conference2.short_title)) - - create(:schedule, program: conference2.program) - visit admin_conference_schedule_path(conference2.short_title, conference2.program.schedules.first) - expect(current_path).to eq(admin_conference_schedule_path(conference2.short_title, conference2.program.schedules.first)) - - visit admin_conference_program_reports_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_reports_path(conference2.short_title)) - - visit admin_conference_registrations_path(conference2.short_title) - expect(current_path).to eq(admin_conference_registrations_path(conference2.short_title)) - - create(:registration, user: create(:user), conference: conference2) - visit edit_admin_conference_registration_path(conference2.short_title, conference2.registrations.first) - expect(current_path).to eq(root_path) - - visit new_admin_conference_registration_period_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:registration_period, conference: conference2) - visit edit_admin_conference_registration_period_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_questions_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 new_admin_conference_sponsorship_level_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:sponsorship_level, conference: conference2) - visit edit_admin_conference_sponsorship_level_path(conference2.short_title, conference2.sponsorship_levels.first) - expect(current_path).to eq(root_path) - - visit admin_conference_sponsors_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_sponsor_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:sponsor, conference: conference2, sponsorship_level: conference2.sponsorship_levels.first) - visit edit_admin_conference_sponsor_path(conference2.short_title, conference2.sponsors.first) - expect(current_path).to eq(root_path) - - visit admin_conference_tickets_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_ticket_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:ticket, conference: conference2) - visit edit_admin_conference_ticket_path(conference2.short_title, conference2.tickets.first) - expect(current_path).to eq(root_path) - - visit admin_conference_campaigns_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_campaign_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:campaign, conference: conference2) - visit edit_admin_conference_campaign_path(conference2.short_title, conference2.campaigns.first) - expect(current_path).to eq(root_path) - - visit admin_conference_targets_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_target_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:target, conference: conference2) - visit edit_admin_conference_target_path(conference2.short_title, conference2.targets.first) - expect(current_path).to eq(root_path) - - visit admin_conference_program_tracks_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_tracks_path(conference2.short_title)) - - visit admin_conference_roles_path(conference2.short_title) - expect(current_path).to eq(admin_conference_roles_path(conference2.short_title)) - - visit admin_conference_emails_path(conference2.short_title) - expect(current_path).to eq(admin_conference_emails_path(conference2.short_title)) - - visit admin_conference_resources_path(conference2.short_title) - expect(current_path).to eq(admin_conference_resources_path(conference2.short_title)) - - visit new_admin_conference_resource_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_resource_path(conference2.short_title)) - - create(:resource, conference: conference2) - visit edit_admin_conference_resource_path(conference2.short_title, conference2.resources.first) - expect(current_path).to eq(edit_admin_conference_resource_path(conference2.short_title, conference2.resources.first)) - - visit admin_revision_history_path - expect(current_path).to eq(root_path) + it_behaves_like 'correct abilities for organizers and organization_admin' end - scenario 'when user is info desk' do - sign_in user_info_desk + context 'when user is organizer' do + before do + sign_in user_organizer + end - visit admin_conference_path(conference3.short_title) - expect(current_path).to eq(admin_conference_path(conference3.short_title)) + scenario 'cannot manage organization' do + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) - expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') - expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference3.short_title}/edit") - expect(page).to have_text('Basics') - expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference3.short_title}/contact/edit") - expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference3.short_title}/commercials") - expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference3.short_title}/splashpage") - expect(page).to_not have_link('Venue', href: "/admin/conferences/#{conference3.short_title}/venue") - expect(page).to_not have_link('Rooms', href: "/admin/conferences/#{conference3.short_title}/venue/rooms") - expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference3.short_title}/lodgings") - expect(page).to_not have_link('Program', href: "/admin/conferences/#{conference3.short_title}/program") - expect(page).to_not have_link('Call for Papers', href: "/admin/conferences/#{conference2.short_title}/program/cfp") - expect(page).to_not have_link('Events', href: "/admin/conferences/#{conference3.short_title}/program/events") - expect(page).to_not have_link('Tracks', href: "/admin/conferences/#{conference3.short_title}/program/tracks") - expect(page).to_not have_link('Event Types', href: "/admin/conferences/#{conference3.short_title}/program/event_types") - expect(page).to_not have_link('Difficulty Levels', href: "/admin/conferences/#{conference3.short_title}/program/difficulty_levels") - expect(page).to_not have_link('Schedules', href: "/admin/conferences/#{conference3.short_title}/schedules") - expect(page).to_not have_link('Reports', href: "/admin/conferences/#{conference3.short_title}/program/reports") - expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference3.short_title}/registrations") - expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference3.short_title}/registration_period") - expect(page).to have_link('Questions', href: "/admin/conferences/#{conference3.short_title}/questions") - expect(page).to_not have_text('Donations') - expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference3.short_title}/sponsorship_levels") - expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference3.short_title}/sponsors") - expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference3.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference3.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference3.short_title}/targets") - expect(page).to_not have_link('E-Mails', href: "/admin/conferences/#{conference3.short_title}/emails") - expect(page).to have_link('Roles', href: "/admin/conferences/#{conference3.short_title}/roles") - expect(page).to have_link('Resources', href: "/admin/conferences/#{conference3.short_title}/resources") + visit edit_admin_organization_path(organization) + expect(current_path).to eq(root_path) - visit edit_admin_conference_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_organization_path + expect(current_path).to eq(root_path) + end - visit edit_admin_conference_contact_path(conference3.short_title) - expect(current_path).to eq(root_path) + it_behaves_like 'correct abilities for organizers and organization_admin' + end - visit admin_conference_commercials_path(conference3.short_title) - expect(current_path).to eq(admin_conference_commercials_path(conference3.short_title)) + shared_examples 'correct abilities for cfps and info_desk' do |role| + scenario 'correct ability' do + if role == 'cfp' + conference = conference2 + elsif role == 'info_desk' + conference = conference3 + end - visit new_admin_conference_splashpage_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) - visit edit_admin_conference_splashpage_path(conference3.short_title) - expect(current_path).to eq(root_path) + expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference.short_title}/edit") + expect(page).to have_text('Basics') + expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference.short_title}/commercials") + expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference.short_title}/splashpage") + expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference.short_title}/lodgings") + expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference.short_title}/registration_period") + expect(page).to_not have_text('Donations') + expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") + expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") + expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") + expect(page).to_not have_text('Objectives') + expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") + expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") - visit new_admin_conference_venue_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) - conference3.venue = create(:venue) - visit edit_admin_conference_venue_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit edit_admin_organization_path(organization) + expect(current_path).to eq(root_path) - visit admin_conference_venue_rooms_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_organization_path + expect(current_path).to eq(root_path) - create(:room, venue: conference3.venue) - visit edit_admin_conference_venue_room_path(conference3.short_title, conference3.venue.rooms.first) - expect(current_path).to eq(root_path) + visit edit_admin_conference_path(conference.short_title) + expect(current_path).to eq(root_path) - visit admin_conference_lodgings_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit edit_admin_conference_contact_path(conference.short_title) + expect(current_path).to eq(root_path) - visit new_admin_conference_lodging_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_commercials_path(conference.short_title) + expect(current_path).to eq(admin_conference_commercials_path(conference.short_title)) - create(:lodging, conference: conference3) - visit edit_admin_conference_lodging_path(conference3.short_title, conference3.lodgings.first) - expect(current_path).to eq(root_path) + visit new_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(root_path) - visit new_admin_conference_program_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit edit_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(root_path) - visit edit_admin_conference_program_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(root_path) - visit new_admin_conference_program_cfp_path(conference3.short_title) - expect(current_path).to eq(root_path) + conference.venue = create(:venue) + visit edit_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(root_path) - visit edit_admin_conference_program_cfp_path(conference3.short_title, conference3.program.cfp) - expect(current_path).to eq(root_path) + visit admin_conference_lodgings_path(conference.short_title) + expect(current_path).to eq(root_path) - visit admin_conference_program_events_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_lodging_path(conference.short_title) + expect(current_path).to eq(root_path) - create(:event, program: conference3.program) - visit edit_admin_conference_program_event_path(conference3.short_title, conference3.program.events.first) - expect(current_path).to eq(root_path) + create(:lodging, conference: conference) + visit edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first) + expect(current_path).to eq(root_path) - visit admin_conference_program_event_types_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) - visit new_admin_conference_program_event_type_path(conference3.short_title) - expect(current_path).to eq(root_path) + create(:registration_period, conference: conference) + visit edit_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) - visit edit_admin_conference_program_event_type_path(conference3.short_title, conference3.program.event_types.first) - expect(current_path).to eq(root_path) + visit admin_conference_sponsorship_levels_path(conference.short_title) + expect(current_path).to eq(root_path) - visit admin_conference_program_difficulty_levels_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_sponsorship_level_path(conference.short_title) + expect(current_path).to eq(root_path) - visit new_admin_conference_program_difficulty_level_path(conference3.short_title) - expect(current_path).to eq(root_path) + create(:sponsorship_level, conference: conference) + visit edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first) + expect(current_path).to eq(root_path) - visit edit_admin_conference_program_difficulty_level_path(conference3.short_title, conference3.program.difficulty_levels.first) - expect(current_path).to eq(root_path) + visit admin_conference_sponsors_path(conference.short_title) + expect(current_path).to eq(root_path) - visit admin_conference_schedules_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_sponsor_path(conference.short_title) + expect(current_path).to eq(root_path) - create(:schedule, program: conference3.program) - visit admin_conference_schedule_path(conference3.short_title, conference3.program.schedules.first) - expect(current_path).to eq(root_path) + create(:sponsor, conference: conference, sponsorship_level: conference.sponsorship_levels.first) + visit edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first) + expect(current_path).to eq(root_path) - visit admin_conference_program_reports_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_tickets_path(conference.short_title) + expect(current_path).to eq(root_path) - visit admin_conference_registrations_path(conference3.short_title) - expect(current_path).to eq(admin_conference_registrations_path(conference3.short_title)) + visit new_admin_conference_ticket_path(conference.short_title) + expect(current_path).to eq(root_path) - create(:registration, user: create(:user), conference: conference3) - visit edit_admin_conference_registration_path(conference3.short_title, conference3.registrations.first) - expect(current_path).to eq(edit_admin_conference_registration_path(conference3.short_title, conference3.registrations.first)) + create(:ticket, conference: conference) + visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) + expect(current_path).to eq(root_path) - visit new_admin_conference_registration_period_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_campaigns_path(conference.short_title) + expect(current_path).to eq(root_path) - create(:registration_period, conference: conference3) - visit edit_admin_conference_registration_period_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_campaign_path(conference.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)) + create(:campaign, conference: conference) + visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) + 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_targets_path(conference.short_title) + expect(current_path).to eq(root_path) - visit new_admin_conference_sponsorship_level_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_target_path(conference.short_title) + expect(current_path).to eq(root_path) - create(:sponsorship_level, conference: conference3) - visit edit_admin_conference_sponsorship_level_path(conference3.short_title, conference3.sponsorship_levels.first) - expect(current_path).to eq(root_path) + create(:target, conference: conference) + visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) + expect(current_path).to eq(root_path) - visit admin_conference_sponsors_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_roles_path(conference.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) - visit new_admin_conference_sponsor_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_resources_path(conference.short_title) + expect(current_path).to eq(admin_conference_resources_path(conference.short_title)) - create(:sponsor, conference: conference3, sponsorship_level: conference3.sponsorship_levels.first) - visit edit_admin_conference_sponsor_path(conference3.short_title, conference3.sponsors.first) - expect(current_path).to eq(root_path) + visit new_admin_conference_resource_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_resource_path(conference.short_title)) - visit admin_conference_tickets_path(conference3.short_title) - expect(current_path).to eq(root_path) + create(:resource, conference: conference) + visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) + expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) - visit new_admin_conference_ticket_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_revision_history_path + expect(current_path).to eq(root_path) + end + end - create(:ticket, conference: conference3) - visit edit_admin_conference_ticket_path(conference3.short_title, conference3.tickets.first) - expect(current_path).to eq(root_path) + context 'when user is cfp' do + before do + sign_in user_cfp + @conference = conference2 + end + scenario 'has correct abilities' do + visit admin_conference_path(conference2.short_title) + expect(current_path).to eq(admin_conference_path(conference2.short_title)) - visit admin_conference_campaigns_path(conference3.short_title) - expect(current_path).to eq(root_path) + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference2.short_title}/edit") + expect(page).to have_text('Basics') + expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference2.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference2.short_title}/commercials") + expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference2.short_title}/splashpage") + expect(page).to have_link('Venue', href: "/admin/conferences/#{conference2.short_title}/venue") + expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference2.short_title}/venue/rooms") + expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference2.short_title}/lodgings") + expect(page).to have_link('Program', href: "/admin/conferences/#{conference2.short_title}/program") + expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference2.short_title}/program/cfps") + expect(page).to have_link('Events', href: "/admin/conferences/#{conference2.short_title}/program/events") + expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference2.short_title}/program/tracks") + expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference2.short_title}/program/event_types") + expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference2.short_title}/program/difficulty_levels") + expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference2.short_title}/schedules") + expect(page).to have_link('Reports', href: "/admin/conferences/#{conference2.short_title}/program/reports") + expect(page).to_not have_link('Registrations', href: "/admin/conferences/#{conference2.short_title}/registrations") + expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference2.short_title}/registration_period") + expect(page).to_not have_link('Questions', href: "/admin/conferences/#{conference2.short_title}/questions") + expect(page).to_not have_text('Donations') + expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference2.short_title}/supporter_levels") + expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference2.short_title}/sponsors") + expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference2.short_title}/tickets") + expect(page).to_not have_text('Objectives') + expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference2.short_title}/campaigns") + expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference2.short_title}/targets") + expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference2.short_title}/emails") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference2.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference2.short_title}/resources") - visit new_admin_conference_campaign_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_venue_rooms_path(conference2.short_title) + expect(current_path).to eq(admin_conference_venue_rooms_path(conference2.short_title)) + create(:room, venue: conference2.venue) + visit edit_admin_conference_venue_room_path(conference2.short_title, conference2.venue.rooms.first) + expect(current_path).to eq(edit_admin_conference_venue_room_path(conference2.short_title, conference2.venue.rooms.first)) - create(:campaign, conference: conference3) - visit edit_admin_conference_campaign_path(conference3.short_title, conference3.campaigns.first) - expect(current_path).to eq(root_path) + visit new_admin_conference_program_path(conference2.short_title) + expect(current_path).to eq(new_admin_conference_program_path(conference2.short_title)) - visit admin_conference_targets_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit edit_admin_conference_program_path(conference2.short_title) + expect(current_path).to eq(edit_admin_conference_program_path(conference2.short_title)) - visit new_admin_conference_target_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit new_admin_conference_program_cfp_path(conference2.short_title) + expect(current_path).to eq(new_admin_conference_program_cfp_path(conference2.short_title)) - create(:target, conference: conference3) - visit edit_admin_conference_target_path(conference3.short_title, conference3.targets.first) - expect(current_path).to eq(root_path) + visit edit_admin_conference_program_cfp_path(conference2.short_title) + expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference2.short_title)) - visit admin_conference_program_tracks_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_program_events_path(conference2.short_title) + expect(current_path).to eq(admin_conference_program_events_path(conference2.short_title)) - visit admin_conference_roles_path(conference3.short_title) - expect(current_path).to eq(admin_conference_roles_path(conference3.short_title)) + create(:event, program: conference2.program) + visit edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first) + expect(current_path).to eq(edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first)) - visit admin_conference_emails_path(conference3.short_title) - expect(current_path).to eq(root_path) + visit admin_conference_program_event_types_path(conference2.short_title) + expect(current_path).to eq(admin_conference_program_event_types_path(conference2.short_title)) - visit admin_conference_resources_path(conference3.short_title) - expect(current_path).to eq(admin_conference_resources_path(conference3.short_title)) + visit new_admin_conference_program_event_type_path(conference2.short_title) + expect(current_path).to eq(new_admin_conference_program_event_type_path(conference2.short_title)) - visit new_admin_conference_resource_path(conference3.short_title) - expect(current_path).to eq(new_admin_conference_resource_path(conference3.short_title)) + visit edit_admin_conference_program_event_type_path(conference2.short_title, conference2.program.event_types.first) + expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference2.short_title, conference2.program.event_types.first)) - create(:resource, conference: conference3) - visit edit_admin_conference_resource_path(conference3.short_title, conference3.resources.first) - expect(current_path).to eq(edit_admin_conference_resource_path(conference3.short_title, conference3.resources.first)) + visit admin_conference_program_difficulty_levels_path(conference2.short_title) + expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference2.short_title)) - visit admin_revision_history_path - expect(current_path).to eq(root_path) + visit new_admin_conference_program_difficulty_level_path(conference2.short_title) + expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference2.short_title)) + + visit edit_admin_conference_program_difficulty_level_path(conference2.short_title, conference2.program.difficulty_levels.first) + expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference2.short_title, conference2.program.difficulty_levels.first)) + + visit admin_conference_schedules_path(conference2.short_title) + expect(current_path).to eq(admin_conference_schedules_path(conference2.short_title)) + + create(:schedule, program: conference2.program) + visit admin_conference_schedule_path(conference2.short_title, conference2.program.schedules.first) + expect(current_path).to eq(admin_conference_schedule_path(conference2.short_title, conference2.program.schedules.first)) + + visit admin_conference_program_reports_path(conference2.short_title) + expect(current_path).to eq(admin_conference_program_reports_path(conference2.short_title)) + + visit admin_conference_registrations_path(conference2.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference2.short_title)) + + create(:registration, user: create(:user), conference: conference2) + visit edit_admin_conference_registration_path(conference2.short_title, conference2.registrations.first) + expect(current_path).to eq(root_path) + + visit new_admin_conference_registration_period_path(conference2.short_title) + expect(current_path).to eq(root_path) + + create(:registration_period, conference: conference2) + visit edit_admin_conference_registration_period_path(conference2.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_questions_path(conference2.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_program_tracks_path(conference2.short_title) + expect(current_path).to eq(admin_conference_program_tracks_path(conference2.short_title)) + + visit admin_conference_roles_path(conference2.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference2.short_title)) + + visit admin_conference_emails_path(conference2.short_title) + expect(current_path).to eq(admin_conference_emails_path(conference2.short_title)) + end + + it_behaves_like 'correct abilities for cfps and info_desk', 'cfp' + end + + context 'when user is info desk' do + before do + sign_in user_info_desk + end + + scenario 'has correct abilities' do + visit admin_conference_path(conference3.short_title) + expect(current_path).to eq(admin_conference_path(conference3.short_title)) + + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to_not have_link('Venue', href: "/admin/conferences/#{conference3.short_title}/venue") + expect(page).to_not have_link('Rooms', href: "/admin/conferences/#{conference3.short_title}/venue/rooms") + expect(page).to_not have_link('Program', href: "/admin/conferences/#{conference3.short_title}/program") + expect(page).to_not have_link('Call for Papers', href: "/admin/conferences/#{conference2.short_title}/program/cfps") + expect(page).to_not have_link('Events', href: "/admin/conferences/#{conference3.short_title}/program/events") + expect(page).to_not have_link('Tracks', href: "/admin/conferences/#{conference3.short_title}/program/tracks") + expect(page).to_not have_link('Event Types', href: "/admin/conferences/#{conference3.short_title}/program/event_types") + expect(page).to_not have_link('Difficulty Levels', href: "/admin/conferences/#{conference3.short_title}/program/difficulty_levels") + expect(page).to_not have_link('Schedules', href: "/admin/conferences/#{conference3.short_title}/schedules") + expect(page).to_not have_link('Reports', href: "/admin/conferences/#{conference3.short_title}/program/reports") + expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference3.short_title}/registrations") + expect(page).to have_link('Questions', href: "/admin/conferences/#{conference3.short_title}/questions") + expect(page).to_not have_link('E-Mails', href: "/admin/conferences/#{conference3.short_title}/emails") + + visit admin_conference_venue_rooms_path(conference3.short_title) + expect(current_path).to eq(root_path) + + create(:room, venue: conference3.venue) + visit edit_admin_conference_venue_room_path(conference3.short_title, conference3.venue.rooms.first) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_cfp_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_cfp_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_program_events_path(conference3.short_title) + expect(current_path).to eq(root_path) + + create(:event, program: conference3.program) + visit edit_admin_conference_program_event_path(conference3.short_title, conference3.program.events.first) + expect(current_path).to eq(root_path) + + visit admin_conference_program_event_types_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_event_type_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_event_type_path(conference3.short_title, conference3.program.event_types.first) + expect(current_path).to eq(root_path) + + visit admin_conference_program_difficulty_levels_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_difficulty_level_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_difficulty_level_path(conference3.short_title, conference3.program.difficulty_levels.first) + expect(current_path).to eq(root_path) + + visit admin_conference_schedules_path(conference3.short_title) + expect(current_path).to eq(root_path) + + create(:schedule, program: conference3.program) + visit admin_conference_schedule_path(conference3.short_title, conference3.program.schedules.first) + expect(current_path).to eq(root_path) + + visit admin_conference_program_reports_path(conference3.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_registrations_path(conference3.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference3.short_title)) + + create(:registration, user: create(:user), conference: conference3) + visit edit_admin_conference_registration_path(conference3.short_title, conference3.registrations.first) + expect(current_path).to eq(edit_admin_conference_registration_path(conference3.short_title, conference3.registrations.first)) + + visit admin_conference_questions_path(conference3.short_title) + expect(current_path).to eq(admin_conference_questions_path(conference3.short_title)) + + visit admin_conference_program_tracks_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) + end + + it_behaves_like 'correct abilities for cfps and info_desk', 'info_desk' end end diff --git a/spec/features/organization_spec.rb b/spec/features/organization_spec.rb new file mode 100644 index 00000000..72fee466 --- /dev/null +++ b/spec/features/organization_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +feature Organization do + let!(:organization) { create(:organization) } + let!(:organization_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } + let(:organization_admin) { create(:user, role_ids: [organization_admin_role.id]) } + let(:admin_user) { create(:admin) } + + shared_examples 'successfully updates a organization' do + scenario 'updates a exsisting organization', feature: true, js: true do + visit edit_admin_organization_path(organization) + fill_in 'organization_name', with: 'changed name' + + click_button 'Update Organization' + + organization.reload + expect(flash).to eq('Organization successfully updated') + expect(organization.name).to eq('changed name') + end + end + + context 'signed in as site admin' do + before do + sign_in admin_user + end + scenario 'creates a new organization', feature: true, js: true do + visit new_admin_organization_path + fill_in 'organization_name', with: 'Organization name' + + click_button 'Create Organization' + + expect(flash).to eq('Organization successfully created') + expect(Organization.last.name).to eq('Organization name') + end + + it_behaves_like 'successfully updates a organization' + end + + context 'signed in as organization admin' do + before do + sign_in organization_admin + end + scenario "can't create new organization", feature: true, js: true do + visit new_admin_organization_path + + expect(flash).to eq('You are not authorized to access this page.') + end + + it_behaves_like 'successfully updates a organization' + end +end From 3daa12f83fdbc9a44ea6c14d7843501262478721 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 28 Jun 2017 08:05:04 +0530 Subject: [PATCH 07/11] fix tests for cfps after rebase --- spec/features/ability_spec.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/spec/features/ability_spec.rb b/spec/features/ability_spec.rb index 41775de4..915ce401 100644 --- a/spec/features/ability_spec.rb +++ b/spec/features/ability_spec.rb @@ -114,12 +114,12 @@ feature 'Has correct abilities' do visit new_admin_conference_program_cfp_path(conference1.short_title) expect(current_path).to eq root_path - + conference1.program.cfp.destroy! visit new_admin_conference_program_cfp_path(conference1.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference1.short_title) create(:cfp, program: conference1.program) - + visit edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp) expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp)) @@ -484,13 +484,15 @@ feature 'Has correct abilities' do expect(current_path).to eq(edit_admin_conference_program_path(conference2.short_title)) visit new_admin_conference_program_cfp_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_cfp_path(conference2.short_title)) + expect(current_path).to eq root_path - visit edit_admin_conference_program_cfp_path(conference2.short_title) - expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference2.short_title)) + conference2.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference2.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference2.short_title) + create(:cfp, program: conference2.program) - visit admin_conference_program_events_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_events_path(conference2.short_title)) + visit edit_admin_conference_program_cfp_path(conference2.short_title, conference2.program.cfp) + expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference2.short_title, conference2.program.cfp)) create(:event, program: conference2.program) visit edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first) @@ -592,9 +594,14 @@ feature 'Has correct abilities' do expect(current_path).to eq(root_path) visit new_admin_conference_program_cfp_path(conference3.short_title) - expect(current_path).to eq(root_path) + expect(current_path).to eq root_path - visit edit_admin_conference_program_cfp_path(conference3.short_title) + conference1.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference3.short_title) + expect(current_path).to eq root_path + create(:cfp, program: conference1.program) + + visit edit_admin_conference_program_cfp_path(conference3.short_title, conference3.program.cfp) expect(current_path).to eq(root_path) visit admin_conference_program_events_path(conference3.short_title) From 651abcab87cf1699fba41f9c31eb1a314046059b Mon Sep 17 00:00:00 2001 From: shlok007 Date: Fri, 30 Jun 2017 09:18:17 +0530 Subject: [PATCH 08/11] split feature tests for abilities and suggested changes --- app/models/ability.rb | 73 +- spec/features/ability_spec.rb | 661 ------------------ spec/features/cfp_ability_spec.rb | 250 +++++++ spec/features/info_desk_ability_spec.rb | 246 +++++++ .../organization_admin_ability_spec.rb | 240 +++++++ spec/features/organizer_ability_spec.rb | 247 +++++++ spec/features/user_ability_spec.rb | 21 + spec/models/ability_spec.rb | 42 +- 8 files changed, 1059 insertions(+), 721 deletions(-) delete mode 100644 spec/features/ability_spec.rb create mode 100644 spec/features/cfp_ability_spec.rb create mode 100644 spec/features/info_desk_ability_spec.rb create mode 100644 spec/features/organization_admin_ability_spec.rb create mode 100644 spec/features/organizer_ability_spec.rb create mode 100644 spec/features/user_ability_spec.rb diff --git a/app/models/ability.rb b/app/models/ability.rb index 37090a49..8185fadd 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -154,10 +154,7 @@ class Ability can :manage, Organization, id: org_ids_for_organization_admin can :new, Conference can :manage, Conference, organization_id: org_ids_for_organization_admin - conf_ids_for_organization_admin = [] - org_ids_for_organization_admin.each do |org_id| - conf_ids_for_organization_admin += Organization.find(org_id).conferences.pluck(:id) - end + conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id) can [:index, :show], Role can [:edit, :update], Role do |role| role.resource_type == 'Organization' && (org_ids_for_organization_admin.include? role.resource_id) @@ -168,44 +165,44 @@ class Ability def signed_in_with_organizer_role(user, conf_ids_for_organization_admin = []) # ids of all the conferences for which the user has the 'organizer' role and # conferences that belong to organizations for which user is 'organization_admin' - conf_ids_for_organization_admin_and_organizer = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq - can :manage, Resource, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Conference, id: conf_ids_for_organization_admin_and_organizer - can :manage, Splashpage, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Contact, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, EmailSettings, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Campaign, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Target, conference_id: conf_ids_for_organization_admin_and_organizer + conf_ids = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq + can :manage, Resource, conference_id: conf_ids + can :manage, Conference, id: conf_ids + can :manage, Splashpage, conference_id: conf_ids + can :manage, Contact, conference_id: conf_ids + can :manage, EmailSettings, conference_id: conf_ids + can :manage, Campaign, conference_id: conf_ids + can :manage, Target, conference_id: conf_ids can :manage, Commercial, commercialable_type: 'Conference', - commercialable_id: conf_ids_for_organization_admin_and_organizer - can :manage, Registration, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, RegistrationPeriod, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Question, conference_id: conf_ids_for_organization_admin_and_organizer + commercialable_id: conf_ids + can :manage, Registration, conference_id: conf_ids + can :manage, RegistrationPeriod, conference_id: conf_ids + can :manage, Question, conference_id: conf_ids can :manage, Question do |question| - !(question.conferences.pluck(:id) & conf_ids_for_organization_admin_and_organizer).empty? + !(question.conferences.pluck(:id) & conf_ids).empty? end - can :manage, Vposition, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Vday, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Program, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Schedule, program: { conference_id: conf_ids_for_organization_admin_and_organizer } - can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids_for_organization_admin_and_organizer } } - can :manage, Cfp, program: { conference_id: conf_ids_for_organization_admin_and_organizer} - can :manage, Event, program: { conference_id: conf_ids_for_organization_admin_and_organizer} - can :manage, EventType, program: { conference_id: conf_ids_for_organization_admin_and_organizer} - can :manage, Track, program: { conference_id: conf_ids_for_organization_admin_and_organizer} - can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_organization_admin_and_organizer} + can :manage, Vposition, conference_id: conf_ids + can :manage, Vday, conference_id: conf_ids + can :manage, Program, conference_id: conf_ids + can :manage, Schedule, program: { conference_id: conf_ids } + can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids } } + can :manage, Cfp, program: { conference_id: conf_ids} + can :manage, Event, program: { conference_id: conf_ids} + can :manage, EventType, program: { conference_id: conf_ids} + can :manage, Track, program: { conference_id: conf_ids} + can :manage, DifficultyLevel, program: { conference_id: conf_ids} can :manage, Commercial, commercialable_type: 'Event', - commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id) - can :manage, Venue, conference_id: conf_ids_for_organization_admin_and_organizer + commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id) + can :manage, Venue, conference_id: conf_ids can :manage, Commercial, commercialable_type: 'Venue', - commercialable_id: Venue.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id) - can :manage, Lodging, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Room, venue: { conference_id: conf_ids_for_organization_admin_and_organizer} - can :manage, Sponsor, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, SponsorshipLevel, conference_id: conf_ids_for_organization_admin_and_organizer - can :manage, Ticket, conference_id: conf_ids_for_organization_admin_and_organizer + commercialable_id: Venue.where(conference_id: conf_ids).pluck(:id) + can :manage, Lodging, conference_id: conf_ids + can :manage, Room, venue: { conference_id: conf_ids} + can :manage, Sponsor, conference_id: conf_ids + can :manage, SponsorshipLevel, conference_id: conf_ids + can :manage, Ticket, conference_id: conf_ids can :index, Comment, commentable_type: 'Event', - commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organization_admin_and_organizer).pluck(:id)).pluck(:id) + commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id) # Abilities for Role (Conference resource) can [:index, :show], Role do |role| @@ -213,11 +210,11 @@ class Ability end can [:edit, :update, :toggle_user], Role do |role| - role.resource_type == 'Conference' && (conf_ids_for_organization_admin_and_organizer.include? role.resource_id) + role.resource_type == 'Conference' && (conf_ids.include? role.resource_id) end can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version| - version.item_type == 'User' || (conf_ids_for_organization_admin_and_organizer.include? version.conference_id) + version.item_type == 'User' || (conf_ids.include? version.conference_id) end end diff --git a/spec/features/ability_spec.rb b/spec/features/ability_spec.rb deleted file mode 100644 index 915ce401..00000000 --- a/spec/features/ability_spec.rb +++ /dev/null @@ -1,661 +0,0 @@ -require 'spec_helper' - -feature 'Has correct abilities' do - - let(:organization) { create(:organization) } - # It is necessary to use bang version of let to build roles before user - let(:conference1) { create(:full_conference, organization: organization) } # user is organizer - let(:conference2) { create(:full_conference, organization: organization) } # user is cfp - let(:conference3) { create(:full_conference, organization: organization) } # user is info_desk - let(:conference6) { create(:conference, organization: organization) } # user is organizer, venue is not set by default - - let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) } - let(:role_organizer_conf1) { Role.find_by(name: 'organizer', resource: conference1) } - let(:role_organizer_conf6) { Role.find_by(name: 'organizer', resource: conference6) } - let(:role_cfp) { Role.find_by(name: 'cfp', resource: conference2) } - let(:role_info_desk) { Role.find_by(name: 'info_desk', resource: conference3) } - - let(:user) { create(:user) } - let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) } - let(:user_organizer) { create(:user, role_ids: [role_organizer_conf1.id, role_organizer_conf6.id]) } - let(:user_cfp) { create(:user, role_ids: [role_cfp.id]) } - let(:user_info_desk) { create(:user, role_ids: [role_info_desk.id]) } - - scenario 'when user has no role' do - sign_in user - - visit admin_conference_path(conference1.short_title) - expect(current_path).to eq root_path - expect(flash).to eq 'You are not authorized to access this page.' - end - - shared_examples 'correct abilities for organizers and organization_admin' do - scenario 'for conference attributes' do - visit admin_conference_path(conference1.short_title) - expect(current_path).to eq(admin_conference_path(conference1.short_title)) - - expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') - expect(page).to have_link('Basics', href: "/admin/conferences/#{conference1.short_title}/edit") - expect(page).to have_link('Contact', href: "/admin/conferences/#{conference1.short_title}/contact/edit") - expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference1.short_title}/commercials") - expect(page).to have_link('Splashpage', href: "/admin/conferences/#{conference1.short_title}/splashpage") - expect(page).to have_link('Venue', href: "/admin/conferences/#{conference1.short_title}/venue") - expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference1.short_title}/venue/rooms") - expect(page).to have_link('Lodgings', href: "/admin/conferences/#{conference1.short_title}/lodgings") - expect(page).to have_link('Program', href: "/admin/conferences/#{conference1.short_title}/program") - expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference1.short_title}/program/cfps") - expect(page).to have_link('Events', href: "/admin/conferences/#{conference1.short_title}/program/events") - expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference1.short_title}/program/tracks") - expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference1.short_title}/program/event_types") - expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference1.short_title}/program/difficulty_levels") - expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference1.short_title}/schedules") - expect(page).to have_link('Reports', href: "/admin/conferences/#{conference1.short_title}/program/reports") - expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference1.short_title}/registrations") - expect(page).to have_link('Registration Period', href: "/admin/conferences/#{conference1.short_title}/registration_period") - expect(page).to have_link('Questions', href: "/admin/conferences/#{conference1.short_title}/questions") - expect(page).to have_text('Donations') - expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference1.short_title}/sponsorship_levels") - expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference1.short_title}/sponsors") - expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference1.short_title}/tickets") - expect(page).to have_text('Objectives') - expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference1.short_title}/campaigns") - expect(page).to have_link('Goals', href: "/admin/conferences/#{conference1.short_title}/targets") - expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference1.short_title}/emails") - expect(page).to have_link('Roles', href: "/admin/conferences/#{conference1.short_title}/roles") - expect(page).to have_link('Resources', href: "/admin/conferences/#{conference1.short_title}/resources") - - visit admin_conference_path(conference6.short_title) - expect(page).to have_link('Add venue', href: "/admin/conferences/#{conference6.short_title}/venue/new") - - visit edit_admin_conference_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_path(conference1.short_title)) - - visit edit_admin_conference_contact_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_contact_path(conference1.short_title)) - - visit admin_conference_commercials_path(conference1.short_title) - expect(current_path).to eq(admin_conference_commercials_path(conference1.short_title)) - - visit new_admin_conference_splashpage_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_splashpage_path(conference1.short_title)) - - visit edit_admin_conference_splashpage_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_splashpage_path(conference1.short_title)) - - visit new_admin_conference_venue_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_venue_path(conference1.short_title)) - - conference1.venue = create(:venue) - visit edit_admin_conference_venue_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_venue_path(conference1.short_title)) - - visit admin_conference_venue_rooms_path(conference1.short_title) - expect(current_path).to eq(admin_conference_venue_rooms_path(conference1.short_title)) - - create(:room, venue: conference1.venue) - visit edit_admin_conference_venue_room_path(conference1.short_title, conference1.venue.rooms.first) - expect(current_path).to eq(edit_admin_conference_venue_room_path(conference1.short_title, conference1.venue.rooms.first)) - - visit admin_conference_lodgings_path(conference1.short_title) - expect(current_path).to eq(admin_conference_lodgings_path(conference1.short_title)) - - visit new_admin_conference_lodging_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_lodging_path(conference1.short_title)) - - create(:lodging, conference: conference1) - visit edit_admin_conference_lodging_path(conference1.short_title, conference1.lodgings.first) - expect(current_path).to eq(edit_admin_conference_lodging_path(conference1.short_title, conference1.lodgings.first)) - - visit new_admin_conference_program_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_program_path(conference1.short_title)) - - visit edit_admin_conference_program_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_program_path(conference1.short_title)) - - visit new_admin_conference_program_cfp_path(conference1.short_title) - expect(current_path).to eq root_path - - conference1.program.cfp.destroy! - visit new_admin_conference_program_cfp_path(conference1.short_title) - expect(current_path).to eq new_admin_conference_program_cfp_path(conference1.short_title) - create(:cfp, program: conference1.program) - - visit edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp) - expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference1.short_title, conference1.program.cfp)) - - visit admin_conference_program_events_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_events_path(conference1.short_title)) - - create(:event, program: conference1.program) - visit edit_admin_conference_program_event_path(conference1.short_title, conference1.program.events.first) - expect(current_path).to eq(edit_admin_conference_program_event_path(conference1.short_title, conference1.program.events.first)) - - visit admin_conference_program_event_types_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_event_types_path(conference1.short_title)) - - visit new_admin_conference_program_event_type_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_program_event_type_path(conference1.short_title)) - - visit edit_admin_conference_program_event_type_path(conference1.short_title, conference1.program.event_types.first) - expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference1.short_title, conference1.program.event_types.first)) - - visit admin_conference_program_difficulty_levels_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference1.short_title)) - - visit new_admin_conference_program_difficulty_level_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference1.short_title)) - - visit edit_admin_conference_program_difficulty_level_path(conference1.short_title, conference1.program.difficulty_levels.first) - expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference1.short_title, conference1.program.difficulty_levels.first)) - - visit admin_conference_schedules_path(conference1.short_title) - expect(current_path).to eq(admin_conference_schedules_path(conference1.short_title)) - - create(:schedule, program: conference1.program) - visit admin_conference_schedule_path(conference1.short_title, conference1.program.schedules.first) - expect(current_path).to eq(admin_conference_schedule_path(conference1.short_title, conference1.program.schedules.first)) - - visit admin_conference_program_reports_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_reports_path(conference1.short_title)) - - visit admin_conference_registrations_path(conference1.short_title) - expect(current_path).to eq(admin_conference_registrations_path(conference1.short_title)) - - create(:registration, user: create(:user), conference: conference1) - visit edit_admin_conference_registration_path(conference1.short_title, conference1.registrations.first) - expect(current_path).to eq(edit_admin_conference_registration_path(conference1.short_title, conference1.registrations.first)) - - visit new_admin_conference_registration_period_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_registration_period_path(conference1.short_title)) - - create(:registration_period, conference: conference1) - visit edit_admin_conference_registration_period_path(conference1.short_title) - expect(current_path).to eq(edit_admin_conference_registration_period_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_sponsorship_levels_path(conference1.short_title) - expect(current_path).to eq(admin_conference_sponsorship_levels_path(conference1.short_title)) - - visit new_admin_conference_sponsorship_level_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_sponsorship_level_path(conference1.short_title)) - - create(:sponsorship_level, conference: conference1) - visit edit_admin_conference_sponsorship_level_path(conference1.short_title, conference1.sponsorship_levels.first) - expect(current_path).to eq(edit_admin_conference_sponsorship_level_path(conference1.short_title, conference1.sponsorship_levels.first)) - - visit admin_conference_sponsors_path(conference1.short_title) - expect(current_path).to eq(admin_conference_sponsors_path(conference1.short_title)) - - visit new_admin_conference_sponsor_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_sponsor_path(conference1.short_title)) - - create(:sponsor, conference: conference1, sponsorship_level: conference1.sponsorship_levels.first) - visit edit_admin_conference_sponsor_path(conference1.short_title, conference1.sponsors.first) - expect(current_path).to eq(edit_admin_conference_sponsor_path(conference1.short_title, conference1.sponsors.first)) - - visit admin_conference_tickets_path(conference1.short_title) - expect(current_path).to eq(admin_conference_tickets_path(conference1.short_title)) - - visit new_admin_conference_ticket_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_ticket_path(conference1.short_title)) - - create(:ticket, conference: conference1) - visit edit_admin_conference_ticket_path(conference1.short_title, conference1.tickets.first) - expect(current_path).to eq(edit_admin_conference_ticket_path(conference1.short_title, conference1.tickets.first)) - - visit admin_conference_campaigns_path(conference1.short_title) - expect(current_path).to eq(admin_conference_campaigns_path(conference1.short_title)) - - visit new_admin_conference_campaign_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_campaign_path(conference1.short_title)) - - create(:campaign, conference: conference1) - visit edit_admin_conference_campaign_path(conference1.short_title, conference1.campaigns.first) - expect(current_path).to eq(edit_admin_conference_campaign_path(conference1.short_title, conference1.campaigns.first)) - - visit admin_conference_targets_path(conference1.short_title) - expect(current_path).to eq(admin_conference_targets_path(conference1.short_title)) - - visit new_admin_conference_target_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_target_path(conference1.short_title)) - - create(:target, conference: conference1) - visit edit_admin_conference_target_path(conference1.short_title, conference1.targets.first) - expect(current_path).to eq(edit_admin_conference_target_path(conference1.short_title, conference1.targets.first)) - - visit admin_conference_program_tracks_path(conference1.short_title) - expect(current_path).to eq(admin_conference_program_tracks_path(conference1.short_title)) - - visit admin_conference_roles_path(conference1.short_title) - expect(current_path).to eq(admin_conference_roles_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_resources_path(conference1.short_title) - expect(current_path).to eq(admin_conference_resources_path(conference1.short_title)) - - visit new_admin_conference_resource_path(conference1.short_title) - expect(current_path).to eq(new_admin_conference_resource_path(conference1.short_title)) - - create(:resource, conference: conference1) - visit edit_admin_conference_resource_path(conference1.short_title, conference1.resources.first) - expect(current_path).to eq(edit_admin_conference_resource_path(conference1.short_title, conference1.resources.first)) - - visit admin_revision_history_path - expect(current_path).to eq(admin_revision_history_path) - end - end - - context 'when user is organization_admin' do - before do - sign_in user_organization_admin - end - - scenario 'can manage organization' do - visit admin_organizations_path - expect(current_path).to eq(admin_organizations_path) - - visit edit_admin_organization_path(organization) - expect(current_path).to eq(edit_admin_organization_path(organization)) - - visit new_admin_organization_path - expect(current_path).to eq(root_path) - end - - it_behaves_like 'correct abilities for organizers and organization_admin' - end - - context 'when user is organizer' do - before do - sign_in user_organizer - end - - scenario 'cannot manage organization' do - visit admin_organizations_path - expect(current_path).to eq(admin_organizations_path) - - visit edit_admin_organization_path(organization) - expect(current_path).to eq(root_path) - - visit new_admin_organization_path - expect(current_path).to eq(root_path) - end - - it_behaves_like 'correct abilities for organizers and organization_admin' - end - - shared_examples 'correct abilities for cfps and info_desk' do |role| - scenario 'correct ability' do - if role == 'cfp' - conference = conference2 - elsif role == 'info_desk' - conference = conference3 - end - - visit admin_conference_path(conference.short_title) - expect(current_path).to eq(admin_conference_path(conference.short_title)) - - expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference.short_title}/edit") - expect(page).to have_text('Basics') - expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference.short_title}/contact/edit") - expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference.short_title}/commercials") - expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference.short_title}/splashpage") - expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference.short_title}/lodgings") - expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference.short_title}/registration_period") - expect(page).to_not have_text('Donations') - expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") - expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") - expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") - expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") - expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") - - visit admin_organizations_path - expect(current_path).to eq(admin_organizations_path) - - visit edit_admin_organization_path(organization) - expect(current_path).to eq(root_path) - - visit new_admin_organization_path - expect(current_path).to eq(root_path) - - visit edit_admin_conference_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit edit_admin_conference_contact_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_commercials_path(conference.short_title) - expect(current_path).to eq(admin_conference_commercials_path(conference.short_title)) - - visit new_admin_conference_splashpage_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit edit_admin_conference_splashpage_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_venue_path(conference.short_title) - expect(current_path).to eq(root_path) - - conference.venue = create(:venue) - visit edit_admin_conference_venue_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_lodgings_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_lodging_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:lodging, conference: conference) - visit edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first) - expect(current_path).to eq(root_path) - - visit new_admin_conference_registration_period_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:registration_period, conference: conference) - visit edit_admin_conference_registration_period_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_sponsorship_levels_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_sponsorship_level_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:sponsorship_level, conference: conference) - visit edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first) - expect(current_path).to eq(root_path) - - visit admin_conference_sponsors_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_sponsor_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:sponsor, conference: conference, sponsorship_level: conference.sponsorship_levels.first) - visit edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first) - expect(current_path).to eq(root_path) - - visit admin_conference_tickets_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_ticket_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:ticket, conference: conference) - visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) - expect(current_path).to eq(root_path) - - visit admin_conference_campaigns_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_campaign_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:campaign, conference: conference) - visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) - expect(current_path).to eq(root_path) - - visit admin_conference_targets_path(conference.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_target_path(conference.short_title) - expect(current_path).to eq(root_path) - - create(:target, conference: conference) - visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) - expect(current_path).to eq(root_path) - - visit admin_conference_roles_path(conference.short_title) - expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) - - visit admin_conference_resources_path(conference.short_title) - expect(current_path).to eq(admin_conference_resources_path(conference.short_title)) - - visit new_admin_conference_resource_path(conference.short_title) - expect(current_path).to eq(new_admin_conference_resource_path(conference.short_title)) - - create(:resource, conference: conference) - visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) - expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) - - visit admin_revision_history_path - expect(current_path).to eq(root_path) - end - end - - context 'when user is cfp' do - before do - sign_in user_cfp - @conference = conference2 - end - scenario 'has correct abilities' do - visit admin_conference_path(conference2.short_title) - expect(current_path).to eq(admin_conference_path(conference2.short_title)) - - expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') - expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference2.short_title}/edit") - expect(page).to have_text('Basics') - expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference2.short_title}/contact/edit") - expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference2.short_title}/commercials") - expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference2.short_title}/splashpage") - expect(page).to have_link('Venue', href: "/admin/conferences/#{conference2.short_title}/venue") - expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference2.short_title}/venue/rooms") - expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference2.short_title}/lodgings") - expect(page).to have_link('Program', href: "/admin/conferences/#{conference2.short_title}/program") - expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference2.short_title}/program/cfps") - expect(page).to have_link('Events', href: "/admin/conferences/#{conference2.short_title}/program/events") - expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference2.short_title}/program/tracks") - expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference2.short_title}/program/event_types") - expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference2.short_title}/program/difficulty_levels") - expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference2.short_title}/schedules") - expect(page).to have_link('Reports', href: "/admin/conferences/#{conference2.short_title}/program/reports") - expect(page).to_not have_link('Registrations', href: "/admin/conferences/#{conference2.short_title}/registrations") - expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference2.short_title}/registration_period") - expect(page).to_not have_link('Questions', href: "/admin/conferences/#{conference2.short_title}/questions") - expect(page).to_not have_text('Donations') - expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference2.short_title}/supporter_levels") - expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference2.short_title}/sponsors") - expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference2.short_title}/tickets") - expect(page).to_not have_text('Objectives') - expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference2.short_title}/campaigns") - expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference2.short_title}/targets") - expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference2.short_title}/emails") - expect(page).to have_link('Roles', href: "/admin/conferences/#{conference2.short_title}/roles") - expect(page).to have_link('Resources', href: "/admin/conferences/#{conference2.short_title}/resources") - - visit admin_conference_venue_rooms_path(conference2.short_title) - expect(current_path).to eq(admin_conference_venue_rooms_path(conference2.short_title)) - create(:room, venue: conference2.venue) - visit edit_admin_conference_venue_room_path(conference2.short_title, conference2.venue.rooms.first) - expect(current_path).to eq(edit_admin_conference_venue_room_path(conference2.short_title, conference2.venue.rooms.first)) - - visit new_admin_conference_program_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_path(conference2.short_title)) - - visit edit_admin_conference_program_path(conference2.short_title) - expect(current_path).to eq(edit_admin_conference_program_path(conference2.short_title)) - - visit new_admin_conference_program_cfp_path(conference2.short_title) - expect(current_path).to eq root_path - - conference2.program.cfp.destroy! - visit new_admin_conference_program_cfp_path(conference2.short_title) - expect(current_path).to eq new_admin_conference_program_cfp_path(conference2.short_title) - create(:cfp, program: conference2.program) - - visit edit_admin_conference_program_cfp_path(conference2.short_title, conference2.program.cfp) - expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference2.short_title, conference2.program.cfp)) - - create(:event, program: conference2.program) - visit edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first) - expect(current_path).to eq(edit_admin_conference_program_event_path(conference2.short_title, conference2.program.events.first)) - - visit admin_conference_program_event_types_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_event_types_path(conference2.short_title)) - - visit new_admin_conference_program_event_type_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_event_type_path(conference2.short_title)) - - visit edit_admin_conference_program_event_type_path(conference2.short_title, conference2.program.event_types.first) - expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference2.short_title, conference2.program.event_types.first)) - - visit admin_conference_program_difficulty_levels_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference2.short_title)) - - visit new_admin_conference_program_difficulty_level_path(conference2.short_title) - expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference2.short_title)) - - visit edit_admin_conference_program_difficulty_level_path(conference2.short_title, conference2.program.difficulty_levels.first) - expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference2.short_title, conference2.program.difficulty_levels.first)) - - visit admin_conference_schedules_path(conference2.short_title) - expect(current_path).to eq(admin_conference_schedules_path(conference2.short_title)) - - create(:schedule, program: conference2.program) - visit admin_conference_schedule_path(conference2.short_title, conference2.program.schedules.first) - expect(current_path).to eq(admin_conference_schedule_path(conference2.short_title, conference2.program.schedules.first)) - - visit admin_conference_program_reports_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_reports_path(conference2.short_title)) - - visit admin_conference_registrations_path(conference2.short_title) - expect(current_path).to eq(admin_conference_registrations_path(conference2.short_title)) - - create(:registration, user: create(:user), conference: conference2) - visit edit_admin_conference_registration_path(conference2.short_title, conference2.registrations.first) - expect(current_path).to eq(root_path) - - visit new_admin_conference_registration_period_path(conference2.short_title) - expect(current_path).to eq(root_path) - - create(:registration_period, conference: conference2) - visit edit_admin_conference_registration_period_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_questions_path(conference2.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_program_tracks_path(conference2.short_title) - expect(current_path).to eq(admin_conference_program_tracks_path(conference2.short_title)) - - visit admin_conference_roles_path(conference2.short_title) - expect(current_path).to eq(admin_conference_roles_path(conference2.short_title)) - - visit admin_conference_emails_path(conference2.short_title) - expect(current_path).to eq(admin_conference_emails_path(conference2.short_title)) - end - - it_behaves_like 'correct abilities for cfps and info_desk', 'cfp' - end - - context 'when user is info desk' do - before do - sign_in user_info_desk - end - - scenario 'has correct abilities' do - visit admin_conference_path(conference3.short_title) - expect(current_path).to eq(admin_conference_path(conference3.short_title)) - - expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') - expect(page).to_not have_link('Venue', href: "/admin/conferences/#{conference3.short_title}/venue") - expect(page).to_not have_link('Rooms', href: "/admin/conferences/#{conference3.short_title}/venue/rooms") - expect(page).to_not have_link('Program', href: "/admin/conferences/#{conference3.short_title}/program") - expect(page).to_not have_link('Call for Papers', href: "/admin/conferences/#{conference2.short_title}/program/cfps") - expect(page).to_not have_link('Events', href: "/admin/conferences/#{conference3.short_title}/program/events") - expect(page).to_not have_link('Tracks', href: "/admin/conferences/#{conference3.short_title}/program/tracks") - expect(page).to_not have_link('Event Types', href: "/admin/conferences/#{conference3.short_title}/program/event_types") - expect(page).to_not have_link('Difficulty Levels', href: "/admin/conferences/#{conference3.short_title}/program/difficulty_levels") - expect(page).to_not have_link('Schedules', href: "/admin/conferences/#{conference3.short_title}/schedules") - expect(page).to_not have_link('Reports', href: "/admin/conferences/#{conference3.short_title}/program/reports") - expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference3.short_title}/registrations") - expect(page).to have_link('Questions', href: "/admin/conferences/#{conference3.short_title}/questions") - expect(page).to_not have_link('E-Mails', href: "/admin/conferences/#{conference3.short_title}/emails") - - visit admin_conference_venue_rooms_path(conference3.short_title) - expect(current_path).to eq(root_path) - - create(:room, venue: conference3.venue) - visit edit_admin_conference_venue_room_path(conference3.short_title, conference3.venue.rooms.first) - expect(current_path).to eq(root_path) - - visit new_admin_conference_program_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit edit_admin_conference_program_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_program_cfp_path(conference3.short_title) - expect(current_path).to eq root_path - - conference1.program.cfp.destroy! - visit new_admin_conference_program_cfp_path(conference3.short_title) - expect(current_path).to eq root_path - create(:cfp, program: conference1.program) - - visit edit_admin_conference_program_cfp_path(conference3.short_title, conference3.program.cfp) - expect(current_path).to eq(root_path) - - visit admin_conference_program_events_path(conference3.short_title) - expect(current_path).to eq(root_path) - - create(:event, program: conference3.program) - visit edit_admin_conference_program_event_path(conference3.short_title, conference3.program.events.first) - expect(current_path).to eq(root_path) - - visit admin_conference_program_event_types_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_program_event_type_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit edit_admin_conference_program_event_type_path(conference3.short_title, conference3.program.event_types.first) - expect(current_path).to eq(root_path) - - visit admin_conference_program_difficulty_levels_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit new_admin_conference_program_difficulty_level_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit edit_admin_conference_program_difficulty_level_path(conference3.short_title, conference3.program.difficulty_levels.first) - expect(current_path).to eq(root_path) - - visit admin_conference_schedules_path(conference3.short_title) - expect(current_path).to eq(root_path) - - create(:schedule, program: conference3.program) - visit admin_conference_schedule_path(conference3.short_title, conference3.program.schedules.first) - expect(current_path).to eq(root_path) - - visit admin_conference_program_reports_path(conference3.short_title) - expect(current_path).to eq(root_path) - - visit admin_conference_registrations_path(conference3.short_title) - expect(current_path).to eq(admin_conference_registrations_path(conference3.short_title)) - - create(:registration, user: create(:user), conference: conference3) - visit edit_admin_conference_registration_path(conference3.short_title, conference3.registrations.first) - expect(current_path).to eq(edit_admin_conference_registration_path(conference3.short_title, conference3.registrations.first)) - - visit admin_conference_questions_path(conference3.short_title) - expect(current_path).to eq(admin_conference_questions_path(conference3.short_title)) - - visit admin_conference_program_tracks_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) - end - - it_behaves_like 'correct abilities for cfps and info_desk', 'info_desk' - end -end diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb new file mode 100644 index 00000000..52725527 --- /dev/null +++ b/spec/features/cfp_ability_spec.rb @@ -0,0 +1,250 @@ +require 'spec_helper' + +feature 'Has correct abilities' do + + let(:organization) { create(:organization) } + # It is necessary to use bang version of let to build roles before user + let(:conference) { create(:full_conference, organization: organization) } # user is cfp + let(:role_cfp) { Role.find_by(name: 'cfp', resource: conference) } + let(:user_cfp) { create(:user, role_ids: [role_cfp.id]) } + + context 'when user is cfp' do + before do + sign_in user_cfp + end + + scenario 'for organization and conference attributes' do + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) + + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference.short_title}/edit") + expect(page).to have_text('Basics') + expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference.short_title}/commercials") + expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference.short_title}/splashpage") + expect(page).to have_link('Venue', href: "/admin/conferences/#{conference.short_title}/venue") + expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference.short_title}/venue/rooms") + expect(page).to have_link('Program', href: "/admin/conferences/#{conference.short_title}/program") + expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference.short_title}/program/cfps") + expect(page).to have_link('Events', href: "/admin/conferences/#{conference.short_title}/program/events") + expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference.short_title}/program/tracks") + expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference.short_title}/program/event_types") + expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference.short_title}/program/difficulty_levels") + expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference.short_title}/schedules") + expect(page).to have_link('Reports', href: "/admin/conferences/#{conference.short_title}/program/reports") + expect(page).to_not have_link('Registrations', href: "/admin/conferences/#{conference.short_title}/registrations") + expect(page).to_not have_link('Questions', href: "/admin/conferences/#{conference.short_title}/questions") + expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") + expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference.short_title}/lodgings") + expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference.short_title}/registration_period") + expect(page).to_not have_text('Donations') + expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") + expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") + expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") + expect(page).to_not have_text('Objectives') + expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") + expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + + visit admin_conference_venue_rooms_path(conference.short_title) + expect(current_path).to eq(admin_conference_venue_rooms_path(conference.short_title)) + create(:room, venue: conference.venue) + visit edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first) + expect(current_path).to eq(edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first)) + + visit new_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_path(conference.short_title)) + + visit edit_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_program_path(conference.short_title)) + + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + conference.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + create(:cfp, program: conference.program) + + visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) + expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) + + create(:event, program: conference.program) + visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first) + expect(current_path).to eq(edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)) + + visit admin_conference_program_event_types_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_event_types_path(conference.short_title)) + + visit new_admin_conference_program_event_type_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_event_type_path(conference.short_title)) + + visit edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first) + expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first)) + + visit admin_conference_program_difficulty_levels_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference.short_title)) + + visit new_admin_conference_program_difficulty_level_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference.short_title)) + + visit edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first) + expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first)) + + visit admin_conference_schedules_path(conference.short_title) + expect(current_path).to eq(admin_conference_schedules_path(conference.short_title)) + + create(:schedule, program: conference.program) + visit admin_conference_schedule_path(conference.short_title, conference.program.schedules.first) + expect(current_path).to eq(admin_conference_schedule_path(conference.short_title, conference.program.schedules.first)) + + visit admin_conference_program_reports_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_reports_path(conference.short_title)) + + visit admin_conference_registrations_path(conference.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference.short_title)) + + create(:registration, user: create(:user), conference: conference) + visit edit_admin_conference_registration_path(conference.short_title, conference.registrations.first) + expect(current_path).to eq(root_path) + + visit new_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:registration_period, conference: conference) + visit edit_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_questions_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_program_tracks_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_tracks_path(conference.short_title)) + + visit admin_conference_roles_path(conference.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) + + visit admin_conference_emails_path(conference.short_title) + expect(current_path).to eq(admin_conference_emails_path(conference.short_title)) + + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) + + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) + + visit edit_admin_organization_path(organization) + expect(current_path).to eq(root_path) + + visit new_admin_organization_path + expect(current_path).to eq(root_path) + + visit edit_admin_conference_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_contact_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_commercials_path(conference.short_title) + expect(current_path).to eq(admin_conference_commercials_path(conference.short_title)) + + visit new_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(root_path) + + conference.venue = create(:venue) + visit edit_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_lodgings_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_lodging_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:lodging, conference: conference) + visit edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first) + expect(current_path).to eq(root_path) + + visit new_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:registration_period, conference: conference) + visit edit_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_sponsorship_levels_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_sponsorship_level_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:sponsorship_level, conference: conference) + visit edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first) + expect(current_path).to eq(root_path) + + visit admin_conference_sponsors_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_sponsor_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:sponsor, conference: conference, sponsorship_level: conference.sponsorship_levels.first) + visit edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first) + expect(current_path).to eq(root_path) + + visit admin_conference_tickets_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_ticket_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:ticket, conference: conference) + visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) + expect(current_path).to eq(root_path) + + visit admin_conference_campaigns_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_campaign_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:campaign, conference: conference) + visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) + expect(current_path).to eq(root_path) + + visit admin_conference_targets_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_target_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:target, conference: conference) + visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) + expect(current_path).to eq(root_path) + + visit admin_conference_roles_path(conference.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) + + visit admin_conference_resources_path(conference.short_title) + expect(current_path).to eq(admin_conference_resources_path(conference.short_title)) + + visit new_admin_conference_resource_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_resource_path(conference.short_title)) + + create(:resource, conference: conference) + visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) + expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) + + visit admin_revision_history_path + expect(current_path).to eq(root_path) + end + end +end diff --git a/spec/features/info_desk_ability_spec.rb b/spec/features/info_desk_ability_spec.rb new file mode 100644 index 00000000..d7b0b909 --- /dev/null +++ b/spec/features/info_desk_ability_spec.rb @@ -0,0 +1,246 @@ +require 'spec_helper' + +feature 'Has correct abilities' do + + let(:organization) { create(:organization) } + # It is necessary to use bang version of let to build roles before user + let(:conference) { create(:full_conference, organization: organization) } # user is info_desk + + let(:role_info_desk) { Role.find_by(name: 'info_desk', resource: conference) } + + let(:user_info_desk) { create(:user, role_ids: [role_info_desk.id]) } + + context 'when user is info desk' do + before do + sign_in user_info_desk + end + + scenario 'for organization and conference attributes' do + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) + + expect(page).to_not have_link('Basics', href: "/admin/conferences/#{conference.short_title}/edit") + expect(page).to have_text('Basics') + expect(page).to_not have_link('Contact', href: "/admin/conferences/#{conference.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference.short_title}/commercials") + expect(page).to_not have_link('Splashpage', href: "/admin/conferences/#{conference.short_title}/splashpage") + expect(page).to_not have_link('Lodgings', href: "/admin/conferences/#{conference.short_title}/lodgings") + expect(page).to_not have_link('Registration Period', href: "/admin/conferences/#{conference.short_title}/registration_period") + expect(page).to_not have_text('Donations') + expect(page).to_not have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") + expect(page).to_not have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") + expect(page).to_not have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") + expect(page).to_not have_text('Objectives') + expect(page).to_not have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") + expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to_not have_link('Venue', href: "/admin/conferences/#{conference.short_title}/venue") + expect(page).to_not have_link('Rooms', href: "/admin/conferences/#{conference.short_title}/venue/rooms") + expect(page).to_not have_link('Program', href: "/admin/conferences/#{conference.short_title}/program") + expect(page).to_not have_link('Call for Papers', href: "/admin/conferences/#{conference.short_title}/program/cfps") + expect(page).to_not have_link('Events', href: "/admin/conferences/#{conference.short_title}/program/events") + expect(page).to_not have_link('Tracks', href: "/admin/conferences/#{conference.short_title}/program/tracks") + expect(page).to_not have_link('Event Types', href: "/admin/conferences/#{conference.short_title}/program/event_types") + expect(page).to_not have_link('Difficulty Levels', href: "/admin/conferences/#{conference.short_title}/program/difficulty_levels") + expect(page).to_not have_link('Schedules', href: "/admin/conferences/#{conference.short_title}/schedules") + expect(page).to_not have_link('Reports', href: "/admin/conferences/#{conference.short_title}/program/reports") + expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference.short_title}/registrations") + expect(page).to have_link('Questions', href: "/admin/conferences/#{conference.short_title}/questions") + expect(page).to_not have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") + + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) + + visit edit_admin_organization_path(organization) + expect(current_path).to eq(root_path) + + visit new_admin_organization_path + expect(current_path).to eq(root_path) + + visit edit_admin_conference_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_contact_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_commercials_path(conference.short_title) + expect(current_path).to eq(admin_conference_commercials_path(conference.short_title)) + + visit new_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(root_path) + + conference.venue = create(:venue) + visit edit_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_lodgings_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_lodging_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:lodging, conference: conference) + visit edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first) + expect(current_path).to eq(root_path) + + visit new_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:registration_period, conference: conference) + visit edit_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_sponsorship_levels_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_sponsorship_level_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:sponsorship_level, conference: conference) + visit edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first) + expect(current_path).to eq(root_path) + + visit admin_conference_sponsors_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_sponsor_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:sponsor, conference: conference, sponsorship_level: conference.sponsorship_levels.first) + visit edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first) + expect(current_path).to eq(root_path) + + visit admin_conference_tickets_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_ticket_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:ticket, conference: conference) + visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) + expect(current_path).to eq(root_path) + + visit admin_conference_campaigns_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_campaign_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:campaign, conference: conference) + visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) + expect(current_path).to eq(root_path) + + visit admin_conference_targets_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_target_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:target, conference: conference) + visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) + expect(current_path).to eq(root_path) + + visit admin_conference_roles_path(conference.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) + + visit admin_conference_resources_path(conference.short_title) + expect(current_path).to eq(admin_conference_resources_path(conference.short_title)) + + visit new_admin_conference_resource_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_resource_path(conference.short_title)) + + create(:resource, conference: conference) + visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) + expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) + + visit admin_revision_history_path + expect(current_path).to eq(root_path) + + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) + + visit admin_conference_venue_rooms_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:room, venue: conference.venue) + visit edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + conference.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + create(:cfp, program: conference.program) + + visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) + expect(current_path).to eq(root_path) + + visit admin_conference_program_events_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:event, program: conference.program) + visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first) + expect(current_path).to eq(root_path) + + visit admin_conference_program_event_types_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_event_type_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first) + expect(current_path).to eq(root_path) + + visit admin_conference_program_difficulty_levels_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit new_admin_conference_program_difficulty_level_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first) + expect(current_path).to eq(root_path) + + visit admin_conference_schedules_path(conference.short_title) + expect(current_path).to eq(root_path) + + create(:schedule, program: conference.program) + visit admin_conference_schedule_path(conference.short_title, conference.program.schedules.first) + expect(current_path).to eq(root_path) + + visit admin_conference_program_reports_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_registrations_path(conference.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference.short_title)) + + create(:registration, user: create(:user), conference: conference) + visit edit_admin_conference_registration_path(conference.short_title, conference.registrations.first) + expect(current_path).to eq(edit_admin_conference_registration_path(conference.short_title, conference.registrations.first)) + + visit admin_conference_questions_path(conference.short_title) + expect(current_path).to eq(admin_conference_questions_path(conference.short_title)) + + visit admin_conference_program_tracks_path(conference.short_title) + expect(current_path).to eq(root_path) + + visit admin_conference_emails_path(conference.short_title) + expect(current_path).to eq(root_path) + end + end +end diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb new file mode 100644 index 00000000..5a247dd8 --- /dev/null +++ b/spec/features/organization_admin_ability_spec.rb @@ -0,0 +1,240 @@ +require 'spec_helper' + +feature 'Has correct abilities' do + let(:organization) { create(:organization) } + let(:conference) { create(:full_conference, organization: organization) } # user is organization_admin + let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) } + let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) } + + context 'when user is organization_admin' do + before do + sign_in user_organization_admin + end + + scenario 'for organization attributes' do + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) + + visit edit_admin_organization_path(organization) + expect(current_path).to eq(edit_admin_organization_path(organization)) + + visit new_admin_organization_path + expect(current_path).to eq(root_path) + end + + scenario 'for conference attributes' do + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) + + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to have_link('Basics', href: "/admin/conferences/#{conference.short_title}/edit") + expect(page).to have_link('Contact', href: "/admin/conferences/#{conference.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference.short_title}/commercials") + expect(page).to have_link('Splashpage', href: "/admin/conferences/#{conference.short_title}/splashpage") + expect(page).to have_link('Venue', href: "/admin/conferences/#{conference.short_title}/venue") + expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference.short_title}/venue/rooms") + expect(page).to have_link('Lodgings', href: "/admin/conferences/#{conference.short_title}/lodgings") + expect(page).to have_link('Program', href: "/admin/conferences/#{conference.short_title}/program") + expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference.short_title}/program/cfps") + expect(page).to have_link('Events', href: "/admin/conferences/#{conference.short_title}/program/events") + expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference.short_title}/program/tracks") + expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference.short_title}/program/event_types") + expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference.short_title}/program/difficulty_levels") + expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference.short_title}/schedules") + expect(page).to have_link('Reports', href: "/admin/conferences/#{conference.short_title}/program/reports") + expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference.short_title}/registrations") + expect(page).to have_link('Registration Period', href: "/admin/conferences/#{conference.short_title}/registration_period") + expect(page).to have_link('Questions', href: "/admin/conferences/#{conference.short_title}/questions") + expect(page).to have_text('Donations') + expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") + expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") + expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") + expect(page).to have_text('Objectives') + expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") + expect(page).to have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") + expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + + visit edit_admin_conference_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_path(conference.short_title)) + + visit edit_admin_conference_contact_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_contact_path(conference.short_title)) + + visit admin_conference_commercials_path(conference.short_title) + expect(current_path).to eq(admin_conference_commercials_path(conference.short_title)) + + visit new_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_splashpage_path(conference.short_title)) + + visit edit_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_splashpage_path(conference.short_title)) + + visit new_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_venue_path(conference.short_title)) + + conference.venue = create(:venue) + visit edit_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_venue_path(conference.short_title)) + + visit admin_conference_venue_rooms_path(conference.short_title) + expect(current_path).to eq(admin_conference_venue_rooms_path(conference.short_title)) + + create(:room, venue: conference.venue) + visit edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first) + expect(current_path).to eq(edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first)) + + visit admin_conference_lodgings_path(conference.short_title) + expect(current_path).to eq(admin_conference_lodgings_path(conference.short_title)) + + visit new_admin_conference_lodging_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_lodging_path(conference.short_title)) + + create(:lodging, conference: conference) + visit edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first) + expect(current_path).to eq(edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first)) + + visit new_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_path(conference.short_title)) + + visit edit_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_program_path(conference.short_title)) + + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + conference.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + create(:cfp, program: conference.program) + + visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) + expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) + + visit admin_conference_program_events_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_events_path(conference.short_title)) + + create(:event, program: conference.program) + visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first) + expect(current_path).to eq(edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)) + + visit admin_conference_program_event_types_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_event_types_path(conference.short_title)) + + visit new_admin_conference_program_event_type_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_event_type_path(conference.short_title)) + + visit edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first) + expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first)) + + visit admin_conference_program_difficulty_levels_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference.short_title)) + + visit new_admin_conference_program_difficulty_level_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference.short_title)) + + visit edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first) + expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first)) + + visit admin_conference_schedules_path(conference.short_title) + expect(current_path).to eq(admin_conference_schedules_path(conference.short_title)) + + create(:schedule, program: conference.program) + visit admin_conference_schedule_path(conference.short_title, conference.program.schedules.first) + expect(current_path).to eq(admin_conference_schedule_path(conference.short_title, conference.program.schedules.first)) + + visit admin_conference_program_reports_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_reports_path(conference.short_title)) + + visit admin_conference_registrations_path(conference.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference.short_title)) + + create(:registration, user: create(:user), conference: conference) + visit edit_admin_conference_registration_path(conference.short_title, conference.registrations.first) + expect(current_path).to eq(edit_admin_conference_registration_path(conference.short_title, conference.registrations.first)) + + visit new_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_registration_period_path(conference.short_title)) + + create(:registration_period, conference: conference) + visit edit_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_registration_period_path(conference.short_title)) + + visit admin_conference_questions_path(conference.short_title) + expect(current_path).to eq(admin_conference_questions_path(conference.short_title)) + + visit admin_conference_sponsorship_levels_path(conference.short_title) + expect(current_path).to eq(admin_conference_sponsorship_levels_path(conference.short_title)) + + visit new_admin_conference_sponsorship_level_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_sponsorship_level_path(conference.short_title)) + + create(:sponsorship_level, conference: conference) + visit edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first) + expect(current_path).to eq(edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first)) + + visit admin_conference_sponsors_path(conference.short_title) + expect(current_path).to eq(admin_conference_sponsors_path(conference.short_title)) + + visit new_admin_conference_sponsor_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_sponsor_path(conference.short_title)) + + create(:sponsor, conference: conference, sponsorship_level: conference.sponsorship_levels.first) + visit edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first) + expect(current_path).to eq(edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first)) + + visit admin_conference_tickets_path(conference.short_title) + expect(current_path).to eq(admin_conference_tickets_path(conference.short_title)) + + visit new_admin_conference_ticket_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_ticket_path(conference.short_title)) + + create(:ticket, conference: conference) + visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) + expect(current_path).to eq(edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first)) + + visit admin_conference_campaigns_path(conference.short_title) + expect(current_path).to eq(admin_conference_campaigns_path(conference.short_title)) + + visit new_admin_conference_campaign_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_campaign_path(conference.short_title)) + + create(:campaign, conference: conference) + visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) + expect(current_path).to eq(edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first)) + + visit admin_conference_targets_path(conference.short_title) + expect(current_path).to eq(admin_conference_targets_path(conference.short_title)) + + visit new_admin_conference_target_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_target_path(conference.short_title)) + + create(:target, conference: conference) + visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) + expect(current_path).to eq(edit_admin_conference_target_path(conference.short_title, conference.targets.first)) + + visit admin_conference_program_tracks_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_tracks_path(conference.short_title)) + + visit admin_conference_roles_path(conference.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) + + visit admin_conference_emails_path(conference.short_title) + expect(current_path).to eq(admin_conference_emails_path(conference.short_title)) + + visit admin_conference_resources_path(conference.short_title) + expect(current_path).to eq(admin_conference_resources_path(conference.short_title)) + + visit new_admin_conference_resource_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_resource_path(conference.short_title)) + + create(:resource, conference: conference) + visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) + expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) + + visit admin_revision_history_path + expect(current_path).to eq(admin_revision_history_path) + end + end +end diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb new file mode 100644 index 00000000..9604fad6 --- /dev/null +++ b/spec/features/organizer_ability_spec.rb @@ -0,0 +1,247 @@ +require 'spec_helper' + +feature 'Has correct abilities' do + + let(:organization) { create(:organization) } + # It is necessary to use bang version of let to build roles before user + let(:conference) { create(:full_conference, organization: organization) } # user is organizer + let(:other_conference) { create(:conference, organization: organization) } # user is organizer, venue is not set by default + let(:role_organizer_conf) { Role.find_by(name: 'organizer', resource: conference) } + let(:role_organizer_other_conf) { Role.find_by(name: 'organizer', resource: other_conference) } + let(:user_organizer) { create(:user, role_ids: [role_organizer_conf.id, role_organizer_other_conf.id]) } + + context 'when user is organizer' do + before do + sign_in user_organizer + end + + scenario 'for organization attributes' do + visit admin_organizations_path + expect(current_path).to eq(admin_organizations_path) + + visit edit_admin_organization_path(organization) + expect(current_path).to eq(root_path) + + visit new_admin_organization_path + expect(current_path).to eq(root_path) + end + + scenario 'for conference attributes' do + visit admin_conference_path(conference.short_title) + expect(current_path).to eq(admin_conference_path(conference.short_title)) + + expect(page).to have_selector('li.nav-header.nav-header-bigger a', text: 'Dashboard') + expect(page).to have_link('Basics', href: "/admin/conferences/#{conference.short_title}/edit") + expect(page).to have_link('Contact', href: "/admin/conferences/#{conference.short_title}/contact/edit") + expect(page).to have_link('Commercials', href: "/admin/conferences/#{conference.short_title}/commercials") + expect(page).to have_link('Splashpage', href: "/admin/conferences/#{conference.short_title}/splashpage") + expect(page).to have_link('Venue', href: "/admin/conferences/#{conference.short_title}/venue") + expect(page).to have_link('Rooms', href: "/admin/conferences/#{conference.short_title}/venue/rooms") + expect(page).to have_link('Lodgings', href: "/admin/conferences/#{conference.short_title}/lodgings") + expect(page).to have_link('Program', href: "/admin/conferences/#{conference.short_title}/program") + expect(page).to have_link('Call for Papers', href: "/admin/conferences/#{conference.short_title}/program/cfps") + expect(page).to have_link('Events', href: "/admin/conferences/#{conference.short_title}/program/events") + expect(page).to have_link('Tracks', href: "/admin/conferences/#{conference.short_title}/program/tracks") + expect(page).to have_link('Event Types', href: "/admin/conferences/#{conference.short_title}/program/event_types") + expect(page).to have_link('Difficulty Levels', href: "/admin/conferences/#{conference.short_title}/program/difficulty_levels") + expect(page).to have_link('Schedules', href: "/admin/conferences/#{conference.short_title}/schedules") + expect(page).to have_link('Reports', href: "/admin/conferences/#{conference.short_title}/program/reports") + expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference.short_title}/registrations") + expect(page).to have_link('Registration Period', href: "/admin/conferences/#{conference.short_title}/registration_period") + expect(page).to have_link('Questions', href: "/admin/conferences/#{conference.short_title}/questions") + expect(page).to have_text('Donations') + expect(page).to have_link('Sponsorship Levels', href: "/admin/conferences/#{conference.short_title}/sponsorship_levels") + expect(page).to have_link('Sponsors', href: "/admin/conferences/#{conference.short_title}/sponsors") + expect(page).to have_link('Tickets', href: "/admin/conferences/#{conference.short_title}/tickets") + expect(page).to have_text('Objectives') + expect(page).to have_link('Campaigns', href: "/admin/conferences/#{conference.short_title}/campaigns") + expect(page).to have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") + expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") + expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") + expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + + visit admin_conference_path(other_conference.short_title) + expect(page).to have_link('Add venue', href: "/admin/conferences/#{other_conference.short_title}/venue/new") + + visit edit_admin_conference_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_path(conference.short_title)) + + visit edit_admin_conference_contact_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_contact_path(conference.short_title)) + + visit admin_conference_commercials_path(conference.short_title) + expect(current_path).to eq(admin_conference_commercials_path(conference.short_title)) + + visit new_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_splashpage_path(conference.short_title)) + + visit edit_admin_conference_splashpage_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_splashpage_path(conference.short_title)) + + visit new_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_venue_path(conference.short_title)) + + conference.venue = create(:venue) + visit edit_admin_conference_venue_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_venue_path(conference.short_title)) + + visit admin_conference_venue_rooms_path(conference.short_title) + expect(current_path).to eq(admin_conference_venue_rooms_path(conference.short_title)) + + create(:room, venue: conference.venue) + visit edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first) + expect(current_path).to eq(edit_admin_conference_venue_room_path(conference.short_title, conference.venue.rooms.first)) + + visit admin_conference_lodgings_path(conference.short_title) + expect(current_path).to eq(admin_conference_lodgings_path(conference.short_title)) + + visit new_admin_conference_lodging_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_lodging_path(conference.short_title)) + + create(:lodging, conference: conference) + visit edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first) + expect(current_path).to eq(edit_admin_conference_lodging_path(conference.short_title, conference.lodgings.first)) + + visit new_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_path(conference.short_title)) + + visit edit_admin_conference_program_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_program_path(conference.short_title)) + + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + conference.program.cfp.destroy! + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + create(:cfp, program: conference.program) + + visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) + expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) + + visit admin_conference_program_events_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_events_path(conference.short_title)) + + create(:event, program: conference.program) + visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first) + expect(current_path).to eq(edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)) + + visit admin_conference_program_event_types_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_event_types_path(conference.short_title)) + + visit new_admin_conference_program_event_type_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_event_type_path(conference.short_title)) + + visit edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first) + expect(current_path).to eq(edit_admin_conference_program_event_type_path(conference.short_title, conference.program.event_types.first)) + + visit admin_conference_program_difficulty_levels_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_difficulty_levels_path(conference.short_title)) + + visit new_admin_conference_program_difficulty_level_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_program_difficulty_level_path(conference.short_title)) + + visit edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first) + expect(current_path).to eq(edit_admin_conference_program_difficulty_level_path(conference.short_title, conference.program.difficulty_levels.first)) + + visit admin_conference_schedules_path(conference.short_title) + expect(current_path).to eq(admin_conference_schedules_path(conference.short_title)) + + create(:schedule, program: conference.program) + visit admin_conference_schedule_path(conference.short_title, conference.program.schedules.first) + expect(current_path).to eq(admin_conference_schedule_path(conference.short_title, conference.program.schedules.first)) + + visit admin_conference_program_reports_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_reports_path(conference.short_title)) + + visit admin_conference_registrations_path(conference.short_title) + expect(current_path).to eq(admin_conference_registrations_path(conference.short_title)) + + create(:registration, user: create(:user), conference: conference) + visit edit_admin_conference_registration_path(conference.short_title, conference.registrations.first) + expect(current_path).to eq(edit_admin_conference_registration_path(conference.short_title, conference.registrations.first)) + + visit new_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_registration_period_path(conference.short_title)) + + create(:registration_period, conference: conference) + visit edit_admin_conference_registration_period_path(conference.short_title) + expect(current_path).to eq(edit_admin_conference_registration_period_path(conference.short_title)) + + visit admin_conference_questions_path(conference.short_title) + expect(current_path).to eq(admin_conference_questions_path(conference.short_title)) + + visit admin_conference_sponsorship_levels_path(conference.short_title) + expect(current_path).to eq(admin_conference_sponsorship_levels_path(conference.short_title)) + + visit new_admin_conference_sponsorship_level_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_sponsorship_level_path(conference.short_title)) + + create(:sponsorship_level, conference: conference) + visit edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first) + expect(current_path).to eq(edit_admin_conference_sponsorship_level_path(conference.short_title, conference.sponsorship_levels.first)) + + visit admin_conference_sponsors_path(conference.short_title) + expect(current_path).to eq(admin_conference_sponsors_path(conference.short_title)) + + visit new_admin_conference_sponsor_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_sponsor_path(conference.short_title)) + + create(:sponsor, conference: conference, sponsorship_level: conference.sponsorship_levels.first) + visit edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first) + expect(current_path).to eq(edit_admin_conference_sponsor_path(conference.short_title, conference.sponsors.first)) + + visit admin_conference_tickets_path(conference.short_title) + expect(current_path).to eq(admin_conference_tickets_path(conference.short_title)) + + visit new_admin_conference_ticket_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_ticket_path(conference.short_title)) + + create(:ticket, conference: conference) + visit edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first) + expect(current_path).to eq(edit_admin_conference_ticket_path(conference.short_title, conference.tickets.first)) + + visit admin_conference_campaigns_path(conference.short_title) + expect(current_path).to eq(admin_conference_campaigns_path(conference.short_title)) + + visit new_admin_conference_campaign_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_campaign_path(conference.short_title)) + + create(:campaign, conference: conference) + visit edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first) + expect(current_path).to eq(edit_admin_conference_campaign_path(conference.short_title, conference.campaigns.first)) + + visit admin_conference_targets_path(conference.short_title) + expect(current_path).to eq(admin_conference_targets_path(conference.short_title)) + + visit new_admin_conference_target_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_target_path(conference.short_title)) + + create(:target, conference: conference) + visit edit_admin_conference_target_path(conference.short_title, conference.targets.first) + expect(current_path).to eq(edit_admin_conference_target_path(conference.short_title, conference.targets.first)) + + visit admin_conference_program_tracks_path(conference.short_title) + expect(current_path).to eq(admin_conference_program_tracks_path(conference.short_title)) + + visit admin_conference_roles_path(conference.short_title) + expect(current_path).to eq(admin_conference_roles_path(conference.short_title)) + + visit admin_conference_emails_path(conference.short_title) + expect(current_path).to eq(admin_conference_emails_path(conference.short_title)) + + visit admin_conference_resources_path(conference.short_title) + expect(current_path).to eq(admin_conference_resources_path(conference.short_title)) + + visit new_admin_conference_resource_path(conference.short_title) + expect(current_path).to eq(new_admin_conference_resource_path(conference.short_title)) + + create(:resource, conference: conference) + visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) + expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) + + visit admin_revision_history_path + expect(current_path).to eq(admin_revision_history_path) + end + end +end diff --git a/spec/features/user_ability_spec.rb b/spec/features/user_ability_spec.rb new file mode 100644 index 00000000..d56e7441 --- /dev/null +++ b/spec/features/user_ability_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +feature 'Has correct abilities' do + + let(:organization) { create(:organization) } + let(:conference) { create(:full_conference, organization: organization) } # user is cfp + let(:user) { create(:user) } + + context 'when user has no role' do + before do + sign_in user + end + + scenario 'for administration views' do + visit admin_conference_path(conference.short_title) + + expect(current_path).to eq root_path + expect(flash).to eq 'You are not authorized to access this page.' + end + end +end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index fcf9b384..6803ffc5 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -139,22 +139,20 @@ describe 'User' do end shared_examples 'user with any role' do - before do - @other_organization = create(:organization) - @other_conference = create(:conference, organization: @other_organization) - end + let!(:other_organization) { create(:organization) } + let!(:other_conference) { create(:conference, organization: other_organization) } - it{ should_not be_able_to(:update, Role.find_by(name: 'organization_admin', resource: @other_organization)) } - it{ should_not be_able_to(:edit, Role.find_by(name: 'organization_admin', resource: @other_organization)) } - it{ should_not be_able_to(:show, Role.find_by(name: 'organization_admin', resource: @other_organization)) } + it{ should_not be_able_to(:update, Role.find_by(name: 'organization_admin', resource: other_organization)) } + it{ should_not be_able_to(:edit, Role.find_by(name: 'organization_admin', resource: other_organization)) } + it{ should_not be_able_to(:show, Role.find_by(name: 'organization_admin', resource: other_organization)) } - %w(organizer cfp info_desk volunteers_coordinator).each do |role| - it{ should_not be_able_to(:toggle_user, Role.find_by(name: role, resource: @other_conference)) } - it{ should_not be_able_to(:update, Role.find_by(name: role, resource: @other_conference)) } - it{ should_not be_able_to(:edit, Role.find_by(name: role, resource: @other_conference)) } - it{ should be_able_to(:show, Role.find_by(name: role, resource: @other_conference)) } - it{ should be_able_to(:index, Role.find_by(name: role, resource: @other_conference)) } - end + %w(organizer cfp info_desk volunteers_coordinator).each do |role| + it{ should_not be_able_to(:toggle_user, Role.find_by(name: role, resource: other_conference)) } + it{ should_not be_able_to(:update, Role.find_by(name: role, resource: other_conference)) } + it{ should_not be_able_to(:edit, Role.find_by(name: role, resource: other_conference)) } + it{ should be_able_to(:show, Role.find_by(name: role, resource: other_conference)) } + it{ should be_able_to(:index, Role.find_by(name: role, resource: other_conference)) } + end end shared_examples 'user with non-organizer role' do |role_name| @@ -199,8 +197,8 @@ describe 'User' do it{ should_not be_able_to(:new, Organization)} it{ should_not be_able_to(:create, Organization)} - it{ should_not be_able_to(:new, Conference.new) } - it{ should_not be_able_to(:create, Conference.new) } + it{ should_not be_able_to(:new, Conference)} + it{ should_not be_able_to(:create, Conference) } it{ should be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should be_able_to(:manage, my_conference.splashpage) } @@ -269,8 +267,8 @@ describe 'User' do let(:role) { Role.find_by(name: 'cfp', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } - it{ should_not be_able_to(:new, Conference.new) } - it{ should_not be_able_to(:create, Conference.new) } + it{ should_not be_able_to(:new, Conference) } + it{ should_not be_able_to(:create, Conference) } it{ should_not be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should_not be_able_to(:manage, my_conference.splashpage) } @@ -336,8 +334,8 @@ describe 'User' do let(:role) { Role.find_by(name: 'info_desk', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } - it{ should_not be_able_to(:new, Conference.new) } - it{ should_not be_able_to(:create, Conference.new) } + it{ should_not be_able_to(:new, Conference) } + it{ should_not be_able_to(:create, Conference) } it{ should_not be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should_not be_able_to(:manage, my_conference.splashpage) } @@ -403,8 +401,8 @@ describe 'User' do let(:role) { Role.find_by(name: 'volunteers_coordinator', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } - it{ should_not be_able_to(:new, Conference.new) } - it{ should_not be_able_to(:create, Conference.new) } + it{ should_not be_able_to(:new, Conference) } + it{ should_not be_able_to(:create, Conference) } it{ should_not be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should_not be_able_to(:manage, my_conference.splashpage) } From d59a036cf17b405df38bbdf13aafce6dcef838df Mon Sep 17 00:00:00 2001 From: shlok007 Date: Fri, 30 Jun 2017 09:27:19 +0530 Subject: [PATCH 09/11] removed unnecessary comments and fixed grammatical errors --- spec/features/cfp_ability_spec.rb | 3 +-- spec/features/info_desk_ability_spec.rb | 5 +---- spec/features/organization_admin_ability_spec.rb | 2 +- spec/features/organization_spec.rb | 6 +++--- spec/features/organizer_ability_spec.rb | 3 +-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb index 52725527..235dedea 100644 --- a/spec/features/cfp_ability_spec.rb +++ b/spec/features/cfp_ability_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' feature 'Has correct abilities' do let(:organization) { create(:organization) } - # It is necessary to use bang version of let to build roles before user - let(:conference) { create(:full_conference, organization: organization) } # user is cfp + let(:conference) { create(:full_conference, organization: organization) } let(:role_cfp) { Role.find_by(name: 'cfp', resource: conference) } let(:user_cfp) { create(:user, role_ids: [role_cfp.id]) } diff --git a/spec/features/info_desk_ability_spec.rb b/spec/features/info_desk_ability_spec.rb index d7b0b909..7d0039fe 100644 --- a/spec/features/info_desk_ability_spec.rb +++ b/spec/features/info_desk_ability_spec.rb @@ -3,11 +3,8 @@ require 'spec_helper' feature 'Has correct abilities' do let(:organization) { create(:organization) } - # It is necessary to use bang version of let to build roles before user - let(:conference) { create(:full_conference, organization: organization) } # user is info_desk - + let(:conference) { create(:full_conference, organization: organization) } let(:role_info_desk) { Role.find_by(name: 'info_desk', resource: conference) } - let(:user_info_desk) { create(:user, role_ids: [role_info_desk.id]) } context 'when user is info desk' do diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb index 5a247dd8..3a5ffcd3 100644 --- a/spec/features/organization_admin_ability_spec.rb +++ b/spec/features/organization_admin_ability_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' feature 'Has correct abilities' do let(:organization) { create(:organization) } - let(:conference) { create(:full_conference, organization: organization) } # user is organization_admin + let(:conference) { create(:full_conference, organization: organization) } let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) } let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) } diff --git a/spec/features/organization_spec.rb b/spec/features/organization_spec.rb index 72fee466..6fcf590b 100644 --- a/spec/features/organization_spec.rb +++ b/spec/features/organization_spec.rb @@ -6,7 +6,7 @@ feature Organization do let(:organization_admin) { create(:user, role_ids: [organization_admin_role.id]) } let(:admin_user) { create(:admin) } - shared_examples 'successfully updates a organization' do + shared_examples 'successfully updates an organization' do scenario 'updates a exsisting organization', feature: true, js: true do visit edit_admin_organization_path(organization) fill_in 'organization_name', with: 'changed name' @@ -33,7 +33,7 @@ feature Organization do expect(Organization.last.name).to eq('Organization name') end - it_behaves_like 'successfully updates a organization' + it_behaves_like 'successfully updates an organization' end context 'signed in as organization admin' do @@ -46,6 +46,6 @@ feature Organization do expect(flash).to eq('You are not authorized to access this page.') end - it_behaves_like 'successfully updates a organization' + it_behaves_like 'successfully updates an organization' end end diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index 9604fad6..7617bc0a 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' feature 'Has correct abilities' do let(:organization) { create(:organization) } - # It is necessary to use bang version of let to build roles before user - let(:conference) { create(:full_conference, organization: organization) } # user is organizer + let(:conference) { create(:full_conference, organization: organization) } let(:other_conference) { create(:conference, organization: organization) } # user is organizer, venue is not set by default let(:role_organizer_conf) { Role.find_by(name: 'organizer', resource: conference) } let(:role_organizer_other_conf) { Role.find_by(name: 'organizer', resource: other_conference) } From f68fd39095915bcfda29a41b1ddc2abc19aa8695 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Mon, 3 Jul 2017 04:17:06 +0530 Subject: [PATCH 10/11] fixed abilities for conference#new and organization#new --- app/models/ability.rb | 6 +++--- spec/models/ability_spec.rb | 38 +++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 8185fadd..5001278a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -150,11 +150,11 @@ class Ability def signed_in_with_organization_admin_role(user) org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) + conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id) - can :manage, Organization, id: org_ids_for_organization_admin + can [:read, :update, :destroy], Organization, id: org_ids_for_organization_admin can :new, Conference can :manage, Conference, organization_id: org_ids_for_organization_admin - conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id) can [:index, :show], Role can [:edit, :update], Role do |role| role.resource_type == 'Organization' && (org_ids_for_organization_admin.include? role.resource_id) @@ -167,7 +167,7 @@ class Ability # conferences that belong to organizations for which user is 'organization_admin' conf_ids = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq can :manage, Resource, conference_id: conf_ids - can :manage, Conference, id: conf_ids + can [:read, :update, :destroy], Conference, id: conf_ids can :manage, Splashpage, conference_id: conf_ids can :manage, Contact, conference_id: conf_ids can :manage, EmailSettings, conference_id: conf_ids diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 6803ffc5..02aa4882 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -172,11 +172,19 @@ describe 'User' do context 'when user has the role organization_admin' do let(:role) { Role.find_by(name: 'organization_admin', resource: organization) } let(:user) { create(:user, role_ids: [role.id]) } - let(:other_conference) { create(:conference) } + let(:other_organization) { create(:organization) } + let(:other_conference) { create(:conference, organization: other_organization) } - it{ should_not be_able_to(:manage, other_conference) } it{ should be_able_to(:manage, my_conference) } - it{ should be_able_to(:manage, organization) } + it{ should be_able_to(:read, organization) } + it{ should be_able_to(:update, organization) } + it{ should be_able_to(:destroy, organization) } + it{ should be_able_to(:new, Conference.new) } + it{ should be_able_to(:create, Conference.new(organization_id: organization.id)) } + it{ should_not be_able_to(:manage, other_conference) } + it{ should_not be_able_to(:create, Conference.new(organization_id: other_organization.id)) } + it{ should_not be_able_to(:new, Organization.new) } + it{ should_not be_able_to(:create, Organization.new) } end context 'when user has the role organizer' do @@ -195,11 +203,13 @@ describe 'User' do should be_able_to(:destroy, my_venue) end - it{ should_not be_able_to(:new, Organization)} - it{ should_not be_able_to(:create, Organization)} - it{ should_not be_able_to(:new, Conference)} - it{ should_not be_able_to(:create, Conference) } - it{ should be_able_to(:manage, my_conference) } + it{ should_not be_able_to(:new, Organization.new)} + it{ should_not be_able_to(:create, Organization.new)} + it{ should_not be_able_to(:new, Conference.new)} + it{ should_not be_able_to(:create, Conference.new) } + it{ should be_able_to(:read, my_conference) } + it{ should be_able_to(:update, my_conference) } + it{ should be_able_to(:destroy, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should be_able_to(:manage, my_conference.splashpage) } it{ should_not be_able_to(:manage, conference_public.splashpage) } @@ -267,8 +277,8 @@ describe 'User' do let(:role) { Role.find_by(name: 'cfp', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } - it{ should_not be_able_to(:new, Conference) } - it{ should_not be_able_to(:create, Conference) } + it{ should_not be_able_to(:new, Conference.new) } + it{ should_not be_able_to(:create, Conference.new) } it{ should_not be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should_not be_able_to(:manage, my_conference.splashpage) } @@ -334,8 +344,8 @@ describe 'User' do let(:role) { Role.find_by(name: 'info_desk', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } - it{ should_not be_able_to(:new, Conference) } - it{ should_not be_able_to(:create, Conference) } + it{ should_not be_able_to(:new, Conference.new) } + it{ should_not be_able_to(:create, Conference.new) } it{ should_not be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should_not be_able_to(:manage, my_conference.splashpage) } @@ -401,8 +411,8 @@ describe 'User' do let(:role) { Role.find_by(name: 'volunteers_coordinator', resource: my_conference) } let(:user) { create(:user, role_ids: [role.id]) } - it{ should_not be_able_to(:new, Conference) } - it{ should_not be_able_to(:create, Conference) } + it{ should_not be_able_to(:new, Conference.new) } + it{ should_not be_able_to(:create, Conference.new) } it{ should_not be_able_to(:manage, my_conference) } it{ should_not be_able_to(:manage, conference_public) } it{ should_not be_able_to(:manage, my_conference.splashpage) } From 7d472f2ad5670fd754eb44d56358a8cd50c75e94 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 4 Jul 2017 05:55:41 +0530 Subject: [PATCH 11/11] fix failing tests --- app/views/admin/registration_periods/show.html.haml | 2 +- app/views/admin/splashpages/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/registration_periods/show.html.haml b/app/views/admin/registration_periods/show.html.haml index 9ef02e37..057a7a37 100644 --- a/app/views/admin/registration_periods/show.html.haml +++ b/app/views/admin/registration_periods/show.html.haml @@ -25,5 +25,5 @@ = link_to 'Delete', admin_conference_registration_period_path, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' - else - - if can? :create, @conference + - if can? :create, @conference.build_registration_period = link_to 'New Registration Period', new_admin_conference_registration_period_path, class: 'btn btn-primary' diff --git a/app/views/admin/splashpages/show.html.haml b/app/views/admin/splashpages/show.html.haml index 0c6be8a8..b4e5f24c 100644 --- a/app/views/admin/splashpages/show.html.haml +++ b/app/views/admin/splashpages/show.html.haml @@ -90,5 +90,5 @@ - else .row .col-md-12.text-right - - if can? :create, @conference + - if can? :create, @conference.build_splashpage = link_to 'Create Splashpage', new_admin_conference_splashpage_path, class: 'btn btn-primary'