<commit_before>require 'spec_helper'
include Kaminari::Helpers

describe 'Kaminari::Helpers' do
  describe 'Tag' do
    describe '#page_url_for', :if => defined?(Rails) do
      if ActionPack::VERSION::STRING > '5'
        before { helper.request.assign_parameters(_routes, "users", "index", {}, '', []) }
      else
        before { helper.request.assign_parameters(_routes, "users", "index") }
      end

      context "for first page" do
        subject { Tag.new(helper).page_url_for(1) }
        it { should == "/users" }

        context 'config.params_on_first_page == false' do
          before { Kaminari.config.params_on_first_page = true }
          after  { Kaminari.config.params_on_first_page = false }
          it { should == "/users?page=1" }
        end
      end

      context "with a friendly route setting" do
        if ActionPack::VERSION::STRING > '5'
          before { helper.request.assign_parameters(_routes, "addresses", "index", {:page => 3}, '', []) }
        else
          before { helper.request.assign_parameters(_routes, "addresses", "index", :page => 3) }
        end

        context "for first page" do
          subject { Tag.new(helper).page_url_for(1) }
          it { should == "/addresses" }

          context 'config.params_on_first_page == false' do
            before { Kaminari.config.params_on_first_page = true }
            after  { Kaminari.config.params_on_first_page = false }
            it { should match("/addresses/page/1") }
          end
        end

        context "for other page" do
          subject { Tag.new(helper).page_url_for(5) }
          it { should == "/addresses/page/5" }
        end
      end

      context "with param_name = 'user[page]' option" do
        before do
          helper.params.merge!(:user => {:page => "3", :scope => "active"})
        end

        context "for first page" do
          subject { Tag.new(helper, :param_name => "user[page]").page_url_for(1) }
          if ActiveSupport::VERSION::STRING < "3.1.0"
            it { should_not match(/user\[page\]=\d+/) }
            it { should match(/user\[scope\]=active/) }
          else
            it { should_not match(/user%5Bpage%5D=\d+/) } # not match user[page]=\d+
            it { should match(/user%5Bscope%5D=active/) } #     match user[scope]=active
          end
        end

        context "for other page" do
          subject { Tag.new(helper, :param_name => "user[page]").page_url_for(2) }
          if ActiveSupport::VERSION::STRING < "3.1.0"
            it { should match(/user\[page\]=2/) }
            it { should match(/user\[scope\]=active/) }
          else
            it { should match(/user%5Bpage%5D=2/) }       # match user[page]=2
            it { should match(/user%5Bscope%5D=active/) } # match user[scope]=active
          end
        end
      end

      context "with param_name = 'foo.page' option" do
        before do
          helper.params.merge!(:'foo.page' => 2)
        end

        context "for first page" do<commit_msg>Do not call #merge! on `ActionController::Parameters`<commit_after>require 'spec_helper'
include Kaminari::Helpers

describe 'Kaminari::Helpers' do
  describe 'Tag' do
    describe '#page_url_for', :if => defined?(Rails) do
      if ActionPack::VERSION::STRING > '5'
        before { helper.request.assign_parameters(_routes, "users", "index", {}, '', []) }
      else
        before { helper.request.assign_parameters(_routes, "users", "index") }
      end

      context "for first page" do
        subject { Tag.new(helper).page_url_for(1) }
        it { should == "/users" }

        context 'config.params_on_first_page == false' do
          before { Kaminari.config.params_on_first_page = true }
          after  { Kaminari.config.params_on_first_page = false }
          it { should == "/users?page=1" }
        end
      end

      context "with a friendly route setting" do
        if ActionPack::VERSION::STRING > '5'
          before { helper.request.assign_parameters(_routes, "addresses", "index", {:page => 3}, '', []) }
        else
          before { helper.request.assign_parameters(_routes, "addresses", "index", :page => 3) }
        end

        context "for first page" do
          subject { Tag.new(helper).page_url_for(1) }
          it { should == "/addresses" }

          context 'config.params_on_first_page == false' do
            before { Kaminari.config.params_on_first_page = true }
            after  { Kaminari.config.params_on_first_page = false }
            it { should match("/addresses/page/1") }
          end
        end

        context "for other page" do
          subject { Tag.new(helper).page_url_for(5) }
          it { should == "/addresses/page/5" }
        end
      end

      context "with param_name = 'user[page]' option" do
        before do
          helper.params[:user] = {:page => "3", :scope => "active"}
        end

        context "for first page" do
          subject { Tag.new(helper, :param_name => "user[page]").page_url_for(1) }
          if ActiveSupport::VERSION::STRING < "3.1.0"
            it { should_not match(/user\[page\]=\d+/) }
            it { should match(/user\[scope\]=active/) }
          else
            it { should_not match(/user%5Bpage%5D=\d+/) } # not match user[page]=\d+
            it { should match(/user%5Bscope%5D=active/) } #     match user[scope]=active
          end
        end

        context "for other page" do
          subject { Tag.new(helper, :param_name => "user[page]").page_url_for(2) }
          if ActiveSupport::VERSION::STRING < "3.1.0"
            it { should match(/user\[page\]=2/) }
            it { should match(/user\[scope\]=active/) }
          else
            it { should match(/user%5Bpage%5D=2/) }       # match user[page]=2
            it { should match(/user%5Bscope%5D=active/) } # match user[scope]=active
          end
        end
      end

      context "with param_name = 'foo.page' option" do
        before do
          helper.params['foo.page'] = 2
        end

        context "for first page" do
{'fraction_non_alphanumeric': 0.13728729555592267, 'fraction_numerical': 0.010242854782752353, 'mean_word_length': 2.0982599795291708, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '4089236', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1815, 'n_words': 420}