Sha256: b9b8c53c31c6f385c8d1807923470676c460514fbb0349f4f1e7b5fc91fd359a

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'

describe 'Formtastic::SemanticFormHelper.builder' do

  include FormtasticSpecHelper
  
  class MyCustomFormBuilder < ::Formtastic::SemanticFormBuilder
    def awesome_input(method, options)
      self.text_field(method)
    end
  end
  
  before do
    @output_buffer = ActiveSupport::SafeBuffer.new
    mock_everything
  end
  
  it 'is the Formtastic::SemanticFormBuilder by default' do
    ::Formtastic::SemanticFormHelper.builder.should == ::Formtastic::SemanticFormBuilder
  end
  
  it 'can be configured to use your own custom form builder' do
    # Set it to a custom builder class
    ::Formtastic::SemanticFormHelper.builder = MyCustomFormBuilder
    ::Formtastic::SemanticFormHelper.builder.should == MyCustomFormBuilder
    
    # Reset it to the default
    ::Formtastic::SemanticFormHelper.builder = ::Formtastic::SemanticFormBuilder
    ::Formtastic::SemanticFormHelper.builder.should == ::Formtastic::SemanticFormBuilder
  end
  
  describe "when using a custom builder" do
    
    before do
      @new_post.stub!(:title)
      ::Formtastic::SemanticFormHelper.builder = MyCustomFormBuilder
    end
    
    after do
      ::Formtastic::SemanticFormHelper.builder = ::Formtastic::SemanticFormBuilder
    end
    
    describe "semantic_form_for" do
      
      it "should yeild and instance of the custom builder" do
        semantic_form_for(@new_post) do |builder|
          builder.class.should == MyCustomFormBuilder
        end
      end
      
      it "should allow me to call my custom input" do
        semantic_form_for(@new_post) do |builder|
          concat(builder.input(:title, :as => :awesome))
        end
      end
    
    end
    
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formtastic-rails3-0.9.7 spec/custom_builder_spec.rb