forked from mjbellantoni/formtastic-bootstrap
/
buttons_helper_spec.rb
149 lines (112 loc) · 4.03 KB
/
buttons_helper_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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# encoding: utf-8
require 'spec_helper'
describe 'Formtastic::FormBuilder#buttons' do
include FormtasticSpecHelper
before do
@output_buffer = ''
mock_everything
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
end
describe 'with a block' do
describe 'when no options are provided' do
before do
concat(semantic_form_for(@new_post) do |builder|
buttons = builder.buttons do
concat('hello')
end
concat(buttons)
end)
end
it 'should render a div inside the form, with a class of "form-actions"' do
output_buffer.should have_tag("form div.form-actions")
end
it 'should not render an ol inside the div' do
output_buffer.should_not have_tag("form div.form-actions ol")
end
it 'should render the contents of the block inside the input' do
output_buffer.should have_tag("form div.form-actions", /hello/)
end
it 'should not render a legend inside the div' do
output_buffer.should_not have_tag("form div.form-actions legend")
end
end
describe 'when other options are provided' do
before do
@id_option = 'advanced'
@class_option = 'wide'
concat(semantic_form_for(@new_post) do |builder|
builder.buttons :id => @id_option, :class => @class_option do
end
end)
end
it 'should pass the options into the div tag as attributes' do
output_buffer.should have_tag("form div##{@id_option}")
output_buffer.should have_tag("form div.#{@class_option}")
end
end
end
describe 'without a block' do
describe 'with no args (default buttons)' do
before do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.buttons)
end)
end
it 'should render a form' do
output_buffer.should have_tag('form')
end
it 'should render a "form-actions" div inside the form' do
output_buffer.should have_tag('form div.form-actions')
end
it 'should not render a legend in the div' do
output_buffer.should_not have_tag('form div.form-actions legend')
end
it 'should render a button item in the ol for each default button' do
output_buffer.should have_tag('form div.form-actions input.btn', :count => 1)
end
it 'should render a commit list item for the commit button' do
output_buffer.should have_tag('form div.form-actions input.commit')
end
end
describe 'with button names as args' do
before do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit))
end)
end
it 'should render a form with a div containing an input for each button arg' do
output_buffer.should have_tag('form > div.form-actions > input', :count => 1)
output_buffer.should have_tag('form > div.form-actions > input.commit')
end
end
describe 'with :names' do
before do
ActiveSupport::Deprecation.should_receive(:warn)
concat(
semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit, :name => "Now click a button"))
end
)
end
it 'should warn that \':name\' is not supported' do
# Assertion is above in the before block.
end
end
describe 'with button names and an options hash' do
before do
concat(
semantic_form_for(@new_post) do |builder|
concat(builder.buttons(:commit, :id => "my-id"))
end
)
end
it 'should render a form with a div containing a input for each button arg' do
output_buffer.should have_tag('form > div.form-actions > input', :count => 1)
output_buffer.should have_tag('form > div.form-actions > input.commit', :count => 1)
end
it 'should pass the options down to the div' do
output_buffer.should have_tag('form > div#my-id.form-actions')
end
end
end
end