verify user if accessing admin area. Testing: setup organizer_conference_1_role
This commit is contained in:
parent
ab17e6db11
commit
940f76bf13
22 changed files with 91 additions and 62 deletions
|
|
@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
before_filter :get_conferences
|
before_filter :get_conferences
|
||||||
before_filter :store_location
|
before_filter :store_location
|
||||||
|
before_filter :verify_user_admin
|
||||||
helper_method :date_string
|
helper_method :date_string
|
||||||
# Ensure every controller authorizes resource or skips authorization (skip_authorization_check)
|
# Ensure every controller authorizes resource or skips authorization (skip_authorization_check)
|
||||||
check_authorization unless: :devise_controller?
|
check_authorization unless: :devise_controller?
|
||||||
|
|
@ -33,6 +34,12 @@ class ApplicationController < ActionController::Base
|
||||||
@conferences =Conference.all
|
@conferences =Conference.all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_user_admin
|
||||||
|
if self.class.to_s.split('::').first == 'Admin'
|
||||||
|
verify_user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def verify_user
|
def verify_user
|
||||||
:authenticate_user!
|
:authenticate_user!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,9 @@ class Ability
|
||||||
# Ids of all the conferences for which the user has an 'organizer' role
|
# Ids of all the conferences for which the user has an 'organizer' role
|
||||||
conf_ids_for_organizer =
|
conf_ids_for_organizer =
|
||||||
Conference.with_role(:organizer, user).pluck(:id) unless user.new_record?
|
Conference.with_role(:organizer, user).pluck(:id) unless user.new_record?
|
||||||
|
# Ids of the venues of the conference for which (conferences) the user has an 'organizer' role
|
||||||
|
conf_ids_for_organizer_venue =
|
||||||
|
Conference.with_role(:organizer, user).pluck(:venue_id) unless user.new_record?
|
||||||
# Ids of all the conferences for which the user has a 'cfp' role
|
# Ids of all the conferences for which the user has a 'cfp' role
|
||||||
conf_ids_for_cfp =
|
conf_ids_for_cfp =
|
||||||
Conference.with_role(:cfp, user).pluck(:id) unless user.new_record?
|
Conference.with_role(:cfp, user).pluck(:id) unless user.new_record?
|
||||||
|
|
@ -105,7 +108,7 @@ class Ability
|
||||||
# Authorize Conference by its 'id' attribute
|
# Authorize Conference by its 'id' attribute
|
||||||
can :manage, Conference, id: conf_ids_for_organizer
|
can :manage, Conference, id: conf_ids_for_organizer
|
||||||
# Authorize venues of conferences, which user can manage
|
# Authorize venues of conferences, which user can manage
|
||||||
can :manage, Venue, conference: { id: conf_ids_for_organizer }
|
can :manage, Venue, id: conf_ids_for_organizer_venue
|
||||||
# id: Conference.where(id: conf_ids_for_organizer).map(&:venue_id)
|
# id: Conference.where(id: conf_ids_for_organizer).map(&:venue_id)
|
||||||
# User can view the admin 'users' page if he is an organizer for any conference
|
# User can view the admin 'users' page if he is an organizer for any conference
|
||||||
can :manage, User if user.has_role?('organizer', :any)
|
can :manage, User if user.has_role?('organizer', :any)
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ require 'spec_helper'
|
||||||
describe Admin::ConferenceController do
|
describe Admin::ConferenceController do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
|
||||||
|
|
||||||
let(:conference) { create(:conference) }
|
let(:conference) { create(:conference) }
|
||||||
let(:organizer) { create(:organizer) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
|
let!(:organizer_role) { create(:organizer_conference_1_role, resource_id: conference.id) }
|
||||||
|
|
||||||
|
let(:organizer) { create(:organizer_conference_1, is_admin: true) }
|
||||||
let(:participant) { create(:participant) }
|
let(:participant) { create(:participant) }
|
||||||
|
|
||||||
shared_examples 'access as administration' do
|
shared_examples 'access as administration' do
|
||||||
|
|
@ -226,34 +226,42 @@ describe Admin::ConferenceController do
|
||||||
it 'requires organizer privileges' do
|
it 'requires organizer privileges' do
|
||||||
get :show, id: conference.short_title
|
get :show, id: conference.short_title
|
||||||
expect(response).to redirect_to(send(path))
|
expect(response).to redirect_to(send(path))
|
||||||
|
if message
|
||||||
expect(flash[:alert]).to match(/#{message}/)
|
expect(flash[:alert]).to match(/#{message}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
it 'requires organizer privileges' do
|
it 'requires organizer privileges' do
|
||||||
get :index
|
get :index
|
||||||
expect(response).to redirect_to(send(path))
|
expect(response).to redirect_to(send(path))
|
||||||
|
if message
|
||||||
expect(flash[:alert]).to match(/#{message}/)
|
expect(flash[:alert]).to match(/#{message}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'GET #new' do
|
describe 'GET #new' do
|
||||||
it 'requires organizer privileges' do
|
it 'requires organizer privileges' do
|
||||||
get :new
|
get :new
|
||||||
expect(response).to redirect_to(send(path))
|
expect(response).to redirect_to(send(path))
|
||||||
|
if message
|
||||||
expect(flash[:alert]).to match(/#{message}/)
|
expect(flash[:alert]).to match(/#{message}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
it 'requires organizer privileges' do
|
it 'requires organizer privileges' do
|
||||||
post :create, conference: attributes_for(:conference,
|
post :create, conference: attributes_for(:conference,
|
||||||
short_title: 'ExCon')
|
short_title: 'ExCon')
|
||||||
expect(response).to redirect_to(send(path))
|
expect(response).to redirect_to(send(path))
|
||||||
|
if message
|
||||||
expect(flash[:alert]).to match(/#{message}/)
|
expect(flash[:alert]).to match(/#{message}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'PATCH #update' do
|
describe 'PATCH #update' do
|
||||||
it 'requires organizer privileges' do
|
it 'requires organizer privileges' do
|
||||||
|
|
@ -261,10 +269,12 @@ describe Admin::ConferenceController do
|
||||||
conference: attributes_for(:conference,
|
conference: attributes_for(:conference,
|
||||||
short_title: 'ExCon')
|
short_title: 'ExCon')
|
||||||
expect(response).to redirect_to(send(path))
|
expect(response).to redirect_to(send(path))
|
||||||
|
if message
|
||||||
expect(flash[:alert]).to match(/#{message}/)
|
expect(flash[:alert]).to match(/#{message}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'participant access' do
|
describe 'participant access' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
@ -277,7 +287,7 @@ describe Admin::ConferenceController do
|
||||||
|
|
||||||
describe 'guest access' do
|
describe 'guest access' do
|
||||||
|
|
||||||
it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this page.'
|
it_behaves_like 'access as participant or guest', :new_user_session_path
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe Admin::UsersController do
|
describe Admin::UsersController do
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_role) { create(:organizer_conference_1_role ) }
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let(:organizer) { create(:organizer) }
|
let(:organizer) { create(:organizer_conference_1) }
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
before(:each) do
|
before(:each) do
|
||||||
sign_in(organizer)
|
sign_in(organizer)
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,17 @@ FactoryGirl.define do
|
||||||
factory :role do
|
factory :role do
|
||||||
|
|
||||||
factory :organizer_role do
|
factory :organizer_role do
|
||||||
name 'Organizer'
|
name 'organizer'
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :participant_role do
|
factory :participant_role do
|
||||||
name 'Participant'
|
name 'Participant'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :organizer_conference_1_role do
|
||||||
|
name 'organizer'
|
||||||
|
resource_type 'Conference'
|
||||||
|
resource_id 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,12 @@ FactoryGirl.define do
|
||||||
after(:create) { |user| user.role_ids = create(:participant_role).id }
|
after(:create) { |user| user.role_ids = create(:participant_role).id }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :organizer do
|
factory :organizer_conference_1 do
|
||||||
after(:create) { |user| user.role_ids = create(:organizer_role).id }
|
after(:create) { |user| user.role_ids = create(:organizer_conference_1_role).id }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :admin do
|
||||||
|
is_admin true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ feature Campaign do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'add and update campaign' do |user|
|
shared_examples 'add and update campaign' do |user|
|
||||||
scenario 'adds and update a campaign', feature: true, js: true do
|
scenario 'adds and update a campaign', feature: true, js: true do
|
||||||
|
|
@ -52,6 +52,6 @@ feature Campaign do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'add and update campaign', :organizer
|
it_behaves_like 'add and update campaign', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ feature Conference do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'add and update cfp' do |user|
|
shared_examples 'add and update cfp' do |user|
|
||||||
scenario 'adds a new cfp', feature: true, js: true do
|
scenario 'adds a new cfp', feature: true, js: true do
|
||||||
|
|
@ -87,6 +87,6 @@ feature Conference do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'add and update cfp', :organizer
|
it_behaves_like 'add and update cfp', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ feature Conference do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'add and update conference' do |user|
|
shared_examples 'add and update conference' do |user|
|
||||||
scenario 'adds a new conference', feature: true, js: true do
|
scenario 'adds a new conference', feature: true, js: true do
|
||||||
|
|
@ -36,7 +36,7 @@ feature Conference do
|
||||||
scenario 'update conference', feature: true, js: true do
|
scenario 'update conference', feature: true, js: true do
|
||||||
conference = create(:conference)
|
conference = create(:conference)
|
||||||
expected_count = Conference.count
|
expected_count = Conference.count
|
||||||
sign_in create(user)
|
sign_in create(:organizer_conference_1_role)
|
||||||
|
|
||||||
visit edit_admin_conference_path(conference.short_title)
|
visit edit_admin_conference_path(conference.short_title)
|
||||||
fill_in 'conference_title', with: 'New Con'
|
fill_in 'conference_title', with: 'New Con'
|
||||||
|
|
@ -56,6 +56,6 @@ feature Conference do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'add and update conference', :organizer
|
it_behaves_like 'add and update conference', :admin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature DifficultyLevel do
|
feature DifficultyLevel do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'difficulty levels' do |user|
|
shared_examples 'difficulty levels' do |user|
|
||||||
scenario 'adds and updates difficulty level', feature: true, js: true do
|
scenario 'adds and updates difficulty level', feature: true, js: true do
|
||||||
|
|
@ -50,6 +50,6 @@ feature DifficultyLevel do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'difficulty levels', :organizer
|
it_behaves_like 'difficulty levels', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature Event do
|
feature Event do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'email settings' do |user|
|
shared_examples 'email settings' do |user|
|
||||||
scenario 'updates email settings',
|
scenario 'updates email settings',
|
||||||
|
|
@ -91,6 +91,6 @@ feature Event do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'email settings', :organizer
|
it_behaves_like 'email settings', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature EventType do
|
feature EventType do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'event types' do |user|
|
shared_examples 'event types' do |user|
|
||||||
scenario 'adds and updates event type', feature: true, js: true do
|
scenario 'adds and updates event type', feature: true, js: true do
|
||||||
|
|
@ -55,6 +55,6 @@ feature EventType do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'event types', :organizer
|
it_behaves_like 'event types', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature Lodging do
|
feature Lodging do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'lodgings' do |user|
|
shared_examples 'lodgings' do |user|
|
||||||
scenario 'adds and updates lodgings', feature: true, js: true do
|
scenario 'adds and updates lodgings', feature: true, js: true do
|
||||||
|
|
@ -56,6 +56,6 @@ feature Lodging do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'lodgings', :organizer
|
it_behaves_like 'lodgings', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ require 'spec_helper'
|
||||||
feature Event do
|
feature Event do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'proposal workflow' do
|
shared_examples 'proposal workflow' do
|
||||||
scenario 'submitts a proposal, accepts and confirms',
|
scenario 'submitts a proposal, accepts and confirms',
|
||||||
feature: true, js: true do
|
feature: true, js: true do
|
||||||
|
|
||||||
organizer = create(:organizer, email: 'admin@example.com')
|
organizer = create(:organizer_conference_1, email: 'admin@example.com')
|
||||||
participant = create(:participant, email: 'participant@example.com')
|
participant = create(:participant, email: 'participant@example.com')
|
||||||
|
|
||||||
expected_count = Event.count + 1
|
expected_count = Event.count + 1
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature Room do
|
feature Room do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'rooms' do |user|
|
shared_examples 'rooms' do |user|
|
||||||
scenario 'adds and updates rooms', feature: true, js: true do
|
scenario 'adds and updates rooms', feature: true, js: true do
|
||||||
|
|
@ -43,6 +43,6 @@ feature Room do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'rooms', :organizer
|
it_behaves_like 'rooms', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature Sponsor do
|
feature Sponsor do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'sponsors' do |user|
|
shared_examples 'sponsors' do |user|
|
||||||
scenario 'adds and updates sponsors', feature: true, js: true do
|
scenario 'adds and updates sponsors', feature: true, js: true do
|
||||||
|
|
@ -69,6 +69,6 @@ feature Sponsor do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'sponsors', :organizer
|
it_behaves_like 'sponsors', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature SponsorshipLevel do
|
feature SponsorshipLevel do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'sponsorship levels' do |user|
|
shared_examples 'sponsorship levels' do |user|
|
||||||
scenario 'adds and updates sponsorship level', feature: true, js: true do
|
scenario 'adds and updates sponsorship level', feature: true, js: true do
|
||||||
|
|
@ -36,6 +36,6 @@ feature SponsorshipLevel do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'sponsorship levels', :organizer
|
it_behaves_like 'sponsorship levels', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature SupporterLevel do
|
feature SupporterLevel do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'supporter levels' do |user|
|
shared_examples 'supporter levels' do |user|
|
||||||
scenario 'adds and updates supporter level', feature: true, js: true do
|
scenario 'adds and updates supporter level', feature: true, js: true do
|
||||||
|
|
@ -43,6 +43,6 @@ feature SupporterLevel do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'supporter levels', :organizer
|
it_behaves_like 'supporter levels', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
feature Track do
|
feature Track do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'tracks' do |user|
|
shared_examples 'tracks' do |user|
|
||||||
scenario 'adds and updates tracks', feature: true, js: true do
|
scenario 'adds and updates tracks', feature: true, js: true do
|
||||||
|
|
@ -50,6 +50,6 @@ feature Track do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'tracks', :organizer
|
it_behaves_like 'tracks', :organizer_conference_1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ feature Conference do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_role) { create(:organizer_conference_1_role) }
|
||||||
|
|
||||||
shared_examples 'venue' do |user|
|
shared_examples 'venue' do |user|
|
||||||
scenario 'adds and updates venue' do
|
scenario 'adds and updates venue' do
|
||||||
|
|
@ -59,7 +59,7 @@ feature Conference do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer' do
|
describe 'organizer' do
|
||||||
it_behaves_like 'venue', :organizer
|
it_behaves_like 'venue', :organizer_conference_1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ require 'spec_helper'
|
||||||
feature Conference do
|
feature Conference do
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role) { create(:organizer_conference_1_role) }
|
||||||
let(:organizer) { create(:organizer) }
|
let(:organizer) { create(:organizer_conference_1) }
|
||||||
let(:conference) { create(:conference) }
|
let(:conference) { create(:conference) }
|
||||||
|
|
||||||
shared_examples 'volunteer' do
|
shared_examples 'volunteer' do
|
||||||
|
|
|
||||||
|
|
@ -4,44 +4,44 @@ describe User do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:organizer_role) { create(:organizer_role) }
|
let!(:organizer_conference_1_role ) { create(:organizer_conference_1_role ) }
|
||||||
let!(:organizer) { create(:user) }
|
let!(:organizer) { create(:organizer_conference_1 ) }
|
||||||
|
|
||||||
it 'returns the correct role' do
|
it 'returns the correct role' do
|
||||||
participant = create(:user, email: 'participant@example.de')
|
participant = create(:user, email: 'participant@example.de')
|
||||||
expect(organizer.roles.first).to eq(organizer_role)
|
expect(organizer.roles.first).to eq(organizer_conference_1_role)
|
||||||
expect(participant.roles.first).to eq(participant_role)
|
expect(participant.roles.first).to eq(organizer_conference_1_role)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the correct roles' do
|
it 'returns the correct roles' do
|
||||||
roles = [participant_role.id, organizer_role.id]
|
roles = [participant_role.id, organizer_conference_1_role.id]
|
||||||
user_with_all_roles = create(:user, email: 'participant@example.de')
|
user_with_all_roles = create(:user, email: 'participant@example.de')
|
||||||
user_with_all_roles.role_ids = roles
|
user_with_all_roles.role_ids = roles
|
||||||
user_with_all_roles.save
|
user_with_all_roles.save
|
||||||
|
|
||||||
expect(user_with_all_roles.roles.length).to eq(2)
|
expect(user_with_all_roles.roles.length).to eq(2)
|
||||||
expect(user_with_all_roles.roles[0]).to eq(participant_role)
|
expect(user_with_all_roles.roles[0]).to eq(participant_role)
|
||||||
expect(user_with_all_roles.roles[1]).to eq(organizer_role)
|
expect(user_with_all_roles.roles[1]).to eq(organizer_conference_1_role )
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#role?' do
|
describe '#role?' do
|
||||||
shared_examples '#role?' do |user, role, expected|
|
shared_examples '#role?' do |user, role, expected|
|
||||||
it "returns #{expected} for #{role}" do
|
it "returns #{expected} for #{role}" do
|
||||||
user_obj = create(user, email: 'e@example.com')
|
user_obj = create(user, email: 'e@example.com')
|
||||||
expect(user_obj.role?(role)).to be expected
|
expect(user_obj.has_role?(role)).to be expected
|
||||||
expect(user_obj.role?(role.downcase)).to be expected
|
expect(user_obj.has_role?(role.downcase)).to be expected
|
||||||
expect(user_obj.role?(role.upcase)).to be expected
|
expect(user_obj.has_role?(role.upcase)).to be expected
|
||||||
expect(user_obj.role?(role.downcase.capitalize)).to be expected
|
expect(user_obj.has_role?(role.downcase.capitalize)).to be expected
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'organizer' do
|
context 'organizer' do
|
||||||
it_behaves_like '#role?', :organizer, 'oRganIzeR', true
|
it_behaves_like '#role?', :organizer_conference_1_role, 'oRganIzeR', true
|
||||||
it_behaves_like '#role?', :organizer, 'partiCipant', false
|
it_behaves_like '#role?', :organizer_conference_1_role, 'partiCipant', false
|
||||||
|
|
||||||
it 'assigns first user organizer role' do
|
it 'assigns first user organizer role' do
|
||||||
expect(organizer.role?('Organizer')).to be true
|
expect(organizer.has_role?('organizer', Conference.first)).to be true
|
||||||
expect(organizer.role_ids).to match_array([organizer_role.id])
|
expect(organizer.role_ids).to match_array([organizer_conference_1_role.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue