Sha256: eab205549c3be6c7838e50b728876d2183ab5edeacd1f272f481e69670be23bf

Contents?: true

Size: 1.52 KB

Versions: 15

Compression:

Stored size: 1.52 KB

Contents

require 'test_helper'

module Rails3JQueryAutocomplete
	module Orm
		class MongoMapperTest < Test::Unit::TestCase
			include Rails3JQueryAutocomplete::Orm::MongoMapper

			context "#get_autocomplete_order" do
				context "order is specified" do
					should 'returns the parametrized order for Mongoid' do
						assert_equal [[:field, :asc], [:state, :desc]],
							get_autocomplete_order(:method, :order => 'field ASC, state DESC')
					end
				end

				context 'order is not specified' do
					should 'return the method ordered ASC by default' do
						assert_equal [[:method, :asc]],
							get_autocomplete_order(:method, {})
					end
				end
			end

			context "#get_autocomplete_items" do
				setup do
					@model = mock(Object)

					@parameters = {
						:model => @model,
						:method => :field,
						:term => 'query',
						:options => {:full => false}
					}
					mock(self).get_autocomplete_limit(anything) { 10 }
					mock(self).get_autocomplete_order(anything, anything) { [[:order, :asc]] }
				end

				context 'not a full search' do
					should 'do stuff' do
						mock(@model).where({:field=>/^query.*/i}).mock!.limit(10).
								mock!.sort([[:order, :asc]])

						get_autocomplete_items(@parameters)	
					end
				end

				context 'full search' do
					should 'return a full search query' do
						@parameters[:options] = {:full => true}

						mock(@model).where({:field => /.*query.*/i}).mock!.limit(10).
								mock!.sort([[:order, :asc]])
						
						get_autocomplete_items(@parameters)	
					end
				end
			end
		end
	end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rails3-jquery-autocomplete-1.0.12 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.11 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.10 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.9 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.8 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.7 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.6 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.5 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.4 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.3 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.2 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.1 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-1.0.0 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-0.9.1 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
rails3-jquery-autocomplete-0.9.0 test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb