dynamic_fieldsets 0.0.3 → 0.0.4
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/CHANGELOG +7 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +1 -0
- data/README.rdoc +15 -2
- data/Rakefile +24 -4
- data/VERSION +1 -1
- data/app/controllers/dynamic_fieldsets/fields_controller.rb +25 -0
- data/app/controllers/dynamic_fieldsets/fieldset_children_controller.rb +57 -0
- data/app/controllers/dynamic_fieldsets/fieldsets_controller.rb +91 -5
- data/app/helpers/dynamic_fieldsets/fields_helper.rb +1 -15
- data/app/helpers/dynamic_fieldsets/fieldset_children_helper.rb +5 -0
- data/app/helpers/dynamic_fieldsets/nested_model_helper.rb +18 -0
- data/app/helpers/dynamic_fieldsets_helper.rb +70 -44
- data/app/models/dynamic_fieldsets/dependency.rb +76 -0
- data/app/models/dynamic_fieldsets/dependency_clause.rb +32 -0
- data/app/models/dynamic_fieldsets/dependency_group.rb +108 -0
- data/app/models/dynamic_fieldsets/field.rb +17 -12
- data/app/models/dynamic_fieldsets/field_default.rb +27 -1
- data/app/models/dynamic_fieldsets/field_record.rb +19 -4
- data/app/models/dynamic_fieldsets/fieldset.rb +35 -30
- data/app/models/dynamic_fieldsets/fieldset_associator.rb +52 -8
- data/app/models/dynamic_fieldsets/fieldset_child.rb +148 -0
- data/app/views/dynamic_fieldsets/fields/_disable_field_form.html.erb +4 -0
- data/app/views/dynamic_fieldsets/fields/_field_default_fields.html.erb +1 -1
- data/app/views/dynamic_fieldsets/fields/_form.html.erb +9 -27
- data/app/views/dynamic_fieldsets/fields/index.html.erb +8 -5
- data/app/views/dynamic_fieldsets/fields/new.html.erb +5 -1
- data/app/views/dynamic_fieldsets/fields/show.html.erb +1 -13
- data/app/views/dynamic_fieldsets/fieldset_children/_dependency_clause_fields.html.erb +25 -0
- data/app/views/dynamic_fieldsets/fieldset_children/_dependency_fields.html.erb +12 -0
- data/app/views/dynamic_fieldsets/fieldset_children/_dependency_group_fields.html.erb +16 -0
- data/app/views/dynamic_fieldsets/fieldset_children/_form.html.erb +34 -0
- data/app/views/dynamic_fieldsets/fieldset_children/edit.html.erb +6 -0
- data/app/views/dynamic_fieldsets/fieldsets/_associate_child.html.erb +4 -0
- data/app/views/dynamic_fieldsets/fieldsets/_child.html.erb +41 -0
- data/app/views/dynamic_fieldsets/fieldsets/_form.html.erb +2 -8
- data/app/views/dynamic_fieldsets/fieldsets/children.html.erb +47 -39
- data/app/views/dynamic_fieldsets/fieldsets/index.html.erb +4 -4
- data/app/views/dynamic_fieldsets/fieldsets/new.html.erb +5 -1
- data/app/views/dynamic_fieldsets/fieldsets/reorder.html.erb +4 -0
- data/app/views/dynamic_fieldsets/fieldsets/show.html.erb +1 -12
- data/app/views/dynamic_fieldsets/shared/_javascript_watcher.html.erb +255 -0
- data/app/views/dynamic_fieldsets/shared/_nested_model_javascript.html.erb +35 -0
- data/config/.routes.rb.swp +0 -0
- data/config/routes.rb +11 -0
- data/dynamic_fieldsets.gemspec +41 -4
- data/lib/dynamic_fieldsets/dynamic_fieldsets_in_model.rb +141 -14
- data/lib/generators/dynamic_fieldsets/templates/migrations/install_migration.rb +39 -5
- data/spec/dummy/app/controllers/information_forms_controller.rb +2 -1
- data/spec/dummy/app/models/information_form.rb +1 -1
- data/spec/dummy/app/views/information_forms/dynamic_view.html.erb +18 -0
- data/spec/dummy/app/views/information_forms/show.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +9 -1
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/db/migrate/{20110726215814_create_dynamic_fieldsets_tables.rb → 20110809161724_create_dynamic_fieldsets_tables.rb} +39 -5
- data/spec/dummy/db/schema.rb +40 -11
- data/spec/dummy/features/field.feature +17 -2
- data/spec/dummy/features/fieldset.feature +1 -21
- data/spec/dummy/features/fieldset_children.feature +50 -0
- data/spec/dummy/features/javascript_tests.feature +91 -0
- data/spec/dummy/features/step_definitions/field_steps.rb +9 -5
- data/spec/dummy/features/step_definitions/fieldset_associator_steps.rb +3 -1
- data/spec/dummy/features/step_definitions/fieldset_children_steps.rb +65 -0
- data/spec/dummy/features/step_definitions/fieldset_steps.rb +0 -27
- data/spec/dummy/features/step_definitions/javascript_steps.rb +208 -0
- data/spec/dummy/features/step_definitions/web_steps.rb +5 -0
- data/spec/dummy/features/support/paths.rb +10 -1
- data/spec/dummy/features/support/selectors.rb +2 -0
- data/spec/dummy/public/javascripts/jquery-1.6.2.min.js +18 -0
- data/spec/dummy/public/javascripts/jquery-ui-1.8.15.custom.min.js +111 -0
- data/spec/dummy/public/javascripts/jquery-ui-nestedSortable.js +356 -0
- data/spec/dummy/public/stylesheets/scaffold.css +101 -0
- data/spec/dynamic_fieldsets_helper_spec.rb +236 -55
- data/spec/dynamic_fieldsets_in_model_spec.rb +122 -4
- data/spec/models/dependency_clause_spec.rb +55 -0
- data/spec/models/dependency_group_spec.rb +237 -0
- data/spec/models/dependency_spec.rb +173 -0
- data/spec/models/field_default_spec.rb +49 -0
- data/spec/models/field_record_spec.rb +11 -2
- data/spec/models/field_spec.rb +30 -6
- data/spec/models/fieldset_associator_spec.rb +138 -25
- data/spec/models/fieldset_child_spec.rb +122 -0
- data/spec/models/fieldset_spec.rb +78 -80
- data/spec/support/dependency_group_helper.rb +9 -0
- data/spec/support/dependency_helper.rb +13 -0
- data/spec/support/field_helper.rb +0 -2
- data/spec/support/fieldset_child_helper.rb +10 -0
- data/spec/support/fieldset_helper.rb +2 -18
- metadata +51 -5
|
@@ -5,10 +5,14 @@ include ActionView::Helpers
|
|
|
5
5
|
describe DynamicFieldsetsHelper do
|
|
6
6
|
include DynamicFieldsetsHelper
|
|
7
7
|
include FieldsetHelper
|
|
8
|
+
|
|
8
9
|
describe ".dynamic_fieldset_renderer" do
|
|
9
10
|
before(:each) do
|
|
10
11
|
@fsa = mock_model(FieldsetAssociator)
|
|
12
|
+
@fsa.stub!(:id).and_return(2)
|
|
11
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")
|
|
12
16
|
@fsa.stub!(:field_values).and_return []
|
|
13
17
|
stub!(:fieldset_renderer).and_return []
|
|
14
18
|
end
|
|
@@ -29,6 +33,7 @@ describe DynamicFieldsetsHelper do
|
|
|
29
33
|
|
|
30
34
|
describe "dynamic_fieldset_form_renderer method" do
|
|
31
35
|
it "should call dynamic_fieldset_renderer with 'form'" do
|
|
36
|
+
pending 'hex is working on this'
|
|
32
37
|
fsa = mock_model(FieldsetAssociator)
|
|
33
38
|
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "form")
|
|
34
39
|
dynamic_fieldset_form_renderer(fsa)
|
|
@@ -50,6 +55,7 @@ describe DynamicFieldsetsHelper do
|
|
|
50
55
|
@fieldset.stub!(:id).and_return 326
|
|
51
56
|
@values = {}
|
|
52
57
|
@form_type = "form"
|
|
58
|
+
DynamicFieldsets::FieldsetChild.stub!(:where).and_return( [mock_model(FieldsetChild)] )
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
it "should include the fsa object, fieldset object, and a values hash" do
|
|
@@ -76,20 +82,140 @@ describe DynamicFieldsetsHelper do
|
|
|
76
82
|
end
|
|
77
83
|
|
|
78
84
|
it "should include markup for the fieldset itself" do
|
|
79
|
-
fieldset_renderer(@fsa,@fieldset,@values, @form_type).should
|
|
80
|
-
|x| !x.select{ |v| v =~ /id='fieldset-326'/ }.nil?
|
|
81
|
-
}
|
|
85
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type).join.should match /id=["']fieldset-326["']/
|
|
82
86
|
end
|
|
83
87
|
|
|
84
|
-
it "should return
|
|
88
|
+
it "should return an array of html elements" do
|
|
85
89
|
fieldset_renderer(@fsa,@fieldset,@values, @form_type).should be_a_kind_of Array
|
|
86
90
|
end
|
|
87
91
|
end
|
|
92
|
+
|
|
93
|
+
describe ".field_form_renderer appends html attributes to the field element" do
|
|
94
|
+
before(:each) do
|
|
95
|
+
@fsa = mock_model FieldsetAssociator
|
|
96
|
+
@field = Field.new
|
|
97
|
+
@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
|
+
@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
|
+
end
|
|
113
|
+
|
|
114
|
+
it "successfully for fieldtype radio" do
|
|
115
|
+
@field.stub!(:field_type).and_return 'radio'
|
|
116
|
+
@field.stub!(:options).and_return [@option]
|
|
117
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /class=["']test["']/
|
|
118
|
+
end
|
|
119
|
+
it "successfully for fieldtype checkbox" do
|
|
120
|
+
@field.stub!(:field_type).and_return 'checkbox'
|
|
121
|
+
@field.stub!(:options).and_return [@option]
|
|
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["']/
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
describe ".field_form_renderer appends the field id and child id attribute to the field element" do
|
|
153
|
+
before(:each) do
|
|
154
|
+
@field_id = 420
|
|
155
|
+
@child_id = 365
|
|
156
|
+
@fsa = mock_model FieldsetAssociator
|
|
157
|
+
@field = Field.new
|
|
158
|
+
@fieldset_child = mock_model FieldsetChild
|
|
159
|
+
@fieldset_child.stub!(:child).and_return @field
|
|
160
|
+
@fieldset_child.stub!(:id).and_return @child_id
|
|
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 []
|
|
165
|
+
@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
|
+
end
|
|
173
|
+
|
|
174
|
+
it "successfully for fieldtype radio" do
|
|
175
|
+
@field.stub!(:field_type).and_return 'radio'
|
|
176
|
+
@field.stub!(:options).and_return [@option]
|
|
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}["']/
|
|
209
|
+
end
|
|
210
|
+
end
|
|
88
211
|
|
|
89
212
|
describe ".field_form_renderer" do
|
|
90
213
|
before(:each) do
|
|
91
|
-
@fsa = mock_model
|
|
214
|
+
@fsa = mock_model FieldsetAssociator
|
|
92
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
|
|
93
219
|
@field.stub!(:id).and_return 420
|
|
94
220
|
@field.stub!(:html_attributes).and_return []
|
|
95
221
|
@field.stub!(:has_default?).and_return false
|
|
@@ -99,157 +225,212 @@ describe DynamicFieldsetsHelper do
|
|
|
99
225
|
@values = []
|
|
100
226
|
end
|
|
101
227
|
|
|
102
|
-
it "
|
|
103
|
-
lambda { field_form_renderer(@fsa,@
|
|
228
|
+
it "includes the form object, the field object, and an array of values" do
|
|
229
|
+
lambda { field_form_renderer(@fsa,@fieldset_child,@values) }.should_not raise_error
|
|
104
230
|
end
|
|
105
231
|
|
|
106
|
-
it "
|
|
107
|
-
@field.should_receive(:field_html_attributes).and_return
|
|
108
|
-
field_form_renderer(@fsa,@
|
|
232
|
+
it "calls the html_attributes method for the field" do
|
|
233
|
+
@field.should_receive(:field_html_attributes).and_return []
|
|
234
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
109
235
|
end
|
|
110
236
|
|
|
111
|
-
it "
|
|
237
|
+
it "calls the field_options method for the field if it is a select" do
|
|
112
238
|
@field.stub!(:field_type).and_return 'select'
|
|
113
239
|
@field.should_receive(:options)
|
|
114
|
-
field_form_renderer(@fsa,@
|
|
240
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
115
241
|
end
|
|
116
242
|
|
|
117
|
-
it "
|
|
243
|
+
it "calls the field_options method for the field if it is a multiple select" do
|
|
118
244
|
@field.stub!(:field_type).and_return 'multiple_select'
|
|
119
245
|
@field.should_receive(:options)
|
|
120
|
-
field_form_renderer(@fsa,@
|
|
246
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
121
247
|
end
|
|
122
248
|
|
|
123
|
-
it "
|
|
249
|
+
it "calls the field_options method for the field if it is a checkbox" do
|
|
124
250
|
@field.stub!(:field_type).and_return 'checkbox'
|
|
125
251
|
@field.should_receive(:options)
|
|
126
|
-
field_form_renderer(@fsa,@
|
|
252
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
127
253
|
end
|
|
128
254
|
|
|
129
|
-
it "
|
|
255
|
+
it "calls the field_options method for the field if it is a radio" do
|
|
130
256
|
@field.stub!(:field_type).and_return 'radio'
|
|
131
257
|
@field.should_receive(:options)
|
|
132
|
-
field_form_renderer(@fsa,@
|
|
258
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
133
259
|
end
|
|
134
260
|
|
|
135
261
|
|
|
136
262
|
## HELPER TAGS
|
|
137
263
|
|
|
138
|
-
it "
|
|
139
|
-
field_form_renderer(@fsa,@
|
|
140
|
-
|x| !x.select{ |v| v =~ /<label for=/ }.nil?
|
|
141
|
-
}
|
|
264
|
+
it "has a label tag" do
|
|
265
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /<label for=/
|
|
142
266
|
end
|
|
143
267
|
|
|
144
|
-
it "
|
|
268
|
+
it "does not have a label tag for type instruction" do
|
|
269
|
+
@field.stub!(:field_type).and_return 'instruction'
|
|
270
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should_not match /<label for=/
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it "displays label content enclosed in <p> tags for type instruction" do
|
|
274
|
+
@field.stub!(:field_type).and_return 'instruction'
|
|
275
|
+
@field.stub!(:label).and_return 'some label'
|
|
276
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /<p>some label<\/p>/
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
it "calls select_tag if the type is select" do
|
|
145
280
|
@field.stub!(:field_type).and_return 'select'
|
|
146
281
|
should_receive(:select_tag)
|
|
147
|
-
field_form_renderer(@fsa,@
|
|
282
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
148
283
|
end
|
|
149
284
|
|
|
150
|
-
it "
|
|
285
|
+
it "calls select_tag if the type is multiple select" do
|
|
151
286
|
@field.stub!(:field_type).and_return 'multiple_select'
|
|
152
287
|
should_receive(:select_tag)
|
|
153
|
-
field_form_renderer(@fsa,@
|
|
288
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it "has the multiple attribute set if the type is multiple select" do
|
|
292
|
+
@field.stub!(:field_type).and_return 'multiple_select'
|
|
293
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /multiple=["']multiple["']/
|
|
154
294
|
end
|
|
155
295
|
|
|
156
|
-
it "
|
|
296
|
+
it "calls text_field if the type is textfield" do
|
|
157
297
|
@field.stub!(:field_type).and_return 'textfield'
|
|
158
298
|
should_receive(:text_field)
|
|
159
|
-
field_form_renderer(@fsa,@
|
|
299
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
160
300
|
end
|
|
161
301
|
|
|
162
|
-
it "
|
|
302
|
+
it "calls check_box_tag if the type is checkbox" do
|
|
163
303
|
option = mock_model(FieldOption)
|
|
164
304
|
option.stub!(:name).and_return ""
|
|
165
305
|
@field.stub!(:field_type).and_return 'checkbox'
|
|
166
306
|
@field.stub!(:options).and_return [option]
|
|
167
|
-
should_receive(:
|
|
168
|
-
field_form_renderer(@fsa,@
|
|
307
|
+
should_receive(:check_box_tag)
|
|
308
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
169
309
|
end
|
|
170
310
|
|
|
171
|
-
it "
|
|
311
|
+
it "calls radio_button if the type is radio" do
|
|
172
312
|
option = mock_model(FieldOption)
|
|
173
313
|
option.stub!(:name).and_return ""
|
|
174
314
|
@field.stub!(:field_type).and_return 'radio'
|
|
175
315
|
@field.stub!(:options).and_return [option]
|
|
176
316
|
should_receive(:radio_button)
|
|
177
|
-
field_form_renderer(@fsa,@
|
|
317
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
178
318
|
end
|
|
179
319
|
|
|
180
|
-
it "
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
320
|
+
it "has a text_area tag if the type is textarea" do
|
|
321
|
+
@field.stub!(:field_type).and_return 'textarea'
|
|
322
|
+
field_form_renderer(@fsa,@fieldset_child,@values).join.should match /<textarea/
|
|
184
323
|
end
|
|
185
324
|
|
|
186
|
-
it "
|
|
325
|
+
it "calls date_select if the type is date" do
|
|
187
326
|
@field.stub!(:field_type).and_return 'date'
|
|
188
327
|
should_receive(:date_select)
|
|
189
|
-
field_form_renderer(@fsa,@
|
|
328
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
190
329
|
end
|
|
191
330
|
|
|
192
|
-
it "
|
|
331
|
+
it "calls datetime_select if the type is datetime" do
|
|
193
332
|
@field.stub!(:field_type).and_return 'datetime'
|
|
194
333
|
should_receive(:datetime_select)
|
|
195
|
-
field_form_renderer(@fsa,@
|
|
334
|
+
field_form_renderer(@fsa,@fieldset_child,@values)
|
|
196
335
|
end
|
|
197
336
|
|
|
198
337
|
|
|
199
|
-
it "
|
|
200
|
-
field_form_renderer(@fsa,@
|
|
338
|
+
it "returns an array of html" do
|
|
339
|
+
field_form_renderer(@fsa,@fieldset_child,@values).should be_a_kind_of Array
|
|
201
340
|
end
|
|
202
341
|
end
|
|
203
342
|
|
|
204
343
|
describe "field_show_renderer method" do
|
|
205
344
|
before(:each) do
|
|
206
|
-
@fsa = mock_model
|
|
345
|
+
@fsa = mock_model FieldsetAssociator
|
|
207
346
|
@field = Field.new
|
|
208
|
-
@
|
|
347
|
+
@fieldset_child = mock_model FieldsetChild
|
|
348
|
+
@fieldset_child.stub!(:child).and_return @field
|
|
349
|
+
@fieldset_child.stub!(:id).and_return 420
|
|
209
350
|
@values = []
|
|
210
351
|
end
|
|
211
352
|
|
|
212
353
|
it "should return an array of strings" do
|
|
213
|
-
result = field_show_renderer(@fsa, @
|
|
354
|
+
result = field_show_renderer(@fsa, @fieldset_child, @values)
|
|
214
355
|
result.should be_a_kind_of Array
|
|
215
356
|
end
|
|
216
357
|
|
|
217
358
|
it "should include the class dynamic_fieldsets_field" do
|
|
218
|
-
field_show_renderer(@fsa, @
|
|
359
|
+
field_show_renderer(@fsa, @fieldset_child, @values).join.should match /dynamic_fieldsets_field/
|
|
219
360
|
end
|
|
220
361
|
|
|
221
362
|
it "should include the class dynamic_fieldsets_field_label" do
|
|
222
|
-
field_show_renderer(@fsa, @
|
|
363
|
+
field_show_renderer(@fsa, @fieldset_child, @values).join.should match /dynamic_fieldsets_field_label/
|
|
223
364
|
end
|
|
224
365
|
|
|
225
366
|
it "should include the class dynamic_fieldsets_field_value" do
|
|
226
|
-
field_show_renderer(@fsa, @
|
|
367
|
+
field_show_renderer(@fsa, @fieldset_child, @values).join.should match /dynamic_fieldsets_field_value/
|
|
227
368
|
end
|
|
228
369
|
|
|
229
370
|
it "should return 'No answer given' if the field has no answer for the current fieldset associator" do
|
|
230
|
-
field_show_renderer(@fsa, @
|
|
371
|
+
field_show_renderer(@fsa, @fieldset_child, nil).join.should match /No answer given/
|
|
231
372
|
end
|
|
232
373
|
end
|
|
233
374
|
|
|
234
375
|
describe "field_renderer method" do
|
|
235
376
|
before(:each) do
|
|
236
|
-
@fsa = mock_model
|
|
237
|
-
@
|
|
377
|
+
@fsa = mock_model FieldsetAssociator
|
|
378
|
+
@fieldset_child = mock_model FieldsetChild
|
|
238
379
|
@values = []
|
|
239
380
|
end
|
|
240
381
|
|
|
241
382
|
it "should call the form helper if the form_type is form" do
|
|
242
383
|
self.should_receive(:field_form_renderer)
|
|
243
|
-
field_renderer(@fsa, @
|
|
384
|
+
field_renderer(@fsa, @fieldset_child, @values, "form")
|
|
244
385
|
end
|
|
245
386
|
|
|
246
387
|
it "should default to the show helper if the form_type is not form" do
|
|
247
388
|
self.should_receive(:field_show_renderer)
|
|
248
|
-
field_renderer(@fsa, @
|
|
389
|
+
field_renderer(@fsa, @fieldset_child, @values, "show")
|
|
249
390
|
end
|
|
250
391
|
end
|
|
251
392
|
|
|
252
393
|
describe "populate method" do
|
|
253
|
-
|
|
394
|
+
before(:each) do
|
|
395
|
+
@field = mock_model Field
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
it "calls field_defaults if no value is passed" do
|
|
399
|
+
value = nil
|
|
400
|
+
@field.should_receive(:field_defaults).and_return []
|
|
401
|
+
populate(@field,value)
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
it "calls field_defaults if empty value array is passed" do
|
|
405
|
+
value = []
|
|
406
|
+
@field.should_receive(:field_defaults).and_return []
|
|
407
|
+
populate(@field,value)
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
it "returns value if one is passed" do
|
|
411
|
+
value = "test"
|
|
412
|
+
result = populate(@field,value)
|
|
413
|
+
result.should == "test"
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it "returns a default value if one exists" do
|
|
417
|
+
@default = mock_model FieldDefault
|
|
418
|
+
@default.stub!(:value).and_return "test"
|
|
419
|
+
value = nil
|
|
420
|
+
@field.stub!(:field_defaults).and_return [@default]
|
|
421
|
+
result = populate(@field,value)
|
|
422
|
+
result.should == "test"
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
it "returns multiple defaults if they exist" do
|
|
426
|
+
@default1 = mock_model FieldDefault
|
|
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)
|
|
433
|
+
end
|
|
434
|
+
|
|
254
435
|
end
|
|
255
436
|
end
|
|
@@ -30,6 +30,101 @@ describe DynamicFieldsetsInModel do
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
describe "run_validations! method" do
|
|
34
|
+
before(:each) do
|
|
35
|
+
@information_form = InformationForm.new
|
|
36
|
+
@information_form.stub!(:run_dynamic_fieldset_validations!)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should call run_dynamic_fieldset_validations!" do
|
|
40
|
+
@information_form.should_receive(:run_dynamic_fieldset_validations!)
|
|
41
|
+
@information_form.run_validations!
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "run_dynamic_fieldset_validations! method" do
|
|
46
|
+
before(:each) do
|
|
47
|
+
@field = Field.new(:name => "Test Field", :label => "Test Field", :field_type => "textfield")
|
|
48
|
+
@fieldset = Fieldset.new(:name => "first", :nkey => "first", :description => "description")
|
|
49
|
+
@fieldset.stub!(:children).and_return([@field])
|
|
50
|
+
@fsa = FieldsetAssociator.new
|
|
51
|
+
@fsa.stub!(:fieldset).and_return(@fieldset)
|
|
52
|
+
@fsa.stub!(:id).and_return(1)
|
|
53
|
+
|
|
54
|
+
@information_form = InformationForm.new
|
|
55
|
+
@information_form.stub!(:run_fieldset_child_validations!)
|
|
56
|
+
@information_form.stub!(:fieldset_associator).and_return(@fsa)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should iterate over dynamic_fieldset keys" do
|
|
60
|
+
@information_form.dynamic_fieldsets.should_receive(:keys).and_return([])
|
|
61
|
+
@information_form.run_dynamic_fieldset_validations!
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should call run_fieldset_child_validations for each key" do
|
|
65
|
+
@information_form.should_receive(:run_fieldset_child_validations!)
|
|
66
|
+
@information_form.run_dynamic_fieldset_validations!
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "run_fieldset_child_validations! method" do
|
|
71
|
+
before(:each) do
|
|
72
|
+
@field = Field.new(:name => "Test Field", :label => "Test Field", :field_type => "textfield", :required => true)
|
|
73
|
+
@field.stub!(:id).and_return(42)
|
|
74
|
+
@fieldset = Fieldset.new(:name => "first", :nkey => "first", :description => "description")
|
|
75
|
+
@fieldset.stub!(:children).and_return([@field])
|
|
76
|
+
@fsa = FieldsetAssociator.new
|
|
77
|
+
@fsa.stub!(:fieldset).and_return(@fieldset)
|
|
78
|
+
@fsa.stub!(:id).and_return(1)
|
|
79
|
+
|
|
80
|
+
@information_form = InformationForm.new
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should recurse if the child is a field" do
|
|
84
|
+
values = { "fsa-1" => { "field-42"=>[] } }
|
|
85
|
+
@information_form.stub!(:dynamic_fieldset_values).and_return(values)
|
|
86
|
+
@fieldset.should_receive(:children).and_return([@field])
|
|
87
|
+
@information_form.run_fieldset_child_validations!(@fsa.id, @fieldset)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should add an error if there is no matching field in self.dynamic_fieldset_values" do
|
|
91
|
+
values = { "fsa-1" => { "field-4200"=>"" } }
|
|
92
|
+
@information_form.stub!(:dynamic_fieldset_values).and_return(values)
|
|
93
|
+
@information_form.run_fieldset_child_validations!(@fsa.id, @field)
|
|
94
|
+
@information_form.errors[:base].should include "Test Field is required and the input is missing"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should add an error if the field is required, the value is an array, and the value is empty" do
|
|
98
|
+
values = { "fsa-1" => { "field-42"=>[] } }
|
|
99
|
+
@information_form.stub!(:dynamic_fieldset_values).and_return(values)
|
|
100
|
+
@information_form.run_fieldset_child_validations!(@fsa.id, @field)
|
|
101
|
+
@information_form.errors[:base].should include "Test Field is required"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should add an error if the field is required, the value is not an array, and the value is an empty string" do
|
|
105
|
+
values = { "fsa-1" => { "field-42"=>"" } }
|
|
106
|
+
@information_form.stub!(:dynamic_fieldset_values).and_return(values)
|
|
107
|
+
@information_form.run_fieldset_child_validations!(@fsa.id, @field)
|
|
108
|
+
@information_form.errors[:base].should include "Test Field is required"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should add an error if the field is required, the value is not an array, and the value is a nil" do
|
|
112
|
+
values = { "fsa-1" => { "field-42"=>nil } }
|
|
113
|
+
@information_form.stub!(:dynamic_fieldset_values).and_return(values)
|
|
114
|
+
@information_form.run_fieldset_child_validations!(@fsa.id, @field)
|
|
115
|
+
@information_form.errors[:base].should include "Test Field is required"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "should not add an error if the field is not required" do
|
|
119
|
+
@field.required = false
|
|
120
|
+
|
|
121
|
+
values = { "fsa-1" => { "field-42"=>"" } }
|
|
122
|
+
@information_form.stub!(:dynamic_fieldset_values).and_return(values)
|
|
123
|
+
@information_form.run_fieldset_child_validations!(@fsa.id, @field)
|
|
124
|
+
@information_form.errors.should == {}
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
33
128
|
describe "method missing method" do
|
|
34
129
|
before(:each) do
|
|
35
130
|
@model = InformationForm.new
|
|
@@ -128,8 +223,9 @@ describe DynamicFieldsetsInModel do
|
|
|
128
223
|
describe "fieldset_associator method" do
|
|
129
224
|
before(:each) do
|
|
130
225
|
@model = InformationForm.new
|
|
226
|
+
@model.stub!(:id).and_return(1234)
|
|
131
227
|
@model.stub!(:dynamic_fieldsets).and_return({:child_form => {:fieldset => :fingerprint_form}})
|
|
132
|
-
@fsa = DynamicFieldsets::FieldsetAssociator.new(:fieldset_model_id =>
|
|
228
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new(:fieldset_model_id => @model.id, :fieldset_model_type => "InformationForm", :fieldset_model_name => :child_form)
|
|
133
229
|
DynamicFieldsets::FieldsetAssociator.stub!(:find_by_fieldset_model_parameters).and_return(@fsa)
|
|
134
230
|
end
|
|
135
231
|
|
|
@@ -138,12 +234,16 @@ describe DynamicFieldsetsInModel do
|
|
|
138
234
|
@model.fieldset_associator(:child_form).should == @fsa
|
|
139
235
|
end
|
|
140
236
|
|
|
141
|
-
it "should
|
|
237
|
+
it "should make a new fieldset associator object if one does not exist" do
|
|
142
238
|
DynamicFieldsets::FieldsetAssociator.stub!(:find_by_fieldset_model_parameters).and_return([])
|
|
143
239
|
DynamicFieldsets::FieldsetAssociator.stub!(:create).and_return(@fsa)
|
|
144
240
|
|
|
145
|
-
#
|
|
146
|
-
|
|
241
|
+
# new has been called on the object with specific parameters
|
|
242
|
+
# but it does not match the fsa object because it has a different object id
|
|
243
|
+
new_fsa = @model.fieldset_associator(:child_form)
|
|
244
|
+
new_fsa.fieldset_model_id.should == @model.id
|
|
245
|
+
new_fsa.fieldset_model_type.should == "InformationForm"
|
|
246
|
+
new_fsa.fieldset_model_name.should == "child_form"
|
|
147
247
|
end
|
|
148
248
|
|
|
149
249
|
it "should return nil if the sym param does not match a key in the dynamic_fieldsets field" do
|
|
@@ -172,4 +272,22 @@ describe DynamicFieldsetsInModel do
|
|
|
172
272
|
@model.fieldset(:not_child_form).should be_nil
|
|
173
273
|
end
|
|
174
274
|
end
|
|
275
|
+
|
|
276
|
+
# values =
|
|
277
|
+
# {"fsa-1"=>{"field-19"=>"Blahfaceee", "field-20"=>"8", "field-21"=>"No...",
|
|
278
|
+
# "field-22"=>["9"], "field-24"=>"10", "field-17(1i)"=>"1952", "field-17(2i)"=>"2",
|
|
279
|
+
# "field-17(3i)"=>"24", "field-18"=>["4", "5"]}}
|
|
280
|
+
describe "save_dynamic_fieldset method" do
|
|
281
|
+
before(:each) do
|
|
282
|
+
values = { "fsa-1" => { "field-42"=>"testing" } }
|
|
283
|
+
@model = InformationForm.new
|
|
284
|
+
@model.stub!(:dynamic_fieldset_values).and_return values
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it "calls dynamic_fieldset_values" do
|
|
288
|
+
@model.should respond_to :dynamic_fieldset_values
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
end
|
|
292
|
+
|
|
175
293
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe DependencyClause do
|
|
5
|
+
it "should respond to dependency_group" do
|
|
6
|
+
DependencyClause.new.should respond_to :dependency_group
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should respond to dependencies" do
|
|
10
|
+
DependencyClause.new.should respond_to :dependencies
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "validations" do
|
|
14
|
+
before(:each) do
|
|
15
|
+
@clause = DependencyClause.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should be valid" do
|
|
19
|
+
@clause.dependency_group_id = 1
|
|
20
|
+
@clause.should be_valid
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should require a dependency group" do
|
|
24
|
+
@clause.should have(1).error_on(:dependency_group_id)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "evaluate" do
|
|
29
|
+
before(:each) do
|
|
30
|
+
@clause = DependencyClause.new
|
|
31
|
+
@dependency1 = Dependency.new
|
|
32
|
+
@dependency2 = Dependency.new
|
|
33
|
+
@clause.stub!(:dependencies).and_return([@dependency1, @dependency2])
|
|
34
|
+
@evaluate_args = {}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should take a hash as input" do
|
|
38
|
+
@dependency1.stub!(:evaluate).and_return(true)
|
|
39
|
+
@dependency2.stub!(:evaluate).and_return(false)
|
|
40
|
+
@clause.evaluate(@evaluate_args).should_not raise_error ArgumentError
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should return true if at least one of the dependencies evaluateds to true" do
|
|
44
|
+
@dependency1.stub!(:evaluate).and_return(true)
|
|
45
|
+
@dependency2.stub!(:evaluate).and_return(false)
|
|
46
|
+
@clause.evaluate(@evaluate_args).should be_true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should return false if none of the dependencies evaluatue to true" do
|
|
50
|
+
@dependency1.stub!(:evaluate).and_return(false)
|
|
51
|
+
@dependency2.stub!(:evaluate).and_return(false)
|
|
52
|
+
@clause.evaluate(@evaluate_args).should be_false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|