<commit_before>require 'test_helper'

#
# == Admin namespace
#
module Admin
  #
  # == VideoUploadsController test
  #
  class VideoUploadsControllerTest < ActionController::TestCase
    include Devise::TestHelpers

    setup :initialize_test

    #
    # == Routes / Templates / Responses
    #
    test 'should get index page if logged in' do
      get :index
      assert_response :success
    end

    test 'should get show page if logged in' do
      get :show, id: @video_upload
      assert_response :success
    end

    test 'should get edit page if logged in' do
      get :edit, id: @video_upload
      assert_response :success
    end

    test 'should update category if logged in' do
      patch :update, id: @video_upload, video_platform: {}
      assert_redirected_to admin_video_upload_path(@video_upload)
    end

    test 'should destroy VideoUpload' do
      assert_difference 'VideoUpload.count', -1 do
        delete :destroy, id: @video_upload
      end
      assert_redirected_to admin_video_uploads_path
    end

    #
    # == Crud actions
    #
    test 'should redirect to users/sign_in if not logged in' do
      sign_out @administrator
      assert_crud_actions(@video_upload, new_user_session_path, model_name)
    end

    test 'should redirect to dashboard if subscriber' do
      sign_in @subscriber
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
    end

    #
    # == Module disabled
    #
    test 'should not access page if video module is disabled' do
      disable_optional_module @super_administrator, @video_module, 'Video' # in test_helper.rb
      sign_in @super_administrator
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
      sign_in @administrator
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
      sign_in @subscriber
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
    end

    #
    # == Abilities
    #
    test 'should test abilities for subscriber' do
      sign_in @subscriber
      ability = Ability.new(@subscriber)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.cannot?(:read, @video_upload), 'should not be able to read'
      assert ability.cannot?(:update, @video_upload), 'should not be able to update'
      assert ability.cannot?(:destroy, @video_upload), 'should not be able to destroy'
    end

    test 'should test abilities for administrator' do
      ability = Ability.new(@administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.can?(:read, @video_upload), 'should be able to read'
      assert ability.can?(:update, @video_upload), 'should be able to update'
      assert ability.can?(:destroy, @video_upload), 'should be able to destroy'
    end

    test 'should test abilities for super_administrator' do
      sign_in @super_administrator
      ability = Ability.new(@super_administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.can?(:read, @video_upload), 'should be able to read'
      assert ability.can?(:update, @video_upload), 'should be able to update'
      assert ability.can?(:destroy, @video_upload), 'should be able to destroy'
    end

    test 'should test abilities for administrator with video_platform disabled' do
      disable_video_upload_settings
      ability = Ability.new(@administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.cannot?(:read, @video_upload), 'should not be able to read'
      assert ability.cannot?(:update, @video_upload), 'should not be able to update'
      assert ability.cannot?(:destroy, @video_upload), 'should not be able to destroy'
    end

    test 'should test abilities for super_administrator with video_platform disabled' do
      disable_video_upload_settings
      sign_in @super_administrator
      ability = Ability.new(@super_administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.cannot?(:read, @video_upload), 'should not be able to read'
      assert ability.cannot?(:update, @video_upload), 'should not be able to update'
      assert ability.cannot?(:destroy, @video_upload), 'should not be able to destroy'
    end


    private<commit_msg>Fix small bug in tests<commit_after>require 'test_helper'

#
# == Admin namespace
#
module Admin
  #
  # == VideoUploadsController test
  #
  class VideoUploadsControllerTest < ActionController::TestCase
    include Devise::TestHelpers

    setup :initialize_test

    #
    # == Routes / Templates / Responses
    #
    test 'should get index page if logged in' do
      get :index
      assert_response :success
    end

    test 'should get show page if logged in' do
      get :show, id: @video_upload
      assert_response :success
    end

    test 'should get edit page if logged in' do
      get :edit, id: @video_upload
      assert_response :success
    end

    test 'should update category if logged in' do
      patch :update, id: @video_upload, video_upload: {}
      assert_redirected_to admin_video_upload_path(@video_upload)
    end

    test 'should destroy VideoUpload' do
      assert_difference 'VideoUpload.count', -1 do
        delete :destroy, id: @video_upload
      end
      assert_redirected_to admin_video_uploads_path
    end

    #
    # == Crud actions
    #
    test 'should redirect to users/sign_in if not logged in' do
      sign_out @administrator
      assert_crud_actions(@video_upload, new_user_session_path, model_name)
    end

    test 'should redirect to dashboard if subscriber' do
      sign_in @subscriber
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
    end

    #
    # == Module disabled
    #
    test 'should not access page if video module is disabled' do
      disable_optional_module @super_administrator, @video_module, 'Video' # in test_helper.rb
      sign_in @super_administrator
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
      sign_in @administrator
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
      sign_in @subscriber
      assert_crud_actions(@video_upload, admin_dashboard_path, model_name)
    end

    #
    # == Abilities
    #
    test 'should test abilities for subscriber' do
      sign_in @subscriber
      ability = Ability.new(@subscriber)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.cannot?(:read, @video_upload), 'should not be able to read'
      assert ability.cannot?(:update, @video_upload), 'should not be able to update'
      assert ability.cannot?(:destroy, @video_upload), 'should not be able to destroy'
    end

    test 'should test abilities for administrator' do
      ability = Ability.new(@administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.can?(:read, @video_upload), 'should be able to read'
      assert ability.can?(:update, @video_upload), 'should be able to update'
      assert ability.can?(:destroy, @video_upload), 'should be able to destroy'
    end

    test 'should test abilities for super_administrator' do
      sign_in @super_administrator
      ability = Ability.new(@super_administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.can?(:read, @video_upload), 'should be able to read'
      assert ability.can?(:update, @video_upload), 'should be able to update'
      assert ability.can?(:destroy, @video_upload), 'should be able to destroy'
    end

    test 'should test abilities for administrator with video_upload disabled' do
      disable_video_upload_settings
      ability = Ability.new(@administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.cannot?(:read, @video_upload), 'should not be able to read'
      assert ability.cannot?(:update, @video_upload), 'should not be able to update'
      assert ability.cannot?(:destroy, @video_upload), 'should not be able to destroy'
    end

    test 'should test abilities for super_administrator with video_upload disabled' do
      disable_video_upload_settings
      sign_in @super_administrator
      ability = Ability.new(@super_administrator)
      assert ability.cannot?(:create, VideoUpload.new), 'should not be able to create'
      assert ability.cannot?(:read, @video_upload), 'should not be able to read'
      assert ability.cannot?(:update, @video_upload), 'should not be able to update'
      assert ability.cannot?(:destroy, @video_upload), 'should not be able to destroy'
    end


    private
{'fraction_non_alphanumeric': 0.08302312464749013, 'fraction_numerical': 0.00022560631697687535, 'mean_word_length': 3.5027932960893855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4558565', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2468, 'n_words': 811}