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
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
include DynamicFieldsets
|
|
3
2
|
|
|
4
|
-
describe FieldsetAssociator do
|
|
3
|
+
describe DynamicFieldsets::FieldsetAssociator do
|
|
5
4
|
include FieldsetAssociatorHelper
|
|
6
5
|
|
|
7
6
|
it "should respond to fieldset" do
|
|
8
|
-
FieldsetAssociator.new.should respond_to :fieldset
|
|
7
|
+
DynamicFieldsets::FieldsetAssociator.new.should respond_to :fieldset
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
it "should respond to field_records" do
|
|
12
|
-
FieldsetAssociator.new.should respond_to :field_records
|
|
11
|
+
DynamicFieldsets::FieldsetAssociator.new.should respond_to :field_records
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
describe "validations" do
|
|
16
15
|
before(:each) do
|
|
17
|
-
@fsa = FieldsetAssociator.new
|
|
16
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
it "should be valid" do
|
|
@@ -41,46 +40,47 @@ describe FieldsetAssociator do
|
|
|
41
40
|
it "should error require a unique field model, field model name pair" do
|
|
42
41
|
@fsa.attributes = valid_attributes
|
|
43
42
|
@fsa.save
|
|
44
|
-
fsa2 = FieldsetAssociator.new
|
|
43
|
+
fsa2 = DynamicFieldsets::FieldsetAssociator.new
|
|
45
44
|
fsa2.should have(1).error_on(:fieldset_model_name)
|
|
46
45
|
end
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
describe "find_by_fieldset_model_parameters" do
|
|
50
49
|
before(:each) do
|
|
51
|
-
@fieldset = mock_model(Fieldset)
|
|
50
|
+
@fieldset = mock_model(DynamicFieldsets::Fieldset)
|
|
52
51
|
@fieldset.stub!(:nkey).and_return(":hire_form")
|
|
53
52
|
@fieldset.stub!(:id).and_return(1)
|
|
54
|
-
@fsa = FieldsetAssociator.create(valid_attributes)
|
|
53
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.create(valid_attributes)
|
|
55
54
|
|
|
56
55
|
@fieldset_model_attributes = valid_attributes
|
|
57
56
|
@fieldset_model_attributes[:fieldset] = :hire_form
|
|
58
57
|
end
|
|
59
58
|
|
|
60
59
|
it "should respond to find_by_fieldset_model_parameters" do
|
|
61
|
-
FieldsetAssociator.should respond_to :find_by_fieldset_model_parameters
|
|
60
|
+
DynamicFieldsets::FieldsetAssociator.should respond_to :find_by_fieldset_model_parameters
|
|
62
61
|
end
|
|
63
62
|
|
|
64
|
-
it "should call Fieldset find_by_nkey" do
|
|
65
|
-
Fieldset.should_receive(:find_by_nkey).and_return(@fieldset)
|
|
66
|
-
FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes)
|
|
63
|
+
it "should call DynamicFieldsets::Fieldset find_by_nkey" do
|
|
64
|
+
DynamicFieldsets::Fieldset.should_receive(:find_by_nkey).and_return(@fieldset)
|
|
65
|
+
DynamicFieldsets::FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes)
|
|
67
66
|
end
|
|
68
67
|
|
|
69
68
|
it "should throw an error if the fieldset does not exist" do
|
|
70
|
-
Fieldset.stub!(:find_by_nkey).and_return(nil)
|
|
71
|
-
lambda { FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes) }.should raise_error
|
|
69
|
+
DynamicFieldsets::Fieldset.stub!(:find_by_nkey).and_return(nil)
|
|
70
|
+
lambda { DynamicFieldsets::FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes) }.should raise_error
|
|
72
71
|
end
|
|
73
72
|
|
|
74
73
|
it "should return the correct fieldset associator" do
|
|
75
|
-
Fieldset.stub!(:find_by_nkey).and_return(@fieldset)
|
|
74
|
+
DynamicFieldsets::Fieldset.stub!(:find_by_nkey).and_return(@fieldset)
|
|
76
75
|
# this is a fun hack because of all the fsas being made during tests
|
|
77
|
-
FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes).should include @fsa
|
|
76
|
+
DynamicFieldsets::FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes).should include @fsa
|
|
78
77
|
end
|
|
79
78
|
end
|
|
80
79
|
|
|
81
80
|
describe "field_values method" do
|
|
82
81
|
before(:each) do
|
|
83
|
-
|
|
82
|
+
pending "this method was completely rewritten. Most of the functionality was moved to other models."
|
|
83
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new
|
|
84
84
|
|
|
85
85
|
@field = mock_model DynamicFieldsets::Field
|
|
86
86
|
@fieldset_child = mock_model DynamicFieldsets::FieldsetChild
|
|
@@ -95,7 +95,7 @@ describe FieldsetAssociator do
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it "returns a hash" do
|
|
98
|
-
@fieldset_child.child.stub!(:
|
|
98
|
+
@fieldset_child.child.stub!(:type).and_return ''
|
|
99
99
|
@fsa.field_values.should be_a_kind_of Hash
|
|
100
100
|
end
|
|
101
101
|
|
|
@@ -107,27 +107,27 @@ describe FieldsetAssociator do
|
|
|
107
107
|
# I am aware these two tests aren't really realistic because ids should be different
|
|
108
108
|
# Results should be consistent with these when ids are different
|
|
109
109
|
it "returns multiple select values as an array of ids" do
|
|
110
|
-
@fieldset_child.child.stub!(:
|
|
110
|
+
@fieldset_child.child.stub!(:type).and_return 'multiple_select'
|
|
111
111
|
@fsa.field_values.should == { 37 => [42, 42] }
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
it "returns checkboxes values as an array of ids" do
|
|
115
|
-
@field.stub!(:
|
|
115
|
+
@field.stub!(:type).and_return 'checkbox'
|
|
116
116
|
@fsa.field_values.should == { 37 => [42, 42] }
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
it "returns select values as an id" do
|
|
120
|
-
@field.stub!(:
|
|
120
|
+
@field.stub!(:type).and_return 'select'
|
|
121
121
|
@fsa.field_values.should == { 37 => 42 }
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
it "returns radio values as an id" do
|
|
125
|
-
@field.stub!(:
|
|
125
|
+
@field.stub!(:type).and_return 'radio'
|
|
126
126
|
@fsa.field_values.should == { 37 => 42 }
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
it "returns all other field types as strings" do
|
|
130
|
-
@field.stub!(:
|
|
130
|
+
@field.stub!(:type).and_return 'textfield'
|
|
131
131
|
@field_record.stub!(:value).and_return 'forty two'
|
|
132
132
|
@fsa.field_values.should == { 37 => "forty two" }
|
|
133
133
|
end
|
|
@@ -136,12 +136,12 @@ describe FieldsetAssociator do
|
|
|
136
136
|
# these tests seem silly when they don't hit the database
|
|
137
137
|
describe "field_records_by_field_name method" do
|
|
138
138
|
before(:each) do
|
|
139
|
-
@fieldset = Fieldset.new
|
|
140
|
-
@field = Field.new(:name => "test_field")
|
|
141
|
-
@child = FieldsetChild.new(:fieldset => @fieldset, :child => @field)
|
|
139
|
+
@fieldset = DynamicFieldsets::Fieldset.new
|
|
140
|
+
@field = DynamicFieldsets::Field.new(:name => "test_field")
|
|
141
|
+
@child = DynamicFieldsets::FieldsetChild.new(:fieldset => @fieldset, :child => @field)
|
|
142
142
|
|
|
143
|
-
@fsa = FieldsetAssociator.new(:fieldset => @fieldset)
|
|
144
|
-
@record = FieldRecord.new(:fieldset_child => @child)
|
|
143
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new(:fieldset => @fieldset)
|
|
144
|
+
@record = DynamicFieldsets::FieldRecord.new(:fieldset_child => @child)
|
|
145
145
|
|
|
146
146
|
@fsa.stub!(:field_records).and_return([@record])
|
|
147
147
|
end
|
|
@@ -157,22 +157,22 @@ describe FieldsetAssociator do
|
|
|
157
157
|
|
|
158
158
|
describe "dependency_child_hash and look_for_dependents" do
|
|
159
159
|
before(:each) do
|
|
160
|
-
@fsa = FieldsetAssociator.new
|
|
160
|
+
@fsa = DynamicFieldsets::FieldsetAssociator.new
|
|
161
161
|
|
|
162
|
-
@fieldset1 = Fieldset.new
|
|
162
|
+
@fieldset1 = DynamicFieldsets::Fieldset.new
|
|
163
163
|
@fieldset1.stub!(:id).and_return(100)
|
|
164
|
-
@fieldset2 = Fieldset.new
|
|
164
|
+
@fieldset2 = DynamicFieldsets::Fieldset.new
|
|
165
165
|
@fieldset2.stub!(:id).and_return(200)
|
|
166
166
|
|
|
167
|
-
@field1 = Field.new
|
|
167
|
+
@field1 = DynamicFieldsets::Field.new
|
|
168
168
|
@field1.stub!(:id).and_return(100)
|
|
169
|
-
@field2 = Field.new
|
|
169
|
+
@field2 = DynamicFieldsets::Field.new
|
|
170
170
|
@field2.stub!(:id).and_return(200)
|
|
171
171
|
|
|
172
172
|
@fsa.stub!(:fieldset_id).and_return(100)
|
|
173
173
|
@fsa.stub!(:fieldset).and_return(@fieldset1)
|
|
174
174
|
|
|
175
|
-
@fsc1 = FieldsetChild.new
|
|
175
|
+
@fsc1 = DynamicFieldsets::FieldsetChild.new
|
|
176
176
|
@fsc1.stub!(:id).and_return(100)
|
|
177
177
|
@fsc1.stub!(:fieldset_id).and_return(@fieldset1.id)
|
|
178
178
|
@fsc1.stub!(:child_id).and_return(@fieldset2.id)
|
|
@@ -180,14 +180,14 @@ describe FieldsetAssociator do
|
|
|
180
180
|
@fsc1.stub!(:child).and_return(@fieldset2)
|
|
181
181
|
@fieldset1.stub!(:fieldset_children).and_return([@fsc1])
|
|
182
182
|
|
|
183
|
-
@fsc2 = FieldsetChild.new
|
|
183
|
+
@fsc2 = DynamicFieldsets::FieldsetChild.new
|
|
184
184
|
@fsc2.stub!(:id).and_return(200)
|
|
185
185
|
@fsc2.stub!(:fieldset_id).and_return(@fieldset2.id)
|
|
186
186
|
@fsc2.stub!(:child_id).and_return(@field1.id)
|
|
187
187
|
@fsc2.stub!(:child_type).and_return("DynamicFieldsets::Field")
|
|
188
188
|
@fsc2.stub!(:child).and_return(@field1)
|
|
189
189
|
|
|
190
|
-
@fsc3 = FieldsetChild.new
|
|
190
|
+
@fsc3 = DynamicFieldsets::FieldsetChild.new
|
|
191
191
|
@fsc3.stub!(:id).and_return(300)
|
|
192
192
|
@fsc3.stub!(:fieldset_id).and_return(@fieldset2.id)
|
|
193
193
|
@fsc3.stub!(:child_id).and_return(@field2.id)
|
|
@@ -196,19 +196,19 @@ describe FieldsetAssociator do
|
|
|
196
196
|
|
|
197
197
|
@fieldset2.stub!(:fieldset_children).and_return([@fsc2, @fsc3])
|
|
198
198
|
|
|
199
|
-
@group = DependencyGroup.new
|
|
199
|
+
@group = DynamicFieldsets::DependencyGroup.new
|
|
200
200
|
@group.stub!(:id).and_return(100)
|
|
201
201
|
@group.stub!(:fieldset_child_id).and_return(@fsc3.id)
|
|
202
202
|
@group.stub!(:fieldset_child).and_return(@fsc3)
|
|
203
203
|
@group.stub!(:action).and_return("show")
|
|
204
204
|
|
|
205
|
-
@clause = DependencyClause.new
|
|
205
|
+
@clause = DynamicFieldsets::DependencyClause.new
|
|
206
206
|
@clause.stub!(:id).and_return(100)
|
|
207
207
|
@clause.stub!(:dependency_group).and_return(@group)
|
|
208
208
|
@clause.stub!(:dependency_group_id).and_return(@group.id)
|
|
209
209
|
@group.stub!(:dependency_clauses).and_return([@clause])
|
|
210
210
|
|
|
211
|
-
@dependency = Dependency.new
|
|
211
|
+
@dependency = DynamicFieldsets::Dependency.new
|
|
212
212
|
@dependency.stub!(:id).and_return(100)
|
|
213
213
|
@dependency.stub!(:value).and_return(5)
|
|
214
214
|
@dependency.stub!(:relationship).and_return("equals")
|
|
@@ -266,7 +266,5 @@ describe FieldsetAssociator do
|
|
|
266
266
|
}
|
|
267
267
|
@fsa.dependency_child_hash.should == expected_results
|
|
268
268
|
end
|
|
269
|
-
|
|
270
269
|
end
|
|
271
|
-
|
|
272
270
|
end
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
include DynamicFieldsets
|
|
3
2
|
|
|
4
|
-
describe FieldsetChild do
|
|
3
|
+
describe DynamicFieldsets::FieldsetChild do
|
|
5
4
|
include FieldsetChildHelper
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
FieldsetChild.new
|
|
6
|
+
before do
|
|
7
|
+
@child = DynamicFieldsets::FieldsetChild.new
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
FieldsetChild.new.should respond_to :child
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "should respond to dependency_group" do
|
|
16
|
-
FieldsetChild.new.should respond_to :dependency_group
|
|
17
|
-
end
|
|
10
|
+
subject { @child }
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
describe "fields" do
|
|
13
|
+
it { should respond_to :fieldset_id }
|
|
14
|
+
it { should respond_to :child_id }
|
|
15
|
+
it { should respond_to :child_type }
|
|
16
|
+
it { should respond_to :order_num }
|
|
21
17
|
end
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
describe "associations" do
|
|
20
|
+
before do
|
|
21
|
+
pending "can't get shoulda working"
|
|
22
|
+
end
|
|
23
|
+
it { should belong_to :child }
|
|
24
|
+
it { should belong_to :fieldset }
|
|
25
|
+
it { should have_many :field_records }
|
|
26
|
+
it { should have_one :dependency_group }
|
|
27
|
+
it { should have_many :dependencies }
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
describe "validations" do
|
|
28
31
|
before(:each) do
|
|
29
|
-
@fieldset_child = FieldsetChild.new
|
|
32
|
+
@fieldset_child = DynamicFieldsets::FieldsetChild.new
|
|
30
33
|
end
|
|
31
34
|
it "are valid" do
|
|
32
35
|
@fieldset_child.attributes = valid_attributes
|
|
@@ -47,56 +50,94 @@ describe FieldsetChild do
|
|
|
47
50
|
@fieldset_child.should have(1).error_on(:order_num)
|
|
48
51
|
end
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
describe "validates includsion of child type" do
|
|
54
|
+
it "should allow a child type of 'DynamicFieldsets::Field'" do
|
|
55
|
+
@fieldset_child.child_type = "DynamicFieldsets::Field"
|
|
56
|
+
@fieldset_child.should have(0).error_on(:child_type)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should allow a child type of 'DynamicFieldsets::Fieldset'" do
|
|
60
|
+
@fieldset_child.child_type = "DynamicFieldsets::Fieldset"
|
|
61
|
+
@fieldset_child.should have(0).error_on(:child_type)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should not allow a child type if not 'DynamicFieldsets::Field' or 'DynamicFieldsets::Fieldset'" do
|
|
65
|
+
@fieldset_child.child_type = "Not Field or Fieldset"
|
|
66
|
+
@fieldset_child.should have(1).error_on(:child_type)
|
|
67
|
+
end
|
|
53
68
|
end
|
|
54
69
|
|
|
55
|
-
it "should
|
|
56
|
-
@fieldset_child.
|
|
57
|
-
@fieldset_child.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
it "should not allow a child type if not 'DynamicFieldsets::Field' or 'DynamicFieldsets::Fieldset'" do
|
|
61
|
-
@fieldset_child.child_type = "Not Field or Fieldset"
|
|
62
|
-
@fieldset_child.should have(1).error_on(:child_type)
|
|
70
|
+
it "should call these additional validators" do
|
|
71
|
+
@fieldset_child.should_receive(:no_duplicate_fields_in_fieldset_children)
|
|
72
|
+
@fieldset_child.should_receive(:cannot_be_own_parent)
|
|
73
|
+
@fieldset_child.should_receive(:no_parental_loop)
|
|
74
|
+
@fieldset_child.valid?
|
|
63
75
|
end
|
|
64
76
|
|
|
77
|
+
# no_duplicate_fields_in_fieldset_children
|
|
65
78
|
it "should not allow duplicate pairings of fieldsets and fields" do
|
|
66
|
-
fieldset = Fieldset.new
|
|
67
|
-
field = Field.new
|
|
79
|
+
fieldset = DynamicFieldsets::Fieldset.new
|
|
80
|
+
field = DynamicFieldsets::Field.new
|
|
68
81
|
field.stub!(:id).and_return(100)
|
|
69
|
-
fieldset_child1 = FieldsetChild.new(:fieldset => fieldset, :child => field, :order_num => 1)
|
|
82
|
+
fieldset_child1 = DynamicFieldsets::FieldsetChild.new(:fieldset => fieldset, :child => field, :order_num => 1)
|
|
70
83
|
fieldset_child1.stub!(:id).and_return(100)
|
|
71
|
-
fieldset_child2 = FieldsetChild.new(:fieldset => fieldset, :child => field, :order_num => 2)
|
|
72
|
-
FieldsetChild.stub!(:where).and_return([fieldset_child1])
|
|
84
|
+
fieldset_child2 = DynamicFieldsets::FieldsetChild.new(:fieldset => fieldset, :child => field, :order_num => 2)
|
|
85
|
+
DynamicFieldsets::FieldsetChild.stub!(:where).and_return([fieldset_child1])
|
|
73
86
|
fieldset_child2.should have(1).error_on(:child_id)
|
|
74
87
|
end
|
|
75
88
|
|
|
89
|
+
# cannot_be_own_parent
|
|
76
90
|
# this should have two errors, because it's also a loop
|
|
77
91
|
it "cannot be it's own parent" do
|
|
78
|
-
fieldset = Fieldset.new
|
|
92
|
+
fieldset = DynamicFieldsets::Fieldset.new
|
|
79
93
|
fieldset.stub!(:id).and_return(100)
|
|
80
|
-
fieldset_child = FieldsetChild.new(:fieldset_id => fieldset.id, :child => fieldset, :order_num => 1)
|
|
94
|
+
fieldset_child = DynamicFieldsets::FieldsetChild.new(:fieldset_id => fieldset.id, :child => fieldset, :order_num => 1)
|
|
81
95
|
fieldset_child.should have(2).error_on(:child_id)
|
|
82
96
|
end
|
|
83
97
|
|
|
98
|
+
# no_parental_loop
|
|
84
99
|
it "should not allow a parent fieldset when it would create a cycle" do
|
|
85
|
-
fieldset1 = Fieldset.new
|
|
100
|
+
fieldset1 = DynamicFieldsets::Fieldset.new
|
|
86
101
|
fieldset1.stub!(:id).and_return(100)
|
|
87
|
-
fieldset2 = Fieldset.new
|
|
102
|
+
fieldset2 = DynamicFieldsets::Fieldset.new
|
|
88
103
|
fieldset2.stub!(:id).and_return(200)
|
|
89
|
-
fieldset3 = Fieldset.new
|
|
104
|
+
fieldset3 = DynamicFieldsets::Fieldset.new
|
|
90
105
|
fieldset3.stub!(:id).and_return(300)
|
|
91
|
-
fieldset_child1 = FieldsetChild.create(:fieldset_id => fieldset1.id, :child => fieldset2, :order_num => 1)
|
|
92
|
-
fieldset_child2 = FieldsetChild.create(:fieldset_id => fieldset2.id, :child => fieldset3, :order_num => 1)
|
|
93
|
-
fieldset_child3 = FieldsetChild.new(:fieldset_id => fieldset3.id, :child => fieldset1, :order_num => 1)
|
|
106
|
+
fieldset_child1 = DynamicFieldsets::FieldsetChild.create(:fieldset_id => fieldset1.id, :child => fieldset2, :order_num => 1)
|
|
107
|
+
fieldset_child2 = DynamicFieldsets::FieldsetChild.create(:fieldset_id => fieldset2.id, :child => fieldset3, :order_num => 1)
|
|
108
|
+
fieldset_child3 = DynamicFieldsets::FieldsetChild.new(:fieldset_id => fieldset3.id, :child => fieldset1, :order_num => 1)
|
|
94
109
|
fieldset_child3.should have(1).error_on(:child_id)
|
|
95
110
|
end
|
|
96
111
|
end
|
|
97
112
|
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
# Scopes and static methods
|
|
114
|
+
it { DynamicFieldsets::FieldsetChild.should respond_to(:ordered) }
|
|
115
|
+
describe ".ordered scope" do
|
|
116
|
+
it "needs tests"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Methods
|
|
120
|
+
|
|
121
|
+
it { should respond_to :children }
|
|
122
|
+
describe ".children" do
|
|
123
|
+
it "needs tests"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it { should respond_to :fieldset_child_list }
|
|
127
|
+
describe ".fieldset_child_list" do
|
|
128
|
+
it "should match the constant FIELDSET_CHILD_LIST" do
|
|
129
|
+
@child.fieldset_child_list.should == DynamicFieldsets::FieldsetChild::FIELDSET_CHILD_LIST
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it { should respond_to :get_value_using_fsa }
|
|
134
|
+
describe ".get_value_using_fsa" do
|
|
135
|
+
it "needs tests"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it { should respond_to :last_order_num }
|
|
139
|
+
describe ".last_order_num" do
|
|
140
|
+
it "needs tests"
|
|
100
141
|
end
|
|
101
142
|
|
|
102
143
|
describe "root_fieldset method" do
|
|
@@ -104,12 +145,12 @@ describe FieldsetChild do
|
|
|
104
145
|
# too many issues with stubbing, getting lazy and saving
|
|
105
146
|
# could be refactored at some point
|
|
106
147
|
|
|
107
|
-
@field = Field.create({ :name => "Test field name", :label => "Test field label", :
|
|
108
|
-
@fieldset = Fieldset.create({:name => "Hire Form", :description => "Hire a person for a job", :nkey => "hire_form"})
|
|
109
|
-
@root_fieldset = Fieldset.create({:name => "Hire Form2", :description => "Hire a person for a job2", :nkey => "hire_form2"})
|
|
148
|
+
@field = DynamicFieldsets::Field.create({ :name => "Test field name", :label => "Test field label", :type => "textfield", :required => true, :enabled => true, })
|
|
149
|
+
@fieldset = DynamicFieldsets::Fieldset.create({:name => "Hire Form", :description => "Hire a person for a job", :nkey => "hire_form"})
|
|
150
|
+
@root_fieldset = DynamicFieldsets::Fieldset.create({:name => "Hire Form2", :description => "Hire a person for a job2", :nkey => "hire_form2"})
|
|
110
151
|
|
|
111
|
-
@field_child = FieldsetChild.create(:child => @child, :fieldset => @fieldset, :order_num => 1)
|
|
112
|
-
@child = FieldsetChild.create(:child => @fieldset, :fieldset => @root_fieldset, :order_num => 2)
|
|
152
|
+
@field_child = DynamicFieldsets::FieldsetChild.create(:child => @child, :fieldset => @fieldset, :order_num => 1)
|
|
153
|
+
@child = DynamicFieldsets::FieldsetChild.create(:child => @fieldset, :fieldset => @root_fieldset, :order_num => 2)
|
|
113
154
|
end
|
|
114
155
|
it "should return a fieldset if it is not present as the child in fieldset child" do
|
|
115
156
|
@child.root_fieldset.should == @root_fieldset
|
|
@@ -119,4 +160,15 @@ describe FieldsetChild do
|
|
|
119
160
|
@field_child.root_fieldset.id.should == @root_fieldset.id
|
|
120
161
|
end
|
|
121
162
|
end
|
|
163
|
+
|
|
164
|
+
it { should respond_to :siblings }
|
|
165
|
+
describe ".siblings" do
|
|
166
|
+
it "needs tests"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it { should respond_to :to_hash }
|
|
170
|
+
describe "to_hash method" do
|
|
171
|
+
it "needs specs"
|
|
172
|
+
it "needs comments"
|
|
173
|
+
end
|
|
122
174
|
end
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe Fieldset do
|
|
2
|
+
|
|
3
|
+
describe DynamicFieldsets::Fieldset do
|
|
5
4
|
include FieldsetHelper
|
|
6
5
|
|
|
7
6
|
it "should respond to parent" do
|
|
8
|
-
Fieldset.new.should respond_to :parent
|
|
7
|
+
DynamicFieldsets::Fieldset.new.should respond_to :parent
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
it "should respond to child_fields" do
|
|
12
|
-
Fieldset.new.should respond_to :child_fields
|
|
11
|
+
DynamicFieldsets::Fieldset.new.should respond_to :child_fields
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
it "should respond to child_fieldsets" do
|
|
16
|
-
Fieldset.new.should respond_to :child_fieldsets
|
|
15
|
+
DynamicFieldsets::Fieldset.new.should respond_to :child_fieldsets
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
describe "validations" do
|
|
20
19
|
before(:each) do
|
|
21
|
-
@fieldset = Fieldset.new
|
|
20
|
+
@fieldset = DynamicFieldsets::Fieldset.new
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
it "should be valid" do
|
|
@@ -39,7 +38,7 @@ describe Fieldset do
|
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
it "should require a unique nkey" do
|
|
42
|
-
Fieldset.create(valid_attributes)
|
|
41
|
+
DynamicFieldsets::Fieldset.create(valid_attributes)
|
|
43
42
|
@fieldset.attributes = valid_attributes
|
|
44
43
|
@fieldset.should have(1).error_on(:nkey)
|
|
45
44
|
end
|
|
@@ -48,37 +47,37 @@ describe Fieldset do
|
|
|
48
47
|
describe ".roots scope" do
|
|
49
48
|
before(:each) do
|
|
50
49
|
# we could stub this one but I am not convinced the polymorphic relationships actually work
|
|
51
|
-
@root_fieldset = Fieldset.new( valid_attributes )
|
|
50
|
+
@root_fieldset = DynamicFieldsets::Fieldset.new( valid_attributes )
|
|
52
51
|
@root_fieldset.save
|
|
53
52
|
|
|
54
|
-
@child_fieldset = Fieldset.new( valid_attributes )
|
|
53
|
+
@child_fieldset = DynamicFieldsets::Fieldset.new( valid_attributes )
|
|
55
54
|
@child_fieldset.nkey = "something_else" # need to pass validations
|
|
56
55
|
@child_fieldset.save
|
|
57
56
|
|
|
58
|
-
@fieldset_children = FieldsetChild.new(:child => @child_fieldset, :fieldset => @root_fieldset, :order_num => 1)
|
|
57
|
+
@fieldset_children = DynamicFieldsets::FieldsetChild.new(:child => @child_fieldset, :fieldset => @root_fieldset, :order_num => 1)
|
|
59
58
|
@fieldset_children.save
|
|
60
59
|
end
|
|
61
60
|
|
|
62
|
-
it ": Fieldset responds to .roots" do
|
|
63
|
-
Fieldset.should respond_to :roots
|
|
61
|
+
it ": DynamicFieldsets::Fieldset responds to .roots" do
|
|
62
|
+
DynamicFieldsets::Fieldset.should respond_to :roots
|
|
64
63
|
end
|
|
65
64
|
|
|
66
65
|
it "returns fieldsets with no parent" do
|
|
67
|
-
roots = Fieldset.roots
|
|
66
|
+
roots = DynamicFieldsets::Fieldset.roots
|
|
68
67
|
roots.each do |root|
|
|
69
68
|
root.parent.should be_nil
|
|
70
69
|
end
|
|
71
70
|
end
|
|
72
71
|
|
|
73
72
|
it "does not return fieldsets with a parent" do
|
|
74
|
-
roots = Fieldset.roots
|
|
73
|
+
roots = DynamicFieldsets::Fieldset.roots
|
|
75
74
|
roots.should_not include @child_fieldset
|
|
76
75
|
end
|
|
77
76
|
end
|
|
78
77
|
|
|
79
78
|
describe ".root? method" do
|
|
80
79
|
before(:each) do
|
|
81
|
-
@fieldset = Fieldset.new
|
|
80
|
+
@fieldset = DynamicFieldsets::Fieldset.new
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
it "calls parent" do
|
|
@@ -98,7 +97,7 @@ describe Fieldset do
|
|
|
98
97
|
|
|
99
98
|
describe "parent_fieldset_list static method" do
|
|
100
99
|
it "should include values for any fieldset" do
|
|
101
|
-
fieldset = Fieldset.new(:name => "parent_fieldset_list test", :nkey => "parent_fieldset_list_test")
|
|
100
|
+
fieldset = DynamicFieldsets::Fieldset.new(:name => "parent_fieldset_list test", :nkey => "parent_fieldset_list_test")
|
|
102
101
|
fieldset.save(:validate => false)
|
|
103
102
|
DynamicFieldsets::Fieldset.parent_fieldset_list.should include [fieldset.name, fieldset.id]
|
|
104
103
|
end
|
|
@@ -107,31 +106,29 @@ describe Fieldset do
|
|
|
107
106
|
# gave up on stubs and mocks on this one due to how the data is constantized
|
|
108
107
|
describe "children method" do
|
|
109
108
|
before(:each) do
|
|
110
|
-
@root_fieldset = Fieldset.new( valid_attributes )
|
|
109
|
+
@root_fieldset = DynamicFieldsets::Fieldset.new( valid_attributes )
|
|
111
110
|
@root_fieldset.stub!(:id).and_return(1234)
|
|
112
111
|
|
|
113
|
-
@child_fieldset = Fieldset.new( valid_attributes )
|
|
112
|
+
@child_fieldset = DynamicFieldsets::Fieldset.new( valid_attributes )
|
|
114
113
|
@child_fieldset.nkey = "child_fieldset"
|
|
115
114
|
@child_fieldset.save
|
|
116
|
-
@cfs = FieldsetChild.new(:child => @child_fieldset, :fieldset => @root_fieldset, :order_num => 1)
|
|
115
|
+
@cfs = DynamicFieldsets::FieldsetChild.new(:child => @child_fieldset, :fieldset => @root_fieldset, :order_num => 1)
|
|
117
116
|
|
|
118
|
-
@field1 =
|
|
117
|
+
@field1 = DynamicFieldsets::TextField.new(
|
|
119
118
|
:name => "Test field name",
|
|
120
119
|
:label => "Test field label",
|
|
121
|
-
:field_type => "textfield",
|
|
122
120
|
:required => true,
|
|
123
121
|
:enabled => true)
|
|
124
|
-
@field1.save
|
|
125
|
-
@cf1 = FieldsetChild.new(:child => @field1, :fieldset => @root_fieldset, :order_num => 2)
|
|
122
|
+
@field1.save!
|
|
123
|
+
@cf1 = DynamicFieldsets::FieldsetChild.new(:child => @field1, :fieldset => @root_fieldset, :order_num => 2)
|
|
126
124
|
|
|
127
|
-
@field2 =
|
|
125
|
+
@field2 = DynamicFieldsets::TextField.new(
|
|
128
126
|
:name => "Test field name",
|
|
129
127
|
:label => "Test field label",
|
|
130
|
-
:field_type => "textfield",
|
|
131
128
|
:required => true,
|
|
132
129
|
:enabled => false)
|
|
133
|
-
@field2.save
|
|
134
|
-
@cf2 = FieldsetChild.new(:child => @field2, :fieldset => @root_fieldset, :order_num => 3)
|
|
130
|
+
@field2.save!
|
|
131
|
+
@cf2 = DynamicFieldsets::FieldsetChild.new(:child => @field2, :fieldset => @root_fieldset, :order_num => 3)
|
|
135
132
|
|
|
136
133
|
@root_fieldset_children = [@cfs, @cf1, @cf2]
|
|
137
134
|
@root_fieldset.stub!(:fieldset_children).and_return(@root_fieldset_children)
|
|
@@ -163,5 +160,4 @@ describe Fieldset do
|
|
|
163
160
|
children.last.should == @field1
|
|
164
161
|
end
|
|
165
162
|
end
|
|
166
|
-
|
|
167
163
|
end
|