surveyor 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +22 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +4 -1
- data/app/views/partials/_answer.html.haml +1 -1
- data/app/views/partials/_section_menu.html.haml +8 -1
- data/app/views/surveyor/edit.html.haml +1 -1
- data/app/views/surveyor/new.html.haml +1 -1
- data/app/views/surveyor/show.html.haml +17 -20
- data/ci-exec.sh +1 -1
- data/config/routes.rb +7 -7
- data/features/internationalization.feature +68 -2
- data/features/show_survey.feature +29 -0
- data/features/step_definitions/parser_steps.rb +15 -0
- data/features/step_definitions/surveyor_steps.rb +11 -9
- data/features/support/paths.rb +5 -2
- data/features/z_redcap_parser.feature +4 -1
- data/lib/assets/javascripts/surveyor/jquery.surveyor.js +5 -1
- data/lib/assets/stylesheets/surveyor.sass +2 -0
- data/lib/generators/surveyor/install_generator.rb +4 -0
- data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +2 -2
- data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +2 -1
- data/lib/generators/surveyor/templates/surveys/languages.rb +9 -5
- data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +4 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +4 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +4 -0
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +1 -1
- data/lib/surveyor/models/answer_methods.rb +2 -2
- data/lib/surveyor/models/question_methods.rb +3 -3
- data/lib/surveyor/models/response_methods.rb +18 -5
- data/lib/surveyor/models/response_set_methods.rb +1 -1
- data/lib/surveyor/models/survey_methods.rb +2 -2
- data/lib/surveyor/models/survey_section_methods.rb +2 -2
- data/lib/surveyor/parser.rb +25 -4
- data/lib/surveyor/redcap_parser.rb +13 -13
- data/lib/surveyor/surveyor_controller_methods.rb +22 -19
- data/lib/surveyor/version.rb +1 -1
- data/lib/tasks/surveyor_tasks.rake +1 -1
- data/spec/controllers/surveyor_controller_spec.rb +155 -269
- data/spec/lib/parser_spec.rb +189 -21
- data/spec/models/response_set_spec.rb +7 -5
- data/spec/spec_helper.rb +3 -1
- data/stacktests.sh +1 -1
- data/surveyor.gemspec +3 -1
- metadata +271 -275
data/lib/surveyor/version.rb
CHANGED
@@ -7,7 +7,7 @@ namespace :surveyor do
|
|
7
7
|
file = File.join(Rails.root, ENV["FILE"])
|
8
8
|
raise "File does not exist: #{file}" unless FileTest.exists?(file)
|
9
9
|
puts "--- Parsing #{file} ---"
|
10
|
-
Surveyor::Parser.
|
10
|
+
Surveyor::Parser.parse_file(file, {:trace => Rake.application.options.trace})
|
11
11
|
puts "--- Done #{file} ---"
|
12
12
|
end
|
13
13
|
desc "generate and load survey from REDCap Data Dictionary (specify FILE=surveys/redcap.csv)"
|
@@ -1,345 +1,255 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe SurveyorController do
|
4
|
+
include Surveyor::Engine.routes.url_helpers
|
5
|
+
before do
|
6
|
+
@routes = Surveyor::Engine.routes
|
7
|
+
end
|
8
|
+
|
9
|
+
let!(:survey) { Factory(:survey, :title => "Alphabet", :access_code => "alpha", :survey_version => 0)}
|
10
|
+
let!(:survey_beta) { Factory(:survey, :title => "Alphabet", :access_code => "alpha", :survey_version => 1)}
|
11
|
+
let!(:response_set) { Factory(:response_set, :survey => survey, :access_code => "pdq")}
|
12
|
+
let!(:response_set_beta) { Factory(:response_set, :survey => survey_beta, :access_code => "rst")}
|
13
|
+
before { ResponseSet.stub!(:create).and_return(response_set) }
|
4
14
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# end
|
15
|
+
# match '/', :to => 'surveyor#new', :as => 'available_surveys', :via => :get
|
16
|
+
# match '/:survey_code', :to => 'surveyor#create', :as => 'take_survey', :via => :post
|
17
|
+
# match '/:survey_code', :to => 'surveyor#export', :as => 'export_survey', :via => :get
|
18
|
+
# match '/:survey_code/:response_set_code', :to => 'surveyor#show', :as => 'view_my_survey', :via => :get
|
19
|
+
# match '/:survey_code/:response_set_code/take', :to => 'surveyor#edit', :as => 'edit_my_survey', :via => :get
|
20
|
+
# match '/:survey_code/:response_set_code', :to => 'surveyor#update', :as => 'update_my_survey', :via => :put
|
12
21
|
|
13
|
-
|
22
|
+
context "#new" do
|
14
23
|
def do_get
|
15
24
|
get :new
|
16
25
|
end
|
17
|
-
|
18
|
-
it "should render index template" do
|
26
|
+
it "renders new" do
|
19
27
|
do_get
|
20
28
|
response.should be_success
|
21
29
|
response.should render_template('new')
|
22
30
|
end
|
23
|
-
|
24
|
-
it "assigns surveys_by_access_code to surveys grouped by access_code" do
|
25
|
-
original = Factory(:survey, :title => "Foo", :access_code => 'foo')
|
26
|
-
supplant = Factory(:survey, :title => "Foo", :access_code => 'foo', :survey_version => 1)
|
27
|
-
hash = {"foo"=>[supplant, original]}
|
31
|
+
it "assigns surveys_by_access_code" do
|
28
32
|
do_get
|
29
|
-
assigns(:surveys_by_access_code).should
|
33
|
+
assigns(:surveys_by_access_code).should == {"alpha" => [survey_beta,survey]}
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@newsurvey = Factory(:survey, :title => "xyz", :access_code => "xyz", :survey_version => 1)
|
37
|
-
@response_set = Factory(:response_set, :access_code => "pdq")
|
38
|
-
ResponseSet.stub!(:create).and_return(@response_set)
|
37
|
+
context "#create" do
|
38
|
+
def do_post(params = {})
|
39
|
+
post :create, {:survey_code => "alpha"}.merge(params)
|
39
40
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
it "should create a new response_set" do
|
56
|
-
ResponseSet.should_receive(:create).and_return(@response_set)
|
57
|
-
do_post
|
58
|
-
end
|
59
|
-
it "should redirect to the new response_set" do
|
60
|
-
do_post
|
61
|
-
response.should redirect_to(
|
62
|
-
edit_my_survey_url(:survey_code => "xyz", :response_set_code => "pdq"))
|
63
|
-
end
|
41
|
+
it "finds latest version" do
|
42
|
+
do_post
|
43
|
+
assigns(:survey).should == survey_beta
|
44
|
+
end
|
45
|
+
it "finds specified survey_version" do
|
46
|
+
do_post :survey_version => 0
|
47
|
+
assigns(:survey).should == survey
|
48
|
+
end
|
49
|
+
it "creates a new response_set" do
|
50
|
+
ResponseSet.should_receive(:create)
|
51
|
+
do_post
|
52
|
+
end
|
53
|
+
it "should redirects to the new response_set" do
|
54
|
+
do_post
|
55
|
+
response.should redirect_to( edit_my_survey_path(:survey_code => "alpha", :response_set_code => "pdq"))
|
64
56
|
end
|
65
57
|
|
66
|
-
|
67
|
-
it "
|
58
|
+
context "with failures" do
|
59
|
+
it "redirect to #new on failed ResponseSet#create" do
|
68
60
|
ResponseSet.should_receive(:create).and_return(false)
|
69
|
-
|
70
|
-
response.should redirect_to(
|
61
|
+
do_post
|
62
|
+
response.should redirect_to(available_surveys_path)
|
71
63
|
end
|
72
|
-
it "
|
73
|
-
|
74
|
-
response.should redirect_to(
|
64
|
+
it "redirect to #new on failed Survey#find" do
|
65
|
+
do_post :survey_code => "missing"
|
66
|
+
response.should redirect_to(available_surveys_path)
|
75
67
|
end
|
76
68
|
end
|
77
69
|
|
78
|
-
|
79
|
-
it "
|
80
|
-
|
70
|
+
context "with javascript check, assigned in session" do
|
71
|
+
it "enabled" do
|
72
|
+
do_post :surveyor_javascript_enabled => "true"
|
81
73
|
session[:surveyor_javascript].should_not be_nil
|
82
74
|
session[:surveyor_javascript].should == "enabled"
|
83
75
|
end
|
84
|
-
|
85
|
-
it "sets the user session to know that javascript is not enabled" do
|
76
|
+
it "disabled" do
|
86
77
|
post :create, :survey_code => "xyz", :surveyor_javascript_enabled => "not_true"
|
87
78
|
session[:surveyor_javascript].should_not be_nil
|
88
79
|
session[:surveyor_javascript].should == "not_enabled"
|
89
80
|
end
|
90
|
-
|
91
81
|
end
|
92
|
-
|
93
82
|
end
|
94
83
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
:title => "xyz", :access_code => "xyz", :sections => [Factory(:survey_section)])
|
99
|
-
@response_set = Factory(:response_set, :access_code => "pdq", :survey => @survey)
|
100
|
-
end
|
101
|
-
|
102
|
-
def do_get
|
103
|
-
get :show, :survey_code => "xyz", :response_set_code => "pdq"
|
84
|
+
context "#show" do
|
85
|
+
def do_get(params = {})
|
86
|
+
get :show, {:survey_code => "alpha", :response_set_code => "pdq"}.merge(params)
|
104
87
|
end
|
105
|
-
|
106
|
-
it "should be successful" do
|
88
|
+
it "renders show" do
|
107
89
|
do_get
|
108
90
|
response.should be_success
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should render show template" do
|
112
|
-
do_get
|
113
91
|
response.should render_template('show')
|
114
92
|
end
|
115
|
-
|
116
|
-
|
117
|
-
ResponseSet.should_receive(:find_by_access_code).
|
118
|
-
with("pdq",{:include=>{:responses=>[:question, :answer]}}).and_return(@response_set)
|
93
|
+
it "finds ResponseSet with includes" do
|
94
|
+
ResponseSet.should_receive(:find_by_access_code).with("pdq",{:include=>{:responses=>[:question, :answer]}})
|
119
95
|
do_get
|
120
96
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
response.should redirect_to(available_surveys_url)
|
97
|
+
it "redirects for missing response set" do
|
98
|
+
do_get :response_set_code => "DIFFERENT"
|
99
|
+
response.should redirect_to(available_surveys_path)
|
125
100
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
assigns[:response_set].should ==
|
136
|
-
assigns[:survey].should ==
|
137
|
-
|
138
|
-
get :show, :survey_code => "xyz", :response_set_code => "rst"
|
139
|
-
response.should be_success
|
140
|
-
response.should render_template('show')
|
141
|
-
assigns[:response_set].should == supplant_response_set
|
142
|
-
assigns[:survey].should == supplant
|
101
|
+
it "assigns earlier survey_version" do
|
102
|
+
response_set
|
103
|
+
do_get
|
104
|
+
assigns[:response_set].should == response_set
|
105
|
+
assigns[:survey].should == survey
|
106
|
+
end
|
107
|
+
it "assigns later survey_version" do
|
108
|
+
response_set_beta
|
109
|
+
do_get :response_set_code => "rst"
|
110
|
+
assigns[:response_set].should == response_set_beta
|
111
|
+
assigns[:survey].should == survey_beta
|
143
112
|
end
|
144
|
-
|
145
113
|
end
|
146
114
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
@response_set = Factory(:response_set, :access_code => "PDQ", :survey => @survey)
|
115
|
+
context "#edit" do
|
116
|
+
def do_get(params = {})
|
117
|
+
survey.sections = [Factory(:survey_section, :survey => survey)]
|
118
|
+
get :edit, {:survey_code => "alpha", :response_set_code => "pdq"}.merge(params)
|
152
119
|
end
|
153
|
-
|
154
|
-
|
155
|
-
ResponseSet.should_receive(:find_by_access_code).and_return(@response_set)
|
156
|
-
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
120
|
+
it "renders edit" do
|
121
|
+
do_get
|
157
122
|
response.should be_success
|
158
123
|
response.should render_template('edit')
|
159
|
-
assigns[:response_set].should == @response_set
|
160
|
-
assigns[:survey].should == @survey
|
161
124
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
125
|
+
it "assigns survey and response set" do
|
126
|
+
do_get
|
127
|
+
assigns[:survey].should == survey
|
128
|
+
assigns[:response_set].should == response_set
|
166
129
|
end
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
174
|
-
assigns[:dependents].should_not be_empty
|
130
|
+
it "redirects for missing response set" do
|
131
|
+
do_get :response_set_code => "DIFFERENT"
|
132
|
+
response.should redirect_to(available_surveys_path)
|
133
|
+
end
|
134
|
+
it "assigns dependents if javascript not enabled" do
|
135
|
+
controller.stub!(:get_unanswered_dependencies_minus_section_questions).and_return([Factory(:question)])
|
175
136
|
session[:surveyor_javascript].should be_nil
|
137
|
+
do_get
|
138
|
+
assigns[:dependents].should_not be_empty
|
176
139
|
end
|
177
|
-
|
178
|
-
|
179
|
-
ResponseSet.should_receive(:find_by_access_code).and_return(@response_set)
|
180
|
-
controller.stub!(:get_unanswered_dependencies_minus_section_questions).
|
181
|
-
and_return([Question.new])
|
182
|
-
|
140
|
+
it "does not assign dependents if javascript is enabled" do
|
141
|
+
controller.stub!(:get_unanswered_dependencies_minus_section_questions).and_return([Factory(:question)])
|
183
142
|
session[:surveyor_javascript] = "enabled"
|
184
|
-
|
185
|
-
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
143
|
+
do_get
|
186
144
|
assigns[:dependents].should be_empty
|
187
|
-
session[:surveyor_javascript].should == "enabled"
|
188
145
|
end
|
146
|
+
it "assigns earlier survey_version" do
|
147
|
+
do_get
|
148
|
+
assigns[:response_set].should == response_set
|
149
|
+
assigns[:survey].should == survey
|
150
|
+
end
|
151
|
+
it "assigns later survey_version" do
|
152
|
+
survey_beta.sections = [Factory(:survey_section, :survey => survey_beta)]
|
153
|
+
do_get :response_set_code => "rst"
|
154
|
+
assigns[:survey].should == survey_beta
|
155
|
+
assigns[:response_set].should == response_set_beta
|
189
156
|
|
190
|
-
it "should render correct survey survey_version" do
|
191
|
-
supplant = Factory(:survey, :title => "XYZ", :access_code => 'XYZ', :survey_version => 1)
|
192
|
-
supplant_section = Factory(:survey_section, :survey => supplant)
|
193
|
-
supplant_response_set = Factory(:response_set, :access_code => "RST", :survey => supplant)
|
194
|
-
|
195
|
-
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
196
|
-
response.should be_success
|
197
|
-
response.should render_template('edit')
|
198
|
-
assigns[:response_set].should == @response_set
|
199
|
-
assigns[:survey].should == @survey
|
200
|
-
|
201
|
-
get :edit, :survey_code => "XYZ", :response_set_code => "RST"
|
202
|
-
response.should be_success
|
203
|
-
response.should render_template('edit')
|
204
|
-
assigns[:response_set].should == supplant_response_set
|
205
|
-
assigns[:survey].should == supplant
|
206
157
|
end
|
207
158
|
end
|
208
159
|
|
209
|
-
|
210
|
-
let(:survey_code) { 'XYZ' }
|
211
|
-
let!(:survey) { Factory(:survey, :title => survey_code, :access_code => survey_code) }
|
212
|
-
|
213
|
-
let(:response_set_code) { 'PDQ' }
|
214
|
-
let!(:response_set) { Factory(:response_set, :access_code => response_set_code, :survey => survey) }
|
215
|
-
|
160
|
+
context "#update" do
|
216
161
|
let(:responses_ui_hash) { {} }
|
217
|
-
|
218
|
-
let(:params) {
|
162
|
+
let(:update_params) {
|
219
163
|
{
|
220
|
-
:survey_code =>
|
221
|
-
:response_set_code =>
|
222
|
-
:r => responses_ui_hash.empty? ? nil : responses_ui_hash
|
164
|
+
:survey_code => "alpha",
|
165
|
+
:response_set_code => "pdq"
|
223
166
|
}
|
224
167
|
}
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
it "should find the response set requested" do
|
168
|
+
shared_examples "#update action" do
|
169
|
+
before do
|
170
|
+
ResponseSet.stub!(:find_by_access_code).and_return(response_set)
|
171
|
+
responses_ui_hash['11'] = {'api_id' => 'something', 'answer_id' => '56', 'question_id' => '9'}
|
172
|
+
end
|
173
|
+
it "finds a response set" do
|
232
174
|
ResponseSet.should_receive(:find_by_access_code).and_return(response_set)
|
233
175
|
do_put
|
234
176
|
end
|
235
|
-
|
236
|
-
it 'applies any provided responses to the response set' do
|
237
|
-
ResponseSet.stub!(:find_by_access_code).and_return(response_set)
|
238
|
-
|
239
|
-
responses_ui_hash['11'] = a_ui_response('answer_id' => '56', 'question_id' => '9')
|
177
|
+
it "saves responses" do
|
240
178
|
response_set.should_receive(:update_from_ui_hash).with(responses_ui_hash)
|
241
|
-
do_put
|
242
|
-
end
|
243
179
|
|
244
|
-
|
180
|
+
do_put(:r => responses_ui_hash)
|
181
|
+
end
|
182
|
+
it "does not fail when there are no responses" do
|
245
183
|
lambda { do_put }.should_not raise_error
|
246
184
|
end
|
247
|
-
|
248
|
-
describe 'when updating the response set produces a exception' do
|
249
|
-
before do
|
250
|
-
responses_ui_hash['11'] = a_ui_response('answer_id' => '56', 'question_id' => '9')
|
251
|
-
|
252
|
-
ResponseSet.stub!(:find_by_access_code).and_return(response_set)
|
253
|
-
end
|
254
|
-
|
185
|
+
context "with update exceptions" do
|
255
186
|
it 'retries the update on a constraint violation' do
|
256
|
-
response_set.should_receive(:update_from_ui_hash).ordered.
|
257
|
-
with(responses_ui_hash).and_raise(ActiveRecord::StatementInvalid)
|
187
|
+
response_set.should_receive(:update_from_ui_hash).ordered.with(responses_ui_hash).and_raise(ActiveRecord::StatementInvalid)
|
258
188
|
response_set.should_receive(:update_from_ui_hash).ordered.with(responses_ui_hash)
|
259
189
|
|
260
|
-
|
190
|
+
expect { do_put(:r => responses_ui_hash) }.to_not raise_error
|
261
191
|
end
|
262
192
|
|
263
193
|
it 'only retries three times' do
|
264
|
-
response_set.should_receive(:update_from_ui_hash).exactly(3).times.
|
265
|
-
with(responses_ui_hash).and_raise(ActiveRecord::StatementInvalid)
|
194
|
+
response_set.should_receive(:update_from_ui_hash).exactly(3).times.with(responses_ui_hash).and_raise(ActiveRecord::StatementInvalid)
|
266
195
|
|
267
|
-
|
196
|
+
expect { do_put(:r => responses_ui_hash) }.to raise_error(ActiveRecord::StatementInvalid)
|
268
197
|
end
|
269
198
|
|
270
199
|
it 'does not retry for other errors' do
|
271
|
-
response_set.should_receive(:update_from_ui_hash).once.
|
272
|
-
with(responses_ui_hash).and_raise('Bad news')
|
200
|
+
response_set.should_receive(:update_from_ui_hash).once.with(responses_ui_hash).and_raise('Bad news')
|
273
201
|
|
274
|
-
|
202
|
+
expect { do_put(:r => responses_ui_hash) }.to raise_error('Bad news')
|
275
203
|
end
|
276
204
|
end
|
277
205
|
end
|
278
206
|
|
279
|
-
|
280
|
-
def do_put
|
281
|
-
put :update,
|
207
|
+
context "with form submission" do
|
208
|
+
def do_put(extra_params = {})
|
209
|
+
put :update, update_params.merge(extra_params)
|
282
210
|
end
|
283
211
|
|
284
|
-
|
285
|
-
|
286
|
-
it "should redirect to 'edit' without params" do
|
212
|
+
it_behaves_like "#update action"
|
213
|
+
it "redirects to #edit without params" do
|
287
214
|
do_put
|
288
|
-
response.should redirect_to(:
|
215
|
+
response.should redirect_to(edit_my_survey_path(:survey_code => "alpha", :response_set_code => "pdq"))
|
289
216
|
end
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
params[:finish] = 'finish'
|
294
|
-
do_put
|
295
|
-
end
|
296
|
-
|
297
|
-
it "completes the found response set" do
|
298
|
-
response_set.reload.should be_complete
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'flashes completion' do
|
302
|
-
flash[:notice].should == "Completed survey"
|
303
|
-
end
|
217
|
+
it "completes the found response set on finish" do
|
218
|
+
do_put :finish => 'finish'
|
219
|
+
response_set.reload.should be_complete
|
304
220
|
end
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
221
|
+
it 'flashes completion' do
|
222
|
+
do_put :finish => 'finish'
|
223
|
+
flash[:notice].should == "Completed survey"
|
224
|
+
end
|
225
|
+
it "redirects for missing response set" do
|
226
|
+
do_put :response_set_code => "DIFFERENT"
|
227
|
+
response.should redirect_to(available_surveys_path)
|
310
228
|
flash[:notice].should == "Unable to find your responses to the survey"
|
311
229
|
end
|
312
230
|
end
|
313
231
|
|
314
|
-
|
315
|
-
def do_put
|
316
|
-
xhr :put, :update,
|
232
|
+
context 'with ajax' do
|
233
|
+
def do_put(extra_params = {})
|
234
|
+
xhr :put, :update, update_params.merge(extra_params)
|
317
235
|
end
|
318
236
|
|
319
|
-
|
320
|
-
|
321
|
-
it "should return dependencies" do
|
237
|
+
it_behaves_like "#update action"
|
238
|
+
it "returns dependencies" do
|
322
239
|
ResponseSet.stub!(:find_by_access_code).and_return(response_set)
|
240
|
+
response_set.should_receive(:all_dependencies).and_return({"show" => ['q_1'], "hide" => ['q_2']})
|
323
241
|
|
324
|
-
response_set.should_receive(:all_dependencies).
|
325
|
-
and_return({"show" => ['q_1'], "hide" => ['q_2']})
|
326
|
-
|
327
|
-
responses_ui_hash['4'] = a_ui_response("question_id"=>"9", "answer_id"=>"12") # check
|
328
242
|
do_put
|
329
|
-
|
330
|
-
JSON.parse(response.body).
|
331
|
-
should == {"show" => ['q_1'], "hide" => ["q_2"]}
|
243
|
+
JSON.parse(response.body).should == {"show" => ['q_1'], "hide" => ["q_2"]}
|
332
244
|
end
|
333
|
-
|
334
|
-
|
335
|
-
params[:response_set_code] = 'ELSE'
|
336
|
-
do_put
|
245
|
+
it "returns 404 for missing response set" do
|
246
|
+
do_put :response_set_code => "DIFFERENT"
|
337
247
|
response.status.should == 404
|
338
248
|
end
|
339
249
|
end
|
340
250
|
end
|
341
251
|
|
342
|
-
|
252
|
+
context "#export" do
|
343
253
|
render_views
|
344
254
|
|
345
255
|
let(:json) {
|
@@ -347,7 +257,7 @@ describe SurveyorController do
|
|
347
257
|
JSON.parse(response.body)
|
348
258
|
}
|
349
259
|
|
350
|
-
|
260
|
+
context "question inside and outside a question group" do
|
351
261
|
def question_text(refid)
|
352
262
|
<<-SURVEY
|
353
263
|
q "Where is a foo?", :pick => :one, :help_text => 'Look around.', :reference_identifier => #{refid.inspect},
|
@@ -360,7 +270,6 @@ describe SurveyorController do
|
|
360
270
|
condition_R :q_bar, "==", :a_1
|
361
271
|
SURVEY
|
362
272
|
end
|
363
|
-
|
364
273
|
let(:survey_text) {
|
365
274
|
<<-SURVEY
|
366
275
|
survey 'xyz' do
|
@@ -378,42 +287,19 @@ describe SurveyorController do
|
|
378
287
|
end
|
379
288
|
SURVEY
|
380
289
|
}
|
381
|
-
|
382
|
-
let(:survey) {
|
383
|
-
Surveyor::Parser.new.parse(survey_text)
|
384
|
-
}
|
385
|
-
|
290
|
+
let(:survey) { Surveyor::Parser.new.parse(survey_text) }
|
386
291
|
let(:solo_question_json) { json['sections'][0]['questions_and_groups'][1] }
|
387
292
|
let(:grouped_question_json) { json['sections'][0]['questions_and_groups'][2]['questions'][0] }
|
388
293
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
node.values.each { |val| remove_key_recursively(val, key) }
|
394
|
-
when Array
|
395
|
-
node.each { |val| remove_key_recursively(val, key) }
|
396
|
-
end
|
294
|
+
it "produces identical JSON except for API IDs and question reference identifers" do
|
295
|
+
solo_question_json['answers'].to_json.should be_json_eql( grouped_question_json['answers'].to_json).excluding("uuid", "reference_identifier")
|
296
|
+
solo_question_json['dependency'].to_json.should be_json_eql( grouped_question_json['dependency'].to_json).excluding("uuid", "reference_identifier")
|
297
|
+
solo_question_json.to_json.should be_json_eql( grouped_question_json.to_json).excluding("uuid", "reference_identifier")
|
397
298
|
end
|
398
|
-
|
399
|
-
it 'produces identical JSON except for API IDs and question reference identifers' do
|
400
|
-
[solo_question_json, grouped_question_json].each do |node|
|
401
|
-
node.reject! { |k, v| k == 'reference_identifier' }
|
402
|
-
remove_key_recursively(node, 'uuid')
|
403
|
-
end
|
404
|
-
|
405
|
-
# easier to see differences this way
|
406
|
-
solo_question_json['answers'].should == grouped_question_json['answers']
|
407
|
-
solo_question_json['dependency'].should == grouped_question_json['dependency']
|
408
|
-
|
409
|
-
solo_question_json.should == grouped_question_json
|
410
|
-
end
|
411
|
-
|
412
|
-
it 'produces the expected reference identifier for the solo question' do
|
299
|
+
it "produces the expected reference identifier for the solo question" do
|
413
300
|
solo_question_json['reference_identifier'].should == 'foo_solo'
|
414
301
|
end
|
415
|
-
|
416
|
-
it 'produces the expected reference identifer for the question in the group' do
|
302
|
+
it "produces the expected reference identifer for the question in the group" do
|
417
303
|
grouped_question_json['reference_identifier'].should == 'foo_grouped'
|
418
304
|
end
|
419
305
|
end
|