rails3-jquery-autocomplete 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,6 +1,10 @@
1
1
  README.markdown
2
2
  Rakefile
3
+ init.rb
3
4
  lib/autocomplete.rb
4
5
  lib/generators/autocomplete_generator.rb
5
6
  lib/generators/templates/autocomplete-rails.js
7
+ rails3-jquery-autocomplete.gemspec
8
+ test/controller_module_test.rb
9
+ test/test_helper.rb
6
10
  Manifest
data/README.markdown CHANGED
@@ -66,7 +66,3 @@ This will generate an HTML tag that looks like:
66
66
  Now your autocomplete JS code is unobtrusive, Rails 3 style.
67
67
 
68
68
  And... That's it!
69
-
70
- ## TODO
71
-
72
- Tests
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('rails3-jquery-autocomplete', '0.1.1') do |p|
5
+ Echoe.new('rails3-jquery-autocomplete', '0.1.2') do |p|
6
6
  p.description = "Use jQuery's autocomplete plugin with Rails 3."
7
7
  p.url = "http://github.com/crowdint/rails3-jquery-autocomplete"
8
8
  p.author = "David Padilla"
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'autocomplete'
@@ -2,21 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rails3-jquery-autocomplete}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["David Padilla"]
9
- s.date = %q{2010-07-15}
9
+ s.date = %q{2010-07-19}
10
10
  s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
11
11
  s.email = %q{david@crowdint.com}
12
12
  s.extra_rdoc_files = ["README.markdown", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js"]
13
- s.files = ["README.markdown", "Rakefile", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js", "Manifest", "rails3-jquery-autocomplete.gemspec"]
13
+ s.files = ["README.markdown", "Rakefile", "init.rb", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js", "rails3-jquery-autocomplete.gemspec", "test/controller_module_test.rb", "test/test_helper.rb", "Manifest"]
14
14
  s.homepage = %q{http://github.com/crowdint/rails3-jquery-autocomplete}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rails3-jquery-autocomplete", "--main", "README.markdown"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{rails3-jquery-autocomplete}
18
18
  s.rubygems_version = %q{1.3.7}
19
19
  s.summary = %q{Use jQuery's autocomplete plugin with Rails 3.}
20
+ s.test_files = ["test/controller_module_test.rb", "test/test_helper.rb"]
20
21
 
21
22
  if s.respond_to? :specification_version then
22
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,98 @@
1
+ require "test_helper"
2
+
3
+ class ActorsController < ApplicationController
4
+ autocomplete :movie, :name
5
+ end
6
+
7
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
8
+
9
+ class Actor < ActiveRecord::Base
10
+ belongs_to :movie
11
+ end
12
+
13
+ class Movie < ActiveRecord::Base
14
+ end
15
+
16
+ def setup_db
17
+ ActiveRecord::Schema.define(:version => 1) do
18
+ create_table :movies do |t|
19
+ t.column :name, :string
20
+ end
21
+
22
+ create_table :actors do |t|
23
+ t.column :movie_id, :integer
24
+ t.column :name, :string
25
+ end
26
+ end
27
+ end
28
+
29
+ def teardown_db
30
+ ActiveRecord::Base.connection.tables.each do |table|
31
+ ActiveRecord::Base.connection.drop_table(table)
32
+ end
33
+ end
34
+
35
+ class ActorsControllerTest < ActionController::TestCase
36
+ def setup
37
+ setup_db
38
+
39
+ @controller = ActorsController.new
40
+ @controller.request = @request = ActionController::TestRequest.new
41
+ @controller.response = @response = ActionController::TestResponse.new
42
+ end
43
+
44
+ def teardown
45
+ teardown_db
46
+ end
47
+
48
+ def test_response_succesful
49
+ get :autocomplete_movie_name, :term => 'Al'
50
+ assert_response :success
51
+ end
52
+
53
+ def test_response_json
54
+ @movie = Movie.create(:name => 'Alpha')
55
+
56
+ get :autocomplete_movie_name, :term => 'Al'
57
+ json_response = JSON.parse(@response.body)
58
+ assert_equal(json_response.first["label"], @movie.name)
59
+ assert_equal(json_response.first["value"], @movie.name)
60
+ assert_equal(json_response.first["id"], @movie.id)
61
+ end
62
+
63
+ def test_alphabetic_order
64
+ @movie = Movie.create(:name => 'Alzpha')
65
+ @movie = Movie.create(:name => 'Alspha')
66
+ @movie = Movie.create(:name => 'Alpha')
67
+
68
+ get :autocomplete_movie_name, :term => 'Al'
69
+ json_response = JSON.parse(@response.body)
70
+ assert_equal(json_response.first["label"], "Alpha")
71
+ assert_equal(json_response.last["label"], "Alzpha")
72
+ end
73
+
74
+ def test_alternative_sort_order
75
+ @movie = Movie.create(:name => 'Alzpha')
76
+ @movie = Movie.create(:name => 'Alspha')
77
+ @movie = Movie.create(:name => 'Alpha')
78
+
79
+ ActorsController.send(:autocomplete, :movie, :name, {:order => "name DESC"})
80
+
81
+ get :autocomplete_movie_name, :term => 'Al'
82
+ json_response = JSON.parse(@response.body)
83
+ assert_equal(json_response.first["label"], "Alzpha")
84
+ assert_equal(json_response.last["label"], "Alpha")
85
+ end
86
+
87
+ def test_response_limit
88
+ @movie = Movie.create(:name => 'Alzpha')
89
+ @movie = Movie.create(:name => 'Alspha')
90
+ @movie = Movie.create(:name => 'Alpha')
91
+
92
+ ActorsController.send(:autocomplete, :movie, :name, {:limit => 1})
93
+
94
+ get :autocomplete_movie_name, :term => 'Al'
95
+ json_response = JSON.parse(@response.body)
96
+ assert_equal(json_response.length, 1)
97
+ end
98
+ end
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+ gem 'rails', '>=3.0.0.beta4'
5
+
6
+ require "active_support"
7
+ require "active_record"
8
+ require "active_model"
9
+ require "action_controller"
10
+ require "rails/railtie"
11
+
12
+ ENV["RAILS_ENV"] = "test"
13
+ RAILS_ROOT = "anywhere"
14
+
15
+ require "#{File.dirname(__FILE__)}/../init"
16
+
17
+ class ApplicationController < ActionController::Base; end
18
+
19
+ ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
20
+
21
+ Autocomplete::Routes = ActionDispatch::Routing::RouteSet.new
22
+ Autocomplete::Routes.draw do |map|
23
+ map.connect ':controller/:action/:id'
24
+ map.connect ':controller/:action'
25
+ end
26
+
27
+ ActionController::Base.send :include, Autocomplete::Routes.url_helpers
28
+
29
+ class ActiveSupport::TestCase
30
+ setup do
31
+ @routes = Autocomplete::Routes
32
+ end
33
+ 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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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-07-15 00:00:00 -05:00
18
+ date: 2010-07-19 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -33,11 +33,14 @@ extra_rdoc_files:
33
33
  files:
34
34
  - README.markdown
35
35
  - Rakefile
36
+ - init.rb
36
37
  - lib/autocomplete.rb
37
38
  - lib/generators/autocomplete_generator.rb
38
39
  - lib/generators/templates/autocomplete-rails.js
39
- - Manifest
40
40
  - rails3-jquery-autocomplete.gemspec
41
+ - test/controller_module_test.rb
42
+ - test/test_helper.rb
43
+ - Manifest
41
44
  has_rdoc: true
42
45
  homepage: http://github.com/crowdint/rails3-jquery-autocomplete
43
46
  licenses: []
@@ -78,5 +81,6 @@ rubygems_version: 1.3.7
78
81
  signing_key:
79
82
  specification_version: 3
80
83
  summary: Use jQuery's autocomplete plugin with Rails 3.
81
- test_files: []
82
-
84
+ test_files:
85
+ - test/controller_module_test.rb
86
+ - test/test_helper.rb