Skip to content

Commit 34f1663

Browse files
author
Matthew Bellantoni
committed
Implement DatetimeSelectInput.
1 parent 59cd046 commit 34f1663

File tree

3 files changed

+130
-11
lines changed

3 files changed

+130
-11
lines changed

lib/formtastic-bootstrap/inputs.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
module FormtasticBootstrap
22
module Inputs
33

4-
autoload :Base, "formtastic-bootstrap/inputs/base"
4+
autoload :Base, "formtastic-bootstrap/inputs/base"
55
# autoload :Basic
6-
autoload :BooleanInput, "formtastic-bootstrap/inputs/boolean_input"
7-
autoload :CheckBoxesInput, "formtastic-bootstrap/inputs/check_boxes_input"
8-
# autoload :CountryInput # Come back to this.
9-
autoload :DateInput, "formtastic-bootstrap/inputs/date_input"
10-
# autoload :DatePickerInput # Come back to this.
6+
autoload :BooleanInput, "formtastic-bootstrap/inputs/boolean_input"
7+
autoload :CheckBoxesInput, "formtastic-bootstrap/inputs/check_boxes_input"
8+
# autoload :CountryInput # Come back to this.
9+
autoload :DateInput, "formtastic-bootstrap/inputs/date_input"
10+
# autoload :DatePickerInput # Come back to this.
1111
# autoload :DatetimePickerInput
12-
autoload :DateSelectInput, "formtastic-bootstrap/inputs/date_select_input"
13-
autoload :DatetimeInput, "formtastic-bootstrap/inputs/datetime_input"
14-
# autoload :DatetimeSelectInput
12+
autoload :DateSelectInput, "formtastic-bootstrap/inputs/date_select_input"
13+
autoload :DatetimeInput, "formtastic-bootstrap/inputs/datetime_input"
14+
autoload :DatetimeSelectInput, "formtastic-bootstrap/inputs/datetime_select_input"
1515
# autoload :EmailInput
1616
# autoload :FileInput
1717
# autoload :HiddenInput
@@ -23,9 +23,9 @@ module Inputs
2323
# autoload :RangeInput
2424
# autoload :SearchInput
2525
# autoload :SelectInput
26-
autoload :StringInput, "formtastic-bootstrap/inputs/string_input"
26+
autoload :StringInput, "formtastic-bootstrap/inputs/string_input"
2727
# autoload :TextInput
28-
autoload :TimeInput, "formtastic-bootstrap/inputs/time_input"
28+
autoload :TimeInput, "formtastic-bootstrap/inputs/time_input"
2929
# autoload :TimePickerInput
3030
# autoload :TimeSelectInput
3131
# autoload :TimeZoneInput
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module FormtasticBootstrap
2+
module Inputs
3+
class DatetimeSelectInput < Formtastic::Inputs::DatetimeSelectInput
4+
include Base
5+
include Base::Timeish
6+
end
7+
end
8+
end
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)