Sha256: 54f1132f90627ab911a4c289d1f167fcb4155b2537aaf3d64dba69f60953b14d

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

require 'formtastic'
require 'active_enum/form_helpers/formtastic'

describe 'ActiveEnum::FormHelpers::Formtastic' do
  include RSpec::Rails::HelperExampleGroup
  include Formtastic::SemanticFormHelper

  before do
    reset_class Person do
      enumerate :sex do
        value :id => 1, :name => 'Male'
        value :id => 2, :name => 'Female'
      end
    end
  end

  it "should use enum input type for enumerated attribute" do
    output = semantic_form_for(Person.new, :url => people_path) do |f|
      concat f.input(:sex)
    end
    output.should have_selector('select#person_sex')
    output.should have_xpath('//option[@value=1]', :content => 'Male')
    output.should have_xpath('//option[@value=2]', :content => 'Female')
  end

  it "should not use enum input type if :as option indicates other type" do
    output = semantic_form_for(Person.new, :url => people_path) do |f|
      concat f.input(:sex, :as => :string)
    end
    output.should have_selector('input#person_sex')
  end

  it "should raise error if attribute for enum input is not enumerated" do
    lambda {
      semantic_form_for(Person.new, :url => people_path) {|f| f.input(:attending, :as => :enum) }
    }.should raise_error "Attribute 'attending' has no enum class"
  end

  it "should not use enum input type if class does not support ActiveEnum" do
    output = semantic_form_for(:not_active_record, NotActiveRecord.new, :url => people_path) do |f|
      concat f.input(:name)
    end
    output.should have_selector('input#not_active_record_name')
  end

  def people_path
    '/people'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_enum-0.9.0 spec/active_enum/form_helpers/formtastic_spec.rb
active_enum-0.8.2 spec/active_enum/form_helpers/formtastic_spec.rb