@@ -355,6 +355,49 class UserTest < ActiveSupport::TestCase | |||||
355 |
|
355 | |||
356 | end |
|
356 | end | |
357 |
|
357 | |||
|
358 | context "#allowed_to?" do | |||
|
359 | context "with a unique project" do | |||
|
360 | should "return false if project is archived" do | |||
|
361 | project = Project.find(1) | |||
|
362 | Project.any_instance.stubs(:status).returns(Project::STATUS_ARCHIVED) | |||
|
363 | assert ! @admin.allowed_to?(:view_issues, Project.find(1)) | |||
|
364 | end | |||
|
365 | ||||
|
366 | should "return false if related module is disabled" do | |||
|
367 | project = Project.find(1) | |||
|
368 | project.enabled_module_names = ["issue_tracking"] | |||
|
369 | assert @admin.allowed_to?(:add_issues, project) | |||
|
370 | assert ! @admin.allowed_to?(:view_wiki_pages, project) | |||
|
371 | end | |||
|
372 | ||||
|
373 | should "authorize nearly everything for admin users" do | |||
|
374 | project = Project.find(1) | |||
|
375 | assert ! @admin.member_of?(project) | |||
|
376 | %w(edit_issues delete_issues manage_news manage_documents manage_wiki).each do |p| | |||
|
377 | assert @admin.allowed_to?(p.to_sym, project) | |||
|
378 | end | |||
|
379 | end | |||
|
380 | ||||
|
381 | should "authorize normal users depending on their roles" do | |||
|
382 | project = Project.find(1) | |||
|
383 | assert @jsmith.allowed_to?(:delete_messages, project) #Manager | |||
|
384 | assert ! @dlopper.allowed_to?(:delete_messages, project) #Developper | |||
|
385 | end | |||
|
386 | end | |||
|
387 | ||||
|
388 | context "with options[:global]" do | |||
|
389 | should "authorize if user has at least one role that has this permission" do | |||
|
390 | @dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere | |||
|
391 | @anonymous = User.find(6) | |||
|
392 | assert @jsmith.allowed_to?(:delete_issue_watchers, nil, :global => true) | |||
|
393 | assert ! @dlopper2.allowed_to?(:delete_issue_watchers, nil, :global => true) | |||
|
394 | assert @dlopper2.allowed_to?(:add_issues, nil, :global => true) | |||
|
395 | assert ! @anonymous.allowed_to?(:add_issues, nil, :global => true) | |||
|
396 | assert @anonymous.allowed_to?(:view_issues, nil, :global => true) | |||
|
397 | end | |||
|
398 | end | |||
|
399 | end | |||
|
400 | ||||
358 | if Object.const_defined?(:OpenID) |
|
401 | if Object.const_defined?(:OpenID) | |
359 |
|
402 | |||
360 | def test_setting_identity_url |
|
403 | def test_setting_identity_url |
General Comments 0
You need to be logged in to leave comments.
Login now