|
| 1 | +# encoding: utf-8 |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +describe 'datetime select input' do |
| 5 | + |
| 6 | + include FormtasticSpecHelper |
| 7 | + |
| 8 | + before do |
| 9 | + @output_buffer = '' |
| 10 | + mock_everything |
| 11 | + end |
| 12 | + |
| 13 | + describe "general" do |
| 14 | + |
| 15 | + before do |
| 16 | + ::I18n.backend.store_translations :en, {} |
| 17 | + output_buffer.replace '' |
| 18 | + concat(semantic_form_for(@new_post) do |builder| |
| 19 | + concat(builder.input(:publish_at, :as => :datetime_select)) |
| 20 | + end) |
| 21 | + end |
| 22 | + |
| 23 | + it_should_have_input_wrapper_with_class("datetime_select") |
| 24 | + it_should_have_input_wrapper_with_class(:input) |
| 25 | + it_should_have_input_wrapper_with_id("post_publish_at_input") |
| 26 | + it_should_apply_error_logic_for_input_type(:datetime_select) |
| 27 | + |
| 28 | + it 'should have a legend and label with the label text inside the fieldset' do |
| 29 | + output_buffer.should have_tag('form div.control-group.datetime_select label.control-label', /Publish at/) |
| 30 | + end |
| 31 | + |
| 32 | + it 'should have five selects' do |
| 33 | + output_buffer.should have_tag('form div.control-group.datetime_select div.controls select', :count => 5) |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + describe "when namespace is provided" do |
| 38 | + |
| 39 | + before do |
| 40 | + output_buffer.replace '' |
| 41 | + concat(semantic_form_for(@new_post, :namespace => "context2") do |builder| |
| 42 | + concat(builder.input(:publish_at, :as => :datetime_select)) |
| 43 | + end) |
| 44 | + end |
| 45 | + |
| 46 | + it_should_have_input_wrapper_with_id("context2_post_publish_at_input") |
| 47 | + it_should_have_select_with_id("context2_post_publish_at_1i") |
| 48 | + it_should_have_select_with_id("context2_post_publish_at_2i") |
| 49 | + it_should_have_select_with_id("context2_post_publish_at_3i") |
| 50 | + it_should_have_select_with_id("context2_post_publish_at_4i") |
| 51 | + it_should_have_select_with_id("context2_post_publish_at_5i") |
| 52 | + |
| 53 | + end |
| 54 | + |
| 55 | + describe "when index is provided" do |
| 56 | + |
| 57 | + before do |
| 58 | + @output_buffer = '' |
| 59 | + mock_everything |
| 60 | + |
| 61 | + concat(semantic_form_for(@new_post) do |builder| |
| 62 | + concat(builder.fields_for(:author, :index => 3) do |author| |
| 63 | + concat(author.input(:created_at, :as => :datetime_select)) |
| 64 | + end) |
| 65 | + end) |
| 66 | + end |
| 67 | + |
| 68 | + it 'should index the id of the control-group' do |
| 69 | + output_buffer.should have_tag("div.control-group#post_author_attributes_3_created_at_input") |
| 70 | + end |
| 71 | + |
| 72 | + it 'should index the id of the select tag' do |
| 73 | + output_buffer.should have_tag("select#post_author_attributes_3_created_at_1i") |
| 74 | + output_buffer.should have_tag("select#post_author_attributes_3_created_at_2i") |
| 75 | + output_buffer.should have_tag("select#post_author_attributes_3_created_at_3i") |
| 76 | + output_buffer.should have_tag("select#post_author_attributes_3_created_at_4i") |
| 77 | + output_buffer.should have_tag("select#post_author_attributes_3_created_at_5i") |
| 78 | + end |
| 79 | + |
| 80 | + it 'should index the name of the select tag' do |
| 81 | + output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(1i)]']") |
| 82 | + output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(2i)]']") |
| 83 | + output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(3i)]']") |
| 84 | + output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(4i)]']") |
| 85 | + output_buffer.should have_tag("select[@name='post[author_attributes][3][created_at(5i)]']") |
| 86 | + end |
| 87 | + |
| 88 | + end |
| 89 | + |
| 90 | + |
| 91 | + describe ':labels option' do |
| 92 | + describe ':labels option' do |
| 93 | + it "should provide a message that :labels is not supported" do |
| 94 | + pending ':labels is not supported' |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + end |
| 99 | + |
| 100 | + describe "when required" do |
| 101 | + it "should add the required attribute to the input's html options" do |
| 102 | + with_config :use_required_attribute, true do |
| 103 | + concat(semantic_form_for(@new_post) do |builder| |
| 104 | + concat(builder.input(:title, :as => :datetime_select, :required => true)) |
| 105 | + end) |
| 106 | + output_buffer.should have_tag("select[@required]", :count => 5) |
| 107 | + end |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | +end |
0 commit comments