Sha256: a74bd8e12339a1ab4e5d2f30a5f4f143f06d5291ea35797687dd36a62c71adc6

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 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 class for select option values for enum input type" do
    output = semantic_form_for(Person.new, :url => people_path) do |f|
      concat f.input(:sex, :as => :enum)
    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 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

  def people_path
    '/people'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_enum-0.7.0 spec/active_enum/form_helpers/formtastic_spec.rb