dynamic_fieldsets 0.0.16 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rdebugrc +3 -0
- data/.rspec +1 -0
- data/CHANGELOG +7 -0
- data/Gemfile +17 -8
- data/Gemfile.lock +77 -60
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/app/controllers/dynamic_fieldsets/fields_controller.rb +5 -4
- data/app/helpers/dynamic_fieldsets_helper.rb +48 -131
- data/app/models/dynamic_fieldsets.rb +2 -0
- data/app/models/dynamic_fieldsets/checkbox_field.rb +29 -0
- data/app/models/dynamic_fieldsets/date_field.rb +37 -0
- data/app/models/dynamic_fieldsets/datetime_field.rb +36 -0
- data/app/models/dynamic_fieldsets/dependency.rb +1 -1
- data/app/models/dynamic_fieldsets/dependency_clause.rb +1 -1
- data/app/models/dynamic_fieldsets/dependency_group.rb +1 -1
- data/app/models/dynamic_fieldsets/field.rb +170 -42
- data/app/models/dynamic_fieldsets/field_default.rb +3 -3
- data/app/models/dynamic_fieldsets/field_html_attribute.rb +1 -1
- data/app/models/dynamic_fieldsets/field_option.rb +1 -1
- data/app/models/dynamic_fieldsets/field_record.rb +1 -1
- data/app/models/dynamic_fieldsets/fieldset.rb +36 -1
- data/app/models/dynamic_fieldsets/fieldset_associator.rb +9 -34
- data/app/models/dynamic_fieldsets/fieldset_child.rb +43 -24
- data/app/models/dynamic_fieldsets/instruction_field.rb +35 -0
- data/app/models/dynamic_fieldsets/multiple_select_field.rb +43 -0
- data/app/models/dynamic_fieldsets/radio_field.rb +27 -0
- data/app/models/dynamic_fieldsets/select_field.rb +16 -0
- data/app/models/dynamic_fieldsets/text_field.rb +14 -0
- data/app/models/dynamic_fieldsets/textarea_field.rb +40 -0
- data/app/views/dynamic_fieldsets/fields/_form.html.erb +50 -52
- data/app/views/dynamic_fieldsets/fields/edit.html.erb +5 -2
- data/app/views/dynamic_fieldsets/fields/index.html.erb +1 -1
- data/app/views/dynamic_fieldsets/fields/new.html.erb +3 -1
- data/app/views/dynamic_fieldsets/fields/show.html.erb +1 -1
- data/app/views/dynamic_fieldsets/fieldsets/_child.html.erb +1 -1
- data/app/views/dynamic_fieldsets/form_partials/_checkbox_field.html.erb +8 -0
- data/app/views/dynamic_fieldsets/form_partials/_date_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_datetime_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_input_footer.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_input_header.html.erb +7 -0
- data/app/views/dynamic_fieldsets/form_partials/_instruction_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_multiple_select_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_radio_field.html.erb +8 -0
- data/app/views/dynamic_fieldsets/form_partials/_select_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_text_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/form_partials/_textarea_field.html.erb +1 -0
- data/app/views/dynamic_fieldsets/shared/_javascript_watcher.html.erb +8 -8
- data/app/views/dynamic_fieldsets/show_partials/_show_incomplete.html.erb +1 -0
- data/app/views/dynamic_fieldsets/show_partials/_show_incomplete_footer.html.erb +2 -0
- data/app/views/dynamic_fieldsets/show_partials/_show_incomplete_header.html.erb +1 -0
- data/app/views/dynamic_fieldsets/show_partials/_show_instruction.html.erb +1 -0
- data/app/views/dynamic_fieldsets/show_partials/_show_multiple_answers.html.erb +13 -0
- data/app/views/dynamic_fieldsets/show_partials/_show_single_answer.html.erb +8 -0
- data/autotest/discover.rb +2 -0
- data/dynamic_fieldsets.gemspec +74 -20
- data/lib/dynamic_fieldsets/config.rb +45 -0
- data/lib/dynamic_fieldsets/dynamic_fieldsets_in_model.rb +38 -63
- data/lib/dynamic_fieldsets/field_with_field_options.rb +58 -0
- data/lib/dynamic_fieldsets/field_with_multiple_answers.rb +89 -0
- data/lib/dynamic_fieldsets/field_with_single_answer.rb +84 -0
- data/lib/dynamic_fieldsets/railtie.rb +6 -1
- data/lib/generators/dynamic_fieldsets/install_generator.rb +3 -3
- data/lib/generators/dynamic_fieldsets/templates/config.rb +15 -0
- data/lib/generators/dynamic_fieldsets/templates/migrations/install_migration.rb +1 -1
- data/spec/dummy/config/initializers/dynamic_fieldsets.rb +15 -0
- data/spec/dummy/db/migrate/20120213211033_create_dynamic_fieldsets_tables.rb +1 -1
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/features/step_definitions/field_steps.rb +4 -4
- data/spec/dummy/features/step_definitions/fieldset_children_steps.rb +2 -2
- data/spec/dummy/features/step_definitions/javascript_steps.rb +7 -7
- data/spec/dynamic_fieldsets_helper_spec.rb +278 -312
- data/spec/dynamic_fieldsets_in_model_spec.rb +2 -2
- data/spec/field_with_field_options_spec.rb +49 -0
- data/spec/field_with_multiple_answers_spec.rb +50 -0
- data/spec/field_with_single_answer_spec.rb +51 -0
- data/spec/models/checkbox_field_spec.rb +19 -0
- data/spec/models/date_field_spec.rb +24 -0
- data/spec/models/datetime_field_spec.rb +24 -0
- data/spec/models/dependency_clause_spec.rb +7 -8
- data/spec/models/dependency_group_spec.rb +27 -30
- data/spec/models/dependency_spec.rb +8 -9
- data/spec/models/field_default_spec.rb +19 -14
- data/spec/models/field_html_attribute_spec.rb +3 -4
- data/spec/models/field_option_spec.rb +8 -9
- data/spec/models/field_record_spec.rb +8 -9
- data/spec/models/field_spec.rb +195 -94
- data/spec/models/fieldset_associator_spec.rb +39 -41
- data/spec/models/fieldset_child_spec.rb +99 -47
- data/spec/models/fieldset_spec.rb +25 -29
- data/spec/models/instruction_field_spec.rb +38 -0
- data/spec/models/multiple_select_field_spec.rb +31 -0
- data/spec/models/radio_field_spec.rb +21 -0
- data/spec/models/text_field_spec.rb +19 -0
- data/spec/models/textarea_field_spec.rb +39 -0
- data/spec/support/field_helper.rb +1 -1
- metadata +106 -28
|
@@ -6,295 +6,267 @@ describe DynamicFieldsetsHelper do
|
|
|
6
6
|
include DynamicFieldsetsHelper
|
|
7
7
|
include FieldsetHelper
|
|
8
8
|
|
|
9
|
-
describe "
|
|
10
|
-
before(:each) do
|
|
11
|
-
@fsa = mock_model(FieldsetAssociator)
|
|
12
|
-
@fsa.stub!(:id).and_return(2)
|
|
13
|
-
@fsa.stub!(:fieldset).and_return mock_model(Fieldset)
|
|
14
|
-
@fsa.stub!(:fieldset_id).and_return(1)
|
|
15
|
-
@fsa.stub!(:fieldset_model_name).and_return("Turkey")
|
|
16
|
-
@fsa.stub!(:field_values).and_return []
|
|
17
|
-
stub!(:fieldset_renderer).and_return []
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should include a form object and a field set associator object" do
|
|
21
|
-
lambda { dynamic_fieldset_renderer(@fsa, "form") }.should_not raise_error
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should call the fieldset_renderer with the fsa's root fieldset" do
|
|
25
|
-
@fsa.should_receive(:fieldset)
|
|
26
|
-
dynamic_fieldset_renderer(@fsa, "form")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should return a string of html" do
|
|
30
|
-
dynamic_fieldset_renderer(@fsa, "form").should be_a_kind_of String
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe "dynamic_fieldset_form_renderer method" do
|
|
35
|
-
it "should call dynamic_fieldset_renderer with 'form'" do
|
|
36
|
-
pending 'hex is working on this'
|
|
37
|
-
fsa = mock_model(FieldsetAssociator)
|
|
38
|
-
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "form")
|
|
39
|
-
dynamic_fieldset_form_renderer(fsa)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "dynamic_fieldset_show_renderer" do
|
|
44
|
-
it "should call dynamic_fieldset_renderer with 'show'" do
|
|
45
|
-
fsa = mock_model(FieldsetAssociator)
|
|
46
|
-
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "show")
|
|
47
|
-
dynamic_fieldset_show_renderer(fsa)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe ".fieldset_renderer" do
|
|
52
|
-
before(:each) do
|
|
53
|
-
@fsa = mock_model(FieldsetAssociator)
|
|
54
|
-
@fieldset = Fieldset.new
|
|
55
|
-
@fieldset.stub!(:id).and_return 326
|
|
56
|
-
@values = {}
|
|
57
|
-
@form_type = "form"
|
|
58
|
-
DynamicFieldsets::FieldsetChild.stub!(:where).and_return( [mock_model(FieldsetChild)] )
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should include the fsa object, fieldset object, and a values hash" do
|
|
62
|
-
lambda { fieldset_renderer(@fsa,@fieldset,@values, @form_type) }.should_not raise_error
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should call the children method on the fieldset object" do
|
|
66
|
-
@fieldset.should_receive(:children).and_return []
|
|
67
|
-
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "should call the field_renderer method if the current child is a field" do
|
|
71
|
-
@field = mock_model(Field)
|
|
72
|
-
@fieldset.stub!(:children).and_return [@field]
|
|
73
|
-
self.should_receive(:field_renderer).and_return []
|
|
74
|
-
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should call the fieldset_renderer recursively if the current child is a fieldset" do
|
|
78
|
-
@child_fieldset = mock_model(Fieldset)
|
|
79
|
-
@fieldset.stub!(:children).and_return [@child_fieldset]
|
|
80
|
-
self.should_receive(:fieldset_renderer)
|
|
81
|
-
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "should include markup for the fieldset itself" do
|
|
85
|
-
fieldset_renderer(@fsa,@fieldset,@values, @form_type).join.should match /id=["']fieldset-326["']/
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "should return an array of html elements" do
|
|
89
|
-
fieldset_renderer(@fsa,@fieldset,@values, @form_type).should be_a_kind_of Array
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
describe ".field_form_renderer appends html attributes to the field element" do
|
|
9
|
+
describe "field_renderer method" do
|
|
94
10
|
before(:each) do
|
|
95
11
|
@fsa = mock_model FieldsetAssociator
|
|
96
|
-
@field = Field.new
|
|
97
12
|
@fieldset_child = mock_model FieldsetChild
|
|
98
|
-
@fieldset_child.stub!(:child).and_return @field
|
|
99
|
-
@fieldset_child.stub!(:id).and_return 200
|
|
100
|
-
|
|
101
|
-
@field.stub!(:id).and_return 420
|
|
102
|
-
@field.stub!(:has_default?).and_return false
|
|
103
|
-
@field.stub!(:default).and_return ""
|
|
104
|
-
@field.stub!(:options).and_return []
|
|
105
13
|
@values = []
|
|
106
|
-
@htmlattr = mock_model FieldHtmlAttribute
|
|
107
|
-
@htmlattr.stub!(:attribute_name).and_return 'class'
|
|
108
|
-
@htmlattr.stub!(:value).and_return 'test'
|
|
109
|
-
@field.stub!(:field_html_attributes).and_return [@htmlattr]
|
|
110
|
-
@option = mock_model FieldOption
|
|
111
|
-
@option.stub!(:name).and_return 'option1'
|
|
112
14
|
end
|
|
113
15
|
|
|
114
|
-
it "
|
|
115
|
-
|
|
116
|
-
@
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
it "
|
|
120
|
-
|
|
121
|
-
@
|
|
122
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
123
|
-
end
|
|
124
|
-
it "successfully for fieldtype select" do
|
|
125
|
-
@field.stub!(:field_type).and_return 'select'
|
|
126
|
-
@field.stub!(:options).and_return [@option]
|
|
127
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
128
|
-
end
|
|
129
|
-
it "successfully for fieldtype multiple_select" do
|
|
130
|
-
@field.stub!(:field_type).and_return 'multiple_select'
|
|
131
|
-
@field.stub!(:options).and_return [@option]
|
|
132
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
133
|
-
end
|
|
134
|
-
it "successfully for fieldtype textfield" do
|
|
135
|
-
@field.stub!(:field_type).and_return 'textfield'
|
|
136
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
137
|
-
end
|
|
138
|
-
it "successfully for fieldtype textarea" do
|
|
139
|
-
@field.stub!(:field_type).and_return 'textarea'
|
|
140
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
141
|
-
end
|
|
142
|
-
it "successfully for fieldtype date" do
|
|
143
|
-
@field.stub!(:field_type).and_return 'date'
|
|
144
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
145
|
-
end
|
|
146
|
-
it "successfully for fieldtype datetime" do
|
|
147
|
-
@field.stub!(:field_type).and_return 'datetime'
|
|
148
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
16
|
+
it "should call the form helper if the form_type is form" do
|
|
17
|
+
self.should_receive(:field_form_renderer)
|
|
18
|
+
field_renderer(@fsa, @fieldset_child, @values, "form")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should default to the show helper if the form_type is not form" do
|
|
22
|
+
self.should_receive(:field_show_renderer)
|
|
23
|
+
field_renderer(@fsa, @fieldset_child, @values, "show")
|
|
149
24
|
end
|
|
150
25
|
end
|
|
151
|
-
|
|
152
|
-
describe "
|
|
26
|
+
|
|
27
|
+
describe "field_show_renderer method" do
|
|
153
28
|
before(:each) do
|
|
154
|
-
|
|
155
|
-
@child_id = 365
|
|
29
|
+
pending "This was significantly refactored"
|
|
156
30
|
@fsa = mock_model FieldsetAssociator
|
|
157
31
|
@field = Field.new
|
|
158
32
|
@fieldset_child = mock_model FieldsetChild
|
|
159
33
|
@fieldset_child.stub!(:child).and_return @field
|
|
160
|
-
@fieldset_child.stub!(:id).and_return
|
|
161
|
-
@field.stub!(:id).and_return @field_id
|
|
162
|
-
@field.stub!(:has_default?).and_return false
|
|
163
|
-
@field.stub!(:default).and_return ""
|
|
164
|
-
@field.stub!(:options).and_return []
|
|
34
|
+
@fieldset_child.stub!(:id).and_return 420
|
|
165
35
|
@values = []
|
|
166
|
-
@htmlattr = mock_model FieldHtmlAttribute
|
|
167
|
-
@htmlattr.stub!(:attribute_name).and_return 'class'
|
|
168
|
-
@htmlattr.stub!(:value).and_return 'test'
|
|
169
|
-
@field.stub!(:field_html_attributes).and_return [@htmlattr]
|
|
170
|
-
@option = mock_model FieldOption
|
|
171
|
-
@option.stub!(:name).and_return 'option1'
|
|
172
36
|
end
|
|
173
|
-
|
|
174
|
-
it "
|
|
175
|
-
@
|
|
176
|
-
|
|
177
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
178
|
-
end
|
|
179
|
-
it "successfully for fieldtype checkbox" do
|
|
180
|
-
@field.stub!(:field_type).and_return 'checkbox'
|
|
181
|
-
@field.stub!(:options).and_return [@option]
|
|
182
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
183
|
-
end
|
|
184
|
-
it "successfully for fieldtype select" do
|
|
185
|
-
@field.stub!(:field_type).and_return 'select'
|
|
186
|
-
@field.stub!(:options).and_return [@option]
|
|
187
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
188
|
-
end
|
|
189
|
-
it "successfully for fieldtype multiple_select" do
|
|
190
|
-
@field.stub!(:field_type).and_return 'multiple_select'
|
|
191
|
-
@field.stub!(:options).and_return [@option]
|
|
192
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
193
|
-
end
|
|
194
|
-
it "successfully for fieldtype textfield" do
|
|
195
|
-
@field.stub!(:field_type).and_return 'textfield'
|
|
196
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
197
|
-
end
|
|
198
|
-
it "successfully for fieldtype textarea" do
|
|
199
|
-
@field.stub!(:field_type).and_return 'textarea'
|
|
200
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
201
|
-
end
|
|
202
|
-
it "successfully for fieldtype date" do
|
|
203
|
-
@field.stub!(:field_type).and_return 'date'
|
|
204
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
205
|
-
end
|
|
206
|
-
it "successfully for fieldtype datetime" do
|
|
207
|
-
@field.stub!(:field_type).and_return 'datetime'
|
|
208
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /id=["']field-#{@field_id}-child-#{@child_id}["']/
|
|
37
|
+
|
|
38
|
+
it "should return an array of strings" do
|
|
39
|
+
result = field_show_renderer(@fsa, @fieldset_child, @values)
|
|
40
|
+
result.should be_a_kind_of Array
|
|
209
41
|
end
|
|
210
|
-
end
|
|
211
42
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
@fsa = mock_model FieldsetAssociator
|
|
215
|
-
@field = Field.new
|
|
216
|
-
@fieldset_child = mock_model FieldsetChild
|
|
217
|
-
@fieldset_child.stub!(:child).and_return @field
|
|
218
|
-
@fieldset_child.stub!(:id).and_return 300
|
|
219
|
-
@field.stub!(:id).and_return 420
|
|
220
|
-
@field.stub!(:html_attributes).and_return []
|
|
221
|
-
@field.stub!(:has_default?).and_return false
|
|
222
|
-
@field.stub!(:default).and_return ""
|
|
223
|
-
@field.stub!(:field_type).and_return ""
|
|
224
|
-
@field.stub!(:options).and_return []
|
|
225
|
-
@values = []
|
|
43
|
+
it "should include the class field" do
|
|
44
|
+
field_show_renderer(@fsa, @fieldset_child, @values).join.should match(/field/)
|
|
226
45
|
end
|
|
227
|
-
|
|
228
|
-
it "
|
|
229
|
-
|
|
46
|
+
|
|
47
|
+
it "should include the class label" do
|
|
48
|
+
field_show_renderer(@fsa, @fieldset_child, @values).join.should match(/label/)
|
|
230
49
|
end
|
|
231
50
|
|
|
232
|
-
it "
|
|
233
|
-
@
|
|
234
|
-
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
51
|
+
it "should include the class value" do
|
|
52
|
+
field_show_renderer(@fsa, @fieldset_child, @values).join.should match(/value/)
|
|
235
53
|
end
|
|
236
54
|
|
|
237
|
-
it "
|
|
238
|
-
@
|
|
239
|
-
@field.should_receive(:options)
|
|
240
|
-
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
55
|
+
it "should return 'No answer given' if the field has no answer for the current fieldset associator" do
|
|
56
|
+
field_show_renderer(@fsa, @fieldset_child, nil).join.should match(/No answer given/)
|
|
241
57
|
end
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "field_form_renderer" do
|
|
61
|
+
before do
|
|
62
|
+
pending "significant refactoring done here. probably all of these are trash now"
|
|
247
63
|
end
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
64
|
+
|
|
65
|
+
describe ".field_form_renderer appends html attributes to the field element" do
|
|
66
|
+
before(:each) do
|
|
67
|
+
@fsa = mock_model FieldsetAssociator
|
|
68
|
+
@field = Field.new
|
|
69
|
+
@fieldset_child = mock_model FieldsetChild
|
|
70
|
+
@fieldset_child.stub!(:child).and_return @field
|
|
71
|
+
@fieldset_child.stub!(:id).and_return 200
|
|
72
|
+
|
|
73
|
+
@field.stub!(:id).and_return 420
|
|
74
|
+
@field.stub!(:has_default?).and_return false
|
|
75
|
+
@field.stub!(:default).and_return ""
|
|
76
|
+
@field.stub!(:options).and_return []
|
|
77
|
+
@values = []
|
|
78
|
+
@htmlattr = mock_model FieldHtmlAttribute
|
|
79
|
+
@htmlattr.stub!(:attribute_name).and_return 'class'
|
|
80
|
+
@htmlattr.stub!(:value).and_return 'test'
|
|
81
|
+
@field.stub!(:field_html_attributes).and_return [@htmlattr]
|
|
82
|
+
@option = mock_model FieldOption
|
|
83
|
+
@option.stub!(:name).and_return 'option1'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "successfully for fieldtype radio" do
|
|
87
|
+
@field.stub!(:type).and_return 'radio'
|
|
88
|
+
@field.stub!(:options).and_return [@option]
|
|
89
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
90
|
+
end
|
|
91
|
+
it "successfully for fieldtype checkbox" do
|
|
92
|
+
@field.stub!(:type).and_return 'checkbox'
|
|
93
|
+
@field.stub!(:options).and_return [@option]
|
|
94
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
95
|
+
end
|
|
96
|
+
it "successfully for fieldtype select" do
|
|
97
|
+
@field.stub!(:type).and_return 'select'
|
|
98
|
+
@field.stub!(:options).and_return [@option]
|
|
99
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
100
|
+
end
|
|
101
|
+
it "successfully for fieldtype multiple_select" do
|
|
102
|
+
@field.stub!(:type).and_return 'multiple_select'
|
|
103
|
+
@field.stub!(:options).and_return [@option]
|
|
104
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
105
|
+
end
|
|
106
|
+
it "successfully for fieldtype textfield" do
|
|
107
|
+
@field.stub!(:type).and_return 'textfield'
|
|
108
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
109
|
+
end
|
|
110
|
+
it "successfully for fieldtype textarea" do
|
|
111
|
+
@field.stub!(:type).and_return 'textarea'
|
|
112
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
113
|
+
end
|
|
114
|
+
it "successfully for fieldtype date" do
|
|
115
|
+
@field.stub!(:type).and_return 'date'
|
|
116
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
117
|
+
end
|
|
118
|
+
it "successfully for fieldtype datetime" do
|
|
119
|
+
@field.stub!(:type).and_return 'datetime'
|
|
120
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/class=["']test["']/)
|
|
121
|
+
end
|
|
253
122
|
end
|
|
254
123
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
124
|
+
describe ".field_form_renderer appends the field id and child id attribute to the field element" do
|
|
125
|
+
before(:each) do
|
|
126
|
+
@field_id = 420
|
|
127
|
+
@child_id = 365
|
|
128
|
+
@fsa = mock_model FieldsetAssociator
|
|
129
|
+
@field = Field.new
|
|
130
|
+
@fieldset_child = mock_model FieldsetChild
|
|
131
|
+
@fieldset_child.stub!(:child).and_return @field
|
|
132
|
+
@fieldset_child.stub!(:id).and_return @child_id
|
|
133
|
+
@field.stub!(:id).and_return @field_id
|
|
134
|
+
@field.stub!(:has_default?).and_return false
|
|
135
|
+
@field.stub!(:default).and_return ""
|
|
136
|
+
@field.stub!(:options).and_return []
|
|
137
|
+
@values = []
|
|
138
|
+
@htmlattr = mock_model FieldHtmlAttribute
|
|
139
|
+
@htmlattr.stub!(:attribute_name).and_return 'class'
|
|
140
|
+
@htmlattr.stub!(:value).and_return 'test'
|
|
141
|
+
@field.stub!(:field_html_attributes).and_return [@htmlattr]
|
|
142
|
+
@option = mock_model FieldOption
|
|
143
|
+
@option.stub!(:name).and_return 'option1'
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "successfully for fieldtype radio" do
|
|
147
|
+
@field.stub!(:type).and_return 'radio'
|
|
148
|
+
@field.stub!(:options).and_return [@option]
|
|
149
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
150
|
+
end
|
|
151
|
+
it "successfully for fieldtype checkbox" do
|
|
152
|
+
@field.stub!(:type).and_return 'checkbox'
|
|
153
|
+
@field.stub!(:options).and_return [@option]
|
|
154
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
155
|
+
end
|
|
156
|
+
it "successfully for fieldtype select" do
|
|
157
|
+
@field.stub!(:type).and_return 'select'
|
|
158
|
+
@field.stub!(:options).and_return [@option]
|
|
159
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
160
|
+
end
|
|
161
|
+
it "successfully for fieldtype multiple_select" do
|
|
162
|
+
@field.stub!(:type).and_return 'multiple_select'
|
|
163
|
+
@field.stub!(:options).and_return [@option]
|
|
164
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
165
|
+
end
|
|
166
|
+
it "successfully for fieldtype textfield" do
|
|
167
|
+
@field.stub!(:type).and_return 'textfield'
|
|
168
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
169
|
+
end
|
|
170
|
+
it "successfully for fieldtype textarea" do
|
|
171
|
+
@field.stub!(:type).and_return 'textarea'
|
|
172
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
173
|
+
end
|
|
174
|
+
it "successfully for fieldtype date" do
|
|
175
|
+
@field.stub!(:type).and_return 'date'
|
|
176
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
177
|
+
end
|
|
178
|
+
it "successfully for fieldtype datetime" do
|
|
179
|
+
@field.stub!(:type).and_return 'datetime'
|
|
180
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/id=["']field-#{@field_id}-child-#{@child_id}["']/)
|
|
181
|
+
end
|
|
259
182
|
end
|
|
260
|
-
|
|
183
|
+
|
|
184
|
+
describe ".field_form_renderer" do
|
|
185
|
+
before(:each) do
|
|
186
|
+
@fsa = mock_model FieldsetAssociator
|
|
187
|
+
@field = Field.new
|
|
188
|
+
@fieldset_child = mock_model FieldsetChild
|
|
189
|
+
@fieldset_child.stub!(:child).and_return @field
|
|
190
|
+
@fieldset_child.stub!(:id).and_return 300
|
|
191
|
+
@field.stub!(:id).and_return 420
|
|
192
|
+
@field.stub!(:html_attributes).and_return []
|
|
193
|
+
@field.stub!(:has_default?).and_return false
|
|
194
|
+
@field.stub!(:default).and_return ""
|
|
195
|
+
@field.stub!(:type).and_return ""
|
|
196
|
+
@field.stub!(:options).and_return []
|
|
197
|
+
@values = []
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "includes the form object, the field object, and an array of values" do
|
|
201
|
+
lambda { field_form_renderer(@fsa,@fieldset_child,@values) }.should_not raise_error
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "calls the html_attributes method for the field" do
|
|
205
|
+
@field.should_receive(:field_html_attributes).and_return []
|
|
206
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "calls the field_options method for the field if it is a select" do
|
|
210
|
+
@field.stub!(:type).and_return 'select'
|
|
211
|
+
@field.should_receive(:options)
|
|
212
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "calls the field_options method for the field if it is a multiple select" do
|
|
216
|
+
@field.stub!(:type).and_return 'multiple_select'
|
|
217
|
+
@field.should_receive(:options)
|
|
218
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it "calls the field_options method for the field if it is a checkbox" do
|
|
222
|
+
@field.stub!(:type).and_return 'checkbox'
|
|
223
|
+
@field.should_receive(:options)
|
|
224
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it "calls the field_options method for the field if it is a radio" do
|
|
228
|
+
@field.stub!(:type).and_return 'radio'
|
|
229
|
+
@field.should_receive(:options)
|
|
230
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
261
233
|
|
|
262
234
|
## HELPER TAGS
|
|
263
235
|
|
|
264
236
|
it "has a label tag" do
|
|
265
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match
|
|
237
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/<label for=/)
|
|
266
238
|
end
|
|
267
239
|
|
|
268
240
|
it "does not have a label tag for type instruction" do
|
|
269
|
-
@field.stub!(:
|
|
270
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should_not match
|
|
241
|
+
@field.stub!(:type).and_return 'instruction'
|
|
242
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should_not match(/<label for=/)
|
|
271
243
|
end
|
|
272
244
|
|
|
273
245
|
it "displays label content enclosed in <p> tags for type instruction" do
|
|
274
|
-
@field.stub!(:
|
|
246
|
+
@field.stub!(:type).and_return 'instruction'
|
|
275
247
|
@field.stub!(:label).and_return 'some label'
|
|
276
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match
|
|
248
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/<p>some label<\/p>/)
|
|
277
249
|
end
|
|
278
250
|
|
|
279
251
|
it "calls select_tag if the type is select" do
|
|
280
|
-
@field.stub!(:
|
|
252
|
+
@field.stub!(:type).and_return 'select'
|
|
281
253
|
should_receive(:select_tag)
|
|
282
254
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
283
255
|
end
|
|
284
256
|
|
|
285
257
|
it "calls select_tag if the type is multiple select" do
|
|
286
|
-
@field.stub!(:
|
|
258
|
+
@field.stub!(:type).and_return 'multiple_select'
|
|
287
259
|
should_receive(:select_tag)
|
|
288
260
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
289
261
|
end
|
|
290
262
|
|
|
291
263
|
it "has the multiple attribute set if the type is multiple select" do
|
|
292
|
-
@field.stub!(:
|
|
293
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match
|
|
264
|
+
@field.stub!(:type).and_return 'multiple_select'
|
|
265
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/multiple=["']multiple["']/)
|
|
294
266
|
end
|
|
295
267
|
|
|
296
268
|
it "calls text_field if the type is textfield" do
|
|
297
|
-
@field.stub!(:
|
|
269
|
+
@field.stub!(:type).and_return 'textfield'
|
|
298
270
|
should_receive(:text_field)
|
|
299
271
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
300
272
|
end
|
|
@@ -302,7 +274,7 @@ describe DynamicFieldsetsHelper do
|
|
|
302
274
|
it "calls check_box_tag if the type is checkbox" do
|
|
303
275
|
option = mock_model(FieldOption)
|
|
304
276
|
option.stub!(:name).and_return ""
|
|
305
|
-
@field.stub!(:
|
|
277
|
+
@field.stub!(:type).and_return 'checkbox'
|
|
306
278
|
@field.stub!(:options).and_return [option]
|
|
307
279
|
should_receive(:check_box_tag)
|
|
308
280
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
@@ -311,25 +283,25 @@ describe DynamicFieldsetsHelper do
|
|
|
311
283
|
it "calls radio_button if the type is radio" do
|
|
312
284
|
option = mock_model(FieldOption)
|
|
313
285
|
option.stub!(:name).and_return ""
|
|
314
|
-
@field.stub!(:
|
|
286
|
+
@field.stub!(:type).and_return 'radio'
|
|
315
287
|
@field.stub!(:options).and_return [option]
|
|
316
288
|
should_receive(:radio_button)
|
|
317
289
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
318
290
|
end
|
|
319
291
|
|
|
320
292
|
it "has a text_area tag if the type is textarea" do
|
|
321
|
-
@field.stub!(:
|
|
322
|
-
field_form_renderer(@fsa,@fieldset_child,@values).join.should match
|
|
293
|
+
@field.stub!(:type).and_return 'textarea'
|
|
294
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match(/<textarea/)
|
|
323
295
|
end
|
|
324
296
|
|
|
325
297
|
it "calls date_select if the type is date" do
|
|
326
|
-
@field.stub!(:
|
|
298
|
+
@field.stub!(:type).and_return 'date'
|
|
327
299
|
should_receive(:date_select)
|
|
328
300
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
329
301
|
end
|
|
330
302
|
|
|
331
303
|
it "calls datetime_select if the type is datetime" do
|
|
332
|
-
@field.stub!(:
|
|
304
|
+
@field.stub!(:type).and_return 'datetime'
|
|
333
305
|
should_receive(:datetime_select)
|
|
334
306
|
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
335
307
|
end
|
|
@@ -340,97 +312,91 @@ describe DynamicFieldsetsHelper do
|
|
|
340
312
|
end
|
|
341
313
|
end
|
|
342
314
|
|
|
343
|
-
describe "
|
|
315
|
+
describe ".fieldset_renderer" do
|
|
344
316
|
before(:each) do
|
|
345
|
-
@fsa = mock_model
|
|
346
|
-
@
|
|
347
|
-
@
|
|
348
|
-
@
|
|
349
|
-
@
|
|
350
|
-
|
|
317
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
318
|
+
@fieldset = Fieldset.new
|
|
319
|
+
@fieldset.stub!(:id).and_return 326
|
|
320
|
+
@values = {}
|
|
321
|
+
@form_type = "form"
|
|
322
|
+
DynamicFieldsets::FieldsetChild.stub!(:where).and_return( [mock_model(FieldsetChild)] )
|
|
351
323
|
end
|
|
352
324
|
|
|
353
|
-
it "should
|
|
354
|
-
|
|
355
|
-
result.should be_a_kind_of Array
|
|
325
|
+
it "should include the fsa object, fieldset object, and a values hash" do
|
|
326
|
+
lambda { fieldset_renderer(@fsa,@fieldset,@values, @form_type) }.should_not raise_error
|
|
356
327
|
end
|
|
357
328
|
|
|
358
|
-
it "should
|
|
359
|
-
|
|
329
|
+
it "should call the children method on the fieldset object" do
|
|
330
|
+
@fieldset.should_receive(:children).and_return []
|
|
331
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
360
332
|
end
|
|
361
|
-
|
|
362
|
-
it "should
|
|
363
|
-
|
|
333
|
+
|
|
334
|
+
it "should call the field_renderer method if the current child is a field" do
|
|
335
|
+
@field = mock_model(Field)
|
|
336
|
+
@fieldset.stub!(:children).and_return [@field]
|
|
337
|
+
self.should_receive(:field_renderer).and_return []
|
|
338
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
364
339
|
end
|
|
365
|
-
|
|
366
|
-
it "should
|
|
367
|
-
|
|
340
|
+
|
|
341
|
+
it "should call the fieldset_renderer recursively if the current child is a fieldset" do
|
|
342
|
+
@child_fieldset = mock_model(Fieldset)
|
|
343
|
+
@fieldset.stub!(:children).and_return [@child_fieldset]
|
|
344
|
+
self.should_receive(:fieldset_renderer)
|
|
345
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
368
346
|
end
|
|
369
347
|
|
|
370
|
-
it "should
|
|
371
|
-
|
|
372
|
-
end
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
describe "field_renderer method" do
|
|
376
|
-
before(:each) do
|
|
377
|
-
@fsa = mock_model FieldsetAssociator
|
|
378
|
-
@fieldset_child = mock_model FieldsetChild
|
|
379
|
-
@values = []
|
|
348
|
+
it "should include markup for the fieldset itself" do
|
|
349
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type).join.should match(/id=["']fieldset-326["']/)
|
|
380
350
|
end
|
|
381
351
|
|
|
382
|
-
it "should
|
|
383
|
-
|
|
384
|
-
field_renderer(@fsa, @fieldset_child, @values, "form")
|
|
352
|
+
it "should return an array of html elements" do
|
|
353
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type).should be_a_kind_of Array
|
|
385
354
|
end
|
|
355
|
+
end
|
|
386
356
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
357
|
+
describe "dynamic_fieldset_show_renderer" do
|
|
358
|
+
it "should call dynamic_fieldset_renderer with 'show'" do
|
|
359
|
+
fsa = mock_model(FieldsetAssociator)
|
|
360
|
+
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "show")
|
|
361
|
+
dynamic_fieldset_show_renderer(fsa)
|
|
390
362
|
end
|
|
391
363
|
end
|
|
392
364
|
|
|
393
|
-
describe "
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
value = nil
|
|
400
|
-
@field.should_receive(:field_defaults).and_return []
|
|
401
|
-
populate(@field,value)
|
|
365
|
+
describe "dynamic_fieldset_form_renderer method" do
|
|
366
|
+
it "should call dynamic_fieldset_renderer with 'form'" do
|
|
367
|
+
pending 'hex is working on this'
|
|
368
|
+
fsa = mock_model(FieldsetAssociator)
|
|
369
|
+
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "form")
|
|
370
|
+
dynamic_fieldset_form_renderer(fsa)
|
|
402
371
|
end
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
describe ".dynamic_fieldset_renderer" do
|
|
375
|
+
before(:each) do
|
|
376
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
377
|
+
@fsa.stub!(:id).and_return(2)
|
|
378
|
+
@fsa.stub!(:fieldset).and_return mock_model(Fieldset)
|
|
379
|
+
@fsa.stub!(:fieldset_id).and_return(1)
|
|
380
|
+
@fsa.stub!(:fieldset_model_name).and_return("Turkey")
|
|
381
|
+
@fsa.stub!(:field_values).and_return []
|
|
382
|
+
stub!(:fieldset_renderer).and_return []
|
|
408
383
|
end
|
|
409
|
-
|
|
410
|
-
it "
|
|
411
|
-
|
|
412
|
-
result = populate(@field,value)
|
|
413
|
-
result.should == "test"
|
|
384
|
+
|
|
385
|
+
it "should include a form object and a field set associator object" do
|
|
386
|
+
lambda { dynamic_fieldset_renderer(@fsa, "form") }.should_not raise_error
|
|
414
387
|
end
|
|
415
|
-
|
|
416
|
-
it "
|
|
417
|
-
@
|
|
418
|
-
@
|
|
419
|
-
value = nil
|
|
420
|
-
@field.stub!(:field_defaults).and_return [@default]
|
|
421
|
-
result = populate(@field,value)
|
|
422
|
-
result.should == "test"
|
|
388
|
+
|
|
389
|
+
it "should call the fieldset_renderer with the fsa's root fieldset" do
|
|
390
|
+
@fsa.should_receive(:fieldset)
|
|
391
|
+
dynamic_fieldset_renderer(@fsa, "form")
|
|
423
392
|
end
|
|
424
|
-
|
|
425
|
-
it "
|
|
426
|
-
@
|
|
427
|
-
@default1.stub!(:value).and_return "Robin"
|
|
428
|
-
@default2 = mock_model FieldDefault
|
|
429
|
-
@default2.stub!(:value).and_return "Sparrow"
|
|
430
|
-
value = nil
|
|
431
|
-
@field.stub!(:field_defaults).and_return [@default1, @default2]
|
|
432
|
-
populate(@field,value)
|
|
393
|
+
|
|
394
|
+
it "should return a string of html" do
|
|
395
|
+
dynamic_fieldset_renderer(@fsa, "form").should be_a_kind_of String
|
|
433
396
|
end
|
|
434
|
-
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
describe ".javascript_renderer" do
|
|
400
|
+
it "needs tests"
|
|
435
401
|
end
|
|
436
402
|
end
|