rails3-jquery-autocomplete 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +1 -1
- data/lib/rails3-jquery-autocomplete.rb +1 -1
- data/test/autocomplete_generator_test.rb +1 -1
- data/test/controller_module_test.rb +68 -67
- data/test/form_helper_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- metadata +4 -4
data/README.markdown
CHANGED
@@ -151,7 +151,7 @@ I have created a step to test your autocomplete with Cucumber and Capybara, all
|
|
151
151
|
|
152
152
|
Then you'll have access to the following step:
|
153
153
|
|
154
|
-
|
154
|
+
I choose "([^"]*)" in the autocomplete list
|
155
155
|
|
156
156
|
An example on how to use it:
|
157
157
|
|
@@ -31,7 +31,7 @@ module Rails3JQueryAutocomplete
|
|
31
31
|
order = options[:order] || "#{method} ASC"
|
32
32
|
|
33
33
|
define_method("autocomplete_#{object}_#{method}") do
|
34
|
-
|
34
|
+
if params[:term] && !params[:term].empty?
|
35
35
|
items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{(options[:full] ? '%' : '')}#{params[:term].downcase}%"]).limit(limit).order(order)
|
36
36
|
else
|
37
37
|
items = {}
|
@@ -36,6 +36,8 @@ def teardown_db
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class ActorsControllerTest < ActionController::TestCase
|
39
|
+
require 'shoulda'
|
40
|
+
require 'redgreen'
|
39
41
|
def setup
|
40
42
|
setup_db
|
41
43
|
|
@@ -48,90 +50,89 @@ class ActorsControllerTest < ActionController::TestCase
|
|
48
50
|
teardown_db
|
49
51
|
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@movie = Movie.create(:name => 'Alpha')
|
58
|
-
|
59
|
-
get :autocomplete_movie_name, :term => 'Al'
|
60
|
-
json_response = JSON.parse(@response.body)
|
61
|
-
assert_equal(json_response.first["label"], @movie.name)
|
62
|
-
assert_equal(json_response.first["value"], @movie.name)
|
63
|
-
assert_equal(json_response.first["id"], @movie.id)
|
64
|
-
end
|
53
|
+
context "the autocomplete gem" do
|
54
|
+
setup do
|
55
|
+
@movie = Movie.create(:name => 'Alpha')
|
56
|
+
@movie2 = Movie.create(:name => 'Alspha')
|
57
|
+
@movie3 = Movie.create(:name => 'Alzpha')
|
58
|
+
end
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@movie = Movie.create(:name => 'Alpha')
|
60
|
+
should "be able to access the autocomplete action regardless of the quality of param[:term]" do
|
61
|
+
get :autocomplete_movie_name
|
62
|
+
assert_response :success
|
70
63
|
|
71
|
-
|
72
|
-
|
73
|
-
assert_equal(json_response.first["label"], "Alpha")
|
74
|
-
assert_equal(json_response.last["label"], "Alzpha")
|
75
|
-
end
|
64
|
+
get :autocomplete_movie_name, :term => ''
|
65
|
+
assert_response :success
|
76
66
|
|
77
|
-
|
78
|
-
|
79
|
-
@movie = Movie.create(:name => 'Alspha')
|
80
|
-
@movie = Movie.create(:name => 'Alpha')
|
67
|
+
get :autocomplete_movie_name, :term => nil
|
68
|
+
assert_response :success
|
81
69
|
|
82
|
-
|
70
|
+
get :autocomplete_movie_name, :term => 'Al'
|
71
|
+
assert_response :success
|
72
|
+
end
|
83
73
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
74
|
+
should "respond with expected json" do
|
75
|
+
get :autocomplete_movie_name, :term => 'Al'
|
76
|
+
json_response = JSON.parse(@response.body)
|
77
|
+
assert_equal(json_response.first["label"], @movie.name)
|
78
|
+
assert_equal(json_response.first["value"], @movie.name)
|
79
|
+
assert_equal(json_response.first["id"], @movie.id)
|
80
|
+
end
|
89
81
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
should "return results in alphabetical order by default" do
|
83
|
+
get :autocomplete_movie_name, :term => 'Al'
|
84
|
+
json_response = JSON.parse(@response.body)
|
85
|
+
assert_equal(json_response.first["label"], "Alpha")
|
86
|
+
assert_equal(json_response.last["label"], "Alzpha")
|
87
|
+
end
|
94
88
|
|
95
|
-
|
89
|
+
should "be able to sort in other ways if desired" do
|
90
|
+
ActorsController.send(:autocomplete, :movie, :name, {:order => "name DESC"})
|
96
91
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
92
|
+
get :autocomplete_movie_name, :term => 'Al'
|
93
|
+
json_response = JSON.parse(@response.body)
|
94
|
+
assert_equal(json_response.first["label"], "Alzpha")
|
95
|
+
assert_equal(json_response.last["label"], "Alpha")
|
96
|
+
end
|
101
97
|
|
102
|
-
|
103
|
-
|
98
|
+
should "be able to limit the results" do
|
99
|
+
ActorsController.send(:autocomplete, :movie, :name, {:limit => 1})
|
104
100
|
|
105
|
-
|
101
|
+
get :autocomplete_movie_name, :term => 'Al'
|
102
|
+
json_response = JSON.parse(@response.body)
|
103
|
+
assert_equal(json_response.length, 1)
|
104
|
+
end
|
106
105
|
|
107
|
-
|
108
|
-
|
109
|
-
assert_equal(json_response.length, 1)
|
110
|
-
assert_equal(json_response.first["label"], 'aLpHa')
|
111
|
-
end
|
106
|
+
should "ignore case of search term and results" do
|
107
|
+
@movie = Movie.create(:name => 'aLpHa')
|
112
108
|
|
113
|
-
|
114
|
-
@movie = Movie.create(:name => 'aLpHa')
|
109
|
+
ActorsController.send(:autocomplete, :movie, :name)
|
115
110
|
|
116
|
-
|
111
|
+
get :autocomplete_movie_name, :term => 'Al'
|
112
|
+
json_response = JSON.parse(@response.body)
|
113
|
+
assert_equal(json_response.length, Movie.count)
|
114
|
+
assert_equal(json_response.last["label"], 'aLpHa')
|
115
|
+
end
|
117
116
|
|
118
|
-
|
119
|
-
|
120
|
-
assert_equal(json_response.length, 1)
|
121
|
-
assert_equal(json_response.first["label"], 'aLpHa')
|
122
|
-
end
|
117
|
+
should "match term to letters in middle of words when full-text search is on" do
|
118
|
+
ActorsController.send(:autocomplete, :movie, :name, {:full => true})
|
123
119
|
|
124
|
-
|
125
|
-
|
120
|
+
get :autocomplete_movie_name, :term => 'ph'
|
121
|
+
json_response = JSON.parse(@response.body)
|
122
|
+
assert_equal(json_response.length, Movie.count)
|
123
|
+
assert_equal(json_response.first["label"], @movie.name)
|
124
|
+
end
|
126
125
|
|
127
|
-
|
126
|
+
should "be able to customize what is displayed" do
|
127
|
+
ActorsController.send(:autocomplete, :movie, :name, {:display_value => :display_name})
|
128
128
|
|
129
|
-
|
129
|
+
get :autocomplete_movie_name, :term => 'Al'
|
130
130
|
|
131
|
-
|
131
|
+
json_response = JSON.parse(@response.body)
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
assert_equal(@movie.display_name, json_response.first["label"])
|
134
|
+
assert_equal(@movie.display_name, json_response.first["value"])
|
135
|
+
assert_equal(@movie.id, json_response.first["id"])
|
136
|
+
end
|
136
137
|
end
|
137
|
-
end
|
138
|
+
end
|
data/test/form_helper_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 5
|
10
|
+
version: 0.3.5
|
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-09-
|
18
|
+
date: 2010-09-27 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|