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
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe DependencyGroup do
|
|
5
|
+
include DependencyGroupHelper
|
|
6
|
+
|
|
7
|
+
it "should respond to fieldset_child" do
|
|
8
|
+
DependencyGroup.new.should respond_to :fieldset_child
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should respond to dependency_clauses" do
|
|
12
|
+
DependencyGroup.new.should respond_to :dependency_clauses
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "validations" do
|
|
16
|
+
before(:each) do
|
|
17
|
+
@group = DependencyGroup.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should be valid" do
|
|
21
|
+
@group.attributes = valid_attributes
|
|
22
|
+
@group.should be_valid
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should require a fieldset_child" do
|
|
26
|
+
@group.should have(1).error_on(:fieldset_child_id)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should have an action" do
|
|
30
|
+
@group.should have(2).error_on(:action)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "action should be in Action_list" do
|
|
34
|
+
@group.action = "invalid action"
|
|
35
|
+
@group.should have(1).error_on(:action)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "action_list method" do
|
|
40
|
+
it "should return an hash" do
|
|
41
|
+
DependencyGroup.new.action_list.should be_a_kind_of(Hash)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "dependency_group_fieldset_chldren method" do
|
|
46
|
+
before(:each) do
|
|
47
|
+
@fieldset_child_1 = FieldsetChild.create(:fieldset_id => 1, :child_id => 1, :child_type => "DynamicFieldsets::Field", :order_num => 1)
|
|
48
|
+
@fieldset_child_2 = FieldsetChild.create(:fieldset_id => 2, :child_id => 2, :child_type => "DynamicFieldsets::Field", :order_num => 2)
|
|
49
|
+
@fieldset_child_3 = FieldsetChild.create(:fieldset_id => 3, :child_id => 3, :child_type => "DynamicFieldsets::Field", :order_num => 3)
|
|
50
|
+
@group = DependencyGroup.create(:fieldset_child => @fieldset_child_3, :action => "show")
|
|
51
|
+
@clause = DependencyClause.create(:dependency_group => @group)
|
|
52
|
+
@dependency_1 = Dependency.create(:fieldset_child => @fieldset_child_1, :dependency_clause => @clause, :value => "5", :relationship => "equals")
|
|
53
|
+
@dependency_2 = Dependency.create(:fieldset_child => @fieldset_child_2, :dependency_clause => @clause, :value => "5", :relationship => "equals")
|
|
54
|
+
@input_hash = JSON.parse(@group.dependency_group_fieldset_children)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should return a hash object once parsed from json" do
|
|
58
|
+
@input_hash.should be_a_kind_of(Hash)
|
|
59
|
+
end
|
|
60
|
+
it "should return an array of fieldset children that are tied to a dependency group through the dependency clause for the value" do
|
|
61
|
+
lambda{@input_hash.has_value?([@fieldset_child_1.id, @fieldset_child_2.id])}.should be_true
|
|
62
|
+
end
|
|
63
|
+
it "should return the dependency group's fieldset child for the key" do
|
|
64
|
+
@input_hash.has_key?(@fieldset_child_3.id.to_s).should be_true
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "dependent_fieldset_children method" do
|
|
69
|
+
before(:each) do
|
|
70
|
+
@group = DependencyGroup.new
|
|
71
|
+
@group.attributes = valid_attributes
|
|
72
|
+
@group.save
|
|
73
|
+
@clause = DependencyClause.create(:dependency_group => @group)
|
|
74
|
+
@dependency = Dependency.create(:value => 5, :relationship => "equals", :dependency_clause => @clause, :fieldset_child_id => 42)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should return an array" do
|
|
78
|
+
@group.dependent_fieldset_children.should be_a_kind_of(Array)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should return fieldset children ids included in the group" do
|
|
82
|
+
#debugger
|
|
83
|
+
@group.dependent_fieldset_children.should include 42
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should not return fieldset children ids not included in the group" do
|
|
87
|
+
@group.dependent_fieldset_children.should_not include 41
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "get_action method" do
|
|
92
|
+
before(:each) do
|
|
93
|
+
@group = DependencyGroup.new
|
|
94
|
+
@group.stub!(:evaluate).and_return(true)
|
|
95
|
+
@group.action = "show"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should take a hash as input" do
|
|
99
|
+
@group.get_action({}).should_not raise_error ArgumentError
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "should return the success action if evaluate returns true" do
|
|
103
|
+
@group.get_action({}).should == "show"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "should return the failure action if evaluate returns false" do
|
|
107
|
+
@group.stub!(:evaluate).and_return(false)
|
|
108
|
+
@group.get_action({}).should == "hide"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe "evaluate method" do
|
|
113
|
+
before(:each) do
|
|
114
|
+
@group = DependencyGroup.new
|
|
115
|
+
@clause1 = DependencyClause.new
|
|
116
|
+
@clause2 = DependencyClause.new
|
|
117
|
+
@group.stub!(:dependency_clauses).and_return([@clause1, @clause2])
|
|
118
|
+
@input_values = {}
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "should take a hash as input" do
|
|
122
|
+
@group.stub!(:dependency_clauses).and_return([])
|
|
123
|
+
@group.evaluate({}).should_not raise_error ArgumentError
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should return true if all the clauses evaluate to true" do
|
|
127
|
+
@clause1.stub!(:evaluate).and_return(true)
|
|
128
|
+
@clause2.stub!(:evaluate).and_return(true)
|
|
129
|
+
@group.evaluate(@input_values).should be_true
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should return true if one of the clauses evaluates to false" do
|
|
133
|
+
@clause1.stub!(:evaluate).and_return(false)
|
|
134
|
+
@clause2.stub!(:evaluate).and_return(true)
|
|
135
|
+
@group.evaluate(@input_values).should be_false
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "to_hash" do
|
|
140
|
+
before(:each) do
|
|
141
|
+
@field = Field.new
|
|
142
|
+
@field.stub!(:id).and_return 100
|
|
143
|
+
|
|
144
|
+
@fieldset_child1 = FieldsetChild.new
|
|
145
|
+
@fieldset_child1.stub!(:id).and_return 100
|
|
146
|
+
@fieldset_child2 = FieldsetChild.new
|
|
147
|
+
@fieldset_child2.stub!(:id).and_return 200
|
|
148
|
+
|
|
149
|
+
@dependency = Dependency.new
|
|
150
|
+
@dependency.stub!(:id).and_return 100
|
|
151
|
+
@dependency.stub!(:fieldset_child_id).and_return @fieldset_child1.id
|
|
152
|
+
@dependency.stub!(:relationship).and_return "equals"
|
|
153
|
+
@dependency.stub!(:value).and_return 5
|
|
154
|
+
|
|
155
|
+
@clause = DependencyClause.new
|
|
156
|
+
@clause.stub!(:id).and_return 100
|
|
157
|
+
|
|
158
|
+
@group = DependencyGroup.new
|
|
159
|
+
@group.stub!(:id).and_return 100
|
|
160
|
+
@group.stub!(:fieldset_child_id).and_return @fieldset_child2.id
|
|
161
|
+
@group.stub!(:action).and_return "show"
|
|
162
|
+
|
|
163
|
+
@fieldset_child1.stub!(:dependencies).and_return [@dependency]
|
|
164
|
+
@dependency.stub!(:fieldset_child).and_return @fieldset_child1
|
|
165
|
+
@dependency.stub!(:dependency_clause).and_return @clause
|
|
166
|
+
@clause.stub!(:dependencies).and_return [@dependency]
|
|
167
|
+
@clause.stub!(:dependency_group).and_return @group
|
|
168
|
+
@group.stub!(:fieldset_child).and_return @fieldset_child2
|
|
169
|
+
@group.stub!(:dependency_clauses).and_return [@clause]
|
|
170
|
+
@fieldset_child2.stub!(:child).and_return @field
|
|
171
|
+
@fieldset_child2.stub!(:child_id).and_return @field.id
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "should return a hash" do
|
|
175
|
+
@group.to_hash.should be_a_kind_of Hash
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it "should have a specific return structure" do
|
|
179
|
+
expected_result = {
|
|
180
|
+
"action" => @group.action,
|
|
181
|
+
"fieldset_child_id" => @fieldset_child2.id,
|
|
182
|
+
"field_id" => @field.id,
|
|
183
|
+
"clause" => {
|
|
184
|
+
@clause.id => {
|
|
185
|
+
@dependency.id => {
|
|
186
|
+
"fieldset_child_id" => @dependency.fieldset_child_id,
|
|
187
|
+
"relationship" => @dependency.relationship,
|
|
188
|
+
"value" => @dependency.value
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@group.to_hash.should == expected_result
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "should have a specific return structure even with a greater complexity" do
|
|
198
|
+
fieldset_child3 = FieldsetChild.new
|
|
199
|
+
fieldset_child3.stub!(:id).and_return 300
|
|
200
|
+
|
|
201
|
+
dependency2 = Dependency.new
|
|
202
|
+
dependency2.stub!(:id).and_return 200
|
|
203
|
+
dependency2.stub!(:relationship).and_return "equals"
|
|
204
|
+
dependency2.stub!(:value).and_return 5
|
|
205
|
+
dependency2.stub!(:fieldset_child_id).and_return fieldset_child3.id
|
|
206
|
+
|
|
207
|
+
fieldset_child3.stub!(:dependencies).and_return [dependency2]
|
|
208
|
+
dependency2.stub!(:fieldset_child).and_return fieldset_child3
|
|
209
|
+
dependency2.stub!(:dependency_clause).and_return @clause
|
|
210
|
+
@clause.stub!(:dependencies).and_return [@dependency, dependency2]
|
|
211
|
+
|
|
212
|
+
expected_result = {
|
|
213
|
+
"action" => @group.action,
|
|
214
|
+
"fieldset_child_id" => @group.fieldset_child_id,
|
|
215
|
+
"field_id" => @field.id,
|
|
216
|
+
"clause" => {
|
|
217
|
+
@clause.id => {
|
|
218
|
+
@dependency.id => {
|
|
219
|
+
"fieldset_child_id" => @dependency.fieldset_child_id,
|
|
220
|
+
"relationship" => @dependency.relationship,
|
|
221
|
+
"value" => @dependency.value
|
|
222
|
+
},
|
|
223
|
+
dependency2.id => {
|
|
224
|
+
"fieldset_child_id" => dependency2.fieldset_child_id,
|
|
225
|
+
"relationship" => dependency2.relationship,
|
|
226
|
+
"value" => dependency2.value
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@group.to_hash.should == expected_result
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include DynamicFieldsets
|
|
3
|
+
|
|
4
|
+
describe Dependency do
|
|
5
|
+
include DependencyHelper
|
|
6
|
+
|
|
7
|
+
it "should respond to fieldset_child" do
|
|
8
|
+
Dependency.new.should respond_to :fieldset_child
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should respond to dependency_clause" do
|
|
12
|
+
Dependency.new.should respond_to :dependency_clause
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "validations" do
|
|
16
|
+
|
|
17
|
+
before(:each) do
|
|
18
|
+
@dependency = Dependency.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should be valid" do
|
|
22
|
+
@dependency.attributes = valid_attributes
|
|
23
|
+
@dependency.should be_valid
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should have a fieldset_child_id" do
|
|
27
|
+
@dependency.should have(1).error_on(:fieldset_child_id)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should not require a dependency_clause_id" do
|
|
31
|
+
#@dependency.should have(1).error_on(:dependency_clause_id)
|
|
32
|
+
@dependency.should have(0).error_on(:dependency_clause_id)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should have a relationship limited to allowable values" do
|
|
36
|
+
@dependency.relationship = "equals"
|
|
37
|
+
@dependency.should have(0).error_on(:relationship)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should error when relationship is not one of the allowable values" do
|
|
41
|
+
@dependency.relationship = "invalid relationship"
|
|
42
|
+
@dependency.should have(1).error_on(:relationship)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "evaluate" do
|
|
47
|
+
before(:each) do
|
|
48
|
+
@fieldset_child = FieldsetChild.new
|
|
49
|
+
@fieldset_child.stub!(:id).and_return(100)
|
|
50
|
+
@dependency = Dependency.new
|
|
51
|
+
@dependency.attributes = valid_attributes
|
|
52
|
+
@input_hash = {100 => "test value"}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should take a hash's input" do
|
|
56
|
+
lambda{@dependency.evaluate(@input_hash)}.should_not raise_error
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should return true when input matches requirements" do
|
|
60
|
+
@dependency.stub!(:process_relationship).and_return(true)
|
|
61
|
+
@dependency.evaluate(@input_hash).should be_true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should return false when input does not match requirements" do
|
|
65
|
+
@dependency.stub!(:process_relationship).and_return(false)
|
|
66
|
+
@dependency.evaluate(@input_hash).should be_false
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should return false when key pairing does not exist" do
|
|
70
|
+
@dependency.stub!(:process_relationship).and_return(false)
|
|
71
|
+
@dependency.evaluate({1 => "test_value"}).should be_false
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "relationship_list" do
|
|
77
|
+
it "should return an array" do
|
|
78
|
+
@dependency = Dependency.new
|
|
79
|
+
@dependency.attributes = valid_attributes
|
|
80
|
+
@dependency.relationship_list.should be_an_instance_of Array
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "process_relationship" do
|
|
85
|
+
before(:each) do
|
|
86
|
+
@dependency = Dependency.new
|
|
87
|
+
@dependency.attributes = valid_attributes
|
|
88
|
+
@dependency.value = "test string"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should take a string as input" do
|
|
92
|
+
input_value = "test string"
|
|
93
|
+
lambda{@dependency.process_relationship(input_value)}.should_not raise_error
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "should return true if the value and input_value are equal and relatinship is equal" do
|
|
97
|
+
@dependency.relationship = "equals"
|
|
98
|
+
input_value = "test string"
|
|
99
|
+
@dependency.process_relationship(input_value).should be_true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "should return false if the value and input value are not equal and relationship is equal" do
|
|
103
|
+
@dependency.relationship = "equals"
|
|
104
|
+
input_value = "not test string"
|
|
105
|
+
@dependency.process_relationship(input_value).should be_false
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should return true if the value and input_value are not equal and relationship is not equal" do
|
|
109
|
+
@dependency.relationship = "not equals"
|
|
110
|
+
input_value = "not test string"
|
|
111
|
+
@dependency.process_relationship(input_value).should be_true
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should return false if the value and input_value are equal and relationship is not equal" do
|
|
115
|
+
@dependency.relationship = "not equals"
|
|
116
|
+
input_value = "test string"
|
|
117
|
+
@dependency.process_relationship(input_value).should be_false
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "should return true if the value is within the input_value array and relationship is includes" do
|
|
121
|
+
@dependency.relationship = "includes"
|
|
122
|
+
input_value = ["test string"]
|
|
123
|
+
@dependency.process_relationship(input_value).should be_true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should return false if the value is not within the input_value array and relationship is includes" do
|
|
127
|
+
@dependency.relationship = "includes"
|
|
128
|
+
input_value = ["a"]
|
|
129
|
+
@dependency.process_relationship(input_value).should be_false
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should return true if the value is not within the input_value array and relationship is not includes" do
|
|
133
|
+
@dependency.relationship = "not includes"
|
|
134
|
+
input_value = ["a"]
|
|
135
|
+
@dependency.process_relationship(input_value).should be_true
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "should return false if the value is within the input_value array and relationship is not includes" do
|
|
139
|
+
@dependency.relationship = "not includes"
|
|
140
|
+
input_value = ["test string"]
|
|
141
|
+
@dependency.process_relationship(input_value).should be_false
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "should return true if the input_value is an empty string and relationship is blank" do
|
|
145
|
+
@dependency.relationship = "blank"
|
|
146
|
+
input_value = ""
|
|
147
|
+
@dependency.process_relationship(input_value).should be_true
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "should return false if the input_value is not an empty string and relationship is blank" do
|
|
151
|
+
@dependency.relationship = "blank"
|
|
152
|
+
input_value = "test string"
|
|
153
|
+
@dependency.process_relationship(input_value).should be_false
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should return true if the input_value is not an empty string and relationship is not blank" do
|
|
157
|
+
@dependency.relationship = "not blank"
|
|
158
|
+
input_value = "test string"
|
|
159
|
+
@dependency.process_relationship(input_value).should be_true
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should return false if the input_value is not an empty string and relationship is not blank" do
|
|
163
|
+
@dependency.relationship = "not blank"
|
|
164
|
+
input_value = ""
|
|
165
|
+
@dependency.process_relationship(input_value).should be_false
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
describe "to_hash method" do
|
|
171
|
+
it "should have spec tests"
|
|
172
|
+
end
|
|
173
|
+
end
|
|
@@ -23,4 +23,53 @@ describe FieldDefault do
|
|
|
23
23
|
@field_default.should have(1).error_on(:value)
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
# note that these are saving because I am testing a before save
|
|
28
|
+
# instead of testing the method directly
|
|
29
|
+
describe "convert_option_name_to_id method" do
|
|
30
|
+
before(:each) do
|
|
31
|
+
@field = Field.new(:field_type => "select")
|
|
32
|
+
@field.stub!(:id).and_return(1)
|
|
33
|
+
@field_option = FieldOption.new(:name => "test value")
|
|
34
|
+
@field_option.stub!(:id).and_return(2)
|
|
35
|
+
FieldOption.stub!(:find_by_name).and_return(@field_option)
|
|
36
|
+
@default = FieldDefault.new(:field => @field, :value => "test value")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should convert the value to a field option id if the field's type is an option type" do
|
|
40
|
+
@default.save
|
|
41
|
+
@default.value.should == @field_option.id
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should retain it's value if the field's type is not an option type" do
|
|
45
|
+
@field.field_type = "textfield"
|
|
46
|
+
@default.save
|
|
47
|
+
@default.value.should_not == @field_option.id
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "pretty_value method" do
|
|
52
|
+
before(:each) do
|
|
53
|
+
@field = Field.new(:field_type => "select")
|
|
54
|
+
@field.stub!(:id).and_return(1)
|
|
55
|
+
@field_option = FieldOption.new(:name => "test value")
|
|
56
|
+
@field_option.stub!(:id).and_return(2)
|
|
57
|
+
FieldOption.stub!(:find_by_name).and_return(@field_option)
|
|
58
|
+
@default = FieldDefault.new(:field => @field, :value => "test value")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should return the value if the field is not an option type" do
|
|
62
|
+
@field.field_type = "textfield"
|
|
63
|
+
@default.pretty_value.should == @default.value
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should return the field option name if the field is an option type" do
|
|
67
|
+
@default.pretty_value.should == @field_option.name
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should return the value if the field is not set" do
|
|
71
|
+
@default.field = nil
|
|
72
|
+
@default.pretty_value.should == @default.value
|
|
73
|
+
end
|
|
74
|
+
end
|
|
26
75
|
end
|
|
@@ -18,14 +18,16 @@ describe FieldRecord do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "should be valid" do
|
|
21
|
-
@field_record.
|
|
21
|
+
@field_record.fieldset_child = FieldsetChild.new
|
|
22
22
|
@field_record.fieldset_associator = FieldsetAssociator.new
|
|
23
23
|
@field_record.value = "42"
|
|
24
|
+
child = mock_model(DynamicFieldsets::Field)
|
|
25
|
+
@field_record.fieldset_child = FieldsetChild.new(:child => child)
|
|
24
26
|
@field_record.should be_valid
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
it "should require field" do
|
|
28
|
-
@field_record.should have(1).error_on(:
|
|
30
|
+
@field_record.should have(1).error_on(:fieldset_child)
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
it "should require fieldset_associator" do
|
|
@@ -40,5 +42,12 @@ describe FieldRecord do
|
|
|
40
42
|
@field_record.value = ""
|
|
41
43
|
@field_record.should have(0).error_on(:value)
|
|
42
44
|
end
|
|
45
|
+
|
|
46
|
+
it "should error if the fieldset_child has the wrong type" do
|
|
47
|
+
child = mock_model(DynamicFieldsets::Fieldset)
|
|
48
|
+
@field_record.fieldset_child = FieldsetChild.new(:child => child)
|
|
49
|
+
@field_record.valid?
|
|
50
|
+
@field_record.should have(1).error_on(:fieldset_child)
|
|
51
|
+
end
|
|
43
52
|
end
|
|
44
53
|
end
|
data/spec/models/field_spec.rb
CHANGED
|
@@ -4,8 +4,8 @@ include DynamicFieldsets
|
|
|
4
4
|
describe Field do
|
|
5
5
|
include FieldHelper
|
|
6
6
|
|
|
7
|
-
it "should respond to
|
|
8
|
-
Field.new.should respond_to :
|
|
7
|
+
it "should respond to parent_fieldset" do
|
|
8
|
+
Field.new.should respond_to :parent_fieldsets
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "should respond to field_options" do
|
|
@@ -42,10 +42,6 @@ describe Field do
|
|
|
42
42
|
@field.should have(2).error_on(:field_type)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
it "should require order number" do
|
|
46
|
-
@field.should have(1).error_on(:order_num)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
45
|
it "should require type within the allowable types" do
|
|
50
46
|
@field.field_type = "unsupported_type"
|
|
51
47
|
@field.should have(1).error_on(:field_type)
|
|
@@ -166,4 +162,32 @@ describe Field do
|
|
|
166
162
|
Field.option_field_types.should be_a_kind_of Array
|
|
167
163
|
end
|
|
168
164
|
end
|
|
165
|
+
|
|
166
|
+
describe "in_use? method" do
|
|
167
|
+
before(:each) do
|
|
168
|
+
@field = Field.new
|
|
169
|
+
@field.stub!(:id).and_return(1)
|
|
170
|
+
|
|
171
|
+
end
|
|
172
|
+
it "should return true if there is a field record associated with the field" do
|
|
173
|
+
@fieldset_child = FieldsetChild.new(:child => @field, :fieldset => nil )
|
|
174
|
+
@fieldset_child.stub!(:field_records).and_return(["random", "array" "of", "stuff"])
|
|
175
|
+
@field.stub!(:fieldset_children).and_return([@fieldset_child])
|
|
176
|
+
|
|
177
|
+
@field.in_use?.should be_true
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "should return true if the field is in a fieldset (through a fieldset child)" do
|
|
181
|
+
@fieldset = Fieldset.new
|
|
182
|
+
@fieldset.stub!(:id).and_return(2)
|
|
183
|
+
@fieldset_child = FieldsetChild.new(:child => @field, :fieldset_id => @fieldset.id)
|
|
184
|
+
@field.stub!(:fieldset_children).and_return([@fieldset_child])
|
|
185
|
+
|
|
186
|
+
@field.in_use?.should be_true
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "should return false otherwise" do
|
|
190
|
+
@field.in_use?.should be_false
|
|
191
|
+
end
|
|
192
|
+
end
|
|
169
193
|
end
|