surveyor 0.7.1 → 0.8.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/VERSION +1 -1
- data/app/controllers/surveyor_controller.rb +3 -4
- data/app/models/answer.rb +1 -2
- data/app/models/dependency.rb +7 -6
- data/app/models/dependency_condition.rb +11 -48
- data/app/models/response.rb +2 -14
- data/app/models/response_set.rb +1 -1
- data/app/models/validation.rb +13 -0
- data/app/models/validation_condition.rb +39 -0
- data/config/routes.rb +3 -3
- data/generators/surveyor/surveyor_generator.rb +1 -1
- data/generators/surveyor/templates/migrate/create_validation_conditions.rb +32 -0
- data/generators/surveyor/templates/migrate/create_validations.rb +20 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +19 -3
- data/lib/surveyor/acts_as_response.rb +33 -0
- data/lib/surveyor.rb +1 -0
- data/script/surveyor/question_group.rb +1 -0
- data/script/surveyor/survey.rb +3 -0
- data/spec/controllers/surveyor_controller_spec.rb +68 -203
- data/spec/factories.rb +58 -25
- data/spec/models/answer_spec.rb +1 -1
- data/spec/models/dependency_condition_spec.rb +47 -64
- data/spec/models/dependency_spec.rb +11 -5
- data/spec/models/question_group_spec.rb +25 -1
- data/spec/models/question_spec.rb +2 -2
- data/spec/models/response_set_spec.rb +10 -25
- data/spec/models/response_spec.rb +11 -46
- data/spec/models/survey_spec.rb +9 -10
- data/spec/models/validation_condition_spec.rb +53 -0
- data/spec/models/validation_spec.rb +32 -0
- data/surveyor.gemspec +11 -2
- metadata +11 -2
@@ -2,17 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe SurveyorController do
|
4
4
|
|
5
|
-
# map.
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
5
|
+
# map.with_options :controller => 'surveyor' do |s|
|
6
|
+
# s.available_surveys "#{root}", :conditions => {:method => :get}, :action => "new" # GET survey list
|
7
|
+
# s.take_survey "#{root}:survey_code", :conditions => {:method => :post}, :action => "create" # Only POST of survey to create
|
8
|
+
# s.view_my_survey "#{root}:survey_code/:response_set_code", :conditions => {:method => :get}, :action => "show" # GET viewable/printable? survey
|
9
|
+
# s.edit_my_survey "#{root}:survey_code/:response_set_code/take", :conditions => {:method => :get}, :action => "edit" # GET editable survey
|
10
|
+
# s.update_my_survey "#{root}:survey_code/:response_set_code", :conditions => {:method => :put}, :action => "update" # PUT edited survey
|
11
|
+
# end
|
11
12
|
|
12
|
-
describe "
|
13
|
+
describe "available surveys: GET /surveys" do
|
13
14
|
|
14
15
|
before(:each) do
|
15
|
-
@survey =
|
16
|
+
@survey = Factory(:survey)
|
16
17
|
Survey.stub!(:find).and_return([@survey])
|
17
18
|
end
|
18
19
|
|
@@ -20,123 +21,67 @@ describe SurveyorController do
|
|
20
21
|
get :new
|
21
22
|
end
|
22
23
|
|
23
|
-
it "should be successful" do
|
24
|
-
do_get
|
25
|
-
response.should be_success
|
26
|
-
end
|
27
|
-
|
28
24
|
it "should render index template" do
|
29
25
|
do_get
|
26
|
+
response.should be_success
|
30
27
|
response.should render_template('new')
|
31
28
|
end
|
32
|
-
|
33
29
|
it "should find all surveys" do
|
34
30
|
Survey.should_receive(:find).with(:all).and_return([@survey])
|
35
31
|
do_get
|
36
32
|
end
|
37
|
-
|
38
33
|
it "should assign the found surveys for the view" do
|
39
34
|
do_get
|
40
35
|
assigns[:surveys].should == [@survey]
|
41
36
|
end
|
42
37
|
end
|
43
38
|
|
44
|
-
describe "
|
45
|
-
before(:each) do
|
46
|
-
@surveys = mock("Array of Surveys", :to_xml => "XML")
|
47
|
-
Survey.stub!(:find).and_return(@surveys)
|
48
|
-
end
|
49
|
-
|
50
|
-
def do_get
|
51
|
-
@request.env["HTTP_ACCEPT"] = "application/xml"
|
52
|
-
get :new
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should be successful" do
|
56
|
-
do_get
|
57
|
-
response.should be_success
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should find all surveys" do
|
61
|
-
Survey.should_receive(:find).with(:all).and_return(@surveys)
|
62
|
-
do_get
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should render the found surveys as xml" do
|
66
|
-
@surveys.should_receive(:to_xml).and_return("XML")
|
67
|
-
do_get
|
68
|
-
response.body.should == "XML"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "handling POST /surveys/XYZ (take_survey)" do
|
39
|
+
describe "take survey: POST /surveys/XYZ" do
|
73
40
|
|
74
41
|
before(:each) do
|
75
|
-
@survey =
|
76
|
-
@response_set =
|
77
|
-
ResponseSet.stub!(:
|
42
|
+
@survey = Factory(:survey, :title => "XYZ", :access_code => "XYZ")
|
43
|
+
@response_set = Factory(:response_set, :access_code => "PDQ")
|
44
|
+
ResponseSet.stub!(:create).and_return(@response_set)
|
78
45
|
Survey.stub!(:find_by_access_code).and_return(@survey)
|
79
46
|
end
|
80
47
|
|
81
|
-
describe "with
|
82
|
-
|
48
|
+
describe "with success" do
|
83
49
|
def do_post
|
84
|
-
@response_set.should_receive(:save!).and_return(true)
|
85
50
|
post :create, :survey_code => "XYZ"
|
86
51
|
end
|
87
|
-
|
88
52
|
it "should look for the survey" do
|
89
53
|
Survey.should_receive(:find_by_access_code).with("XYZ").and_return(@survey)
|
90
54
|
do_post
|
91
55
|
end
|
92
56
|
it "should create a new response_set" do
|
93
|
-
ResponseSet.should_receive(:
|
57
|
+
ResponseSet.should_receive(:create).and_return(@response_set)
|
94
58
|
do_post
|
95
59
|
end
|
96
|
-
|
97
60
|
it "should redirect to the new response_set" do
|
98
61
|
do_post
|
99
62
|
response.should redirect_to(edit_my_survey_url(:survey_code => "XYZ", :response_set_code => "PDQ"))
|
100
63
|
end
|
101
|
-
|
102
64
|
end
|
103
65
|
|
104
|
-
describe "with
|
105
|
-
|
106
|
-
|
107
|
-
@response_set.should_receive(:save!).and_return(false)
|
66
|
+
describe "with failures" do
|
67
|
+
it "should re-redirect to 'new' if ResponseSet failed create" do
|
68
|
+
ResponseSet.should_receive(:create).and_return(false)
|
108
69
|
post :create, :survey_code => "XYZ"
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should re-redirect to 'new'" do
|
112
|
-
do_post
|
113
70
|
response.should redirect_to(available_surveys_url)
|
114
71
|
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "with survey not found" do
|
119
|
-
|
120
|
-
def do_post
|
72
|
+
it "should re-redirect to 'new' if Survey failed find" do
|
121
73
|
Survey.should_receive(:find_by_access_code).and_return(nil)
|
122
74
|
post :create, :survey_code => "XYZ"
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should re-redirect to 'new'" do
|
126
|
-
do_post
|
127
75
|
response.should redirect_to(available_surveys_url)
|
128
76
|
end
|
129
|
-
|
130
77
|
end
|
131
78
|
end
|
132
79
|
|
133
|
-
describe "
|
80
|
+
describe "view my survey: GET /surveys/XYZ/PDQ" do
|
134
81
|
|
135
82
|
before(:each) do
|
136
|
-
@survey =
|
137
|
-
@response_set =
|
138
|
-
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
139
|
-
@response_set.stub!(:survey).and_return(@survey)
|
83
|
+
@survey = Factory(:survey, :title => "XYZ", :access_code => "XYZ", :sections => [Factory(:survey_section)])
|
84
|
+
@response_set = Factory(:response_set, :access_code => "PDQ", :survey => @survey)
|
140
85
|
end
|
141
86
|
|
142
87
|
def do_get
|
@@ -147,28 +92,26 @@ describe SurveyorController do
|
|
147
92
|
do_get
|
148
93
|
response.should be_success
|
149
94
|
end
|
150
|
-
|
151
95
|
it "should render show template" do
|
152
96
|
do_get
|
153
97
|
response.should render_template('show')
|
154
98
|
end
|
155
|
-
|
156
99
|
it "should find the response_set requested" do
|
100
|
+
pending
|
157
101
|
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
158
102
|
do_get
|
159
103
|
end
|
160
|
-
|
161
104
|
it "should assign the found response_set and survey for the view" do
|
105
|
+
pending
|
162
106
|
do_get
|
163
107
|
assigns[:response_set].should equal(@response_set)
|
164
108
|
assigns[:survey].should equal(@survey)
|
165
109
|
end
|
166
|
-
|
167
110
|
it "should redirect if :response_code not found" do
|
111
|
+
pending
|
168
112
|
get :show, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
169
113
|
response.should redirect_to(available_surveys_url)
|
170
114
|
end
|
171
|
-
|
172
115
|
# I'm not sure this is enterly neccessary since we look up the survey from the response_code in the url -BC
|
173
116
|
it "should redirect if :survey_code in url doesn't match response_set.survey.access_code" do
|
174
117
|
pending
|
@@ -177,27 +120,22 @@ describe SurveyorController do
|
|
177
120
|
end
|
178
121
|
end
|
179
122
|
|
180
|
-
describe "
|
123
|
+
describe "edit my survey: GET /surveys/XYZ/PDQ/take" do
|
181
124
|
|
182
125
|
before(:each) do
|
183
|
-
@survey =
|
184
|
-
@
|
185
|
-
@
|
186
|
-
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
187
|
-
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
188
|
-
@response_set.stub!(:survey).and_return(@survey)
|
126
|
+
@survey = Factory(:survey, :title => "XYZ", :access_code => "XYZ")
|
127
|
+
@section = Factory(:survey_section, :survey => @survey)
|
128
|
+
@response_set = Factory(:response_set, :access_code => "PDQ", :survey => @survey)
|
189
129
|
end
|
190
130
|
|
191
131
|
it "should be successful, render edit with the requested survey" do
|
192
|
-
ResponseSet.should_receive(:find_by_access_code).
|
193
|
-
|
132
|
+
ResponseSet.should_receive(:find_by_access_code).and_return(@response_set)
|
194
133
|
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
195
134
|
response.should be_success
|
196
135
|
response.should render_template('edit')
|
197
|
-
assigns[:response_set].should
|
198
|
-
assigns[:survey].should
|
136
|
+
assigns[:response_set].should == @response_set
|
137
|
+
assigns[:survey].should == @survey
|
199
138
|
end
|
200
|
-
|
201
139
|
it "should redirect if :response_code not found" do
|
202
140
|
get :edit, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
203
141
|
response.should redirect_to(available_surveys_url)
|
@@ -205,124 +143,51 @@ describe SurveyorController do
|
|
205
143
|
|
206
144
|
end
|
207
145
|
|
208
|
-
describe "
|
146
|
+
describe "update my survey: PUT /surveys/XYZ/PDQ" do
|
209
147
|
|
210
148
|
before(:each) do
|
211
|
-
@survey =
|
212
|
-
@
|
213
|
-
|
214
|
-
@response_set.stub!(:
|
215
|
-
@response_set.stub!(:
|
149
|
+
@survey = Factory(:survey, :title => "XYZ", :access_code => "XYZ")
|
150
|
+
@section = Factory(:survey_section, :survey => @survey)
|
151
|
+
@response_set = Factory(:response_set, :access_code => "PDQ", :survey => @survey)
|
152
|
+
# @response_set.stub!(:update_attributes).and_return(true)
|
153
|
+
# @response_set.stub!(:complete!).and_return(Time.now)
|
154
|
+
# @response_set.stub!(:save).and_return(true)
|
216
155
|
end
|
217
156
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
157
|
+
def do_put
|
158
|
+
put :update, :survey_code => "XYZ", :response_set_code => "PDQ"
|
159
|
+
end
|
160
|
+
def do_put_with_finish
|
161
|
+
responses = {
|
162
|
+
"6"=>{"question_id"=>"6", "20"=>{"string_value"=>"saf"}}, #string
|
163
|
+
"7"=>{"question_id"=>"7", "21"=>{"text_value"=>""}}, #text
|
164
|
+
"1"=>{"question_id"=>"1", "answer_id"=>"1", "4"=>{"string_value"=>""}}, #radio+txt
|
165
|
+
"2"=>{"answer_id"=>"6"}, #radio
|
166
|
+
"3"=>{"answer_id"=>"10"}, #radio
|
167
|
+
"4"=>{"question_id"=>"4", "answer_id"=>"15"}, #check
|
168
|
+
"5"=>{"question_id"=>"5", "16"=>{"selected"=>"1"}, "19"=>{"string_value"=>""}} #check+txt
|
169
|
+
}
|
170
|
+
put :update, :survey_code => "XYZ", :response_set_code => "PDQ", :finish => "finish", :responses => responses
|
226
171
|
end
|
227
172
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
response_set_params = {"survey_code"=>"XYZ", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}]}}}
|
232
|
-
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
# describe "issue with posting data to an existing survey and the data not saving properly" do
|
237
|
-
# @survey = mock_model(Survey, :access_code => "XYZ")
|
238
|
-
# @response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
239
|
-
# ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
240
|
-
# @response_set.stub!(:survey).and_return(@survey)
|
241
|
-
# @response_set.stub!(:complete!).and_return(Time.now)
|
242
|
-
#
|
243
|
-
#
|
244
|
-
# end
|
245
|
-
|
246
|
-
# first post {"survey_code"=>"test_survey", "commit"=>"Next Section (Utensiles and you!) >>", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}, {"answer_id"=>"0", "string_value"=>""}], "2"=>[{"answer_id"=>"6"}], "3"=>[{"answer_id"=>"10"}], "4"=>[{"answer_id"=>"14"}], "5"=>[{"answer_id"=>"0"}, {"answer_id"=>"0"}]}, "existing_response_attributes"=>{"6"=>{"1"=>{"answer_id"=>"20", "string_value"=>"B"}}, "7"=>{"2"=>{"text_value"=>"foo", "answer_id"=>"21"}}, "5"=>{"7"=>{"answer_id"=>"17"}, "16"=>{"answer_id"=>"19", "string_value"=>"blah"}}}}, "authenticity_token"=>"d9ba68fe20a46703f3737b5cb0b7e17b7390de32", "_method"=>"put", "action"=>"update", "controller"=>"app", "response_set_code"=>"9VEsec1dK6", "section"=>"2"}
|
247
|
-
# second post {"survey_code"=>"test_survey", "commit"=>"Next Section (Utensiles and you!) >>", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}, {"answer_id"=>"0", "string_value"=>""}], "2"=>[{"answer_id"=>"6"}], "3"=>[{"answer_id"=>"10"}], "4"=>[{"answer_id"=>"14"}], "5"=>[{"answer_id"=>"0"}, {"answer_id"=>"0"}]}, "existing_response_attributes"=>{"6"=>{"1"=>{"answer_id"=>"20", "string_value"=>"B"}}, "7"=>{"2"=>{"text_value"=>"boooo", "answer_id"=>"21"}}, "5"=>{"7"=>{"answer_id"=>"17"}, "16"=>{"answer_id"=>"19", "string_value"=>"blahblahstink"}}}}, "authenticity_token"=>"d9ba68fe20a46703f3737b5cb0b7e17b7390de32", "_method"=>"put", "action"=>"update", "controller"=>"app", "response_set_code"=>"9VEsec1dK6", "section"=>"2"}
|
248
|
-
|
249
|
-
|
173
|
+
it "should find the response set requested" do
|
174
|
+
ResponseSet.should_receive(:find_by_access_code).and_return(@response_set)
|
175
|
+
do_put
|
250
176
|
end
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
it "should re-render 'edit'" do
|
256
|
-
put :update, :survey_code => "XYZ", :response_set_code => "PDQ"
|
257
|
-
response.should be_success
|
258
|
-
response.should render_template('edit')
|
259
|
-
flash[:notice].should == "Unable to update survey"
|
260
|
-
end
|
261
|
-
|
177
|
+
it "should redirect to 'edit' without params" do
|
178
|
+
do_put
|
179
|
+
response.should redirect_to(:action => :edit)
|
180
|
+
flash[:notice].should == "Unable to update survey"
|
262
181
|
end
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
before(:each) do
|
268
|
-
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
269
|
-
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
270
|
-
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
271
|
-
@response_set.stub!(:survey).and_return(@survey)
|
272
|
-
@response_set.stub!(:complete!).and_return(Time.now)
|
182
|
+
it "should complete the found response set on finish" do
|
183
|
+
do_put_with_finish
|
184
|
+
flash[:notice].should == "Completed survey"
|
273
185
|
end
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
put :finish, :survey_code => "XYZ", :response_set_code => "PDQ"
|
279
|
-
end
|
280
|
-
|
281
|
-
it "should find the response_set requested" do
|
282
|
-
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
283
|
-
do_put
|
284
|
-
end
|
285
|
-
|
286
|
-
it "should update the found response set" do
|
287
|
-
@response_set.should_receive(:complete!).and_return(Time.now)
|
288
|
-
do_put
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should assign the found response set and survey for the view" do
|
292
|
-
do_put
|
293
|
-
assigns(:response_set).should equal(@response_set)
|
294
|
-
assigns(:survey).should equal(@response_set.survey)
|
295
|
-
end
|
296
|
-
|
297
|
-
it "should render the 'edit' template" do
|
298
|
-
do_put
|
299
|
-
response.should render_template('edit')
|
300
|
-
flash[:notice].should == "Completed survey"
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should redirect to available surveys if :response_code not found" do
|
304
|
-
put :update, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
305
|
-
response.should redirect_to(available_surveys_url)
|
306
|
-
flash[:notice].should == "Unable to find your responses to the survey"
|
307
|
-
end
|
308
|
-
|
186
|
+
it "should redirect to available surveys if :response_code not found" do
|
187
|
+
put :update, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
188
|
+
response.should redirect_to(available_surveys_url)
|
189
|
+
flash[:notice].should == "Unable to find your responses to the survey"
|
309
190
|
end
|
310
|
-
|
311
|
-
describe "with failed update" do
|
312
|
-
|
313
|
-
def do_put
|
314
|
-
put :finish, :survey_code => "XYZ", :response_set_code => "PDQ"
|
315
|
-
end
|
316
191
|
|
317
|
-
it "should re-render 'edit'" do
|
318
|
-
@response_set.should_receive(:complete!).and_return(false)
|
319
|
-
do_put
|
320
|
-
response.should render_template('edit')
|
321
|
-
flash[:notice].should == "Unable to complete survey"
|
322
|
-
end
|
323
|
-
|
324
|
-
end
|
325
192
|
end
|
326
|
-
|
327
|
-
|
328
193
|
end
|
data/spec/factories.rb
CHANGED
@@ -22,19 +22,33 @@ end
|
|
22
22
|
|
23
23
|
Factory.sequence(:question_display_order){|n| n }
|
24
24
|
|
25
|
-
Factory.define :question do |
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
Factory.define :question do |q|
|
26
|
+
q.association :survey_section # s.survey_section_id {}
|
27
|
+
q.question_group_id {}
|
28
|
+
q.text {"What is your favorite color?"}
|
29
|
+
q.short_text {"favorite_color"}
|
30
|
+
q.help_text {"just write it in the box"}
|
31
|
+
q.pick {:none}
|
32
|
+
q.reference_identifier {|me| "q_#{me.object_id}"}
|
33
|
+
q.data_export_identifier {}
|
34
|
+
q.common_namespace {}
|
35
|
+
q.common_identifier {}
|
36
|
+
q.display_order {Factory.next :question_display_order}
|
37
|
+
q.display_type {} # nil is default
|
38
|
+
q.is_mandatory {false}
|
39
|
+
q.display_width {}
|
40
|
+
end
|
41
|
+
|
42
|
+
Factory.define :question_group do |g|
|
43
|
+
g.text {"Describe your family"}
|
44
|
+
g.help_text {}
|
45
|
+
g.reference_identifier {|me| "g_#{me.object_id}"}
|
46
|
+
g.data_export_identifier {}
|
47
|
+
g.common_namespace {}
|
48
|
+
g.common_identifier {}
|
49
|
+
g.display_type {}
|
50
|
+
g.custom_class {}
|
51
|
+
g.custom_renderer {}
|
38
52
|
end
|
39
53
|
|
40
54
|
Factory.sequence(:answer_display_order){|n| n }
|
@@ -46,26 +60,23 @@ Factory.define :answer do |a|
|
|
46
60
|
a.help_text {"Clear is the absense of color"}
|
47
61
|
a.weight {}
|
48
62
|
a.response_class {"String"}
|
49
|
-
a.display_order {}
|
50
|
-
a.is_exclusive {}
|
51
|
-
a.hide_label {}
|
52
63
|
a.reference_identifier {}
|
53
64
|
a.data_export_identifier {}
|
54
|
-
a.
|
55
|
-
a.
|
56
|
-
a.
|
57
|
-
a.
|
58
|
-
a.
|
59
|
-
a.allow_negative {}
|
60
|
-
a.allow_blank {}
|
61
|
-
a.unit {}
|
65
|
+
a.common_namespace {}
|
66
|
+
a.common_identifier {}
|
67
|
+
a.display_order {Factory.next :answer_display_order}
|
68
|
+
a.is_exclusive {}
|
69
|
+
a.hide_label {}
|
62
70
|
a.display_length {}
|
71
|
+
a.custom_class {}
|
72
|
+
a.custom_renderer {}
|
63
73
|
end
|
64
74
|
|
65
75
|
Factory.define :dependency do |d|
|
66
76
|
# the dependent question
|
67
77
|
d.association :question # d.question_id {}
|
68
|
-
d.
|
78
|
+
d.question_group_id {}
|
79
|
+
d.rule {"A and B"}
|
69
80
|
end
|
70
81
|
|
71
82
|
Factory.define :dependency_condition do |d|
|
@@ -105,3 +116,25 @@ Factory.define :response do |r|
|
|
105
116
|
r.response_other {}
|
106
117
|
r.response_group {}
|
107
118
|
end
|
119
|
+
|
120
|
+
Factory.define :validation do |v|
|
121
|
+
v.association :answer # v.answer_id {}
|
122
|
+
v.rule {"A"}
|
123
|
+
v.message {}
|
124
|
+
end
|
125
|
+
|
126
|
+
Factory.define :validation_condition do |v|
|
127
|
+
v.association :validation # v.validation_id {}
|
128
|
+
v.rule_key {"A"}
|
129
|
+
v.question_id {}
|
130
|
+
v.operator {"=="}
|
131
|
+
v.answer_id {}
|
132
|
+
v.datetime_value {}
|
133
|
+
v.integer_value {}
|
134
|
+
v.float_value {}
|
135
|
+
v.unit {}
|
136
|
+
v.text_value {}
|
137
|
+
v.string_value {}
|
138
|
+
v.response_other {}
|
139
|
+
v.regexp {}
|
140
|
+
end
|
data/spec/models/answer_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Answer, "when creating a new answer" do
|
|
9
9
|
@answer.should be_valid
|
10
10
|
end
|
11
11
|
|
12
|
-
it "should be invalid without a
|
12
|
+
it "should be invalid without a question_id" do
|
13
13
|
@answer.question_id = nil
|
14
14
|
@answer.should_not be_valid
|
15
15
|
end
|