breakpointer-surveyor 0.2.0
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 +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/app/controllers/answers_controller.rb +87 -0
- data/app/controllers/dependencies_controller.rb +87 -0
- data/app/controllers/dependency_conditions_controller.rb +87 -0
- data/app/controllers/questions_controller.rb +85 -0
- data/app/controllers/sections_controller.rb +87 -0
- data/app/controllers/surveying_controller.rb +139 -0
- data/app/controllers/surveys_controller.rb +87 -0
- data/app/helpers/answers_helper.rb +2 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/questions_helper.rb +2 -0
- data/app/helpers/sections_helper.rb +2 -0
- data/app/helpers/survey_form_builder.rb +38 -0
- data/app/helpers/survey_importer_helper.rb +2 -0
- data/app/helpers/surveying_helper.rb +91 -0
- data/app/helpers/surveys_helper.rb +2 -0
- data/app/models/answer.rb +18 -0
- data/app/models/dependency.rb +43 -0
- data/app/models/dependency_condition.rb +76 -0
- data/app/models/question.rb +44 -0
- data/app/models/question_group.rb +5 -0
- data/app/models/response.rb +58 -0
- data/app/models/response_set.rb +174 -0
- data/app/models/survey.rb +54 -0
- data/app/models/survey_section.rb +19 -0
- data/app/models/user.rb +5 -0
- data/app/views/answer_display_types/_any_answer.html.haml +3 -0
- data/app/views/answer_display_types/_any_other_and_string.html.haml +5 -0
- data/app/views/answer_display_types/_any_string.html.haml +4 -0
- data/app/views/answer_display_types/_date.html.haml +3 -0
- data/app/views/answer_display_types/_datetime.html.haml +2 -0
- data/app/views/answer_display_types/_default.html.haml +1 -0
- data/app/views/answer_display_types/_float.html.haml +5 -0
- data/app/views/answer_display_types/_grid_any_answer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_default.html.haml +2 -0
- data/app/views/answer_display_types/_grid_float.html.haml +2 -0
- data/app/views/answer_display_types/_grid_integer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_one_answer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_string.html.haml +2 -0
- data/app/views/answer_display_types/_integer.html.haml +6 -0
- data/app/views/answer_display_types/_one_answer.html.haml +3 -0
- data/app/views/answer_display_types/_one_string.html.haml +6 -0
- data/app/views/answer_display_types/_repeater_integer.html.haml +6 -0
- data/app/views/answer_display_types/_repeater_string.html.haml +7 -0
- data/app/views/answer_display_types/_string.html.haml +7 -0
- data/app/views/answer_display_types/_text.html.haml +6 -0
- data/app/views/answer_display_types/_time.html.haml +2 -0
- data/app/views/layouts/surveys.html.erb +17 -0
- data/app/views/question_display_types/_default.html.haml +12 -0
- data/app/views/question_display_types/_dropdown.html.haml +12 -0
- data/app/views/question_display_types/_grid_default.html.haml +14 -0
- data/app/views/question_display_types/_grid_dropdown.html.haml +15 -0
- data/app/views/question_display_types/_group_default.html.haml +8 -0
- data/app/views/question_display_types/_group_dropdown.html.haml +6 -0
- data/app/views/question_display_types/_image.html.haml +2 -0
- data/app/views/question_display_types/_inline.html.haml +12 -0
- data/app/views/question_display_types/_label.html.haml +4 -0
- data/app/views/question_display_types/_repeater_default.html.haml +10 -0
- data/app/views/question_display_types/_repeater_dropdown.html.haml +8 -0
- data/app/views/question_display_types/_slider.html.haml +17 -0
- data/app/views/question_group_display_types/_default.html.haml +13 -0
- data/app/views/question_group_display_types/_grid.html.haml +24 -0
- data/app/views/question_group_display_types/_repeater.html.haml +20 -0
- data/app/views/surveying/edit.html.haml +38 -0
- data/app/views/surveying/finish.html.haml +1 -0
- data/app/views/surveying/index.html.erb +19 -0
- data/app/views/surveying/new.html.haml +17 -0
- data/app/views/surveying/show.html.haml +8 -0
- data/config/routes.rb +10 -0
- data/generators/surveyor/surveyor_generator.rb +38 -0
- data/generators/surveyor/templates/README +9 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
- data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +201 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +3549 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +7616 -0
- data/generators/surveyor/templates/assets/javascripts/jquery.form.js +637 -0
- data/generators/surveyor/templates/assets/javascripts/surveyor.js +35 -0
- data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
- data/generators/surveyor/templates/assets/stylesheets/reset.css +46 -0
- data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +321 -0
- data/generators/surveyor/templates/assets/stylesheets/surveyor.css +245 -0
- data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
- data/generators/surveyor/templates/migrate/create_answers.rb +46 -0
- data/generators/surveyor/templates/migrate/create_dependencies.rb +21 -0
- data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
- data/generators/surveyor/templates/migrate/create_question_groups.rb +18 -0
- data/generators/surveyor/templates/migrate/create_questions.rb +33 -0
- data/generators/surveyor/templates/migrate/create_response_sets.rb +22 -0
- data/generators/surveyor/templates/migrate/create_responses.rb +33 -0
- data/generators/surveyor/templates/migrate/create_survey_sections.rb +25 -0
- data/generators/surveyor/templates/migrate/create_surveys.rb +25 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +201 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/tasks/surveyor_tasks.rake +29 -0
- data/lib/tiny_code.rb +58 -0
- data/lib/user_manager.rb +9 -0
- data/lib/xml_formatter.rb +12 -0
- data/script/surveyor/answer.rb +84 -0
- data/script/surveyor/columnizer.rb +36 -0
- data/script/surveyor/dependency.rb +43 -0
- data/script/surveyor/dependency_condition.rb +74 -0
- data/script/surveyor/dslparse.rb +66 -0
- data/script/surveyor/question.rb +76 -0
- data/script/surveyor/question_group.rb +33 -0
- data/script/surveyor/specs/answer_spec.rb +66 -0
- data/script/surveyor/specs/question_dependency_spec.rb +46 -0
- data/script/surveyor/specs/question_group_spec.rb +9 -0
- data/script/surveyor/specs/question_spec.rb +111 -0
- data/script/surveyor/specs/section_spec.rb +58 -0
- data/script/surveyor/survey.rb +108 -0
- data/script/surveyor/survey_section.rb +153 -0
- data/script/surveyor/whr_dsl.tmproj +244 -0
- data/spec/controllers/answers_controller_spec.rb +64 -0
- data/spec/controllers/dependencies_controller_spec.rb +63 -0
- data/spec/controllers/dependency_conditions_controller_spec.rb +64 -0
- data/spec/controllers/questions_controller_spec.rb +64 -0
- data/spec/controllers/sections_controller_spec.rb +64 -0
- data/spec/controllers/surveying_controller_spec.rb +328 -0
- data/spec/controllers/surveying_routing_spec.rb +45 -0
- data/spec/controllers/surveys_controller_spec.rb +64 -0
- data/spec/fixtures/answers.yml +9 -0
- data/spec/fixtures/dependencies.yml +7 -0
- data/spec/fixtures/dependency_conditions.yml +27 -0
- data/spec/fixtures/question_groups.yml +7 -0
- data/spec/fixtures/questions.yml +15 -0
- data/spec/fixtures/response_sets.yml +13 -0
- data/spec/fixtures/responses.yml +9 -0
- data/spec/fixtures/survey_sections.yml +11 -0
- data/spec/fixtures/surveys.yml +9 -0
- data/spec/fixtures/users.yml +7 -0
- data/spec/helpers/survey_importer_helper_spec.rb +11 -0
- data/spec/helpers/surveying_helper_spec.rb +11 -0
- data/spec/models/answer_spec.rb +62 -0
- data/spec/models/dependency_condition_spec.rb +347 -0
- data/spec/models/dependency_spec.rb +82 -0
- data/spec/models/question_group_spec.rb +11 -0
- data/spec/models/question_spec.rb +70 -0
- data/spec/models/response_set_spec.rb +172 -0
- data/spec/models/response_spec.rb +94 -0
- data/spec/models/survey_section_spec.rb +34 -0
- data/spec/models/survey_spec.rb +72 -0
- data/spec/models/user_spec.rb +11 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +72 -0
- data/spec/views/app/edit.html.erb_spec.rb +20 -0
- data/spec/views/app/index.html.erb_spec.rb +19 -0
- data/spec/views/app/new.html.erb_spec.rb +21 -0
- data/spec/views/app/show.html.erb_spec.rb +17 -0
- data/surveyor.gemspec +258 -0
- data/uninstall.rb +1 -0
- metadata +286 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe SectionsController do
|
|
4
|
+
|
|
5
|
+
describe "REST actions"do
|
|
6
|
+
|
|
7
|
+
it "GETs all sections" do
|
|
8
|
+
@sections = [mock(SurveySection)]
|
|
9
|
+
SurveySection.should_receive(:find).and_return(@sections)
|
|
10
|
+
get "index"
|
|
11
|
+
assigns[:sections].should_not be_empty
|
|
12
|
+
assigns[:sections].should == @sections
|
|
13
|
+
response.should be_success
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "GETs one section" do
|
|
17
|
+
@section = mock(SurveySection)
|
|
18
|
+
SurveySection.should_receive(:find).and_return(@section)
|
|
19
|
+
get 'show', :id => @section
|
|
20
|
+
assigns[:section].should == @section
|
|
21
|
+
response.should be_success
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "GETs a new section" do
|
|
25
|
+
get 'new'
|
|
26
|
+
assigns[:section].should_not be_nil
|
|
27
|
+
response.should be_success
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "POSTs a new section" do
|
|
31
|
+
@section = SurveySection.new(:title => "test")
|
|
32
|
+
@section.stub!(:new).and_return(true)
|
|
33
|
+
SurveySection.should_receive(:new).with(@section.attributes).and_return(@section)
|
|
34
|
+
post 'create', {:section => @section.attributes}
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "GETs an editable section" do
|
|
39
|
+
@section = mock(SurveySection)
|
|
40
|
+
SurveySection.should_receive(:find).and_return(@section)
|
|
41
|
+
|
|
42
|
+
get 'edit', :id => @section
|
|
43
|
+
assigns[:section].should == @section
|
|
44
|
+
response.should be_success
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "PUTs an editiable section" do
|
|
48
|
+
@section = mock(SurveySection, :title => "test")
|
|
49
|
+
SurveySection.should_receive(:find).and_return(@section)
|
|
50
|
+
@section.stub!(:update_attributes)
|
|
51
|
+
put 'update', :id => @section
|
|
52
|
+
response.should be_success
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "DELETEs an existing section" do
|
|
56
|
+
@section = mock(SurveySection)
|
|
57
|
+
@section.stub!(:destroy)
|
|
58
|
+
SurveySection.should_receive(:find).with(@section).and_return(@section)
|
|
59
|
+
delete 'destroy', :id => @section
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe SurveyingController do
|
|
4
|
+
|
|
5
|
+
# map.available_surveys 'surveys', :conditions => {:method => :get}, :action => "new" # GET survey list
|
|
6
|
+
# map.take_survey 'surveys/:survey_code', :conditions => {:method => :post}, :action => "create" # Only POST of survey to create
|
|
7
|
+
# map.view_my_survey 'surveys/:survey_code/:response_set_code', :conditions => {:method => :get}, :action => "show" # GET viewable/printable? survey
|
|
8
|
+
# map.edit_my_survey 'surveys/:survey_code/:response_set_code/take', :conditions => {:method => :get}, :action => "edit" # GET editable survey
|
|
9
|
+
# map.update_my_survey 'surveys/:survey_code/:response_set_code', :conditions => {:method => :put}, :action => "update" # PUT edited survey
|
|
10
|
+
# map.finish_my_survey 'surveys/:survey_code/:response_set_code/finish', :conditions => {:method => :put}, :action => "finish" # PUT to close out the response_set
|
|
11
|
+
|
|
12
|
+
describe "handling GET /surveys (available_surveys)" do
|
|
13
|
+
|
|
14
|
+
before(:each) do
|
|
15
|
+
@survey = mock_model(Survey)
|
|
16
|
+
Survey.stub!(:find).and_return([@survey])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def do_get
|
|
20
|
+
get :new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should be successful" do
|
|
24
|
+
do_get
|
|
25
|
+
response.should be_success
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should render index template" do
|
|
29
|
+
do_get
|
|
30
|
+
response.should render_template('new')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should find all surveys" do
|
|
34
|
+
Survey.should_receive(:find).with(:all).and_return([@survey])
|
|
35
|
+
do_get
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should assign the found surveys for the view" do
|
|
39
|
+
do_get
|
|
40
|
+
assigns[:surveys].should == [@survey]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "handling GET /surveys.xml (available_surveys)" do
|
|
45
|
+
before(:each) do
|
|
46
|
+
@surveys = mock("Array of Surveys", :to_xml => "XML")
|
|
47
|
+
Survey.stub!(:find).and_return(@surveys)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def do_get
|
|
51
|
+
@request.env["HTTP_ACCEPT"] = "application/xml"
|
|
52
|
+
get :new
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should be successful" do
|
|
56
|
+
do_get
|
|
57
|
+
response.should be_success
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should find all surveys" do
|
|
61
|
+
Survey.should_receive(:find).with(:all).and_return(@surveys)
|
|
62
|
+
do_get
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should render the found surveys as xml" do
|
|
66
|
+
@surveys.should_receive(:to_xml).and_return("XML")
|
|
67
|
+
do_get
|
|
68
|
+
response.body.should == "XML"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "handling POST /surveys/XYZ (take_survey)" do
|
|
73
|
+
|
|
74
|
+
before(:each) do
|
|
75
|
+
@survey = mock_model(Survey, :access_code => "XYZ")
|
|
76
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
|
77
|
+
ResponseSet.stub!(:new).and_return(@response_set)
|
|
78
|
+
Survey.stub!(:find_by_access_code).and_return(@survey)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe "with successful save" do
|
|
82
|
+
|
|
83
|
+
def do_post
|
|
84
|
+
@response_set.should_receive(:save!).and_return(true)
|
|
85
|
+
post :create, :survey_code => "XYZ"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should look for the survey" do
|
|
89
|
+
Survey.should_receive(:find_by_access_code).with("XYZ").and_return(@survey)
|
|
90
|
+
do_post
|
|
91
|
+
end
|
|
92
|
+
it "should create a new response_set" do
|
|
93
|
+
ResponseSet.should_receive(:new).and_return(@response_set)
|
|
94
|
+
do_post
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should redirect to the new response_set" do
|
|
98
|
+
do_post
|
|
99
|
+
response.should redirect_to(edit_my_survey_url(:survey_code => "XYZ", :response_set_code => "PDQ"))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "with failed save" do
|
|
105
|
+
|
|
106
|
+
def do_post
|
|
107
|
+
@response_set.should_receive(:save!).and_return(false)
|
|
108
|
+
post :create, :survey_code => "XYZ"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should re-redirect to 'new'" do
|
|
112
|
+
do_post
|
|
113
|
+
response.should redirect_to(available_surveys_url)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "with survey not found" do
|
|
119
|
+
|
|
120
|
+
def do_post
|
|
121
|
+
Survey.should_receive(:find_by_access_code).and_return(nil)
|
|
122
|
+
post :create, :survey_code => "XYZ"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should re-redirect to 'new'" do
|
|
126
|
+
do_post
|
|
127
|
+
response.should redirect_to(available_surveys_url)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe "handling GET /surveys/XYZ/PDQ (view_my_survey)" do
|
|
134
|
+
|
|
135
|
+
before(:each) do
|
|
136
|
+
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
|
137
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
|
138
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
139
|
+
@response_set.stub!(:survey).and_return(@survey)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def do_get
|
|
143
|
+
get :show, :survey_code => "XYZ", :response_set_code => "PDQ"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "should be successful" do
|
|
147
|
+
do_get
|
|
148
|
+
response.should be_success
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "should render show template" do
|
|
152
|
+
do_get
|
|
153
|
+
response.should render_template('show')
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should find the response_set requested" do
|
|
157
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
158
|
+
do_get
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should assign the found response_set and survey for the view" do
|
|
162
|
+
do_get
|
|
163
|
+
assigns[:response_set].should equal(@response_set)
|
|
164
|
+
assigns[:survey].should equal(@survey)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "should redirect if :response_code not found" do
|
|
168
|
+
get :show, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
|
169
|
+
response.should redirect_to(available_surveys_url)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# I'm not sure this is enterly neccessary since we look up the survey from the response_code in the url -BC
|
|
173
|
+
it "should redirect if :survey_code in url doesn't match response_set.survey.access_code" do
|
|
174
|
+
pending
|
|
175
|
+
get :show, :survey_code => "DIFFERENT", :response_set_code => "PDQ"
|
|
176
|
+
response.should redirect_to(available_surveys_url)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe "handling GET /surveys/XYZ/PDQ/take (edit_my_survey)" do
|
|
181
|
+
|
|
182
|
+
before(:each) do
|
|
183
|
+
@survey = mock_model(Survey, :access_code => "XYZ")
|
|
184
|
+
@survey_section = mock_model(SurveySection)
|
|
185
|
+
@survey.stub!(:sections).and_return([@survey_section])
|
|
186
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
|
187
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
188
|
+
@response_set.stub!(:survey).and_return(@survey)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should be successful, render edit with the requested survey" do
|
|
192
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
193
|
+
|
|
194
|
+
get :edit, :survey_code => "XYZ", :response_set_code => "PDQ"
|
|
195
|
+
response.should be_success
|
|
196
|
+
response.should render_template('edit')
|
|
197
|
+
assigns[:response_set].should equal(@response_set)
|
|
198
|
+
assigns[:survey].should equal(@survey)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "should redirect if :response_code not found" do
|
|
202
|
+
get :edit, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
|
203
|
+
response.should redirect_to(available_surveys_url)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
describe "handling PUT /surveys/XYZ/PDQ (update_my_survey)" do
|
|
209
|
+
|
|
210
|
+
before(:each) do
|
|
211
|
+
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
|
212
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
|
213
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
214
|
+
@response_set.stub!(:survey).and_return(@survey)
|
|
215
|
+
@response_set.stub!(:add_responses).and_return(true)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe "with no response_set in update" do
|
|
219
|
+
|
|
220
|
+
it "should find the response set requested" do
|
|
221
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
222
|
+
put :update, :survey_code => "XYZ", :response_set_code => "PDQ"
|
|
223
|
+
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
describe "with a new response set" do
|
|
229
|
+
|
|
230
|
+
it "should accept properly formatted params and save the data" do
|
|
231
|
+
response_set_params = {"survey_code"=>"XYZ", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}]}}}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# describe "issue with posting data to an existing survey and the data not saving properly" do
|
|
237
|
+
# @survey = mock_model(Survey, :access_code => "XYZ")
|
|
238
|
+
# @response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
|
239
|
+
# ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
240
|
+
# @response_set.stub!(:survey).and_return(@survey)
|
|
241
|
+
# @response_set.stub!(:complete!).and_return(Time.now)
|
|
242
|
+
#
|
|
243
|
+
#
|
|
244
|
+
# end
|
|
245
|
+
|
|
246
|
+
# first post {"survey_code"=>"test_survey", "commit"=>"Next Section (Utensiles and you!) >>", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}, {"answer_id"=>"0", "string_value"=>""}], "2"=>[{"answer_id"=>"6"}], "3"=>[{"answer_id"=>"10"}], "4"=>[{"answer_id"=>"14"}], "5"=>[{"answer_id"=>"0"}, {"answer_id"=>"0"}]}, "existing_response_attributes"=>{"6"=>{"1"=>{"answer_id"=>"20", "string_value"=>"B"}}, "7"=>{"2"=>{"text_value"=>"foo", "answer_id"=>"21"}}, "5"=>{"7"=>{"answer_id"=>"17"}, "16"=>{"answer_id"=>"19", "string_value"=>"blah"}}}}, "authenticity_token"=>"d9ba68fe20a46703f3737b5cb0b7e17b7390de32", "_method"=>"put", "action"=>"update", "controller"=>"app", "response_set_code"=>"9VEsec1dK6", "section"=>"2"}
|
|
247
|
+
# second post {"survey_code"=>"test_survey", "commit"=>"Next Section (Utensiles and you!) >>", "response_set"=>{"new_response_attributes"=>{"1"=>[{"answer_id"=>"2"}, {"answer_id"=>"0", "string_value"=>""}], "2"=>[{"answer_id"=>"6"}], "3"=>[{"answer_id"=>"10"}], "4"=>[{"answer_id"=>"14"}], "5"=>[{"answer_id"=>"0"}, {"answer_id"=>"0"}]}, "existing_response_attributes"=>{"6"=>{"1"=>{"answer_id"=>"20", "string_value"=>"B"}}, "7"=>{"2"=>{"text_value"=>"boooo", "answer_id"=>"21"}}, "5"=>{"7"=>{"answer_id"=>"17"}, "16"=>{"answer_id"=>"19", "string_value"=>"blahblahstink"}}}}, "authenticity_token"=>"d9ba68fe20a46703f3737b5cb0b7e17b7390de32", "_method"=>"put", "action"=>"update", "controller"=>"app", "response_set_code"=>"9VEsec1dK6", "section"=>"2"}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
describe "with failed update" do
|
|
254
|
+
|
|
255
|
+
it "should re-render 'edit'" do
|
|
256
|
+
put :update, :survey_code => "XYZ", :response_set_code => "PDQ"
|
|
257
|
+
response.should be_success
|
|
258
|
+
response.should render_template('edit')
|
|
259
|
+
flash[:notice].should == "Unable to update survey"
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
describe "handling PUT /surveys/XYZ/PDQ/finish (finish_my_survey)" do
|
|
266
|
+
|
|
267
|
+
before(:each) do
|
|
268
|
+
@survey = mock_model(Survey, :access_code => "XYZ", :sections => [mock_model(SurveySection)])
|
|
269
|
+
@response_set = mock_model(ResponseSet, :access_code => "PDQ")
|
|
270
|
+
ResponseSet.stub!(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
271
|
+
@response_set.stub!(:survey).and_return(@survey)
|
|
272
|
+
@response_set.stub!(:complete!).and_return(Time.now)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
describe "with successful update" do
|
|
276
|
+
|
|
277
|
+
def do_put
|
|
278
|
+
put :finish, :survey_code => "XYZ", :response_set_code => "PDQ"
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
it "should find the response_set requested" do
|
|
282
|
+
ResponseSet.should_receive(:find_by_access_code).with("PDQ").and_return(@response_set)
|
|
283
|
+
do_put
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
it "should update the found response set" do
|
|
287
|
+
@response_set.should_receive(:complete!).and_return(Time.now)
|
|
288
|
+
do_put
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it "should assign the found response set and survey for the view" do
|
|
292
|
+
do_put
|
|
293
|
+
assigns(:response_set).should equal(@response_set)
|
|
294
|
+
assigns(:survey).should equal(@response_set.survey)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "should render the 'edit' template" do
|
|
298
|
+
do_put
|
|
299
|
+
response.should render_template('edit')
|
|
300
|
+
flash[:notice].should == "Completed survey"
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it "should redirect to available surveys if :response_code not found" do
|
|
304
|
+
put :update, :survey_code => "XYZ", :response_set_code => "DIFFERENT"
|
|
305
|
+
response.should redirect_to(available_surveys_url)
|
|
306
|
+
flash[:notice].should == "Unable to find your responses to the survey"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
describe "with failed update" do
|
|
312
|
+
|
|
313
|
+
def do_put
|
|
314
|
+
put :finish, :survey_code => "XYZ", :response_set_code => "PDQ"
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
it "should re-render 'edit'" do
|
|
318
|
+
@response_set.should_receive(:complete!).and_return(false)
|
|
319
|
+
do_put
|
|
320
|
+
response.should render_template('edit')
|
|
321
|
+
flash[:notice].should == "Unable to complete survey"
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe SurveyingController do
|
|
4
|
+
describe "route generation" do
|
|
5
|
+
it "should map { :controller => 'surveying', :action => 'new'} to /" do
|
|
6
|
+
route_for(:controller => 'surveying', :action => "new").should == "/"
|
|
7
|
+
end
|
|
8
|
+
it "should map { :controller => 'surveying', :action => 'create', :survey_code => 1} to /1" do
|
|
9
|
+
route_for(:controller => 'surveying', :action => "create", :survey_code => 1).should == "/1"
|
|
10
|
+
end
|
|
11
|
+
it "should map { 'surveying', :action => 'show', :survey_code => 1, :response_set_code => 'XYZ'} to /1/XYZ" do
|
|
12
|
+
route_for(:controller => 'surveying', :action => "show", :survey_code => 1, :response_set_code => "XYZ").should == "/1/XYZ"
|
|
13
|
+
end
|
|
14
|
+
it "should map { :controller => 'surveying', :action => 'edit', :survey_code => 1, :response_set_code => 'XYZ'} to /1/XYZ/take" do
|
|
15
|
+
route_for(:controller => 'surveying', :action => "edit", :survey_code => 1, :response_set_code => "XYZ").should == "/1/XYZ/take"
|
|
16
|
+
end
|
|
17
|
+
it "should map { :controller => 'surveying', :action => 'update', :survey_code => 1, :response_set_code => 'XYZ'} to /1/XYZ" do
|
|
18
|
+
route_for(:controller => 'surveying', :action => "update", :survey_code => 1, :response_set_code => "XYZ").should == "/1/XYZ"
|
|
19
|
+
end
|
|
20
|
+
it "should map { :controller => 'surveying', :action => 'finish', :survey_code => 1, :response_set_code => 'XYZ'} to /1/XYZ/finish" do
|
|
21
|
+
route_for(:controller => 'surveying', :action => "finish", :survey_code => 1, :response_set_code => "XYZ").should == "/1/XYZ/finish"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "route recognition" do
|
|
26
|
+
it "should generate params { :controller => 'surveying', :action => 'new' } from GET /" do
|
|
27
|
+
params_from(:get, "/").should == {:controller => 'surveying', :action => "new"}
|
|
28
|
+
end
|
|
29
|
+
it "should generate params { :controller => 'surveying', :action => 'create', :survey_code => '1' } from POST /1" do
|
|
30
|
+
params_from(:post, "/1").should == {:controller => 'surveying', :action => "create", :survey_code => "1"}
|
|
31
|
+
end
|
|
32
|
+
it "should generate params { :controller => 'surveying', :action => 'show', :survey_code => '1', :response_set_code => 'XYZ' } from GET /1/XYZ" do
|
|
33
|
+
params_from(:get, "/1/XYZ").should == {:controller => 'surveying', :action => "show", :survey_code => "1", :response_set_code => "XYZ"}
|
|
34
|
+
end
|
|
35
|
+
it "should generate params { :controller => 'surveying', :action => 'edit', :survey_code => '1', :response_set_code => 'XYZ' } from GET /1/XYZ/take" do
|
|
36
|
+
params_from(:get, "/1/XYZ/take").should == {:controller => 'surveying', :action => "edit", :survey_code => "1", :response_set_code => "XYZ"}
|
|
37
|
+
end
|
|
38
|
+
it "should generate params { :controller => 'surveying', :action => 'update', :survey_code => '1', :response_set_code } from PUT /1/XYZ" do
|
|
39
|
+
params_from(:put, "/1/XYZ").should == {:controller => 'surveying', :action => "update", :survey_code => "1", :response_set_code => "XYZ"}
|
|
40
|
+
end
|
|
41
|
+
it "should generate params { :controller => 'surveying', :action => 'finish', :survey_code => '1', :response_set_code } from PUT /1/XYZ/finish" do
|
|
42
|
+
params_from(:put, "/1/XYZ/finish").should == {:controller => 'surveying', :action => "finish", :survey_code => "1", :response_set_code => "XYZ"}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe SurveysController do
|
|
4
|
+
|
|
5
|
+
describe "REST actions"do
|
|
6
|
+
|
|
7
|
+
it "GETs all surveys" do
|
|
8
|
+
@surveys = [mock(Survey)]
|
|
9
|
+
Survey.should_receive(:find).and_return(@surveys)
|
|
10
|
+
get "index"
|
|
11
|
+
assigns[:surveys].should_not be_empty
|
|
12
|
+
assigns[:surveys].should == @surveys
|
|
13
|
+
response.should be_success
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "GETs one survey" do
|
|
17
|
+
@survey = mock(Survey)
|
|
18
|
+
Survey.should_receive(:find).and_return(@survey)
|
|
19
|
+
get 'show', :id => @survey
|
|
20
|
+
assigns[:survey].should == @survey
|
|
21
|
+
response.should be_success
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "GETs a new survey" do
|
|
25
|
+
get 'new'
|
|
26
|
+
assigns[:survey].should_not be_nil
|
|
27
|
+
response.should be_success
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "POSTs a new survey" do
|
|
31
|
+
@survey = Survey.new(:title => "test")
|
|
32
|
+
@survey.stub!(:new).and_return(true)
|
|
33
|
+
Survey.should_receive(:new).with(@survey.attributes).and_return(@survey)
|
|
34
|
+
post 'create', {:survey => @survey.attributes}
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "GETs an editable survey" do
|
|
39
|
+
@survey = mock(Survey)
|
|
40
|
+
Survey.should_receive(:find).and_return(@survey)
|
|
41
|
+
|
|
42
|
+
get 'edit', :id => @survey
|
|
43
|
+
assigns[:survey].should == @survey
|
|
44
|
+
response.should be_success
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "PUTs an editiable survey" do
|
|
48
|
+
@survey = mock(Survey, :title => "test")
|
|
49
|
+
Survey.should_receive(:find).and_return(@survey)
|
|
50
|
+
@survey.stub!(:update_attributes)
|
|
51
|
+
put 'update', :id => @survey
|
|
52
|
+
response.should be_success
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "DELETEs an existing survey" do
|
|
56
|
+
@survey = mock(Survey)
|
|
57
|
+
@survey.stub!(:destroy)
|
|
58
|
+
Survey.should_receive(:find).with(@survey).and_return(@survey)
|
|
59
|
+
delete 'destroy', :id => @survey
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|