Sha256: dd316bb3e8e0cb76592ba6809df1a0bf63f666c3622f4622151fd2426bd064e9

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require "spec_helper"

describe DataTable do

  include DataTable::ActiveRecord::ClassMethods

  context "#_find_objects" do

    it "should find the objects required based on the params" do
      params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => 10, :sEcho => 1}

      mock(self)._discover_joins(%w(foo bar baz)) { [] }
      mock(self)._where_conditions("answer", %w(foo bar)) { "where clause" }
      mock(self)._order_fields(params, %w(foo bar baz)) { "order" }

      mock(self).where("where clause") { mock!.includes([]) { mock!.order("order") { mock!.paginate({:page => :page, :per_page => :per_page}) { :answer } } } }
      mock(self)._page(params) { :page }
      mock(self)._per_page(params) { :per_page }

      _find_objects(params, %w(foo bar baz), %w(foo bar)).should == :answer
    end

  end

  context "#_where_conditions" do

    it "should return nil if the query is blank" do
      send(:_where_conditions, "", %w(foo bar baz)).should == nil
    end

    it "should return an AR array with an entry for each search field" do
      send(:_where_conditions, "query", %w(foo bar)).should == ["UPPER(foo) LIKE ? OR UPPER(bar) LIKE ?", "%QUERY%", "%QUERY%"]
    end

  end

  context "#_discover_joins" do

     it "should return the joins on the fields" do
       _discover_joins(%w(foo.bar foz.ber baz)).should == [:foo, :foz]
     end

  end

  context "#_order_fields" do

    it "should find the field name and pass the sort direction" do
      send(:_order_fields, {:iSortCol_0 => "1", :sSortDir_0 => "asc"}, %w(foo bar baz)).should == "bar ASC"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_table-0.1.9 spec/active_record_data_table_spec.rb