rails3-jquery-autocomplete 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  As you may have noticed we are working through the backlog of issues and pull requests
4
4
  and trying to get those caught up. Couple of quick notes related to this.
5
5
 
6
- 1. A new gem with Rails 4 will be forthcoming so users on Rails 4 don't need to point to master.
6
+ 1. A new gem with Rails 4 support HAS BEEN recently RELEASED (1.0.12).
7
7
  2. If there is a specific feature that is in master, but not in the gem I strongly suggest you
8
8
  point to the specific changeset that addresses your issue rather than directly at master. There
9
9
  are going to be a lot of changes going on here and while we will do our best; there will probably
@@ -44,7 +44,7 @@ david@crowdint.com
44
44
 
45
45
  # rails3-jquery-autocomplete
46
46
 
47
- [![Build Status](https://secure.travis-ci.org/crowdint/rails3-jquery-autocomplete.png)](http://travis-ci.org/crowdint/rails3-jquery-autocomplete)
47
+ [![Build Status](https://secure.travis-ci.org/crowdint/rails3-jquery-autocomplete.png)](http://travis-ci.org/crowdint/rails3-jquery-autocomplete) [![Gem Version](https://badge.fury.io/rb/rails3-jquery-autocomplete.png)](http://badge.fury.io/rb/rails3-jquery-autocomplete)
48
48
 
49
49
  An easy way to use jQuery's autocomplete with Rails 3.
50
50
 
@@ -170,6 +170,10 @@ Only the following terms mould match the query 'un':
170
170
 
171
171
  * Unacceptable
172
172
 
173
+ #### :limit => 10 (default behavior)
174
+
175
+ By default your search result set is limited to the first 10 records. This can be overridden by specifying the limit option.
176
+
173
177
  #### :extra_data
174
178
 
175
179
  By default, your search will only return the required columns from the database needed to populate your form, namely id and the column you are searching (name, in the above example).
@@ -203,6 +207,14 @@ This wouldn't really make much sense unless you use it with the "id_element" att
203
207
 
204
208
  Only the object's id and the column you are searching on will be returned in JSON, so if your display_value method requires another parameter, make sure to fetch it with the :extra_data option
205
209
 
210
+ #### :hstore
211
+
212
+ Added option to support searching in hstore columns.
213
+
214
+ Pass a hash with two keys: `:method` and `:key` with values: the hstore field name and the key of the hstore to search.
215
+
216
+ e.g `autocomplete :feature, :name, :hstore => {:method => 'name_translations', :key => 'en'}`
217
+
206
218
 
207
219
  #### :scopes
208
220
  Added option to use scopes. Pass scopes in an array.
@@ -44,6 +44,7 @@
44
44
  jQuery.railsAutocomplete.fn.extend({
45
45
  init: function(e) {
46
46
  e.delimiter = jQuery(e).attr('data-delimiter') || null;
47
+ e.min_length = jQuery(e).attr('min-length') || 2;
47
48
  function split( val ) {
48
49
  return val.split( e.delimiter );
49
50
  }
@@ -88,7 +89,7 @@
88
89
  search: function() {
89
90
  // custom minLength
90
91
  var term = extractLast( this.value );
91
- if ( term.length < 2 ) {
92
+ if ( term.length < e.min_length ) {
92
93
  return false;
93
94
  }
94
95
  },
@@ -1 +1 @@
1
- (function(jQuery){var self=null;jQuery.fn.railsAutocomplete=function(){var handler=function(){if(!this.railsAutoCompleter){this.railsAutoCompleter=new jQuery.railsAutocomplete(this)}};if(jQuery.fn.on!==undefined){return jQuery(document).on("focus",this.selector,handler)}else{return this.live("focus",handler)}};jQuery.railsAutocomplete=function(e){_e=e;this.init(_e)};jQuery.railsAutocomplete.fn=jQuery.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"};jQuery.railsAutocomplete.fn.extend=jQuery.railsAutocomplete.extend=jQuery.extend;jQuery.railsAutocomplete.fn.extend({init:function(e){e.delimiter=jQuery(e).attr("data-delimiter")||null;function split(val){return val.split(e.delimiter)}function extractLast(term){return split(term).pop().replace(/^\s+/,"")}jQuery(e).autocomplete({source:function(request,response){jQuery.getJSON(jQuery(e).attr("data-autocomplete"),{term:extractLast(request.term)},function(){if(arguments[0].length==0){arguments[0]=[];arguments[0][0]={id:"",label:"no existing match"}}jQuery(arguments[0]).each(function(i,el){var obj={};obj[el.id]=el;jQuery(e).data(obj)});response.apply(null,arguments)})},change:function(event,ui){if(jQuery(jQuery(this).attr("data-id-element")).val()==""){return}jQuery(jQuery(this).attr("data-id-element")).val(ui.item?ui.item.id:"");if(jQuery(this).attr("data-update-elements")){var update_elements=jQuery.parseJSON(jQuery(this).attr("data-update-elements"));var data=ui.item?jQuery(this).data(ui.item.id.toString()):{};if(update_elements&&jQuery(update_elements["id"]).val()==""){return}for(var key in update_elements){jQuery(update_elements[key]).val(ui.item?data[key]:"")}}},search:function(){var term=extractLast(this.value);if(term.length<2){return false}},focus:function(){return false},select:function(event,ui){var terms=split(this.value);terms.pop();terms.push(ui.item.value);if(e.delimiter!=null){terms.push("");this.value=terms.join(e.delimiter)}else{this.value=terms.join("");if(jQuery(this).attr("data-id-element")){jQuery(jQuery(this).attr("data-id-element")).val(ui.item.id)}if(jQuery(this).attr("data-update-elements")){var data=jQuery(this).data(ui.item.id.toString());var update_elements=jQuery.parseJSON(jQuery(this).attr("data-update-elements"));for(var key in update_elements){jQuery(update_elements[key]).val(data[key])}}}var remember_string=this.value;jQuery(this).bind("keyup.clearId",function(){if(jQuery.trim(jQuery(this).val())!=jQuery.trim(remember_string)){jQuery(jQuery(this).attr("data-id-element")).val("");jQuery(this).unbind("keyup.clearId")}});jQuery(e).trigger("railsAutocomplete.select",ui);return false}})}});jQuery(document).ready(function(){jQuery("input[data-autocomplete]").railsAutocomplete()})})(jQuery);
1
+ (function(jQuery){var self=null;jQuery.fn.railsAutocomplete=function(){var handler=function(){if(!this.railsAutoCompleter){this.railsAutoCompleter=new jQuery.railsAutocomplete(this)}};if(jQuery.fn.on!==undefined){return jQuery(document).on("focus",this.selector,handler)}else{return this.live("focus",handler)}};jQuery.railsAutocomplete=function(e){_e=e;this.init(_e)};jQuery.railsAutocomplete.fn=jQuery.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"};jQuery.railsAutocomplete.fn.extend=jQuery.railsAutocomplete.extend=jQuery.extend;jQuery.railsAutocomplete.fn.extend({init:function(e){e.delimiter=jQuery(e).attr("data-delimiter")||null;e.min_length=jQuery(e).attr("min-length")||2;function split(val){return val.split(e.delimiter)}function extractLast(term){return split(term).pop().replace(/^\s+/,"")}jQuery(e).autocomplete({source:function(request,response){jQuery.getJSON(jQuery(e).attr("data-autocomplete"),{term:extractLast(request.term)},function(){if(arguments[0].length==0){arguments[0]=[];arguments[0][0]={id:"",label:"no existing match"}}jQuery(arguments[0]).each(function(i,el){var obj={};obj[el.id]=el;jQuery(e).data(obj)});response.apply(null,arguments)})},change:function(event,ui){if(jQuery(jQuery(this).attr("data-id-element")).val()==""){return}jQuery(jQuery(this).attr("data-id-element")).val(ui.item?ui.item.id:"");if(jQuery(this).attr("data-update-elements")){var update_elements=jQuery.parseJSON(jQuery(this).attr("data-update-elements"));var data=ui.item?jQuery(this).data(ui.item.id.toString()):{};if(update_elements&&jQuery(update_elements["id"]).val()==""){return}for(var key in update_elements){jQuery(update_elements[key]).val(ui.item?data[key]:"")}}},search:function(){var term=extractLast(this.value);if(term.length<e.min_length){return false}},focus:function(){return false},select:function(event,ui){var terms=split(this.value);terms.pop();terms.push(ui.item.value);if(e.delimiter!=null){terms.push("");this.value=terms.join(e.delimiter)}else{this.value=terms.join("");if(jQuery(this).attr("data-id-element")){jQuery(jQuery(this).attr("data-id-element")).val(ui.item.id)}if(jQuery(this).attr("data-update-elements")){var data=jQuery(this).data(ui.item.id.toString());var update_elements=jQuery.parseJSON(jQuery(this).attr("data-update-elements"));for(var key in update_elements){jQuery(update_elements[key]).val(data[key])}}}var remember_string=this.value;jQuery(this).bind("keyup.clearId",function(){if(jQuery.trim(jQuery(this).val())!=jQuery.trim(remember_string)){jQuery(jQuery(this).attr("data-id-element")).val("");jQuery(this).unbind("keyup.clearId")}});jQuery(e).trigger("railsAutocomplete.select",ui);return false}})}});jQuery(document).ready(function(){jQuery("input[data-autocomplete]").railsAutocomplete()})})(jQuery);
@@ -3,13 +3,10 @@ module Rails3JQueryAutocomplete
3
3
  def self.included(target)
4
4
  target.extend Rails3JQueryAutocomplete::Autocomplete::ClassMethods
5
5
 
6
- if defined?(Mongoid::Document)
7
- target.send :include, Rails3JQueryAutocomplete::Orm::Mongoid
8
- elsif defined?(MongoMapper::Document)
9
- target.send :include, Rails3JQueryAutocomplete::Orm::MongoMapper
10
- else
11
- target.send :include, Rails3JQueryAutocomplete::Orm::ActiveRecord
12
- end
6
+ target.send :include, Rails3JQueryAutocomplete::Orm::Mongoid if defined?(Mongoid::Document)
7
+ target.send :include, Rails3JQueryAutocomplete::Orm::MongoMapper if defined?(MongoMapper::Document)
8
+ target.send :include, Rails3JQueryAutocomplete::Orm::ActiveRecord
9
+
13
10
  end
14
11
 
15
12
  #
@@ -41,7 +38,25 @@ module Rails3JQueryAutocomplete
41
38
  # end
42
39
  #
43
40
  module ClassMethods
44
- def autocomplete(object, method, options = {})
41
+ def autocomplete(object, method, options = {}, &block)
42
+
43
+ define_method("get_prefix") do |model|
44
+ if model.superclass == Object && model.include?(Mongoid::Document)
45
+ 'mongoid'
46
+ elsif model.superclass == Object && model.include?(MongoMapper::Document)
47
+ 'mongo_mapper'
48
+ else
49
+ 'active_record'
50
+ end
51
+ end
52
+ define_method("get_autocomplete_order") do |method, options, model=nil|
53
+ method("#{get_prefix(get_object(options[:class_name] || object))}_get_autocomplete_order").call(method, options, model)
54
+ end
55
+
56
+ define_method("get_autocomplete_items") do |parameters|
57
+ method("#{get_prefix(get_object(options[:class_name] || object))}_get_autocomplete_items").call(parameters)
58
+ end
59
+
45
60
  define_method("autocomplete_#{object}_#{method}") do
46
61
 
47
62
  method = options[:column_name] if options.has_key?(:column_name)
@@ -57,7 +72,7 @@ module Rails3JQueryAutocomplete
57
72
  items = {}
58
73
  end
59
74
 
60
- render :json => json_for_autocomplete(items, options[:display_value] ||= method, options[:extra_data])
75
+ render :json => json_for_autocomplete(items, options[:display_value] ||= method, options[:extra_data], &block)
61
76
  end
62
77
  end
63
78
  end
@@ -82,7 +97,7 @@ module Rails3JQueryAutocomplete
82
97
  # Hash also includes a key/value pair for each method in extra_data
83
98
  #
84
99
  def json_for_autocomplete(items, method, extra_data=[])
85
- items.collect do |item|
100
+ items.collect! do |item|
86
101
  hash = {"id" => item.id.to_s, "label" => item.send(method), "value" => item.send(method)}
87
102
  extra_data.each do |datum|
88
103
  hash[datum] = item.send(datum)
@@ -90,6 +105,11 @@ module Rails3JQueryAutocomplete
90
105
  # TODO: Come back to remove this if clause when test suite is better
91
106
  hash
92
107
  end
108
+ if block_given?
109
+ yield(items)
110
+ else
111
+ items
112
+ end
93
113
  end
94
114
  end
95
115
  end
@@ -1,25 +1,25 @@
1
1
  module Rails3JQueryAutocomplete
2
2
  module Orm
3
3
  module ActiveRecord
4
- def get_autocomplete_order(method, options, model=nil)
4
+ def active_record_get_autocomplete_order(method, options, model=nil)
5
5
  order = options[:order]
6
6
 
7
7
  table_prefix = model ? "#{model.table_name}." : ""
8
- order || "#{table_prefix}#{method} ASC"
8
+ order || "LOWER(#{table_prefix}#{method}) ASC"
9
9
  end
10
10
 
11
- def get_autocomplete_items(parameters)
11
+ def active_record_get_autocomplete_items(parameters)
12
12
  model = parameters[:model]
13
13
  term = parameters[:term]
14
- method = parameters[:method]
15
14
  options = parameters[:options]
15
+ method = options[:hstore] ? options[:hstore][:method] : parameters[:method]
16
16
  scopes = Array(options[:scopes])
17
17
  where = options[:where]
18
18
  limit = get_autocomplete_limit(options)
19
- order = get_autocomplete_order(method, options, model)
19
+ order = active_record_get_autocomplete_order(method, options, model)
20
20
 
21
21
 
22
- items = model.scoped
22
+ items = (::Rails::VERSION::MAJOR * 10 + ::Rails::VERSION::MINOR) >= 40 ? model.where(nil) : model.scoped
23
23
 
24
24
  scopes.each { |scope| items = items.send(scope) } unless scopes.empty?
25
25
 
@@ -40,7 +40,11 @@ module Rails3JQueryAutocomplete
40
40
  table_name = model.table_name
41
41
  is_full_search = options[:full]
42
42
  like_clause = (postgres?(model) ? 'ILIKE' : 'LIKE')
43
- ["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
43
+ if options[:hstore]
44
+ ["LOWER(#{table_name}.#{method} -> '#{options[:hstore][:key]}') LIKE ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
45
+ else
46
+ ["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
47
+ end
44
48
  end
45
49
 
46
50
  def postgres?(model)
@@ -1,7 +1,7 @@
1
1
  module Rails3JQueryAutocomplete
2
2
  module Orm
3
3
  module MongoMapper
4
- def get_autocomplete_order(method, options, model=nil)
4
+ def mongo_mapper_get_autocomplete_order(method, options, model=nil)
5
5
  order = options[:order]
6
6
  if order
7
7
  order.split(',').collect do |fields|
@@ -13,14 +13,14 @@ module Rails3JQueryAutocomplete
13
13
  end
14
14
  end
15
15
 
16
- def get_autocomplete_items(parameters)
16
+ def mongo_mapper_get_autocomplete_items(parameters)
17
17
  model = parameters[:model]
18
18
  method = parameters[:method]
19
19
  options = parameters[:options]
20
20
  is_full_search = options[:full]
21
21
  term = parameters[:term]
22
22
  limit = get_autocomplete_limit(options)
23
- order = get_autocomplete_order(method, options)
23
+ order = mongo_mapper_get_autocomplete_order(method, options)
24
24
 
25
25
  search = (is_full_search ? '.*' : '^') + term + '.*'
26
26
  items = model.where(method.to_sym => /#{search}/i).limit(limit).sort(order)
@@ -1,7 +1,7 @@
1
1
  module Rails3JQueryAutocomplete
2
2
  module Orm
3
3
  module Mongoid
4
- def get_autocomplete_order(method, options, model=nil)
4
+ def mongoid_get_autocomplete_order(method, options, model=nil)
5
5
  order = options[:order]
6
6
  if order
7
7
  order.split(',').collect do |fields|
@@ -13,14 +13,14 @@ module Rails3JQueryAutocomplete
13
13
  end
14
14
  end
15
15
 
16
- def get_autocomplete_items(parameters)
16
+ def mongoid_get_autocomplete_items(parameters)
17
17
  model = parameters[:model]
18
18
  method = parameters[:method]
19
19
  options = parameters[:options]
20
20
  is_full_search = options[:full]
21
21
  term = parameters[:term]
22
22
  limit = get_autocomplete_limit(options)
23
- order = get_autocomplete_order(method, options)
23
+ order = mongoid_get_autocomplete_order(method, options)
24
24
 
25
25
  if is_full_search
26
26
  search = '.*' + Regexp.escape(term) + '.*'
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '1.0.12'
2
+ VERSION = '1.0.13'
3
3
  end
@@ -8,26 +8,26 @@ module Rails3JQueryAutocomplete
8
8
  context "#get_autocomplete_order" do
9
9
  context 'order is specified' do
10
10
  should 'returns that order option' do
11
- assert_equal "field ASC", get_autocomplete_order(:field, {:order => 'field ASC'})
11
+ assert_equal "field ASC", active_record_get_autocomplete_order(:field, {:order => 'field ASC'})
12
12
  end
13
13
  end
14
14
 
15
15
  context 'no order is specified' do
16
- should 'return the order clause by the field ASC' do
17
- assert_equal "field ASC", get_autocomplete_order(:field, {})
16
+ should 'return the order clause by the LOWER(table_name.field) ASC' do
17
+ assert_equal "LOWER(field) ASC", active_record_get_autocomplete_order(:field, {})
18
18
  end
19
19
 
20
20
  context 'a different model is specified' do
21
- should 'return the order clause by the table_name.field ASC' do
21
+ should 'return the order clause by the LOWER(table_name.field) ASC' do
22
22
  model = Object.new
23
23
  mock(model).table_name { 'table_name' }
24
- assert_equal "table_name.field ASC", get_autocomplete_order(:field, {}, model)
24
+ assert_equal "LOWER(table_name.field) ASC", active_record_get_autocomplete_order(:field, {}, model)
25
25
  end
26
26
  end
27
27
  end
28
28
  end
29
29
 
30
- context '#get_autocomplete_items' do
30
+ context '#active_record_get_autocomplete_items' do
31
31
  should 'retrieve the items from ActiveRecord' do
32
32
  class Dog ; end
33
33
 
@@ -45,7 +45,7 @@ module Rails3JQueryAutocomplete
45
45
  }
46
46
 
47
47
  mock(self).get_autocomplete_limit(anything) { 10 }
48
- mock(self).get_autocomplete_order(anything, anything, anything) { "order ASC" }
48
+ mock(self).active_record_get_autocomplete_order(anything, anything, anything) { "order ASC" }
49
49
  mock(self).get_autocomplete_select_clause(model, method, {}) { ["field"] }
50
50
  mock(self).get_autocomplete_where_clause(model, term, method, {}) { ["WHERE something"] }
51
51
  mock(model).table_name.times(any_times) { 'model_table_name' }
@@ -55,7 +55,38 @@ module Rails3JQueryAutocomplete
55
55
  mock(model).where(["WHERE something"]).mock!.limit(10).mock!.
56
56
  order("order ASC") { 1 }
57
57
 
58
- assert_equal 1, get_autocomplete_items(options)
58
+ assert_equal 1, active_record_get_autocomplete_items(options)
59
+ end
60
+
61
+ should 'use hstore method if present' do
62
+ class Dog ; end
63
+
64
+ model = Dog
65
+ scoped = []
66
+ whered = []
67
+ term = 'query'
68
+ method = :field
69
+ hsmethod = :hsfield
70
+
71
+ options = {
72
+ :model => model,
73
+ :term => term,
74
+ :method => method,
75
+ :options => {hstore: {method: hsmethod}}
76
+ }
77
+
78
+ mock(self).get_autocomplete_limit(anything) { 10 }
79
+ mock(self).active_record_get_autocomplete_order(anything, anything, anything) { "order ASC" }
80
+ mock(self).get_autocomplete_select_clause(model, hsmethod, options[:options]) { ["hsfield"] }
81
+ mock(self).get_autocomplete_where_clause(model, term, hsmethod, options[:options]) { ["WHERE something"] }
82
+ mock(model).table_name.times(any_times) { 'model_table_name' }
83
+
84
+ mock(model).scoped { model }
85
+ mock(model).select(["hsfield"]) { model }
86
+ mock(model).where(["WHERE something"]).mock!.limit(10).mock!.
87
+ order("order ASC") { 1 }
88
+
89
+ assert_equal 1, active_record_get_autocomplete_items(options)
59
90
  end
60
91
  end
61
92
 
@@ -71,6 +102,11 @@ module Rails3JQueryAutocomplete
71
102
  get_autocomplete_select_clause(@model, :method, {})
72
103
  end
73
104
 
105
+ should 'create a select clause with hstore method' do
106
+ assert_equal ["table_name.id", "table_name.hsmethod"],
107
+ get_autocomplete_select_clause(@model, :hsmethod, {hstore: {method: :hsmethod}})
108
+ end
109
+
74
110
  context 'with extra options' do
75
111
  should 'return those extra fields on the clause' do
76
112
  options = {:extra_data => ['table_name.created_at']}
@@ -105,6 +141,15 @@ module Rails3JQueryAutocomplete
105
141
  end
106
142
  end
107
143
 
144
+ context 'HStore' do
145
+ should 'return options for where from hstore options' do
146
+ mock(self).postgres?(@model) { true }
147
+ @options[:hstore] = {method: :hsmethod, key: :hskey}
148
+ @method = :hsmethod
149
+ assert_equal ["LOWER(table_name.hsmethod -> 'hskey') LIKE ?", "query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
150
+ end
151
+ end
152
+
108
153
  context 'full search' do
109
154
  should 'return options for where with the term sourrounded by %%' do
110
155
  mock(self).postgres?(@model) { false }
@@ -5,23 +5,23 @@ module Rails3JQueryAutocomplete
5
5
  class MongoMapperTest < Test::Unit::TestCase
6
6
  include Rails3JQueryAutocomplete::Orm::MongoMapper
7
7
 
8
- context "#get_autocomplete_order" do
8
+ context "#mongo_mapper_get_autocomplete_order" do
9
9
  context "order is specified" do
10
10
  should 'returns the parametrized order for Mongoid' do
11
11
  assert_equal [[:field, :asc], [:state, :desc]],
12
- get_autocomplete_order(:method, :order => 'field ASC, state DESC')
12
+ mongo_mapper_get_autocomplete_order(:method, :order => 'field ASC, state DESC')
13
13
  end
14
14
  end
15
15
 
16
16
  context 'order is not specified' do
17
17
  should 'return the method ordered ASC by default' do
18
18
  assert_equal [[:method, :asc]],
19
- get_autocomplete_order(:method, {})
19
+ mongo_mapper_get_autocomplete_order(:method, {})
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
- context "#get_autocomplete_items" do
24
+ context "#mongo_mapper_get_autocomplete_items" do
25
25
  setup do
26
26
  @model = mock(Object)
27
27
 
@@ -32,7 +32,7 @@ module Rails3JQueryAutocomplete
32
32
  :options => {:full => false}
33
33
  }
34
34
  mock(self).get_autocomplete_limit(anything) { 10 }
35
- mock(self).get_autocomplete_order(anything, anything) { [[:order, :asc]] }
35
+ mock(self).mongo_mapper_get_autocomplete_order(anything, anything) { [[:order, :asc]] }
36
36
  end
37
37
 
38
38
  context 'not a full search' do
@@ -40,7 +40,7 @@ module Rails3JQueryAutocomplete
40
40
  mock(@model).where({:field=>/^query.*/i}).mock!.limit(10).
41
41
  mock!.sort([[:order, :asc]])
42
42
 
43
- get_autocomplete_items(@parameters)
43
+ mongo_mapper_get_autocomplete_items(@parameters)
44
44
  end
45
45
  end
46
46
 
@@ -50,8 +50,8 @@ module Rails3JQueryAutocomplete
50
50
 
51
51
  mock(@model).where({:field => /.*query.*/i}).mock!.limit(10).
52
52
  mock!.sort([[:order, :asc]])
53
-
54
- get_autocomplete_items(@parameters)
53
+
54
+ mongo_mapper_get_autocomplete_items(@parameters)
55
55
  end
56
56
  end
57
57
  end
@@ -5,23 +5,23 @@ module Rails3JQueryAutocomplete
5
5
  class MongoidTest < Test::Unit::TestCase
6
6
  include Rails3JQueryAutocomplete::Orm::Mongoid
7
7
 
8
- context "#get_autocomplete_order" do
8
+ context "#mongoid_get_autocomplete_order" do
9
9
  context "order is specified" do
10
10
  should 'returns the parametrized order for Mongoid' do
11
11
  assert_equal [[:field, :asc], [:state, :desc]],
12
- get_autocomplete_order(:method, :order => 'field ASC, state DESC')
12
+ mongoid_get_autocomplete_order(:method, :order => 'field ASC, state DESC')
13
13
  end
14
14
  end
15
15
 
16
16
  context 'order is not specified' do
17
17
  should 'return the method ordered ASC by default' do
18
18
  assert_equal [[:method, :asc]],
19
- get_autocomplete_order(:method, {})
19
+ mongoid_get_autocomplete_order(:method, {})
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
- context "#get_autocomplete_items" do
24
+ context "#mongoid_get_autocomplete_items" do
25
25
  setup do
26
26
  @model = mock(Object)
27
27
 
@@ -32,7 +32,7 @@ module Rails3JQueryAutocomplete
32
32
  :options => {:full => false}
33
33
  }
34
34
  mock(self).get_autocomplete_limit(anything) { 10 }
35
- mock(self).get_autocomplete_order(anything, anything) { [[:order, :asc]] }
35
+ mock(self).mongoid_get_autocomplete_order(anything, anything) { [[:order, :asc]] }
36
36
  end
37
37
 
38
38
  context 'not a full search' do
@@ -40,7 +40,7 @@ module Rails3JQueryAutocomplete
40
40
  mock(@model).where({:field=>/^query/i}).mock!.limit(10).
41
41
  mock!.order_by([[:order, :asc]])
42
42
 
43
- get_autocomplete_items(@parameters)
43
+ mongoid_get_autocomplete_items(@parameters)
44
44
  end
45
45
  end
46
46
 
@@ -50,8 +50,8 @@ module Rails3JQueryAutocomplete
50
50
 
51
51
  mock(@model).where({:field=>/.*query.*/i}).mock!.limit(10).
52
52
  mock!.order_by([[:order, :asc]])
53
-
54
- get_autocomplete_items(@parameters)
53
+
54
+ mongoid_get_autocomplete_items(@parameters)
55
55
  end
56
56
  end
57
57
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails3-jquery-autocomplete
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.12
5
+ version: 1.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Padilla
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2013-12-13 00:00:00 Z
15
+ date: 2014-03-15 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails