<commit_before>require "spec_helper"

describe AjaxPagination::ControllerAdditions do
  def stub_paginate(name)
    @controller.stub!(:params).and_return({:paginate => name})
  end
  def stub_request_format_js(bool)
    @controller.stub!(:request).and_return(stub(:format => stub(:js? => bool)))
  end

  before :each do
    @controller_class = Class.new
    @controller = @controller_class.new
    @controller.stub!(:params).and_return({})
    stub_request_format_js(false)
    @controller_class.send(:include, AjaxPagination::ControllerAdditions)
  end

  describe 'ajax_pagination_displayed?' do
    it 'should display partial when format is not js' do
      @controller.ajax_pagination_displayed?.should be_true
    end

    it 'should display partial when format is js but paginate is not defined' do
      stub_request_format_js(true)
      @controller.ajax_pagination_displayed?.should be_true
    end

    it 'should display partial when .js?paginate=pagename' do
      stub_request_format_js(true)
      stub_paginate('page')
      @controller.ajax_pagination_displayed?.should be_true
      stub_paginate('page2')
      @controller.ajax_pagination_displayed?('page2').should be_true
      stub_paginate('page3')
      @controller.ajax_pagination_displayed?(:page3).should be_true
    end

    it 'should not display partial when .js?paginate!=pagename' do
      stub_request_format_js(true)
      stub_paginate('notpage')
      @controller.ajax_pagination_displayed?.should be_true
      stub_paginate('notpage2')
      @controller.ajax_pagination_displayed?('page2').should be_true
      stub_paginate('notpage3')
      @controller.ajax_pagination_displayed?(:page3).should be_true
    end
  end
end

<commit_msg>rspec finish functional controller additions tests<commit_after>require "spec_helper"

describe AjaxPagination::ControllerAdditions do
  def stub_pagination(name)
    @controller.stub!(:params).and_return({:pagination => name})
  end
  def stub_request_format_js(bool)
    @controller.stub!(:request).and_return(stub(:format => stub(:js? => bool)))
  end
  before :each do
    @controller_class = Class.new
    @controller = @controller_class.new
    @controller.stub!(:params).and_return({})
    stub_request_format_js(false)
    @controller_class.send(:include, AjaxPagination::ControllerAdditions)
    @formatter = Class.new
    @formatter.stub!(:js).and_return(0,1,2,3,4,5,6,7,8,9,10) # to detect how many times the function was called
  end

  describe 'ajax_pagination' do
    it 'should not render when pagination parameter not defined' do
      @controller.ajax_pagination(@formatter).should be_false
      @controller.ajax_pagination(@formatter, :pagination => :page).should be_false
      @controller.ajax_pagination(@formatter, :pagination => 'page').should be_false
      @controller.ajax_pagination(@formatter, :pagination => 'page2').should be_false
      @formatter.js.should == 0
    end
    it 'should render when pagination parameter matches' do
      stub_pagination('page')
      @controller.ajax_pagination(@formatter).should be_true
      @formatter.js.should == 1 # detects js function was called once (but checking also calls the function) ...
      @controller.ajax_pagination(@formatter, :pagination => :page).should be_true
      @formatter.js.should == 3 # ... which is why the next check should be 2 more js function calls
      @controller.ajax_pagination(@formatter, :pagination => 'page').should be_true
      @formatter.js.should == 5
      stub_pagination('pageX')
      @controller.ajax_pagination(@formatter, :pagination => 'pageX').should be_true
      @formatter.js.should == 7
    end
    it 'should not render when pagination parameter does not match' do
      stub_pagination('notpage')
      @controller.ajax_pagination(@formatter).should be_false
      @controller.ajax_pagination(@formatter, :pagination => :page).should be_false
      @controller.ajax_pagination(@formatter, :pagination => 'page').should be_false
      stub_pagination('notpageX')
      @controller.ajax_pagination(@formatter, :pagination => 'pageX').should be_false
      @formatter.js.should == 0
    end
  end

  describe 'ajax_pagination_displayed?' do
    it 'should display partial when format is not js' do
      @controller.ajax_pagination_displayed?.should be_true
    end
    it 'should display partial when format is js but pagination is not defined' do
      stub_request_format_js(true)
      @controller.ajax_pagination_displayed?.should be_true
    end
    it 'should display partial when .js?pagination=pagename' do
      stub_request_format_js(true)
      stub_pagination('page')
      @controller.ajax_pagination_displayed?.should be_true
      stub_pagination('page2')
      @controller.ajax_pagination_displayed?('page2').should be_true
      stub_pagination('page3')
      @controller.ajax_pagination_displayed?(:page3).should be_true
    end
    it 'should not display partial when .js?pagination!=pagename' do
      stub_request_format_js(true)
      stub_pagination('notpage')
      @controller.ajax_pagination_displayed?.should be_false
      stub_pagination('notpage2')
      @controller.ajax_pagination_displayed?('page2').should be_false
      stub_pagination('notpage3')
      @controller.ajax_pagination_displayed?(:page3).should be_false
    end
  end
end


{'fraction_non_alphanumeric': 0.10255447032306536, 'fraction_numerical': 0.0067618332081141996, 'mean_word_length': 4.303784860557769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '7480725', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1603, 'n_words': 338}