Sha256: 18201d48f39ee33373c097b8e20264bb7f2ce5cc9e5f0687d7d3fcbb62b8c5fa
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 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 it "should not use $or if there is only one search field" do send(:_where_conditions, "q", %w(f)).should == {"f" => /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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
data_table-0.2.4 | spec/mongoid_data_table_spec.rb |