This repository has been archived by the owner on Oct 12, 2019. It is now read-only.
/
time_zone_input_spec.rb
118 lines (92 loc) · 3.89 KB
/
time_zone_input_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# encoding: utf-8
require 'spec_helper'
describe 'time_zone input' do
include FormtasticSpecHelper
before do
@output_buffer = ''
mock_everything
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:time_zone))
end)
end
it_should_have_bootstrap_horizontal_wrapping
it_should_have_input_wrapper_with_class("time_zone")
it_should_have_input_wrapper_with_class(:input)
it_should_have_input_wrapper_with_id("post_time_zone_input")
it_should_apply_error_logic_for_input_type(:time_zone)
it 'should generate a label for the input' do
output_buffer.should have_tag('form div.form-group label.control-label')
output_buffer.should have_tag('form div.form-group label.control-label[@for="post_time_zone"]')
output_buffer.should have_tag('form div.form-group label.control-label', /Time zone/)
end
it "should generate a select" do
output_buffer.should have_tag("form div.form-group span.form-wrapper select")
output_buffer.should have_tag("form div.form-group span.form-wrapper select#post_time_zone")
output_buffer.should have_tag("form div.form-group span.form-wrapper select[@name=\"post[time_zone]\"]")
end
it 'should use input_html to style inputs' do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
end)
output_buffer.should have_tag("form div.form-group span.form-wrapper select.myclass")
end
describe "when namespace is provided" do
before do
@output_buffer = ''
mock_everything
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
concat(builder.input(:time_zone))
end)
end
it_should_have_input_wrapper_with_id("context2_post_time_zone_input")
it_should_have_select_with_id("context2_post_time_zone")
it_should_have_label_for("context2_post_time_zone")
end
describe "when index is provided" do
before do
@output_buffer = ''
mock_everything
concat(semantic_form_for(@new_post) do |builder|
concat(builder.fields_for(:author, :index => 3) do |author|
concat(author.input(:name, :as => :time_zone))
end)
end)
end
it 'should index the id of the control group' do
output_buffer.should have_tag("div.form-group#post_author_attributes_3_name_input")
end
it 'should index the id of the select tag' do
output_buffer.should have_tag("select#post_author_attributes_3_name")
end
it 'should index the name of the select tag' do
output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
end
end
describe 'when no object is given' do
before(:each) do
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
concat(builder.input(:time_zone, :as => :time_zone))
end)
end
it 'should generate labels' do
output_buffer.should have_tag('form div.form-group label.control-label')
output_buffer.should have_tag('form div.form-group label.control-label[@for="project_time_zone"]')
output_buffer.should have_tag('form div.form-group label.control-label', /Time zone/)
end
it 'should generate select inputs' do
output_buffer.should have_tag("form div.form-group span.form-wrapper select")
output_buffer.should have_tag("form div.form-group span.form-wrapper select#project_time_zone")
output_buffer.should have_tag("form div.form-group span.form-wrapper select[@name=\"project[time_zone]\"]")
end
end
context "when required" do
it "should add the required attribute to the input's html options" do
with_config :use_required_attribute, true do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :time_zone, :required => true))
end)
output_buffer.should have_tag("select[@required]")
end
end
end
end