<commit_before># -*- coding: utf-8 -*-

require 'test_helper'

class Admin::CfForumsControllerTest < ActionController::TestCase
  test "index: should not answer because of anonymous" do
    assert_raise CForum::ForbiddenException do
      get :index
    end
  end

  test "index: should not answer because of not an admin" do
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      get :index
    end
  end

  test "index: should answer with empty list" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :index
    assert_not_nil assigns(:forums)
    assert_blank assigns(:forums)
    assert_response :success
  end

  test "index: should answer with non-empty list" do
    forum = FactoryGirl.create(:cf_forum)
    forum1 = FactoryGirl.create(:cf_forum, :public => false)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :index
    assert_not_nil assigns(:forums)
    assert_equal 2, assigns(:forums).length
    assert_response :success
  end


  test "edit: should not show forum because of anonymous" do
    forum = FactoryGirl.create(:cf_forum)

    assert_raise CForum::ForbiddenException do
      get :edit, {id: forum.forum_id}
    end
  end

  test "edit: should not answer because of not an admin" do
    forum = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      get :edit, {id: forum.forum_id}
    end
  end

  test "edit: should answer" do
    forum = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :edit, {id: forum.forum_id}
    assert_not_nil assigns(:cf_forum)
    assert_response :success
  end

  test "edit: should not edit non-existant" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    assert_raise ActiveRecord::RecordNotFound do
      get :edit, {id: 3324}
    end
  end


  test "new: should not show forum because of anonymous" do
    assert_raise CForum::ForbiddenException do
      get :new
    end
  end

  test "new: should not answer because of not an admin" do
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      get :new
    end
  end

  test "new: should answer" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :new
    assert_not_nil assigns(:cf_forum)
    assert_response :success
  end


  test "create: should not answer because of anonymous" do
    assert_raise CForum::ForbiddenException do
      post :create, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "create: should not answer because of not an admin" do
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      post :create, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "create: should not answer because of invalid" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    assert_no_difference 'CfForum.count' do
      post :create, cf_forum: {name: '', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end

    assert_not_nil assigns(:cf_forum)
    assert !assigns(:cf_forum).valid?
    assert_response :success
  end

  test "create: should create forum" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    assert_difference 'CfForum.count' do
      post :create, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end

    assert_not_nil assigns(:cf_forum)
    assert_redirected_to edit_admin_forum_url(assigns(:cf_forum).forum_id)
  end


  test "update: should not answer because of anonymous" do
    f = FactoryGirl.create(:cf_forum)
    assert_raise CForum::ForbiddenException do
      post :update, id: f.forum_id, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "update: should not answer because of not an admin" do
    f = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      post :update, id: f.forum_id, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "update: should not answer because of invalid" do
    f = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    post :update, id: f.forum_id, cf_forum: {name: '', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}

    f1 = CfForum.find f.forum_id

    assert_not_nil assigns(:cf_forum)
    assert !assigns(:cf_forum).valid?
    assert_equal f.attributes, f1.attributes
    assert_response :success
  end

  test "update: should create forum" do
    f = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    post :update, id: f.forum_id, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}

    f1 = CfForum.find f.forum_id

    assert_not_nil assigns(:cf_forum)
    assert_not_equal f.attributes, f1.attributes
    assert_redirected_to edit_admin_forum_url(assigns(:cf_forum).forum_id)
  end<commit_msg>fixing assertion: check only the name, updated_at may be different<commit_after># -*- coding: utf-8 -*-

require 'test_helper'

class Admin::CfForumsControllerTest < ActionController::TestCase
  test "index: should not answer because of anonymous" do
    assert_raise CForum::ForbiddenException do
      get :index
    end
  end

  test "index: should not answer because of not an admin" do
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      get :index
    end
  end

  test "index: should answer with empty list" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :index
    assert_not_nil assigns(:forums)
    assert_blank assigns(:forums)
    assert_response :success
  end

  test "index: should answer with non-empty list" do
    forum = FactoryGirl.create(:cf_forum)
    forum1 = FactoryGirl.create(:cf_forum, :public => false)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :index
    assert_not_nil assigns(:forums)
    assert_equal 2, assigns(:forums).length
    assert_response :success
  end


  test "edit: should not show forum because of anonymous" do
    forum = FactoryGirl.create(:cf_forum)

    assert_raise CForum::ForbiddenException do
      get :edit, {id: forum.forum_id}
    end
  end

  test "edit: should not answer because of not an admin" do
    forum = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      get :edit, {id: forum.forum_id}
    end
  end

  test "edit: should answer" do
    forum = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :edit, {id: forum.forum_id}
    assert_not_nil assigns(:cf_forum)
    assert_response :success
  end

  test "edit: should not edit non-existant" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    assert_raise ActiveRecord::RecordNotFound do
      get :edit, {id: 3324}
    end
  end


  test "new: should not show forum because of anonymous" do
    assert_raise CForum::ForbiddenException do
      get :new
    end
  end

  test "new: should not answer because of not an admin" do
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      get :new
    end
  end

  test "new: should answer" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    get :new
    assert_not_nil assigns(:cf_forum)
    assert_response :success
  end


  test "create: should not answer because of anonymous" do
    assert_raise CForum::ForbiddenException do
      post :create, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "create: should not answer because of not an admin" do
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      post :create, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "create: should not answer because of invalid" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    assert_no_difference 'CfForum.count' do
      post :create, cf_forum: {name: '', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end

    assert_not_nil assigns(:cf_forum)
    assert !assigns(:cf_forum).valid?
    assert_response :success
  end

  test "create: should create forum" do
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    assert_difference 'CfForum.count' do
      post :create, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end

    assert_not_nil assigns(:cf_forum)
    assert_redirected_to edit_admin_forum_url(assigns(:cf_forum).forum_id)
  end


  test "update: should not answer because of anonymous" do
    f = FactoryGirl.create(:cf_forum)
    assert_raise CForum::ForbiddenException do
      post :update, id: f.forum_id, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "update: should not answer because of not an admin" do
    f = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: false)
    sign_in usr

    assert_raise CForum::ForbiddenException do
      post :update, id: f.forum_id, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}
    end
  end

  test "update: should not answer because of invalid" do
    f = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    post :update, id: f.forum_id, cf_forum: {name: '', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}

    f1 = CfForum.find f.forum_id

    assert_not_nil assigns(:cf_forum)
    assert !assigns(:cf_forum).valid?
    assert_equal f.name, f1.name
    assert_response :success
  end

  test "update: should create forum" do
    f = FactoryGirl.create(:cf_forum)
    usr = FactoryGirl.create(:cf_user, admin: true)
    sign_in usr

    post :update, id: f.forum_id, cf_forum: {name: 'Test', short_name: 'Test', slug: 'test', :public => false, description: 'lala'}

    f1 = CfForum.find f.forum_id

    assert_not_nil assigns(:cf_forum)
    assert_not_equal f.attributes, f1.attributes
    assert_redirected_to edit_admin_forum_url(assigns(:cf_forum).forum_id)
  end
{'fraction_non_alphanumeric': 0.10125213944689668, 'fraction_numerical': 0.0019818034411314294, 'mean_word_length': 3.5990057995029, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4435263', 'n_tokens_mistral': 3844, 'n_tokens_neox': 3570, 'n_words': 1090}