rails3-jquery-autocomplete 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ * 1.0.6 Postgres or non-postgres queries are now determined at model level
3
4
  * 1.0.3 Fixed Formtastic 2.0 + Ruby 1.8.7 compat issue
4
5
  * 1.0.2 Fixed issue #93, #94
5
6
  * 1.0.1 Formtastic 2.0 compatibility fix
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rake/testtask'
5
- require 'rcov/rcovtask'
6
5
 
7
6
  task :default => [:uglify, :test]
8
7
 
@@ -20,9 +19,3 @@ task :uglify do
20
19
  end
21
20
  end
22
21
 
23
- Rcov::RcovTask.new do |t|
24
- t.libs << "test"
25
- t.test_files = FileList['test/**/*_test.rb']
26
- t.rcov_opts = %w{--exclude \/gems\/}
27
- t.verbose = true
28
- end
@@ -14,6 +14,7 @@ module Rails3JQueryAutocomplete
14
14
  method = parameters[:method]
15
15
  options = parameters[:options]
16
16
  scopes = Array(options[:scopes])
17
+ where = options[:where]
17
18
  limit = get_autocomplete_limit(options)
18
19
  order = get_autocomplete_order(method, options, model)
19
20
 
@@ -25,6 +26,9 @@ module Rails3JQueryAutocomplete
25
26
  items = items.select(get_autocomplete_select_clause(model, method, options)) unless options[:full_model]
26
27
  items = items.where(get_autocomplete_where_clause(model, term, method, options)).
27
28
  limit(limit).order(order)
29
+ items = items.where(where) unless where.blank?
30
+
31
+ items
28
32
  end
29
33
 
30
34
  def get_autocomplete_select_clause(model, method, options)
@@ -35,12 +39,13 @@ module Rails3JQueryAutocomplete
35
39
  def get_autocomplete_where_clause(model, term, method, options)
36
40
  table_name = model.table_name
37
41
  is_full_search = options[:full]
38
- like_clause = (postgres? ? 'ILIKE' : 'LIKE')
42
+ like_clause = (postgres?(model) ? 'ILIKE' : 'LIKE')
39
43
  ["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
40
44
  end
41
45
 
42
- def postgres?
43
- defined?(PGconn)
46
+ def postgres?(model)
47
+ # Figure out if this particular model uses the PostgreSQL adapter
48
+ model.connection.class.to_s.match(/PostgreSQLAdapter/)
44
49
  end
45
50
  end
46
51
  end
@@ -2,7 +2,7 @@ module SimpleForm
2
2
  module Inputs
3
3
  class AutocompleteInput < Base
4
4
  def input
5
- @builder.autocomplete_field(attribute_name, options[:url], input_html_options)
5
+ @builder.autocomplete_field(attribute_name, options[:url], input_html_options.merge(update_elements(options[:update_elements])))
6
6
  end
7
7
 
8
8
  protected
@@ -14,6 +14,10 @@ module SimpleForm
14
14
  def has_placeholder?
15
15
  placeholder_present?
16
16
  end
17
+
18
+ def update_elements(elements)
19
+ {'data-update-elements' => elements.to_json}
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
@@ -84,7 +84,7 @@ module Rails3JQueryAutocomplete
84
84
  context '#get_autocomplete_where_clause' do
85
85
  setup do
86
86
  @model = Object.new
87
- mock(@model).table_name { 'table_name' }
87
+ mock(@model).table_name { 'table_name' }
88
88
 
89
89
  @term = 'query'
90
90
  @options = {}
@@ -93,21 +93,21 @@ module Rails3JQueryAutocomplete
93
93
 
94
94
  context 'Not Postgres' do
95
95
  should 'return options for where' do
96
- mock(self).postgres? { false }
96
+ mock(self).postgres?(@model) { false }
97
97
  assert_equal ["LOWER(table_name.method) LIKE ?", "query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
98
98
  end
99
99
  end
100
100
 
101
101
  context 'Postgres' do
102
102
  should 'return options for where with ILIKE' do
103
- mock(self).postgres? { true }
103
+ mock(self).postgres?(@model) { true }
104
104
  assert_equal ["LOWER(table_name.method) ILIKE ?", "query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
105
105
  end
106
106
  end
107
107
 
108
108
  context 'full search' do
109
109
  should 'return options for where with the term sourrounded by %%' do
110
- mock(self).postgres? { false }
110
+ mock(self).postgres?(@model) { false }
111
111
  @options[:full] = true
112
112
  assert_equal ["LOWER(table_name.method) LIKE ?", "%query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
113
113
  end
@@ -115,14 +115,29 @@ module Rails3JQueryAutocomplete
115
115
  end
116
116
 
117
117
  context '#postgres?' do
118
- should 'return nil if PGconn is not defined' do
119
- assert_nil self.postgres?
118
+ setup do
119
+ @model = stub
120
120
  end
121
121
 
122
- should 'return true if PGconn is defined' do
123
- class ::PGconn ; end
122
+ context 'the connection class is not postgres' do
123
+ setup do
124
+ mock(@model).connection { stub }
125
+ end
124
126
 
125
- assert self.postgres?
127
+ should 'return nil if the connection class matches PostgreSQLAdapter' do
128
+ assert_nil self.postgres?(@model)
129
+ end
130
+ end
131
+
132
+ context 'the connection class matches PostgreSQLAdapter' do
133
+ setup do
134
+ class PostgreSQLAdapter; end
135
+ mock(@model).connection { PostgreSQLAdapter.new }
136
+ end
137
+
138
+ should 'return true' do
139
+ assert self.postgres?(@model)
140
+ end
126
141
  end
127
142
  end
128
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails3-jquery-autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000Z
12
+ date: 2012-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70221319872760 !ruby/object:Gem::Requirement
16
+ requirement: &70131949113700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70221319872760
24
+ version_requirements: *70131949113700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3-ruby
27
- requirement: &70221319872200 !ruby/object:Gem::Requirement
27
+ requirement: &70131949113280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70221319872200
35
+ version_requirements: *70131949113280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongoid
38
- requirement: &70221319871460 !ruby/object:Gem::Requirement
38
+ requirement: &70131949112740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70221319871460
46
+ version_requirements: *70131949112740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mongo_mapper
49
- requirement: &70221319870780 !ruby/object:Gem::Requirement
49
+ requirement: &70131949112240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.9'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70221319870780
57
+ version_requirements: *70131949112240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70221319870180 !ruby/object:Gem::Requirement
60
+ requirement: &70131949111780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.3.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70221319870180
68
+ version_requirements: *70131949111780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: shoulda
71
- requirement: &70221319869580 !ruby/object:Gem::Requirement
71
+ requirement: &70131949111320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 2.11.1
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70221319869580
79
+ version_requirements: *70131949111320
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: uglifier
82
- requirement: &70221319869060 !ruby/object:Gem::Requirement
82
+ requirement: &70131949110940 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70221319869060
90
+ version_requirements: *70131949110940
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rr
93
- requirement: &70221319858700 !ruby/object:Gem::Requirement
93
+ requirement: &70131949110480 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,18 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70221319858700
102
- - !ruby/object:Gem::Dependency
103
- name: rcov
104
- requirement: &70221319858060 !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: *70221319858060
101
+ version_requirements: *70131949110480
113
102
  description: Use jQuery's autocomplete plugin with Rails 3.
114
103
  email: david.padilla@crowdint.com
115
104
  executables: []
@@ -167,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
156
  version: '0'
168
157
  requirements: []
169
158
  rubyforge_project:
170
- rubygems_version: 1.8.6
159
+ rubygems_version: 1.8.11
171
160
  signing_key:
172
161
  specification_version: 3
173
162
  summary: Use jQuery's autocomplete plugin with Rails 3.