Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hidde-jan/rails3-jquery-autocomplete
base: bcd47005e0
...
head fork: hidde-jan/rails3-jquery-autocomplete
compare: 7a944b0345
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 8 files changed
  • 0 commit comments
  • 4 contributors
Commits on Nov 25, 2011
@raskhadafi raskhadafi Option :update_elements for SimpleForm implemented. 292b5b6
Commits on Nov 30, 2011
@raskhadafi raskhadafi Option where for active record realized. d6300e9
Commits on Dec 28, 2011
@dabit dabit Merge remote-tracking branch 'raskhadafi/master' e37436d
Commits on Feb 06, 2012
@ljulien ljulien Make sure that you're checking whether the specific model in question…
… uses the PostgreSQL adapter, not only whether PGConn is defined for the entire app. Fixes problems where multiple adapters are used in the same application, such as Issue #118.
b41cd62
@dabit dabit Make sure travis is testing for Ruby 1.9.3 bd1c788
@dabit dabit The Postgres query differences are now treated at
model level. This commits just adds the tests.

The actual commit for this change was merged from
a pull request by @ljulien
8e97e28
Commits on Feb 07, 2012
@dabit dabit Removed rcov since it's not even compatible with ruby 1.9.x 44216eb
@dabit dabit Bump version to 1.0.6 229ac8e
Commits on Feb 18, 2012
@hidde-jan Merge remote-tracking branch 'github/master'
* github/master:
  Bump version to 1.0.6
  Removed rcov since it's not even compatible with ruby 1.9.x
  The Postgres query differences are now treated at model level. This commits just adds the tests.
  Make sure travis is testing for Ruby 1.9.3
  Make sure that you're checking whether the specific model in question uses the PostgreSQL adapter, not only whether PGConn is defined for the entire app.  Fixes problems where multiple adapters are used in the same application, such as Issue #118.
  Option where for active record realized.
  Option :update_elements for SimpleForm implemented.
7a944b0
View
1  .travis.yml
@@ -1,2 +1,3 @@
rvm:
- 1.9.2
+ - 1.9.3
View
1  CHANGELOG.md
@@ -1,5 +1,6 @@
# Changelog
+* 1.0.6 Postgres or non-postgres queries are now determined at model level
* 1.0.3 Fixed Formtastic 2.0 + Ruby 1.8.7 compat issue
* 1.0.2 Fixed issue #93, #94
* 1.0.1 Formtastic 2.0 compatibility fix
View
7 Rakefile
@@ -2,7 +2,6 @@ require 'bundler'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
-require 'rcov/rcovtask'
task :default => [:uglify, :test]
@@ -20,9 +19,3 @@ task :uglify do
end
end
-Rcov::RcovTask.new do |t|
- t.libs << "test"
- t.test_files = FileList['test/**/*_test.rb']
- t.rcov_opts = %w{--exclude \/gems\/}
- t.verbose = true
-end
View
11 lib/rails3-jquery-autocomplete/orm/active_record.rb
@@ -14,6 +14,7 @@ def get_autocomplete_items(parameters)
method = parameters[:method]
options = parameters[:options]
scopes = Array(options[:scopes])
+ where = options[:where]
limit = get_autocomplete_limit(options)
order = get_autocomplete_order(method, options, model)
@@ -25,6 +26,9 @@ def get_autocomplete_items(parameters)
items = items.select(get_autocomplete_select_clause(model, method, options)) unless options[:full_model]
items = items.where(get_autocomplete_where_clause(model, term, method, options)).
limit(limit).order(order)
+ items = items.where(where) unless where.blank?
+
+ items
end
def get_autocomplete_select_clause(model, method, options)
@@ -35,12 +39,13 @@ def get_autocomplete_select_clause(model, method, options)
def get_autocomplete_where_clause(model, term, method, options)
table_name = model.table_name
is_full_search = options[:full]
- like_clause = (postgres? ? 'ILIKE' : 'LIKE')
+ like_clause = (postgres?(model) ? 'ILIKE' : 'LIKE')
["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
end
- def postgres?
- defined?(PGconn)
+ def postgres?(model)
+ # Figure out if this particular model uses the PostgreSQL adapter
+ model.connection.class.to_s.match(/PostgreSQLAdapter/)
end
end
end
View
6 lib/rails3-jquery-autocomplete/simple_form_plugin.rb
@@ -2,7 +2,7 @@ module SimpleForm
module Inputs
class AutocompleteInput < Base
def input
- @builder.autocomplete_field(attribute_name, options[:url], input_html_options)
+ @builder.autocomplete_field(attribute_name, options[:url], input_html_options.merge(update_elements(options[:update_elements])))
end
protected
@@ -14,6 +14,10 @@ def limit
def has_placeholder?
placeholder_present?
end
+
+ def update_elements(elements)
+ {'data-update-elements' => elements.to_json}
+ end
end
end
end
View
2  lib/rails3-jquery-autocomplete/version.rb
@@ -1,3 +1,3 @@
module Rails3JQueryAutocomplete
- VERSION = '1.0.5'
+ VERSION = '1.0.6'
end
View
1  rails3-jquery-autocomplete.gemspec
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
s.add_development_dependency('shoulda', '~>2.11.1')
s.add_development_dependency('uglifier')
s.add_development_dependency('rr')
- s.add_development_dependency('rcov')
s.files = Dir['lib/**/*'] + %w{CHANGELOG.md LICENSE README.md Rakefile}
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
View
33 test/lib/rails3-jquery-autocomplete/orm/active_record_test.rb
@@ -84,7 +84,7 @@ class Dog ; end
context '#get_autocomplete_where_clause' do
setup do
@model = Object.new
- mock(@model).table_name { 'table_name' }
+ mock(@model).table_name { 'table_name' }
@term = 'query'
@options = {}
@@ -93,21 +93,21 @@ class Dog ; end
context 'Not Postgres' do
should 'return options for where' do
- mock(self).postgres? { false }
+ mock(self).postgres?(@model) { false }
assert_equal ["LOWER(table_name.method) LIKE ?", "query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
end
end
context 'Postgres' do
should 'return options for where with ILIKE' do
- mock(self).postgres? { true }
+ mock(self).postgres?(@model) { true }
assert_equal ["LOWER(table_name.method) ILIKE ?", "query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
end
end
context 'full search' do
should 'return options for where with the term sourrounded by %%' do
- mock(self).postgres? { false }
+ mock(self).postgres?(@model) { false }
@options[:full] = true
assert_equal ["LOWER(table_name.method) LIKE ?", "%query%"], get_autocomplete_where_clause(@model, @term, @method, @options)
end
@@ -115,14 +115,29 @@ class Dog ; end
end
context '#postgres?' do
- should 'return nil if PGconn is not defined' do
- assert_nil self.postgres?
+ setup do
+ @model = stub
end
- should 'return true if PGconn is defined' do
- class ::PGconn ; end
+ context 'the connection class is not postgres' do
+ setup do
+ mock(@model).connection { stub }
+ end
- assert self.postgres?
+ should 'return nil if the connection class matches PostgreSQLAdapter' do
+ assert_nil self.postgres?(@model)
+ end
+ end
+
+ context 'the connection class matches PostgreSQLAdapter' do
+ setup do
+ class PostgreSQLAdapter; end
+ mock(@model).connection { PostgreSQLAdapter.new }
+ end
+
+ should 'return true' do
+ assert self.postgres?(@model)
+ end
end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.