Sha256: 3cc544b12bf1fa1e02420a0021361d0f6962b829e220392056209bf57312181c

Contents?: true

Size: 1.68 KB

Versions: 22

Compression:

Stored size: 1.68 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 = ''
    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

22 entries across 22 versions & 5 rubygems

Version Path
formtastic-1.0.1 spec/custom_builder_spec.rb
formtastic-1.0.0 spec/custom_builder_spec.rb
formtastic-1.0.0.rc2 spec/custom_builder_spec.rb
formtastic-1.0.0.rc spec/custom_builder_spec.rb
formtastic-1.0.0.beta4 spec/custom_builder_spec.rb
formtastic-rails3-0.9.10.1 spec/custom_builder_spec.rb
formtastic-1.0.0.beta3 spec/custom_builder_spec.rb
formtastic-1.0.0.beta2 spec/custom_builder_spec.rb
formtastic-1.0.0.beta spec/custom_builder_spec.rb
formtastic-rails3-0.9.10.0 spec/custom_builder_spec.rb
formtastic-0.9.10 spec/custom_builder_spec.rb
formtastic-0.9.9 spec/custom_builder_spec.rb
formtastic-0.9.8 spec/custom_builder_spec.rb
jintastic-1.1.0 vendor/plugins/formtastic/spec/custom_builder_spec.rb
jintastic-1.0.2 vendor/plugins/formtastic/spec/custom_builder_spec.rb
tmayad-formtastic-0.9.7 spec/custom_builder_spec.rb
ShadowBelmolve-formtastic-0.9.7 spec/custom_builder_spec.rb
formtastic-0.9.7 spec/custom_builder_spec.rb
formtastic-0.9.6 spec/custom_builder_spec.rb
formtastic-0.9.5 spec/custom_builder_spec.rb