surveyor 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +26 -0
- data/README.md +67 -168
- data/app/models/survey_translation.rb +5 -0
- data/app/views/partials/_answer.html.haml +9 -5
- data/app/views/partials/_question.html.haml +3 -3
- data/app/views/partials/_question_group.html.haml +9 -8
- data/app/views/partials/_section.html.haml +1 -1
- data/app/views/surveyor/edit.html.haml +3 -3
- data/app/views/surveyor/export.json.rabl +12 -8
- data/app/views/surveyor/new.html.haml +9 -14
- data/app/views/surveyor/show.html.haml +2 -2
- data/doc/surveyor_models.png +0 -0
- data/doc/surveyor_models2.png +0 -0
- data/features/export_to_json.feature +97 -1
- data/features/internationalization.feature +55 -0
- data/features/step_definitions/parser_steps.rb +7 -0
- data/features/step_definitions/surveyor_steps.rb +43 -6
- data/features/step_definitions/ui_steps.rb +22 -0
- data/features/support/env.rb +2 -0
- data/features/support/hooks.rb +4 -0
- data/features/surveyor.feature +117 -1
- data/features/surveyor_dependencies.feature +56 -2
- data/features/surveyor_parser.feature +10 -10
- 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_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_ef8c08_256x240.png → ui-icons_222222_256x240.png} +0 -0
- data/lib/assets/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/assets/images/{ui-icons_ffffff_256x240.png → 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 +1795 -1153
- data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
- data/lib/assets/javascripts/surveyor/jquery.surveyor.js +8 -0
- data/lib/assets/stylesheets/surveyor.sass +2 -2
- data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
- data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +7 -2
- data/lib/assets/stylesheets/surveyor/reset.css +24 -26
- data/lib/generators/surveyor/install_generator.rb +4 -0
- data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +4 -3
- data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +2 -2
- data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +1 -1
- data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +18 -0
- data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
- data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
- data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +5 -0
- data/lib/generators/surveyor/templates/surveys/languages.rb +10 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +14 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +14 -0
- data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +14 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +4 -8
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +22 -26
- data/lib/surveyor/models/answer_methods.rb +41 -10
- data/lib/surveyor/models/question_group_methods.rb +17 -3
- data/lib/surveyor/models/question_methods.rb +32 -5
- data/lib/surveyor/models/response_methods.rb +7 -7
- data/lib/surveyor/models/survey_methods.rb +20 -4
- data/lib/surveyor/models/survey_section_methods.rb +10 -5
- data/lib/surveyor/models/survey_translation_methods.rb +33 -0
- data/lib/surveyor/mustache_context.rb +11 -0
- data/lib/surveyor/parser.rb +15 -2
- data/lib/surveyor/surveyor_controller_methods.rb +19 -17
- data/lib/surveyor/version.rb +1 -1
- data/spec/controllers/surveyor_controller_spec.rb +3 -3
- data/spec/factories.rb +21 -7
- data/spec/helpers/formtastic_custom_input_spec.rb +2 -3
- data/spec/helpers/surveyor_helper_spec.rb +64 -100
- data/spec/models/answer_spec.rb +166 -58
- data/spec/models/question_group_spec.rb +84 -38
- data/spec/models/question_spec.rb +188 -116
- data/spec/models/survey_section_spec.rb +77 -40
- data/spec/models/survey_spec.rb +176 -145
- data/spec/spec_helper.rb +3 -0
- data/stacktests.sh +52 -0
- metadata +36 -18
- data/lib/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/lib/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/lib/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/lib/assets/javascripts/surveyor/jquery-ui.js +0 -11729
- data/lib/assets/javascripts/surveyor/jquery.tools.min.js +0 -204
- data/lib/assets/stylesheets/surveyor/dateinput.css +0 -149
- data/lib/assets/stylesheets/surveyor/jquery-ui.custom.css +0 -572
- data/lib/surveyor/render_text.rb +0 -23
- data/lib/surveyor/surveyor_admin_controller_methods.rb +0 -55
@@ -21,12 +21,12 @@ describe SurveyorController do
|
|
21
21
|
response.should render_template('new')
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "assigns surveys_by_access_code to surveys grouped by access_code" do
|
25
25
|
original = Factory(:survey, :title => "Foo", :access_code => 'foo')
|
26
26
|
supplant = Factory(:survey, :title => "Foo", :access_code => 'foo', :survey_version => 1)
|
27
|
-
hash = {"foo"=>
|
27
|
+
hash = {"foo"=>[supplant, original]}
|
28
28
|
do_get
|
29
|
-
assigns(:
|
29
|
+
assigns(:surveys_by_access_code).should eq hash
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/spec/factories.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# http://github.com/thoughtbot/factory_girl/tree/master
|
2
3
|
require 'rubygems'
|
3
4
|
require 'factory_girl'
|
@@ -5,13 +6,26 @@ require 'factory_girl'
|
|
5
6
|
Factory.sequence(:unique_survey_access_code){|n| "simple survey #{UUIDTools::UUID.random_create.to_s}" }
|
6
7
|
|
7
8
|
Factory.define :survey do |s|
|
8
|
-
s.title
|
9
|
-
s.description
|
10
|
-
s.access_code {Factory.next :unique_survey_access_code}
|
11
|
-
s.
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
s.title "Simple survey"
|
10
|
+
s.description "A simple survey for testing"
|
11
|
+
s.access_code { Factory.next :unique_survey_access_code }
|
12
|
+
s.survey_version 0
|
13
|
+
end
|
14
|
+
|
15
|
+
Factory.define :survey_translation do |t|
|
16
|
+
t.locale "es"
|
17
|
+
t.translation %(title: "Un idioma nunca es suficiente"
|
18
|
+
survey_sections:
|
19
|
+
one:
|
20
|
+
title: "Uno"
|
21
|
+
questions:
|
22
|
+
hello:
|
23
|
+
text: "¡Hola!"
|
24
|
+
name:
|
25
|
+
text: "¿Cómo se llama Usted?"
|
26
|
+
answers:
|
27
|
+
name:
|
28
|
+
help_text: "Mi nombre es...")
|
15
29
|
end
|
16
30
|
|
17
31
|
Factory.sequence(:survey_section_display_order){|n| n }
|
@@ -5,12 +5,11 @@ describe Surveyor::Helpers::FormtasticCustomInput do
|
|
5
5
|
context "input helpers" do
|
6
6
|
it "should translate response class into attribute" do
|
7
7
|
helper.response_class_to_method(:string).should == :string_value
|
8
|
-
helper.response_class_to_method(:other_and_string).should == :string_value
|
9
8
|
helper.response_class_to_method(:integer).should == :integer_value
|
10
9
|
helper.response_class_to_method(:float).should == :float_value
|
11
10
|
helper.response_class_to_method(:datetime).should == :datetime_value
|
12
|
-
helper.response_class_to_method(:date).should == :
|
13
|
-
helper.response_class_to_method(:time).should == :
|
11
|
+
helper.response_class_to_method(:date).should == :date_value
|
12
|
+
helper.response_class_to_method(:time).should == :time_value
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -1,110 +1,77 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe SurveyorHelper do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it "should return the question text with number" do
|
9
|
-
q1 = Factory(:question)
|
10
|
-
q2 = Factory(:question, :display_type => "label")
|
11
|
-
q3 = Factory(:question, :dependency => Factory(:dependency))
|
12
|
-
q4 = Factory(:question, :display_type => "image", :text => "something.jpg")
|
13
|
-
q5 = Factory(:question, :question_group => Factory(:question_group))
|
14
|
-
helper.q_text(q1).should == "<span class='qnum'>1) </span>#{q1.text}"
|
15
|
-
helper.q_text(q2).should == q2.text
|
16
|
-
helper.q_text(q3).should == q3.text
|
17
|
-
|
18
|
-
dir = "images"
|
19
|
-
if Rails.application.config.respond_to?(:assets) && Rails.application.config.assets
|
20
|
-
dir = "assets"
|
21
|
-
end
|
22
|
-
|
23
|
-
helper.q_text(q4).should == %Q(<img alt="Something" src="/#{dir}/something.jpg" />)
|
24
|
-
helper.q_text(q5).should == q5.text
|
25
|
-
end
|
26
|
-
require 'mustache'
|
27
|
-
class FakeMustacheContext < ::Mustache
|
28
|
-
def site
|
29
|
-
"Northwestern"
|
4
|
+
context "numbering" do
|
5
|
+
let(:asset_directory){ asset_pipeline_enabled? ? "assets" : "images" }
|
6
|
+
before do
|
7
|
+
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
|
30
8
|
end
|
31
|
-
|
32
|
-
|
9
|
+
it "should return the question text with number, except for labels, dependencies, images, and grouped questions" do
|
10
|
+
q1 = Factory(:question)
|
11
|
+
q2 = Factory(:question, :display_type => "label")
|
12
|
+
q3 = Factory(:question, :dependency => Factory(:dependency))
|
13
|
+
q4 = Factory(:question, :display_type => "image", :text => "something.jpg")
|
14
|
+
q5 = Factory(:question, :question_group => Factory(:question_group))
|
15
|
+
helper.q_text(q1).should == "<span class='qnum'>1) </span>#{q1.text}"
|
16
|
+
helper.q_text(q2).should == q2.text
|
17
|
+
helper.q_text(q3).should == q3.text
|
18
|
+
helper.q_text(q4).should == %Q(<img alt="Something" src="/#{asset_directory}/something.jpg" />)
|
19
|
+
helper.q_text(q5).should == q5.text
|
33
20
|
end
|
34
|
-
|
35
|
-
def group
|
36
|
-
"NUBIC"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
it "should return text with with substituted value" do
|
40
|
-
q1 = Factory(:question, :text => "You are in {{site}}")
|
41
|
-
label = Factory(:question, :display_type => "label", :text => "Testing {{somethingElse}}")
|
42
|
-
helper.q_text(q1, FakeMustacheContext).should == "<span class='qnum'>1) </span>You are in Northwestern"
|
43
|
-
helper.q_text(label, FakeMustacheContext).should == "Testing something new"
|
44
|
-
end
|
45
|
-
it "should return help_text for question with substituted value" do
|
46
|
-
q2 = Factory(:question, :display_type => "label", :text => "Is you site Northwestern?", :help_text => "If your site is not {{site}}, pick 'no' for the answer")
|
47
|
-
helper.render_help_text(q2, FakeMustacheContext).should == "If your site is not Northwestern, pick 'no' for the answer"
|
48
|
-
end
|
49
|
-
it "should return help_text for group text with number" do
|
50
|
-
g1 = Factory(:question_group, :text => "You are part of the {{group}}")
|
51
|
-
helper.q_text(g1, FakeMustacheContext).should == "<span class='qnum'>1) </span>You are part of the NUBIC"
|
52
|
-
end
|
53
|
-
it "should return help_text for group text" do
|
54
|
-
g1 = Factory(:question_group, :text => "You are part of the {{group}}", :help_text => "Make sure you know what the {{group}} stands for")
|
55
|
-
helper.render_help_text(g1, FakeMustacheContext).should == "Make sure you know what the NUBIC stands for"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return rendered text for answer" do
|
59
|
-
q1 = Factory(:question, :text => "Do you work for {{site}}", :answers => [a1 = Factory(:answer, :text => "No, I don't work for {{site}}"), a2 = Factory(:answer, :text => "Yes, I do work for {{site}}") ])
|
60
|
-
helper.a_text(a1, nil, FakeMustacheContext).should == "No, I don't work for Northwestern"
|
61
|
-
helper.a_text(a2, nil, FakeMustacheContext).should == "Yes, I do work for Northwestern"
|
62
21
|
end
|
63
22
|
|
64
|
-
|
65
|
-
|
66
|
-
|
23
|
+
context "with mustache text substitution" do
|
24
|
+
require 'mustache'
|
25
|
+
let(:mustache_context){ Class.new(::Mustache){ def site; "Northwestern"; end; def somethingElse; "something new"; end; def group; "NUBIC"; end } }
|
26
|
+
it "substitues values into Question#text" do
|
27
|
+
q1 = Factory(:question, :text => "You are in {{site}}")
|
28
|
+
label = Factory(:question, :display_type => "label", :text => "Testing {{somethingElse}}")
|
29
|
+
helper.q_text(q1, mustache_context).should == "<span class='qnum'>1) </span>You are in Northwestern"
|
30
|
+
helper.q_text(label, mustache_context).should == "Testing something new"
|
31
|
+
end
|
67
32
|
end
|
68
33
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
34
|
+
context "response methods" do
|
35
|
+
it "should find or create responses, with index" do
|
36
|
+
q1 = Factory(:question, :answers => [a = Factory(:answer, :text => "different")])
|
37
|
+
q2 = Factory(:question, :answers => [b = Factory(:answer, :text => "strokes")])
|
38
|
+
q3 = Factory(:question, :answers => [c = Factory(:answer, :text => "folks")])
|
39
|
+
rs = Factory(:response_set, :responses => [r1 = Factory(:response, :question => q1, :answer => a), r3 = Factory(:response, :question => q3, :answer => c, :response_group => 1)])
|
40
|
+
|
41
|
+
helper.response_for(rs, nil).should == nil
|
42
|
+
helper.response_for(nil, q1).should == nil
|
43
|
+
helper.response_for(rs, q1).should == r1
|
44
|
+
helper.response_for(rs, q1, a).should == r1
|
45
|
+
helper.response_for(rs, q2).attributes.reject{|k,v| k == "api_id"}.should == Response.new(:question => q2, :response_set => rs).attributes.reject{|k,v| k == "api_id"}
|
46
|
+
helper.response_for(rs, q2, b).attributes.reject{|k,v| k == "api_id"}.should == Response.new(:question => q2, :response_set => rs).attributes.reject{|k,v| k == "api_id"}
|
47
|
+
helper.response_for(rs, q3, c, "1").should == r3
|
74
48
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
helper.rc_to_attr(:string).should == :string_value
|
92
|
-
helper.rc_to_attr(:text).should == :text_value
|
93
|
-
helper.rc_to_attr(:integer).should == :integer_value
|
94
|
-
helper.rc_to_attr(:float).should == :float_value
|
95
|
-
helper.rc_to_attr(:datetime).should == :datetime_value
|
96
|
-
helper.rc_to_attr(:date).should == :date_value
|
97
|
-
helper.rc_to_attr(:time).should == :time_value
|
98
|
-
end
|
49
|
+
end
|
50
|
+
it "should keep an index of responses" do
|
51
|
+
helper.response_idx.should == "1"
|
52
|
+
helper.response_idx.should == "2"
|
53
|
+
helper.response_idx(false).should == "2"
|
54
|
+
helper.response_idx.should == "3"
|
55
|
+
end
|
56
|
+
it "should translate response class into attribute" do
|
57
|
+
helper.rc_to_attr(:string).should == :string_value
|
58
|
+
helper.rc_to_attr(:text).should == :text_value
|
59
|
+
helper.rc_to_attr(:integer).should == :integer_value
|
60
|
+
helper.rc_to_attr(:float).should == :float_value
|
61
|
+
helper.rc_to_attr(:datetime).should == :datetime_value
|
62
|
+
helper.rc_to_attr(:date).should == :date_value
|
63
|
+
helper.rc_to_attr(:time).should == :time_value
|
64
|
+
end
|
99
65
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
66
|
+
it "should translate response class into as" do
|
67
|
+
helper.rc_to_as(:string).should == :string
|
68
|
+
helper.rc_to_as(:text).should == :text
|
69
|
+
helper.rc_to_as(:integer).should == :string
|
70
|
+
helper.rc_to_as(:float).should == :string
|
71
|
+
helper.rc_to_as(:datetime).should == :string
|
72
|
+
helper.rc_to_as(:date).should == :string
|
73
|
+
helper.rc_to_as(:time).should == :string
|
74
|
+
end
|
108
75
|
end
|
109
76
|
|
110
77
|
context "overriding methods" do
|
@@ -121,7 +88,6 @@ describe SurveyorHelper do
|
|
121
88
|
end
|
122
89
|
end
|
123
90
|
end
|
124
|
-
|
125
91
|
it "should translate response class into as" do
|
126
92
|
helper.rc_to_as(:string).should == :string
|
127
93
|
helper.rc_to_as(:text).should == :text
|
@@ -131,7 +97,6 @@ describe SurveyorHelper do
|
|
131
97
|
helper.rc_to_as(:date).should == :date # not string
|
132
98
|
helper.rc_to_as(:time).should == :time
|
133
99
|
end
|
134
|
-
|
135
100
|
after do
|
136
101
|
module SurveyorHelper
|
137
102
|
include Surveyor::Helpers::SurveyorHelperMethods
|
@@ -142,7 +107,7 @@ describe SurveyorHelper do
|
|
142
107
|
end
|
143
108
|
end
|
144
109
|
|
145
|
-
#
|
110
|
+
# run this context after 'overriding methods'
|
146
111
|
context "post override test" do
|
147
112
|
# Sanity check
|
148
113
|
it "should translate response class into as after override" do
|
@@ -150,5 +115,4 @@ describe SurveyorHelper do
|
|
150
115
|
helper.rc_to_as(:date).should == :string # back to string
|
151
116
|
end
|
152
117
|
end
|
153
|
-
|
154
118
|
end
|
data/spec/models/answer_spec.rb
CHANGED
@@ -1,67 +1,175 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
|
-
describe Answer
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
39
41
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
59
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
55
100
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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"
|
61
123
|
end
|
62
124
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
66
174
|
end
|
67
175
|
end
|