hssc_surveyor 1.4.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +28 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +198 -0
- data/Gemfile +5 -0
- data/Gemfile.rails_version +19 -0
- data/MIT-LICENSE +20 -0
- data/README.md +186 -0
- data/Rakefile +105 -0
- data/app/controllers/surveyor_controller.rb +6 -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 +4 -0
- data/app/models/dependency.rb +4 -0
- data/app/models/dependency_condition.rb +4 -0
- data/app/models/question.rb +4 -0
- data/app/models/question_group.rb +5 -0
- data/app/models/response.rb +5 -0
- data/app/models/response_set.rb +4 -0
- data/app/models/survey.rb +4 -0
- data/app/models/survey_section.rb +5 -0
- data/app/models/survey_section_sweeper.rb +15 -0
- data/app/models/survey_translation.rb +5 -0
- data/app/models/validation.rb +4 -0
- data/app/models/validation_condition.rb +4 -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 +41 -0
- data/app/views/partials/_question_group.html.haml +44 -0
- data/app/views/partials/_section.html.haml +12 -0
- data/app/views/partials/_section_menu.html.haml +12 -0
- data/app/views/surveyor/edit.html.haml +24 -0
- data/app/views/surveyor/export.json.rabl +85 -0
- data/app/views/surveyor/new.html.haml +24 -0
- data/app/views/surveyor/show.html.haml +74 -0
- data/app/views/surveyor/show.json.rabl +15 -0
- data/ci-exec.sh +56 -0
- data/config/routes.rb +8 -0
- data/cucumber.yml +10 -0
- data/doc/REPRESENTATIONS.md +34 -0
- data/doc/api_id_schema.json +7 -0
- data/doc/question types.png +0 -0
- data/doc/response_set_schema.json +54 -0
- data/doc/surveyor question combinations.png +0 -0
- data/doc/surveyor reject or delete decision matrix.png +0 -0
- data/doc/surveyor_models.png +0 -0
- data/doc/surveyor_models2.png +0 -0
- data/doc/surveyor_timestamp_schema.json +9 -0
- data/features/ajax_submissions.feature +140 -0
- data/features/export_to_json.feature +344 -0
- data/features/internationalization.feature +121 -0
- data/features/no_duplicates.feature +110 -0
- data/features/show_survey.feature +71 -0
- data/features/step_definitions/parser_steps.rb +145 -0
- data/features/step_definitions/surveyor_steps.rb +325 -0
- data/features/step_definitions/ui_steps.rb +25 -0
- data/features/step_definitions/web_steps.rb +225 -0
- data/features/support/REDCapDemoDatabase_DataDictionary.csv +127 -0
- data/features/support/database_cleaner.rb +16 -0
- data/features/support/env.rb +56 -0
- data/features/support/hooks.rb +4 -0
- data/features/support/paths.rb +39 -0
- data/features/support/redcap_new_headers.csv +1 -0
- data/features/support/redcap_siblings.csv +1 -0
- data/features/support/redcap_whitespace.csv +1 -0
- data/features/support/selectors.rb +39 -0
- data/features/support/simultaneous_ajax.rb +101 -0
- data/features/support/single_quit_selenium_driver.rb +23 -0
- data/features/support/slow_updates.rb +18 -0
- data/features/surveyor.feature +895 -0
- data/features/surveyor_dependencies.feature +476 -0
- data/features/surveyor_parser.feature +504 -0
- data/features/z_redcap_parser.feature +62 -0
- data/lib/assets/images/surveyor/next.gif +0 -0
- data/lib/assets/images/surveyor/prev.gif +0 -0
- data/lib/assets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/assets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/assets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/assets/images/ui-icons_222222_256x240.png +0 -0
- data/lib/assets/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/assets/images/ui-icons_454545_256x240.png +0 -0
- data/lib/assets/images/ui-icons_888888_256x240.png +0 -0
- data/lib/assets/images/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 +156 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +11 -0
- data/lib/assets/stylesheets/surveyor/reset.css +48 -0
- data/lib/assets/stylesheets/surveyor/results.css +125 -0
- data/lib/assets/stylesheets/surveyor/ui.slider.extras.css +110 -0
- data/lib/assets/stylesheets/surveyor.sass +132 -0
- data/lib/generators/surveyor/custom_generator.rb +18 -0
- data/lib/generators/surveyor/install_generator.rb +102 -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_attachment_to_response.rb +5 -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 +284 -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 +17 -0
- data/lib/surveyor/common.rb +59 -0
- data/lib/surveyor/engine.rb +10 -0
- data/lib/surveyor/helpers/asset_pipeline.rb +13 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +13 -0
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +103 -0
- data/lib/surveyor/models/answer_methods.rb +86 -0
- data/lib/surveyor/models/dependency_condition_methods.rb +72 -0
- data/lib/surveyor/models/dependency_methods.rb +60 -0
- data/lib/surveyor/models/question_group_methods.rb +61 -0
- data/lib/surveyor/models/question_methods.rb +115 -0
- data/lib/surveyor/models/response_methods.rb +132 -0
- data/lib/surveyor/models/response_set_methods.rb +196 -0
- data/lib/surveyor/models/survey_methods.rb +103 -0
- data/lib/surveyor/models/survey_section_methods.rb +56 -0
- data/lib/surveyor/models/survey_translation_methods.rb +33 -0
- data/lib/surveyor/models/validation_condition_methods.rb +56 -0
- data/lib/surveyor/models/validation_methods.rb +48 -0
- data/lib/surveyor/mustache_context.rb +11 -0
- data/lib/surveyor/parser.rb +428 -0
- data/lib/surveyor/redcap_parser.rb +289 -0
- data/lib/surveyor/surveyor_controller_methods.rb +237 -0
- data/lib/surveyor/unparser.rb +147 -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 +307 -0
- data/spec/factories.rb +161 -0
- data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
- data/spec/helpers/surveyor_helper_spec.rb +118 -0
- data/spec/lib/benchmark_spec.rb +22 -0
- data/spec/lib/chinese_survey.rb +14 -0
- data/spec/lib/common_spec.rb +34 -0
- data/spec/lib/parser_spec.rb +204 -0
- data/spec/lib/rake_kitchen_sink.rb +40 -0
- data/spec/lib/redcap_parser_spec.rb +75 -0
- data/spec/lib/tasks_spec.rake +26 -0
- data/spec/lib/unparser_spec.rb +126 -0
- data/spec/models/answer_spec.rb +175 -0
- data/spec/models/dependency_condition_spec.rb +439 -0
- data/spec/models/dependency_spec.rb +101 -0
- data/spec/models/question_group_spec.rb +93 -0
- data/spec/models/question_spec.rb +207 -0
- data/spec/models/response_set_spec.rb +477 -0
- data/spec/models/response_spec.rb +218 -0
- data/spec/models/survey_section_spec.rb +85 -0
- data/spec/models/survey_spec.rb +191 -0
- data/spec/models/validation_condition_spec.rb +113 -0
- data/spec/models/validation_spec.rb +74 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +56 -0
- data/stacktests.sh +65 -0
- data/surveyor.gemspec +45 -0
- metadata +657 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Surveyor::Unparser do
|
4
|
+
before(:each) do
|
5
|
+
@survey = Survey.new(:title => "Simple survey", :description => "very simple")
|
6
|
+
@section = @survey.sections.build(:title => "Simple section")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should unparse a basic survey, section, and question" do
|
10
|
+
q1 = @section.questions.build(:text => "What is your favorite color?", :reference_identifier => 1, :pick => :one)
|
11
|
+
a11 = q1.answers.build(:text => "red", :response_class => "answer", :reference_identifier => 1, :question => q1)
|
12
|
+
a12 = q1.answers.build(:text => "green", :response_class => "answer", :reference_identifier => 2, :question => q1)
|
13
|
+
a13 = q1.answers.build(:text => "blue", :response_class => "answer", :reference_identifier => 3, :question => q1)
|
14
|
+
a14 = q1.answers.build(:text => "Other", :response_class => "string", :reference_identifier => 4, :question => q1)
|
15
|
+
a15 = q1.answers.build(:text => "Omit", :reference_identifier => 5, :question => q1, :is_exclusive => true)
|
16
|
+
q2 = @section.questions.build(:text => "What is your name?", :reference_identifier => 2, :pick => :none)
|
17
|
+
a21 = q2.answers.build(:response_class => "string", :reference_identifier => 1, :question => q2)
|
18
|
+
Surveyor::Unparser.unparse(@survey).should ==
|
19
|
+
<<-dsl
|
20
|
+
survey "Simple survey", :description=>"very simple" do
|
21
|
+
section "Simple section" do
|
22
|
+
|
23
|
+
q_1 "What is your favorite color?", :pick=>"one"
|
24
|
+
a_1 "red"
|
25
|
+
a_2 "green"
|
26
|
+
a_3 "blue"
|
27
|
+
a_4 :other, :string
|
28
|
+
a_5 :omit
|
29
|
+
|
30
|
+
q_2 "What is your name?"
|
31
|
+
a_1 :string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
dsl
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should unparse groups" do
|
38
|
+
q3 = @section.questions.build(:text => "Happy?")
|
39
|
+
a31 = q3.answers.build(:text => "Yes", :question => q3)
|
40
|
+
a32 = q3.answers.build(:text => "Maybe", :question => q3)
|
41
|
+
a33 = q3.answers.build(:text => "No", :question => q3)
|
42
|
+
|
43
|
+
q4 = @section.questions.build(:text => "Energized?")
|
44
|
+
a41 = q4.answers.build(:text => "Yes", :question => q4)
|
45
|
+
a42 = q4.answers.build(:text => "Maybe", :question => q4)
|
46
|
+
a43 = q4.answers.build(:text => "No", :question => q4)
|
47
|
+
|
48
|
+
g1 = q3.build_question_group(:text => "How are you feeling?", :display_type => "grid")
|
49
|
+
q4.question_group = g1
|
50
|
+
g1.questions = [q3, q4]
|
51
|
+
|
52
|
+
q5 = @section.questions.build(:text => "Model")
|
53
|
+
a51 = q5.answers.build(:response_class => "string", :question => q3)
|
54
|
+
|
55
|
+
g2 = q5.build_question_group(:text => "Tell us about the cars you own", :display_type => "repeater")
|
56
|
+
g2.questions = [q5]
|
57
|
+
|
58
|
+
Surveyor::Unparser.unparse(@survey).should ==
|
59
|
+
<<-dsl
|
60
|
+
survey "Simple survey", :description=>"very simple" do
|
61
|
+
section "Simple section" do
|
62
|
+
|
63
|
+
grid "How are you feeling?" do
|
64
|
+
a "Yes"
|
65
|
+
a "Maybe"
|
66
|
+
a "No"
|
67
|
+
q "Happy?"
|
68
|
+
q "Energized?"
|
69
|
+
end
|
70
|
+
|
71
|
+
repeater "Tell us about the cars you own" do
|
72
|
+
q "Model"
|
73
|
+
a :string
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
dsl
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should unparse a basic survey, section, and question" do
|
81
|
+
q6 = @section.questions.build(:text => "What... is your name? (e.g. It is 'Arthur', King of the Britons)", :reference_identifier => "montypython3")
|
82
|
+
a61 = q6.answers.build(:response_class => "string", :reference_identifier => 1, :question => q6)
|
83
|
+
|
84
|
+
q7 = @section.questions.build(:text => "What... is your quest? (e.g. To seek the Holy Grail)", :display_type => "label")
|
85
|
+
d1 = q7.build_dependency(:rule => "A", :question => q7)
|
86
|
+
dc1 = d1.dependency_conditions.build(:dependency => d1, :question => q6, :answer => a61, :operator => "==", :string_value => "It is 'Arthur', King of the Britons", :rule_key => "A")
|
87
|
+
|
88
|
+
q8 = @section.questions.build(:text => "How many pets do you own?")
|
89
|
+
a81 = q8.answers.build(:response_class => "integer", :question => q8)
|
90
|
+
v1 = a81.validations.build(:rule => "A", :answer => a81)
|
91
|
+
vc1 = v1.validation_conditions.build(:operator => ">=", :integer_value => 0, :validation => v1, :rule_key => "A")
|
92
|
+
|
93
|
+
q9 = @section.questions.build(:text => "Pick your favorite date AND time", :custom_renderer => "/partials/custom_question")
|
94
|
+
a91 = q9.answers.build(:response_class => "datetime", :question => q9)
|
95
|
+
|
96
|
+
q10 = @section.questions.build(:text => "What time do you usually take a lunch break?", :reference_identifier => "time_lunch")
|
97
|
+
a101 = q10.answers.build(:response_class => "time", :reference_identifier => 1, :question => q10)
|
98
|
+
|
99
|
+
Surveyor::Unparser.unparse(@survey).should ==
|
100
|
+
<<-dsl
|
101
|
+
survey "Simple survey", :description=>"very simple" do
|
102
|
+
section "Simple section" do
|
103
|
+
|
104
|
+
q_montypython3 "What... is your name? (e.g. It is 'Arthur', King of the Britons)"
|
105
|
+
a_1 :string
|
106
|
+
|
107
|
+
label "What... is your quest? (e.g. To seek the Holy Grail)"
|
108
|
+
dependency :rule=>"A"
|
109
|
+
condition_A :q_montypython3, "==", {:string_value=>"It is 'Arthur', King of the Britons", :answer_reference=>"1"}
|
110
|
+
|
111
|
+
q "How many pets do you own?"
|
112
|
+
a :integer
|
113
|
+
validation :rule=>"A"
|
114
|
+
condition_A ">=", :integer_value=>0
|
115
|
+
|
116
|
+
q "Pick your favorite date AND time", :custom_renderer=>"/partials/custom_question"
|
117
|
+
a :datetime
|
118
|
+
|
119
|
+
q_time_lunch "What time do you usually take a lunch break?"
|
120
|
+
a_1 :time
|
121
|
+
end
|
122
|
+
end
|
123
|
+
dsl
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe Answer do
|
5
|
+
let(:answer){ Factory(:answer) }
|
6
|
+
|
7
|
+
context "when creating" do
|
8
|
+
it { answer.should be_valid }
|
9
|
+
it "deletes validation when deleted" do
|
10
|
+
v_id = Factory(:validation, :answer => answer).id
|
11
|
+
answer.destroy
|
12
|
+
Validation.find_by_id(v_id).should be_nil
|
13
|
+
end
|
14
|
+
it "protects #api_id" do
|
15
|
+
saved_attrs = answer.attributes
|
16
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
17
|
+
expect { answer.update_attributes(:api_id => "NEW") }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
18
|
+
else
|
19
|
+
answer.attributes = {:api_id => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
20
|
+
end
|
21
|
+
answer.attributes.should == saved_attrs
|
22
|
+
end
|
23
|
+
it "protects #created_at" do
|
24
|
+
saved_attrs = answer.attributes
|
25
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
26
|
+
expect { answer.update_attributes(:created_at => 3.days.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
27
|
+
else
|
28
|
+
answer.attributes = {:created_at => 3.days.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
29
|
+
end
|
30
|
+
answer.attributes.should == saved_attrs
|
31
|
+
end
|
32
|
+
it "protects #updated_at" do
|
33
|
+
saved_attrs = answer.attributes
|
34
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
35
|
+
expect { answer.update_attributes(:updated_at => 3.hours.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
36
|
+
else
|
37
|
+
answer.attributes = {:updated_at => 3.hours.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
38
|
+
end
|
39
|
+
answer.attributes.should == saved_attrs
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with mustache text substitution" do
|
44
|
+
require 'mustache'
|
45
|
+
let(:mustache_context){ Class.new(::Mustache){ def site; "Northwestern"; end; def foo; "bar"; end } }
|
46
|
+
it "subsitutes Mustache context variables" do
|
47
|
+
answer.text = "You are in {{site}}"
|
48
|
+
answer.in_context(answer.text, mustache_context).should == "You are in Northwestern"
|
49
|
+
answer.text_for(nil, mustache_context).should == "You are in Northwestern"
|
50
|
+
|
51
|
+
answer.help_text = "{{site}} is your site"
|
52
|
+
answer.in_context(answer.help_text, mustache_context).should == "Northwestern is your site"
|
53
|
+
answer.help_text_for(mustache_context).should == "Northwestern is your site"
|
54
|
+
|
55
|
+
answer.default_value = "{{site}}"
|
56
|
+
answer.in_context(answer.default_value, mustache_context).should == "Northwestern"
|
57
|
+
answer.default_value_for(mustache_context).should == "Northwestern"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with translations" do
|
62
|
+
require 'yaml'
|
63
|
+
let(:survey){ Factory(:survey) }
|
64
|
+
let(:survey_section){ Factory(:survey_section) }
|
65
|
+
let(:survey_translation){
|
66
|
+
Factory(:survey_translation, :locale => :es, :translation => {
|
67
|
+
:questions => {
|
68
|
+
:name => {
|
69
|
+
:answers => {
|
70
|
+
:name => {
|
71
|
+
:help_text => "Mi nombre es..."
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}.to_yaml)
|
77
|
+
}
|
78
|
+
let(:question){ Factory(:question, :reference_identifier => "name") }
|
79
|
+
before do
|
80
|
+
answer.reference_identifier = "name"
|
81
|
+
answer.help_text = "My name is..."
|
82
|
+
answer.text = nil
|
83
|
+
answer.question = question
|
84
|
+
question.survey_section = survey_section
|
85
|
+
survey_section.survey = survey
|
86
|
+
survey.translations << survey_translation
|
87
|
+
end
|
88
|
+
it "returns its own translation" do
|
89
|
+
answer.translation(:es)[:help_text].should == "Mi nombre es..."
|
90
|
+
end
|
91
|
+
it "returns translations in views" do
|
92
|
+
answer.help_text_for(nil, :es).should == "Mi nombre es..."
|
93
|
+
end
|
94
|
+
it "returns its own default values" do
|
95
|
+
answer.translation(:de).should == {"text" => nil, "help_text" => "My name is...", "default_value" => nil}
|
96
|
+
end
|
97
|
+
it "returns default values in views" do
|
98
|
+
answer.help_text_for(nil, :de).should == "My name is..."
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "handling strings" do
|
103
|
+
it "#split preserves strings" do
|
104
|
+
answer.split(answer.text).should == "My favorite color is clear"
|
105
|
+
end
|
106
|
+
it "#split(:pre) preserves strings" do
|
107
|
+
answer.split(answer.text, :pre).should == "My favorite color is clear"
|
108
|
+
end
|
109
|
+
it "#split(:post) preserves strings" do
|
110
|
+
answer.split(answer.text, :post).should == ""
|
111
|
+
end
|
112
|
+
it "#split splits strings" do
|
113
|
+
answer.text = "before|after|extra"
|
114
|
+
answer.split(answer.text).should == "before|after|extra"
|
115
|
+
end
|
116
|
+
it "#split(:pre) splits strings" do
|
117
|
+
answer.text = "before|after|extra"
|
118
|
+
answer.split(answer.text, :pre).should == "before"
|
119
|
+
end
|
120
|
+
it "#split(:post) splits strings" do
|
121
|
+
answer.text = "before|after|extra"
|
122
|
+
answer.split(answer.text, :post).should == "after|extra"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "for views" do
|
127
|
+
let(:asset_directory){ asset_pipeline_enabled? ? "assets" : "images" }
|
128
|
+
before do
|
129
|
+
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
|
130
|
+
end
|
131
|
+
it "#text_for with #display_type == image" do
|
132
|
+
answer.text = "rails.png"
|
133
|
+
answer.display_type = :image
|
134
|
+
answer.text_for.should == %(<img alt="Rails" src="/#{asset_directory}/rails.png" />)
|
135
|
+
end
|
136
|
+
it "#text_for with #display_type == hidden_label" do
|
137
|
+
answer.text = "Red"
|
138
|
+
answer.text_for.should == "Red"
|
139
|
+
answer.display_type = "hidden_label"
|
140
|
+
answer.text_for.should == ""
|
141
|
+
end
|
142
|
+
it "#default_value_for"
|
143
|
+
it "#help_text_for"
|
144
|
+
it "reports DOM ready #css_class from #custom_class" do
|
145
|
+
answer.custom_class = "foo bar"
|
146
|
+
answer.css_class.should == "foo bar"
|
147
|
+
end
|
148
|
+
it "reports DOM ready #css_class from #custom_class and #is_exclusive" do
|
149
|
+
answer.custom_class = "foo bar"
|
150
|
+
answer.is_exclusive = true
|
151
|
+
answer.css_class.should == "exclusive foo bar"
|
152
|
+
end
|
153
|
+
it "#text_for preserves strings" do
|
154
|
+
answer.text_for.should == "My favorite color is clear"
|
155
|
+
end
|
156
|
+
it "#text_for(:pre) preserves strings" do
|
157
|
+
answer.text_for(:pre).should == "My favorite color is clear"
|
158
|
+
end
|
159
|
+
it "#text_for(:post) preserves strings" do
|
160
|
+
answer.text_for(:post).should == ""
|
161
|
+
end
|
162
|
+
it "#text_for splits strings" do
|
163
|
+
answer.text = "before|after|extra"
|
164
|
+
answer.text_for.should == "before|after|extra"
|
165
|
+
end
|
166
|
+
it "#text_for(:pre) splits strings" do
|
167
|
+
answer.text = "before|after|extra"
|
168
|
+
answer.text_for(:pre).should == "before"
|
169
|
+
end
|
170
|
+
it "#text_for(:post) splits strings" do
|
171
|
+
answer.text = "before|after|extra"
|
172
|
+
answer.text_for(:post).should == "after|extra"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|