upgrade_surveyor 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.rspec +1 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +253 -0
- data/Gemfile +5 -0
- data/Gemfile.rails_version +25 -0
- data/MIT-LICENSE +20 -0
- data/README.md +164 -0
- data/Rakefile +65 -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/permitted_params.rb +102 -0
- data/app/models/question.rb +3 -0
- data/app/models/question_group.rb +3 -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_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 +21 -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/config/routes.rb +8 -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/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/jquery-ui-1.10.0.custom.sass +1380 -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/assets/stylesheets/surveyor.sass +132 -0
- data/lib/generators/surveyor/custom_generator.rb +18 -0
- data/lib/generators/surveyor/install_generator.rb +98 -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/acts_as_response.rb +19 -0
- data/lib/surveyor/common.rb +59 -0
- data/lib/surveyor/engine.rb +15 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +13 -0
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +86 -0
- data/lib/surveyor/models/answer_methods.rb +76 -0
- data/lib/surveyor/models/dependency_condition_methods.rb +65 -0
- data/lib/surveyor/models/dependency_methods.rb +57 -0
- data/lib/surveyor/models/question_group_methods.rb +62 -0
- data/lib/surveyor/models/question_methods.rb +103 -0
- data/lib/surveyor/models/response_methods.rb +125 -0
- data/lib/surveyor/models/response_set_methods.rb +187 -0
- data/lib/surveyor/models/survey_methods.rb +95 -0
- data/lib/surveyor/models/survey_section_methods.rb +48 -0
- data/lib/surveyor/models/survey_translation_methods.rb +28 -0
- data/lib/surveyor/models/validation_condition_methods.rb +42 -0
- data/lib/surveyor/models/validation_methods.rb +41 -0
- data/lib/surveyor/mustache_context.rb +13 -0
- data/lib/surveyor/parser.rb +427 -0
- data/lib/surveyor/redcap_parser.rb +288 -0
- data/lib/surveyor/surveyor_controller_methods.rb +237 -0
- data/lib/surveyor/unparser.rb +161 -0
- data/lib/surveyor/version.rb +3 -0
- data/lib/surveyor.rb +13 -0
- data/lib/tasks/surveyor_tasks.rake +88 -0
- data/rails/init.rb +1 -0
- data/spec/controllers/surveyor_controller_spec.rb +304 -0
- data/spec/factories.rb +166 -0
- data/spec/features/ajax_spec.rb +205 -0
- data/spec/features/api_spec.rb +157 -0
- data/spec/features/duplicate_prevention_spec.rb +50 -0
- data/spec/features/translations_spec.rb +116 -0
- data/spec/features/ui_spec.rb +466 -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 +114 -0
- data/spec/lib/common_spec.rb +37 -0
- data/spec/lib/parser_spec.rb +393 -0
- data/spec/lib/rake_kitchen_sink.rb +40 -0
- data/spec/lib/redcap_parser_spec.rb +129 -0
- data/spec/lib/tasks_spec.rake +26 -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 +447 -0
- data/spec/models/response_spec.rb +205 -0
- data/spec/models/survey_section_spec.rb +58 -0
- data/spec/models/survey_spec.rb +155 -0
- data/spec/models/validation_condition_spec.rb +98 -0
- data/spec/models/validation_spec.rb +64 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/support/shared.rb +5 -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/surveyor.gemspec +40 -0
- data/switch.sh +53 -0
- metadata +510 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "preventing duplicates", js: true do
|
4
|
+
include_context "everything"
|
5
|
+
it "saves a simple radio button response" do
|
6
|
+
response_set = start_survey('Everything')
|
7
|
+
expect(page).to have_content("What is your favorite color?")
|
8
|
+
within question("1") do
|
9
|
+
choose "blue"
|
10
|
+
choose "red"
|
11
|
+
end
|
12
|
+
wait_for_ajax
|
13
|
+
expect(response_set.count).to eq(1)
|
14
|
+
expect(response_set.for("1", "r").count).to eq(1)
|
15
|
+
end
|
16
|
+
it "saves a simple checkbox response" do
|
17
|
+
response_set = start_survey('Everything')
|
18
|
+
expect(page).to have_content("Choose the colors you don't like")
|
19
|
+
within question("2b") do
|
20
|
+
check "purple"
|
21
|
+
check "orange"
|
22
|
+
uncheck "orange"
|
23
|
+
check "brown"
|
24
|
+
end
|
25
|
+
wait_for_ajax
|
26
|
+
expect(response_set.count).to eq(2)
|
27
|
+
expect(response_set.for("2b", "1").count).to eq(0)
|
28
|
+
expect(response_set.for("2b", "2").count).to eq(1)
|
29
|
+
expect(response_set.for("2b", "3").count).to eq(1)
|
30
|
+
end
|
31
|
+
it "saves a string response" do
|
32
|
+
response_set = start_survey('Everything')
|
33
|
+
expect(page).to have_content("What is the best color for a fire engine?")
|
34
|
+
within question("fire_engine") do
|
35
|
+
fill_in "Color", with: "yellow"
|
36
|
+
end
|
37
|
+
within question("2b") do
|
38
|
+
check "purple"
|
39
|
+
end
|
40
|
+
within question("fire_engine") do
|
41
|
+
fill_in "Color", with: "red"
|
42
|
+
end
|
43
|
+
within question("2b") do
|
44
|
+
uncheck "purple"
|
45
|
+
end
|
46
|
+
wait_for_ajax
|
47
|
+
expect(response_set.count).to eq(1)
|
48
|
+
expect(response_set.for("fire_engine", "color").first.string_value).to eq("red")
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "translations" do
|
6
|
+
it "localizes surveyor prompts" do
|
7
|
+
survey_text = %(
|
8
|
+
survey "One language is never enough" do
|
9
|
+
translations :en => :default
|
10
|
+
translations :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..."}}}}}
|
11
|
+
translations :he => {"title"=>"ידיעת שפה אחת אינה מספיקה", "survey_sections"=>{"one"=>{"title"=>"אחת"}}, "question_groups"=>{"hello"=>{"text"=>"שלום"}}, "questions"=>{"name"=>{"text"=>"מה שמך?", "answers"=>{"name"=>{"help_text"=>"שמי..."}}}}}
|
12
|
+
translations :ko => {"title"=>"한가지 언어로는 충분치 않습니다.", "survey_sections"=>{"one"=>{"title"=>"하나"}}, "question_groups"=>{"hello"=>{"text"=>"안녕하십니까"}}, "questions"=>{"name"=>{"text"=>"성함이 어떻게 되십니까?", "answers"=>{"name"=>{"help_text"=>"제 이름은 ... 입니다"}}}}}
|
13
|
+
section_one "One" do
|
14
|
+
g_hello "Hello" do
|
15
|
+
q_name "What is your name?"
|
16
|
+
a_name :string, :help_text => "My name is..."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
)
|
21
|
+
Surveyor::Parser.parse(survey_text)
|
22
|
+
expect(SurveyTranslation.count).to eq(4)
|
23
|
+
locales = %w(en es he ko)
|
24
|
+
locales.each{|locale| expect(SurveyTranslation.where(locale: locale).count).to eq(1)}
|
25
|
+
|
26
|
+
start_survey("One language is never enough")
|
27
|
+
expect(page).to have_content("One language is never enough")
|
28
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
29
|
+
expect(page).to have_content("One")
|
30
|
+
expect(page).to have_content("Hello")
|
31
|
+
expect(page).to have_content("What is your name?")
|
32
|
+
expect(page).to have_content("My name is...")
|
33
|
+
|
34
|
+
start_survey("One language is never enough", locale: "en")
|
35
|
+
expect(page).to have_content("One language is never enough")
|
36
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
37
|
+
expect(page).to have_content("One")
|
38
|
+
expect(page).to have_content("Hello")
|
39
|
+
expect(page).to have_content("What is your name?")
|
40
|
+
expect(page).to have_content("My name is...")
|
41
|
+
|
42
|
+
start_survey("Un idioma nunca es suficiente", locale: "es")
|
43
|
+
expect(page).to have_content("Un idioma nunca es suficiente")
|
44
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
45
|
+
expect(page).to have_content("Uno")
|
46
|
+
expect(page).to have_content("¡Hola!")
|
47
|
+
expect(page).to have_content("¿Cómo se llama Usted?")
|
48
|
+
expect(page).to have_content("Mi nombre es...")
|
49
|
+
|
50
|
+
start_survey("ידיעת שפה אחת אינה מספיקה", locale: "he")
|
51
|
+
expect(page).to have_content("ידיעת שפה אחת אינה מספיקה")
|
52
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
53
|
+
expect(page).to have_content("אחת")
|
54
|
+
expect(page).to have_content("שלום")
|
55
|
+
expect(page).to have_content("מה שמך?")
|
56
|
+
expect(page).to have_content("שמי...")
|
57
|
+
|
58
|
+
start_survey("한가지 언어로는 충분치 않습니다.", locale: "ko")
|
59
|
+
expect(page).to have_content("한가지 언어로는 충분치 않습니다.")
|
60
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
61
|
+
expect(page).to have_content("하나")
|
62
|
+
expect(page).to have_content("안녕하십니까")
|
63
|
+
expect(page).to have_content("성함이 어떻게 되십니까?")
|
64
|
+
expect(page).to have_content("제 이름은 ... 입니다")
|
65
|
+
|
66
|
+
start_survey("One language is never enough")
|
67
|
+
expect(page).to have_content("One language is never enough")
|
68
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
69
|
+
expect(page).to have_content("One")
|
70
|
+
expect(page).to have_content("Hello")
|
71
|
+
expect(page).to have_content("What is your name?")
|
72
|
+
expect(page).to have_content("My name is...")
|
73
|
+
end
|
74
|
+
it "switches locales", js: true do
|
75
|
+
survey_text = %(
|
76
|
+
survey "One language is never enough" do
|
77
|
+
translations :en => :default
|
78
|
+
translations :es => {"title"=>"Un idioma nunca es suficiente", "survey_sections"=>{"one"=>{"title"=>"Uno"}, "two"=>{"title"=>"Dos"}}, "question_groups"=>{"hello"=>{"text"=>"¡Hola!"}}, "questions"=>{"name"=>{"text"=>"¿Cómo se llama Usted?", "answers"=>{"name"=>{"help_text"=>"Mi nombre es..."}}}, "color"=>{"text"=>"¿Cuál es tu color favorito?"}}}
|
79
|
+
translations :he => {"title"=>"ידיעת שפה אחת אינה מספיקה", "survey_sections"=>{"one"=>{"title"=>"אחת"}, "two"=>{"title"=>"שנים"}}, "question_groups"=>{"hello"=>{"text"=>"שלום"}}, "questions"=>{"name"=>{"text"=>"מה שמך?", "answers"=>{"name"=>{"help_text"=>"שמי..."}}}, "color"=>{"text"=>"מהו הצבע האהוב עליך?"}}}
|
80
|
+
|
81
|
+
section_one "One" do
|
82
|
+
g_hello "Hello" do
|
83
|
+
q_name "What is your name?"
|
84
|
+
a_name :string, :help_text => "My name is..."
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
section_two "Two" do
|
89
|
+
q_color "What is your favorite color?"
|
90
|
+
a_name :string
|
91
|
+
end
|
92
|
+
end
|
93
|
+
)
|
94
|
+
Surveyor::Parser.parse(survey_text)
|
95
|
+
locales = %w(en es he)
|
96
|
+
start_survey("One language is never enough", locale: "en")
|
97
|
+
expect(page).to have_content("One language is never enough")
|
98
|
+
expect(page).to have_content("What is your name?")
|
99
|
+
expect(page).to have_content("Language")
|
100
|
+
locales.each{|locale| expect(page).to have_css("select#locale option[value=#{locale}]")}
|
101
|
+
select("es", from: "locale")
|
102
|
+
expect(page).to have_content("Un idioma nunca es suficiente")
|
103
|
+
expect(page).to have_content("¿Cómo se llama Usted?")
|
104
|
+
click_button "Dos"
|
105
|
+
expect(page).to have_content("¿Cuál es tu color favorito?")
|
106
|
+
select("he", from: "locale")
|
107
|
+
expect(page).to have_content("מהו הצבע האהוב עליך?")
|
108
|
+
end
|
109
|
+
context "without translations" do
|
110
|
+
include_context "favorites"
|
111
|
+
it "hides the locale menu" do
|
112
|
+
start_survey("Favorites")
|
113
|
+
expect('page').to_not have_css("select#locale")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,466 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ui interactions" do
|
4
|
+
context "saves responses" do
|
5
|
+
include_context "everything"
|
6
|
+
it "radio button" do
|
7
|
+
response_set = start_survey('Everything')
|
8
|
+
expect(page).to have_content("What is your favorite color?")
|
9
|
+
within question("1") do
|
10
|
+
choose "red"
|
11
|
+
choose "blue"
|
12
|
+
end
|
13
|
+
click_button "Next section"
|
14
|
+
expect(response_set.count).to eq(1)
|
15
|
+
end
|
16
|
+
it "dropdown" do
|
17
|
+
response_set = start_survey('Everything')
|
18
|
+
expect(page).to have_content("What color is the sky right now?")
|
19
|
+
within question("3") do
|
20
|
+
select "sunset red", from: "What color is the sky right now?"
|
21
|
+
end
|
22
|
+
click_button "Next section"
|
23
|
+
expect(response_set.count).to eq(1)
|
24
|
+
expect(response_set.for("3", "sr").count).to eq(1)
|
25
|
+
click_button "Previous section"
|
26
|
+
within question("3") do
|
27
|
+
select "night black", from: "What color is the sky right now?"
|
28
|
+
end
|
29
|
+
click_button "Next section"
|
30
|
+
expect(response_set.count).to eq(1)
|
31
|
+
expect(response_set.for("3", "nb").count).to eq(1)
|
32
|
+
end
|
33
|
+
it "check and uncheck checkboxes" do
|
34
|
+
response_set = start_survey('Everything')
|
35
|
+
expect(page).to have_content("What color is the sky right now?")
|
36
|
+
check "orange"
|
37
|
+
click_button "Next section"
|
38
|
+
expect(response_set.count).to eq(1)
|
39
|
+
click_button "Previous section"
|
40
|
+
uncheck "orange"
|
41
|
+
click_button "Next section"
|
42
|
+
expect(response_set.count).to eq(0)
|
43
|
+
end
|
44
|
+
it "string" do
|
45
|
+
response_set = start_survey('Everything')
|
46
|
+
expect(page).to have_content("What is the best color for a fire engine?")
|
47
|
+
within question("fire_engine") do
|
48
|
+
fill_in "Color", with: "red"
|
49
|
+
end
|
50
|
+
click_button "Next section"
|
51
|
+
expect(response_set.count).to eq(1)
|
52
|
+
expect(response_set.for("fire_engine", "color").first.string_value).to eq("red")
|
53
|
+
end
|
54
|
+
it "free text" do
|
55
|
+
response_set = start_survey('Everything')
|
56
|
+
expect(page).to have_content("Please compose a poem about a color")
|
57
|
+
within question("color_poem") do
|
58
|
+
fill_in "Poem", with: "green, nature's color, you're not easy, but that's why you're worth it"
|
59
|
+
end
|
60
|
+
click_button "Next section"
|
61
|
+
expect(response_set.count).to eq(1)
|
62
|
+
expect(response_set.for("color_poem", "poem_text").first.text_value).to eq("green, nature's color, you're not easy, but that's why you're worth it")
|
63
|
+
end
|
64
|
+
it "date" do
|
65
|
+
response_set = start_survey('Everything')
|
66
|
+
expect(page).to have_content("When is the next color run?")
|
67
|
+
within question("color_run_date") do
|
68
|
+
fill_in "On", with: "2014-06-08"
|
69
|
+
end
|
70
|
+
click_button "Next section"
|
71
|
+
expect(response_set.count).to eq(1)
|
72
|
+
expect(response_set.for("color_run_date", "date").first.date_value).to eq("2014-06-08")
|
73
|
+
end
|
74
|
+
it "time" do
|
75
|
+
response_set = start_survey('Everything')
|
76
|
+
expect(page).to have_content("What time does it start?")
|
77
|
+
within question("color_run_time") do
|
78
|
+
fill_in "At", with: "1:30am"
|
79
|
+
end
|
80
|
+
click_button "Next section"
|
81
|
+
expect(response_set.count).to eq(1)
|
82
|
+
expect(response_set.for("color_run_time", "time").first.time_value).to eq("01:30")
|
83
|
+
end
|
84
|
+
it "datetime" do
|
85
|
+
response_set = start_survey('Everything')
|
86
|
+
expect(page).to have_content("When is your next hair color appointment?")
|
87
|
+
within question("hair_appointment") do
|
88
|
+
fill_in "At", with: "2014-06-08 17:00:00"
|
89
|
+
end
|
90
|
+
click_button "Next section"
|
91
|
+
expect(response_set.count).to eq(1)
|
92
|
+
expect(response_set.for("hair_appointment", "datetime").first.datetime_value).to eq(Time.zone.parse("2014-06-08 17:00:00"))
|
93
|
+
end
|
94
|
+
it "radio button with date" do
|
95
|
+
pending "better selectors"
|
96
|
+
# Issue 207 - Create separate fields for date and time
|
97
|
+
response_set = start_survey('Everything')
|
98
|
+
expect(page).to have_content("What is your birth date?")
|
99
|
+
within question("birth_date") do
|
100
|
+
choose "I was born on"
|
101
|
+
fill_in "I was born on", with: "2000-01-01"
|
102
|
+
end
|
103
|
+
click_button "Next section"
|
104
|
+
expect(response_set.count).to eq(1)
|
105
|
+
expect(response_set.for("birth_date", "date").first.date_value).to eq("2000-01-01")
|
106
|
+
end
|
107
|
+
it "checkbox with date" do
|
108
|
+
pending "better selectors"
|
109
|
+
# Issue 207 - Create separate fields for date and time
|
110
|
+
response_set = start_survey('Everything')
|
111
|
+
expect(page).to have_content("What is your birth date?")
|
112
|
+
within question("birth_time") do
|
113
|
+
choose "I was born at"
|
114
|
+
fill_in "I was born at", with: "12:01am"
|
115
|
+
end
|
116
|
+
click_button "Next section"
|
117
|
+
expect(response_set.count).to eq(1)
|
118
|
+
expect(response_set.for("birth_time", "time").first.date_value).to eq("00:01")
|
119
|
+
end
|
120
|
+
it "slider" do
|
121
|
+
pending "move slider programmatically"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
context "saves group responses" do
|
125
|
+
include_context "everything"
|
126
|
+
it "grid" do
|
127
|
+
response_set = start_survey('Everything')
|
128
|
+
click_button "Groups"
|
129
|
+
expect(page).to have_content("How interested are you in the following?")
|
130
|
+
within( grid_row("weddings")){ choose "interested" }
|
131
|
+
click_button "Next section"
|
132
|
+
expect(response_set.count).to eq(1)
|
133
|
+
end
|
134
|
+
it "repeater, repeater with a dropdown" do
|
135
|
+
response_set = start_survey('Everything')
|
136
|
+
click_button "Groups"
|
137
|
+
expect(page).to have_content("Tell us about your family")
|
138
|
+
within group("family") do
|
139
|
+
select "Parent", from: "Relation"
|
140
|
+
fill_in "Name", with: "Mom"
|
141
|
+
fill_in "Quality of your relationship", with: "great"
|
142
|
+
end
|
143
|
+
click_button "Next section"
|
144
|
+
click_button "Previous section"
|
145
|
+
within group("family") do
|
146
|
+
within( question("relation", 1)){ select "Parent", from: "Relation" }
|
147
|
+
within( question("name", 1)){ fill_in "Name", with: "Dad" }
|
148
|
+
within( question("quality", 1)){ fill_in "Quality of your relationship", with: "great" }
|
149
|
+
end
|
150
|
+
click_button "Next section"
|
151
|
+
expect(response_set.count).to eq(6)
|
152
|
+
end
|
153
|
+
it "group with a dropdown" do
|
154
|
+
# Issue 251 - Dropdowns inside of group display as radio buttons
|
155
|
+
response_set = start_survey('Everything')
|
156
|
+
click_button "Groups"
|
157
|
+
expect(page).to have_content("Drop it like it's hot")
|
158
|
+
within group("drop_it") do
|
159
|
+
select "It", from: "What to drop"
|
160
|
+
end
|
161
|
+
click_button "Next section"
|
162
|
+
expect(response_set.count).to eq(1)
|
163
|
+
end
|
164
|
+
it "group with labels" do
|
165
|
+
response_set = start_survey('Everything')
|
166
|
+
click_button "Groups"
|
167
|
+
expect(page).to have_content("Drop it like it's hot")
|
168
|
+
within group("drop_it") do
|
169
|
+
expect(page).to have_content("Like Snoop Dogg said")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context "dependencies" do
|
174
|
+
include_context "everything"
|
175
|
+
it "double letter rule keys" do
|
176
|
+
# for a dependency - try this with "lifestyle"
|
177
|
+
end
|
178
|
+
it "simple" do
|
179
|
+
end
|
180
|
+
it "inside a group" do
|
181
|
+
response_set = start_survey('Everything')
|
182
|
+
click_button "Dependencies"
|
183
|
+
expect(page).to have_hidden_question('who')
|
184
|
+
expect(page).to have_hidden_question('weird')
|
185
|
+
within question("anybody") do
|
186
|
+
choose "Yes"
|
187
|
+
end
|
188
|
+
click_button "Next section"
|
189
|
+
click_button "Previous section"
|
190
|
+
expect(page).to_not have_hidden_question('who')
|
191
|
+
expect(page).to have_hidden_question('weird')
|
192
|
+
within question("anybody") do
|
193
|
+
choose "No"
|
194
|
+
end
|
195
|
+
click_button "Next section"
|
196
|
+
click_button "Previous section"
|
197
|
+
expect(page).to have_hidden_question('who')
|
198
|
+
expect(page).to_not have_hidden_question('weird')
|
199
|
+
|
200
|
+
end
|
201
|
+
it "groups" do
|
202
|
+
response_set = start_survey('Everything')
|
203
|
+
click_button "Dependencies"
|
204
|
+
expect(page).to have_hidden_group('anybody_no')
|
205
|
+
within question("anybody") do
|
206
|
+
choose "No"
|
207
|
+
end
|
208
|
+
click_button "Next section"
|
209
|
+
click_button "Previous section"
|
210
|
+
expect(page).to_not have_hidden_group('anybody_no')
|
211
|
+
end
|
212
|
+
it "on question in dependent group" do
|
213
|
+
response_set = start_survey('Everything')
|
214
|
+
click_button "Dependencies"
|
215
|
+
expect(page).to have_hidden_question('feels_like_it')
|
216
|
+
within question("anybody") do
|
217
|
+
choose "No"
|
218
|
+
end
|
219
|
+
click_button "Next section"
|
220
|
+
click_button "Previous section"
|
221
|
+
expect(page).to have_hidden_question('feels_like_it')
|
222
|
+
within question("who_talking") do
|
223
|
+
choose "Are you nuts?"
|
224
|
+
end
|
225
|
+
click_button "Next section"
|
226
|
+
click_button "Previous section"
|
227
|
+
expect(page).to_not have_hidden_question('feels_like_it')
|
228
|
+
end
|
229
|
+
it "!= without responses" do
|
230
|
+
# Issue 337 answer != condition returns false if question was never activated
|
231
|
+
response_set = start_survey('Everything')
|
232
|
+
click_button "Dependencies"
|
233
|
+
expect(page).to have_content("How do you cool your home?")
|
234
|
+
expect(page).to_not have_hidden_question('cooling_2')
|
235
|
+
expect(page).to have_content("How much does it cost to run your non-passive cooling solutions?")
|
236
|
+
within question("cooling_1") do
|
237
|
+
choose "Passive"
|
238
|
+
end
|
239
|
+
click_button "Next section"
|
240
|
+
click_button "Previous section"
|
241
|
+
expect(page).to have_hidden_question('cooling_2')
|
242
|
+
end
|
243
|
+
it "!= without responses, count>0" do
|
244
|
+
# Issue 337 answer != condition returns false if question was never activated
|
245
|
+
response_set = start_survey('Everything')
|
246
|
+
click_button "Dependencies"
|
247
|
+
expect(page).to have_content("How do you heat your home?")
|
248
|
+
expect(page).to have_hidden_question('heating_2')
|
249
|
+
expect(page).to have_content("How much does it cost to run your non-passive heating solutions?")
|
250
|
+
within question("heating_1") do
|
251
|
+
check "Oven"
|
252
|
+
end
|
253
|
+
click_button "Next section"
|
254
|
+
click_button "Previous section"
|
255
|
+
expect(page).to_not have_hidden_question('heating_2')
|
256
|
+
end
|
257
|
+
it "count== dependencies" do
|
258
|
+
response_set = start_survey('Everything')
|
259
|
+
click_button "Dependencies"
|
260
|
+
expect(page).to have_content("How many times do you count a day")
|
261
|
+
expect(page).to have_hidden_question('counts_good')
|
262
|
+
expect(page).to have_hidden_question('counts_twice')
|
263
|
+
|
264
|
+
within question("counts") do
|
265
|
+
check "Once for me"
|
266
|
+
end
|
267
|
+
click_button "Next section"
|
268
|
+
click_button "Previous section"
|
269
|
+
expect(page).to_not have_hidden_question('counts_good')
|
270
|
+
expect(page).to have_hidden_question('counts_twice')
|
271
|
+
|
272
|
+
within question("counts") do
|
273
|
+
check "Once for you"
|
274
|
+
end
|
275
|
+
click_button "Next section"
|
276
|
+
click_button "Previous section"
|
277
|
+
expect(page).to have_hidden_question('counts_good')
|
278
|
+
expect(page).to_not have_hidden_question('counts_twice')
|
279
|
+
end
|
280
|
+
it "when the last response is removed" do
|
281
|
+
response_set = start_survey('Everything')
|
282
|
+
click_button "Dependencies"
|
283
|
+
expect(page).to have_content("How do you heat your home?")
|
284
|
+
expect(page).to have_hidden_question('heating_3')
|
285
|
+
|
286
|
+
within question("heating_1") do
|
287
|
+
check "Forced air"
|
288
|
+
end
|
289
|
+
click_button "Next section"
|
290
|
+
click_button "Previous section"
|
291
|
+
expect(page).to_not have_hidden_question('heating_3')
|
292
|
+
|
293
|
+
within question("heating_1") do
|
294
|
+
uncheck "Forced air"
|
295
|
+
end
|
296
|
+
click_button "Next section"
|
297
|
+
click_button "Previous section"
|
298
|
+
expect(page).to have_hidden_question('heating_3')
|
299
|
+
end
|
300
|
+
it "on checkboxes" do
|
301
|
+
response_set = start_survey('Everything')
|
302
|
+
click_button "Dependencies"
|
303
|
+
expect(page).to have_content("How many times do you count a day")
|
304
|
+
expect(page).to have_hidden_question('thanks_counting')
|
305
|
+
expect(page).to have_hidden_question('yay_everyone')
|
306
|
+
within question("counts") do
|
307
|
+
check "Once for me"
|
308
|
+
end
|
309
|
+
click_button "Next section"
|
310
|
+
click_button "Previous section"
|
311
|
+
expect(page).to_not have_hidden_question('thanks_counting')
|
312
|
+
expect(page).to have_hidden_question('yay_everyone')
|
313
|
+
|
314
|
+
within question("counts") do
|
315
|
+
check "Once for you"
|
316
|
+
end
|
317
|
+
click_button "Next section"
|
318
|
+
click_button "Previous section"
|
319
|
+
expect(page).to_not have_hidden_question('thanks_counting')
|
320
|
+
expect(page).to have_hidden_question('yay_everyone')
|
321
|
+
|
322
|
+
within question("counts") do
|
323
|
+
check "Once for everyone"
|
324
|
+
end
|
325
|
+
click_button "Next section"
|
326
|
+
click_button "Previous section"
|
327
|
+
expect(page).to_not have_hidden_question('thanks_counting')
|
328
|
+
expect(page).to_not have_hidden_question('yay_everyone')
|
329
|
+
end
|
330
|
+
end
|
331
|
+
context "special features" do
|
332
|
+
include_context "everything"
|
333
|
+
it "help text" do
|
334
|
+
response_set = start_survey('Everything')
|
335
|
+
click_button "Special"
|
336
|
+
within question("favorite_food") do
|
337
|
+
expect(page).to have_css("span.help", text: "just say beef")
|
338
|
+
end
|
339
|
+
end
|
340
|
+
it "images" do
|
341
|
+
response_set = start_survey('Everything')
|
342
|
+
click_button "Special"
|
343
|
+
within question("which_way") do
|
344
|
+
expect(page).to have_css('img[src^="/assets/surveyor/next.gif"]')
|
345
|
+
expect(page).to have_css('img[src^="/assets/surveyor/prev.gif"]')
|
346
|
+
end
|
347
|
+
end
|
348
|
+
it "custom css class" do
|
349
|
+
response_set = start_survey('Everything')
|
350
|
+
click_button "Special"
|
351
|
+
expect(page).to have_css("fieldset.q_default.hidden")
|
352
|
+
end
|
353
|
+
it "default answer" do
|
354
|
+
response_set = start_survey('Everything')
|
355
|
+
click_button "Special"
|
356
|
+
click_button "Click here to finish"
|
357
|
+
expect(response_set.count).to eq(1)
|
358
|
+
expect(response_set.for("favorite_food", "food").first.string_value).to eq("beef")
|
359
|
+
end
|
360
|
+
it "hidden questions" do
|
361
|
+
# Issue 197 - Add a hidden field type
|
362
|
+
# does not appear in DOM, does not receive question numering
|
363
|
+
response_set = start_survey('Everything')
|
364
|
+
click_button "Special"
|
365
|
+
expect(page).to_not have_content("What is your name?")
|
366
|
+
expect(page).to_not have_content("Friends")
|
367
|
+
expect(page).to_not have_content("Who are your friends?")
|
368
|
+
# custom class "hidden" does nothing unless you add your own css to hide it
|
369
|
+
expect(page).to have_content("5) What is your favorite number?")
|
370
|
+
end
|
371
|
+
it "customizing numbering" do
|
372
|
+
override_surveyor_helper_numbering
|
373
|
+
response_set = start_survey('Everything')
|
374
|
+
expect(page).to have_content("A. What is your favorite color?")
|
375
|
+
expect(page).to have_content("B. Choose the colors you don't like")
|
376
|
+
expect(page).to have_content("C. What color is the sky right now?")
|
377
|
+
expect(page).to have_content("D. What is the best color for a fire engine?")
|
378
|
+
expect(page).to have_content("E. What was the last room you painted, and what color?")
|
379
|
+
restore_surveyor_helper_numbering
|
380
|
+
end
|
381
|
+
it "mustache syntax" do
|
382
|
+
# Issue 259 - substitution of the text with Mustache
|
383
|
+
SurveyorController.send(:include, mustache_context_module(name: "Santa", thing: "beards"))
|
384
|
+
response_set = start_survey('Everything')
|
385
|
+
click_button "Special"
|
386
|
+
expect(page).to have_content("Regarding Santa")
|
387
|
+
expect(page).to have_content("Answer all you know about Santa")
|
388
|
+
expect(page).to have_content("Where does Santa live?")
|
389
|
+
expect(page).to have_content("If you don't know where Santa lives, skip the question")
|
390
|
+
expect(page).to have_content("Santa lives on North Pole")
|
391
|
+
expect(page).to have_content("Santa lives on South Pole")
|
392
|
+
expect(page).to have_content("Santa doesn't exist")
|
393
|
+
expect(page).to have_content("Now think about beards")
|
394
|
+
expect(page).to have_content("Yes, beards")
|
395
|
+
end
|
396
|
+
it "mustache with simple hash context" do
|
397
|
+
# Issue 296 - Mustache rendering doesn't work with simple hash contexts
|
398
|
+
SurveyorController.send(:include, hash_context_module({name: "Father Christmas", thing: "reindeer"}))
|
399
|
+
response_set = start_survey('Everything')
|
400
|
+
click_button "Special"
|
401
|
+
expect(page).to have_content("Regarding Father Christmas")
|
402
|
+
expect(page).to have_content("Answer all you know about Father Christmas")
|
403
|
+
expect(page).to have_content("Where does Father Christmas live?")
|
404
|
+
expect(page).to have_content("If you don't know where Father Christmas lives, skip the question")
|
405
|
+
expect(page).to have_content("Father Christmas lives on North Pole")
|
406
|
+
expect(page).to have_content("Father Christmas lives on South Pole")
|
407
|
+
expect(page).to have_content("Father Christmas doesn't exist")
|
408
|
+
expect(page).to have_content("Now think about reindeer")
|
409
|
+
expect(page).to have_content("Yes, reindeer")
|
410
|
+
end
|
411
|
+
end
|
412
|
+
context "versioning" do
|
413
|
+
include_context "favorites"
|
414
|
+
include_context "favorites-ish"
|
415
|
+
it "takes current survey" do
|
416
|
+
response_set = start_survey('Favorites')
|
417
|
+
expect(page).to have_content("What is your favorite color?")
|
418
|
+
expect(page).to have_content("redish")
|
419
|
+
choose "blueish"
|
420
|
+
choose "redish"
|
421
|
+
click_button "Next section"
|
422
|
+
click_button "Click here to finish"
|
423
|
+
expect(response_set.count).to eq(1)
|
424
|
+
end
|
425
|
+
it "takes previous survey" do
|
426
|
+
response_set = start_survey('Favorites', version: '0')
|
427
|
+
expect(page).to have_content("What is your favorite color?")
|
428
|
+
expect(page).to have_content("red")
|
429
|
+
choose "red"
|
430
|
+
choose "blue"
|
431
|
+
click_button "Next section"
|
432
|
+
click_button "Click here to finish"
|
433
|
+
expect(response_set.count).to eq(1)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
context "shows responses" do
|
437
|
+
include_context "favorites"
|
438
|
+
include_context "feelings"
|
439
|
+
it "takes a survey, then shows it" do
|
440
|
+
response_set = start_survey('Favorites')
|
441
|
+
expect(page).to have_content("What is your favorite color?")
|
442
|
+
choose "red"
|
443
|
+
choose "blue"
|
444
|
+
check "orange"
|
445
|
+
check "brown"
|
446
|
+
click_button "Next section"
|
447
|
+
click_button "Click here to finish"
|
448
|
+
visit("/surveys/favorites/#{response_set.access_code}/")
|
449
|
+
expect(page).to have_disabled_selected_radio("blue")
|
450
|
+
expect(page).to have_disabled_selected_checkbox("orange")
|
451
|
+
expect(page).to have_disabled_selected_checkbox("brown")
|
452
|
+
end
|
453
|
+
it "takes a survey with grid questions, then shows it" do
|
454
|
+
response_set = start_survey('Feelings')
|
455
|
+
expect(page).to have_content("Tell us how you feel today")
|
456
|
+
within grid_row "anxious|calm" do
|
457
|
+
choose "-1"
|
458
|
+
end
|
459
|
+
click_button "Click here to finish"
|
460
|
+
visit("/surveys/favorites/#{response_set.access_code}/")
|
461
|
+
within grid_row "anxious|calm" do
|
462
|
+
expect(page).to have_disabled_selected_radio("-1")
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|