surveyor_gui 0.0.3
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/Gemfile +7 -0
- data/LICENSE +21 -0
- data/MIT-LICENSE +20 -0
- data/README.md +159 -0
- data/Rakefile +66 -0
- data/app/controllers/answers_controller.rb +3 -0
- data/app/controllers/application_controller.rb +3 -0
- data/app/controllers/dependencys_controller.rb +286 -0
- data/app/controllers/question_groups_controller.rb +84 -0
- data/app/controllers/questions_controller.rb +187 -0
- data/app/controllers/survey_sections_controller.rb +80 -0
- data/app/controllers/surveyforms_controller.rb +4 -0
- data/app/controllers/surveyor_controller.rb +89 -0
- data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
- data/app/controllers/surveyor_gui/responses_controller.rb +39 -0
- data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
- data/app/facades/report_formatter.rb +44 -0
- data/app/facades/report_preview_wrapper.rb +11 -0
- data/app/facades/report_response_generator.rb +147 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/dependency_helper.rb +5 -0
- data/app/helpers/question_helper.rb +22 -0
- data/app/helpers/surveyform_helper.rb +179 -0
- data/app/helpers/surveyor_gui/report_helper.rb +19 -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_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/dependencys/_column.html.erb +1 -0
- data/app/views/dependencys/_dependency.html.erb +22 -0
- data/app/views/dependencys/_dependency_condition_fields.html.erb +48 -0
- data/app/views/dependencys/_form.html.erb +20 -0
- data/app/views/dependencys/blank.html.erb +0 -0
- data/app/views/dependencys/edit.html.erb +1 -0
- data/app/views/dependencys/new.html.erb +1 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/surveyor_gui_blank.html.erb +12 -0
- data/app/views/layouts/surveyor_gui_default.html.erb +16 -0
- data/app/views/layouts/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/question_groups/_form.html.erb +56 -0
- data/app/views/question_groups/_group_inline_field.html.erb +21 -0
- data/app/views/question_groups/_group_inline_fields.html.erb +25 -0
- data/app/views/question_groups/blank.html.erb +0 -0
- data/app/views/question_groups/edit.html.erb +1 -0
- data/app/views/question_groups/new.html.erb +1 -0
- data/app/views/questions/_answer_fields.html.erb +23 -0
- data/app/views/questions/_answer_options.html.erb +28 -0
- data/app/views/questions/_form.html.erb +65 -0
- data/app/views/questions/_grid_dropdown_columns.html.erb +10 -0
- data/app/views/questions/_grid_dropdown_fields.html.erb +42 -0
- data/app/views/questions/_grid_fields.html.erb +9 -0
- data/app/views/questions/_no_picks.html.erb +29 -0
- data/app/views/questions/_pick.html +21 -0
- data/app/views/questions/_picks.html.erb +12 -0
- data/app/views/questions/blank.html.erb +0 -0
- data/app/views/questions/edit.html.erb +1 -0
- data/app/views/questions/new.html.erb +1 -0
- data/app/views/survey_sections/_form.html.erb +13 -0
- data/app/views/survey_sections/blank.html.erb +0 -0
- data/app/views/survey_sections/edit.html.erb +1 -0
- data/app/views/survey_sections/new.html.erb +1 -0
- data/app/views/surveyforms/_form.html.erb +50 -0
- data/app/views/surveyforms/_question_field.html.erb +148 -0
- data/app/views/surveyforms/_question_group.html.erb +116 -0
- data/app/views/surveyforms/_question_group_fields.html.erb +3 -0
- data/app/views/surveyforms/_question_name_and_number.html.erb +6 -0
- data/app/views/surveyforms/_question_section.html.erb +15 -0
- data/app/views/surveyforms/_question_wrapper.html.erb +109 -0
- data/app/views/surveyforms/_survey_section_fields.html.erb +138 -0
- data/app/views/surveyforms/clone_survey.html.erb +13 -0
- data/app/views/surveyforms/edit.html.erb +5 -0
- data/app/views/surveyforms/index.html.erb +40 -0
- data/app/views/surveyforms/new.html.erb +1 -0
- data/app/views/surveyforms/show.html.erb +5 -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 +28 -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 +9 -0
- data/app/views/surveyor_gui/shared/_report_data.html.haml +24 -0
- data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
- data/config.ru +4 -0
- data/config/environment.rb +0 -0
- data/config/routes.rb +71 -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 +1417 -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 +650 -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_default.html.erb +16 -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.rb +17 -0
- data/lib/surveyor_gui/engine.rb +30 -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 +67 -0
- data/lib/surveyor_gui/models/response_set_methods.rb +54 -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/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 +361 -0
- data/spec/controllers/surveyor_controller_spec.rb +303 -0
- data/spec/factories.rb +181 -0
- data/spec/features/create_survey_spec.rb +418 -0
- data/spec/features/dependencies_spec.rb +61 -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 +312 -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 +73 -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.ru +4 -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/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/vendor/assets/stylesheets/.gitkeep +0 -0
- data/vendor/assets/stylesheets/custom.sass +5 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +664 -0
@@ -0,0 +1,268 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
3
|
+
|
4
|
+
describe QuestionType do
|
5
|
+
let(:grid) { FactoryGirl.create(:question_group, display_type: "grid") }
|
6
|
+
let(:inline) { FactoryGirl.create(:question_group, display_type: "inline") }
|
7
|
+
let(:repeater){ FactoryGirl.create(:question_group, display_type: "inline") }
|
8
|
+
|
9
|
+
let(:textbox) { FactoryGirl.create(
|
10
|
+
:question,
|
11
|
+
pick: "none",
|
12
|
+
display_type: "default",
|
13
|
+
question_group_id: nil
|
14
|
+
)
|
15
|
+
}
|
16
|
+
let(:textbox_a) { FactoryGirl.create(
|
17
|
+
:answer,
|
18
|
+
question_id: textbox.id,
|
19
|
+
response_class: :text
|
20
|
+
)
|
21
|
+
}
|
22
|
+
let(:text) { FactoryGirl.create(
|
23
|
+
:question,
|
24
|
+
pick: "none",
|
25
|
+
display_type: "default",
|
26
|
+
question_group_id: nil
|
27
|
+
)
|
28
|
+
}
|
29
|
+
let(:text_a) { FactoryGirl.create(
|
30
|
+
:answer,
|
31
|
+
question_id: text.id,
|
32
|
+
response_class: :string
|
33
|
+
)
|
34
|
+
}
|
35
|
+
let(:float) { FactoryGirl.create(
|
36
|
+
:question,
|
37
|
+
pick: "none",
|
38
|
+
display_type: "default",
|
39
|
+
question_group_id: nil
|
40
|
+
)
|
41
|
+
}
|
42
|
+
let(:float_a) { FactoryGirl.create(
|
43
|
+
:answer,
|
44
|
+
question_id: float.id,
|
45
|
+
response_class: :float
|
46
|
+
)
|
47
|
+
}
|
48
|
+
let(:integer) { FactoryGirl.create(
|
49
|
+
:question,
|
50
|
+
pick: "none",
|
51
|
+
display_type: "default",
|
52
|
+
question_group_id: nil
|
53
|
+
)
|
54
|
+
}
|
55
|
+
let(:integer_a) { FactoryGirl.create(
|
56
|
+
:answer,
|
57
|
+
question_id: integer.id,
|
58
|
+
response_class: :integer
|
59
|
+
)
|
60
|
+
}
|
61
|
+
let(:date) { FactoryGirl.create(
|
62
|
+
:question,
|
63
|
+
pick: "none",
|
64
|
+
display_type: "default",
|
65
|
+
question_group_id: nil
|
66
|
+
)
|
67
|
+
}
|
68
|
+
let(:date_a) { FactoryGirl.create(
|
69
|
+
:answer,
|
70
|
+
question_id: date.id,
|
71
|
+
response_class: :date
|
72
|
+
)
|
73
|
+
}
|
74
|
+
let(:file) { FactoryGirl.create(
|
75
|
+
:question,
|
76
|
+
pick: "none",
|
77
|
+
display_type: "default",
|
78
|
+
question_group_id: nil
|
79
|
+
)
|
80
|
+
}
|
81
|
+
let(:file_a) { FactoryGirl.create(
|
82
|
+
:answer,
|
83
|
+
question_id: file.id,
|
84
|
+
response_class: :blob
|
85
|
+
)
|
86
|
+
}
|
87
|
+
let(:label) { FactoryGirl.create(
|
88
|
+
:question,
|
89
|
+
pick: "none",
|
90
|
+
display_type: "label",
|
91
|
+
question_group_id: nil
|
92
|
+
)
|
93
|
+
}
|
94
|
+
let(:pick_one) { FactoryGirl.create(
|
95
|
+
:question,
|
96
|
+
pick: "one",
|
97
|
+
display_type: "default",
|
98
|
+
question_group_id: nil
|
99
|
+
)
|
100
|
+
}
|
101
|
+
let(:pick_any) { FactoryGirl.create(
|
102
|
+
:question,
|
103
|
+
pick: "any",
|
104
|
+
display_type: "default",
|
105
|
+
question_group_id: nil
|
106
|
+
)
|
107
|
+
}
|
108
|
+
let(:pick_one_inline) { FactoryGirl.create(
|
109
|
+
:question,
|
110
|
+
pick: "one",
|
111
|
+
display_type: "default",
|
112
|
+
question_group_id: inline.id
|
113
|
+
)
|
114
|
+
}
|
115
|
+
let(:pick_any_inline) { FactoryGirl.create(
|
116
|
+
:question,
|
117
|
+
pick: "any",
|
118
|
+
display_type: "default",
|
119
|
+
question_group_id: inline.id
|
120
|
+
)
|
121
|
+
}
|
122
|
+
let(:dropdown) { FactoryGirl.create(
|
123
|
+
:question,
|
124
|
+
pick: "one",
|
125
|
+
display_type: "dropdown",
|
126
|
+
question_group_id: nil
|
127
|
+
)
|
128
|
+
}
|
129
|
+
let(:slider) { FactoryGirl.create(
|
130
|
+
:question,
|
131
|
+
pick: "one",
|
132
|
+
display_type: "slider",
|
133
|
+
question_group_id: nil
|
134
|
+
)
|
135
|
+
}
|
136
|
+
let(:stars) { FactoryGirl.create(
|
137
|
+
:question,
|
138
|
+
pick: "one",
|
139
|
+
display_type: "stars",
|
140
|
+
question_group_id: nil
|
141
|
+
)
|
142
|
+
}
|
143
|
+
let(:grid_one) { FactoryGirl.create(
|
144
|
+
:question,
|
145
|
+
pick: "one",
|
146
|
+
display_type: "default",
|
147
|
+
question_group_id: grid.id
|
148
|
+
)
|
149
|
+
}
|
150
|
+
let(:grid_any) { FactoryGirl.create(
|
151
|
+
:question,
|
152
|
+
pick: "any",
|
153
|
+
display_type: "default",
|
154
|
+
question_group_id: grid.id
|
155
|
+
)
|
156
|
+
}
|
157
|
+
let(:grid_dropdown) { FactoryGirl.create(
|
158
|
+
:question,
|
159
|
+
pick: "one",
|
160
|
+
display_type: "dropdown",
|
161
|
+
question_group_id: grid.id
|
162
|
+
)
|
163
|
+
}
|
164
|
+
let(:group_inline) { FactoryGirl.create(
|
165
|
+
:question,
|
166
|
+
pick: "",
|
167
|
+
display_type: "",
|
168
|
+
question_group_id: inline.id
|
169
|
+
)
|
170
|
+
}
|
171
|
+
let(:repeater) { FactoryGirl.create(
|
172
|
+
:question,
|
173
|
+
pick: "",
|
174
|
+
display_type: "",
|
175
|
+
question_group_id: repeater.id
|
176
|
+
)
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
context "when categorizing question" do
|
181
|
+
before do
|
182
|
+
text.reload
|
183
|
+
text_a.reload
|
184
|
+
textbox.reload
|
185
|
+
textbox_a.reload
|
186
|
+
float.reload
|
187
|
+
float_a.reload
|
188
|
+
integer.reload
|
189
|
+
integer_a.reload
|
190
|
+
date.reload
|
191
|
+
date_a.reload
|
192
|
+
file.reload
|
193
|
+
file_a.reload
|
194
|
+
end
|
195
|
+
|
196
|
+
it "recognizes a textbox question" do
|
197
|
+
textbox.reload
|
198
|
+
textbox_a.reload
|
199
|
+
expect(textbox.question_type.id).to eql :box
|
200
|
+
end
|
201
|
+
|
202
|
+
it "recognizes a text question" do
|
203
|
+
expect(text.question_type.id).to eql :string
|
204
|
+
end
|
205
|
+
|
206
|
+
it "recognizes a float question" do
|
207
|
+
expect(float.question_type.id).to eql :number
|
208
|
+
end
|
209
|
+
|
210
|
+
it "recognizes an date question" do
|
211
|
+
expect(date.question_type.id).to eql :date
|
212
|
+
end
|
213
|
+
|
214
|
+
it "recognizes a file question" do
|
215
|
+
expect(file.question_type.id).to eql :file
|
216
|
+
end
|
217
|
+
|
218
|
+
it "recognizes a label" do
|
219
|
+
expect(label.question_type.id).to eql :label
|
220
|
+
end
|
221
|
+
|
222
|
+
it "recognizes a pick one question" do
|
223
|
+
expect(pick_one.question_type.id).to eql :pick_one
|
224
|
+
end
|
225
|
+
|
226
|
+
it "recognizes a pick any question" do
|
227
|
+
expect(pick_any.question_type.id).to eql :pick_any
|
228
|
+
end
|
229
|
+
|
230
|
+
it "recognizes an inline pick one question" do
|
231
|
+
expect(pick_one_inline.question_type.id).to eql :pick_one
|
232
|
+
end
|
233
|
+
|
234
|
+
it "recognizes an inline pick any question" do
|
235
|
+
expect(pick_any_inline.question_type.id).to eql :pick_any
|
236
|
+
end
|
237
|
+
|
238
|
+
it "recognizes a dropdown question" do
|
239
|
+
expect(dropdown.question_type.id).to eql :dropdown
|
240
|
+
end
|
241
|
+
|
242
|
+
it "recognizes a slider question" do
|
243
|
+
expect(slider.question_type.id).to eql :slider
|
244
|
+
end
|
245
|
+
|
246
|
+
it "recognizes a stars question" do
|
247
|
+
expect(stars.question_type.id).to eql :stars
|
248
|
+
end
|
249
|
+
|
250
|
+
it "recognizes a grid one question" do
|
251
|
+
expect(grid_one.question_type.id).to eql :grid_one
|
252
|
+
end
|
253
|
+
|
254
|
+
it "recognizes a grid any question" do
|
255
|
+
expect(grid_any.question_type.id).to eql :grid_any
|
256
|
+
end
|
257
|
+
|
258
|
+
it "recognizes a grid dropdown question" do
|
259
|
+
expect(grid_dropdown.question_type.id).to eql :grid_dropdown
|
260
|
+
end
|
261
|
+
|
262
|
+
it "recognizes a group inline question" do
|
263
|
+
expect(group_inline.question_type.id).to eql :group_inline
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ValidationCondition do
|
4
|
+
before(:each) do
|
5
|
+
@validation_condition = FactoryGirl.create(:validation_condition)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be valid" do
|
9
|
+
@validation_condition.should be_valid
|
10
|
+
end
|
11
|
+
# this causes issues with building and saving
|
12
|
+
# it "should be invalid without a parent validation_id" do
|
13
|
+
# @validation_condition.validation_id = nil
|
14
|
+
# @validation_condition.should have(1).errors_on(:validation_id)
|
15
|
+
# end
|
16
|
+
|
17
|
+
it "should be invalid without an operator" do
|
18
|
+
@validation_condition.operator = nil
|
19
|
+
@validation_condition.should have(2).errors_on(:operator)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be invalid without a rule_key" do
|
23
|
+
@validation_condition.should be_valid
|
24
|
+
@validation_condition.rule_key = nil
|
25
|
+
@validation_condition.should_not be_valid
|
26
|
+
@validation_condition.should have(1).errors_on(:rule_key)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have unique rule_key within the context of a validation" do
|
30
|
+
@validation_condition.should be_valid
|
31
|
+
FactoryGirl.create(:validation_condition, :validation_id => 2, :rule_key => "2")
|
32
|
+
@validation_condition.rule_key = "2" #rule key uniquness is scoped by validation_id
|
33
|
+
@validation_condition.validation_id = 2
|
34
|
+
@validation_condition.should_not be_valid
|
35
|
+
@validation_condition.should have(1).errors_on(:rule_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have an operator in Surveyor::Common::OPERATORS" do
|
39
|
+
Surveyor::Common::OPERATORS.each do |o|
|
40
|
+
@validation_condition.operator = o
|
41
|
+
@validation_condition.should have(0).errors_on(:operator)
|
42
|
+
end
|
43
|
+
@validation_condition.operator = "#"
|
44
|
+
@validation_condition.should have(1).error_on(:operator)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ValidationCondition, "validating responses" do
|
49
|
+
def test_var(vhash, ahash, rhash)
|
50
|
+
v = FactoryGirl.create(:validation_condition, vhash)
|
51
|
+
a = FactoryGirl.create(:answer, ahash)
|
52
|
+
r = FactoryGirl.create(:response, {:answer => a, :question => a.question}.merge(rhash))
|
53
|
+
return v.is_valid?(r)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should validate a response by regexp" do
|
57
|
+
test_var({:operator => "=~", :regexp => /^[a-z]{1,6}$/.to_s}, {:response_class => "string"}, {:string_value => "clear"}).should be_true
|
58
|
+
test_var({:operator => "=~", :regexp => /^[a-z]{1,6}$/.to_s}, {:response_class => "string"}, {:string_value => "foobarbaz"}).should be_false
|
59
|
+
end
|
60
|
+
it "should validate a response by integer comparison" do
|
61
|
+
test_var({:operator => ">", :integer_value => 3}, {:response_class => "integer"}, {:integer_value => 4}).should be_true
|
62
|
+
test_var({:operator => "<=", :integer_value => 256}, {:response_class => "integer"}, {:integer_value => 512}).should be_false
|
63
|
+
end
|
64
|
+
it "should validate a response by (in)equality" do
|
65
|
+
test_var({:operator => "!=", :datetime_value => Date.today + 1}, {:response_class => "date"}, {:datetime_value => Date.today}).should be_true
|
66
|
+
test_var({:operator => "==", :string_value => "foo"}, {:response_class => "string"}, {:string_value => "foo"}).should be_true
|
67
|
+
end
|
68
|
+
it "should represent itself as a hash" do
|
69
|
+
@v = FactoryGirl.create(:validation_condition, :rule_key => "A")
|
70
|
+
@v.stub(:is_valid?).and_return(true)
|
71
|
+
@v.to_hash("foo").should == {:A => true}
|
72
|
+
@v.stub(:is_valid?).and_return(false)
|
73
|
+
@v.to_hash("foo").should == {:A => false}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe ValidationCondition, "validating responses by other responses" do
|
78
|
+
def test_var(v_hash, a_hash, r_hash, ca_hash, cr_hash)
|
79
|
+
ca = FactoryGirl.create(:answer, ca_hash)
|
80
|
+
cr = FactoryGirl.create(:response, cr_hash.merge(:answer => ca, :question => ca.question))
|
81
|
+
v = FactoryGirl.create(:validation_condition, v_hash.merge({:question_id => ca.question.id, :answer_id => ca.id}))
|
82
|
+
a = FactoryGirl.create(:answer, a_hash)
|
83
|
+
r = FactoryGirl.create(:response, r_hash.merge(:answer => a, :question => a.question))
|
84
|
+
return v.is_valid?(r)
|
85
|
+
end
|
86
|
+
it "should validate a response by integer comparison" do
|
87
|
+
test_var({:operator => ">"}, {:response_class => "integer"}, {:integer_value => 4}, {:response_class => "integer"}, {:integer_value => 3}).should be_true
|
88
|
+
test_var({:operator => "<="}, {:response_class => "integer"}, {:integer_value => 512}, {:response_class => "integer"}, {:integer_value => 4}).should be_false
|
89
|
+
end
|
90
|
+
it "should validate a response by (in)equality" do
|
91
|
+
test_var({:operator => "!="}, {:response_class => "date"}, {:datetime_value => Date.today}, {:response_class => "date"}, {:datetime_value => Date.today + 1}).should be_true
|
92
|
+
test_var({:operator => "=="}, {:response_class => "string"}, {:string_value => "donuts"}, {:response_class => "string"}, {:string_value => "donuts"}).should be_true
|
93
|
+
end
|
94
|
+
it "should not validate a response by regexp" do
|
95
|
+
test_var({:operator => "=~"}, {:response_class => "date"}, {:datetime_value => Date.today}, {:response_class => "date"}, {:datetime_value => Date.today + 1}).should be_false
|
96
|
+
test_var({:operator => "=~"}, {:response_class => "string"}, {:string_value => "donuts"}, {:response_class => "string"}, {:string_value => "donuts"}).should be_false
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Validation do
|
4
|
+
before(:each) do
|
5
|
+
@validation = FactoryGirl.create(:validation)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be valid" do
|
9
|
+
@validation.should be_valid
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be invalid without a rule" do
|
13
|
+
@validation.rule = nil
|
14
|
+
@validation.should have(2).errors_on(:rule)
|
15
|
+
@validation.rule = " "
|
16
|
+
@validation.should have(1).errors_on(:rule)
|
17
|
+
end
|
18
|
+
|
19
|
+
# this causes issues with building and saving
|
20
|
+
# it "should be invalid without a answer_id" do
|
21
|
+
# @validation.answer_id = nil
|
22
|
+
# @validation.should have(1).error_on(:answer_id)
|
23
|
+
# end
|
24
|
+
|
25
|
+
it "should be invalid unless rule composed of only references and operators" do
|
26
|
+
@validation.rule = "foo"
|
27
|
+
@validation.should have(1).error_on(:rule)
|
28
|
+
@validation.rule = "1 to 2"
|
29
|
+
@validation.should have(1).error_on(:rule)
|
30
|
+
@validation.rule = "a and b"
|
31
|
+
@validation.should have(1).error_on(:rule)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
describe Validation, "reporting its status" do
|
35
|
+
def test_var(vhash, vchashes, ahash, rhash)
|
36
|
+
a = FactoryGirl.create(:answer, ahash)
|
37
|
+
v = FactoryGirl.create(:validation, {:answer => a, :rule => "A"}.merge(vhash))
|
38
|
+
vchashes.each do |vchash|
|
39
|
+
FactoryGirl.create(:validation_condition, {:validation => v, :rule_key => "A"}.merge(vchash))
|
40
|
+
end
|
41
|
+
rs = FactoryGirl.create(:response_set)
|
42
|
+
r = FactoryGirl.create(:response, {:answer => a, :question => a.question}.merge(rhash))
|
43
|
+
rs.responses << r
|
44
|
+
return v.is_valid?(rs)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should validate a response by integer comparison" do
|
48
|
+
test_var({:rule => "A and B"}, [{:operator => ">=", :integer_value => 0}, {:rule_key => "B", :operator => "<=", :integer_value => 120}], {:response_class => "integer"}, {:integer_value => 48}).should be_true
|
49
|
+
end
|
50
|
+
it "should validate a response by regexp" do
|
51
|
+
test_var({}, [{:operator => "=~", :regexp => '/^[a-z]{1,6}$/'}], {:response_class => "string"}, {:string_value => ""}).should be_false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
describe Validation, "with conditions" do
|
55
|
+
it "should destroy conditions when destroyed" do
|
56
|
+
@validation = FactoryGirl.create(:validation)
|
57
|
+
FactoryGirl.create(:validation_condition, :validation => @validation, :rule_key => "A")
|
58
|
+
FactoryGirl.create(:validation_condition, :validation => @validation, :rule_key => "B")
|
59
|
+
FactoryGirl.create(:validation_condition, :validation => @validation, :rule_key => "C")
|
60
|
+
v_ids = @validation.validation_conditions.map(&:id)
|
61
|
+
@validation.destroy
|
62
|
+
v_ids.each{|id| DependencyCondition.find_by_id(id).should == nil}
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# This file is customized to run specs withing the testbed environemnt
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
begin
|
4
|
+
require File.expand_path("../../testbed/config/environment", __FILE__)
|
5
|
+
rescue LoadError => e
|
6
|
+
fail "Could not load the testbed app. Have you generated it?\n#{e.class}: #{e}"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rspec/rails'
|
10
|
+
require 'rspec/autorun'
|
11
|
+
|
12
|
+
require 'capybara/rails'
|
13
|
+
require 'capybara/rspec'
|
14
|
+
require 'capybara/poltergeist'
|
15
|
+
require 'capybara/webkit'
|
16
|
+
require 'factories'
|
17
|
+
require 'json_spec'
|
18
|
+
require 'database_cleaner'
|
19
|
+
require 'rspec/retry'
|
20
|
+
require 'rack/utils'
|
21
|
+
|
22
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
|
+
# in spec/support/ and its subdirectories.
|
24
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
25
|
+
|
26
|
+
Capybara.app = Rack::ShowExceptions.new(Testbed::Application)
|
27
|
+
# Checks for pending migrations before tests are run.
|
28
|
+
# If you are not using ActiveRecord, you can remove this line.
|
29
|
+
ActiveRecord::Migration.check_pending! if ::Rails.version >= "4.0" && defined?(ActiveRecord::Migration)
|
30
|
+
|
31
|
+
|
32
|
+
Capybara.register_driver :poltergeist do |app|
|
33
|
+
Capybara::Poltergeist::Driver.new(app, debug: false)
|
34
|
+
end
|
35
|
+
|
36
|
+
Capybara.server_port = 3001
|
37
|
+
Capybara.asset_host = "http://lvh.me:3001"
|
38
|
+
|
39
|
+
Capybara.javascript_driver = :poltergeist
|
40
|
+
|
41
|
+
RSpec.configure do |config|
|
42
|
+
config.include JsonSpec::Helpers
|
43
|
+
config.include SurveyorAPIHelpers
|
44
|
+
config.include SurveyorUIHelpers
|
45
|
+
config.include WaitForAjax
|
46
|
+
|
47
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
48
|
+
|
49
|
+
# == Mock Framework
|
50
|
+
#
|
51
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
52
|
+
#
|
53
|
+
# config.mock_with :mocha
|
54
|
+
# config.mock_with :flexmock
|
55
|
+
# config.mock_with :rr
|
56
|
+
config.mock_with :rspec
|
57
|
+
|
58
|
+
# config.expect_with :rspec do |c|
|
59
|
+
# c.syntax = :expect
|
60
|
+
# end
|
61
|
+
|
62
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
63
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
64
|
+
|
65
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
66
|
+
# examples within a transaction, remove the following line or assign false
|
67
|
+
# instead of true.
|
68
|
+
config.use_transactional_fixtures = false
|
69
|
+
|
70
|
+
# If true, the base class of anonymous controllers will be inferred
|
71
|
+
# automatically. This will be the default behavior in future versions of
|
72
|
+
# rspec-rails.
|
73
|
+
config.infer_base_class_for_anonymous_controllers = false
|
74
|
+
|
75
|
+
# Run specs in random order to surface order dependencies. If you find an
|
76
|
+
# order dependency and want to debug it, you can fix the order by providing
|
77
|
+
# the seed, which is printed after each run.
|
78
|
+
# --seed 1234
|
79
|
+
config.order = "random"
|
80
|
+
|
81
|
+
# rspec-retry
|
82
|
+
# https://github.com/rspec/rspec-core/issues/456
|
83
|
+
config.verbose_retry = true # show retry status in spec process
|
84
|
+
retry_count = ENV['RSPEC_RETRY_COUNT']
|
85
|
+
config.default_retry_count = retry_count.try(:to_i) || 1
|
86
|
+
puts "RSpec retry count is #{config.default_retry_count}"
|
87
|
+
|
88
|
+
# host
|
89
|
+
config.before :each do
|
90
|
+
# host = "lvh.me:"+Capybara.current_session.driver.server.port.to_s
|
91
|
+
## puts host
|
92
|
+
# Capybara.asset_host = "http://#{host}"
|
93
|
+
# Rails.application.routes.default_url_options[:host] = host
|
94
|
+
## #"lvh.me:"+Capybara.current_session.driver.server.port.to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
# Database Cleaner
|
98
|
+
config.before :suite do
|
99
|
+
DatabaseCleaner.clean_with :truncation
|
100
|
+
DatabaseCleaner.strategy = :transaction
|
101
|
+
end
|
102
|
+
|
103
|
+
config.before :each do
|
104
|
+
if example.metadata[:clean_with_truncation] || example.metadata[:js]
|
105
|
+
DatabaseCleaner.strategy = :truncation
|
106
|
+
else
|
107
|
+
DatabaseCleaner.strategy = :transaction
|
108
|
+
end
|
109
|
+
DatabaseCleaner.start
|
110
|
+
end
|
111
|
+
|
112
|
+
config.after :each do
|
113
|
+
Capybara.reset_sessions!
|
114
|
+
DatabaseCleaner.clean
|
115
|
+
end
|
116
|
+
end
|
117
|
+
JsonSpec.configure do
|
118
|
+
exclude_keys "id", "created_at", "updated_at", "uuid", "modified_at", "completed_at"
|
119
|
+
end
|