permission_test.rb revision c622fbf3120c732e74ab43bb0457388b477e6898
70N/Arequire 'test_helper'
70N/A
286N/Aclass PermissionTest < ActiveSupport::TestCase
70N/A
70N/A should belong_to :creator
70N/A should belong_to :item
70N/A should belong_to :subject
70N/A
70N/A [ 'owner', 'editor' ].each do |val|
70N/A should allow_value(val).for :role
70N/A end
70N/A
70N/A [ nil, '','foo' ].each do |val|
70N/A should_not allow_value(val).for :role
70N/A end
70N/A
70N/A context 'Ontology' do
70N/A setup do
70N/A @ontology = Factory :ontology
70N/A end
70N/A
70N/A context 'admin user' do
70N/A setup do
70N/A @admin = Factory :admin
70N/A end
70N/A
70N/A should 'have owner and editor permissions' do
70N/A assert @ontology.permission?(:owner, @admin)
70N/A assert @ontology.permission?(:editor, @admin)
70N/A end
356N/A end
70N/A
70N/A context 'owner user' do
70N/A setup do
98N/A @permission = Factory :permission, item: @ontology
321N/A end
321N/A
213N/A should 'have owner and editor permissions' do
304N/A assert @ontology.permission?(:owner, @permission.subject)
325N/A assert @ontology.permission?(:editor, @permission.subject)
320N/A end
332N/A end
231N/A
98N/A context 'editor user' do
347N/A setup do
346N/A @permission = Factory :permission, item: @ontology, role: 'editor'
324N/A end
347N/A
310N/A should 'have editor permission' do
316N/A assert @ontology.permission?(:editor, @permission.subject)
290N/A end
332N/A end
332N/A
332N/A context 'team user' do
210N/A setup do
128N/A @team_user = Factory :team_user
326N/A @permission = Factory :permission, item: @ontology, subject: @team_user.team
335N/A end
70N/A
294N/A should 'have owner and editor permissions' do
98N/A assert @ontology.permission?(:owner, @team_user.user)
277N/A assert @ontology.permission?(:editor, @team_user.user)
356N/A end
289N/A end
326N/A
290N/A context 'bernd' do
286N/A should 'not have any permissions' do
90N/A assert !@ontology.permission?(:owner, nil)
295N/A assert !@ontology.permission?(:editor, nil)
70N/A end
299N/A end
262N/A
277N/A context 'editor' do
332N/A setup do
332N/A @permission = Factory :permission, item: @ontology, role: 'editor'
70N/A end
70N/A
319N/A should 'not have owner permission' do
280N/A assert !@ontology.permission?(:owner, @permission.subject)
319N/A end
70N/A end
70N/A
98N/A context 'user on other team' do
98N/A setup do
231N/A @team_user = Factory :team_user
98N/A @permission = Factory :permission, item: @ontology
156N/A end
156N/A
98N/A should 'not have owner and editor permissions' do
70N/A assert !@ontology.permission?(:owner, @team_user.user)
70N/A assert !@ontology.permission?(:editor, @team_user.user)
70N/A end
70N/A end
70N/A
70N/A context 'some user' do
70N/A setup do
70N/A @user = Factory :user
70N/A end
70N/A
70N/A should 'not have permissions without ontology having permissions' do
70N/A assert !@ontology.permission?(:owner, @user)
70N/A assert !@ontology.permission?(:editor, @user)
70N/A end
70N/A end
70N/A end
70N/Aend
70N/A