Permalink
Browse files

Base form helper and builder.

  • Loading branch information...
1 parent a7d0cc2 commit 27f050b9494c6a91bc9dc936c3b33884c41b442d @carlosantoniodasilva carlosantoniodasilva committed Nov 18, 2009
Showing with 86 additions and 14 deletions.
  1. +0 −9 README.rdoc
  2. +1 −1 init.rb
  3. +2 −1 lib/simple_form.rb
  4. +4 −0 lib/simple_form/form_builder.rb
  5. +12 −0 lib/simple_form/form_helper.rb
  6. +44 −1 test/simple_form_test.rb
  7. +23 −2 test/test_helper.rb
View
@@ -7,14 +7,5 @@ Forms made easy!
Please refer to TODO file.
-== Contributors
-
-* José Valim (http://github.com/josevalim)
-* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
-
-== Bugs and Feedback
-
-If you discover any bugs or want to drop a line, feel free to create an issue on
-GitHub or send an e-mail to the mailing list.
MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
View
@@ -1 +1 @@
-# Include hook code here
+require 'simple_form'
View
@@ -1 +1,2 @@
-# SimpleForm
+require 'simple_form/form_helper'
+require 'simple_form/form_builder'
@@ -0,0 +1,4 @@
+module SimpleForm
+ class FormBuilder < ActionView::Helpers::FormBuilder
+ end
+end
@@ -0,0 +1,12 @@
+module SimpleForm
+ module FormHelper
+
+ def simple_form_for(*args, &block)
+ options = args.extract_options!
+ options[:builder] = SimpleForm::FormBuilder
+ form_for(*(args << options), &block)
+ end
+ end
+end
+
+ActionView::Base.send :include, SimpleForm::FormHelper
View
@@ -1,5 +1,48 @@
require 'test_helper'
-class SimpleFormTest < ActiveSupport::TestCase
+class MockController
+ def url_for(*args)
+ "http://example.com"
+ end
+end
+
+class MockResponse
+
+ def initialize(test_case)
+ @test_case = test_case
+ end
+
+ def content_type
+ 'text/html'
+ end
+
+ def body
+ @test_case.send :output_buffer
+ end
+end
+
+class SimpleFormTest < ActionView::TestCase
+ tests SimpleForm::FormHelper
+
+ def protect_against_forgery?
+ false
+ end
+
+ def setup
+ @controller = MockController.new
+ @response = MockResponse.new(self)
+ end
+
+ test 'yields an instance of FormBuilder' do
+ simple_form_for :product do |f|
+ assert f.instance_of?(SimpleForm::FormBuilder)
+ end
+ end
+
+ test 'pass options to simple form' do
+ simple_form_for :product, :url => '/products', :html => { :id => 'my_form' } do |f| end
+ assert_select 'form#my_form'
+ assert_select 'form[action=/products]'
+ end
end
View
@@ -1,3 +1,24 @@
+#ENV["RAILS_ENV"] = "test"
require 'rubygems'
-require 'active_support'
-require 'active_support/test_case'
+require 'test/unit'
+
+require 'action_controller'
+require 'action_view/test_case'
+
+require File.join(File.dirname(__FILE__), '..', 'lib', 'simple_form')
+
+#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+#ActionController::Base.logger = nil
+#ActionController::Routing::Routes.reload rescue nil
+#ActionController::Base.session_store = nil
+
+#FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
+#ActionView::Base.cache_template_loading = true
+#ActionController::Base.view_paths = FIXTURE_LOAD_PATH
+
+
+#class ActiveSupport::TestCase
+# self.use_transactional_fixtures = true
+# self.use_instantiated_fixtures = false
+#end

0 comments on commit 27f050b

Please sign in to comment.