rework roles with rolify
This commit is contained in:
parent
f9f840c811
commit
4af0e59ca6
40 changed files with 167 additions and 228 deletions
3
Gemfile
3
Gemfile
|
|
@ -23,6 +23,9 @@ gem 'omniauth-google-oauth2'
|
|||
# Use cancancan as authorization framework
|
||||
gem 'cancancan'
|
||||
|
||||
# Use rolify to set roles
|
||||
gem 'rolify'
|
||||
|
||||
# Use transitions as state machine
|
||||
gem 'transitions', :require => %w( transitions active_record/transitions )
|
||||
|
||||
|
|
|
|||
|
|
@ -296,6 +296,7 @@ GEM
|
|||
request_store (1.0.6)
|
||||
rest-client (1.6.7)
|
||||
mime-types (>= 1.16)
|
||||
rolify (3.4.0)
|
||||
rspec (3.0.0)
|
||||
rspec-core (~> 3.0.0)
|
||||
rspec-expectations (~> 3.0.0)
|
||||
|
|
@ -441,6 +442,7 @@ DEPENDENCIES
|
|||
rails-observers
|
||||
rdoc-generator-fivefish
|
||||
redcarpet
|
||||
rolify
|
||||
rspec-activemodel-mocks
|
||||
rspec-rails
|
||||
rubocop
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
class Role < ActiveRecord::Base
|
||||
attr_accessible :name
|
||||
attr_accessible :name, :description
|
||||
has_and_belongs_to_many :users
|
||||
belongs_to :resource, polymorphic: true
|
||||
|
||||
scopify
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
class User < ActiveRecord::Base
|
||||
rolify
|
||||
include Gravtastic
|
||||
gravtastic size: 32
|
||||
|
||||
before_create :setup_role
|
||||
|
||||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :confirmable,
|
||||
# :lockable, :timeoutable and :omniauthable
|
||||
|
|
@ -23,8 +26,6 @@ class User < ActiveRecord::Base
|
|||
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
before_create :setup_role
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
# Searches for user based on email. Returns found user or new user.
|
||||
|
|
@ -47,26 +48,13 @@ class User < ActiveRecord::Base
|
|||
user
|
||||
end
|
||||
|
||||
def role?(role)
|
||||
Rails.logger.debug('Checking role in user')
|
||||
!!roles.find_by_name(role.to_s.downcase.camelize)
|
||||
end
|
||||
|
||||
def admin?
|
||||
role?('Admin')
|
||||
end
|
||||
|
||||
def organizer?
|
||||
role?('Organizer')
|
||||
end
|
||||
|
||||
def get_roles
|
||||
roles
|
||||
end
|
||||
|
||||
def setup_role
|
||||
roles << Role.where(name: 'Admin') if User.count == 0
|
||||
roles << Role.where(name: 'Participant') if roles.empty?
|
||||
roles << Role.where(name: 'organizer') if User.count == 0
|
||||
roles << Role.where(name: 'participant') if roles.empty?
|
||||
end
|
||||
|
||||
def self.prepare(params)
|
||||
|
|
|
|||
8
config/initializers/rolify.rb
Normal file
8
config/initializers/rolify.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Rolify.configure do |config|
|
||||
# By default ORM adapter is ActiveRecord. uncomment to use mongoid
|
||||
# config.use_mongoid
|
||||
|
||||
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
|
||||
# Enable this feature _after_ running rake db:migrate as it relies on the roles table
|
||||
config.use_dynamic_shortcuts
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class AddDescriptionAndResourceToRoles < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :roles, :description, :string
|
||||
add_reference :roles, :resource, polymorphic: true
|
||||
|
||||
add_index(:roles, :name)
|
||||
add_index(:roles, [:name, :resource_type, :resource_id])
|
||||
add_index(:roles_users, [:user_id, :role_id])
|
||||
end
|
||||
end
|
||||
|
|
@ -352,15 +352,23 @@ ActiveRecord::Schema.define(version: 20140724113107) do
|
|||
|
||||
create_table "roles", force: true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.integer "resource_id"
|
||||
t.string "resource_type"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
|
||||
add_index "roles", ["name"], name: "index_roles_on_name"
|
||||
|
||||
create_table "roles_users", id: false, force: true do |t|
|
||||
t.integer "role_id"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
add_index "roles_users", ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id"
|
||||
|
||||
create_table "rooms", force: true do |t|
|
||||
t.string "guid", null: false
|
||||
t.integer "conference_id"
|
||||
|
|
|
|||
24
db/seeds.rb
24
db/seeds.rb
|
|
@ -5,22 +5,28 @@
|
|||
#
|
||||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
||||
# Mayor.create(name: 'Emanuel', city: cities.first)
|
||||
Role.create(name: "Participant")
|
||||
Role.create(name: "Organizer")
|
||||
Role.create(name: "Admin")
|
||||
|
||||
qtype_yesno = QuestionType.create(title: "Yes/No")
|
||||
QuestionType.create(title: "Single Choice")
|
||||
QuestionType.create(title: "Multiple Choice")
|
||||
# Questions
|
||||
qtype_yesno = QuestionType.create(title: 'Yes/No')
|
||||
qtype_single = QuestionType.create(title: 'Single Choice')
|
||||
qtype_multiple = QuestionType.create(title: 'Multiple Choice')
|
||||
|
||||
answer_yes = Answer.create(title: "Yes")
|
||||
answer_no = Answer.create(title: "No")
|
||||
<<<<<<< HEAD
|
||||
questions_yes_no.each do |i|
|
||||
q = Question.create(title: i, question_type_id: qtype_yesno.id, global: true)
|
||||
|
||||
questions_yes_no = ["Do you need handicapped access to the venue?", "Are you attending with partner?", "Will you attend the social event(s)?", "Will you stay at suggested hotel?"]
|
||||
=======
|
||||
answer_yes = Answer.create(title: 'Yes')
|
||||
answer_no = Answer.create(title: 'No')
|
||||
|
||||
questions_yes_no = ['Do you need handicapped access to the venue?',
|
||||
'Are you attending with partner?', 'Will you attend the social event(s)?',
|
||||
'Will you stay at suggested hotel?']
|
||||
|
||||
questions_yes_no.each do |i|
|
||||
q = Question.create(title: i, question_type_id: qtype_yesno.id, global: true)
|
||||
|
||||
>>>>>>> rework roles with rolify
|
||||
Qanswer.create(question_id: q.id, answer_id: answer_no.id)
|
||||
Qanswer.create(question_id: q.id, answer_id: answer_yes.id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,16 +3,14 @@ require 'spec_helper'
|
|||
describe Admin::ConferenceController do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
let(:conference) { create(:conference) }
|
||||
let(:admin) { create(:admin) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
let(:participant) { create(:participant) }
|
||||
|
||||
shared_examples 'access as administration or organizer' do
|
||||
shared_examples 'access as administration' do
|
||||
|
||||
describe 'PATCH #update' do
|
||||
|
||||
|
|
@ -27,7 +25,7 @@ describe Admin::ConferenceController do
|
|||
it 'changes conference attributes' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con',
|
||||
short_title: 'ExCon')
|
||||
short_title: 'ExCon')
|
||||
|
||||
conference.reload
|
||||
expect(conference.title).to eq('Example Con')
|
||||
|
|
@ -67,7 +65,7 @@ describe Admin::ConferenceController do
|
|||
it 'does not change conference attributes' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con',
|
||||
short_title: nil)
|
||||
short_title: nil)
|
||||
|
||||
conference.reload
|
||||
expect(flash[:alert]).
|
||||
|
|
@ -79,7 +77,7 @@ describe Admin::ConferenceController do
|
|||
it 're-renders the #show template' do
|
||||
patch :update, id: conference.short_title, conference:
|
||||
attributes_for(:conference, title: 'Example Con',
|
||||
short_title: nil)
|
||||
short_title: nil)
|
||||
|
||||
expect(flash[:alert]).
|
||||
to eq("Updating conference failed. Short title can't be blank.")
|
||||
|
|
@ -216,59 +214,54 @@ describe Admin::ConferenceController do
|
|||
describe 'administrator access' do
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it_behaves_like 'access as administration or organizer'
|
||||
|
||||
end
|
||||
|
||||
describe 'organizer access' do
|
||||
|
||||
before(:each) do
|
||||
sign_in(organizer)
|
||||
end
|
||||
|
||||
it_behaves_like 'access as administration or organizer'
|
||||
it_behaves_like 'access as administration'
|
||||
|
||||
end
|
||||
|
||||
shared_examples 'access as participant or guest' do |success_path|
|
||||
shared_examples 'access as participant or guest' do |path, message|
|
||||
describe 'GET #show' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
get :show, id: conference.short_title
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
get :index
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
get :new
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
post :create, conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
it 'requires admin privileges' do
|
||||
it 'requires organizer privileges' do
|
||||
patch :update, id: conference.short_title,
|
||||
conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(success_path))
|
||||
conference: attributes_for(:conference,
|
||||
short_title: 'ExCon')
|
||||
expect(response).to redirect_to(send(path))
|
||||
expect(flash[:alert]).to match(/#{message}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -278,13 +271,13 @@ describe Admin::ConferenceController do
|
|||
sign_in(participant)
|
||||
end
|
||||
|
||||
it_behaves_like 'access as participant or guest', :root_path
|
||||
it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this page.'
|
||||
|
||||
end
|
||||
|
||||
describe 'guest access' do
|
||||
|
||||
it_behaves_like 'access as participant or guest', :new_user_session_path
|
||||
it_behaves_like 'access as participant or guest', :root_path, 'You are not authorized to access this page.'
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
require 'spec_helper'
|
||||
describe Admin::UsersController do
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let(:admin) { create(:admin) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
let(:user) { create(:user) }
|
||||
before(:each) do
|
||||
sign_in(admin)
|
||||
sign_in(organizer)
|
||||
end
|
||||
describe 'GET #index' do
|
||||
it 'populates an array of users' do
|
||||
user1 = create(:user, email: 'gopesh.7500@gmail.com')
|
||||
user2 = create(:user, email: 'gopesh_750@gmail.com')
|
||||
get :index
|
||||
expect(assigns(:users)).to match_array([user, admin, user1, user2])
|
||||
expect(assigns(:users)).to match_array([user, organizer, user1, user2])
|
||||
end
|
||||
it 'renders index template' do
|
||||
get :index
|
||||
|
|
@ -31,13 +31,13 @@ describe Admin::UsersController do
|
|||
:user, email: 'example@incoherent.de', id: user.id).email).
|
||||
to eq('example@incoherent.de')
|
||||
end
|
||||
it "redirects to the updated user" do
|
||||
it 'redirects to the updated user' do
|
||||
patch :update, id: user.id
|
||||
expect(response).to redirect_to admin_users_path
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'DELETE #destroy' do
|
||||
describe 'DELETE #destroy' do
|
||||
before :each do
|
||||
@user = create(:user)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :role do
|
||||
|
||||
factory :admin_role do
|
||||
name 'Admin'
|
||||
end
|
||||
|
||||
factory :organizer_role do
|
||||
name 'Organizer'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,12 +19,9 @@ FactoryGirl.define do
|
|||
after(:create) { |user| user.role_ids = create(:participant_role).id }
|
||||
end
|
||||
|
||||
factory :admin do
|
||||
after(:create) { |user| user.role_ids = create(:admin_role).id }
|
||||
end
|
||||
|
||||
factory :organizer do
|
||||
after(:create) { |user| user.role_ids = create(:organizer_role).id }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ require 'spec_helper'
|
|||
feature Campaign do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'add and update campaign' do |user|
|
||||
scenario 'adds and update a campaign', feature: true, js: true do
|
||||
|
|
@ -42,7 +41,7 @@ feature Campaign do
|
|||
|
||||
expect(Campaign.count).to eq(expected_count)
|
||||
|
||||
campaign = Campaign.where('name'=> 'Test Campaign').first
|
||||
campaign = Campaign.where('name' => 'Test Campaign').first
|
||||
visit edit_admin_conference_campaign_path(conference.short_title, campaign.id)
|
||||
|
||||
fill_in 'campaign_name', with: 'Test Campaign 42'
|
||||
|
|
@ -52,8 +51,7 @@ feature Campaign do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'add and update campaign', :admin
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'add and update campaign', :organizer
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ require 'spec_helper'
|
|||
feature Conference do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'add and update cfp' do |user|
|
||||
scenario 'adds a new cfp', feature: true, js: true do
|
||||
|
|
@ -87,8 +86,7 @@ feature Conference do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'add and update cfp', :admin
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'add and update cfp', :organizer
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ require 'spec_helper'
|
|||
feature Conference do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'add and update conference' do |user|
|
||||
scenario 'adds a new conference', feature: true, js: true do
|
||||
|
|
@ -56,12 +55,7 @@ feature Conference do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'add and update conference', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'add and update conference', :organizer
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature DifficultyLevel do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'difficulty levels' do |user|
|
||||
scenario 'adds and updates difficulty level', feature: true, js: true do
|
||||
|
|
@ -50,10 +49,6 @@ feature DifficultyLevel do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'difficulty levels', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'difficulty levels', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Event do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'email settings' do |user|
|
||||
scenario 'updates email settings',
|
||||
|
|
@ -91,10 +90,6 @@ feature Event do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'email settings', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'email settings', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature EventType do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'event types' do |user|
|
||||
scenario 'adds and updates event type', feature: true, js: true do
|
||||
|
|
@ -55,10 +54,6 @@ feature EventType do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'event types', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'event types', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Lodging do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'lodgings' do |user|
|
||||
scenario 'adds and updates lodgings', feature: true, js: true do
|
||||
|
|
@ -56,10 +55,6 @@ feature Lodging do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'lodgings', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'lodgings', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
feature Openid do
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'sign in with openid' do
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,15 @@ require 'spec_helper'
|
|||
|
||||
feature Event do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'proposal workflow' do
|
||||
scenario 'submitts a proposal, accepts and confirms',
|
||||
feature: true, js: true do
|
||||
|
||||
admin = create(:admin, email: 'admin@example.com')
|
||||
participant = create(:participant, email: 'participant@example.com', biography: "")
|
||||
organizer = create(:organizer, email: 'admin@example.com')
|
||||
participant = create(:participant, email: 'participant@example.com')
|
||||
|
||||
expected_count = Event.count + 1
|
||||
conference = create(:conference)
|
||||
|
|
@ -49,7 +48,7 @@ feature Event do
|
|||
expect(page.has_content?('Example Proposal')).to be true
|
||||
|
||||
sign_out
|
||||
sign_in admin
|
||||
sign_in organizer
|
||||
|
||||
# Reject proposal
|
||||
visit admin_conference_events_path(conference.short_title)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Room do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'rooms' do |user|
|
||||
scenario 'adds and updates rooms', feature: true, js: true do
|
||||
|
|
@ -43,10 +42,6 @@ feature Room do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'rooms', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'rooms', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Sponsor do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'sponsors' do |user|
|
||||
scenario 'adds and updates sponsors', feature: true, js: true do
|
||||
|
|
@ -69,10 +68,6 @@ feature Sponsor do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'sponsors', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'sponsors', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature SponsorshipLevel do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'sponsorship levels' do |user|
|
||||
scenario 'adds and updates sponsorship level', feature: true, js: true do
|
||||
|
|
@ -36,10 +35,6 @@ feature SponsorshipLevel do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'sponsorship levels', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'sponsorship levels', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature SupporterLevel do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'supporter levels' do |user|
|
||||
scenario 'adds and updates supporter level', feature: true, js: true do
|
||||
|
|
@ -43,10 +42,6 @@ feature SupporterLevel do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'supporter levels', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'supporter levels', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Track do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'tracks' do |user|
|
||||
scenario 'adds and updates tracks', feature: true, js: true do
|
||||
|
|
@ -50,10 +49,6 @@ feature Track do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'tracks', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'tracks', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
require 'spec_helper'
|
||||
feature User do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let(:admin) { create(:admin) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
|
||||
shared_examples 'admin ability' do
|
||||
shared_examples 'organizer ability' do |_user|
|
||||
scenario 'deletes a user', feature: true, js: true do
|
||||
sign_in(admin)
|
||||
sign_in(organizer)
|
||||
visit admin_users_path
|
||||
expected_count = User.count - 1
|
||||
page.all('btn btn-primary btn-danger') do
|
||||
|
|
@ -22,7 +21,7 @@ feature User do
|
|||
end
|
||||
scenario 'can modify roles', feature: true, js: true do
|
||||
@user = create(:user)
|
||||
sign_in(admin)
|
||||
sign_in(organizer)
|
||||
visit admin_users_path
|
||||
find("#user-modify-role-#{@user.id}").click
|
||||
if find("#user-role-selection-#{@user.id}").visible?
|
||||
|
|
@ -36,7 +35,7 @@ feature User do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'admin ability', :admin
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'organizer ability', :organizer
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ require 'spec_helper'
|
|||
feature Conference do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
shared_examples 'venue' do |user|
|
||||
scenario 'adds and updates venue' do
|
||||
|
|
@ -59,10 +58,6 @@ feature Conference do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'venue', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'venue', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,15 +2,14 @@ require 'spec_helper'
|
|||
|
||||
feature Conference do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let(:admin) { create(:admin) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let(:organizer) { create(:organizer) }
|
||||
let(:conference) { create(:conference) }
|
||||
|
||||
shared_examples 'volunteer' do
|
||||
scenario 'adds and updates vdays', feature: true, js: true do
|
||||
sign_in(admin)
|
||||
sign_in(organizer)
|
||||
visit admin_conference_volunteers_info_path(
|
||||
conference_id: conference.short_title)
|
||||
check('Enable Volunteering')
|
||||
|
|
@ -54,7 +53,7 @@ feature Conference do
|
|||
end
|
||||
|
||||
scenario 'adds and updates vpositions', feature: true, js: true do
|
||||
sign_in(admin)
|
||||
sign_in(organizer)
|
||||
visit admin_conference_volunteers_info_path(
|
||||
conference_id: conference.short_title)
|
||||
|
||||
|
|
@ -119,10 +118,6 @@ feature Conference do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'admin' do
|
||||
it_behaves_like 'volunteer', :admin
|
||||
end
|
||||
|
||||
describe 'organizer' do
|
||||
it_behaves_like 'volunteer', :organizer
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ describe Campaign do
|
|||
describe '#url_parameters' do
|
||||
it 'returns the parameters in the correct format' do
|
||||
campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = create(:conference)
|
||||
|
||||
result = '?utm_source=google+&utm_medium=advertisement&utm_term=opensource&utm_content=content&utm_campaign=20percent'
|
||||
|
|
@ -32,17 +33,19 @@ describe Campaign do
|
|||
describe '#visits' do
|
||||
it 'returns one if there is one visit' do
|
||||
campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
create(:visit, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent', started_at: Time.now)
|
||||
create(:visit, utm_source: 'google+', utm_medium: 'advertisement', utm_term: 'opensource',
|
||||
utm_content: 'content', utm_campaign: '20percent', started_at: Time.now)
|
||||
expect(campaign.visits_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'returns zero if there are no visits' do
|
||||
campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = create(:conference)
|
||||
|
||||
expect(campaign.visits_count).to eq(0)
|
||||
|
|
@ -52,7 +55,8 @@ describe Campaign do
|
|||
describe '#registrations' do
|
||||
it 'returns zero if there are no registration' do
|
||||
campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
expect(campaign.registrations_count).to eq(0)
|
||||
|
|
@ -62,7 +66,8 @@ describe Campaign do
|
|||
describe '#submissions' do
|
||||
it 'returns zero if there are no submissions' do
|
||||
campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement',
|
||||
utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent')
|
||||
utm_term: 'opensource', utm_content: 'content',
|
||||
utm_campaign: '20percent')
|
||||
campaign.conference = build(:conference)
|
||||
|
||||
expect(campaign.submissions_count).to eq(0)
|
||||
|
|
|
|||
|
|
@ -274,9 +274,8 @@ describe Conference do
|
|||
|
||||
describe '#get_top_submitter' do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
it 'calculates correct hash with top submitters' do
|
||||
event = create(:event, conference: subject)
|
||||
|
|
@ -307,7 +306,7 @@ describe Conference do
|
|||
target = build(:target, target_count: 10, unit: Target.units[:registrations])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"10 Registrations by #{target.due_date}" => '0'
|
||||
"10 Registrations by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
|
||||
end
|
||||
|
|
@ -317,7 +316,7 @@ describe Conference do
|
|||
subject.targets = [target]
|
||||
subject.registrations = [create(:registration)]
|
||||
result = {
|
||||
"10 Registrations by #{target.due_date}" => '10'
|
||||
"10 Registrations by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:registrations])).to eq(result)
|
||||
end
|
||||
|
|
@ -330,7 +329,7 @@ describe Conference do
|
|||
target = build(:target, target_count: 10, unit: Target.units[:submissions])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"10 Submissions by #{target.due_date}" => '0'
|
||||
"10 Submissions by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||
end
|
||||
|
|
@ -340,7 +339,7 @@ describe Conference do
|
|||
subject.targets = [target]
|
||||
subject.events = [create(:event)]
|
||||
result = {
|
||||
"10 Submissions by #{target.due_date}" => '10'
|
||||
"10 Submissions by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||
end
|
||||
|
|
@ -349,7 +348,7 @@ describe Conference do
|
|||
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
|
||||
subject.targets = [target]
|
||||
result = {
|
||||
"300 Program minutes by #{target.due_date}" => '0'
|
||||
"300 Program minutes by #{target.due_date}" => '0'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
||||
end
|
||||
|
|
@ -359,7 +358,7 @@ describe Conference do
|
|||
subject.targets = [target]
|
||||
subject.events = [create(:event)]
|
||||
result = {
|
||||
"300 Program minutes by #{target.due_date}" => '10'
|
||||
"300 Program minutes by #{target.due_date}" => '10'
|
||||
}
|
||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
||||
end
|
||||
|
|
@ -897,9 +896,8 @@ describe Conference do
|
|||
|
||||
describe 'self#event_distribution' do
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
it 'self#event_distribution calculates correct values with user' do
|
||||
create(:user, last_sign_in_at: Date.today - 3.months) # active
|
||||
|
|
@ -1426,9 +1424,8 @@ describe Conference do
|
|||
describe '#user_registered?' do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,27 +3,25 @@ require 'spec_helper'
|
|||
describe User do
|
||||
|
||||
# It is necessary to use bang version of let to build roles before user
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:participant_role) { create(:participant_role) }
|
||||
let!(:admin_role) { create(:admin_role) }
|
||||
let!(:admin) { create(:user) }
|
||||
let!(:organizer_role) { create(:organizer_role) }
|
||||
let!(:organizer) { create(:user) }
|
||||
|
||||
it 'returns the correct role' do
|
||||
participant = create(:user, email: 'participant@example.de')
|
||||
expect(admin.roles.first).to eq(admin_role)
|
||||
expect(organizer.roles.first).to eq(organizer_role)
|
||||
expect(participant.roles.first).to eq(participant_role)
|
||||
end
|
||||
|
||||
it 'returns the correct roles' do
|
||||
roles = [organizer_role.id, participant_role.id, admin_role.id]
|
||||
roles = [participant_role.id, organizer_role.id]
|
||||
user_with_all_roles = create(:user, email: 'participant@example.de')
|
||||
user_with_all_roles.role_ids = roles
|
||||
user_with_all_roles.save
|
||||
|
||||
expect(user_with_all_roles.roles.length).to eq(3)
|
||||
expect(user_with_all_roles.roles.length).to eq(2)
|
||||
expect(user_with_all_roles.roles[0]).to eq(participant_role)
|
||||
expect(user_with_all_roles.roles[1]).to eq(organizer_role)
|
||||
expect(user_with_all_roles.roles[2]).to eq(admin_role)
|
||||
end
|
||||
|
||||
describe '#role?' do
|
||||
|
|
@ -37,19 +35,17 @@ describe User do
|
|||
end
|
||||
end
|
||||
|
||||
context 'admin' do
|
||||
it_behaves_like '#role?', :admin, 'orgAnizer', false
|
||||
it_behaves_like '#role?', :admin, 'adMin', true
|
||||
it_behaves_like '#role?', :admin, 'partiCipant', false
|
||||
context 'organizer' do
|
||||
it_behaves_like '#role?', :organizer, 'oRganIzeR', true
|
||||
it_behaves_like '#role?', :organizer, 'partiCipant', false
|
||||
|
||||
it 'assigns first user admin role' do
|
||||
expect(admin.role?('Admin')).to be true
|
||||
expect(admin.role_ids).to match_array([admin_role.id])
|
||||
it 'assigns first user organizer role' do
|
||||
expect(organizer.role?('Organizer')).to be true
|
||||
expect(organizer.role_ids).to match_array([organizer_role.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'participant' do
|
||||
it_behaves_like '#role?', :participant, 'orgAnizer', false
|
||||
it_behaves_like '#role?', :participant, 'adMin', false
|
||||
it_behaves_like '#role?', :participant, 'partiCipant', true
|
||||
|
||||
|
|
@ -58,11 +54,5 @@ describe User do
|
|||
expect(participant.role_ids).to match_array([participant_role.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'organizer' do
|
||||
it_behaves_like '#role?', :organizer, 'orgAnizer', true
|
||||
it_behaves_like '#role?', :organizer, 'adMin', false
|
||||
it_behaves_like '#role?', :organizer, 'partiCipant', false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ RSpec.configure do |config|
|
|||
config.before(:each) do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
end
|
||||
|
||||
|
||||
config.before(:each, js: true) do
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module Sidebar
|
|||
def sidebar
|
||||
@conference = create(:conference)
|
||||
assign :conference, @conference
|
||||
render
|
||||
render
|
||||
expect(view).to render_template('admin/conference/_sidebar')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ require 'spec_helper'
|
|||
describe 'admin/conference/edit' do
|
||||
|
||||
it 'renders conference details which are editable' do
|
||||
@conference = create(:conference, title: 'OpenSUSE')
|
||||
@conference = create(:conference, title: 'openSUSE')
|
||||
assign :conference, @conference
|
||||
render template: 'admin/conference/edit.html.haml'
|
||||
expect(rendered).to include('OpenSUSE')
|
||||
expect(rendered).to include('openSUSE')
|
||||
expect(rendered).to include("#{@conference.contact_email}")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe 'admin/conference/index' do
|
||||
it 'renders all conference names with links' do
|
||||
assign(:conferences, [create(:conference, title: 'OpenSUSE'), create(:conference)])
|
||||
assign(:conferences, [create(:conference, title: 'openSUSE'), create(:conference)])
|
||||
render
|
||||
expect(rendered).to include('OpenSUSE')
|
||||
expect(rendered).to include("The dog and pony show")
|
||||
expect(rendered).to include('openSUSE')
|
||||
expect(rendered).to include('The dog and pony show')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe 'admin/conference/show' do
|
||||
|
||||
it 'renders conference dashboard' do
|
||||
conference = create(:conference, title: 'OpenSUSE')
|
||||
conference = create(:conference, title: 'openSUSE')
|
||||
assign :conference, conference
|
||||
assign :conference_progress, conference.get_status
|
||||
render
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe 'admin/social_events/index' do
|
||||
|
||||
it 'renders social events' do
|
||||
it 'renders social events' do
|
||||
@social_event = create(:social_event)
|
||||
assign :conference, @social_event.conference
|
||||
render
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "admin/volunteers/show" do
|
||||
describe 'admin/volunteers/show' do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ describe 'conference/show.html.haml' do
|
|||
sponsor_email: 'example@example.com',
|
||||
facebook_url: 'http://www.fbexample.com',
|
||||
google_url: 'http://www.google-example.com',
|
||||
instagram_url: "http://instagram.com",
|
||||
twitter_url: "http://twitter.com",
|
||||
instagram_url: 'http://instagram.com',
|
||||
twitter_url: 'http://twitter.com',
|
||||
include_registrations_in_splash: true,
|
||||
include_program_in_splash: true,
|
||||
include_sponsors_in_splash: true,
|
||||
|
|
@ -65,8 +65,8 @@ describe 'conference/show.html.haml' do
|
|||
expect(view).to render_template('conference/_social_media')
|
||||
expect(view.content_for(:splash)).to include('http://www.fbexample.com')
|
||||
expect(view.content_for(:splash)).to include('http://www.google-example.com')
|
||||
expect(view.content_for(:splash)).to include("http://instagram.com")
|
||||
expect(view.content_for(:splash)).to include("http://twitter.com")
|
||||
expect(view.content_for(:splash)).to include('http://instagram.com')
|
||||
expect(view.content_for(:splash)).to include('http://twitter.com')
|
||||
end
|
||||
|
||||
it 'renders location partial' do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue