rails3-jquery-autocomplete 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -272,10 +272,13 @@ You can run the integration tests with the cucumber command while on the
272
272
  integration folder:
273
273
 
274
274
  cd integration
275
+ rake db:migrate
275
276
  cucumber
276
277
 
277
278
  # Changelog
278
279
 
280
+ * 0.7.1 Fixed joined scopes (Issue #43)
281
+ * 0.7.0 Scopes
279
282
  * 0.6.6 ILIKE for postgres
280
283
  * 0.6.5 JS select event
281
284
  * 0.6.4 Use YAJL instead of JSON
@@ -1,5 +1,5 @@
1
1
  class ScopedAutocompletesController < ApplicationController
2
- autocomplete :brand, :name, :scope => "active"
2
+ autocomplete :brand, :name, :scopes => ["active", "with_address"]
3
3
 
4
4
  def new
5
5
  @product = Product.new
@@ -0,0 +1,2 @@
1
+ class Address < ActiveRecord::Base
2
+ end
@@ -12,4 +12,7 @@
12
12
 
13
13
  class Brand < ActiveRecord::Base
14
14
  scope :active, where(:state => true)
15
+ scope :with_address, joins(:address)
16
+
17
+ belongs_to :address
15
18
  end
@@ -0,0 +1,13 @@
1
+ class CreateAddresses < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :addresses do |t|
4
+ t.string :street
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :addresses
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class AddAddressIdToBrand < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :brands, :address_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :brands, :address_id
8
+ end
9
+ end
@@ -10,7 +10,13 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20110423000347) do
13
+ ActiveRecord::Schema.define(:version => 20110512153811) do
14
+
15
+ create_table "addresses", :force => true do |t|
16
+ t.string "street"
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ end
14
20
 
15
21
  create_table "brands", :force => true do |t|
16
22
  t.string "name"
@@ -18,6 +24,7 @@ ActiveRecord::Schema.define(:version => 20110423000347) do
18
24
  t.datetime "updated_at"
19
25
  t.string "type"
20
26
  t.boolean "state"
27
+ t.integer "address_id"
21
28
  end
22
29
 
23
30
  create_table "features", :force => true do |t|
@@ -6,11 +6,11 @@ Feature: Autocomplete
6
6
  Background:
7
7
  Given the following brands exists:
8
8
  | name | state |
9
- | Alpha | 1 |
10
- | Beta | 0 |
11
- | Gamma | 0 |
12
- | Kappa | 1 |
13
- | Kappler | 0 |
9
+ | Alpha | true |
10
+ | Beta | false |
11
+ | Gamma | false |
12
+ | Kappa | true |
13
+ | Kappler | false |
14
14
  And the following features exists:
15
15
  | name |
16
16
  | Shiny |
@@ -66,6 +66,7 @@ Feature: Autocomplete
66
66
 
67
67
  @javascript
68
68
  Scenario: Autocomplete with scope
69
+ Given the "Kappa" brand has an address
69
70
  Given I go to the new scoped autocomplete page
70
71
  And I fill in "Brand name" with "ka"
71
72
  And I choose "Kappa" in the autocomplete list
@@ -7,4 +7,9 @@ And /^I send (.*) to "(.*)"$/ do |key, element|
7
7
  find_field(element).native.send_keys(key)
8
8
  end
9
9
 
10
+ Given /^the "([^"]*)" brand has an address$/ do |brand_name|
11
+ brand = Brand.find_by_name(brand_name)
12
+ brand.address = Address.create
13
+ brand.save!
14
+ end
10
15
 
@@ -89,10 +89,10 @@ module Rails3JQueryAutocomplete
89
89
  # items = get_autocomplete_items(:model => get_object(object), :options => options, :term => term, :method => method)
90
90
  #
91
91
  def get_autocomplete_items(parameters)
92
- model = parameters[:model]
93
- term = parameters[:term]
94
- method = parameters[:method]
95
- options = parameters[:options]
92
+ model = parameters[:model]
93
+ term = parameters[:term]
94
+ method = parameters[:method]
95
+ options = parameters[:options]
96
96
 
97
97
  is_full_search = options[:full]
98
98
  scopes = Array(options[:scopes])
@@ -111,8 +111,9 @@ module Rails3JQueryAutocomplete
111
111
  search = (is_full_search ? '.*' : '^') + term + '.*'
112
112
  items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
113
113
  when :activerecord
114
- items = items.select([:id, method] + (options[:extra_data].blank? ? [] : options[:extra_data])) unless options[:full_model]
115
- items = items.where(["LOWER(#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]) \
114
+ table_name = model.table_name
115
+ items = items.select(["#{table_name}.id", "#{table_name}.#{method}"] + (options[:extra_data].blank? ? [] : options[:extra_data])) unless options[:full_model]
116
+ items = items.where(["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]) \
116
117
  .limit(limit).order(order)
117
118
  end
118
119
  end
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.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: 2011-04-25 00:00:00 -05:00
18
+ date: 2011-05-12 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -144,6 +144,7 @@ files:
144
144
  - integration/app/helpers/id_elements_helper.rb
145
145
  - integration/app/helpers/layout_helper.rb
146
146
  - integration/app/helpers/sub_classes_helper.rb
147
+ - integration/app/models/address.rb
147
148
  - integration/app/models/brand.rb
148
149
  - integration/app/models/feature.rb
149
150
  - integration/app/models/foreign_brand.rb
@@ -177,6 +178,8 @@ files:
177
178
  - integration/db/migrate/20101209053936_add_type_to_brand.rb
178
179
  - integration/db/migrate/20110209020136_create_features.rb
179
180
  - integration/db/migrate/20110423000347_add_state_to_brands.rb
181
+ - integration/db/migrate/20110512153732_create_addresses.rb
182
+ - integration/db/migrate/20110512153811_add_address_id_to_brand.rb
180
183
  - integration/db/schema.rb
181
184
  - integration/db/seeds.rb
182
185
  - integration/doc/README_FOR_APP