rails4-autocomplete 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +31 -0
  3. data/README.md +374 -0
  4. data/Rakefile +21 -0
  5. data/lib/assets/javascripts/autocomplete-rails-uncompressed.js +136 -0
  6. data/lib/assets/javascripts/autocomplete-rails.js +16 -0
  7. data/lib/cucumber/autocomplete.rb +6 -0
  8. data/lib/generators/autocomplete/install_generator.rb +14 -0
  9. data/lib/generators/autocomplete/uncompressed_generator.rb +14 -0
  10. data/lib/rails4-autocomplete.rb +23 -0
  11. data/lib/rails4-autocomplete/autocomplete.rb +96 -0
  12. data/lib/rails4-autocomplete/form_helper.rb +47 -0
  13. data/lib/rails4-autocomplete/formtastic.rb +41 -0
  14. data/lib/rails4-autocomplete/formtastic_plugin.rb +44 -0
  15. data/lib/rails4-autocomplete/orm.rb +8 -0
  16. data/lib/rails4-autocomplete/orm/active_record.rb +52 -0
  17. data/lib/rails4-autocomplete/orm/mongo_mapper.rb +30 -0
  18. data/lib/rails4-autocomplete/orm/mongoid.rb +34 -0
  19. data/lib/rails4-autocomplete/rails/engine.rb +5 -0
  20. data/lib/rails4-autocomplete/simple_form_plugin.rb +84 -0
  21. data/lib/rails4-autocomplete/version.rb +3 -0
  22. data/lib/steak/autocomplete.rb +12 -0
  23. data/test/form_helper_test.rb +25 -0
  24. data/test/generators/autocomplete/install_generator_test.rb +25 -0
  25. data/test/generators/autocomplete/uncompressed_generator_test.rb +25 -0
  26. data/test/lib/rails3-jquery-autocomplete/autocomplete_test.rb +59 -0
  27. data/test/lib/rails3-jquery-autocomplete/orm/active_record_test.rb +145 -0
  28. data/test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb +60 -0
  29. data/test/lib/rails3-jquery-autocomplete/orm/mongoid_test.rb +60 -0
  30. data/test/lib/rails3-jquery-autocomplete/simple_form_plugin_test.rb +33 -0
  31. data/test/lib/rails3-jquery-autocomplete_test.rb +38 -0
  32. data/test/test_helper.rb +36 -0
  33. data/test/view_test_helper.rb +108 -0
  34. metadata +268 -0
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ module Rails4Autocomplete
4
+ module Orm
5
+ class MongoidTest < Test::Unit::TestCase
6
+ include Rails4Autocomplete::Orm::Mongoid
7
+
8
+ context "#get_autocomplete_order" do
9
+ context "order is specified" do
10
+ should 'returns the parametrized order for Mongoid' do
11
+ assert_equal [[:field, :asc], [:state, :desc]],
12
+ get_autocomplete_order(:method, :order => 'field ASC, state DESC')
13
+ end
14
+ end
15
+
16
+ context 'order is not specified' do
17
+ should 'return the method ordered ASC by default' do
18
+ assert_equal [[:method, :asc]],
19
+ get_autocomplete_order(:method, {})
20
+ end
21
+ end
22
+ end
23
+
24
+ context "#get_autocomplete_items" do
25
+ setup do
26
+ @model = mock(Object)
27
+
28
+ @parameters = {
29
+ :model => @model,
30
+ :method => :field,
31
+ :term => 'query',
32
+ :options => {:full => false}
33
+ }
34
+ mock(self).get_autocomplete_limit(anything) { 10 }
35
+ mock(self).get_autocomplete_order(anything, anything) { [[:order, :asc]] }
36
+ end
37
+
38
+ context 'not a full search' do
39
+ should 'do stuff' do
40
+ mock(@model).where({:field=>/^query/i}).mock!.limit(10).
41
+ mock!.order_by([[:order, :asc]])
42
+
43
+ get_autocomplete_items(@parameters)
44
+ end
45
+ end
46
+
47
+ context 'full search' do
48
+ should 'return a full search query' do
49
+ @parameters[:options] = {:full => true}
50
+
51
+ mock(@model).where({:field=>/.*query.*/i}).mock!.limit(10).
52
+ mock!.order_by([[:order, :asc]])
53
+
54
+ get_autocomplete_items(@parameters)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+ require 'view_test_helper'
3
+
4
+ module Rails4Autocomplete
5
+ class SimpleFormPluginTest < ActionView::TestCase
6
+
7
+ should "apply a class of 'autocomplete'" do
8
+ with_input_for @user, :name, :autocomplete
9
+ assert_select "input#user_name.autocomplete[type=text][name='user[name]']"
10
+ end
11
+
12
+ should "add a data-autocomplete attribute with the provided :url" do
13
+ with_input_for @user, :name, :autocomplete, :url => '/test'
14
+ assert_select "input#user_name[data-autocomplete=/test]"
15
+ end
16
+
17
+ should "add a data-update-elements attribute with encoded data if passed an :update_elements option" do
18
+ with_input_for @user, :name, :autocomplete, :update_elements => { :id => '#this', :ego => '#that' }
19
+ assert_select "input#user_name[data-update-elements='{&quot;id&quot;:&quot;#this&quot;,&quot;ego&quot;:&quot;#that&quot;}']"
20
+ end
21
+
22
+ should "not add a data-update-elements attribute if not passed an :update_elements option" do
23
+ with_input_for @user, :name, :autocomplete, :url => '/test'
24
+ assert_no_select "input#user_name[data-update-elements]"
25
+ end
26
+
27
+ should "add arbitrary html options, if specified" do
28
+ with_input_for @user, :name, :autocomplete, :input_html => { :class => "superego" }
29
+ assert_select "input#user_name.superego"
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module Rails4Autocomplete
4
+ class Rails4AutocompleteTest < ActionController::TestCase
5
+ ActorsController = Class.new(ActionController::Base)
6
+ ActorsController.autocomplete(:movie, :name)
7
+
8
+ class ::Movie ; end
9
+
10
+ context '#autocomplete_object_method' do
11
+ setup do
12
+ @controller = ActorsController.new
13
+ @items = {}
14
+ @options = { :display_value => :name }
15
+ end
16
+
17
+ should 'respond to the action' do
18
+ assert_respond_to @controller, :autocomplete_movie_name
19
+ end
20
+
21
+ should 'render the JSON items' do
22
+ mock(@controller).get_autocomplete_items({
23
+ :model => Movie, :method => :name, :options => @options, :term => "query"
24
+ }) { @items }
25
+
26
+ mock(@controller).json_for_autocomplete(@items, :name, nil)
27
+ get :autocomplete_movie_name, :term => 'query'
28
+ end
29
+
30
+ context 'no term is specified' do
31
+ should "render an empty hash" do
32
+ mock(@controller).json_for_autocomplete({}, :name, nil)
33
+ get :autocomplete_movie_name
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ ENV["RAILS_ENV"] = "test"
8
+ module Rails
9
+ def self.env
10
+ ActiveSupport::StringInquirer.new("test")
11
+ end
12
+ end
13
+
14
+ require 'rails/all'
15
+ require 'mongoid'
16
+ require 'mongo_mapper'
17
+ require 'shoulda'
18
+ require 'rr'
19
+ require 'rails/test_help'
20
+ require 'rails4-autocomplete'
21
+
22
+ module Rails4Autocomplete
23
+ class Application < ::Rails::Application
24
+ end
25
+ end
26
+
27
+ Rails4Autocomplete::Application.routes.draw do
28
+ match '/:controller(/:action(/:id))'
29
+ end
30
+
31
+ ActionController::Base.send :include, Rails4Autocomplete::Application.routes.url_helpers
32
+
33
+ class Test::Unit::TestCase
34
+ include RR::Adapters::TestUnit
35
+ end
36
+
@@ -0,0 +1,108 @@
1
+ class User
2
+ extend ActiveModel::Naming
3
+ include ActiveModel::Conversion
4
+
5
+ attr_accessor :id, :name, :description, :created_at, :updated_at
6
+
7
+ def initialize(options={})
8
+ @new_record = false
9
+ options.each do |key, value|
10
+ send("#{key}=", value)
11
+ end if options
12
+ end
13
+
14
+ def new_record!
15
+ @new_record = true
16
+ end
17
+
18
+ def persisted?
19
+ !@new_record
20
+ end
21
+ end
22
+
23
+ class MockController
24
+ attr_writer :action_name
25
+
26
+ def _routes
27
+ self
28
+ end
29
+
30
+ def action_name
31
+ defined?(@action_name) ? @action_name : "edit"
32
+ end
33
+
34
+ def url_for(*args)
35
+ "http://example.com"
36
+ end
37
+
38
+ def url_helpers
39
+ self
40
+ end
41
+
42
+ def hash_for_user_path(*args); end
43
+ def hash_for_users_path(*args); end
44
+ end
45
+
46
+ class MockResponse
47
+
48
+ def initialize(test_case)
49
+ @test_case = test_case
50
+ end
51
+
52
+ def content_type
53
+ 'text/html'
54
+ end
55
+
56
+ def body
57
+ @test_case.send :output_buffer
58
+ end
59
+ end
60
+
61
+ class ActionView::TestCase
62
+ include Rails4Autocomplete::Autocomplete
63
+ include SimpleForm::ActionViewExtensions::FormHelper
64
+
65
+ setup :set_controller
66
+ setup :set_response
67
+ setup :setup_new_user
68
+
69
+ def assert_no_select(selector, value = nil)
70
+ assert_select(selector, :text => value, :count => 0)
71
+ end
72
+
73
+ def with_concat_form_for(*args, &block)
74
+ concat simple_form_for(*args, &block)
75
+ end
76
+
77
+ def with_input_for(object, attribute_name, type, options={})
78
+ with_concat_form_for(object) do |f|
79
+ f.input(attribute_name, options.merge(:as => type))
80
+ end
81
+ end
82
+
83
+ def set_controller
84
+ @controller = MockController.new
85
+ end
86
+
87
+ def set_response
88
+ @response = MockResponse.new(self)
89
+ end
90
+
91
+ def setup_new_user
92
+ @user = User.new(
93
+ :id => 1,
94
+ :name => 'New in SimpleForm!',
95
+ :description => 'Hello!',
96
+ :created_at => Time.now
97
+ )
98
+ end
99
+
100
+ def protect_against_forgery?
101
+ false
102
+ end
103
+
104
+ def user_path(*args)
105
+ '/users'
106
+ end
107
+ alias :users_path :user_path
108
+ end
metadata ADDED
@@ -0,0 +1,268 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails4-autocomplete
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7
5
+ platform: ruby
6
+ authors:
7
+ - alex_tian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: mongo_mapper
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: bson_ext
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-unit
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 2.2.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 2.2.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: shoulda
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 3.0.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: uglifier
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rr
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simple_form
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: '1.5'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ~>
193
+ - !ruby/object:Gem::Version
194
+ version: '1.5'
195
+ description: Use jQuery's autocomplete plugin with Rails 4.
196
+ email: peterwillcn@gmail.com
197
+ executables: []
198
+ extensions: []
199
+ extra_rdoc_files: []
200
+ files:
201
+ - lib/assets/javascripts/autocomplete-rails-uncompressed.js
202
+ - lib/assets/javascripts/autocomplete-rails.js
203
+ - lib/cucumber/autocomplete.rb
204
+ - lib/generators/autocomplete/install_generator.rb
205
+ - lib/generators/autocomplete/uncompressed_generator.rb
206
+ - lib/rails4-autocomplete/autocomplete.rb
207
+ - lib/rails4-autocomplete/form_helper.rb
208
+ - lib/rails4-autocomplete/formtastic.rb
209
+ - lib/rails4-autocomplete/formtastic_plugin.rb
210
+ - lib/rails4-autocomplete/orm/active_record.rb
211
+ - lib/rails4-autocomplete/orm/mongo_mapper.rb
212
+ - lib/rails4-autocomplete/orm/mongoid.rb
213
+ - lib/rails4-autocomplete/orm.rb
214
+ - lib/rails4-autocomplete/rails/engine.rb
215
+ - lib/rails4-autocomplete/simple_form_plugin.rb
216
+ - lib/rails4-autocomplete/version.rb
217
+ - lib/rails4-autocomplete.rb
218
+ - lib/steak/autocomplete.rb
219
+ - CHANGELOG.md
220
+ - README.md
221
+ - Rakefile
222
+ - test/form_helper_test.rb
223
+ - test/generators/autocomplete/install_generator_test.rb
224
+ - test/generators/autocomplete/uncompressed_generator_test.rb
225
+ - test/lib/rails3-jquery-autocomplete/autocomplete_test.rb
226
+ - test/lib/rails3-jquery-autocomplete/orm/active_record_test.rb
227
+ - test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
228
+ - test/lib/rails3-jquery-autocomplete/orm/mongoid_test.rb
229
+ - test/lib/rails3-jquery-autocomplete/simple_form_plugin_test.rb
230
+ - test/lib/rails3-jquery-autocomplete_test.rb
231
+ - test/test_helper.rb
232
+ - test/view_test_helper.rb
233
+ homepage: http://github.com/peterwillcn/rails4-autocomplete
234
+ licenses:
235
+ - MIT
236
+ metadata: {}
237
+ post_install_message:
238
+ rdoc_options: []
239
+ require_paths:
240
+ - lib
241
+ required_ruby_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements: []
252
+ rubyforge_project:
253
+ rubygems_version: 2.0.3
254
+ signing_key:
255
+ specification_version: 4
256
+ summary: Use jQuery's autocomplete plugin with Rails 4.
257
+ test_files:
258
+ - test/form_helper_test.rb
259
+ - test/generators/autocomplete/install_generator_test.rb
260
+ - test/generators/autocomplete/uncompressed_generator_test.rb
261
+ - test/lib/rails3-jquery-autocomplete/autocomplete_test.rb
262
+ - test/lib/rails3-jquery-autocomplete/orm/active_record_test.rb
263
+ - test/lib/rails3-jquery-autocomplete/orm/mongo_mapper_test.rb
264
+ - test/lib/rails3-jquery-autocomplete/orm/mongoid_test.rb
265
+ - test/lib/rails3-jquery-autocomplete/simple_form_plugin_test.rb
266
+ - test/lib/rails3-jquery-autocomplete_test.rb
267
+ - test/test_helper.rb
268
+ - test/view_test_helper.rb