Sha256: efa07fcafcd25a3e1279bc439c7d810c9a4cbfeaa29a23574c19f7cb462f60b1

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

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

describe 'date input' do
  
  include FormtasticSpecHelper
  
  before do
    @output_buffer = ''
    mock_everything
    
    semantic_form_for(@new_post) do |builder|
      concat(builder.input(:publish_at, :as => :date))
    end
  end

  it_should_have_input_wrapper_with_class("date")
  it_should_have_input_wrapper_with_id("post_publish_at_input")
  it_should_have_a_nested_fieldset
  it_should_apply_error_logic_for_input_type(:date)
  
  it 'should have a legend - classified as a label - containing the label text inside the fieldset' do
    output_buffer.should have_tag('form li.date fieldset legend.label', /Publish at/)
  end

  it 'should have an ordered list of three items inside the fieldset' do
    output_buffer.should have_tag('form li.date fieldset ol')
    output_buffer.should have_tag('form li.date fieldset ol li', :count => 3)
  end

  it 'should have three labels for year, month and day' do
    output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
    output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
    output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
    output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
  end

  it 'should have three selects for year, month and day' do
    output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
  end

  it_should_select_existing_datetime_else_current(:year, :month, :day)
  it_should_select_explicit_default_value_if_set(:year, :month, :day)
  
  describe "when :selected is nil" do
    
    before(:each) do
      output_buffer.replace ''
      semantic_form_for(:project, :url => 'http://test.host') do |builder|
        concat(builder.input(:publish_at, :as => :datetime, :selected => nil))
      end
    end
    
    it "should not pre-select any options" do
      output_buffer.should_not have_tag("form li.datetime li select option[@selected]")
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jintastic-1.1.0 vendor/plugins/formtastic/spec/inputs/date_input_spec.rb
jintastic-1.0.2 vendor/plugins/formtastic/spec/inputs/date_input_spec.rb