Sha256: c5b39085a6effb1ca9df6de4ec88e7cf264c85336331a5ea61e854872e185a9d

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module PaginatedTable
  describe ControllerHelpers do
    let(:params) { stub("params") }
    let(:request) { stub("request", :xhr? => false) }
    let(:controller) {
      controller = Object.new
      controller.extend(ControllerHelpers)
      controller.stubs(:params => params, :request => request)
      controller
    }

    describe "#paginated_table" do
      let(:collection) { stub("collection") }
      let(:tables) { { "collection_name" => collection } }
      let(:page) { stub("page") }
      let(:data) { stub("data") }
      let(:data_page) { stub("data_page", :data => data, :page => page) }

      before do
        PageParams.stubs(:create_page_from_params).with(params).returns(page)
        DataPage.stubs(:new).with(collection, page).returns(data_page)
      end

      it "sets an instance variable on the controller with the data page" do
        controller.paginated_table(tables)
        controller.instance_variable_get("@collection_name").must_equal data_page
      end

      it "renders the named partial without layout if request is xhr?" do
        request.stubs(:xhr? => true)
        controller.expects(:render).
          with(:partial => "collection_name", :layout => false)
        controller.paginated_table(tables)
      end

      it "does not render if request is not xhr?" do
        request.stubs(:xhr? => false)
        controller.expects(:render).never
        controller.paginated_table(tables)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paginated_table-0.0.3 test/units/controller_helpers_test.rb
paginated_table-0.0.2 test/units/controller_helpers_test.rb
paginated_table-0.0.1 test/units/controller_helpers_test.rb