<commit_before>require 'spec_helper'

describe 'Kaminari::ActionViewExtension' do
  describe '#paginate' do
    before do
      50.times {|i| User.create! :name => "user#{i}"}
      @users = User.page(1)
    end
    subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} }
    it { should be_a String }

    context 'escaping the pagination for javascript' do
      it 'should escape for javascript' do
        lambda { escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
      end
    end
  end

  describe '#link_to_previous_page' do
    before do
      50.times {|i| User.create! :name => "user#{i}"}
    end
    context 'having previous pages' do
      before do
        @users = User.page(50)
      end
      context 'the default behaviour' do
        subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
        it { should be_a String }
        it { should match /rel="previous"/ }
      end
      context 'overriding rel=' do
        subject { helper.link_to_previous_page @users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
        it { should match /rel="external"/ }
      end
    end
    context 'the first page' do
      before do
        @users = User.page(1)
      end
      subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
      it { should_not be }
    end
  end

  describe '#link_to_next_page' do
    before do
      50.times {|i| User.create! :name => "user#{i}"}
    end
    context 'having more page' do
      before do
        @users = User.page(1)
      end
      context 'the default behaviour' do
        subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
        it { should be_a String }
        it { should match(/rel="next"/) }
      end
      context 'overriding rel=' do
        subject { helper.link_to_next_page @users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
        it { should match(/rel="external"/) }
      end
    end
    context 'the last page' do
      before do
        @users = User.page(2)
      end
      subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
      it { should_not be }
    end
  end

  describe '#page_entries_info' do
    context 'on a model without namespace' do
      before do
        @users = User.page(1).per(25)
      end
      context 'having no entries' do
        subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
        it      { should == 'No entries found' }
      end

      context 'having 1 entry' do
        before do
          User.create!
          @users = User.page(1).per(25)
        end
        subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
        it      { should == 'Displaying <b>1</b> user' }

        context 'setting the entry name option to "member"' do
          subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
          it      { should == 'Displaying <b>1</b> member' }
        end
      end

      context 'having more than 1 but less than a page of entries' do
        before do
          10.times {|i| User.create!}
          @users = User.page(1).per(25)
        end
        subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
        it      { should == 'Displaying <b>all 10</b> users' }

        context 'setting the entry name option to "member"' do
          subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
          it      { should == 'Displaying <b>all 10</b> members' }
        end
      end

      context 'having more than one page of entries' do
        before do
          50.times {|i| User.create!}
        end

        describe 'the first page' do
          before do
            @users = User.page(1).per(25)
          end
          subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
          it      { should == 'Displaying users <b>1&nbsp;-&nbsp;25</b> of <b>50</b> in total' }
<commit_msg>always create User with a name<commit_after>require 'spec_helper'

describe 'Kaminari::ActionViewExtension' do
  describe '#paginate' do
    before do
      50.times {|i| User.create! :name => "user#{i}"}
      @users = User.page(1)
    end
    subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} }
    it { should be_a String }

    context 'escaping the pagination for javascript' do
      it 'should escape for javascript' do
        lambda { escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
      end
    end
  end

  describe '#link_to_previous_page' do
    before do
      50.times {|i| User.create! :name => "user#{i}"}
    end
    context 'having previous pages' do
      before do
        @users = User.page(50)
      end
      context 'the default behaviour' do
        subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
        it { should be_a String }
        it { should match /rel="previous"/ }
      end
      context 'overriding rel=' do
        subject { helper.link_to_previous_page @users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
        it { should match /rel="external"/ }
      end
    end
    context 'the first page' do
      before do
        @users = User.page(1)
      end
      subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
      it { should_not be }
    end
  end

  describe '#link_to_next_page' do
    before do
      50.times {|i| User.create! :name => "user#{i}"}
    end
    context 'having more page' do
      before do
        @users = User.page(1)
      end
      context 'the default behaviour' do
        subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
        it { should be_a String }
        it { should match(/rel="next"/) }
      end
      context 'overriding rel=' do
        subject { helper.link_to_next_page @users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
        it { should match(/rel="external"/) }
      end
    end
    context 'the last page' do
      before do
        @users = User.page(2)
      end
      subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
      it { should_not be }
    end
  end

  describe '#page_entries_info' do
    context 'on a model without namespace' do
      before do
        @users = User.page(1).per(25)
      end
      context 'having no entries' do
        subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
        it      { should == 'No entries found' }
      end

      context 'having 1 entry' do
        before do
          User.create! :name => 'user1'
          @users = User.page(1).per(25)
        end
        subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
        it      { should == 'Displaying <b>1</b> user' }

        context 'setting the entry name option to "member"' do
          subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
          it      { should == 'Displaying <b>1</b> member' }
        end
      end

      context 'having more than 1 but less than a page of entries' do
        before do
          10.times {|i| User.create! :name => "user#{i}"}
          @users = User.page(1).per(25)
        end
        subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
        it      { should == 'Displaying <b>all 10</b> users' }

        context 'setting the entry name option to "member"' do
          subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
          it      { should == 'Displaying <b>all 10</b> members' }
        end
      end

      context 'having more than one page of entries' do
        before do
          50.times {|i| User.create! :name => "user#{i}"}
        end

        describe 'the first page' do
          before do
            @users = User.page(1).per(25)
          end
          subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
          it      { should == 'Displaying users <b>1&nbsp;-&nbsp;25</b> of <b>50</b> in total' }

{'fraction_non_alphanumeric': 0.14130434782608695, 'fraction_numerical': 0.009112867808519982, 'mean_word_length': 2.3749536865505743, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 128, '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': '6529357', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2702, 'n_words': 851}