surveyor 0.13.0 → 0.14.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/README.md +13 -3
- data/VERSION +1 -1
- data/app/helpers/surveyor_helper.rb +5 -5
- data/app/models/response_set.rb +10 -5
- data/app/models/survey_section_sweeper.rb +15 -0
- data/app/views/partials/_question.html.haml +2 -2
- data/app/views/partials/_section.html.haml +13 -0
- data/app/views/surveyor/edit.html.haml +9 -14
- data/app/views/surveyor/new.html.haml +3 -3
- data/app/views/surveyor/show.html.haml +6 -3
- data/features/surveyor.feature +1 -1
- data/generators/extend_surveyor/templates/extensions/survey_extensions.rb +24 -0
- data/generators/extend_surveyor/templates/extensions/surveyor_controller_extensions.rb +28 -0
- data/generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb +1 -1
- data/generators/extend_surveyor/templates/extensions/surveyor_helper_extensions.rb +17 -0
- data/generators/surveyor/surveyor_generator.rb +9 -1
- data/generators/surveyor/templates/locales/surveyor_en.yml +15 -0
- data/generators/surveyor/templates/locales/surveyor_he.yml +16 -0
- data/generators/surveyor/templates/migrate/add_section_id_to_responses.rb +11 -0
- data/lib/surveyor/surveyor_controller_methods.rb +9 -8
- data/spec/controllers/surveyor_controller_spec.rb +1 -6
- data/spec/factories.rb +1 -0
- data/spec/models/response_set_spec.rb +16 -1
- data/spec/views/surveyor/show.html.haml_spec.rb +32 -0
- data/surveyor.gemspec +13 -3
- metadata +14 -4
data/README.md
CHANGED
@@ -59,19 +59,19 @@ As a plugin:
|
|
59
59
|
|
60
60
|
gem install haml
|
61
61
|
gem install fastercsv
|
62
|
-
script/plugin install git://github.com/breakpointer/surveyor.git -r 'tag v0.
|
62
|
+
script/plugin install git://github.com/breakpointer/surveyor.git -r 'tag v0.14.0'
|
63
63
|
|
64
64
|
Or as a gem:
|
65
65
|
|
66
66
|
# in environment.rb
|
67
|
-
config.gem "surveyor", :version => '~> 0.
|
67
|
+
config.gem "surveyor", :version => '~> 0.14.0', :source => 'http://gemcutter.org'
|
68
68
|
|
69
69
|
rake gems:install
|
70
70
|
|
71
71
|
Or as a gem (with bundler):
|
72
72
|
|
73
73
|
# in environment.rb
|
74
|
-
gem "surveyor", '~> 0.
|
74
|
+
gem "surveyor", '~> 0.14.0'
|
75
75
|
|
76
76
|
bundle install
|
77
77
|
|
@@ -114,6 +114,16 @@ To work on the plugin code (for enhancements, and bug fixes, etc...) fork this g
|
|
114
114
|
|
115
115
|
# Changes
|
116
116
|
|
117
|
+
0.14.0
|
118
|
+
|
119
|
+
* view my survey specs fixed, fragment caching for surveyor#edit, localization. thanks bnadav
|
120
|
+
|
121
|
+
0.13.0
|
122
|
+
|
123
|
+
* simpler customization of surveyor.
|
124
|
+
* spec plugins task
|
125
|
+
* Feature instead of Story for cucumber. http://wiki.github.com/aslakhellesoy/cucumber/upgrading
|
126
|
+
|
117
127
|
0.12.0
|
118
128
|
|
119
129
|
* fix parser error in ruby 1.9, where instance_variables are symbols. closes #61
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.14.0
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module SurveyorHelper
|
2
|
-
|
2
|
+
|
3
3
|
# Layout: stylsheets and javascripts
|
4
4
|
def surveyor_includes
|
5
5
|
surveyor_stylsheets + surveyor_javascripts
|
@@ -25,14 +25,14 @@ module SurveyorHelper
|
|
25
25
|
submit_tag(section.title, :name => "section[#{section.id}]")
|
26
26
|
end
|
27
27
|
def previous_section
|
28
|
-
# submit_tag("&
|
28
|
+
# submit_tag("#{t ('surveyor.previous_section')} »", :name => "section[#{@section.previous.id}]") unless @section.previous.nil?
|
29
29
|
# refactored to use copy in memory instead of making extra db calls
|
30
|
-
submit_tag(
|
30
|
+
submit_tag(t('surveyor.previous_section'), :name => "section[#{@sections[@sections.index(@section)-1].id}]") unless @sections.first == @section
|
31
31
|
end
|
32
32
|
def next_section
|
33
|
-
# @section.next.nil? ? submit_tag(
|
33
|
+
# @section.next.nil? ? submit_tag(t ('surveyor.click_here_to_finish'), :name => "finish") : submit_tag("Next section «", :name => "section[#{@section.next.id}]")
|
34
34
|
# refactored to use copy in memory instead of making extra db calls
|
35
|
-
@sections.last == @section ? submit_tag(
|
35
|
+
@sections.last == @section ? submit_tag(t('surveyor.click_here_to_finish'), :name => "finish") : submit_tag(t('surveyor.next_section'), :name => "section[#{@sections[@sections.index(@section)+1].id}]")
|
36
36
|
end
|
37
37
|
|
38
38
|
# Questions
|
data/app/models/response_set.rb
CHANGED
@@ -66,14 +66,14 @@ class ResponseSet < ActiveRecord::Base
|
|
66
66
|
if (answer_id = responses_hash[:answer_id])
|
67
67
|
if (!responses_hash[:answer_id].empty?) # Dropdowns return answer id but have an empty value if they are not set... ignoring those.
|
68
68
|
#radio or dropdown - only one response
|
69
|
-
responses.build({:question_id => question_id, :answer_id => answer_id}.merge(responses_hash[answer_id] || {}))
|
69
|
+
responses.build({:question_id => question_id, :answer_id => answer_id, :survey_section_id => current_section_id}.merge(responses_hash[answer_id] || {}))
|
70
70
|
end
|
71
71
|
else
|
72
72
|
#possibly multiples responses - unresponded radios end up here too
|
73
73
|
# we use the variable question_id, not the "question_id" in the response_hash
|
74
74
|
responses_hash.delete_if{|k,v| k == "question_id"}.each do |answer_id, response_hash|
|
75
75
|
unless response_hash.delete_if{|k,v| v.blank?}.empty?
|
76
|
-
responses.build({:question_id => question_id, :answer_id => answer_id}.merge(response_hash))
|
76
|
+
responses.build({:question_id => question_id, :answer_id => answer_id, :survey_section_id => current_section_id}.merge(response_hash))
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -87,14 +87,14 @@ class ResponseSet < ActiveRecord::Base
|
|
87
87
|
if (answer_id = group_hash[:answer_id]) # if group_hash has an answer_id key we treat it differently
|
88
88
|
if (!group_hash[:answer_id].empty?) # dropdowns return empty values in answer_ids if they are not selected
|
89
89
|
#radio or dropdown - only one response
|
90
|
-
responses.build({:question_id => question_id, :answer_id => answer_id, :response_group => response_group_number}.merge(group_hash[answer_id] || {}))
|
90
|
+
responses.build({:question_id => question_id, :answer_id => answer_id, :response_group => response_group_number, :section_id => current_section_id}.merge(group_hash[answer_id] || {}))
|
91
91
|
end
|
92
92
|
else
|
93
93
|
#possibly multiples responses - unresponded radios end up here too
|
94
94
|
# we use the variable question_id in the key, not the "question_id" in the response_hash... same with response_group key
|
95
95
|
group_hash.delete_if{|k,v| (k == "question_id") or (k == "response_group")}.each do |answer_id, inner_hash|
|
96
96
|
unless inner_hash.delete_if{|k,v| v.blank?}.empty?
|
97
|
-
responses.build({:question_id => question_id, :answer_id => answer_id, :response_group => response_group_number}.merge(inner_hash))
|
97
|
+
responses.build({:question_id => question_id, :answer_id => answer_id, :response_group => response_group_number, :section_id => current_section_id}.merge(inner_hash))
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
@@ -153,7 +153,12 @@ class ResponseSet < ActiveRecord::Base
|
|
153
153
|
arr = dependencies.partition{|d| d.is_met?(self) }
|
154
154
|
{:show => arr[0].map{|d| d.question_group_id.nil? ? "question_#{d.question_id}" : "question_group_#{d.question_group_id}"}, :hide => arr[1].map{|d| d.question_group_id.nil? ? "question_#{d.question_id}" : "question_group_#{d.question_group_id}"}}
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
|
+
# Check existence of responses to questions from a given survey_section
|
158
|
+
def no_responses_for_section?(section)
|
159
|
+
self.responses.count(:conditions => {:survey_section_id => section.id}) == 0
|
160
|
+
end
|
161
|
+
|
157
162
|
protected
|
158
163
|
|
159
164
|
def dependencies(question_ids = nil)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class SurveySectionSweeper < ActionController::Caching::Sweeper
|
2
|
+
observer SurveySection
|
3
|
+
|
4
|
+
def after_save(section)
|
5
|
+
expire_cache(section)
|
6
|
+
end
|
7
|
+
|
8
|
+
def after_destroy(section)
|
9
|
+
expire_cache(section)
|
10
|
+
end
|
11
|
+
|
12
|
+
def expire_cache(section)
|
13
|
+
expire_fregment "section_#{section.id}"
|
14
|
+
end
|
15
|
+
end
|
@@ -19,7 +19,7 @@
|
|
19
19
|
%ol.answers
|
20
20
|
%li.answer
|
21
21
|
- options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
|
22
|
-
= renderer == :slider ? select_tag("responses[#{question.id}][answer_id]", options, {:id => "slider_#{question.id}"}) : select_tag("responses[#{question.id}][answer_id]", ["<option value=''
|
22
|
+
= renderer == :slider ? select_tag("responses[#{question.id}][answer_id]", options, {:id => "slider_#{question.id}"}) : select_tag("responses[#{question.id}][answer_id]", ["<option value=''>#{t('surveyor.Select_one')}</option>"].concat(options))
|
23
23
|
- when :grid_default
|
24
24
|
- reset_cycle("col")
|
25
25
|
- content_tag_for :tr, question, :class => question.css_class(response_set) do
|
@@ -69,4 +69,4 @@
|
|
69
69
|
%ol.answers{:class => renderer == :inline ? "inline" : nil}
|
70
70
|
- question.answers.each do |answer|
|
71
71
|
- content_tag_for :li, answer, :class => answer.custom_class do
|
72
|
-
= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
72
|
+
= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
@@ -0,0 +1,13 @@
|
|
1
|
+
- div_for @section, :class => @section.custom_class do
|
2
|
+
%span.title= @section.title
|
3
|
+
.questions
|
4
|
+
- group_questions ||= []
|
5
|
+
- @questions.each_with_index do |question, index|
|
6
|
+
- unless question.part_of_group?
|
7
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set})
|
8
|
+
- else # gather up the group questions
|
9
|
+
- group_questions << question
|
10
|
+
- if (index + 1 >= @questions.size) or (question.question_group_id != @questions[index + 1].question_group_id)
|
11
|
+
- # this is the last question of the section, or the group
|
12
|
+
= render(:partial => question.question_group.custom_renderer || "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
|
13
|
+
- group_questions = []
|
@@ -16,18 +16,13 @@
|
|
16
16
|
-# @dependents.each_with_index do |question, index|
|
17
17
|
= dependency_explanation_helper(question, @response_set)
|
18
18
|
= render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set, :number => "D#{index+1}"})
|
19
|
-
|
20
|
-
|
21
|
-
.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- group_questions << question
|
28
|
-
- if (index + 1 >= @questions.size) or (question.question_group_id != @questions[index + 1].question_group_id)
|
29
|
-
- # this is the last question of the section, or the group
|
30
|
-
= render(:partial => question.question_group.custom_renderer || "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
|
31
|
-
- group_questions = []
|
19
|
+
-# cache section if there are no responses for that section in th current response_set
|
20
|
+
- if @response_set.no_responses_for_section?(@section)
|
21
|
+
- cache("section_#{@section.id}") do
|
22
|
+
-# cache
|
23
|
+
= render(:partial => "/partials/section", :locals => {:section => @section, :questions => @questions, :response_set => @response_set})
|
24
|
+
- else
|
25
|
+
-# no cache
|
26
|
+
= render(:partial => "/partials/section", :locals => {:section => @section, :questions => @questions, :response_set => @response_set})
|
32
27
|
.next_section= next_section
|
33
|
-
|
28
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#surveyor
|
2
2
|
#header
|
3
|
-
.title=
|
3
|
+
.title= t ('surveyor.take_these_surveys')
|
4
4
|
%br
|
5
5
|
#survey_list
|
6
6
|
%ul
|
@@ -10,7 +10,7 @@
|
|
10
10
|
- form_tag(take_survey_path(:survey_code => survey.access_code)) do
|
11
11
|
= survey.title
|
12
12
|
|
13
|
-
= submit_tag(
|
13
|
+
= submit_tag( t ('surveyor.take_it') )
|
14
14
|
- else
|
15
15
|
%li
|
16
|
-
No surveys
|
16
|
+
No surveys
|
@@ -3,10 +3,13 @@
|
|
3
3
|
- div_for section do
|
4
4
|
.title= section.title
|
5
5
|
.questions
|
6
|
-
-
|
6
|
+
- group_questions ||= []
|
7
|
+
- section.questions.each_with_index do |question, index|
|
7
8
|
- if question.part_of_group?
|
8
|
-
-
|
9
|
+
- group_questions << question
|
10
|
+
- if (index + 1 >= section.questions.size) or (question.question_group_id != section.questions[index + 1].question_group_id)
|
9
11
|
- # skip to the last question of the section, or the last question of the group
|
10
|
-
= render(:partial => "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set})
|
12
|
+
= render(:partial => "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
|
13
|
+
- group_questions = []
|
11
14
|
- else
|
12
15
|
= render(:partial => "/partials/question", :locals => {:question => question, :response_set => @response_set})
|
data/features/surveyor.feature
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module SurveyExtensions
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ClassMethods)
|
4
|
+
base.send(:include, InstanceMethods)
|
5
|
+
base.class_eval do
|
6
|
+
# Same as typing in the class
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
# def title
|
16
|
+
# foo
|
17
|
+
# end
|
18
|
+
# def foo
|
19
|
+
# "bar"
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Add "survey" to config['extend'] array in config/initializers/surveyor.rb to activate these extensions
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SurveyorControllerExtensions
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ClassMethods)
|
4
|
+
base.send(:include, InstanceMethods)
|
5
|
+
base.class_eval do
|
6
|
+
# Same as typing in the class
|
7
|
+
# before_filter :pimp_my_ride
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
# def pimp_my_ride
|
16
|
+
# flash[:notice] = "pimped!"
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Actions
|
21
|
+
# Redefine the controller actions [index, new, create, show, update] here
|
22
|
+
# def new
|
23
|
+
# render :text =>"surveys are down"
|
24
|
+
# end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Add "surveyor_controller" to config['extend'] array in config/initializers/surveyor.rb to activate these extensions
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SurveyorHelperExtensions
|
2
|
+
def self.included(base) # :nodoc:
|
3
|
+
base.send(:include, InstanceMethods)
|
4
|
+
base.class_eval do
|
5
|
+
# Same as typing in the module
|
6
|
+
# alias_method_chain :question_number_helper, :sauce
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
# def question_number_helper_with_sauce(number)
|
12
|
+
# question_number_helper_without_sauce(number) + "Extra sauce"
|
13
|
+
# end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Add "surveyor_helper" to config['extend'] array in config/initializers/surveyor.rb to activate these extensions
|
@@ -26,7 +26,8 @@ class SurveyorGenerator < Rails::Generator::Base
|
|
26
26
|
"create_dependencies", "create_dependency_conditions",
|
27
27
|
"create_validations", "create_validation_conditions",
|
28
28
|
"add_display_order_to_surveys", "add_correct_answer_id_to_questions",
|
29
|
-
"add_index_to_response_sets", "add_index_to_surveys",
|
29
|
+
"add_index_to_response_sets", "add_index_to_surveys",
|
30
|
+
"add_unique_indicies", "add_section_id_to_responses"].each_with_index do |model, i|
|
30
31
|
unless (prev_migrations = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/[0-9]+_#{model}.rb$/)).empty?
|
31
32
|
prev_migration_timestamp = prev_migrations[0].match(/([0-9]+)_#{model}.rb$/)[1]
|
32
33
|
end
|
@@ -44,6 +45,13 @@ class SurveyorGenerator < Rails::Generator::Base
|
|
44
45
|
m.directory "public/stylesheets/sass"
|
45
46
|
m.file "assets/stylesheets/sass/surveyor.sass", "public/stylesheets/sass/surveyor.sass"
|
46
47
|
|
48
|
+
|
49
|
+
# Locales
|
50
|
+
m.directory "config/locales"
|
51
|
+
Dir.glob(File.join(File.dirname(__FILE__), "templates", "locales", "*.yml")).map{|path| File.basename(path)}.each do |filename|
|
52
|
+
m.file "locales/#{filename}", "config/locales/#{filename}"
|
53
|
+
end
|
54
|
+
|
47
55
|
# Surveys
|
48
56
|
m.directory "surveys/fixtures"
|
49
57
|
m.file "surveys/kitchen_sink_survey.rb", "surveys/kitchen_sink_survey.rb"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
+
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
en:
|
5
|
+
surveyor:
|
6
|
+
take_these_surveys: "You may take these surveys"
|
7
|
+
take_it: "Take it"
|
8
|
+
Completed_survey: "Completed survey"
|
9
|
+
Unable_to_find_your_responses: "Unable to find your responses to the survey"
|
10
|
+
Unable to_find_that_survey: "Unable to find that survey"
|
11
|
+
survey_started_success: "Survey started successfully"
|
12
|
+
click_here_to_finish: "Click here to finish"
|
13
|
+
previous_section: "« Previous section"
|
14
|
+
next_section: "Next section »"
|
15
|
+
Select_one: "Select one ..."
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Localization file for Hebrew. Add more files in this directory for other locales.
|
2
|
+
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
he:
|
5
|
+
surveyor:
|
6
|
+
take_these_surveys: "תוכלו לבצע סקרים אלו"
|
7
|
+
take_it: "בצע"
|
8
|
+
Completed_survey: "סיום הסקר"
|
9
|
+
Unable_to_find_your_responses: "לא נמצאו תשובותיך לסקר"
|
10
|
+
Unable to_find_that_survey: "לא ניתן לאתר את הסקר המבוקש"
|
11
|
+
survey_started_success: "הסקר הוחל בהצלחה"
|
12
|
+
click_here_to_finish: "לסיום"
|
13
|
+
previous_section: "חזרה »"
|
14
|
+
next_section: "« המשך"
|
15
|
+
Select_one: "בחר/י"
|
16
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddSectionIdToResponses < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :responses, :survey_section_id, :integer
|
4
|
+
add_index :responses, :survey_section_id
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_index :responses, :survey_section_id
|
9
|
+
remove_column :responses, :survey_section_id
|
10
|
+
end
|
11
|
+
end
|
@@ -4,7 +4,7 @@ module Surveyor
|
|
4
4
|
base.send :before_filter, :get_current_user, :only => [:new, :create]
|
5
5
|
base.send :layout, 'surveyor_default'
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
# Actions
|
9
9
|
def new
|
10
10
|
@surveys = Survey.find(:all)
|
@@ -16,10 +16,10 @@ module Surveyor
|
|
16
16
|
@survey = Survey.find_by_access_code(params[:survey_code])
|
17
17
|
@response_set = ResponseSet.create(:survey => @survey, :user_id => (@current_user.nil? ? @current_user : @current_user.id))
|
18
18
|
if (@survey && @response_set)
|
19
|
-
flash[:notice] =
|
19
|
+
flash[:notice] = t('surveyor.survey_started_success')
|
20
20
|
redirect_to(edit_my_survey_path(:survey_code => @survey.access_code, :response_set_code => @response_set.access_code))
|
21
21
|
else
|
22
|
-
flash[:notice] =
|
22
|
+
flash[:notice] = t('surveyor.Unable_to_find_that_survey')
|
23
23
|
redirect_to surveyor_index
|
24
24
|
end
|
25
25
|
end
|
@@ -27,6 +27,7 @@ module Surveyor
|
|
27
27
|
def show
|
28
28
|
@response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => [:question, :answer]})
|
29
29
|
if @response_set
|
30
|
+
@survey = @response_set.survey
|
30
31
|
respond_to do |format|
|
31
32
|
format.html #{render :action => :show}
|
32
33
|
format.csv {
|
@@ -34,7 +35,7 @@ module Surveyor
|
|
34
35
|
}
|
35
36
|
end
|
36
37
|
else
|
37
|
-
flash[:notice] =
|
38
|
+
flash[:notice] = t('surveyor.Unable_to_find_your_responses')
|
38
39
|
redirect_to surveyor_index
|
39
40
|
end
|
40
41
|
end
|
@@ -52,7 +53,7 @@ module Surveyor
|
|
52
53
|
@questions = @section.questions
|
53
54
|
@dependents = (@response_set.unanswered_dependencies - @section.questions) || []
|
54
55
|
else
|
55
|
-
flash[:notice] =
|
56
|
+
flash[:notice] = t('surveyor.Unable_to_find_your_responses')
|
56
57
|
redirect_to surveyor_index
|
57
58
|
end
|
58
59
|
end
|
@@ -63,7 +64,7 @@ module Surveyor
|
|
63
64
|
if @response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => :answer},:lock => true)
|
64
65
|
@response_set.current_section_id = params[:current_section_id]
|
65
66
|
else
|
66
|
-
flash[:notice] =
|
67
|
+
flash[:notice] = t('surveyor.Unable_to_find_your_responses')
|
67
68
|
redirect_to(available_surveys_path) and return
|
68
69
|
end
|
69
70
|
|
@@ -80,10 +81,10 @@ module Surveyor
|
|
80
81
|
respond_to do |format|
|
81
82
|
format.html do
|
82
83
|
if saved && params[:finish]
|
83
|
-
flash[:notice] =
|
84
|
+
flash[:notice] = t('surveyor.Completed_survey')
|
84
85
|
redirect_to surveyor_finish
|
85
86
|
else
|
86
|
-
flash[:notice] =
|
87
|
+
flash[:notice] = t('surveyor.Unable_to_update_survey') if !saved #and !saved.nil? # saved.nil? is true if there are no questions on the page (i.e. if it only contains a label)
|
87
88
|
redirect_to :action => "edit", :anchor => anchor_from(params[:section]), :params => {:section => section_id_from(params[:section])}
|
88
89
|
end
|
89
90
|
end
|
@@ -80,7 +80,7 @@ describe SurveyorController do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "view my survey: GET /surveys/xyz/pdq" do
|
83
|
-
|
83
|
+
#integrate_views
|
84
84
|
before(:each) do
|
85
85
|
@survey = Factory(:survey, :title => "xyz", :access_code => "xyz", :sections => [Factory(:survey_section)])
|
86
86
|
@response_set = Factory(:response_set, :access_code => "pdq", :survey => @survey)
|
@@ -105,11 +105,6 @@ describe SurveyorController do
|
|
105
105
|
do_get
|
106
106
|
end
|
107
107
|
|
108
|
-
it "should assign the found response_set and survey for the view" do
|
109
|
-
do_get
|
110
|
-
assigns[:response_set].should == @response_set
|
111
|
-
end
|
112
|
-
|
113
108
|
it "should redirect if :response_code not found" do
|
114
109
|
get :show, :survey_code => "xyz", :response_set_code => "DIFFERENT"
|
115
110
|
response.should redirect_to(available_surveys_url)
|
data/spec/factories.rb
CHANGED
@@ -80,6 +80,21 @@ describe ResponseSet, "Updating the response set" do
|
|
80
80
|
|
81
81
|
pending
|
82
82
|
end
|
83
|
+
describe "assoication of responses to a survey_section" do
|
84
|
+
before(:each) do
|
85
|
+
@section = Factory(:survey_section)
|
86
|
+
@response_set.current_section_id = @section.id
|
87
|
+
end
|
88
|
+
it "should detect existence of responses to questions that belong to a given survey_section" do
|
89
|
+
@response_set.update_attributes(:response_attributes => @radio_response_attributes)
|
90
|
+
@response_set.no_responses_for_section?(@section).should be_false
|
91
|
+
end
|
92
|
+
it "should detect absence of responses to questions that belong to a given survey_section" do
|
93
|
+
@response_set.update_attributes(:response_attributes => @radio_response_attributes) #responses are associated with @section
|
94
|
+
@another_section = Factory(:survey_section)
|
95
|
+
@response_set.no_responses_for_section?(@another_section).should be_true
|
96
|
+
end
|
97
|
+
end
|
83
98
|
end
|
84
99
|
|
85
100
|
describe ResponseSet, "with dependencies" do
|
@@ -242,4 +257,4 @@ describe ResponseSet, "exporting csv" do
|
|
242
257
|
csv.should match "What flavor?"
|
243
258
|
csv.should match /pecan pie/
|
244
259
|
end
|
245
|
-
end
|
260
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe "surveyor/show" do
|
5
|
+
before(:each) do
|
6
|
+
@survey = Factory(:survey, :title => "xyz", :access_code => "xyz", :sections => [Factory(:survey_section)])
|
7
|
+
@survey.sections.first.questions=Array.new(3) {Factory(:question)}
|
8
|
+
template.stub!(:next_number).and_return(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should render _question partial,if question is not part of a question_group" do
|
12
|
+
@survey.sections.first.questions.each{|q| q.stub(:part_of_group?).and_return(false)}
|
13
|
+
assigns[:survey] = @survey
|
14
|
+
expect_render_partial_calls('question', 3)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should render _question_group partial for a group of questions" do
|
18
|
+
question_group = Factory.create(:question_group)
|
19
|
+
# Assosciate all questions with the question_group
|
20
|
+
@survey.sections.first.questions.each{|q| q.question_group = question_group}
|
21
|
+
assigns[:survey] = @survey
|
22
|
+
expect_render_partial_calls('question_group', 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
def expect_render_partial_calls(partial_name, num_calls)
|
26
|
+
# Excpection regaring calls to render :partial
|
27
|
+
template.should_receive(:render).exactly(num_calls).times.with(hash_including(:partial => "/partials/#{partial_name}"))
|
28
|
+
render "surveyor/show.html.haml"
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
data/surveyor.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{surveyor}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.14.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Chamberlain", "Mark Yoon"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-24}
|
13
13
|
s.email = %q{yoon@northwestern.edu}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.md"
|
@@ -32,12 +32,14 @@ Gem::Specification.new do |s|
|
|
32
32
|
"app/models/response_set.rb",
|
33
33
|
"app/models/survey.rb",
|
34
34
|
"app/models/survey_section.rb",
|
35
|
+
"app/models/survey_section_sweeper.rb",
|
35
36
|
"app/models/validation.rb",
|
36
37
|
"app/models/validation_condition.rb",
|
37
38
|
"app/views/layouts/surveyor_default.html.erb",
|
38
39
|
"app/views/partials/_answer.html.haml",
|
39
40
|
"app/views/partials/_question.html.haml",
|
40
41
|
"app/views/partials/_question_group.html.haml",
|
42
|
+
"app/views/partials/_section.html.haml",
|
41
43
|
"app/views/surveyor/edit.html.haml",
|
42
44
|
"app/views/surveyor/new.html.haml",
|
43
45
|
"app/views/surveyor/show.html.haml",
|
@@ -49,8 +51,11 @@ Gem::Specification.new do |s|
|
|
49
51
|
"features/surveyor.feature",
|
50
52
|
"generators/extend_surveyor/extend_surveyor_generator.rb",
|
51
53
|
"generators/extend_surveyor/templates/EXTENDING_SURVEYOR",
|
54
|
+
"generators/extend_surveyor/templates/extensions/survey_extensions.rb",
|
52
55
|
"generators/extend_surveyor/templates/extensions/surveyor_controller.rb",
|
56
|
+
"generators/extend_surveyor/templates/extensions/surveyor_controller_extensions.rb",
|
53
57
|
"generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb",
|
58
|
+
"generators/extend_surveyor/templates/extensions/surveyor_helper_extensions.rb",
|
54
59
|
"generators/surveyor/surveyor_generator.rb",
|
55
60
|
"generators/surveyor/templates/README",
|
56
61
|
"generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif",
|
@@ -104,10 +109,13 @@ Gem::Specification.new do |s|
|
|
104
109
|
"generators/surveyor/templates/assets/stylesheets/reset.css",
|
105
110
|
"generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass",
|
106
111
|
"generators/surveyor/templates/assets/stylesheets/ui.theme.css",
|
112
|
+
"generators/surveyor/templates/locales/surveyor_en.yml",
|
113
|
+
"generators/surveyor/templates/locales/surveyor_he.yml",
|
107
114
|
"generators/surveyor/templates/migrate/add_correct_answer_id_to_questions.rb",
|
108
115
|
"generators/surveyor/templates/migrate/add_display_order_to_surveys.rb",
|
109
116
|
"generators/surveyor/templates/migrate/add_index_to_response_sets.rb",
|
110
117
|
"generators/surveyor/templates/migrate/add_index_to_surveys.rb",
|
118
|
+
"generators/surveyor/templates/migrate/add_section_id_to_responses.rb",
|
111
119
|
"generators/surveyor/templates/migrate/add_unique_indicies.rb",
|
112
120
|
"generators/surveyor/templates/migrate/create_answers.rb",
|
113
121
|
"generators/surveyor/templates/migrate/create_dependencies.rb",
|
@@ -171,6 +179,7 @@ Gem::Specification.new do |s|
|
|
171
179
|
"spec/rcov.opts",
|
172
180
|
"spec/spec.opts",
|
173
181
|
"spec/spec_helper.rb",
|
182
|
+
"spec/views/surveyor/show.html.haml_spec.rb",
|
174
183
|
"surveyor.gemspec",
|
175
184
|
"uninstall.rb"
|
176
185
|
]
|
@@ -194,7 +203,8 @@ Gem::Specification.new do |s|
|
|
194
203
|
"spec/models/survey_spec.rb",
|
195
204
|
"spec/models/validation_condition_spec.rb",
|
196
205
|
"spec/models/validation_spec.rb",
|
197
|
-
"spec/spec_helper.rb"
|
206
|
+
"spec/spec_helper.rb",
|
207
|
+
"spec/views/surveyor/show.html.haml_spec.rb"
|
198
208
|
]
|
199
209
|
|
200
210
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surveyor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 39
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 14
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.14.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Chamberlain
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-08-
|
19
|
+
date: 2010-08-24 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -73,12 +73,14 @@ files:
|
|
73
73
|
- app/models/response_set.rb
|
74
74
|
- app/models/survey.rb
|
75
75
|
- app/models/survey_section.rb
|
76
|
+
- app/models/survey_section_sweeper.rb
|
76
77
|
- app/models/validation.rb
|
77
78
|
- app/models/validation_condition.rb
|
78
79
|
- app/views/layouts/surveyor_default.html.erb
|
79
80
|
- app/views/partials/_answer.html.haml
|
80
81
|
- app/views/partials/_question.html.haml
|
81
82
|
- app/views/partials/_question_group.html.haml
|
83
|
+
- app/views/partials/_section.html.haml
|
82
84
|
- app/views/surveyor/edit.html.haml
|
83
85
|
- app/views/surveyor/new.html.haml
|
84
86
|
- app/views/surveyor/show.html.haml
|
@@ -90,8 +92,11 @@ files:
|
|
90
92
|
- features/surveyor.feature
|
91
93
|
- generators/extend_surveyor/extend_surveyor_generator.rb
|
92
94
|
- generators/extend_surveyor/templates/EXTENDING_SURVEYOR
|
95
|
+
- generators/extend_surveyor/templates/extensions/survey_extensions.rb
|
93
96
|
- generators/extend_surveyor/templates/extensions/surveyor_controller.rb
|
97
|
+
- generators/extend_surveyor/templates/extensions/surveyor_controller_extensions.rb
|
94
98
|
- generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb
|
99
|
+
- generators/extend_surveyor/templates/extensions/surveyor_helper_extensions.rb
|
95
100
|
- generators/surveyor/surveyor_generator.rb
|
96
101
|
- generators/surveyor/templates/README
|
97
102
|
- generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif
|
@@ -145,10 +150,13 @@ files:
|
|
145
150
|
- generators/surveyor/templates/assets/stylesheets/reset.css
|
146
151
|
- generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass
|
147
152
|
- generators/surveyor/templates/assets/stylesheets/ui.theme.css
|
153
|
+
- generators/surveyor/templates/locales/surveyor_en.yml
|
154
|
+
- generators/surveyor/templates/locales/surveyor_he.yml
|
148
155
|
- generators/surveyor/templates/migrate/add_correct_answer_id_to_questions.rb
|
149
156
|
- generators/surveyor/templates/migrate/add_display_order_to_surveys.rb
|
150
157
|
- generators/surveyor/templates/migrate/add_index_to_response_sets.rb
|
151
158
|
- generators/surveyor/templates/migrate/add_index_to_surveys.rb
|
159
|
+
- generators/surveyor/templates/migrate/add_section_id_to_responses.rb
|
152
160
|
- generators/surveyor/templates/migrate/add_unique_indicies.rb
|
153
161
|
- generators/surveyor/templates/migrate/create_answers.rb
|
154
162
|
- generators/surveyor/templates/migrate/create_dependencies.rb
|
@@ -212,6 +220,7 @@ files:
|
|
212
220
|
- spec/rcov.opts
|
213
221
|
- spec/spec.opts
|
214
222
|
- spec/spec_helper.rb
|
223
|
+
- spec/views/surveyor/show.html.haml_spec.rb
|
215
224
|
- surveyor.gemspec
|
216
225
|
- uninstall.rb
|
217
226
|
has_rdoc: true
|
@@ -264,3 +273,4 @@ test_files:
|
|
264
273
|
- spec/models/validation_condition_spec.rb
|
265
274
|
- spec/models/validation_spec.rb
|
266
275
|
- spec/spec_helper.rb
|
276
|
+
- spec/views/surveyor/show.html.haml_spec.rb
|