Sha256: f4875810e2a42eb6bc50925bdc0e7cb8ae1a6f12f93675b26d59be8a200086d0

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require "spec_helper"

describe TableFor::ViewAdditions do
  before(:each) do
    @view_class = Class.new
    @view = @view_class.new
    @view_class.send(:include, ActionView::Helpers::TextHelper)
    @view_class.send(:include, TableFor::ViewAdditions::ClassMethods)
    @view_class.send(:include, Blocks::ViewAdditions::ClassMethods)
    @records = [OpenStruct.new(:id => 1)]
    @column = stub(:name => :my_column)
  end

  describe "#table_for" do
    it "should call render_template on the TableFor::Base instance" do
      TableFor::Base.expects(:new).returns(mock(:render_template => ""))
      @view.table_for(@records)
    end

    it "should pass the view as the first parameter to TableFor::Base initialization" do
      TableFor::Base.expects(:new).with {|view, options| view == @view}.returns(mock(:render_template => ""))
      @view.table_for(@records)
    end

    it "should default the template to render" do
      TableFor::Base.any_instance.expects(:render_template).with {|template| template == "table_for/table_for"}.returns("")
      @view.table_for(@records)
    end

    it "should default the variable to 'table' to render" do
      TableFor::Base.expects(:new).with {|view, options| options[:variable] == "table"}.returns(mock(:render_template => ""))
      @view.table_for(@records)
    end

    it "should default the records to the collection passed in" do
      TableFor::Base.expects(:new).with {|view, options| options[:records] == @records}.returns(mock(:render_template => ""))
      @view.table_for(@records)
    end

    it "should add any runtime options to the options initialized for TableFor::Base" do
      TableFor::Base.expects(:new).with {|view, options| options[:option1] == 1 && options[:option2] == "2"}.returns(mock(:render_template => ""))
      @view.table_for(@records, :option1 => 1, :option2 => "2")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
table-for-3.3.0 spec/table_for/view_additions_spec.rb
table-for-3.2.0 spec/table_for/view_additions_spec.rb