<commit_before>require "test_helper"

class Admin::PostsControllerTest < ActionController::TestCase

  setup do
    @typus_user = Factory(:typus_user)
    @request.session[:typus_user_id] = @typus_user.id
    @post = Factory(:post)
  end

  teardown do
    Post.delete_all
    TypusUser.delete_all
  end

  ##############################################################################
  #
  ##############################################################################

  context "CRUD" do

    should "render index" do
      get :index
      assert_response :success
      assert_template 'index'
    end

    should "render new" do
      get :new
      assert_response :success
      assert_template 'new'
    end

    should "create" do
      assert_difference('Post.count') do
        post :create, { :post => { :title => 'This is another title', :body => 'Body' } }
        assert_response :redirect
        assert_redirected_to "/admin/posts/edit/#{Post.last.id}"
      end
    end

    should "render show" do
      get :show, { :id => @post.id }
      assert_response :success
      assert_template 'show'
    end

    should "render edit" do
      get :edit, { :id => @post.id }
      assert_response :success
      assert_template 'edit'
    end

    should "update" do
      post :update, { :id => @post.id, :title => 'Updated' }
      assert_response :redirect
      assert_redirected_to "/admin/posts/edit/#{@post.id}"
    end

  end

  context "Forms" do

    setup do
      get :new
    end<commit_msg>Test for available actions on index and edit<commit_after>require "test_helper"

class Admin::PostsControllerTest < ActionController::TestCase

  setup do
    @typus_user = Factory(:typus_user)
    @request.session[:typus_user_id] = @typus_user.id
    @post = Factory(:post)
  end

  teardown do
    Post.delete_all
    TypusUser.delete_all
  end

  ##############################################################################
  #
  ##############################################################################

  context "CRUD" do

    should "render index" do
      get :index
      assert_response :success
      assert_template 'index'
    end

    should "render new" do
      get :new
      assert_response :success
      assert_template 'new'
    end

    should "create" do
      assert_difference('Post.count') do
        post :create, { :post => { :title => 'This is another title', :body => 'Body' } }
        assert_response :redirect
        assert_redirected_to "/admin/posts/edit/#{Post.last.id}"
      end
    end

    should "render show" do
      get :show, { :id => @post.id }
      assert_response :success
      assert_template 'show'
    end

    should "render edit" do
      get :edit, { :id => @post.id }
      assert_response :success
      assert_template 'edit'
    end

    should "update" do
      post :update, { :id => @post.id, :title => 'Updated' }
      assert_response :redirect
      assert_redirected_to "/admin/posts/edit/#{@post.id}"
    end

  end

  context "Actions" do

    should "be edit and trash on index" do
      get :index

      expected = [ {"action_name"=>"Edit", "action"=>"edit"},
                   {"confirm"=>"Trash Post?", "action_name"=>"Trash", "method"=>"delete", "action"=>"destroy"}]

      assert_equal expected, assigns(:actions)
    end

    should "be edit and unrelate on edit" do
      get :edit, { :id => @post.id }

      expected = [ {"action_name"=>"Edit", "action"=>"edit"},
                   {"confirm"=>"Unrelate?", "action_name"=>"Unrelate", "resource_id"=>1, "resource"=>"Post", "action" => "unrelate"}]

      assert_equal expected, assigns(:actions)
    end

  end

  context "Forms" do

    setup do
      get :new
    end
{'fraction_non_alphanumeric': 0.19501072961373392, 'fraction_numerical': 0.0002682403433476395, 'mean_word_length': 2.860248447204969, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6194040', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1086, 'n_words': 285}