rails3-jquery-autocomplete 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -1
- data/lib/rails3-jquery-autocomplete/helpers.rb +3 -2
- data/test/implementations_test.rb +36 -0
- data/test/support/active_record.rb +24 -23
- data/test/support/mongoid.rb +26 -23
- data/test/test_controller.rb +101 -0
- data/test/test_helper.rb +3 -0
- metadata +8 -8
- data/test/active_record_controller_test.rb +0 -100
- data/test/mongoid_controller_test.rb +0 -100
data/README.markdown
CHANGED
@@ -210,6 +210,7 @@ You need to have an instance of MongoDB running on your computer or all the mong
|
|
210
210
|
|
211
211
|
# Changelog
|
212
212
|
|
213
|
+
* 0.5.1 Add STI support
|
213
214
|
* 0.5.0 Formtastic support
|
214
215
|
* 0.4.0 MongoID support
|
215
216
|
* 0.3.6 Using .live() to put autocomplete on dynamic fields
|
@@ -218,4 +219,4 @@ You need to have an instance of MongoDB running on your computer or all the mong
|
|
218
219
|
|
219
220
|
[Crowd Interactive](http://www.crowdint.com) is an American web design and development company that happens to work in Colima, Mexico.
|
220
221
|
We specialize in building and growing online retail stores. We don’t work with everyone – just companies we believe in. Call us today to see if there’s a fit.
|
221
|
-
Find more info [here](http://www.crowdint.com)!
|
222
|
+
Find more info [here](http://www.crowdint.com)!
|
@@ -19,9 +19,10 @@ module Rails3JQueryAutocomplete
|
|
19
19
|
# Returns a symbol representing what implementation should be used to query
|
20
20
|
# the database and raises *NotImplementedError* if ORM implementor can not be found
|
21
21
|
def get_implementation(object)
|
22
|
-
|
22
|
+
ancestors_ary = object.ancestors.collect(&:to_s)
|
23
|
+
if ancestors_ary.include?('ActiveRecord::Base')
|
23
24
|
:activerecord
|
24
|
-
elsif
|
25
|
+
elsif ancestors_ary.include?('Mongoid::Document')
|
25
26
|
:mongoid
|
26
27
|
else
|
27
28
|
raise NotImplementedError
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require 'test_controller'
|
3
|
+
require 'support/mongoid'
|
4
|
+
require 'support/active_record'
|
5
|
+
|
6
|
+
class ActiveRecordControllerTest < ActionController::TestCase
|
7
|
+
include Rails3JQueryAutocomplete::TestCase::ActiveRecord
|
8
|
+
include Rails3JQueryAutocomplete::TestCase
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActiveRecordSTIControllerTest < ActionController::TestCase
|
12
|
+
require 'support/active_record'
|
13
|
+
include Rails3JQueryAutocomplete::TestCase::ActiveRecord
|
14
|
+
include Rails3JQueryAutocomplete::TestCase
|
15
|
+
|
16
|
+
def create_models
|
17
|
+
@parent_movie_class = Object.const_set(:Movie, Class.new(::ActiveRecord::Base))
|
18
|
+
@parent_movie_class.class_eval do
|
19
|
+
def display_name
|
20
|
+
"Movie: #{name}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
@movie_class = Object.const_set(:HorrorMovie, Class.new(@parent_movie_class))
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy_models
|
27
|
+
Object.send(:remove_const, :Movie)
|
28
|
+
Object.send(:remove_const, :HorrorMovie)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class MonogidControllerTest < ActionController::TestCase
|
34
|
+
include Rails3JQueryAutocomplete::TestCase::Mongoid
|
35
|
+
include Rails3JQueryAutocomplete::TestCase
|
36
|
+
end
|
@@ -1,19 +1,5 @@
|
|
1
|
-
class Actor < ActiveRecord::Base
|
2
|
-
belongs_to :movie
|
3
|
-
end
|
4
|
-
|
5
|
-
class Movie < ActiveRecord::Base
|
6
|
-
def display_name
|
7
|
-
"Movie: #{name}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ActorsController < ActionController::Base
|
12
|
-
autocomplete :movie, :name
|
13
|
-
end
|
14
|
-
|
15
1
|
module Rails3JQueryAutocomplete
|
16
|
-
module
|
2
|
+
module TestCase
|
17
3
|
module ActiveRecord
|
18
4
|
def setup
|
19
5
|
::ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
@@ -21,23 +7,38 @@ module Rails3JQueryAutocomplete
|
|
21
7
|
create_table :movies do |t|
|
22
8
|
t.column :name, :string
|
23
9
|
end
|
24
|
-
|
25
|
-
create_table :actors do |t|
|
26
|
-
t.column :movie_id, :integer
|
27
|
-
t.column :name, :string
|
28
|
-
end
|
29
10
|
end
|
30
11
|
|
31
|
-
|
32
|
-
|
33
|
-
@
|
12
|
+
create_models
|
13
|
+
|
14
|
+
@controller = ActorsController.new
|
15
|
+
|
16
|
+
@movie1 = @movie_class.create(:name => 'Alpha')
|
17
|
+
@movie2 = @movie_class.create(:name => 'Alspha')
|
18
|
+
@movie3 = @movie_class.create(:name => 'Alzpha')
|
34
19
|
end
|
35
20
|
|
36
21
|
def teardown
|
22
|
+
destroy_models
|
37
23
|
::ActiveRecord::Base.connection.tables.each do |table|
|
38
24
|
::ActiveRecord::Base.connection.drop_table(table)
|
39
25
|
end
|
40
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def create_models
|
30
|
+
@movie_class = Object.const_set(:Movie, Class.new(::ActiveRecord::Base))
|
31
|
+
@movie_class.class_eval do
|
32
|
+
def display_name
|
33
|
+
"Movie: #{name}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy_models
|
39
|
+
Object.send(:remove_const, :Movie)
|
40
|
+
end
|
41
|
+
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
data/test/support/mongoid.rb
CHANGED
@@ -1,24 +1,5 @@
|
|
1
|
-
class Character
|
2
|
-
include Mongoid::Document
|
3
|
-
field :name, :class => String
|
4
|
-
referenced_in :game
|
5
|
-
end
|
6
|
-
|
7
|
-
class Game
|
8
|
-
include Mongoid::Document
|
9
|
-
field :name, :class => String
|
10
|
-
references_one :character
|
11
|
-
def display_name
|
12
|
-
"Game: #{name}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class GamesController < ActionController::Base
|
17
|
-
autocomplete :game, :name
|
18
|
-
end
|
19
|
-
|
20
1
|
module Rails3JQueryAutocomplete
|
21
|
-
module
|
2
|
+
module TestCase
|
22
3
|
module Mongoid
|
23
4
|
def setup
|
24
5
|
::Mongoid.configure do |config|
|
@@ -28,14 +9,36 @@ module Rails3JQueryAutocomplete
|
|
28
9
|
config.logger = nil
|
29
10
|
end
|
30
11
|
|
31
|
-
|
32
|
-
|
33
|
-
@
|
12
|
+
create_models
|
13
|
+
|
14
|
+
@controller = ActorsController.new
|
15
|
+
|
16
|
+
@movie1 = @movie_class.create(:name => 'Alpha')
|
17
|
+
@movie2 = @movie_class.create(:name => 'Alspha')
|
18
|
+
@movie3 = @movie_class.create(:name => 'Alzpha')
|
34
19
|
end
|
35
20
|
|
36
21
|
def teardown
|
22
|
+
destroy_models
|
37
23
|
::Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
|
38
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def create_models
|
28
|
+
@movie_class = Object.const_set(:Movie, Class.new)
|
29
|
+
@movie_class.send(:include, ::Mongoid::Document)
|
30
|
+
@movie_class.field(:name, :class => String)
|
31
|
+
@movie_class.class_eval do
|
32
|
+
def display_name
|
33
|
+
"Movie: #{name}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy_models
|
39
|
+
Object.send(:remove_const, :Movie)
|
40
|
+
end
|
41
|
+
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Rails3JQueryAutocomplete
|
2
|
+
module TestCase
|
3
|
+
|
4
|
+
include Shoulda::InstanceMethods
|
5
|
+
extend Shoulda::ClassMethods
|
6
|
+
include Shoulda::Assertions
|
7
|
+
extend Shoulda::Macros
|
8
|
+
include Shoulda::Helpers
|
9
|
+
|
10
|
+
context "the autocomplete gem" do
|
11
|
+
|
12
|
+
should "be able to access the autocomplete action regardless of the quality of param[:term]" do
|
13
|
+
get :autocomplete_movie_name
|
14
|
+
assert_response :success
|
15
|
+
|
16
|
+
get :autocomplete_movie_name, :term => ''
|
17
|
+
assert_response :success
|
18
|
+
|
19
|
+
get :autocomplete_movie_name, :term => nil
|
20
|
+
assert_response :success
|
21
|
+
|
22
|
+
get :autocomplete_movie_name, :term => 'Al'
|
23
|
+
assert_response :success
|
24
|
+
end
|
25
|
+
|
26
|
+
should "respond with expected json" do
|
27
|
+
get :autocomplete_movie_name, :term => 'Al'
|
28
|
+
json_response = JSON.parse(@response.body)
|
29
|
+
assert_equal(json_response.first["label"], @movie1.name)
|
30
|
+
assert_equal(json_response.first["value"], @movie1.name)
|
31
|
+
assert_equal(json_response.first["id"].to_s, @movie1.id.to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "return results in alphabetical order by default" do
|
35
|
+
get :autocomplete_movie_name, :term => 'Al'
|
36
|
+
json_response = JSON.parse(@response.body)
|
37
|
+
assert_equal(json_response.first["label"], "Alpha")
|
38
|
+
assert_equal(json_response.last["label"], "Alzpha")
|
39
|
+
end
|
40
|
+
|
41
|
+
should "be able to sort in other ways if desired" do
|
42
|
+
@controller.class_eval do
|
43
|
+
autocomplete :movie, :name, {:order => "name DESC"}
|
44
|
+
end
|
45
|
+
|
46
|
+
get :autocomplete_movie_name, :term => 'Al'
|
47
|
+
json_response = JSON.parse(@response.body)
|
48
|
+
assert_equal(json_response.first["label"], "Alzpha")
|
49
|
+
assert_equal(json_response.last["label"], "Alpha")
|
50
|
+
end
|
51
|
+
|
52
|
+
should "be able to limit the results" do
|
53
|
+
@controller.class_eval do
|
54
|
+
autocomplete :movie, :name, {:limit => 1}
|
55
|
+
end
|
56
|
+
|
57
|
+
get :autocomplete_movie_name, :term => 'Al'
|
58
|
+
json_response = JSON.parse(@response.body)
|
59
|
+
assert_equal(json_response.length, 1)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "ignore case of search term and results" do
|
63
|
+
@movie = @movie_class.create(:name => 'aLpHa')
|
64
|
+
|
65
|
+
@controller.class_eval do
|
66
|
+
autocomplete :movie, :name
|
67
|
+
end
|
68
|
+
|
69
|
+
get :autocomplete_movie_name, :term => 'Al'
|
70
|
+
json_response = JSON.parse(@response.body)
|
71
|
+
assert_equal(json_response.length, @movie_class.count)
|
72
|
+
assert_equal(json_response.last["label"], 'aLpHa')
|
73
|
+
end
|
74
|
+
|
75
|
+
should "match term to letters in middle of words when full-text search is on" do
|
76
|
+
@controller.class_eval do
|
77
|
+
autocomplete :movie, :name, {:full => true}
|
78
|
+
end
|
79
|
+
|
80
|
+
get :autocomplete_movie_name, :term => 'ph'
|
81
|
+
json_response = JSON.parse(@response.body)
|
82
|
+
assert_equal(json_response.length, @movie_class.count)
|
83
|
+
assert_equal(json_response.first["label"], @movie1.name)
|
84
|
+
end
|
85
|
+
|
86
|
+
should "be able to customize what is displayed" do
|
87
|
+
@controller.class_eval do
|
88
|
+
autocomplete :movie, :name, {:display_value => :display_name}
|
89
|
+
end
|
90
|
+
|
91
|
+
get :autocomplete_movie_name, :term => 'Al'
|
92
|
+
|
93
|
+
json_response = JSON.parse(@response.body)
|
94
|
+
|
95
|
+
assert_equal(@movie1.display_name, json_response.first["label"])
|
96
|
+
assert_equal(@movie1.display_name, json_response.first["value"])
|
97
|
+
assert_equal(@movie1.id.to_s, json_response.first["id"].to_s)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -24,3 +24,6 @@ Rails3JQueryAutocomplete::Application.routes.draw do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
ActionController::Base.send :include, Rails3JQueryAutocomplete::Application.routes.url_helpers
|
27
|
+
|
28
|
+
ActorsController = Class.new(ActionController::Base)
|
29
|
+
ActorsController.autocomplete(:movie, :name)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-jquery-autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Padilla
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-24 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -54,13 +54,13 @@ files:
|
|
54
54
|
- lib/rails3-jquery-autocomplete/form_helper.rb
|
55
55
|
- lib/rails3-jquery-autocomplete/formtastic_plugin.rb
|
56
56
|
- lib/rails3-jquery-autocomplete/helpers.rb
|
57
|
-
- test/active_record_controller_test.rb
|
58
57
|
- test/form_helper_test.rb
|
59
58
|
- test/generators/generator_test.rb
|
60
59
|
- test/helpers.rb
|
61
|
-
- test/
|
60
|
+
- test/implementations_test.rb
|
62
61
|
- test/support/active_record.rb
|
63
62
|
- test/support/mongoid.rb
|
63
|
+
- test/test_controller.rb
|
64
64
|
- test/test_helper.rb
|
65
65
|
- LICENSE
|
66
66
|
has_rdoc: true
|
@@ -98,11 +98,11 @@ signing_key:
|
|
98
98
|
specification_version: 3
|
99
99
|
summary: Use jQuery's autocomplete plugin with Rails 3.
|
100
100
|
test_files:
|
101
|
-
- test/active_record_controller_test.rb
|
102
101
|
- test/form_helper_test.rb
|
103
102
|
- test/generators/generator_test.rb
|
104
103
|
- test/helpers.rb
|
105
|
-
- test/
|
104
|
+
- test/implementations_test.rb
|
106
105
|
- test/support/active_record.rb
|
107
106
|
- test/support/mongoid.rb
|
107
|
+
- test/test_controller.rb
|
108
108
|
- test/test_helper.rb
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require 'support/active_record'
|
3
|
-
|
4
|
-
module Rails3JQueryAutocomplete
|
5
|
-
module Test
|
6
|
-
module ActiveRecord
|
7
|
-
|
8
|
-
class ActorsControllerTest < ActionController::TestCase
|
9
|
-
|
10
|
-
include Rails3JQueryAutocomplete::Test::ActiveRecord
|
11
|
-
|
12
|
-
setup do
|
13
|
-
@controller = ActorsController.new
|
14
|
-
end
|
15
|
-
|
16
|
-
context "the autocomplete gem" do
|
17
|
-
|
18
|
-
should "be able to access the autocomplete action regardless of the quality of param[:term]" do
|
19
|
-
get :autocomplete_movie_name
|
20
|
-
assert_response :success
|
21
|
-
|
22
|
-
get :autocomplete_movie_name, :term => ''
|
23
|
-
assert_response :success
|
24
|
-
|
25
|
-
get :autocomplete_movie_name, :term => nil
|
26
|
-
assert_response :success
|
27
|
-
|
28
|
-
get :autocomplete_movie_name, :term => 'Al'
|
29
|
-
assert_response :success
|
30
|
-
end
|
31
|
-
|
32
|
-
should "respond with expected json" do
|
33
|
-
get :autocomplete_movie_name, :term => 'Al'
|
34
|
-
json_response = JSON.parse(@response.body)
|
35
|
-
assert_equal(json_response.first["label"], @movie.name)
|
36
|
-
assert_equal(json_response.first["value"], @movie.name)
|
37
|
-
assert_equal(json_response.first["id"], @movie.id)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "return results in alphabetical order by default" do
|
41
|
-
get :autocomplete_movie_name, :term => 'Al'
|
42
|
-
json_response = JSON.parse(@response.body)
|
43
|
-
assert_equal(json_response.first["label"], "Alpha")
|
44
|
-
assert_equal(json_response.last["label"], "Alzpha")
|
45
|
-
end
|
46
|
-
|
47
|
-
should "be able to sort in other ways if desired" do
|
48
|
-
ActorsController.send(:autocomplete, :movie, :name, {:order => "name DESC"})
|
49
|
-
|
50
|
-
get :autocomplete_movie_name, :term => 'Al'
|
51
|
-
json_response = JSON.parse(@response.body)
|
52
|
-
assert_equal(json_response.first["label"], "Alzpha")
|
53
|
-
assert_equal(json_response.last["label"], "Alpha")
|
54
|
-
end
|
55
|
-
|
56
|
-
should "be able to limit the results" do
|
57
|
-
ActorsController.send(:autocomplete, :movie, :name, {:limit => 1})
|
58
|
-
|
59
|
-
get :autocomplete_movie_name, :term => 'Al'
|
60
|
-
json_response = JSON.parse(@response.body)
|
61
|
-
assert_equal(json_response.length, 1)
|
62
|
-
end
|
63
|
-
|
64
|
-
should "ignore case of search term and results" do
|
65
|
-
@movie = Movie.create(:name => 'aLpHa')
|
66
|
-
|
67
|
-
ActorsController.send(:autocomplete, :movie, :name)
|
68
|
-
|
69
|
-
get :autocomplete_movie_name, :term => 'Al'
|
70
|
-
json_response = JSON.parse(@response.body)
|
71
|
-
assert_equal(json_response.length, Movie.count)
|
72
|
-
assert_equal(json_response.last["label"], 'aLpHa')
|
73
|
-
end
|
74
|
-
|
75
|
-
should "match term to letters in middle of words when full-text search is on" do
|
76
|
-
ActorsController.send(:autocomplete, :movie, :name, {:full => true})
|
77
|
-
|
78
|
-
get :autocomplete_movie_name, :term => 'ph'
|
79
|
-
json_response = JSON.parse(@response.body)
|
80
|
-
assert_equal(json_response.length, Movie.count)
|
81
|
-
assert_equal(json_response.first["label"], @movie.name)
|
82
|
-
end
|
83
|
-
|
84
|
-
should "be able to customize what is displayed" do
|
85
|
-
ActorsController.send(:autocomplete, :movie, :name, {:display_value => :display_name})
|
86
|
-
|
87
|
-
get :autocomplete_movie_name, :term => 'Al'
|
88
|
-
|
89
|
-
json_response = JSON.parse(@response.body)
|
90
|
-
|
91
|
-
assert_equal(@movie.display_name, json_response.first["label"])
|
92
|
-
assert_equal(@movie.display_name, json_response.first["value"])
|
93
|
-
assert_equal(@movie.id, json_response.first["id"])
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require 'support/mongoid'
|
3
|
-
|
4
|
-
module Rails3JQueryAutocomplete
|
5
|
-
module Test
|
6
|
-
module Mongoid
|
7
|
-
|
8
|
-
class GamesControllerTest < ActionController::TestCase
|
9
|
-
|
10
|
-
include Rails3JQueryAutocomplete::Test::Mongoid
|
11
|
-
|
12
|
-
setup do
|
13
|
-
@controller = GamesController.new
|
14
|
-
end
|
15
|
-
|
16
|
-
context "the autocomplete gem" do
|
17
|
-
|
18
|
-
should "be able to access the autocomplete action regardless of the quality of param[:term]" do
|
19
|
-
get :autocomplete_game_name
|
20
|
-
assert_response :success
|
21
|
-
|
22
|
-
get :autocomplete_game_name, :term => ''
|
23
|
-
assert_response :success
|
24
|
-
|
25
|
-
get :autocomplete_game_name, :term => nil
|
26
|
-
assert_response :success
|
27
|
-
|
28
|
-
get :autocomplete_game_name, :term => 'Al'
|
29
|
-
assert_response :success
|
30
|
-
end
|
31
|
-
|
32
|
-
should "respond with expected json" do
|
33
|
-
get :autocomplete_game_name, :term => 'Al'
|
34
|
-
json_response = JSON.parse(@response.body)
|
35
|
-
assert_equal(json_response.first["label"], @game.name)
|
36
|
-
assert_equal(json_response.first["value"], @game.name)
|
37
|
-
assert_equal(json_response.first["id"], @game.id.to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "return results in alphabetical order by default" do
|
41
|
-
get :autocomplete_game_name, :term => 'Al'
|
42
|
-
json_response = JSON.parse(@response.body)
|
43
|
-
assert_equal(json_response.first["label"], "Alpha")
|
44
|
-
assert_equal(json_response.last["label"], "Alzpha")
|
45
|
-
end
|
46
|
-
|
47
|
-
should "be able to sort in other ways if desired" do
|
48
|
-
GamesController.send(:autocomplete, :game, :name, {:order => "name DESC"})
|
49
|
-
|
50
|
-
get :autocomplete_game_name, :term => 'Al'
|
51
|
-
json_response = JSON.parse(@response.body)
|
52
|
-
assert_equal(json_response.first["label"], "Alzpha")
|
53
|
-
assert_equal(json_response.last["label"], "Alpha")
|
54
|
-
end
|
55
|
-
|
56
|
-
should "be able to limit the results" do
|
57
|
-
GamesController.send(:autocomplete, :game, :name, {:limit => 1})
|
58
|
-
|
59
|
-
get :autocomplete_game_name, :term => 'Al'
|
60
|
-
json_response = JSON.parse(@response.body)
|
61
|
-
assert_equal(json_response.length, 1)
|
62
|
-
end
|
63
|
-
|
64
|
-
should "ignore case of search term and results" do
|
65
|
-
@game = Game.create(:name => 'aLpHa')
|
66
|
-
|
67
|
-
GamesController.send(:autocomplete, :game, :name)
|
68
|
-
|
69
|
-
get :autocomplete_game_name, :term => 'Al'
|
70
|
-
json_response = JSON.parse(@response.body)
|
71
|
-
assert_equal(json_response.length, Game.count)
|
72
|
-
assert_equal(json_response.last["label"], 'aLpHa')
|
73
|
-
end
|
74
|
-
|
75
|
-
should "match term to letters in middle of words when full-text search is on" do
|
76
|
-
GamesController.send(:autocomplete, :game, :name, {:full => true})
|
77
|
-
|
78
|
-
get :autocomplete_game_name, :term => 'ph'
|
79
|
-
json_response = JSON.parse(@response.body)
|
80
|
-
assert_equal(json_response.length, Game.count)
|
81
|
-
assert_equal(json_response.first["label"], @game.name)
|
82
|
-
end
|
83
|
-
|
84
|
-
should "be able to customize what is displayed" do
|
85
|
-
GamesController.send(:autocomplete, :game, :name, {:display_value => :display_name})
|
86
|
-
|
87
|
-
get :autocomplete_game_name, :term => 'Al'
|
88
|
-
|
89
|
-
json_response = JSON.parse(@response.body)
|
90
|
-
|
91
|
-
assert_equal(@game.display_name, json_response.first["label"])
|
92
|
-
assert_equal(@game.display_name, json_response.first["value"])
|
93
|
-
assert_equal(@game.id.to_s, json_response.first["id"])
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|