upgrade_surveyor_gui 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +44 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +46 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/MIT-LICENSE +20 -0
- data/README.md +244 -0
- data/Rakefile +66 -0
- data/app/controllers/surveyor_controller.rb +89 -0
- data/app/controllers/surveyor_gui/answers_controller.rb +3 -0
- data/app/controllers/surveyor_gui/application_controller.rb +3 -0
- data/app/controllers/surveyor_gui/dependencys_controller.rb +286 -0
- data/app/controllers/surveyor_gui/question_groups_controller.rb +90 -0
- data/app/controllers/surveyor_gui/questions_controller.rb +187 -0
- data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
- data/app/controllers/surveyor_gui/responses_controller.rb +41 -0
- data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
- data/app/controllers/surveyor_gui/survey_sections_controller.rb +80 -0
- data/app/controllers/surveyor_gui/surveyforms_controller.rb +4 -0
- data/app/facades/report_formatter.rb +46 -0
- data/app/facades/report_preview_wrapper.rb +11 -0
- data/app/facades/report_response_generator.rb +147 -0
- data/app/helpers/surveyor_gui/application_helper.rb +2 -0
- data/app/helpers/surveyor_gui/dependencys_helper.rb +5 -0
- data/app/helpers/surveyor_gui/question_groups_helper.rb +3 -0
- data/app/helpers/surveyor_gui/questions_helper.rb +22 -0
- data/app/helpers/surveyor_gui/reports_helper.rb +19 -0
- data/app/helpers/surveyor_gui/surveyforms_helper.rb +164 -0
- data/app/helpers/surveyor_helper.rb +4 -0
- data/app/inputs/currency_input.rb +5 -0
- data/app/inputs/date_picker_input.rb +7 -0
- data/app/inputs/datetime_picker_input.rb +5 -0
- data/app/inputs/percent_input.rb +5 -0
- data/app/inputs/time_picker_input.rb +5 -0
- data/app/mailers/.gitkeep +0 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/answer.rb +4 -0
- data/app/models/column.rb +3 -0
- data/app/models/dependency.rb +4 -0
- data/app/models/dependency_condition.rb +4 -0
- data/app/models/permitted_params_decorator.rb +80 -0
- data/app/models/question.rb +4 -0
- data/app/models/question_group.rb +4 -0
- data/app/models/question_group_tracker.rb +19 -0
- data/app/models/question_type.rb +7 -0
- data/app/models/response.rb +4 -0
- data/app/models/response_set.rb +4 -0
- data/app/models/row.rb +3 -0
- data/app/models/survey.rb +4 -0
- data/app/models/survey_section.rb +4 -0
- data/app/models/surveyform.rb +103 -0
- data/app/uploaders/blob_uploader.rb +48 -0
- data/app/views/layouts/surveyor_gui/application.html.erb +14 -0
- data/app/views/layouts/surveyor_gui/surveyor_gui_blank.html.erb +13 -0
- data/app/views/layouts/surveyor_gui/surveyor_gui_default.html.erb +17 -0
- data/app/views/layouts/surveyor_gui/surveyor_modified.html.erb +14 -0
- data/app/views/partials/_answer.html.haml +33 -0
- data/app/views/partials/_question.html.haml +33 -0
- data/app/views/partials/_question_group.html.haml +73 -0
- data/app/views/partials/_section.html.haml +13 -0
- data/app/views/surveyor/edit.html.haml +21 -0
- data/app/views/surveyor_gui/dependencys/_column.html.erb +1 -0
- data/app/views/surveyor_gui/dependencys/_dependency.html.erb +22 -0
- data/app/views/surveyor_gui/dependencys/_dependency_condition_fields.html.erb +48 -0
- data/app/views/surveyor_gui/dependencys/_form.html.erb +20 -0
- data/app/views/surveyor_gui/dependencys/blank.html.erb +0 -0
- data/app/views/surveyor_gui/dependencys/edit.html.erb +1 -0
- data/app/views/surveyor_gui/dependencys/new.html.erb +1 -0
- data/app/views/surveyor_gui/partials/_url_helpers.html.erb +5 -0
- data/app/views/surveyor_gui/question_groups/_form.html.erb +57 -0
- data/app/views/surveyor_gui/question_groups/_group_inline_field.html.erb +21 -0
- data/app/views/surveyor_gui/question_groups/_group_inline_fields.html.erb +25 -0
- data/app/views/surveyor_gui/question_groups/blank.html.erb +0 -0
- data/app/views/surveyor_gui/question_groups/edit.html.erb +1 -0
- data/app/views/surveyor_gui/question_groups/new.html.erb +1 -0
- data/app/views/surveyor_gui/questions/_answer_fields.html.erb +23 -0
- data/app/views/surveyor_gui/questions/_answer_options.html.erb +28 -0
- data/app/views/surveyor_gui/questions/_form.html.erb +66 -0
- data/app/views/surveyor_gui/questions/_grid_dropdown_columns.html.erb +10 -0
- data/app/views/surveyor_gui/questions/_grid_dropdown_fields.html.erb +42 -0
- data/app/views/surveyor_gui/questions/_grid_fields.html.erb +9 -0
- data/app/views/surveyor_gui/questions/_no_picks.html.erb +29 -0
- data/app/views/surveyor_gui/questions/_pick.html +21 -0
- data/app/views/surveyor_gui/questions/_picks.html.erb +12 -0
- data/app/views/surveyor_gui/questions/blank.html.erb +0 -0
- data/app/views/surveyor_gui/questions/edit.html.erb +1 -0
- data/app/views/surveyor_gui/questions/new.html.erb +1 -0
- data/app/views/surveyor_gui/reports/_graphs.html.haml +21 -0
- data/app/views/surveyor_gui/reports/_grid.html.haml +42 -0
- data/app/views/surveyor_gui/reports/_grid_dropdown.html.haml +56 -0
- data/app/views/surveyor_gui/reports/_repeater.html.haml +27 -0
- data/app/views/surveyor_gui/reports/_show_report.html.haml +33 -0
- data/app/views/surveyor_gui/reports/_single_question.html.haml +70 -0
- data/app/views/surveyor_gui/reports/show.html.erb +14 -0
- data/app/views/surveyor_gui/responses/_grid.html.haml +20 -0
- data/app/views/surveyor_gui/responses/_grid_dropdown.html.haml +20 -0
- data/app/views/surveyor_gui/responses/_repeater.html.haml +22 -0
- data/app/views/surveyor_gui/responses/_survey_results.html.haml +40 -0
- data/app/views/surveyor_gui/responses/index.html.haml +24 -0
- data/app/views/surveyor_gui/responses/show.html.haml +42 -0
- data/app/views/surveyor_gui/shared/_grid_comments.html.haml +10 -0
- data/app/views/surveyor_gui/shared/_new_line.html.haml +2 -0
- data/app/views/surveyor_gui/shared/_pick_comments.html.haml +15 -0
- data/app/views/surveyor_gui/shared/_question_number.html.haml +11 -0
- data/app/views/surveyor_gui/shared/_report_data.html.haml +27 -0
- data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
- data/app/views/surveyor_gui/survey_sections/_form.html.erb +13 -0
- data/app/views/surveyor_gui/survey_sections/blank.html.erb +0 -0
- data/app/views/surveyor_gui/survey_sections/edit.html.erb +1 -0
- data/app/views/surveyor_gui/survey_sections/new.html.erb +1 -0
- data/app/views/surveyor_gui/surveyforms/_form.html.erb +50 -0
- data/app/views/surveyor_gui/surveyforms/_question_field.html.erb +148 -0
- data/app/views/surveyor_gui/surveyforms/_question_group.html.erb +116 -0
- data/app/views/surveyor_gui/surveyforms/_question_group_fields.html.erb +3 -0
- data/app/views/surveyor_gui/surveyforms/_question_name_and_number.html.erb +6 -0
- data/app/views/surveyor_gui/surveyforms/_question_section.html.erb +15 -0
- data/app/views/surveyor_gui/surveyforms/_question_wrapper.html.erb +108 -0
- data/app/views/surveyor_gui/surveyforms/_survey_section_fields.html.erb +137 -0
- data/app/views/surveyor_gui/surveyforms/clone_survey.html.erb +13 -0
- data/app/views/surveyor_gui/surveyforms/edit.html.erb +5 -0
- data/app/views/surveyor_gui/surveyforms/index.html.erb +40 -0
- data/app/views/surveyor_gui/surveyforms/new.html.erb +1 -0
- data/app/views/surveyor_gui/surveyforms/show.html.erb +5 -0
- data/config/environment.rb +0 -0
- data/config/routes.rb +71 -0
- data/config.ru +4 -0
- data/db/migrate/20140307204049_add_template_to_surveys.rb +5 -0
- data/db/migrate/20140307235607_add_test_data_to_response_sets.rb +5 -0
- data/db/migrate/20140308171947_add_original_choice_to_answers.rb +5 -0
- data/db/migrate/20140308172118_add_blob_to_responses.rb +5 -0
- data/db/migrate/20140308172417_add_modifiable_to_survey_section.rb +5 -0
- data/db/migrate/20140308174532_add_modifiable_to_question.rb +5 -0
- data/db/migrate/20140308175305_add_dynamically_generate_to_questions.rb +5 -0
- data/db/migrate/20140311032923_add_dummy_blob_to_questions.rb +5 -0
- data/db/migrate/20140311160609_add_dynamic_source_to_questions.rb +5 -0
- data/db/migrate/20140311161714_add_report_code_to_questions.rb +5 -0
- data/db/migrate/20140530181134_add_is_comment_to_questions.rb +5 -0
- data/db/migrate/20140531012006_add_is_comment_to_answers.rb +5 -0
- data/db/migrate/20140531225529_create_rows.rb +9 -0
- data/db/migrate/20140601011151_create_columns.rb +11 -0
- data/db/migrate/20140602030330_add_column_id_to_answers.rb +5 -0
- data/db/migrate/20140603155606_add_column_id_to_responses.rb +5 -0
- data/db/migrate/20140606023527_add_column_id_to_dependency_conditions.rb +5 -0
- data/db/migrate/20140815165307_add_user_id_to_survey.rb +5 -0
- data/lib/assets/.gitkeep +0 -0
- data/lib/assets/images/addicon.png +0 -0
- data/lib/assets/images/datepicker.gif +0 -0
- data/lib/assets/images/delete.gif +0 -0
- data/lib/assets/images/delete.png +0 -0
- data/lib/assets/images/images/border.png +0 -0
- data/lib/assets/images/images/controls.png +0 -0
- data/lib/assets/images/images/loading.gif +0 -0
- data/lib/assets/images/images/loading_background.png +0 -0
- data/lib/assets/images/images/overlay.png +0 -0
- data/lib/assets/images/rails.png +0 -0
- data/lib/assets/images/star.gif +0 -0
- data/lib/assets/javascripts/.gitkeep +0 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.MetaData.js +121 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.blockUI.js +619 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.rating.js +377 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.validate.js +1188 -0
- data/lib/assets/javascripts/surveyor_gui/surveyor_add_ons.js +10 -0
- data/lib/assets/javascripts/surveyor_gui/surveyor_gui.js +1428 -0
- data/lib/assets/stylesheets/.gitkeep +0 -0
- data/lib/assets/stylesheets/surveyor_gui/jquery.rating.css +12 -0
- data/lib/assets/stylesheets/surveyor_gui/surveyor_add_ons.css +3 -0
- data/lib/assets/stylesheets/surveyor_gui/surveyor_gui.sass +652 -0
- data/lib/enumerable_extenders.rb +31 -0
- data/lib/generators/surveyor_gui/install_generator.rb +57 -0
- data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_add_ons.js +2 -0
- data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_gui_all.js +24 -0
- data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_add_ons.css.sass +1 -0
- data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_gui_all.css.sass +8 -0
- data/lib/generators/surveyor_gui/templates/app/helpers/surveyor_helper.rb +4 -0
- data/lib/generators/surveyor_gui/templates/app/models/response_set_user.rb +13 -0
- data/lib/generators/surveyor_gui/templates/app/views/layouts/surveyor_gui/surveyor_gui_default.html.erb +17 -0
- data/lib/generators/surveyor_gui/templates/config/initializers/simple_form.rb +140 -0
- data/lib/generators/surveyor_gui/templates/config/locales/en.yml +5 -0
- data/lib/surveyor_gui/engine.rb +31 -0
- data/lib/surveyor_gui/helpers/surveyor_helper_methods.rb +19 -0
- data/lib/surveyor_gui/models/answer_methods.rb +24 -0
- data/lib/surveyor_gui/models/column_methods.rb +43 -0
- data/lib/surveyor_gui/models/dependency_condition_methods.rb +53 -0
- data/lib/surveyor_gui/models/dependency_methods.rb +83 -0
- data/lib/surveyor_gui/models/question_and_group_shared_methods.rb +11 -0
- data/lib/surveyor_gui/models/question_group_methods.rb +55 -0
- data/lib/surveyor_gui/models/question_methods.rb +435 -0
- data/lib/surveyor_gui/models/question_type_methods.rb +493 -0
- data/lib/surveyor_gui/models/response_methods.rb +71 -0
- data/lib/surveyor_gui/models/response_set_methods.rb +56 -0
- data/lib/surveyor_gui/models/row_methods.rb +11 -0
- data/lib/surveyor_gui/models/survey_methods.rb +32 -0
- data/lib/surveyor_gui/models/survey_section_methods.rb +32 -0
- data/lib/surveyor_gui/surveyforms_controller_methods.rb +258 -0
- data/lib/surveyor_gui/version.rb +3 -0
- data/lib/surveyor_gui.rb +17 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/surveyor_gui_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/controllers/surveyforms_controller_spec.rb +362 -0
- data/spec/controllers/surveyor_controller_spec.rb +303 -0
- data/spec/factories.rb +181 -0
- data/spec/features/create_survey_spec.rb +417 -0
- data/spec/features/dependencies_spec.rb +65 -0
- data/spec/features/make_and_take_spec.rb +187 -0
- data/spec/features/rearrange_survey_spec.rb +118 -0
- data/spec/features/ui_spec.rb +469 -0
- data/spec/fixtures/REDCapDemoDatabase_DataDictionary.csv +127 -0
- data/spec/fixtures/chinese_survey.rb +14 -0
- data/spec/fixtures/everything.rb +215 -0
- data/spec/fixtures/favorites-ish.rb +22 -0
- data/spec/fixtures/favorites.rb +22 -0
- data/spec/fixtures/feelings.rb +38 -0
- data/spec/fixtures/lifestyle.rb +55 -0
- data/spec/fixtures/numbers.rb +21 -0
- data/spec/fixtures/redcap_new_headers.csv +1 -0
- data/spec/fixtures/redcap_siblings.csv +1 -0
- data/spec/fixtures/redcap_whitespace.csv +1 -0
- data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
- data/spec/helpers/surveyor_helper_spec.rb +116 -0
- data/spec/lib/common_spec.rb +37 -0
- data/spec/lib/parser_spec.rb +393 -0
- data/spec/lib/rake_kitchen_sink.rb +42 -0
- data/spec/lib/redcap_parser_spec.rb +129 -0
- data/spec/lib/unparser_spec.rb +126 -0
- data/spec/models/answer_spec.rb +144 -0
- data/spec/models/dependency_condition_spec.rb +428 -0
- data/spec/models/dependency_spec.rb +90 -0
- data/spec/models/question_group_spec.rb +66 -0
- data/spec/models/question_spec.rb +176 -0
- data/spec/models/response_set_spec.rb +452 -0
- data/spec/models/response_spec.rb +208 -0
- data/spec/models/survey_section_spec.rb +58 -0
- data/spec/models/survey_spec.rb +155 -0
- data/spec/models/surveyor_gui/question_spec.rb +60 -0
- data/spec/models/surveyor_gui/question_type_spec.rb +268 -0
- data/spec/models/validation_condition_spec.rb +98 -0
- data/spec/models/validation_spec.rb +64 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +119 -0
- data/spec/support/scenario_outline_helper.rb +39 -0
- data/spec/support/shared.rb +10 -0
- data/spec/support/surveyforms_creation_helpers.rb +313 -0
- data/spec/support/surveyforms_rearrangement_helpers.rb +170 -0
- data/spec/support/surveyor_api_helpers.rb +15 -0
- data/spec/support/surveyor_ui_helpers.rb +108 -0
- data/spec/support/wait_for_ajax.rb +11 -0
- data/spec/views/questions/edit.html.erb_spec.rb +74 -0
- data/spec/views/surveyforms/edit.html.erb_spec.rb +126 -0
- data/surveyor_gui.gemspec +52 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/surveyor-gui_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016 +0 -0
- data/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6 +0 -0
- data/vendor/assets/stylesheets/.gitkeep +0 -0
- data/vendor/assets/stylesheets/custom.sass +5 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +600 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
survey "Numbers" do
|
2
|
+
section "Addition" do
|
3
|
+
q_1 "What is one plus one?", pick: :one, correct: "2"
|
4
|
+
a_1 "1"
|
5
|
+
a_2 "2"
|
6
|
+
a_3 "3"
|
7
|
+
a_4 "4"
|
8
|
+
|
9
|
+
q_2 "What is five plus one?", pick: :one, correct: "6"
|
10
|
+
a_5 "five"
|
11
|
+
a_6 "six"
|
12
|
+
a_7 "seven"
|
13
|
+
a_8 "eight"
|
14
|
+
end
|
15
|
+
section "Literature" do
|
16
|
+
q_the_answer "What is the 'Answer to the Ultimate Question of Life, The Universe, and Everything'", pick: :one, correct: "adams"
|
17
|
+
a_pi "3.14"
|
18
|
+
a_zero "0"
|
19
|
+
a_adams "42"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Variable / Field Name,Form Name,Field Units,Section Header,Field Type,Field Label,Choices Calculations OR Slider Labels,Field Note,Text Validation Type OR Show Slider Number,Text Validation Min,Text Validation Max,Identifier?,Branching Logic (Show field only if...),Required Field?
|
@@ -0,0 +1 @@
|
|
1
|
+
Variable / Field Name,Form Name,Field Units,Section Header,Field Type,Field Label,Choices OR Calculations,Field Note,Text Validation Type,Text Validation Min,Text Validation Max,Identifier?,Branching Logic (Show field only if...),Required Field?
|
@@ -0,0 +1 @@
|
|
1
|
+
Variable / Field Name,Form Name,Field Units,Section Header,Field Type,Field Label,Choices OR Calculations,Field Note,Text Validation Type,Text Validation Min,Text Validation Max,Identifier?,Branching Logic (Show field only if...),Required Field?
|
@@ -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,116 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe SurveyorHelper do
|
4
|
+
context "numbering" do
|
5
|
+
it "should return the question text with number, except for labels, dependencies, images, and grouped questions" do
|
6
|
+
q1 = FactoryGirl.create(:question)
|
7
|
+
q2 = FactoryGirl.create(:question, :display_type => "label")
|
8
|
+
q3 = FactoryGirl.create(:question) do |question|
|
9
|
+
FactoryGirl.create(:dependency, :question=>question)
|
10
|
+
end
|
11
|
+
q4 = FactoryGirl.create(:question, :display_type => "image", :text => "something.jpg")
|
12
|
+
q5 = FactoryGirl.create(:question, :question_group => FactoryGirl.create(:question_group))
|
13
|
+
helper.q_text(q1).should == "<span class='qnum'>1) </span>#{q1.text}"
|
14
|
+
helper.q_text(q2).should == q2.text
|
15
|
+
helper.q_text(q3).should == q3.text
|
16
|
+
helper.q_text(q4).should =~ /<img alt="Something" src="\/(images|assets)\/something\.jpg" \/>/
|
17
|
+
helper.q_text(q5).should == q5.text
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with mustache text substitution" do
|
22
|
+
require 'mustache'
|
23
|
+
let(:mustache_context){ Class.new(::Mustache){ def site; "Northwestern"; end; def somethingElse; "something new"; end; def group; "NUBIC"; end } }
|
24
|
+
it "substitues values into Question#text" do
|
25
|
+
q1 = FactoryGirl.create(:question, :text => "You are in {{site}}")
|
26
|
+
label = FactoryGirl.create(:question, :display_type => "label", :text => "Testing {{somethingElse}}")
|
27
|
+
helper.q_text(q1, mustache_context).should == "<span class='qnum'>1) </span>You are in Northwestern"
|
28
|
+
helper.q_text(label, mustache_context).should == "Testing something new"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "response methods" do
|
33
|
+
it "should find or create responses, with index" do
|
34
|
+
q1 = FactoryGirl.create(:question, :answers => [a = FactoryGirl.create(:answer, :text => "different")])
|
35
|
+
q2 = FactoryGirl.create(:question, :answers => [b = FactoryGirl.create(:answer, :text => "strokes")])
|
36
|
+
q3 = FactoryGirl.create(:question, :answers => [c = FactoryGirl.create(:answer, :text => "folks")])
|
37
|
+
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)])
|
38
|
+
|
39
|
+
helper.response_for(rs, nil).should == nil
|
40
|
+
helper.response_for(nil, q1).should == nil
|
41
|
+
helper.response_for(rs, q1).should == r1
|
42
|
+
helper.response_for(rs, q1, a).should == r1
|
43
|
+
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"}
|
44
|
+
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"}
|
45
|
+
helper.response_for(rs, q3, c, "1").should == r3
|
46
|
+
|
47
|
+
end
|
48
|
+
it "should keep an index of responses" do
|
49
|
+
helper.response_idx.should == "1"
|
50
|
+
helper.response_idx.should == "2"
|
51
|
+
helper.response_idx(false).should == "2"
|
52
|
+
helper.response_idx.should == "3"
|
53
|
+
end
|
54
|
+
it "should translate response class into attribute" do
|
55
|
+
helper.rc_to_attr(:string).should == :string_value
|
56
|
+
helper.rc_to_attr(:text).should == :text_value
|
57
|
+
helper.rc_to_attr(:integer).should == :integer_value
|
58
|
+
helper.rc_to_attr(:float).should == :float_value
|
59
|
+
helper.rc_to_attr(:datetime).should == :datetime_value
|
60
|
+
helper.rc_to_attr(:date).should == :date_value
|
61
|
+
helper.rc_to_attr(:time).should == :time_value
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should translate response class into as" do
|
65
|
+
helper.rc_to_as(:string).should == :string
|
66
|
+
helper.rc_to_as(:text).should == :text
|
67
|
+
helper.rc_to_as(:integer).should == :string
|
68
|
+
helper.rc_to_as(:float).should == :string
|
69
|
+
helper.rc_to_as(:datetime).should == :string
|
70
|
+
helper.rc_to_as(:date).should == :string
|
71
|
+
helper.rc_to_as(:time).should == :string
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "overriding methods" do
|
76
|
+
before do
|
77
|
+
module SurveyorHelper
|
78
|
+
include Surveyor::Helpers::SurveyorHelperMethods
|
79
|
+
alias :old_rc_to_as :rc_to_as
|
80
|
+
def rc_to_as(type_sym)
|
81
|
+
case type_sym.to_s
|
82
|
+
when /(integer|float)/ then :string
|
83
|
+
when /(datetime)/ then :datetime
|
84
|
+
else type_sym
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
it "should translate response class into as" do
|
90
|
+
helper.rc_to_as(:string).should == :string
|
91
|
+
helper.rc_to_as(:text).should == :text
|
92
|
+
helper.rc_to_as(:integer).should == :string
|
93
|
+
helper.rc_to_as(:float).should == :string
|
94
|
+
helper.rc_to_as(:datetime).should == :datetime # not string
|
95
|
+
helper.rc_to_as(:date).should == :date # not string
|
96
|
+
helper.rc_to_as(:time).should == :time
|
97
|
+
end
|
98
|
+
after do
|
99
|
+
module SurveyorHelper
|
100
|
+
include Surveyor::Helpers::SurveyorHelperMethods
|
101
|
+
def rc_to_as(type_sym)
|
102
|
+
old_rc_to_as(type_sym)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# run this context after 'overriding methods'
|
109
|
+
context "post override test" do
|
110
|
+
# Sanity check
|
111
|
+
it "should translate response class into as after override" do
|
112
|
+
helper.rc_to_as(:datetime).should == :string # back to string
|
113
|
+
helper.rc_to_as(:date).should == :string # back to string
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
it "should have a list of operators" do
|
22
|
+
%w(== != < > <= >= =~).each{|operator| Surveyor::Common::OPERATORS.include?(operator).should be_true }
|
23
|
+
end
|
24
|
+
describe '#generate_api_id' do
|
25
|
+
def generate
|
26
|
+
Surveyor::Common.generate_api_id
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'generates a String' do
|
30
|
+
generate.should be_a String
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'generates a new value every time' do
|
34
|
+
(1..100).collect { generate }.uniq.size.should == 100
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,393 @@
|
|
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 return a survey object" do
|
7
|
+
Surveyor::Parser.new.parse("survey 'hi' do\n end").is_a?(Survey).should be_true
|
8
|
+
end
|
9
|
+
context "basic questions" do
|
10
|
+
include_context "favorites"
|
11
|
+
it "parses" do
|
12
|
+
expect(Survey.count).to eq(1)
|
13
|
+
expect(SurveySection.count).to eq(2)
|
14
|
+
expect(Question.count).to eq(4)
|
15
|
+
expect(Answer.count).to eq(9)
|
16
|
+
surveys = [{title: "Favorites", display_order: 0}]
|
17
|
+
sections = [{title: "Colors", reference_identifier: "colors", display_order: 0},
|
18
|
+
{title: "Numbers", reference_identifier: "numbers", display_order: 1}]
|
19
|
+
questions = [{reference_identifier: nil, text: "These questions are examples of the basic supported input types", pick: "none", display_type: "label", display_order: 0},
|
20
|
+
{reference_identifier: "1", text: "What is your favorite color?", pick: "one", display_type: "default", display_order: 1},
|
21
|
+
{reference_identifier: "2b", text: "Choose the colors you don't like", pick: "any", display_type: "default", display_order: 2},
|
22
|
+
{reference_identifier: "fire_engine", text: "What is the best color for a fire engine?",display_type: "default", display_order: 3}]
|
23
|
+
answers_1 = [{reference_identifier: "r", data_export_identifier: "1", text: "red", response_class: "answer", display_order: 0},
|
24
|
+
{reference_identifier: "b", data_export_identifier: "2", text: "blue", response_class: "answer", display_order: 1},
|
25
|
+
{reference_identifier: "g", data_export_identifier: "3", text: "green", response_class: "answer", display_order: 2},
|
26
|
+
{reference_identifier: nil, text: "Other", response_class: "answer", display_order: 3}]
|
27
|
+
answers_2 = [{reference_identifier: "1", text: "orange", response_class: "answer", display_order: 1},
|
28
|
+
{reference_identifier: "2", text: "purple", response_class: "answer", display_order: 2},
|
29
|
+
{reference_identifier: "3", text: "brown", response_class: "answer", display_order: 0},
|
30
|
+
{reference_identifier: nil, text: "Omit", response_class: "answer", display_order: 3}]
|
31
|
+
surveys.each{|attrs| attrs.each{|k,v| expect(Survey.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
32
|
+
sections.each{|attrs| attrs.each{|k,v| expect(SurveySection.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
33
|
+
questions.each{|attrs| attrs.each{|k,v| expect(Question.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
34
|
+
answers_1.each{|attrs| attrs.each{|k,v| expect(Question.where(display_order: 1).first.answers.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
35
|
+
answers_2.each{|attrs| attrs.each{|k,v| expect(Question.where(display_order: 2).first.answers.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "complex questions" do
|
39
|
+
include_context "feelings"
|
40
|
+
it "parses" do
|
41
|
+
expect(Survey.count).to eq(1)
|
42
|
+
expect(QuestionGroup.count).to eq(3)
|
43
|
+
expect(Question.count).to eq(10)
|
44
|
+
expect(Answer.count).to eq(34)
|
45
|
+
surveys = [{title: "Feelings", display_order: 0}]
|
46
|
+
question_groups = [{text: "Tell us how you feel today", display_type: "grid", reference_identifier: "today"},
|
47
|
+
{text: "How interested are you in the following?", display_type: "grid", reference_identifier: "events"},
|
48
|
+
{text: "Tell us about your family", display_type: "repeater", reference_identifier: "family"}]
|
49
|
+
dropdown_question_attributes = {text: "Relation", pick: "one"}
|
50
|
+
grid_questions = QuestionGroup.where(reference_identifier: "today").first.questions
|
51
|
+
grid_answers_1 = [{text: "-2", display_order: 0},
|
52
|
+
{text: "-1", display_order: 1},
|
53
|
+
{text: "0", display_order: 2},
|
54
|
+
{text: "1", display_order: 3},
|
55
|
+
{text: "2", display_order: 4}]
|
56
|
+
surveys.each{|attrs| attrs.each{|k,v| expect(Survey.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
57
|
+
question_groups.each{|attrs| attrs.each{|k,v| expect(QuestionGroup.where(reference_identifier: attrs[:reference_identifier]).first[k]).to eq(v)} }
|
58
|
+
grid_questions.each{|question| grid_answers_1.each{|attrs| attrs.each{|k,v| expect(question.answers.where(display_order: attrs[:display_order]).first[k]).to eq(v)} } }
|
59
|
+
dropdown_question_attributes.each{|k,v| expect(Question.where(display_type: "dropdown").first[k]).to eq(v)}
|
60
|
+
end
|
61
|
+
it "clears grid answers" do
|
62
|
+
grid_answers_1 = [{text: "-2", display_order: 0},
|
63
|
+
{text: "-1", display_order: 1},
|
64
|
+
{text: "0", display_order: 2},
|
65
|
+
{text: "1", display_order: 3},
|
66
|
+
{text: "2", display_order: 4}]
|
67
|
+
grid_answers_2 = [{text: "indifferent", display_order: 0},
|
68
|
+
{text: "neutral", display_order: 1},
|
69
|
+
{text: "interested", display_order: 2}]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
context "depdencies and validations" do
|
73
|
+
include_context "lifestyle"
|
74
|
+
it "parses" do
|
75
|
+
expect(Survey.count).to eq(1)
|
76
|
+
expect(SurveySection.count).to eq(2)
|
77
|
+
expect(QuestionGroup.count).to eq(1)
|
78
|
+
expect(Question.count).to eq(10)
|
79
|
+
expect(Answer.count).to eq(12)
|
80
|
+
expect(Dependency.count).to eq(6)
|
81
|
+
expect(DependencyCondition.count).to eq(6)
|
82
|
+
expect(Validation.count).to eq(2)
|
83
|
+
expect(ValidationCondition.count).to eq(2)
|
84
|
+
depdendencies = [{rule: "B", question_reference_identifier: "copd_sh_1b"},
|
85
|
+
{rule: "C", question_reference_identifier: "copd_sh_1ba"},
|
86
|
+
{rule: "D", question_reference_identifier: "copd_sh_1bb"},
|
87
|
+
{rule: "Q", question_group_reference_identifier: "one_pet"},
|
88
|
+
{rule: "R", question_reference_identifier: "very_creative"},
|
89
|
+
{rule: "S", question_reference_identifier: "oh_my"}]
|
90
|
+
depdendencies.each{|attrs| (expect(Dependency.where(rule: attrs[:rule]).first.question.reference_identifier).to eq(attrs[:question_reference_identifier])) if attrs[:question_reference_identifier] }
|
91
|
+
depdendencies.each{|attrs| (expect(Dependency.where(rule: attrs[:rule]).first.question_group.reference_identifier).to eq(attrs[:question_group_reference_identifier])) if attrs[:question_group_reference_identifier] }
|
92
|
+
dependency_conditions = [{rule_key: "B", question_reference_identifier: "copd_sh_1", answer_reference_identifier: "1"},
|
93
|
+
{rule_key: "C", question_reference_identifier: "copd_sh_1b", answer_reference_identifier: "quit"},
|
94
|
+
{rule_key: "D", question_reference_identifier: "copd_sh_1b", answer_reference_identifier: "current_as_of_one_month"},
|
95
|
+
{rule_key: "Q", question_reference_identifier: "pets", answer_reference_identifier: "number"},
|
96
|
+
{rule_key: "R", question_reference_identifier: "favorite_pet", answer_reference_identifier: "name"},
|
97
|
+
{rule_key: "S", question_reference_identifier: "dream_pet"}]
|
98
|
+
dependency_conditions.each{|attrs| expect(DependencyCondition.where(rule_key: attrs[:rule_key]).first.question.reference_identifier).to eq(attrs[:question_reference_identifier]) }
|
99
|
+
dependency_conditions.each{|attrs| (expect(DependencyCondition.where(rule_key: attrs[:rule_key]).first.answer.reference_identifier).to eq(attrs[:answer_reference_identifier])) if attrs[:answer_reference_identifier] }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
context "translations" do
|
103
|
+
it 'should produce the survey text for :default locale' do
|
104
|
+
survey_text = %{
|
105
|
+
survey "One language is never enough" do
|
106
|
+
translations :en => :default, :es =>{'questions' => {'name' =>{ 'text' => '¡Hola!'}}}
|
107
|
+
section_one "One" do
|
108
|
+
label_name "Hello!"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
}
|
112
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
113
|
+
survey.is_a?(Survey).should == true
|
114
|
+
survey.translations.size.should == 2
|
115
|
+
question = survey.sections.first.questions.first
|
116
|
+
question.translation(:en)[:text].should == "Hello!"
|
117
|
+
question.translation(:es)[:text].should == "¡Hola!"
|
118
|
+
end
|
119
|
+
it 'should raise an error w/o :default locale' do
|
120
|
+
survey_text = %{
|
121
|
+
survey "One language is never enough" do
|
122
|
+
translations :es =>{'questions' => {'name' =>{ 'text' => '¡Hola!'}}}
|
123
|
+
section_one "One" do
|
124
|
+
label_name "Hello!"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
}
|
128
|
+
s = Survey.all.size
|
129
|
+
expect {survey = Surveyor::Parser.new.parse(survey_text)}.to raise_error
|
130
|
+
Survey.all.size.should == s
|
131
|
+
end
|
132
|
+
it 'should allow multiple default locales' do
|
133
|
+
survey_text = %{
|
134
|
+
survey "Just don't talk about tyres" do
|
135
|
+
translations :'en-US' => :default, :'en-GB' => :default, :es =>{'questions' => {'name' =>{'text' => '¡Hola!'}}}
|
136
|
+
section_one "One" do
|
137
|
+
label_name "Hello!"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
}
|
141
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
142
|
+
survey.is_a?(Survey).should == true
|
143
|
+
survey.translations.size.should == 3
|
144
|
+
question = survey.sections.first.questions.first
|
145
|
+
question.translation(:'en-US')[:text].should == "Hello!"
|
146
|
+
question.translation(:'en-GB')[:text].should == "Hello!"
|
147
|
+
question.translation(:es)[:text].should == "¡Hola!"
|
148
|
+
end
|
149
|
+
context 'when a translation is specified as a Hash' do
|
150
|
+
it 'should should treat the hash as an inline translation' do
|
151
|
+
survey_text = %{
|
152
|
+
survey "One language is never enough" do
|
153
|
+
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..."}}}}}
|
154
|
+
section_one "One" do
|
155
|
+
g_hello "Hello" do
|
156
|
+
q_name "What is your name?"
|
157
|
+
a_name :string, :help_text => "My name is..."
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
}
|
162
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
163
|
+
survey.is_a?(Survey).should == true
|
164
|
+
survey.translations.size.should == 2
|
165
|
+
survey.translation(:es)['title'].should == "Un idioma nunca es suficiente"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
context 'when a translation is specified as a String' do
|
169
|
+
context 'when the survey filename is not given' do
|
170
|
+
it 'should look for the translation file relative to pwd' do
|
171
|
+
Dir.mktmpdir do |dir|
|
172
|
+
FileUtils.cd(dir) do
|
173
|
+
translation_yaml = YAML::dump({'title' => 'Un idioma nunca es suficiente'})
|
174
|
+
translation_temp_file = Tempfile.new('parser_spec_translation.yml',dir)
|
175
|
+
translation_temp_file.write(translation_yaml)
|
176
|
+
translation_temp_file.flush
|
177
|
+
survey_text = %{
|
178
|
+
survey "One language is never enough" do
|
179
|
+
translations :es =>'#{File.basename(translation_temp_file.path)}', :en => :default
|
180
|
+
section_one "One" do
|
181
|
+
g_hello "Hello" do
|
182
|
+
q_name "What is your name?"
|
183
|
+
a_name :string, :help_text => "My name is..."
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
}
|
188
|
+
survey_temp_file = Tempfile.new('parser_spec_survey.rb',dir)
|
189
|
+
survey_temp_file.write(survey_text)
|
190
|
+
survey_temp_file.flush
|
191
|
+
Surveyor::Parser.parse(File.read(survey_temp_file.path))
|
192
|
+
survey = Survey.where(:title=>'One language is never enough').first
|
193
|
+
survey.nil?.should == false
|
194
|
+
survey.translation(:es)['title'].should == "Un idioma nunca es suficiente"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
context 'when the survey filename is given' do
|
200
|
+
it 'should look for the translation file relative to the survey directory' do
|
201
|
+
Dir.mktmpdir do |dir|
|
202
|
+
translation_yaml = YAML::dump({'title' => 'Un idioma nunca es suficiente'})
|
203
|
+
translation_temp_file = Tempfile.new('surveyor:parser_spec.rb',dir)
|
204
|
+
translation_temp_file.write(translation_yaml)
|
205
|
+
translation_temp_file.flush
|
206
|
+
survey_text = %{
|
207
|
+
survey "One language is never enough" do
|
208
|
+
translations :es =>'#{File.basename(translation_temp_file.path)}', :en => :default
|
209
|
+
section_one "One" do
|
210
|
+
g_hello "Hello" do
|
211
|
+
q_name "What is your name?"
|
212
|
+
a_name :string, :help_text => "My name is..."
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
}
|
217
|
+
survey_temp_file = Tempfile.new('surveyor:parser_spec.rb',dir)
|
218
|
+
survey_temp_file.write(survey_text)
|
219
|
+
survey_temp_file.flush
|
220
|
+
Surveyor::Parser.parse_file(survey_temp_file.path)
|
221
|
+
survey = Survey.where(:title=>'One language is never enough').first
|
222
|
+
survey.nil?.should == false
|
223
|
+
survey.translation(:es)['title'].should == "Un idioma nunca es suficiente"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
context "quizzes" do
|
230
|
+
include_context "numbers"
|
231
|
+
it "parses" do
|
232
|
+
expect(Survey.count).to eq(1)
|
233
|
+
expect(SurveySection.count).to eq(2)
|
234
|
+
expect(Question.count).to eq(3)
|
235
|
+
expect(Answer.count).to eq(11)
|
236
|
+
surveys = [{title: "Numbers", display_order: 0}]
|
237
|
+
sections = [{title: "Addition", reference_identifier: nil, display_order: 0},
|
238
|
+
{title: "Literature", reference_identifier: nil, display_order: 1}]
|
239
|
+
questions = [{reference_identifier: "1", text: "What is one plus one?", pick: "one", display_type: "default", display_order: 0},
|
240
|
+
{reference_identifier: "2", text: "What is five plus one?", pick: "one", display_type: "default", display_order: 1},
|
241
|
+
{reference_identifier: "the_answer", text: "What is the 'Answer to the Ultimate Question of Life, The Universe, and Everything'", pick: "one", display_type: "default", display_order: 0}]
|
242
|
+
answers_1 = [{reference_identifier: "1", text: "1", response_class: "answer", display_order: 0},
|
243
|
+
{reference_identifier: "2", text: "2", response_class: "answer", display_order: 1},
|
244
|
+
{reference_identifier: "3", text: "3", response_class: "answer", display_order: 2},
|
245
|
+
{reference_identifier: "4", text: "4", response_class: "answer", display_order: 3}]
|
246
|
+
answers_2 = [{reference_identifier: "5", text: "five", response_class: "answer", display_order: 0},
|
247
|
+
{reference_identifier: "6", text: "six", response_class: "answer", display_order: 1},
|
248
|
+
{reference_identifier: "7", text: "seven", response_class: "answer", display_order: 2},
|
249
|
+
{reference_identifier: "8", text: "eight", response_class: "answer", display_order: 3}]
|
250
|
+
correct_answers = [{question_reference_identifier: "1", correct_answer_text: "2"},
|
251
|
+
{question_reference_identifier: "2", correct_answer_text: "six"},
|
252
|
+
{question_reference_identifier: "the_answer", correct_answer_text: "42"}]
|
253
|
+
surveys.each{|attrs| attrs.each{|k,v| expect(Survey.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
254
|
+
sections.each{|attrs| attrs.each{|k,v| expect(SurveySection.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
255
|
+
questions.each{|attrs| attrs.each{|k,v| expect(Question.where(reference_identifier: attrs[:reference_identifier]).first[k]).to eq(v)} }
|
256
|
+
answers_1.each{|attrs| attrs.each{|k,v| expect(Question.where(reference_identifier: "1").first.answers.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
257
|
+
answers_2.each{|attrs| attrs.each{|k,v| expect(Question.where(reference_identifier: "2").first.answers.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
258
|
+
correct_answers.each{|attrs| expect(Question.where(reference_identifier: attrs[:question_reference_identifier]).first.correct_answer.text).to eq(attrs[:correct_answer_text]) }
|
259
|
+
end
|
260
|
+
end
|
261
|
+
context "mandatory" do
|
262
|
+
it "parses" do
|
263
|
+
survey_text = %{
|
264
|
+
survey "Chores", default_mandatory: true do
|
265
|
+
section "Morning" do
|
266
|
+
q "Did you take out the trash", pick: :one
|
267
|
+
a "Yes"
|
268
|
+
a "No"
|
269
|
+
|
270
|
+
q "Did you do the laundry", pick: :one
|
271
|
+
a "Yes"
|
272
|
+
a "No"
|
273
|
+
|
274
|
+
q "Optional comments", is_mandatory: false
|
275
|
+
a :string
|
276
|
+
end
|
277
|
+
end
|
278
|
+
}
|
279
|
+
survey = Surveyor::Parser.new.parse(survey_text)
|
280
|
+
expect(Survey.count).to eq(1)
|
281
|
+
expect(SurveySection.count).to eq(1)
|
282
|
+
expect(Question.count).to eq(3)
|
283
|
+
questions = [{display_order: 0, text: "Did you take out the trash", is_mandatory: true},
|
284
|
+
{display_order: 1, text: "Did you do the laundry", is_mandatory: true},
|
285
|
+
{display_order: 2, text: "Optional comments", is_mandatory: false}]
|
286
|
+
questions.each{|attrs| attrs.each{|k,v| expect(Question.where(display_order: attrs[:display_order]).first[k]).to eq(v)} }
|
287
|
+
end
|
288
|
+
end
|
289
|
+
context "failures" do
|
290
|
+
it "typos in blocks" do
|
291
|
+
survey_text = %q{
|
292
|
+
survey "Basics" do
|
293
|
+
sectionals "Typo" do
|
294
|
+
end
|
295
|
+
end
|
296
|
+
}
|
297
|
+
expect { Surveyor::Parser.parse(survey_text) }.to raise_error(Surveyor::ParserError, /\"sectionals\" is not a surveyor method./)
|
298
|
+
end
|
299
|
+
it "bad references" do
|
300
|
+
survey_text = %q{
|
301
|
+
survey "Refs" do
|
302
|
+
section "Bad" do
|
303
|
+
q_watch "Do you watch football?", :pick => :one
|
304
|
+
a_1 "Yes"
|
305
|
+
a_2 "No"
|
306
|
+
|
307
|
+
q "Do you like the replacement refs?", :pick => :one
|
308
|
+
dependency :rule => "A or B"
|
309
|
+
condition_A :q_1, "==", :a_1
|
310
|
+
condition_B :q_watch, "==", :b_1
|
311
|
+
a "Yes"
|
312
|
+
a "No"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
}
|
316
|
+
expect { Surveyor::Parser.parse(survey_text) }.to raise_error(Surveyor::ParserError, /Bad references: q_1; q_1, a_1; q_watch, a_b_1/)
|
317
|
+
end
|
318
|
+
it "repeated references" do
|
319
|
+
survey_text = %q{
|
320
|
+
survey "Refs" do
|
321
|
+
section "Bad" do
|
322
|
+
q_watch "Do you watch football?", :pick => :one
|
323
|
+
a_1 "Yes"
|
324
|
+
a_1 "No"
|
325
|
+
|
326
|
+
q_watch "Do you watch baseball?", :pick => :one
|
327
|
+
a_yes "Yes"
|
328
|
+
a_no "No"
|
329
|
+
|
330
|
+
q "Do you like the replacement refs?", :pick => :one
|
331
|
+
dependency :rule => "A or B"
|
332
|
+
condition_A :q_watch, "==", :a_1
|
333
|
+
a "Yes"
|
334
|
+
a "No"
|
335
|
+
end
|
336
|
+
end
|
337
|
+
}
|
338
|
+
expect { Surveyor::Parser.parse(survey_text) }.to raise_error(Surveyor::ParserError, /Duplicate references: q_watch, a_1; q_watch/)
|
339
|
+
end
|
340
|
+
it "with Rails validation errors" do
|
341
|
+
survey_text = %q{
|
342
|
+
survey do
|
343
|
+
section "Usage" do
|
344
|
+
q_PLACED_BAG_1 "Is the bag placed?", :pick => :one
|
345
|
+
a_1 "Yes"
|
346
|
+
a_2 "No"
|
347
|
+
a_3 "Refused"
|
348
|
+
end
|
349
|
+
end
|
350
|
+
}
|
351
|
+
expect { Surveyor::Parser.parse(survey_text) }.to raise_error(Surveyor::ParserError, /Survey not saved: Title can't be blank/)
|
352
|
+
end
|
353
|
+
it "bad shortcuts" do
|
354
|
+
survey_text = %q{
|
355
|
+
survey "shortcuts" do
|
356
|
+
section "Bad" do
|
357
|
+
quack "Do you like ducks?", :pick => :one
|
358
|
+
a_1 "Yes"
|
359
|
+
a_1 "No"
|
360
|
+
end
|
361
|
+
end
|
362
|
+
}
|
363
|
+
expect { Surveyor::Parser.parse(survey_text) }.to raise_error(Surveyor::ParserError, /\"quack\" is not a surveyor method./)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
context "helper methods" do
|
367
|
+
it "should translate shortcuts into full model names" do
|
368
|
+
parser.send(:full, "section").should == "survey_section"
|
369
|
+
parser.send(:full, "g").should == "question_group"
|
370
|
+
parser.send(:full, "repeater").should == "question_group"
|
371
|
+
parser.send(:full, "label").should == "question"
|
372
|
+
parser.send(:full, "vc").should == "validation_condition"
|
373
|
+
parser.send(:full, "vcondition").should == "validation_condition"
|
374
|
+
end
|
375
|
+
it "should translate 'condition' based on context" do
|
376
|
+
parser.send(:full, "condition").should == "dependency_condition"
|
377
|
+
parser.send(:full, "c").should == "dependency_condition"
|
378
|
+
parser.context[:validation] = Validation.new
|
379
|
+
parser.send(:full, "condition").should == "validation_condition"
|
380
|
+
parser.send(:full, "c").should == "validation_condition"
|
381
|
+
parser.context[:validation] = nil
|
382
|
+
parser.send(:full, "condition").should == "dependency_condition"
|
383
|
+
parser.send(:full, "c").should == "dependency_condition"
|
384
|
+
end
|
385
|
+
it "should not translate bad shortcuts" do
|
386
|
+
parser.send(:full, "quack").should == "quack"
|
387
|
+
parser.send(:full, "grizzly").should == "grizzly"
|
388
|
+
end
|
389
|
+
it "should identify models that take blocks" do
|
390
|
+
parser.send(:block_models).should == %w(survey survey_section question_group)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|