rails3-jquery-autocomplete 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -245,6 +245,35 @@ An example on how to use it:
245
245
 
246
246
  I have only tested this using Capybara, no idea if it works with something else, to see it in action, check the [example app](http://github.com/crowdint/rails3-jquery-autocomplete-app).
247
247
 
248
+ # Steak
249
+
250
+ I have created a helper to test your autocomplete with Steak and Capybara, all you have to do is add the following lines to your *acceptance_helper.rb* file:
251
+
252
+ require 'steak/autocomplete'
253
+
254
+ Then you'll have access to the following helper:
255
+
256
+ choose_autocomplete_result
257
+
258
+ An example on how to use it:
259
+
260
+ scenario "Autocomplete" do
261
+ lambda do
262
+ Brand.create! [
263
+ {:name => "Alpha"},
264
+ {:name => "Beta"},
265
+ {:name => "Gamma"}
266
+ ]
267
+ end.should change(Brand, :count).by(3)
268
+
269
+ visit home_page
270
+ fill_in "Brand name", :with => "al"
271
+ choose_autocomplete_result "Alpha"
272
+ find_field("Brand name").value.should include("Alpha")
273
+ end
274
+
275
+ I have only tested this using Capybara, no idea if it works with something else.
276
+
248
277
  # Development
249
278
 
250
279
  If you want to make changes to the gem, first install bundler 1.0.0:
@@ -277,6 +306,7 @@ integration folder:
277
306
 
278
307
  # Changelog
279
308
 
309
+ * 0.7.2 Steak helper
280
310
  * 0.7.1 Fixed joined scopes (Issue #43)
281
311
  * 0.7.0 Scopes
282
312
  * 0.6.6 ILIKE for postgres
@@ -0,0 +1 @@
1
+ --colour
data/integration/Gemfile CHANGED
@@ -5,6 +5,8 @@ gem 'rails', '~>3.0.3'
5
5
  gem 'annotate'
6
6
  gem 'capybara', '~>0.4.0'
7
7
  gem 'cucumber-rails', '~>0.3.2'
8
+ gem 'rspec-rails'
9
+ gem 'steak'
8
10
  gem 'database_cleaner'
9
11
  gem 'haml-rails'
10
12
  gem 'jquery-rails'
@@ -0,0 +1,2 @@
1
+ Autotest.add_discovery { "rails" }
2
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require "steak"
3
+ require 'steak/autocomplete'
4
+
5
+ if defined?(ActiveRecord::Base)
6
+ begin
7
+ require 'database_cleaner'
8
+ DatabaseCleaner.strategy = :truncation
9
+ rescue LoadError => ignore_if_database_cleaner_not_present
10
+ end
11
+ end
12
+
13
+ # Put your acceptance spec helpers inside /spec/acceptance/support
14
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
+
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
2
+
3
+ feature "Autocomplete", %q{
4
+ In order to do funky stuff
5
+ As a User
6
+ I want autocomplete!
7
+ } do
8
+
9
+ background do
10
+ enable_javascript
11
+ lambda do
12
+ Brand.create! [
13
+ { :name => "Alpha" , :state => true },
14
+ { :name => "Beta" , :state => false },
15
+ { :name => "Gamma" , :state => false },
16
+ { :name => "Kappa" , :state => true },
17
+ { :name => "Kappler" , :state => false }
18
+ ]
19
+ end.should change(Brand, :count).by(5)
20
+ lambda { Feature.create! [{:name => "Shiny"}, {:name => "Glowy"}] }.should change(Feature, :count).by(2)
21
+ end
22
+
23
+ context "Autocomplete" do
24
+ scenario "Autocomplete" do
25
+ visit home_page
26
+ fill_in "Brand name", :with => "al"
27
+ choose_autocomplete_result "Alpha"
28
+ find_field("Brand name").value.should include("Alpha")
29
+ end
30
+
31
+ scenario "Autocomplete, id_element option" do
32
+ visit new_id_element_page
33
+ fill_in "Brand name", :with => "al"
34
+ choose_autocomplete_result "Alpha"
35
+ find_field("Brand name").value.should include("Alpha")
36
+ find_field("Brand").value.should include(Brand.find_by_name("Alpha").id.to_s)
37
+ end
38
+
39
+ scenario "Autocomplete for a sub class" do
40
+ lambda { ForeignBrand.create! :name => "Omega" }.should change(ForeignBrand, :count)
41
+
42
+ visit new_sub_class_page
43
+ fill_in "Brand name", :with => "om"
44
+ choose_autocomplete_result "Omega"
45
+ find_field("Brand name").value.should include("Omega")
46
+ end
47
+
48
+ scenario "Multiple autocomplete" do
49
+ visit new_multiple_section_page
50
+ send_to("Brand name", "al")
51
+ choose_autocomplete_result "Alpha"
52
+ send_to("Brand name", "bet")
53
+ choose_autocomplete_result "Beta"
54
+ find_field("Brand name").value.should include("Alpha,Beta")
55
+ end
56
+
57
+ scenario "Autocomplete for Nested Models" do
58
+ visit new_nested_model_page
59
+ send_to("Feature Name", "sh")
60
+ choose_autocomplete_result "Shiny"
61
+ find_field("Feature Name").value.should include("Glowy,Shiny")
62
+ end
63
+
64
+ scenario "Autocomplete for simple_form" do
65
+ visit new_simple_form_page
66
+ fill_in("Brand name", :with => "al")
67
+ choose_autocomplete_result "Alpha"
68
+ find_field("Brand name").value.should include("Alpha")
69
+ end
70
+
71
+ scenario "Autocomplete with scope" do
72
+ kappa_brand = Brand.find_by_name('Kappa')
73
+ kappa_brand.address = Address.create!
74
+ kappa_brand.save!
75
+ visit new_scoped_cutocomplete_page
76
+ fill_in("Brand name", :with => "ka")
77
+ choose_autocomplete_result "Kappa"
78
+ find_field("Brand name").value.should include("Kappa")
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,12 @@
1
+ module HelperMethods
2
+ def enable_javascript
3
+ Capybara.current_driver = :selenium
4
+ Capybara.default_wait_time = 1
5
+ end
6
+
7
+ def send_to(element, key)
8
+ find_field(element).native.send_keys(key)
9
+ end
10
+ end
11
+
12
+ RSpec.configuration.include HelperMethods, :type => :acceptance
@@ -0,0 +1,33 @@
1
+ module NavigationHelpers
2
+ # Put helper methods related to the paths in your application here.
3
+
4
+ def home_page
5
+ "/"
6
+ end
7
+
8
+ def new_id_element_page
9
+ "/id_elements/new"
10
+ end
11
+
12
+ def new_sub_class_page
13
+ "/sub_classes/new"
14
+ end
15
+
16
+ def new_multiple_section_page
17
+ "/multiple_selections/new"
18
+ end
19
+
20
+ def new_nested_model_page
21
+ "/nested_models/new"
22
+ end
23
+
24
+ def new_simple_form_page
25
+ "/simple_forms/new"
26
+ end
27
+
28
+ def new_scoped_cutocomplete_page
29
+ "/scoped_autocompletes/new"
30
+ end
31
+ end
32
+
33
+ RSpec.configuration.include NavigationHelpers, :type => :acceptance
@@ -0,0 +1,37 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'capybara'
6
+ require 'capybara/rails'
7
+ require "capybara/dsl"
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc,
10
+ # in spec/support/ and its subdirectories.
11
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ # == Mock Framework
15
+ #
16
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
17
+ #
18
+ # config.mock_with :mocha
19
+ # config.mock_with :flexmock
20
+ # config.mock_with :rr
21
+ config.mock_with :rspec
22
+
23
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
24
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
25
+
26
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
27
+ # examples within a transaction, remove the following line or assign false
28
+ # instead of true.
29
+ config.use_transactional_fixtures = false
30
+
31
+ config.include Capybara
32
+ config.after(:each) do
33
+ Capybara.reset_sessions!
34
+ Capybara.use_default_driver
35
+ DatabaseCleaner.clean
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
@@ -0,0 +1,12 @@
1
+ module Steak
2
+ module Autocomplete
3
+ def choose_autocomplete_result(text, input_id="input[data-autocomplete]")
4
+ page.execute_script %Q{ $('#{input_id}').trigger("focus") }
5
+ page.execute_script %Q{ $('#{input_id}').trigger("keydown") }
6
+ sleep 1
7
+ page.execute_script %Q{ $('.ui-menu-item a:contains("#{text}")').trigger("mouseenter").trigger("click"); }
8
+ end
9
+ end
10
+ end
11
+
12
+ RSpec.configuration.include Steak::Autocomplete, :type => :acceptance
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: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Padilla
@@ -126,6 +126,7 @@ files:
126
126
  - README.markdown
127
127
  - Rakefile
128
128
  - integration/.gitignore
129
+ - integration/.rspec
129
130
  - integration/Gemfile
130
131
  - integration/Gemfile.lock
131
132
  - integration/README
@@ -157,6 +158,7 @@ files:
157
158
  - integration/app/views/scoped_autocompletes/new.html.haml
158
159
  - integration/app/views/simple_forms/new.html.haml
159
160
  - integration/app/views/sub_classes/new.html.haml
161
+ - integration/autotest/discover.rb
160
162
  - integration/config.ru
161
163
  - integration/config/application.rb
162
164
  - integration/config/boot.rb
@@ -208,6 +210,11 @@ files:
208
210
  - integration/public/stylesheets/sass/application.sass
209
211
  - integration/script/cucumber
210
212
  - integration/script/rails
213
+ - integration/spec/acceptance/acceptance_helper.rb
214
+ - integration/spec/acceptance/autocomplete_spec.rb
215
+ - integration/spec/acceptance/support/helpers.rb
216
+ - integration/spec/acceptance/support/paths.rb
217
+ - integration/spec/spec_helper.rb
211
218
  - lib/cucumber/autocomplete.rb
212
219
  - lib/generators/autocomplete_generator.rb
213
220
  - lib/generators/templates/autocomplete-rails.js
@@ -218,6 +225,7 @@ files:
218
225
  - lib/rails3-jquery-autocomplete/helpers.rb
219
226
  - lib/rails3-jquery-autocomplete/simple_form_plugin.rb
220
227
  - lib/rails3-jquery-autocomplete/version.rb
228
+ - lib/steak/autocomplete.rb
221
229
  - rails3-jquery-autocomplete.gemspec
222
230
  - test/form_helper_test.rb
223
231
  - test/generators/generator_test.rb