dynamic_fieldsets 0.0.2
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 +4 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +157 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +69 -0
- data/VERSION +1 -0
- data/app/controllers/dynamic_fieldsets/fields_controller.rb +75 -0
- data/app/controllers/dynamic_fieldsets/fieldset_associators_controller.rb +24 -0
- data/app/controllers/dynamic_fieldsets/fieldsets_controller.rb +89 -0
- data/app/helpers/dynamic_fieldsets/fields_helper.rb +19 -0
- data/app/helpers/dynamic_fieldsets_helper.rb +207 -0
- data/app/models/dynamic_fieldsets/field.rb +85 -0
- data/app/models/dynamic_fieldsets/field_default.rb +14 -0
- data/app/models/dynamic_fieldsets/field_html_attribute.rb +15 -0
- data/app/models/dynamic_fieldsets/field_option.rb +18 -0
- data/app/models/dynamic_fieldsets/field_record.rb +11 -0
- data/app/models/dynamic_fieldsets/fieldset.rb +57 -0
- data/app/models/dynamic_fieldsets/fieldset_associator.rb +76 -0
- data/app/views/dynamic_fieldsets/fields/_field_default_fields.html.erb +7 -0
- data/app/views/dynamic_fieldsets/fields/_field_html_attribute_fields.html.erb +8 -0
- data/app/views/dynamic_fieldsets/fields/_field_option_fields.html.erb +6 -0
- data/app/views/dynamic_fieldsets/fields/_form.html.erb +81 -0
- data/app/views/dynamic_fieldsets/fields/edit.html.erb +6 -0
- data/app/views/dynamic_fieldsets/fields/index.html.erb +29 -0
- data/app/views/dynamic_fieldsets/fields/new.html.erb +5 -0
- data/app/views/dynamic_fieldsets/fields/show.html.erb +70 -0
- data/app/views/dynamic_fieldsets/fieldset_associators/index.html.erb +18 -0
- data/app/views/dynamic_fieldsets/fieldset_associators/show.html.erb +26 -0
- data/app/views/dynamic_fieldsets/fieldsets/_form.html.erb +37 -0
- data/app/views/dynamic_fieldsets/fieldsets/children.html.erb +45 -0
- data/app/views/dynamic_fieldsets/fieldsets/edit.html.erb +6 -0
- data/app/views/dynamic_fieldsets/fieldsets/index.html.erb +31 -0
- data/app/views/dynamic_fieldsets/fieldsets/new.html.erb +5 -0
- data/app/views/dynamic_fieldsets/fieldsets/show.html.erb +31 -0
- data/config/routes.rb +9 -0
- data/dynamic_fieldsets.gemspec +195 -0
- data/lib/dynamic_fieldsets/config.rb +0 -0
- data/lib/dynamic_fieldsets/dynamic_fieldsets_in_model.rb +164 -0
- data/lib/dynamic_fieldsets/engine.rb +4 -0
- data/lib/dynamic_fieldsets/railtie.rb +13 -0
- data/lib/dynamic_fieldsets.rb +2 -0
- data/lib/generators/dynamic_fieldsets/install_generator.rb +44 -0
- data/lib/generators/dynamic_fieldsets/templates/config.rb +0 -0
- data/lib/generators/dynamic_fieldsets/templates/migrations/install_migration.rb +74 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/information_forms_controller.rb +85 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/helpers/information_forms_helper.rb +2 -0
- data/spec/dummy/app/models/information_form.rb +3 -0
- data/spec/dummy/app/views/information_forms/_form.html.erb +22 -0
- data/spec/dummy/app/views/information_forms/edit.html.erb +6 -0
- data/spec/dummy/app/views/information_forms/index.html.erb +23 -0
- data/spec/dummy/app/views/information_forms/new.html.erb +5 -0
- data/spec/dummy/app/views/information_forms/show.html.erb +11 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20110726215814_create_dynamic_fieldsets_tables.rb +74 -0
- data/spec/dummy/db/migrate/20110727210451_create_information_forms.rb +13 -0
- data/spec/dummy/db/schema.rb +83 -0
- data/spec/dummy/features/field.feature +54 -0
- data/spec/dummy/features/fieldset.feature +68 -0
- data/spec/dummy/features/fieldset_associator.feature +20 -0
- data/spec/dummy/features/step_definitions/debugging_steps.rb +8 -0
- data/spec/dummy/features/step_definitions/field_steps.rb +63 -0
- data/spec/dummy/features/step_definitions/fieldset_associator_steps.rb +11 -0
- data/spec/dummy/features/step_definitions/fieldset_steps.rb +57 -0
- data/spec/dummy/features/step_definitions/web_steps.rb +214 -0
- data/spec/dummy/features/support/env.rb +15 -0
- data/spec/dummy/features/support/paths.rb +46 -0
- data/spec/dummy/features/support/selectors.rb +39 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/jquery.min.js +166 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/public/stylesheets/scaffold.css +56 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dynamic_fieldsets_helper_spec.rb +254 -0
- data/spec/dynamic_fieldsets_in_model_spec.rb +175 -0
- data/spec/dynamic_fieldsets_spec.rb +7 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/models/field_default_spec.rb +26 -0
- data/spec/models/field_html_attribute_spec.rb +30 -0
- data/spec/models/field_option_spec.rb +52 -0
- data/spec/models/field_record_spec.rb +44 -0
- data/spec/models/field_spec.rb +169 -0
- data/spec/models/fieldset_associator_spec.rb +128 -0
- data/spec/models/fieldset_spec.rb +169 -0
- data/spec/reports/SPEC-ActsAsMultipartForm.xml +9 -0
- data/spec/reports/SPEC-MultipartForm-InProgressForm-validations.xml +47 -0
- data/spec/reports/SPEC-MultipartForm-InProgressForm.xml +7 -0
- data/spec/reports/SPEC-Navigation.xml +9 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/field_default_helper.rb +12 -0
- data/spec/support/field_helper.rb +16 -0
- data/spec/support/field_html_attribute_helper.rb +14 -0
- data/spec/support/field_option_helper.rb +13 -0
- data/spec/support/field_record_helper.rb +12 -0
- data/spec/support/fieldset_associator_helper.rb +12 -0
- data/spec/support/fieldset_helper.rb +28 -0
- metadata +328 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe DynamicFieldsetsHelper do
|
|
5
|
+
include DynamicFieldsetsHelper
|
|
6
|
+
include FieldsetHelper
|
|
7
|
+
describe ".dynamic_fieldset_renderer" do
|
|
8
|
+
before(:each) do
|
|
9
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
10
|
+
@fsa.stub!(:fieldset).and_return mock_model(Fieldset)
|
|
11
|
+
@fsa.stub!(:field_values).and_return []
|
|
12
|
+
stub!(:fieldset_renderer).and_return []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should include a form object and a field set associator object" do
|
|
16
|
+
lambda { dynamic_fieldset_renderer(@fsa, "form") }.should_not raise_error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should call the fieldset_renderer with the fsa's root fieldset" do
|
|
20
|
+
@fsa.should_receive(:fieldset)
|
|
21
|
+
dynamic_fieldset_renderer(@fsa, "form")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should return a string of html" do
|
|
25
|
+
dynamic_fieldset_renderer(@fsa, "form").should be_a_kind_of String
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "dynamic_fieldset_form_renderer method" do
|
|
30
|
+
it "should call dynamic_fieldset_renderer with 'form'" do
|
|
31
|
+
fsa = mock_model(FieldsetAssociator)
|
|
32
|
+
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "form")
|
|
33
|
+
dynamic_fieldset_form_renderer(fsa)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "dynamic_fieldset_show_renderer" do
|
|
38
|
+
it "should call dynamic_fieldset_renderer with 'show'" do
|
|
39
|
+
fsa = mock_model(FieldsetAssociator)
|
|
40
|
+
self.should_receive(:dynamic_fieldset_renderer).with(fsa, "show")
|
|
41
|
+
dynamic_fieldset_show_renderer(fsa)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe ".fieldset_renderer" do
|
|
46
|
+
before(:each) do
|
|
47
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
48
|
+
@fieldset = Fieldset.new
|
|
49
|
+
@fieldset.stub!(:id).and_return 326
|
|
50
|
+
@values = {}
|
|
51
|
+
@form_type = "form"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should include the fsa object, fieldset object, and a values hash" do
|
|
55
|
+
lambda { fieldset_renderer(@fsa,@fieldset,@values, @form_type) }.should_not raise_error
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should call the children method on the fieldset object" do
|
|
59
|
+
@fieldset.should_receive(:children).and_return []
|
|
60
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should call the field_renderer method if the current child is a field" do
|
|
64
|
+
@field = mock_model(Field)
|
|
65
|
+
@fieldset.stub!(:children).and_return [@field]
|
|
66
|
+
self.should_receive(:field_renderer).and_return []
|
|
67
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should call the fieldset_renderer recursively if the current child is a fieldset" do
|
|
71
|
+
@child_fieldset = mock_model(Fieldset)
|
|
72
|
+
@fieldset.stub!(:children).and_return [@child_fieldset]
|
|
73
|
+
self.should_receive(:fieldset_renderer)
|
|
74
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should include markup for the fieldset itself" do
|
|
78
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type).should satisfy {
|
|
79
|
+
|x| !x.select{ |v| v =~ /id='fieldset-326'/ }.nil?
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should return a array of html elements" do
|
|
84
|
+
fieldset_renderer(@fsa,@fieldset,@values, @form_type).should be_a_kind_of Array
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe ".field_form_renderer" do
|
|
89
|
+
before(:each) do
|
|
90
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
91
|
+
@field = Field.new
|
|
92
|
+
@field.stub!(:id).and_return 420
|
|
93
|
+
@field.stub!(:html_attributes).and_return []
|
|
94
|
+
@field.stub!(:has_default?).and_return false
|
|
95
|
+
@field.stub!(:default).and_return ""
|
|
96
|
+
@field.stub!(:field_type).and_return ""
|
|
97
|
+
@field.stub!(:options).and_return []
|
|
98
|
+
@values = []
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should include the form object, the field object, and an array of values" do
|
|
102
|
+
lambda { field_form_renderer(@fsa,@field,@values) }.should_not raise_error
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should call the html_attributes method for the field" do
|
|
106
|
+
@field.should_receive(:field_html_attributes).and_return([])
|
|
107
|
+
field_form_renderer(@fsa,@field,@values)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should call the field_options method for the field if it is a select" do
|
|
111
|
+
@field.stub!(:field_type).and_return 'select'
|
|
112
|
+
@field.should_receive(:options)
|
|
113
|
+
field_form_renderer(@fsa,@field,@values)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "should call the field_options method for the field if it is a multiple select" do
|
|
117
|
+
@field.stub!(:field_type).and_return 'multiple_select'
|
|
118
|
+
@field.should_receive(:options)
|
|
119
|
+
field_form_renderer(@fsa,@field,@values)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should call the field_options method for the field if it is a checkbox" do
|
|
123
|
+
@field.stub!(:field_type).and_return 'checkbox'
|
|
124
|
+
@field.should_receive(:options)
|
|
125
|
+
field_form_renderer(@fsa,@field,@values)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "should call the field_options method for the field if it is a radio" do
|
|
129
|
+
@field.stub!(:field_type).and_return 'radio'
|
|
130
|
+
@field.should_receive(:options)
|
|
131
|
+
field_form_renderer(@fsa,@field,@values)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
## HELPER TAGS
|
|
136
|
+
|
|
137
|
+
it "should have a label tag" do
|
|
138
|
+
field_form_renderer(@fsa,@field,@values).should satisfy {
|
|
139
|
+
|x| !x.select{ |v| v =~ /<label for=/ }.nil?
|
|
140
|
+
}
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should call select_tag if the type is select" do
|
|
144
|
+
@field.stub!(:field_type).and_return 'select'
|
|
145
|
+
should_receive(:select_tag)
|
|
146
|
+
field_form_renderer(@fsa,@field,@values)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "should call select_tag if the type is multiple select" do
|
|
150
|
+
@field.stub!(:field_type).and_return 'multiple_select'
|
|
151
|
+
should_receive(:select_tag)
|
|
152
|
+
field_form_renderer(@fsa,@field,@values)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "should call text_field if the type is textfield" do
|
|
156
|
+
@field.stub!(:field_type).and_return 'textfield'
|
|
157
|
+
should_receive(:text_field)
|
|
158
|
+
field_form_renderer(@fsa,@field,@values)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should call check_box if the type is checkbox" do
|
|
162
|
+
option = mock_model(FieldOption)
|
|
163
|
+
option.stub!(:name).and_return ""
|
|
164
|
+
@field.stub!(:field_type).and_return 'checkbox'
|
|
165
|
+
@field.stub!(:options).and_return [option]
|
|
166
|
+
should_receive(:check_box)
|
|
167
|
+
field_form_renderer(@fsa,@field,@values)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should call radio_button if the type is radio" do
|
|
171
|
+
option = mock_model(FieldOption)
|
|
172
|
+
option.stub!(:name).and_return ""
|
|
173
|
+
@field.stub!(:field_type).and_return 'radio'
|
|
174
|
+
@field.stub!(:options).and_return [option]
|
|
175
|
+
should_receive(:radio_button)
|
|
176
|
+
field_form_renderer(@fsa,@field,@values)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "should have a text_area tag if the type is textarea" do
|
|
180
|
+
field_form_renderer(@fsa,@field,@values).should satisfy {
|
|
181
|
+
|x| !x.select{ |v| v =~ /<textarea/ }.nil?
|
|
182
|
+
}
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "should call date_select if the type is date" do
|
|
186
|
+
@field.stub!(:field_type).and_return 'date'
|
|
187
|
+
should_receive(:date_select)
|
|
188
|
+
field_form_renderer(@fsa,@field,@values)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should call datetime_select if the type is datetime" do
|
|
192
|
+
@field.stub!(:field_type).and_return 'datetime'
|
|
193
|
+
should_receive(:datetime_select)
|
|
194
|
+
field_form_renderer(@fsa,@field,@values)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
it "should return an array of html" do
|
|
199
|
+
field_form_renderer(@fsa,@field,@values).should be_a_kind_of Array
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe "field_show_renderer method" do
|
|
204
|
+
before(:each) do
|
|
205
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
206
|
+
@field = Field.new
|
|
207
|
+
@field.stub!(:id).and_return 420
|
|
208
|
+
@values = []
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it "should return an array of strings" do
|
|
212
|
+
result = field_show_renderer(@fsa, @field, @values)
|
|
213
|
+
result.should be_a_kind_of Array
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "should include the class dynamic_fieldsets_field" do
|
|
217
|
+
field_show_renderer(@fsa, @field, @values).join().should match /dynamic_fieldsets_field/
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should include the class dynamic_fieldsets_field_label" do
|
|
221
|
+
field_show_renderer(@fsa, @field, @values).join().should match /dynamic_fieldsets_field_label/
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "should include the class dynamic_fieldsets_field_value" do
|
|
225
|
+
field_show_renderer(@fsa, @field, @values).join().should match /dynamic_fieldsets_field_value/
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "should return 'No answer given' if the field has no answer for the current fieldset associator" do
|
|
229
|
+
field_show_renderer(@fsa, @field, nil).join().should match /No answer given/
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
describe "field_renderer method" do
|
|
234
|
+
before(:each) do
|
|
235
|
+
@fsa = mock_model(FieldsetAssociator)
|
|
236
|
+
@field = Field.new
|
|
237
|
+
@values = []
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "should call the form helper if the form_type is form" do
|
|
241
|
+
self.should_receive(:field_form_renderer)
|
|
242
|
+
field_renderer(@fsa, @field, @values, "form")
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "should default to the show helper if the form_type is not form" do
|
|
246
|
+
self.should_receive(:field_show_renderer)
|
|
247
|
+
field_renderer(@fsa, @field, @values, "show")
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
describe "populate method" do
|
|
252
|
+
it "needs tests"
|
|
253
|
+
end
|
|
254
|
+
end
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
include DynamicFieldsets
|
|
4
|
+
|
|
5
|
+
describe DynamicFieldsetsInModel do
|
|
6
|
+
|
|
7
|
+
it "should respond to acts_as_dynamic_fieldset" do
|
|
8
|
+
InformationForm.should respond_to :acts_as_dynamic_fieldset
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should respond to fieldset_associator" do
|
|
12
|
+
InformationForm.new.should respond_to :fieldset
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should respond to fieldset" do
|
|
16
|
+
InformationForm.new.should respond_to :fieldset_associator
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "acts_as_dynamic_fieldset class method" do
|
|
20
|
+
before(:each) do
|
|
21
|
+
@model = InformationForm.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should initialize the dynamic_fieldsets field" do
|
|
25
|
+
@model.should respond_to :dynamic_fieldsets
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should include the instance methods" do
|
|
29
|
+
@model.should be_a_kind_of (DynamicFieldsets::DynamicFieldsetsInModel::InstanceMethods)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "method missing method" do
|
|
34
|
+
before(:each) do
|
|
35
|
+
@model = InformationForm.new
|
|
36
|
+
@model.stub!(:fieldset_associator)
|
|
37
|
+
@model.stub!(:fieldset)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should call match_fieldset_associator?" do
|
|
41
|
+
@model.should_receive(:match_fieldset_associator?).and_return(true)
|
|
42
|
+
@model.some_method
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should call fieldset_associator if match_fieldset_associator? returns true" do
|
|
46
|
+
@model.stub!(:match_fieldset_associator?).and_return(true)
|
|
47
|
+
@model.should_receive(:fieldset_associator)
|
|
48
|
+
@model.some_method
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should call match_fieldset?" do
|
|
52
|
+
@model.stub!(:match_fieldset_associator?).and_return(false)
|
|
53
|
+
@model.should_receive(:match_fieldset?).and_return(true)
|
|
54
|
+
@model.some_method
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should call fieldset if match_fieldset? returns true" do
|
|
58
|
+
@model.stub!(:match_fieldset_associator?).and_return(false)
|
|
59
|
+
@model.stub!(:match_fieldset?).and_return(true)
|
|
60
|
+
@model.should_receive(:fieldset)
|
|
61
|
+
@model.some_method
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "respond_to? method" do
|
|
66
|
+
before(:each) do
|
|
67
|
+
@model = InformationForm.new
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should call match_fieldset_associator?" do
|
|
71
|
+
@model.should_receive(:match_fieldset_associator?)
|
|
72
|
+
@model.respond_to?(:some_method)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should call match_fieldset?" do
|
|
76
|
+
@model.stub!(:match_fieldset_associator?).and_return(false)
|
|
77
|
+
@model.should_receive(:match_fieldset?)
|
|
78
|
+
@model.respond_to?(:some_method)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "match_fieldset_associator? method" do
|
|
83
|
+
before(:each) do
|
|
84
|
+
@model = InformationForm.new
|
|
85
|
+
@model.stub!(:dynamic_fieldsets).and_return({:child_form => []})
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should call dynamic_fieldsets" do
|
|
89
|
+
@model.should_receive(:dynamic_fieldsets).and_return({:child_form => []})
|
|
90
|
+
@model.match_fieldset_associator?(:some_method)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should return true if the sym parameter matches a key in dynamic_fieldsets" do
|
|
94
|
+
@model.match_fieldset_associator?(:child_form).should be_true
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should return false if the sym parameter does not match a key in dynamic_fieldsets" do
|
|
98
|
+
@model.match_fieldset_associator?(:not_child_form).should be_false
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# need to be abvle to call child_form_fieldset to get the fieldset object
|
|
103
|
+
# because child_form does not exist in the fsa model until after it is created
|
|
104
|
+
describe "match_fieldset? method" do
|
|
105
|
+
before(:each) do
|
|
106
|
+
@model = InformationForm.new
|
|
107
|
+
@model.stub!(:dynamic_fieldsets).and_return({:child_form => []})
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should call dynamic_fieldsets if the calling method includes _fieldset" do
|
|
111
|
+
@model.should_receive(:dynamic_fieldsets).and_return({:child_form => []})
|
|
112
|
+
@model.match_fieldset?(:some_method_fieldset)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should return true if the sym parameter matches a key in dynamic_fieldsets followed by the word fieldset" do
|
|
116
|
+
@model.match_fieldset?(:child_form_fieldset).should be_true
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should return false if the sym parameter does not match a key in dynamic_fieldsets followed by the word fieldset" do
|
|
120
|
+
@model.match_fieldset?(:not_child_form_fieldset).should be_false
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "should return false if the sym parameter matches a key in dynamic_fieldsets not followed by the word fieldset" do
|
|
124
|
+
@model.match_fieldset?(:child_form).should be_false
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
describe "fieldset_associator method" do
|
|
129
|
+
before(:each) do
|
|
130
|
+
@model = InformationForm.new
|
|
131
|
+
@model.stub!(:dynamic_fieldsets).and_return({:child_form => {:fieldset => :fingerprint_form}})
|
|
132
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new(:fieldset_model_id => 1234, :fieldset_model_type => "InformationForm", :fieldset_model_name => :child_form)
|
|
133
|
+
DynamicFieldsets::FieldsetAssociator.stub!(:find_by_fieldset_model_parameters).and_return(@fsa)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should return the fieldset associator object for the specified dynamic fieldset" do
|
|
137
|
+
DynamicFieldsets::FieldsetAssociator.should_receive(:find_by_fieldset_model_parameters).and_return([@fsa])
|
|
138
|
+
@model.fieldset_associator(:child_form).should == @fsa
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "should create a new fieldset associator object if one does not exist" do
|
|
142
|
+
DynamicFieldsets::FieldsetAssociator.stub!(:find_by_fieldset_model_parameters).and_return([])
|
|
143
|
+
DynamicFieldsets::FieldsetAssociator.stub!(:create).and_return(@fsa)
|
|
144
|
+
|
|
145
|
+
# don't know why I need this, should be handled by the create stub
|
|
146
|
+
@model.fieldset_associator(:child_form).should == @fsa
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "should return nil if the sym param does not match a key in the dynamic_fieldsets field" do
|
|
150
|
+
@model.fieldset_associator(:not_child_form).should be_nil
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe "fieldset method" do
|
|
155
|
+
before(:each) do
|
|
156
|
+
@model = InformationForm.new
|
|
157
|
+
@model.stub!(:dynamic_fieldsets).and_return({:child_form => {:fieldset => :fingerprint_form}})
|
|
158
|
+
@fieldset = DynamicFieldsets::Fieldset.new(:nkey => :fingerprint_form)
|
|
159
|
+
DynamicFieldsets::Fieldset.stub!(:find_by_nkey).and_return(@fieldset)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should call find_by_nkey for the fieldset model" do
|
|
163
|
+
DynamicFieldsets::Fieldset.should_receive(:find_by_nkey).and_return(@fieldset)
|
|
164
|
+
@model.fieldset(:child_form)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "should return the fieldset object for the specified dynamic fieldset" do
|
|
168
|
+
@model.fieldset(:child_form).should == @fieldset
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "should return nil if the sym param does not match a kyer in the dynamic_fieldsets field" do
|
|
172
|
+
@model.fieldset(:not_child_form).should be_nil
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe FieldDefault do
|
|
5
|
+
include FieldDefaultHelper
|
|
6
|
+
|
|
7
|
+
it "should respond to field" do
|
|
8
|
+
field_default = FieldDefault.new
|
|
9
|
+
field_default.should respond_to :field
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "validations" do
|
|
13
|
+
before(:each) do
|
|
14
|
+
@field_default = FieldDefault.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be valid" do
|
|
18
|
+
@field_default.attributes = valid_attributes
|
|
19
|
+
@field_default.should be_valid
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should require a label" do
|
|
23
|
+
@field_default.should have(1).error_on(:value)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe FieldHtmlAttribute do
|
|
5
|
+
include FieldHtmlAttributeHelper
|
|
6
|
+
|
|
7
|
+
it "should respond to field" do
|
|
8
|
+
field_html_attribute = FieldHtmlAttribute.new
|
|
9
|
+
field_html_attribute.should respond_to :field
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "validations" do
|
|
13
|
+
before(:each) do
|
|
14
|
+
@field_html_attribute = FieldHtmlAttribute.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be valid" do
|
|
18
|
+
@field_html_attribute.attributes = valid_attributes
|
|
19
|
+
@field_html_attribute.should be_valid
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should require an attribute" do
|
|
23
|
+
@field_html_attribute.should have(1).error_on(:attribute_name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should require a value" do
|
|
27
|
+
@field_html_attribute.should have(1).error_on(:value)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe FieldOption do
|
|
5
|
+
include FieldOptionHelper
|
|
6
|
+
|
|
7
|
+
it "should respond to field" do
|
|
8
|
+
field_option = FieldOption.new
|
|
9
|
+
field_option.should respond_to :field
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "validations" do
|
|
13
|
+
before(:each) do
|
|
14
|
+
@field_option = FieldOption.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should be valid" do
|
|
18
|
+
@field_option.attributes = valid_attributes
|
|
19
|
+
@field_option.should be_valid
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should require a name" do
|
|
23
|
+
@field_option.should have(1).error_on(:name)
|
|
24
|
+
end
|
|
25
|
+
it "should require enabled is a boolean value" do
|
|
26
|
+
@field_option.enabled = nil
|
|
27
|
+
@field_option.should have(1).error_on(:enabled)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "enabled scope" do
|
|
32
|
+
before(:each) do
|
|
33
|
+
@field_option1 = FieldOption.new
|
|
34
|
+
@field_option1.attributes = valid_attributes
|
|
35
|
+
@field_option1.enabled = true
|
|
36
|
+
@field_option1.save
|
|
37
|
+
|
|
38
|
+
@field_option2 = FieldOption.new
|
|
39
|
+
@field_option2.attributes = valid_attributes
|
|
40
|
+
@field_option2.enabled = false
|
|
41
|
+
@field_option2.save
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should return enabled field options" do
|
|
45
|
+
FieldOption.enabled.should include @field_option1
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should not return disabled field options" do
|
|
49
|
+
FieldOption.enabled.should_not include @field_option2
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe FieldRecord do
|
|
5
|
+
include FieldRecordHelper
|
|
6
|
+
|
|
7
|
+
it "should respond to field" do
|
|
8
|
+
FieldRecord.new.should respond_to :field
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should respond to fieldset_associator" do
|
|
12
|
+
FieldRecord.new.should respond_to :fieldset_associator
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "validations" do
|
|
16
|
+
before(:each) do
|
|
17
|
+
@field_record = FieldRecord.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should be valid" do
|
|
21
|
+
@field_record.field = Field.new
|
|
22
|
+
@field_record.fieldset_associator = FieldsetAssociator.new
|
|
23
|
+
@field_record.value = "42"
|
|
24
|
+
@field_record.should be_valid
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should require field" do
|
|
28
|
+
@field_record.should have(1).error_on(:field)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should require fieldset_associator" do
|
|
32
|
+
@field_record.should have(1).error_on(:fieldset_associator)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should require value" do
|
|
36
|
+
@field_record.should have(1).error_on(:value)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should not error if value is a blank string" do
|
|
40
|
+
@field_record.value = ""
|
|
41
|
+
@field_record.should have(0).error_on(:value)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|