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
@@ -1,47 +1,93 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
4
|
describe QuestionGroup do
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
let(:question_group){ Factory(:question_group) }
|
6
|
+
let(:dependency){ Factory(:dependency) }
|
7
|
+
let(:response_set){ Factory(:response_set) }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@question_group.css_class(Factory(:response_set)).should == "g_dependent"
|
9
|
+
context "when creating" do
|
10
|
+
it { question_group.should be_valid }
|
11
|
+
it "#display_type = inline by default" do
|
12
|
+
question_group.display_type = "inline"
|
13
|
+
question_group.renderer.should == :inline
|
14
|
+
end
|
15
|
+
it "#renderer == 'default' when #display_type = nil" do
|
16
|
+
question_group.display_type = nil
|
17
|
+
question_group.renderer.should == :default
|
18
|
+
end
|
19
|
+
it "interprets symbolizes #display_type to #renderer" do
|
20
|
+
question_group.display_type = "foo"
|
21
|
+
question_group.renderer.should == :foo
|
22
|
+
end
|
23
|
+
it "reports DOM ready #css_class based on dependencies" do
|
24
|
+
question_group.dependency = dependency
|
25
|
+
dependency.should_receive(:is_met?).and_return(true)
|
26
|
+
question_group.css_class(response_set).should == "g_dependent"
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
dependency.should_receive(:is_met?).and_return(false)
|
29
|
+
question_group.css_class(response_set).should == "g_dependent g_hidden"
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
question_group.custom_class = "foo bar"
|
32
|
+
dependency.should_receive(:is_met?).and_return(false)
|
33
|
+
question_group.css_class(response_set).should == "g_dependent g_hidden foo bar"
|
34
|
+
end
|
35
|
+
it "protects #api_id" do
|
36
|
+
saved_attrs = question_group.attributes
|
37
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
38
|
+
expect { question_group.update_attributes(:api_id => "NEW") }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
39
|
+
else
|
40
|
+
question_group.attributes = {:api_id => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
41
|
+
end
|
42
|
+
question_group.attributes.should == saved_attrs
|
43
|
+
end
|
44
|
+
it "protects #created_at" do
|
45
|
+
saved_attrs = question_group.attributes
|
46
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
47
|
+
expect { question_group.update_attributes(:created_at => 3.days.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
48
|
+
else
|
49
|
+
question_group.attributes = {:created_at => 3.days.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
50
|
+
end
|
51
|
+
question_group.attributes.should == saved_attrs
|
52
|
+
end
|
53
|
+
it "protects #updated_at" do
|
54
|
+
saved_attrs = question_group.attributes
|
55
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
56
|
+
expect { question_group.update_attributes(:updated_at => 3.hours.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
57
|
+
else
|
58
|
+
question_group.attributes = {:updated_at => 3.hours.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
59
|
+
end
|
60
|
+
question_group.attributes.should == saved_attrs
|
61
|
+
end
|
34
62
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
63
|
+
|
64
|
+
context "with translations" do
|
65
|
+
require 'yaml'
|
66
|
+
let(:survey){ Factory(:survey) }
|
67
|
+
let(:survey_section){ Factory(:survey_section) }
|
68
|
+
let(:survey_translation){
|
69
|
+
Factory(:survey_translation, :locale => :es, :translation => {
|
70
|
+
:question_groups => {
|
71
|
+
:goodbye => {
|
72
|
+
:text => "¡Adios!"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}.to_yaml)
|
76
|
+
}
|
77
|
+
let(:question){ Factory(:question) }
|
78
|
+
before do
|
79
|
+
question_group.text = "Goodbye"
|
80
|
+
question_group.reference_identifier = "goodbye"
|
81
|
+
question_group.questions = [question]
|
82
|
+
question.survey_section = survey_section
|
83
|
+
survey_section.survey = survey
|
84
|
+
survey.translations << survey_translation
|
85
|
+
end
|
86
|
+
it "returns its own translation" do
|
87
|
+
question_group.translation(:es)[:text].should == "¡Adios!"
|
88
|
+
end
|
89
|
+
it "returns its own default values" do
|
90
|
+
question_group.translation(:de).should == {"text" => "Goodbye", "help_text" => nil}
|
91
|
+
end
|
45
92
|
end
|
46
|
-
|
47
93
|
end
|
@@ -1,135 +1,207 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
|
-
describe Question
|
4
|
-
|
5
|
-
@ss = mock_model(SurveySection)
|
6
|
-
@question = Question.new(:text => "What is your favorite color?", :survey_section => @ss, :is_mandatory => false, :display_order => 1)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should be invalid without text" do
|
10
|
-
@question.text = nil
|
11
|
-
@question.should have(1).error_on(:text)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should have a parent survey section" do
|
15
|
-
# this causes issues with building and saving
|
16
|
-
# @question.survey_section = nil
|
17
|
-
# @question.should have(1).error_on(:survey_section_id)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should not be mandatory by default" do
|
21
|
-
@question.mandatory?.should be_false
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should convert pick attribute to string" do
|
25
|
-
@question.pick.should == "none"
|
26
|
-
@question.pick = :one
|
27
|
-
@question.pick.should == "one"
|
28
|
-
@question.pick = nil
|
29
|
-
@question.pick.should == nil
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should split the text" do
|
33
|
-
@question.split_text.should == "What is your favorite color?"
|
34
|
-
@question.split_text(:pre).should == "What is your favorite color?"
|
35
|
-
@question.split_text(:post).should == ""
|
36
|
-
@question.text = "before|after|extra"
|
37
|
-
@question.split_text.should == "before|after|extra"
|
38
|
-
@question.split_text(:pre).should == "before"
|
39
|
-
@question.split_text(:post).should == "after|extra"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should have an api_id" do
|
43
|
-
@question.api_id.length.should == 36
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should protect api_id, timestamps" do
|
47
|
-
saved_attrs = @question.attributes
|
48
|
-
if defined? ActiveModel::MassAssignmentSecurity::Error
|
49
|
-
lambda {@question.update_attributes(:created_at => 3.days.ago, :updated_at => 3.hours.ago)}.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
50
|
-
lambda {@question.update_attributes(:api_id => "NEW")}.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
51
|
-
else
|
52
|
-
@question.attributes = {:created_at => 3.days.ago, :updated_at => 3.hours.ago} # automatically protected by Rails
|
53
|
-
@question.attributes = {:api_id => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
54
|
-
end
|
55
|
-
@question.attributes.should == saved_attrs
|
56
|
-
end
|
57
|
-
end
|
4
|
+
describe Question do
|
5
|
+
let(:question){ Factory(:question) }
|
58
6
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
7
|
+
context "when creating" do
|
8
|
+
it "is invalid without #text" do
|
9
|
+
question.text = nil
|
10
|
+
question.should have(1).error_on :text
|
11
|
+
end
|
12
|
+
it "#is_mandantory == false by default" do
|
13
|
+
question.mandatory?.should be_false
|
14
|
+
end
|
15
|
+
it "converts #pick to string" do
|
16
|
+
question.pick.should == "none"
|
17
|
+
question.pick = :one
|
18
|
+
question.pick.should == "one"
|
19
|
+
question.pick = nil
|
20
|
+
question.pick.should == nil
|
21
|
+
end
|
22
|
+
it "#renderer == 'default' when #display_type = nil" do
|
23
|
+
question.display_type = nil
|
24
|
+
question.renderer.should == :default
|
25
|
+
end
|
26
|
+
it "has #api_id with 36 characters by default" do
|
27
|
+
question.api_id.length.should == 36
|
28
|
+
end
|
29
|
+
it "#part_of_group? and #solo? are aware of question groups" do
|
30
|
+
question.question_group = Factory(:question_group)
|
31
|
+
question.solo?.should be_false
|
32
|
+
question.part_of_group?.should be_true
|
33
|
+
|
34
|
+
question.question_group = nil
|
35
|
+
question.solo?.should be_true
|
36
|
+
question.part_of_group?.should be_false
|
37
|
+
end
|
38
|
+
it "protects #api_id" do
|
39
|
+
saved_attrs = question.attributes
|
40
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
41
|
+
expect { question.update_attributes(:api_id => "NEW") }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
42
|
+
else
|
43
|
+
question.attributes = {:api_id => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
44
|
+
end
|
45
|
+
question.attributes.should == saved_attrs
|
46
|
+
end
|
47
|
+
it "protects #created_at" do
|
48
|
+
saved_attrs = question.attributes
|
49
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
50
|
+
expect { question.update_attributes(:created_at => 3.days.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
51
|
+
else
|
52
|
+
question.attributes = {:created_at => 3.days.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
53
|
+
end
|
54
|
+
question.attributes.should == saved_attrs
|
55
|
+
end
|
56
|
+
it "protects #updated_at" do
|
57
|
+
saved_attrs = question.attributes
|
58
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
59
|
+
expect { question.update_attributes(:updated_at => 3.hours.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
60
|
+
else
|
61
|
+
question.attributes = {:updated_at => 3.hours.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
62
|
+
end
|
63
|
+
question.attributes.should == saved_attrs
|
64
|
+
end
|
78
65
|
end
|
79
|
-
end
|
80
66
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
67
|
+
context "with answers" do
|
68
|
+
let(:answer_1){ Factory(:answer, :question => question, :display_order => 3, :text => "blue")}
|
69
|
+
let(:answer_2){ Factory(:answer, :question => question, :display_order => 1, :text => "red")}
|
70
|
+
let(:answer_3){ Factory(:answer, :question => question, :display_order => 2, :text => "green")}
|
71
|
+
before do
|
72
|
+
[answer_1, answer_2, answer_3].each{|a| question.answers << a }
|
73
|
+
end
|
74
|
+
it{ question.should have(3).answers}
|
75
|
+
it "gets answers in order" do
|
76
|
+
question.answers.should == [answer_2, answer_3, answer_1]
|
77
|
+
question.answers.map(&:display_order).should == [1,2,3]
|
78
|
+
end
|
79
|
+
it "deletes child answers when deleted" do
|
80
|
+
answer_ids = question.answers.map(&:id)
|
81
|
+
question.destroy
|
82
|
+
answer_ids.each{|id| Answer.find_by_id(id).should be_nil}
|
83
|
+
end
|
85
84
|
end
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
context "with dependencies" do
|
87
|
+
let(:response_set){ Factory(:response_set) }
|
88
|
+
let(:dependency){ Factory(:dependency) }
|
89
|
+
before do
|
90
|
+
question.dependency = dependency
|
91
|
+
dependency.stub!(:is_met?).with(response_set).and_return true
|
92
|
+
end
|
93
|
+
it "checks its dependency" do
|
94
|
+
question.triggered?(response_set).should be_true
|
95
|
+
end
|
96
|
+
it "deletes its dependency when deleted" do
|
97
|
+
d_id = question.dependency.id
|
98
|
+
question.destroy
|
99
|
+
Dependency.find_by_id(d_id).should be_nil
|
100
|
+
end
|
90
101
|
end
|
91
102
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
103
|
+
context "with mustache text substitution" do
|
104
|
+
require 'mustache'
|
105
|
+
let(:mustache_context){ Class.new(::Mustache){ def site; "Northwestern"; end; def foo; "bar"; end } }
|
106
|
+
it "subsitutes Mustache context variables" do
|
107
|
+
question.text = "You are in {{site}}"
|
108
|
+
question.in_context(question.text, mustache_context).should == "You are in Northwestern"
|
109
|
+
end
|
110
|
+
it "substitues in views" do
|
111
|
+
question.text = "You are in {{site}}"
|
112
|
+
question.text_for(nil, mustache_context).should == "You are in Northwestern"
|
113
|
+
end
|
99
114
|
end
|
100
115
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
116
|
+
context "with translations" do
|
117
|
+
require 'yaml'
|
118
|
+
let(:survey){ Factory(:survey) }
|
119
|
+
let(:survey_section){ Factory(:survey_section) }
|
120
|
+
let(:survey_translation){
|
121
|
+
Factory(:survey_translation, :locale => :es, :translation => {
|
122
|
+
:questions => {
|
123
|
+
:hello => {
|
124
|
+
:text => "¡Hola!"
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}.to_yaml)
|
128
|
+
}
|
129
|
+
before do
|
130
|
+
question.reference_identifier = "hello"
|
131
|
+
question.survey_section = survey_section
|
132
|
+
survey_section.survey = survey
|
133
|
+
survey.translations << survey_translation
|
105
134
|
end
|
106
|
-
|
107
|
-
|
135
|
+
it "returns its own translation" do
|
136
|
+
YAML.load(survey_translation.translation).should_not be_nil
|
137
|
+
question.translation(:es)[:text].should == "¡Hola!"
|
138
|
+
end
|
139
|
+
it "returns its own default values" do
|
140
|
+
question.translation(:de).should == {"text" => question.text, "help_text" => question.help_text}
|
141
|
+
end
|
142
|
+
it "returns translations in views" do
|
143
|
+
question.text_for(nil, nil, :es).should == "¡Hola!"
|
144
|
+
end
|
145
|
+
it "returns default values in views" do
|
146
|
+
question.text_for(nil, nil, :de).should == question.text
|
108
147
|
end
|
109
148
|
end
|
110
|
-
it "should substitute 'Northwestern' in place {{site}}" do
|
111
|
-
@question.text = "You are in {{site}}"
|
112
|
-
@question.render_question_text(FakeMustacheContext).should == "You are in Northwestern"
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
149
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
150
|
+
context "handling strings" do
|
151
|
+
it "#split preserves strings" do
|
152
|
+
question.split(question.text).should == "What is your favorite color?"
|
153
|
+
end
|
154
|
+
it "#split(:pre) preserves strings" do
|
155
|
+
question.split(question.text, :pre).should == "What is your favorite color?"
|
156
|
+
end
|
157
|
+
it "#split(:post) preserves strings" do
|
158
|
+
question.split(question.text, :post).should == ""
|
159
|
+
end
|
160
|
+
it "#split splits strings" do
|
161
|
+
question.text = "before|after|extra"
|
162
|
+
question.split(question.text).should == "before|after|extra"
|
163
|
+
end
|
164
|
+
it "#split(:pre) splits strings" do
|
165
|
+
question.text = "before|after|extra"
|
166
|
+
question.split(question.text, :pre).should == "before"
|
167
|
+
end
|
168
|
+
it "#split(:post) splits strings" do
|
169
|
+
question.text = "before|after|extra"
|
170
|
+
question.split(question.text, :post).should == "after|extra"
|
171
|
+
end
|
121
172
|
end
|
122
173
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
174
|
+
context "for views" do
|
175
|
+
let(:asset_directory){ asset_pipeline_enabled? ? "assets" : "images" }
|
176
|
+
before do
|
177
|
+
ActionController::Base.helpers.config.assets_dir = "public" unless asset_pipeline_enabled?
|
178
|
+
end
|
179
|
+
it "#text_for with #display_type == image" do
|
180
|
+
question.text = "rails.png"
|
181
|
+
question.display_type = :image
|
182
|
+
question.text_for.should == %(<img alt="Rails" src="/#{asset_directory}/rails.png" />)
|
183
|
+
end
|
184
|
+
it "#help_text_for"
|
185
|
+
it "#text_for preserves strings" do
|
186
|
+
question.text_for.should == "What is your favorite color?"
|
187
|
+
end
|
188
|
+
it "#text_for(:pre) preserves strings" do
|
189
|
+
question.text_for(:pre).should == "What is your favorite color?"
|
190
|
+
end
|
191
|
+
it "#text_for(:post) preserves strings" do
|
192
|
+
question.text_for(:post).should == ""
|
193
|
+
end
|
194
|
+
it "#text_for splits strings" do
|
195
|
+
question.text = "before|after|extra"
|
196
|
+
question.text_for.should == "before|after|extra"
|
197
|
+
end
|
198
|
+
it "#text_for(:pre) splits strings" do
|
199
|
+
question.text = "before|after|extra"
|
200
|
+
question.text_for(:pre).should == "before"
|
201
|
+
end
|
202
|
+
it "#text_for(:post) splits strings" do
|
203
|
+
question.text = "before|after|extra"
|
204
|
+
question.text_for(:post).should == "after|extra"
|
205
|
+
end
|
133
206
|
end
|
134
|
-
|
135
207
|
end
|