Sha256: 145e33576c7a17def8159e5776e2d0ae051014e989d75bceb54746fb5eac243b
Contents?: true
Size: 1.94 KB
Versions: 6
Compression:
Stored size: 1.94 KB
Contents
require "spec_helper" describe DataTable do include DataTable::ClassMethods context "on being included" do it "should extend ClassMethods" do klass = Class.new mock(klass).send(:extend, DataTable::ClassMethods) mock(klass).send(:extend, DataTable::Mongoid::ClassMethods) klass.instance_eval %{include DataTable} end end context "#for_data_table" do it "should produce JSON for the datatables plugin to consume" do params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => "10", :sEcho => "1"} controller = mock!.params { params }.subject fields = %w(foo bar baz) search_fields = %w(foo bar) block = :block mock(self).count { 42 } objects = mock!.total_entries { 10 }.subject mock(self)._find_objects(params, fields, search_fields) { objects } mock(self)._yield_and_render_array(controller, objects, block) { :results } result = for_data_table(controller, fields, search_fields, block) result.should == {:sEcho => 1, :iTotalRecords => 42, :iTotalDisplayRecords => 10, :aaData => :results}.to_json.html_safe end end context "#_yield_and_render_array" do it "should walk through the array and render it, passing in the appropriate local name" do block = lambda {|x| mock!.map { [42] }.subject } result = _yield_and_render_array Object.new, [:foo], block result.should == [[42]] end end context "#_page" do context "with a display length of 10" do it "should return 1 when start is blank" do send(:_page, {:iDisplayStart => "", :iDisplayLength => "10"}).should == 1 end it "should return 1 when start is 0" do send(:_page, {:iDisplayStart => "0", :iDisplayLength => "10"}).should == 1 end it "should return 2 when start is 10" do send(:_page, {:iDisplayStart => "10", :iDisplayLength => "10"}).should == 2 end end end end
Version data entries
6 entries across 6 versions & 1 rubygems