Sha256: baa8b78745a3f2d21c5437e541e8cd4a537f8cb03952ae1252260d122dddf471

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

# coding: utf-8
require File.dirname(__FILE__) + '/test_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 = ''
    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

2 entries across 2 versions & 2 rubygems

Version Path
lperichon-formtastic-0.9.2 spec/custom_builder_spec.rb
formtastic-0.9.1 spec/custom_builder_spec.rb