diff --git a/integration/Gemfile b/integration/Gemfile index 7784530d..3ebc73f9 100644 --- a/integration/Gemfile +++ b/integration/Gemfile @@ -5,6 +5,7 @@ gem 'rails', '~> 3.0.10' gem 'annotate' gem 'capybara' gem 'cucumber-rails' +gem 'formtastic' #, path: '../../formtastic' gem 'rspec-rails' gem 'steak' gem 'database_cleaner' diff --git a/integration/Gemfile.lock b/integration/Gemfile.lock index 6d3e7612..8a6e71bf 100644 --- a/integration/Gemfile.lock +++ b/integration/Gemfile.lock @@ -62,6 +62,10 @@ GEM erubis (2.6.6) abstract (>= 1.0.0) ffi (1.0.9) + formtastic (1.2.4) + actionpack (>= 2.3.7) + activesupport (>= 2.3.7) + i18n (~> 0.4) gherkin (2.4.15) json (>= 1.4.6) haml (3.1.2) @@ -157,6 +161,7 @@ DEPENDENCIES capybara cucumber-rails database_cleaner + formtastic haml-rails jquery-rails launchy diff --git a/integration/app/controllers/formtastics_controller.rb b/integration/app/controllers/formtastics_controller.rb new file mode 100644 index 00000000..1802de94 --- /dev/null +++ b/integration/app/controllers/formtastics_controller.rb @@ -0,0 +1,7 @@ +class FormtasticsController < ApplicationController + autocomplete :brand, :name + + def new + @product = Product.new + end +end diff --git a/integration/app/views/formtastics/new.html.haml b/integration/app/views/formtastics/new.html.haml new file mode 100644 index 00000000..7851b2c5 --- /dev/null +++ b/integration/app/views/formtastics/new.html.haml @@ -0,0 +1,9 @@ +%h1 Formtastic Autocomplete + += semantic_form_for @product do |form| + %p + = form.input :name + %p + = form.input :brand_name, :as => :autocomplete, :url => autocomplete_brand_name_formtastics_path + + diff --git a/integration/config/routes.rb b/integration/config/routes.rb index 9e183922..c926d66c 100644 --- a/integration/config/routes.rb +++ b/integration/config/routes.rb @@ -1,5 +1,7 @@ Integration::Application.routes.draw do + get "formtastics/new" + root :to => 'autocomplete#new' match 'autocomplete/autocomplete_brand_name' => 'autocomplete#autocomplete_brand_name' @@ -27,6 +29,10 @@ resources :scoped_autocompletes do get :autocomplete_brand_name, :on => :collection end + + resources :formtastics do + get :autocomplete_brand_name, :on => :collection + end end #== Route Map # Generated on 25 Apr 2011 09:55 diff --git a/integration/features/autocomplete.feature b/integration/features/autocomplete.feature index 4cdfec7a..c8ead6d2 100644 --- a/integration/features/autocomplete.feature +++ b/integration/features/autocomplete.feature @@ -71,3 +71,10 @@ Feature: Autocomplete And I fill in "Brand name" with "ka" And I choose "Kappa" in the autocomplete list Then the "Brand name" field should contain "Kappa" + + @javascript + Scenario: Autocomplete with Formtastic + Given I go to the new formtastic page + And I fill in "Brand name" with "al" + And I choose "Alpha" in the autocomplete list + Then the "Brand name" field should contain "Alpha" diff --git a/integration/spec/controllers/formtastics_controller_spec.rb b/integration/spec/controllers/formtastics_controller_spec.rb new file mode 100644 index 00000000..737d9180 --- /dev/null +++ b/integration/spec/controllers/formtastics_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe FormtasticsController do + + describe "GET 'new'" do + it "should be successful" do + get 'new' + response.should be_success + end + end + +end diff --git a/integration/spec/views/formtastics/new.html.haml_spec.rb b/integration/spec/views/formtastics/new.html.haml_spec.rb new file mode 100644 index 00000000..73cf189c --- /dev/null +++ b/integration/spec/views/formtastics/new.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "formtastics/new.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/lib/rails3-jquery-autocomplete/formtastic.rb b/lib/rails3-jquery-autocomplete/formtastic.rb index ee32a901..7231f89a 100644 --- a/lib/rails3-jquery-autocomplete/formtastic.rb +++ b/lib/rails3-jquery-autocomplete/formtastic.rb @@ -30,7 +30,7 @@ def to_html # # Formtastic 1.x # - class Formtastic::FormBuilder < ActionView::Helpers::FormBuilder + class Formtastic::SemanticFormBuilder < ActionView::Helpers::FormBuilder include Rails3JQueryAutocomplete::FormtasticPlugin end end diff --git a/lib/rails3-jquery-autocomplete/formtastic_plugin.rb b/lib/rails3-jquery-autocomplete/formtastic_plugin.rb index ff511a28..5ae88df7 100644 --- a/lib/rails3-jquery-autocomplete/formtastic_plugin.rb +++ b/lib/rails3-jquery-autocomplete/formtastic_plugin.rb @@ -1,6 +1,6 @@ module Rails3JQueryAutocomplete module FormtasticPlugin - def autocompleted_input(method, options = {}) + def autocomplete_input(method, options = {}) if options.key?(:selected) || options.key?(:checked) || options.key?(:default) ::ActiveSupport::Deprecation.warn( "The :selected, :checked (and :default) options are deprecated in Formtastic and will be removed from 1.0. " << @@ -8,13 +8,14 @@ def autocompleted_input(method, options = {}) "See http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html for more information.", caller) end + options[:required] = method_required?(method) unless options.key?(:required) options[:as] ||= "autocompleted_string" html_class = [ options[:as], (options[:required] ? :required : :optional) ] html_class << 'error' if @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank? wrapper_html = options.delete(:wrapper_html) || {} - # wrapper_html[:id] ||= generate_html_id(method) + wrapper_html[:id] ||= generate_html_id(method) wrapper_html[:class] = (html_class << wrapper_html[:class]).flatten.compact.join(' ') if options[:input_html] && options[:input_html][:id] @@ -22,8 +23,8 @@ def autocompleted_input(method, options = {}) options[:label_html][:for] ||= options[:input_html][:id] end - # input_parts = self.class.inline_order.dup - # input_parts = input_parts - [:errors, :hints] if options[:as] == :hidden + input_parts = self.class.inline_order.dup + input_parts = input_parts - [:errors, :hints] if options[:as] == :hidden list_item_content = input_parts.map do |type| send(:"inline_#{type}_for", method, options) @@ -32,6 +33,8 @@ def autocompleted_input(method, options = {}) return template.content_tag(:li, Formtastic::Util.html_safe(list_item_content), wrapper_html) end + alias_method :autocompleted_input, :autocomplete_input + protected def autocompleted_string_input(method, options)