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 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
- And I choose "Alpha" in the autocomplete list
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
- unless params[:term] && params[:term].empty?
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 = {}
@@ -19,4 +19,4 @@ class AutocompleteGeneratorTest < Test::Unit::TestCase
19
19
  File.read(File.join(@destination, 'public', 'javascripts', 'autocomplete-rails.js'))
20
20
  )
21
21
  end
22
- end
22
+ end
@@ -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
- def test_response_succesful
52
- get :autocomplete_movie_name, :term => 'Al'
53
- assert_response :success
54
- end
55
-
56
- def test_response_json
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
- def test_alphabetic_order
67
- @movie = Movie.create(:name => 'Alzpha')
68
- @movie = Movie.create(:name => 'Alspha')
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
- get :autocomplete_movie_name, :term => 'Al'
72
- json_response = JSON.parse(@response.body)
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
- def test_alternative_sort_order
78
- @movie = Movie.create(:name => 'Alzpha')
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
- ActorsController.send(:autocomplete, :movie, :name, {:order => "name DESC"})
70
+ get :autocomplete_movie_name, :term => 'Al'
71
+ assert_response :success
72
+ end
83
73
 
84
- get :autocomplete_movie_name, :term => 'Al'
85
- json_response = JSON.parse(@response.body)
86
- assert_equal(json_response.first["label"], "Alzpha")
87
- assert_equal(json_response.last["label"], "Alpha")
88
- end
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
- def test_response_limit
91
- @movie = Movie.create(:name => 'Alzpha')
92
- @movie = Movie.create(:name => 'Alspha')
93
- @movie = Movie.create(:name => 'Alpha')
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
- ActorsController.send(:autocomplete, :movie, :name, {:limit => 1})
89
+ should "be able to sort in other ways if desired" do
90
+ ActorsController.send(:autocomplete, :movie, :name, {:order => "name DESC"})
96
91
 
97
- get :autocomplete_movie_name, :term => 'Al'
98
- json_response = JSON.parse(@response.body)
99
- assert_equal(json_response.length, 1)
100
- end
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
- def test_downcase
103
- @movie = Movie.create(:name => 'aLpHa')
98
+ should "be able to limit the results" do
99
+ ActorsController.send(:autocomplete, :movie, :name, {:limit => 1})
104
100
 
105
- ActorsController.send(:autocomplete, :movie, :name)
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
- get :autocomplete_movie_name, :term => 'Al'
108
- json_response = JSON.parse(@response.body)
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
- def test_full_search
114
- @movie = Movie.create(:name => 'aLpHa')
109
+ ActorsController.send(:autocomplete, :movie, :name)
115
110
 
116
- ActorsController.send(:autocomplete, :movie, :name, {:full => true})
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
- get :autocomplete_movie_name, :term => 'ph'
119
- json_response = JSON.parse(@response.body)
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
- def test_value_option
125
- ActorsController.send(:autocomplete, :movie, :name, {:display_value => :display_name})
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
- @movie = Movie.create(:name => 'Alpha')
126
+ should "be able to customize what is displayed" do
127
+ ActorsController.send(:autocomplete, :movie, :name, {:display_value => :display_name})
128
128
 
129
- get :autocomplete_movie_name, :term => 'Al'
129
+ get :autocomplete_movie_name, :term => 'Al'
130
130
 
131
- json_response = JSON.parse(@response.body)
131
+ json_response = JSON.parse(@response.body)
132
132
 
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"])
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
@@ -22,4 +22,4 @@ class FormHelperTest < ActionView::TestCase
22
22
  post= Post.new
23
23
  assert_match(/data-autocomplete=\"some\/path\"/, autocomplete_field(:post, :author, 'some/path'))
24
24
  end
25
- end
25
+ end
data/test/test_helper.rb CHANGED
@@ -31,4 +31,4 @@ class ActiveSupport::TestCase
31
31
  setup do
32
32
  @routes = Rails3JQueryAutocomplete::Routes
33
33
  end
34
- end
34
+ end
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
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-14 00:00:00 -07:00
18
+ date: 2010-09-27 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency