ref: master
plugins/work_assignment/test/functional/cms_controller_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
require 'test_helper' class CmsControllerTest < ActionController::TestCase def setup @controller = CmsController.new @person = create_user('test_user').person login_as :test_user e = Environment.default e.enabled_plugins = ['WorkAssignmentPlugin'] e.save! @organization = fast_create(Organization) # end should 'not allow non-members to upload submissions on work_assignment' do work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil) get :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id assert_response :forbidden assert_template 'shared/access_denied' end should 'allow members to upload submissions on work_assignment' do @organization.add_member(@person) # then he trys to upload new stuff work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil) get :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id assert_response :success end should 'redirect to Work Assignment view page after upload submission' do @organization.add_member(@person) work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil) post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] , :back_to => @work_assignment.url assert_redirected_to work_assignment.url end should 'upload submission and automatically move it to the author folder' do work_assignment = create_work_assignment('Work Assignment', @organization, nil, nil) @organization.add_member(@person) post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] submission = UploadedFile.last assert_equal work_assignment.find_or_create_author_folder(@person), submission.parent end should 'work_assignment attribute allow_visibility_edition is true when set a new work_assignment' do work_assignment = create_work_assignment('Work Assignment', @organization, nil, true) @organization.add_member(@person) assert_equal true, work_assignment.allow_visibility_edition end should 'a submission and parent attribute "published" be equal to Work Assignment attribute publish submissions' do @organization.add_member(@person) work_assignment = create_work_assignment('Work Assignment', @organization, true, nil) assert_equal true, work_assignment.publish_submissions post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] submission = UploadedFile.last assert_equal work_assignment.publish_submissions, submission.published assert_equal work_assignment.publish_submissions, submission.parent.published other_work_assignment = create_work_assignment('Other Work Assigment', @organization, false, nil) assert_equal false, other_work_assignment.publish_submissions post :upload_files, :profile => @organization.identifier, :parent_id => other_work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] submission = UploadedFile.last assert_equal other_work_assignment.publish_submissions, submission.published assert_equal other_work_assignment.publish_submissions, submission.parent.published end should 'submission inherit Work Assignment "published" attribute and not be set as show_to_followers when it is not public' do @organization.add_member(@person) work_assignment = create_work_assignment('Work Assignment', @organization, false, nil) assert !work_assignment.publish_submissions post :upload_files, :profile => @organization.identifier, :parent_id => work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] submission = UploadedFile.last assert !submission.show_to_followers? assert_equal work_assignment.publish_submissions, submission.published assert_equal work_assignment.publish_submissions, submission.parent.published other_work_assignment = create_work_assignment('Other Work Assigment', @organization, true, nil) assert_equal true, other_work_assignment.publish_submissions post :upload_files, :profile => @organization.identifier, :parent_id => other_work_assignment.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] submission = UploadedFile.last assert submission.show_to_followers? assert_equal other_work_assignment.publish_submissions, submission.published assert_equal other_work_assignment.publish_submissions, submission.parent.published end private def create_work_assignment(name = nil, profile = nil, publish_submissions = nil, allow_visibility_edition = nil) @work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => name, :profile => profile, :publish_submissions => publish_submissions, :allow_visibility_edition => allow_visibility_edition) end end |