Sha256: 087ab1917e44d8ffe0c6d10e53bf03d38b87728bd4a338af291835abc4a185e1

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 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 => :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 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

9 entries across 9 versions & 2 rubygems

Version Path
data_table-0.2.3 spec/mongoid_data_table_spec.rb
data_table-0.2.2 spec/mongoid_data_table_spec.rb
data_table-0.2.1 spec/mongoid_data_table_spec.rb
data_table-0.2.0 spec/mongoid_data_table_spec.rb
mongoid-data_table-0.0.2 spec/mongoid_data_table_spec.rb
mongoid-data_table-0.0.1 spec/mongoid_data_table_spec.rb
data_table-0.1.9 spec/mongoid_data_table_spec.rb
data_table-0.1.8 spec/mongoid_data_table_spec.rb
data_table-0.1.7 spec/mongoid_data_table_spec.rb