Sha256: 9c254c3197997a3b1b1e7f061c41878f8b137d67b84d1a39372e2f2b00d0f771

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 KB

Contents

require "spec_helper"

describe DataTable do

  include DataTable::Mongoid::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)._where_conditions("answer", %w(foo bar)) { "where clause" }
      mock(self)._order_by_fields(params, %w(foo bar baz)) { "order by" }

      mock(self).where("where clause") { mock!.order_by("order by") { mock!.paginate({:page => :page, :per_page => 10}) { :answer } } }
      mock(self)._page(params) { :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 strip out slashes" do
      send(:_where_conditions, "//", %w(foo bar baz)).should == nil
    end

    it "should return a mongoid $or hash with an entry for each search field" do
      send(:_where_conditions, "q", %w(foo bar)).should == {"$or" => [{"foo" => /q/i}, {"bar" => /q/i}]}
    end

  end

  context "#_order_by_fields" do

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
data_table-0.1.6 spec/mongoid_data_table_spec.rb
data_table-0.1.5 spec/mongoid_data_table_spec.rb
data_table-0.1.4 spec/mongoid_data_table_spec.rb
data_table-0.1.3 spec/mongoid_data_table_spec.rb
data_table-0.1.2 spec/mongoid_data_table_spec.rb
data_table-0.1.1 spec/mongoid_data_table_spec.rb