affectiva-surveyor 1.5.0.pre.disco.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +198 -0
- data/Gemfile +5 -0
- data/Gemfile.rails_version +27 -0
- data/MIT-LICENSE +20 -0
- data/README.md +166 -0
- data/Rakefile +106 -0
- data/app/controllers/surveyor_controller.rb +5 -0
- data/app/helpers/results_helper.rb +20 -0
- data/app/helpers/survey_form_builder.rb +37 -0
- data/app/helpers/surveyor_helper.rb +3 -0
- data/app/inputs/quiet_input.rb +5 -0
- data/app/inputs/surveyor_check_boxes_input.rb +35 -0
- data/app/inputs/surveyor_radio_input.rb +18 -0
- data/app/models/answer.rb +3 -0
- data/app/models/dependency.rb +3 -0
- data/app/models/dependency_condition.rb +3 -0
- data/app/models/question.rb +3 -0
- data/app/models/question_group.rb +4 -0
- data/app/models/response.rb +4 -0
- data/app/models/response_set.rb +3 -0
- data/app/models/survey.rb +3 -0
- data/app/models/survey_section.rb +4 -0
- data/app/models/survey_section_sweeper.rb +15 -0
- data/app/models/survey_translation.rb +4 -0
- data/app/models/validation.rb +3 -0
- data/app/models/validation_condition.rb +3 -0
- data/app/views/layouts/results.html.erb +13 -0
- data/app/views/layouts/surveyor_default.html.erb +12 -0
- data/app/views/partials/_answer.html.haml +25 -0
- data/app/views/partials/_dependents.html.haml +5 -0
- data/app/views/partials/_question.html.haml +28 -0
- data/app/views/partials/_question_group.html.haml +44 -0
- data/app/views/partials/_section.html.haml +12 -0
- data/app/views/partials/_section_menu.html.haml +12 -0
- data/app/views/surveyor/edit.html.haml +24 -0
- data/app/views/surveyor/export.json.rabl +85 -0
- data/app/views/surveyor/new.html.haml +24 -0
- data/app/views/surveyor/show.html.haml +74 -0
- data/app/views/surveyor/show.json.rabl +15 -0
- data/ci-exec.sh +56 -0
- data/config/routes.rb +8 -0
- data/cucumber.yml +10 -0
- data/doc/REPRESENTATIONS.md +34 -0
- data/doc/api_id_schema.json +7 -0
- data/doc/question types.png +0 -0
- data/doc/response_set_schema.json +54 -0
- data/doc/surveyor question combinations.png +0 -0
- data/doc/surveyor reject or delete decision matrix.png +0 -0
- data/doc/surveyor_models.png +0 -0
- data/doc/surveyor_models2.png +0 -0
- data/doc/surveyor_timestamp_schema.json +9 -0
- data/features/ajax_submissions.feature +140 -0
- data/features/export_to_json.feature +344 -0
- data/features/internationalization.feature +121 -0
- data/features/no_duplicates.feature +110 -0
- data/features/show_survey.feature +71 -0
- data/features/step_definitions/parser_steps.rb +145 -0
- data/features/step_definitions/surveyor_steps.rb +325 -0
- data/features/step_definitions/ui_steps.rb +25 -0
- data/features/step_definitions/web_steps.rb +225 -0
- data/features/support/REDCapDemoDatabase_DataDictionary.csv +127 -0
- data/features/support/database_cleaner.rb +16 -0
- data/features/support/env.rb +56 -0
- data/features/support/hooks.rb +4 -0
- data/features/support/paths.rb +39 -0
- data/features/support/redcap_new_headers.csv +1 -0
- data/features/support/redcap_siblings.csv +1 -0
- data/features/support/redcap_whitespace.csv +1 -0
- data/features/support/selectors.rb +39 -0
- data/features/support/simultaneous_ajax.rb +101 -0
- data/features/support/single_quit_selenium_driver.rb +23 -0
- data/features/support/slow_updates.rb +18 -0
- data/features/surveyor.feature +895 -0
- data/features/surveyor_dependencies.feature +476 -0
- data/features/surveyor_parser.feature +504 -0
- data/features/z_redcap_parser.feature +62 -0
- data/lib/assets/images/surveyor/next.gif +0 -0
- data/lib/assets/images/surveyor/prev.gif +0 -0
- data/lib/assets/images/surveyor/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/assets/images/surveyor/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_222222_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_454545_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_888888_256x240.png +0 -0
- data/lib/assets/images/surveyor/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/assets/javascripts/surveyor/jquery-1.9.0.js +9555 -0
- data/lib/assets/javascripts/surveyor/jquery-ui-1.10.0.custom.js +14850 -0
- data/lib/assets/javascripts/surveyor/jquery-ui-timepicker-addon.js +1919 -0
- data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
- data/lib/assets/javascripts/surveyor/jquery.selectToUISlider.js +240 -0
- data/lib/assets/javascripts/surveyor/jquery.surveyor.js +154 -0
- data/lib/assets/stylesheets/surveyor.sass +132 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +11 -0
- data/lib/assets/stylesheets/surveyor/reset.css +48 -0
- data/lib/assets/stylesheets/surveyor/results.css +125 -0
- data/lib/assets/stylesheets/surveyor/ui.slider.extras.css +110 -0
- data/lib/generators/surveyor/custom_generator.rb +18 -0
- data/lib/generators/surveyor/install_generator.rb +101 -0
- data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +6 -0
- data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +9 -0
- data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +40 -0
- data/lib/generators/surveyor/templates/app/views/layouts/surveyor_custom.html.erb +13 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +19 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +19 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +19 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +19 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_id_to_question_groups.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids.rb +14 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids_to_response_sets_and_responses.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/add_correct_answer_id_to_questions.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_default_value_to_answers.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_display_order_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_display_type_to_answers.rb +14 -0
- data/lib/generators/surveyor/templates/db/migrate/add_index_to_response_sets.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_index_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/add_section_id_to_responses.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/add_unique_index_on_access_code_and_version_in_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_unique_indicies.rb +18 -0
- data/lib/generators/surveyor/templates/db/migrate/add_version_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/api_ids_must_be_unique.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_answers.rb +38 -0
- data/lib/generators/surveyor/templates/db/migrate/create_dependencies.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_dependency_conditions.rb +30 -0
- data/lib/generators/surveyor/templates/db/migrate/create_question_groups.rb +28 -0
- data/lib/generators/surveyor/templates/db/migrate/create_questions.rb +37 -0
- data/lib/generators/surveyor/templates/db/migrate/create_response_sets.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_responses.rb +34 -0
- data/lib/generators/surveyor/templates/db/migrate/create_survey_sections.rb +30 -0
- data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
- data/lib/generators/surveyor/templates/db/migrate/create_surveys.rb +32 -0
- data/lib/generators/surveyor/templates/db/migrate/create_validation_conditions.rb +33 -0
- data/lib/generators/surveyor/templates/db/migrate/create_validations.rb +21 -0
- data/lib/generators/surveyor/templates/db/migrate/drop_unique_index_on_access_code_in_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb +22 -0
- data/lib/generators/surveyor/templates/db/migrate/update_blank_versions_on_surveys.rb +13 -0
- data/lib/generators/surveyor/templates/surveys/EXTENDING_SURVEYOR.md +52 -0
- data/lib/generators/surveyor/templates/surveys/MODIFYING_SURVEYOR.md +91 -0
- data/lib/generators/surveyor/templates/surveys/date_survey.rb +16 -0
- data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +280 -0
- data/lib/generators/surveyor/templates/surveys/languages.rb +14 -0
- data/lib/generators/surveyor/templates/surveys/quiz.rb +11 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +18 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +18 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +18 -0
- data/lib/generators/surveyor/templates/vendor/assets/stylesheets/custom.sass +5 -0
- data/lib/surveyor.rb +13 -0
- data/lib/surveyor/acts_as_response.rb +17 -0
- data/lib/surveyor/common.rb +59 -0
- data/lib/surveyor/engine.rb +10 -0
- data/lib/surveyor/helpers/asset_pipeline.rb +18 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +13 -0
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +103 -0
- data/lib/surveyor/models/answer_methods.rb +83 -0
- data/lib/surveyor/models/dependency_condition_methods.rb +69 -0
- data/lib/surveyor/models/dependency_methods.rb +57 -0
- data/lib/surveyor/models/question_group_methods.rb +58 -0
- data/lib/surveyor/models/question_methods.rb +112 -0
- data/lib/surveyor/models/response_methods.rb +126 -0
- data/lib/surveyor/models/response_set_methods.rb +188 -0
- data/lib/surveyor/models/survey_methods.rb +100 -0
- data/lib/surveyor/models/survey_section_methods.rb +53 -0
- data/lib/surveyor/models/survey_translation_methods.rb +30 -0
- data/lib/surveyor/models/validation_condition_methods.rb +54 -0
- data/lib/surveyor/models/validation_methods.rb +45 -0
- data/lib/surveyor/mustache_context.rb +11 -0
- data/lib/surveyor/parser.rb +427 -0
- data/lib/surveyor/redcap_parser.rb +288 -0
- data/lib/surveyor/surveyor_controller_methods.rb +236 -0
- data/lib/surveyor/unparser.rb +147 -0
- data/lib/surveyor/version.rb +3 -0
- data/lib/tasks/surveyor_tasks.rake +88 -0
- data/rails/init.rb +1 -0
- data/spec/controllers/surveyor_controller_spec.rb +311 -0
- data/spec/factories.rb +166 -0
- data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
- data/spec/helpers/surveyor_helper_spec.rb +117 -0
- data/spec/lib/benchmark_spec.rb +22 -0
- data/spec/lib/chinese_survey.rb +14 -0
- data/spec/lib/common_spec.rb +34 -0
- data/spec/lib/parser_spec.rb +204 -0
- data/spec/lib/rake_kitchen_sink.rb +40 -0
- data/spec/lib/redcap_parser_spec.rb +75 -0
- data/spec/lib/tasks_spec.rake +26 -0
- data/spec/lib/unparser_spec.rb +126 -0
- data/spec/models/answer_spec.rb +174 -0
- data/spec/models/dependency_condition_spec.rb +439 -0
- data/spec/models/dependency_spec.rb +101 -0
- data/spec/models/question_group_spec.rb +93 -0
- data/spec/models/question_spec.rb +206 -0
- data/spec/models/response_set_spec.rb +477 -0
- data/spec/models/response_spec.rb +218 -0
- data/spec/models/survey_section_spec.rb +85 -0
- data/spec/models/survey_spec.rb +191 -0
- data/spec/models/validation_condition_spec.rb +113 -0
- data/spec/models/validation_spec.rb +74 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +56 -0
- data/stacktests.sh +65 -0
- data/surveyor.gemspec +53 -0
- metadata +601 -0
data/spec/factories.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# http://github.com/thoughtbot/factory_girl/tree/master
|
3
|
+
require 'rubygems'
|
4
|
+
require 'factory_girl'
|
5
|
+
|
6
|
+
FactoryGirl.define do
|
7
|
+
|
8
|
+
sequence(:unique_survey_access_code){|n| "simple survey #{UUIDTools::UUID.random_create.to_s}" }
|
9
|
+
|
10
|
+
factory :survey do |s|
|
11
|
+
s.title "Simple survey"
|
12
|
+
s.description "A simple survey for testing"
|
13
|
+
s.access_code { FactoryGirl.generate :unique_survey_access_code }
|
14
|
+
s.survey_version 0
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
factory :survey_translation do |t|
|
19
|
+
t.locale "es"
|
20
|
+
t.translation %(title: "Un idioma nunca es suficiente"
|
21
|
+
survey_sections:
|
22
|
+
one:
|
23
|
+
title: "Uno"
|
24
|
+
questions:
|
25
|
+
hello:
|
26
|
+
text: "¡Hola!"
|
27
|
+
name:
|
28
|
+
text: "¿Cómo se llama Usted?"
|
29
|
+
answers:
|
30
|
+
name:
|
31
|
+
help_text: "Mi nombre es...")
|
32
|
+
end
|
33
|
+
|
34
|
+
sequence(:survey_section_display_order){|n| n }
|
35
|
+
|
36
|
+
factory :survey_section do |s|
|
37
|
+
s.association :survey # s.survey_id {}
|
38
|
+
s.title {"Demographics"}
|
39
|
+
s.description {"Asking you about your personal data"}
|
40
|
+
s.display_order {FactoryGirl.generate :survey_section_display_order}
|
41
|
+
s.reference_identifier {"demographics"}
|
42
|
+
s.data_export_identifier {"demographics"}
|
43
|
+
end
|
44
|
+
|
45
|
+
sequence(:question_display_order){|n| n }
|
46
|
+
|
47
|
+
factory :question do |q|
|
48
|
+
q.association :survey_section # s.survey_section_id {}
|
49
|
+
# q.question_group_id {}
|
50
|
+
q.text "What is your favorite color?"
|
51
|
+
q.short_text "favorite_color"
|
52
|
+
q.help_text "just write it in the box"
|
53
|
+
q.pick :none
|
54
|
+
q.reference_identifier {|me| "q_#{me.object_id}"}
|
55
|
+
# q.data_export_identifier {}
|
56
|
+
# q.common_namespace {}
|
57
|
+
# q.common_identifier {}
|
58
|
+
q.display_order FactoryGirl.generate(:question_display_order)
|
59
|
+
# q.display_type {} # nil is default
|
60
|
+
q.is_mandatory false
|
61
|
+
# q.display_width {}
|
62
|
+
q.correct_answer_id nil
|
63
|
+
end
|
64
|
+
|
65
|
+
factory :question_group do |g|
|
66
|
+
g.text {"Describe your family"}
|
67
|
+
g.help_text {}
|
68
|
+
g.reference_identifier {|me| "g_#{me.object_id}"}
|
69
|
+
g.data_export_identifier {}
|
70
|
+
g.common_namespace {}
|
71
|
+
g.common_identifier {}
|
72
|
+
g.display_type {}
|
73
|
+
g.custom_class {}
|
74
|
+
g.custom_renderer {}
|
75
|
+
end
|
76
|
+
|
77
|
+
sequence(:answer_display_order){|n| n }
|
78
|
+
|
79
|
+
factory :answer do |a|
|
80
|
+
a.association :question # a.question_id {}
|
81
|
+
a.text "My favorite color is clear"
|
82
|
+
a.short_text "clear"
|
83
|
+
a.help_text "Clear is the absense of color"
|
84
|
+
# a.weight
|
85
|
+
a.response_class "string"
|
86
|
+
# a.reference_identifier {}
|
87
|
+
# a.data_export_identifier {}
|
88
|
+
# a.common_namespace {}
|
89
|
+
# a.common_identifier {}
|
90
|
+
a.display_order {FactoryGirl.generate :answer_display_order}
|
91
|
+
# a.is_exclusive {}
|
92
|
+
a.display_type "default"
|
93
|
+
# a.display_length {}
|
94
|
+
# a.custom_class {}
|
95
|
+
# a.custom_renderer {}
|
96
|
+
end
|
97
|
+
|
98
|
+
factory :dependency do |d|
|
99
|
+
# the dependent question
|
100
|
+
d.association :question # d.question_id {}
|
101
|
+
d.question_group_id {}
|
102
|
+
d.rule {"A"}
|
103
|
+
end
|
104
|
+
|
105
|
+
factory :dependency_condition do |d|
|
106
|
+
d.association :dependency # d.dependency_id {}
|
107
|
+
d.rule_key {"A"}
|
108
|
+
# the conditional question
|
109
|
+
d.question_id {}
|
110
|
+
d.operator {"=="}
|
111
|
+
d.answer_id {}
|
112
|
+
d.datetime_value {}
|
113
|
+
d.integer_value {}
|
114
|
+
d.float_value {}
|
115
|
+
d.unit {}
|
116
|
+
d.text_value {}
|
117
|
+
d.string_value {}
|
118
|
+
d.response_other {}
|
119
|
+
end
|
120
|
+
|
121
|
+
factory :response_set do |r|
|
122
|
+
r.user_id {}
|
123
|
+
r.association :survey # r.survey_id {}
|
124
|
+
r.access_code {Surveyor::Common.make_tiny_code}
|
125
|
+
r.started_at {Time.now}
|
126
|
+
r.completed_at {}
|
127
|
+
end
|
128
|
+
|
129
|
+
factory :response do |r|
|
130
|
+
r.association :response_set # r.response_set_id {}
|
131
|
+
r.survey_section_id {}
|
132
|
+
r.question_id {}
|
133
|
+
r.answer_id {}
|
134
|
+
r.datetime_value {}
|
135
|
+
r.integer_value {}
|
136
|
+
r.float_value {}
|
137
|
+
r.unit {}
|
138
|
+
r.text_value {}
|
139
|
+
r.string_value {}
|
140
|
+
r.response_other {}
|
141
|
+
r.response_group {}
|
142
|
+
end
|
143
|
+
|
144
|
+
factory :validation do |v|
|
145
|
+
v.association :answer # v.answer_id {}
|
146
|
+
v.rule {"A"}
|
147
|
+
v.message {}
|
148
|
+
end
|
149
|
+
|
150
|
+
factory :validation_condition do |v|
|
151
|
+
v.association :validation # v.validation_id {}
|
152
|
+
v.rule_key {"A"}
|
153
|
+
v.question_id {}
|
154
|
+
v.operator {"=="}
|
155
|
+
v.answer_id {}
|
156
|
+
v.datetime_value {}
|
157
|
+
v.integer_value {}
|
158
|
+
v.float_value {}
|
159
|
+
v.unit {}
|
160
|
+
v.text_value {}
|
161
|
+
v.string_value {}
|
162
|
+
v.response_other {}
|
163
|
+
v.regexp {}
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../lib/surveyor/helpers/formtastic_custom_input')
|
3
|
+
|
4
|
+
describe Surveyor::Helpers::FormtasticCustomInput do
|
5
|
+
context "input helpers" do
|
6
|
+
it "should translate response class into attribute" do
|
7
|
+
helper.response_class_to_method(:string).should == :string_value
|
8
|
+
helper.response_class_to_method(:integer).should == :integer_value
|
9
|
+
helper.response_class_to_method(:float).should == :float_value
|
10
|
+
helper.response_class_to_method(:datetime).should == :datetime_value
|
11
|
+
helper.response_class_to_method(:date).should == :date_value
|
12
|
+
helper.response_class_to_method(:time).should == :time_value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe SurveyorHelper do
|
4
|
+
context "numbering" do
|
5
|
+
before do
|
6
|
+
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
|
7
|
+
end
|
8
|
+
it "should return the question text with number, except for labels, dependencies, images, and grouped questions" do
|
9
|
+
q1 = FactoryGirl.create(:question)
|
10
|
+
q2 = FactoryGirl.create(:question, :display_type => "label")
|
11
|
+
q3 = FactoryGirl.create(:question, :dependency => FactoryGirl.create(:dependency))
|
12
|
+
q4 = FactoryGirl.create(:question, :display_type => "image", :text => "something.jpg")
|
13
|
+
q5 = FactoryGirl.create(:question, :question_group => FactoryGirl.create(:question_group))
|
14
|
+
helper.q_text(q1).should == "<span class='qnum'>1) </span>#{q1.text}"
|
15
|
+
helper.q_text(q2).should == q2.text
|
16
|
+
helper.q_text(q3).should == q3.text
|
17
|
+
helper.q_text(q4).should == %Q(<img alt="Something" src="/images/something.jpg" />)
|
18
|
+
helper.q_text(q5).should == q5.text
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with mustache text substitution" do
|
23
|
+
require 'mustache'
|
24
|
+
let(:mustache_context){ Class.new(::Mustache){ def site; "Northwestern"; end; def somethingElse; "something new"; end; def group; "NUBIC"; end } }
|
25
|
+
it "substitues values into Question#text" do
|
26
|
+
q1 = FactoryGirl.create(:question, :text => "You are in {{site}}")
|
27
|
+
label = FactoryGirl.create(:question, :display_type => "label", :text => "Testing {{somethingElse}}")
|
28
|
+
helper.q_text(q1, mustache_context).should == "<span class='qnum'>1) </span>You are in Northwestern"
|
29
|
+
helper.q_text(label, mustache_context).should == "Testing something new"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "response methods" do
|
34
|
+
it "should find or create responses, with index" do
|
35
|
+
q1 = FactoryGirl.create(:question, :answers => [a = FactoryGirl.create(:answer, :text => "different")])
|
36
|
+
q2 = FactoryGirl.create(:question, :answers => [b = FactoryGirl.create(:answer, :text => "strokes")])
|
37
|
+
q3 = FactoryGirl.create(:question, :answers => [c = FactoryGirl.create(:answer, :text => "folks")])
|
38
|
+
rs = FactoryGirl.create(:response_set, :responses => [r1 = FactoryGirl.create(:response, :question => q1, :answer => a), r3 = FactoryGirl.create(:response, :question => q3, :answer => c, :response_group => 1)])
|
39
|
+
|
40
|
+
helper.response_for(rs, nil).should == nil
|
41
|
+
helper.response_for(nil, q1).should == nil
|
42
|
+
helper.response_for(rs, q1).should == r1
|
43
|
+
helper.response_for(rs, q1, a).should == r1
|
44
|
+
helper.response_for(rs, q2).attributes.reject{|k,v| k == "api_id"}.should == Response.new(:question => q2, :response_set => rs).attributes.reject{|k,v| k == "api_id"}
|
45
|
+
helper.response_for(rs, q2, b).attributes.reject{|k,v| k == "api_id"}.should == Response.new(:question => q2, :response_set => rs).attributes.reject{|k,v| k == "api_id"}
|
46
|
+
helper.response_for(rs, q3, c, "1").should == r3
|
47
|
+
|
48
|
+
end
|
49
|
+
it "should keep an index of responses" do
|
50
|
+
helper.response_idx.should == "1"
|
51
|
+
helper.response_idx.should == "2"
|
52
|
+
helper.response_idx(false).should == "2"
|
53
|
+
helper.response_idx.should == "3"
|
54
|
+
end
|
55
|
+
it "should translate response class into attribute" do
|
56
|
+
helper.rc_to_attr(:string).should == :string_value
|
57
|
+
helper.rc_to_attr(:text).should == :text_value
|
58
|
+
helper.rc_to_attr(:integer).should == :integer_value
|
59
|
+
helper.rc_to_attr(:float).should == :float_value
|
60
|
+
helper.rc_to_attr(:datetime).should == :datetime_value
|
61
|
+
helper.rc_to_attr(:date).should == :date_value
|
62
|
+
helper.rc_to_attr(:time).should == :time_value
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should translate response class into as" do
|
66
|
+
helper.rc_to_as(:string).should == :string
|
67
|
+
helper.rc_to_as(:text).should == :text
|
68
|
+
helper.rc_to_as(:integer).should == :string
|
69
|
+
helper.rc_to_as(:float).should == :string
|
70
|
+
helper.rc_to_as(:datetime).should == :string
|
71
|
+
helper.rc_to_as(:date).should == :string
|
72
|
+
helper.rc_to_as(:time).should == :string
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "overriding methods" do
|
77
|
+
before do
|
78
|
+
module SurveyorHelper
|
79
|
+
include Surveyor::Helpers::SurveyorHelperMethods
|
80
|
+
alias :old_rc_to_as :rc_to_as
|
81
|
+
def rc_to_as(type_sym)
|
82
|
+
case type_sym.to_s
|
83
|
+
when /(integer|float)/ then :string
|
84
|
+
when /(datetime)/ then :datetime
|
85
|
+
else type_sym
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
it "should translate response class into as" do
|
91
|
+
helper.rc_to_as(:string).should == :string
|
92
|
+
helper.rc_to_as(:text).should == :text
|
93
|
+
helper.rc_to_as(:integer).should == :string
|
94
|
+
helper.rc_to_as(:float).should == :string
|
95
|
+
helper.rc_to_as(:datetime).should == :datetime # not string
|
96
|
+
helper.rc_to_as(:date).should == :date # not string
|
97
|
+
helper.rc_to_as(:time).should == :time
|
98
|
+
end
|
99
|
+
after do
|
100
|
+
module SurveyorHelper
|
101
|
+
include Surveyor::Helpers::SurveyorHelperMethods
|
102
|
+
def rc_to_as(type_sym)
|
103
|
+
old_rc_to_as(type_sym)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# run this context after 'overriding methods'
|
110
|
+
context "post override test" do
|
111
|
+
# Sanity check
|
112
|
+
it "should translate response class into as after override" do
|
113
|
+
helper.rc_to_as(:datetime).should == :string # back to string
|
114
|
+
helper.rc_to_as(:date).should == :string # back to string
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Surveyor do
|
4
|
+
it "should write thousands of response sets" do
|
5
|
+
Surveyor::Parser.parse(File.read(File.join(Rails.root, 'surveys', 'kitchen_sink_survey.rb')))
|
6
|
+
survey = Survey.last
|
7
|
+
rs = ResponseSet.create(:survey => survey)
|
8
|
+
survey.sections.each{|s| s.questions.each{|q| rs.responses.create(:question => q, :answer => q.answers.first)}}
|
9
|
+
Benchmark.bm 20 do |x|
|
10
|
+
x.report "a test" do
|
11
|
+
full_path = File.join(Rails.root,"#{survey.access_code}_#{Time.now.to_i}.csv")
|
12
|
+
File.open(full_path, 'w') do |f|
|
13
|
+
100.times do # adjust this to test
|
14
|
+
survey.response_sets.each_with_index{|r,i| f.write(r.to_csv(true, i == 0)) } # print access code every time, print_header first time
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
survey "青少年人际关系问卷", :access_code => "青少年人际关系问卷" do
|
2
|
+
section "Basic questions" do
|
3
|
+
grid "第二部分:以下列出了一些描述。请您根据自己的实际情况作答。如果“非常不像我”,请选“1”,如果“非常像我”,请选“5”,以此类推。" do
|
4
|
+
a "1"
|
5
|
+
a "2"
|
6
|
+
a "3"
|
7
|
+
a "4"
|
8
|
+
a "5"
|
9
|
+
q "我常常想出新的有趣的点子", :pick => :one
|
10
|
+
q "我比同龄的其他孩子更有想象力", :pick => :one
|
11
|
+
q "即使一个人独处,我也不会觉得无聊", :pick => :one
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Surveyor::Common, "" do
|
4
|
+
it "should convert text to a code that is more appropirate for a database entry" do
|
5
|
+
# A few answers from the survey
|
6
|
+
{ "This? is a in - t3rrible-@nswer of! (question) on" => "this_t3rrible_nswer",
|
7
|
+
"Private insurance/ HMO/ PPO" => "private_insurance_hmo_ppo",
|
8
|
+
"<bold>VA</bold>" => "va",
|
9
|
+
"PMS (Premenstrual syndrome)/ PMDD (Premenstrual Dysphoric Disorder)" => "pms_pmdd",
|
10
|
+
"Have never been employed outside the home" => "never_been_employed_outside_home",
|
11
|
+
"Professional" => "professional",
|
12
|
+
"Not working because of temporary disability, but expect to return to a job" => "temporary_disability_expect_return_job",
|
13
|
+
"How long has it been since you last visited a doctor for a routine checkup (routine being not for a particular reason)?" => "visited_doctor_for_routine_checkup",
|
14
|
+
"Do you take medications as directed?" => "you_take_medications_as_directed",
|
15
|
+
"Do you every leak urine (or) water when you didn't want to?" => "urine_water_you_didnt_want", #checking for () and ' removal
|
16
|
+
"Do your biological family members (not adopted) have a \"history\" of any of the following?" => "family_members_history_any_following",
|
17
|
+
"Your health:" => "your_health",
|
18
|
+
"In general, you would say your health is:" => "you_would_say_your_health"
|
19
|
+
}.each{|k, v| Surveyor::Common.to_normalized_string(k).should == v}
|
20
|
+
end
|
21
|
+
describe '#generate_api_id' do
|
22
|
+
def generate
|
23
|
+
Surveyor::Common.generate_api_id
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'generates a String' do
|
27
|
+
generate.should be_a String
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'generates a new value every time' do
|
31
|
+
(1..100).collect { generate }.uniq.size.should == 100
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe Surveyor::Parser do
|
5
|
+
let(:parser){ Surveyor::Parser.new }
|
6
|
+
it "should translate shortcuts into full model names" do
|
7
|
+
parser.send(:full, "section").should == "survey_section"
|
8
|
+
parser.send(:full, "g").should == "question_group"
|
9
|
+
parser.send(:full, "repeater").should == "question_group"
|
10
|
+
parser.send(:full, "label").should == "question"
|
11
|
+
parser.send(:full, "vc").should == "validation_condition"
|
12
|
+
parser.send(:full, "vcondition").should == "validation_condition"
|
13
|
+
end
|
14
|
+
it "should translate 'condition' based on context" do
|
15
|
+
parser.send(:full, "condition").should == "dependency_condition"
|
16
|
+
parser.send(:full, "c").should == "dependency_condition"
|
17
|
+
parser.context[:validation] = Validation.new
|
18
|
+
parser.send(:full, "condition").should == "validation_condition"
|
19
|
+
parser.send(:full, "c").should == "validation_condition"
|
20
|
+
parser.context[:validation] = nil
|
21
|
+
parser.send(:full, "condition").should == "dependency_condition"
|
22
|
+
parser.send(:full, "c").should == "dependency_condition"
|
23
|
+
end
|
24
|
+
it "should not translate bad shortcuts" do
|
25
|
+
parser.send(:full, "quack").should == "quack"
|
26
|
+
parser.send(:full, "grizzly").should == "grizzly"
|
27
|
+
end
|
28
|
+
it "should identify models that take blocks" do
|
29
|
+
parser.send(:block_models).should == %w(survey survey_section question_group)
|
30
|
+
end
|
31
|
+
it "should return a survey object" do
|
32
|
+
Surveyor::Parser.new.parse("survey 'hi' do\n end").is_a?(Survey).should be_true
|
33
|
+
end
|
34
|
+
describe 'reference checking' do
|
35
|
+
it 'accepts Answer#reference_identifier via underscore or hash syntax' do
|
36
|
+
survey_text = <<END
|
37
|
+
survey "Numbers" do
|
38
|
+
section_one "One" do
|
39
|
+
q_1 "Select a number", :pick => :one
|
40
|
+
a "One", {:reference_identifier => "1"}
|
41
|
+
a_2 "Two"
|
42
|
+
a_3 "Three"
|
43
|
+
|
44
|
+
label_2 "One is the loneliest number..."
|
45
|
+
dependency :rule => "A"
|
46
|
+
condition_A :q_1, "==", {:answer_reference => "1"}
|
47
|
+
|
48
|
+
label_3 "Two can be as bad as one..."
|
49
|
+
dependency :rule => "A"
|
50
|
+
condition_A :q_1, "==", {:answer_reference => "2"}
|
51
|
+
|
52
|
+
label_4 "that you'll ever do"
|
53
|
+
dependency :rule => "A"
|
54
|
+
condition_A :q_1, "==", :a_1
|
55
|
+
|
56
|
+
label_5 "it's the loneliest number since the number one"
|
57
|
+
dependency :rule => "A"
|
58
|
+
condition_A :q_1, "==", :a_2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
END
|
62
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
63
|
+
survey.is_a?(Survey).should == true
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'translations' do
|
69
|
+
|
70
|
+
it 'should produce the survey text for :default locale' do
|
71
|
+
survey_text = <<END
|
72
|
+
survey "One language is never enough" do
|
73
|
+
translations :en => :default, :es =>{'questions' => {'name' =>{ 'text' => '¡Hola!'}}}
|
74
|
+
section_one "One" do
|
75
|
+
label_name "Hello!"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
END
|
79
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
80
|
+
survey.is_a?(Survey).should == true
|
81
|
+
survey.translations.size.should == 2
|
82
|
+
question = survey.sections.first.questions.first
|
83
|
+
question.translation(:en)[:text].should == "Hello!"
|
84
|
+
question.translation(:es)[:text].should == "¡Hola!"
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
it 'should raise an error w/o :default locale' do
|
89
|
+
survey_text = <<END
|
90
|
+
survey "One language is never enough" do
|
91
|
+
translations :es =>{'questions' => {'name' =>{ 'text' => '¡Hola!'}}}
|
92
|
+
section_one "One" do
|
93
|
+
label_name "Hello!"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
END
|
97
|
+
s = Survey.all.size
|
98
|
+
expect {survey = Surveyor::Parser.new.parse(survey_text)}.to raise_error
|
99
|
+
Survey.all.size.should == s
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
it 'should allow multiple default locales' do
|
104
|
+
survey_text = <<END
|
105
|
+
survey "Just don't talk about tyres" do
|
106
|
+
translations :'en-US' => :default, :'en-GB' => :default, :es =>{'questions' => {'name' =>{'text' => '¡Hola!'}}}
|
107
|
+
section_one "One" do
|
108
|
+
label_name "Hello!"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
END
|
112
|
+
|
113
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
114
|
+
survey.is_a?(Survey).should == true
|
115
|
+
survey.translations.size.should == 3
|
116
|
+
question = survey.sections.first.questions.first
|
117
|
+
question.translation(:'en-US')[:text].should == "Hello!"
|
118
|
+
question.translation(:'en-GB')[:text].should == "Hello!"
|
119
|
+
question.translation(:es)[:text].should == "¡Hola!"
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when a translation is specified as a Hash' do
|
123
|
+
it 'should should treat the hash as an inline translation' do
|
124
|
+
survey_text = <<END
|
125
|
+
survey "One language is never enough" do
|
126
|
+
translations :en => :default, :es => {"title"=>"Un idioma nunca es suficiente", "survey_sections"=>{"one"=>{"title"=>"Uno"}}, "question_groups"=>{"hello"=>{"text"=>"¡Hola!"}}, "questions"=>{"name"=>{"text"=>"¿Cómo se llama Usted?", "answers"=>{"name"=>{"help_text"=>"Mi nombre es..."}}}}}
|
127
|
+
section_one "One" do
|
128
|
+
g_hello "Hello" do
|
129
|
+
q_name "What is your name?"
|
130
|
+
a_name :string, :help_text => "My name is..."
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
END
|
135
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
136
|
+
survey.is_a?(Survey).should == true
|
137
|
+
survey.translations.size.should == 2
|
138
|
+
survey.translation(:es)['title'].should == "Un idioma nunca es suficiente"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when a translation is specified as a String' do
|
143
|
+
|
144
|
+
context 'when the survey filename is not given' do
|
145
|
+
it 'should look for the translation file relative to pwd' do
|
146
|
+
Dir.mktmpdir do |dir|
|
147
|
+
FileUtils.cd(dir) do
|
148
|
+
translation_yaml = YAML::dump({'title' => 'Un idioma nunca es suficiente'})
|
149
|
+
translation_temp_file = Tempfile.new('parser_spec_translation.yml',dir)
|
150
|
+
translation_temp_file.write(translation_yaml)
|
151
|
+
translation_temp_file.flush
|
152
|
+
survey_text = <<END
|
153
|
+
survey "One language is never enough" do
|
154
|
+
translations :es =>'#{File.basename(translation_temp_file.path)}', :en => :default
|
155
|
+
section_one "One" do
|
156
|
+
g_hello "Hello" do
|
157
|
+
q_name "What is your name?"
|
158
|
+
a_name :string, :help_text => "My name is..."
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
END
|
163
|
+
survey_temp_file = Tempfile.new('parser_spec_survey.rb',dir)
|
164
|
+
survey_temp_file.write(survey_text)
|
165
|
+
survey_temp_file.flush
|
166
|
+
Surveyor::Parser.parse(File.read(survey_temp_file.path))
|
167
|
+
survey = Survey.where(:title=>'One language is never enough').first
|
168
|
+
survey.nil?.should == false
|
169
|
+
survey.translation(:es)['title'].should == "Un idioma nunca es suficiente"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
context 'when the survey filename is given' do
|
175
|
+
it 'should look for the translation file relative to the survey directory' do
|
176
|
+
Dir.mktmpdir do |dir|
|
177
|
+
translation_yaml = YAML::dump({'title' => 'Un idioma nunca es suficiente'})
|
178
|
+
translation_temp_file = Tempfile.new('surveyor:parser_spec.rb',dir)
|
179
|
+
translation_temp_file.write(translation_yaml)
|
180
|
+
translation_temp_file.flush
|
181
|
+
survey_text = <<END
|
182
|
+
survey "One language is never enough" do
|
183
|
+
translations :es =>'#{File.basename(translation_temp_file.path)}', :en => :default
|
184
|
+
section_one "One" do
|
185
|
+
g_hello "Hello" do
|
186
|
+
q_name "What is your name?"
|
187
|
+
a_name :string, :help_text => "My name is..."
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
END
|
192
|
+
survey_temp_file = Tempfile.new('surveyor:parser_spec.rb',dir)
|
193
|
+
survey_temp_file.write(survey_text)
|
194
|
+
survey_temp_file.flush
|
195
|
+
Surveyor::Parser.parse_file(survey_temp_file.path)
|
196
|
+
survey = Survey.where(:title=>'One language is never enough').first
|
197
|
+
survey.nil?.should == false
|
198
|
+
survey.translation(:es)['title'].should == "Un idioma nunca es suficiente"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|