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,48 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
|
-
describe SurveySection
|
4
|
-
|
5
|
-
@valid_attributes={:title => "foo", :survey_id => 2, :display_order => 4}
|
6
|
-
@survey_section = SurveySection.new(@valid_attributes)
|
7
|
-
end
|
4
|
+
describe SurveySection do
|
5
|
+
let(:survey_section){ Factory(:survey_section) }
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
7
|
+
context "when creating" do
|
8
|
+
it "is invalid without #title" do
|
9
|
+
survey_section.title = nil
|
10
|
+
survey_section.should have(1).error_on(:title)
|
11
|
+
end
|
12
|
+
it "protects #api_id" do
|
13
|
+
saved_attrs = survey_section.attributes
|
14
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
15
|
+
expect { survey_section.update_attributes(:api_id => "NEW") }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
16
|
+
else
|
17
|
+
survey_section.attributes = {:api_id => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
18
|
+
end
|
19
|
+
survey_section.attributes.should == saved_attrs
|
20
|
+
end
|
21
|
+
it "protects #created_at" do
|
22
|
+
saved_attrs = survey_section.attributes
|
23
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
24
|
+
expect { survey_section.update_attributes(:created_at => 3.days.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
25
|
+
else
|
26
|
+
survey_section.attributes = {:created_at => 3.days.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
27
|
+
end
|
28
|
+
survey_section.attributes.should == saved_attrs
|
29
|
+
end
|
30
|
+
it "protects #updated_at" do
|
31
|
+
saved_attrs = survey_section.attributes
|
32
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
33
|
+
expect { survey_section.update_attributes(:updated_at => 3.hours.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
34
|
+
else
|
35
|
+
survey_section.attributes = {:updated_at => 3.hours.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
36
|
+
end
|
37
|
+
survey_section.attributes.should == saved_attrs
|
38
|
+
end
|
27
39
|
end
|
28
|
-
end
|
29
40
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
context "with questions" do
|
42
|
+
let(:question_1){ Factory(:question, :survey_section => survey_section, :display_order => 3, :text => "Peep")}
|
43
|
+
let(:question_2){ Factory(:question, :survey_section => survey_section, :display_order => 1, :text => "Little")}
|
44
|
+
let(:question_3){ Factory(:question, :survey_section => survey_section, :display_order => 2, :text => "Bo")}
|
45
|
+
before do
|
46
|
+
[question_1, question_2, question_3].each{|q| survey_section.questions << q }
|
47
|
+
end
|
48
|
+
it{ survey_section.should have(3).questions}
|
49
|
+
it "gets questions in order" do
|
50
|
+
survey_section.questions.should == [question_2, question_3, question_1]
|
51
|
+
survey_section.questions.map(&:display_order).should == [1,2,3]
|
52
|
+
end
|
53
|
+
it "deletes child questions when deleted" do
|
54
|
+
question_ids = survey_section.questions.map(&:id)
|
55
|
+
survey_section.destroy
|
56
|
+
question_ids.each{|id| Question.find_by_id(id).should be_nil}
|
57
|
+
end
|
41
58
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
59
|
+
|
60
|
+
context "with translations" do
|
61
|
+
require 'yaml'
|
62
|
+
let(:survey){ Factory(:survey) }
|
63
|
+
let(:survey_translation){
|
64
|
+
Factory(:survey_translation, :locale => :es, :translation => {
|
65
|
+
:survey_sections => {
|
66
|
+
:one => {
|
67
|
+
:title => "Uno"
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}.to_yaml)
|
71
|
+
}
|
72
|
+
before do
|
73
|
+
survey_section.reference_identifier = "one"
|
74
|
+
survey_section.survey = survey
|
75
|
+
survey.translations << survey_translation
|
76
|
+
end
|
77
|
+
it "returns its own translation" do
|
78
|
+
YAML.load(survey_translation.translation).should_not be_nil
|
79
|
+
survey_section.translation(:es)[:title].should == "Uno"
|
80
|
+
end
|
81
|
+
it "returns its own default values" do
|
82
|
+
survey_section.translation(:de).should == {"title" => survey_section.title, "description" => survey_section.description}
|
83
|
+
end
|
46
84
|
end
|
47
|
-
|
48
85
|
end
|
data/spec/models/survey_spec.rb
CHANGED
@@ -1,160 +1,191 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@survey = Factory(:survey, :title => "Foo")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should be invalid without a title" do
|
10
|
-
@survey.title = nil
|
11
|
-
@survey.should have(1).error_on(:title)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should adjust the survey_version to save unique survey_version for each title" do
|
15
|
-
original = Survey.new(:title => "Foo")
|
16
|
-
original.save.should be_true
|
17
|
-
original.survey_version.should == 0
|
18
|
-
imposter = Survey.new(:title => "Foo")
|
19
|
-
imposter.save.should be_true
|
20
|
-
imposter.title.should == "Foo"
|
21
|
-
imposter.survey_version.should == 1
|
22
|
-
bandwagoneer = Survey.new(:title => "Foo")
|
23
|
-
bandwagoneer.save.should be_true
|
24
|
-
bandwagoneer.title.should == "Foo"
|
25
|
-
bandwagoneer.survey_version.should == 2
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should not allow to have duplicate survey_versions of the survey" do
|
29
|
-
survey = Survey.new(:title => "Foo")
|
30
|
-
survey.save.should be_true
|
31
|
-
imposter = Survey.new(:title => "Foo")
|
32
|
-
imposter.save.should be_true
|
33
|
-
imposter.survey_version = 0
|
34
|
-
imposter.save.should be_false
|
35
|
-
imposter.should have(1).error_on(:survey_version)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should not adjust the title when updating itself" do
|
39
|
-
original = Factory(:survey, :title => "Foo")
|
40
|
-
original.save.should be_true
|
41
|
-
original.update_attributes(:title => "Foo")
|
42
|
-
original.title.should == "Foo"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should have an api_id" do
|
46
|
-
@survey.api_id.length.should == 36
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Associations
|
51
|
-
describe Survey, "that has sections" do
|
52
|
-
before(:each) do
|
53
|
-
@survey = Factory(:survey, :title => "Foo")
|
54
|
-
@s1 = Factory(:survey_section, :survey => @survey, :title => "wise", :display_order => 2)
|
55
|
-
@s2 = Factory(:survey_section, :survey => @survey, :title => "er", :display_order => 3)
|
56
|
-
@s3 = Factory(:survey_section, :survey => @survey, :title => "bud", :display_order => 1)
|
57
|
-
@q1 = Factory(:question, :survey_section => @s1, :text => "what is wise?", :display_order => 2)
|
58
|
-
@q2 = Factory(:question, :survey_section => @s2, :text => "what is er?", :display_order => 4)
|
59
|
-
@q3 = Factory(:question, :survey_section => @s2, :text => "what is mill?", :display_order => 3)
|
60
|
-
@q4 = Factory(:question, :survey_section => @s3, :text => "what is bud?", :display_order => 1)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should return survey_sections in display order" do
|
64
|
-
@survey.sections.should have(3).sections
|
65
|
-
@survey.sections.should == [@s3, @s1, @s2]
|
66
|
-
end
|
4
|
+
describe Survey do
|
5
|
+
let(:survey){ Factory(:survey) }
|
67
6
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
7
|
+
context "when creating" do
|
8
|
+
it "is invalid without #title" do
|
9
|
+
survey.title = nil
|
10
|
+
survey.should have(1).error_on :title
|
11
|
+
end
|
12
|
+
it "adjust #survey_version" do
|
13
|
+
original = Survey.new(:title => "Foo")
|
14
|
+
original.save.should be_true
|
15
|
+
original.survey_version.should == 0
|
16
|
+
imposter = Survey.new(:title => "Foo")
|
17
|
+
imposter.save.should be_true
|
18
|
+
imposter.title.should == "Foo"
|
19
|
+
imposter.survey_version.should == 1
|
20
|
+
bandwagoneer = Survey.new(:title => "Foo")
|
21
|
+
bandwagoneer.save.should be_true
|
22
|
+
bandwagoneer.title.should == "Foo"
|
23
|
+
bandwagoneer.survey_version.should == 2
|
24
|
+
end
|
25
|
+
it "prevents duplicate #survey_version" do
|
26
|
+
original = Survey.new(:title => "Foo")
|
27
|
+
original.save.should be_true
|
28
|
+
imposter = Survey.new(:title => "Foo")
|
29
|
+
imposter.save.should be_true
|
30
|
+
imposter.survey_version = 0
|
31
|
+
imposter.save.should be_false
|
32
|
+
imposter.should have(1).error_on(:survey_version)
|
33
|
+
end
|
34
|
+
it "doesn't adjust #title when" do
|
35
|
+
original = Factory(:survey, :title => "Foo")
|
36
|
+
original.save.should be_true
|
37
|
+
original.update_attributes(:title => "Foo")
|
38
|
+
original.title.should == "Foo"
|
39
|
+
end
|
40
|
+
it "has #api_id with 36 characters by default" do
|
41
|
+
survey.api_id.length.should == 36
|
42
|
+
end
|
43
|
+
it "protects #access_code" do
|
44
|
+
saved_attrs = survey.attributes
|
45
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
46
|
+
expect { survey.update_attributes(:access_code => "NEW") }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
47
|
+
else
|
48
|
+
survey.attributes = {:access_code => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
49
|
+
end
|
50
|
+
survey.attributes.should == saved_attrs
|
51
|
+
end
|
52
|
+
it "protects #api_id" do
|
53
|
+
saved_attrs = survey.attributes
|
54
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
55
|
+
expect { survey.update_attributes(:api_id => "NEW") }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
56
|
+
else
|
57
|
+
survey.attributes = {:api_id => "NEW"} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
58
|
+
end
|
59
|
+
survey.attributes.should == saved_attrs
|
60
|
+
end
|
61
|
+
it "protects #created_at" do
|
62
|
+
saved_attrs = survey.attributes
|
63
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
64
|
+
expect { survey.update_attributes(:created_at => 3.days.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
65
|
+
else
|
66
|
+
survey.attributes = {:created_at => 3.days.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
67
|
+
end
|
68
|
+
survey.attributes.should == saved_attrs
|
69
|
+
end
|
70
|
+
it "protects #updated_at" do
|
71
|
+
saved_attrs = survey.attributes
|
72
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
73
|
+
expect { survey.update_attributes(:updated_at => 3.hours.ago) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
74
|
+
else
|
75
|
+
survey.attributes = {:updated_at => 3.hours.ago} # Rails doesn't return false, but this will be checked in the comparison to saved_attrs
|
76
|
+
end
|
77
|
+
survey.attributes.should == saved_attrs
|
78
|
+
end
|
76
79
|
end
|
77
|
-
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
context "activating" do
|
82
|
+
it { survey.active?.should }
|
83
|
+
it "both #inactive_at and #active_at == nil by default" do
|
84
|
+
survey.active_at.should be_nil
|
85
|
+
survey.inactive_at.should be_nil
|
86
|
+
end
|
87
|
+
it "#active_at on a certain date/time" do
|
88
|
+
survey.inactive_at = 2.days.from_now
|
89
|
+
survey.active_at = 2.days.ago
|
90
|
+
survey.active?.should be_true
|
91
|
+
end
|
92
|
+
it "#inactive_at on a certain date/time" do
|
93
|
+
survey.active_at = 3.days.ago
|
94
|
+
survey.inactive_at = 1.days.ago
|
95
|
+
survey.active?.should be_false
|
96
|
+
end
|
97
|
+
it "#activate! and #deactivate!" do
|
98
|
+
survey.activate!
|
99
|
+
survey.active?.should be_true
|
100
|
+
survey.deactivate!
|
101
|
+
survey.active?.should be_false
|
102
|
+
end
|
103
|
+
it "nils out past values of #inactive_at on #activate!" do
|
104
|
+
survey.inactive_at = 5.days.ago
|
105
|
+
survey.active?.should be_false
|
106
|
+
survey.activate!
|
107
|
+
survey.active?.should be_true
|
108
|
+
survey.inactive_at.should be_nil
|
109
|
+
end
|
110
|
+
it "nils out pas values of #active_at on #deactivate!" do
|
111
|
+
survey.active_at = 5.days.ago
|
112
|
+
survey.active?.should be_true
|
113
|
+
survey.deactivate!
|
114
|
+
survey.active?.should be_false
|
115
|
+
survey.active_at.should be_nil
|
116
|
+
end
|
83
117
|
end
|
84
118
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
119
|
+
context "with survey_sections" do
|
120
|
+
let(:s1){ Factory(:survey_section, :survey => survey, :title => "wise", :display_order => 2)}
|
121
|
+
let(:s2){ Factory(:survey_section, :survey => survey, :title => "er", :display_order => 3)}
|
122
|
+
let(:s3){ Factory(:survey_section, :survey => survey, :title => "bud", :display_order => 1)}
|
123
|
+
let(:q1){ Factory(:question, :survey_section => s1, :text => "what is wise?", :display_order => 2)}
|
124
|
+
let(:q2){ Factory(:question, :survey_section => s2, :text => "what is er?", :display_order => 4)}
|
125
|
+
let(:q3){ Factory(:question, :survey_section => s2, :text => "what is mill?", :display_order => 3)}
|
126
|
+
let(:q4){ Factory(:question, :survey_section => s3, :text => "what is bud?", :display_order => 1)}
|
127
|
+
before do
|
128
|
+
[s1, s2, s3].each{|s| survey.sections << s }
|
129
|
+
s1.questions << q1
|
130
|
+
s2.questions << q2
|
131
|
+
s2.questions << q3
|
132
|
+
s3.questions << q4
|
133
|
+
end
|
98
134
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
135
|
+
it{ survey.should have(3).sections}
|
136
|
+
it "gets survey_sections in order" do
|
137
|
+
survey.sections.should == [s3, s1, s2]
|
138
|
+
survey.sections.map(&:display_order).should == [1,2,3]
|
139
|
+
end
|
140
|
+
it "gets survey_sections_with_questions in order" do
|
141
|
+
survey.sections_with_questions.map(&:questions).flatten.should have(4).questions
|
142
|
+
survey.sections_with_questions.map(&:questions).flatten.should == [q4,q1,q3,q2]
|
143
|
+
end
|
144
|
+
it "deletes child survey_sections when deleted" do
|
145
|
+
survey_section_ids = survey.sections.map(&:id)
|
146
|
+
survey.destroy
|
147
|
+
survey_section_ids.each{|id| SurveySection.find_by_id(id).should be_nil}
|
148
|
+
end
|
103
149
|
end
|
104
150
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
151
|
+
context "serialization" do
|
152
|
+
let(:s1){ Factory(:survey_section, :survey => survey, :title => "wise") }
|
153
|
+
let(:s2){ Factory(:survey_section, :survey => survey, :title => "er") }
|
154
|
+
let(:q1){ Factory(:question, :survey_section => s1, :text => "what is wise?") }
|
155
|
+
let(:q2){ Factory(:question, :survey_section => s2, :text => "what is er?") }
|
156
|
+
let(:q3){ Factory(:question, :survey_section => s2, :text => "what is mill?") }
|
157
|
+
before do
|
158
|
+
[s1, s2].each{|s| survey.sections << s }
|
159
|
+
s1.questions << q1
|
160
|
+
s2.questions << q2
|
161
|
+
s2.questions << q3
|
162
|
+
end
|
111
163
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
164
|
+
it "includes title, sections, and questions" do
|
165
|
+
actual = survey.as_json
|
166
|
+
actual[:title].should == 'Simple survey'
|
167
|
+
actual[:sections].size.should == 2
|
168
|
+
actual[:sections][0][:questions_and_groups].size.should == 1
|
169
|
+
actual[:sections][1][:questions_and_groups].size.should == 2
|
170
|
+
end
|
118
171
|
end
|
119
172
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
@survey.update_attributes(:access_code => "NEW").should be_false
|
138
|
-
@survey.update_attributes(:api_id => "AND").should be_false
|
139
|
-
@survey.update_attributes(:active_at => 2.days.ago).should be_false
|
140
|
-
@survey.update_attributes(:inactive_at => 3.days.from_now).should be_false
|
141
|
-
@survey.attributes = {:created_at => 3.days.ago, :updated_at => 3.hours.ago} # automatically protected by Rails
|
142
|
-
end
|
143
|
-
@survey.attributes.should == saved_attrs
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should include title, sections, and questions when serialized" do
|
147
|
-
survey = Factory(:survey, :title => "Foo")
|
148
|
-
s1 = Factory(:survey_section, :survey => survey, :title => "wise")
|
149
|
-
s2 = Factory(:survey_section, :survey => survey, :title => "er")
|
150
|
-
q1 = Factory(:question, :survey_section => s1, :text => "what is wise?")
|
151
|
-
q2 = Factory(:question, :survey_section => s2, :text => "what is er?")
|
152
|
-
q3 = Factory(:question, :survey_section => s2, :text => "what is mill?")
|
153
|
-
|
154
|
-
actual = survey.as_json
|
155
|
-
actual[:title].should == 'Foo'
|
156
|
-
actual[:sections].size.should == 2
|
157
|
-
actual[:sections][0][:questions_and_groups].size.should == 1
|
158
|
-
actual[:sections][1][:questions_and_groups].size.should == 2
|
173
|
+
context "with translations" do
|
174
|
+
require 'yaml'
|
175
|
+
let(:survey_translation){
|
176
|
+
Factory(:survey_translation, :locale => :es, :translation => {
|
177
|
+
:title => "Un idioma nunca es suficiente"
|
178
|
+
}.to_yaml)
|
179
|
+
}
|
180
|
+
before do
|
181
|
+
survey.translations << survey_translation
|
182
|
+
end
|
183
|
+
it "returns its own translation" do
|
184
|
+
YAML.load(survey_translation.translation).should_not be_nil
|
185
|
+
survey.translation(:es)[:title].should == "Un idioma nunca es suficiente"
|
186
|
+
end
|
187
|
+
it "returns its own default values" do
|
188
|
+
survey.translation(:de).should == {"title" => survey.title, "description" => survey.description}
|
189
|
+
end
|
159
190
|
end
|
160
191
|
end
|