<commit_before># encoding: utf-8

require 'spec_helper'

describe RailsAdmin::MainController do

  describe "#dashboard" do
    before do
      controller.stub(:render).and_return(true) # no rendering
    end

    it "shows statistics by default" do
      RailsAdmin.config(Player).abstract_model.should_receive(:count).and_return(0)
      controller.dashboard
    end

    it "does not show statistics if turned off" do
      RailsAdmin.config do |c|
        c.actions do
          dashboard do
            statistics false
          end
        end
      end

      RailsAdmin.config(Player).abstract_model.should_not_receive(:count)
      controller.dashboard
    end
  end

  describe "#check_for_cancel" do

    it "redirects to back if params[:bulk_ids] is nil when params[:bulk_action] is present" do
      controller.stub(:back_or_index) { raise StandardError.new('redirected back') }
      expect { get :bulk_delete, { :model_name => "player", :bulk_action =>"bulk_delete" } }.to raise_error('redirected back')
      expect { get :bulk_delete, { :model_name => "player", :bulk_action =>"bulk_delete", :bulk_ids => [] } }.to_not raise_error('redirected back')
    end
  end

  describe "#get_sort_hash" do
    it "works with belongs_to associations with label method virtual" do
      controller.params = { :sort => "parent_category", :model_name =>"categories" }
      expect(controller.send(:get_sort_hash, RailsAdmin.config(Category))).to eq({:sort=>"categories.parent_category_id", :sort_reverse=>true})
    end

    it "works with belongs_to associations with label method real column" do
      controller.params = { :sort => "team", :model_name =>"players" }
      expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq({:sort=>"teams.name", :sort_reverse=>true})
    end
  end

  describe "#list_entries called from view" do
    before do
      @teams = 21.times.map { FactoryGirl.create :team }
      controller.params = { :model_name => "teams" }
    end

    it "paginates" do
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, false).to_a.length).to eq(21)
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, true).to_a.length).to eq(20)
    end
  end

  describe "#list_entries called from view with kaminari custom param_name" do
    before do
      @teams = 21.times.map { FactoryGirl.create :team }
      controller.params = { :model_name => "teams" }
      Kaminari.config.param_name = :pagina
    end

    it "paginates" do
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, false).to_a.length).to eq(21)
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, true).to_a.length).to eq(20)
    end
  end
<commit_msg>fix spec<commit_after># encoding: utf-8

require 'spec_helper'

describe RailsAdmin::MainController do

  describe "#dashboard" do
    before do
      controller.stub(:render).and_return(true) # no rendering
    end

    it "shows statistics by default" do
      RailsAdmin.config(Player).abstract_model.should_receive(:count).and_return(0)
      controller.dashboard
    end

    it "does not show statistics if turned off" do
      RailsAdmin.config do |c|
        c.actions do
          dashboard do
            statistics false
          end
        end
      end

      RailsAdmin.config(Player).abstract_model.should_not_receive(:count)
      controller.dashboard
    end
  end

  describe "#check_for_cancel" do

    it "redirects to back if params[:bulk_ids] is nil when params[:bulk_action] is present" do
      controller.stub(:back_or_index) { raise StandardError.new('redirected back') }
      expect { get :bulk_delete, { :model_name => "player", :bulk_action =>"bulk_delete" } }.to raise_error('redirected back')
      expect { get :bulk_delete, { :model_name => "player", :bulk_action =>"bulk_delete", :bulk_ids => [] } }.to_not raise_error('redirected back')
    end
  end

  describe "#get_sort_hash" do
    it "works with belongs_to associations with label method virtual" do
      controller.params = { :sort => "parent_category", :model_name =>"categories" }
      expect(controller.send(:get_sort_hash, RailsAdmin.config(Category))).to eq({:sort=>"categories.parent_category_id", :sort_reverse=>true})
    end

    it "works with belongs_to associations with label method real column" do
      controller.params = { :sort => "team", :model_name =>"players" }
      expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq({:sort=>"teams.name", :sort_reverse=>true})
    end
  end

  describe "#list_entries called from view" do
    before do
      @teams = 21.times.map { FactoryGirl.create :team }
      controller.params = { :model_name => "teams" }
    end

    it "paginates" do
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, false).to_a.length).to eq(21)
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, true).to_a.length).to eq(20)
    end
  end

  describe "#list_entries called from view with kaminari custom param_name" do
    before do
      @teams = 21.times.map { FactoryGirl.create :team }
      controller.params = { :model_name => "teams" }
      Kaminari.config.param_name = :pagina
    end

    after do
      Kaminari.config.param_name = :page
    end

    it "paginates" do
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, false).to_a.length).to eq(21)
      expect(controller.list_entries(RailsAdmin.config(Team), :index, nil, true).to_a.length).to eq(20)
    end
  end

{'fraction_non_alphanumeric': 0.11771058315334773, 'fraction_numerical': 0.005039596832253419, 'mean_word_length': 3.5289323553382235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '355667', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1724, 'n_words': 420}