surveyor 0.6.1 → 0.6.2

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 CHANGED
@@ -7,13 +7,15 @@ Surveyor is a rails (gem) plugin, that brings surveys to your rails app. Before
7
7
  As a plugin:
8
8
 
9
9
  sudo gem install haml
10
- script/plugin install git://github.com/breakpointer/surveyor.git
10
+ script/plugin install git://github.com/breakpointer/surveyor.git -r 'tag v0.6.2'
11
11
 
12
12
  Or as a gem plugin:
13
13
 
14
14
  # in environment.rb
15
- config.gem "surveyor", :version => '>=0.4.1', :lib => false
15
+ config.gem "surveyor", :version => '>=0.6.1', :source => 'http://gemcutter.org'
16
16
 
17
+ sudo gem install gemcutter
18
+ gem tumble
17
19
  sudo rake gems:install
18
20
 
19
21
  Generate assets, run migrations:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.6.2
@@ -53,11 +53,9 @@ module SurveyorHelper
53
53
  end
54
54
 
55
55
  # Answers
56
- def fields_for_response(response, &block)
57
- fields_for("responses[#{response.question_id}][#{response.answer_id}]", response, :builder => SurveyFormBuilder, &block)
58
- end
59
- def fields_for_repeater_response(response, response_group, &block) # Changes the response hash to accept response groups for repeater elements
60
- fields_for("response_groups[#{response.question_id}][#{response_group}][#{response.answer_id}]", response, :builder => SurveyFormBuilder, &block)
56
+ def fields_for_response(response, response_group = nil, &block)
57
+ name = response_group.nil? ? "responses[#{response.question_id}][#{response.answer_id}]" : "response_groups[#{response.question_id}][#{response_group}][#{response.answer_id}]"
58
+ fields_for(name, response, :builder => SurveyFormBuilder, &block)
61
59
  end
62
60
  def fields_for_radio(response, &block)
63
61
  fields_for("responses[#{response.question_id}]", response, :builder => SurveyFormBuilder, &block)
@@ -29,38 +29,16 @@ class ResponseSet < ActiveRecord::Base
29
29
  end
30
30
 
31
31
  def response_for(question_id, answer_id, group = nil)
32
- response_group = group.nil? ? nil : group.to_s # for PostgreSql 8.3 compatibility - response_group is a string
33
- # found = responses.find_by_question_id_and_answer_id_and_response_group(question_id, answer_id, response_group)
34
- found = responses.detect{|r| r.question_id == question_id && r.answer_id == answer_id && r.response_group == response_group}
35
- found.blank? ? responses.new(:question_id => question_id, :answer_id => answer_id, :response_group => response_group) : found
32
+ found = responses.detect{|r| r.question_id == question_id && r.answer_id == answer_id && r.response_group.to_s == group.to_s}
33
+ found.blank? ? responses.new(:question_id => question_id, :answer_id => answer_id, :response_group => group) : found
36
34
  end
37
35
 
38
36
  def clear_responses
39
37
  question_ids = Question.find_all_by_survey_section_id(current_section_id).map(&:id)
40
- # logger.warn "responses: #{responses.inspect}\n"
41
38
  responses.select{|r| question_ids.include? r.question_id}.map(&:destroy)
42
39
  responses.reload
43
- # logger.warn "responses: #{responses.inspect}\n"
44
40
  end
45
41
 
46
- # "responses"=>{
47
- #string "6"=>{"question_id"=>"6", "20"=>{"string_value"=>"saf"}},
48
- #text "7"=>{"question_id"=>"7", "21"=>{"text_value"=>""}},
49
- #radio+txt "1"=>{"question_id"=>"1", "answer_id"=>"1", "4"=>{"string_value"=>""}},
50
- #radio "2"=>{"answer_id"=>"6"},
51
- #radio "3"=>{"answer_id"=>"10"},
52
- #check "4"=>{"question_id"=>"4", "answer_id"=>"15"},
53
- #check+txt "5"=>{"question_id"=>"5", "16"=>{"selected"=>"1"}, "19"=>{"string_value"=>""}}
54
- # },
55
- # "survey_code"=>"test_survey",
56
- # "commit"=>"Next Section (Utensiles and you!) >>",
57
- # "authenticity_token"=>"8bee21081eea820ab1c658358c0baaa2e46de5d1",
58
- # "_method"=>"put",
59
- # "action"=>"update",
60
- # "controller"=>"app",
61
- # "response_set_code"=>"T2x8HhCQej",
62
- # "section"=>"2"
63
-
64
42
  def response_attributes=(response_attributes)
65
43
  response_attributes.each do |question_id, responses_hash|
66
44
  # Response.delete_all(["response_set_id =? AND question_id =?", self.id, question_id])
@@ -80,39 +58,7 @@ class ResponseSet < ActiveRecord::Base
80
58
  end
81
59
  end
82
60
  end
83
-
84
- # "24"=>{
85
- # "0"=>{"response_group"=>"0", "question_id"=>"24", "answer_id"=>"172"}, "1"=>{"response_group"=>"1", "question_id"=>"24", "answer_id"=>"173"},
86
- # "2"=>{"response_group"=>"2", "question_id"=>"24", "answer_id"=>""}, "3"=>{"response_group"=>"3", "question_id"=>"24", "answer_id"=>""},
87
- # "4"=>{"response_group"=>"4", "question_id"=>"24", "answer_id"=>""}},
88
- # where "24" is the question id
89
-
90
- # Some other examples:
91
- # "25"=>{
92
- # "0"=>{"response_group"=>"0", "question_id"=>"25", "179"=>{"string_value"=>"camry"}},
93
- # "1"=>{"response_group"=>"1", "question_id"=>"25", "179"=>{"string_value"=>"f150"}},
94
- # "2"=>{"response_group"=>"2", "question_id"=>"25", "179"=>{"string_value"=>""}},
95
- # "3"=>{"response_group"=>"3", "question_id"=>"25", "179"=>{"string_value"=>""}},
96
- # "4"=>{"response_group"=>"4", "question_id"=>"25", "179"=>{"string_value"=>""}}},
97
- #
98
- # "26"=>{
99
- # "0"=>{"response_group"=>"0", "question_id"=>"26", "180"=>{"string_value"=>"1999"}},
100
- # "1"=>{"response_group"=>"1", "question_id"=>"26", "180"=>{"string_value"=>"2004"}},
101
- # "2"=>{"response_group"=>"2", "question_id"=>"26", "180"=>{"string_value"=>""}},
102
- # "3"=>{"response_group"=>"3", "question_id"=>"26", "180"=>{"string_value"=>""}},
103
- # "4"=>{"response_group"=>"4", "question_id"=>"26", "180"=>{"string_value"=>""}}},
104
- #
105
- # "27"=>{
106
- # "0"=>{"182"=>{"integer_value"=>""}, "response_group"=>"0", "question_id"=>"27", "181"=>{"string_value"=>""}},
107
- # "1"=>{"182"=>{"integer_value"=>""}, "response_group"=>"1", "question_id"=>"27", "181"=>{"string_value"=>""}},
108
- # "2"=>{"182"=>{"integer_value"=>""}, "response_group"=>"2", "question_id"=>"27", "181"=>{"string_value"=>""}},
109
- # "3"=>{"182"=>{"integer_value"=>""}, "response_group"=>"3", "question_id"=>"27", "181"=>{"string_value"=>""}},
110
- # "4"=>{"182"=>{"integer_value"=>""}, "response_group"=>"4", "question_id"=>"27", "181"=>{"string_value"=>""}}}},
111
-
112
- # 0,1,2,3,4 are the response group numbers
113
- # and anything else in the response group hash is handled normally
114
-
115
- # method to process responses in response groups
61
+
116
62
  def response_group_attributes=(response_attributes)
117
63
  response_attributes.each do |question_id, responses_group_hash|
118
64
  # Response.delete_all(["response_set_id =? AND question_id =?", self.id, question_id])
@@ -136,41 +82,27 @@ class ResponseSet < ActiveRecord::Base
136
82
  end
137
83
  end
138
84
 
139
- def find_response(answer_id)
140
- self.responses.find_by_answer_id(answer_id)
141
- end
142
-
143
85
  def save_responses
144
- responses.each do |response|
145
- response.save(false)
146
- end
147
- end
148
-
149
- # ResponseSet has an awareness of its internal state
150
- def empty?
151
- self.responses.empty?
86
+ responses.each{|response| response.save(false)}
152
87
  end
153
88
 
154
89
  def complete!
155
90
  self.completed_at = Time.now
156
91
  end
157
92
 
158
- def has_answered_question?(question)
159
- !has_not_answered_question?(question)
160
- end
161
-
162
93
  def has_not_answered_question?(question)
163
94
  self.responses.find_all_by_question_id(question.id).empty?
164
95
  end
165
96
 
166
97
  # Returns the number of response groups (count of group responses enterted) for this question group
167
98
  def count_group_responses(questions)
168
- questions.map{|q| responses.select{|r| r.question_id == q.id && !r.response_group.nil?}.size }.max
99
+ questions.map{|q| responses.select{|r| (r.question_id.to_i == q.id.to_i) && !r.response_group.nil?}.group_by(&:response_group).size }.max
169
100
  end
170
101
 
171
102
  def unanswered_dependencies
172
103
  dependencies.select{|d| d.met?(self) and self.has_not_answered_question?(d.question)}.map(&:question)
173
104
  end
105
+
174
106
  def all_dependencies
175
107
  arr = dependencies.partition{|d| d.met?(self) }
176
108
  {:show => arr[0].map{|d| "question_#{d.question_id}"}, :hide => arr[1].map{|d| "question_#{d.question_id}"}}
@@ -183,3 +115,56 @@ class ResponseSet < ActiveRecord::Base
183
115
  Dependency.depending_on_questions(question_ids)
184
116
  end
185
117
  end
118
+
119
+ # responses
120
+
121
+ # "responses"=>{
122
+ #string "6"=>{"question_id"=>"6", "20"=>{"string_value"=>"saf"}},
123
+ #text "7"=>{"question_id"=>"7", "21"=>{"text_value"=>""}},
124
+ #radio+txt "1"=>{"question_id"=>"1", "answer_id"=>"1", "4"=>{"string_value"=>""}},
125
+ #radio "2"=>{"answer_id"=>"6"},
126
+ #radio "3"=>{"answer_id"=>"10"},
127
+ #check "4"=>{"question_id"=>"4", "answer_id"=>"15"},
128
+ #check+txt "5"=>{"question_id"=>"5", "16"=>{"selected"=>"1"}, "19"=>{"string_value"=>""}}
129
+ # },
130
+ # "survey_code"=>"test_survey",
131
+ # "commit"=>"Next Section (Utensiles and you!) >>",
132
+ # "authenticity_token"=>"8bee21081eea820ab1c658358c0baaa2e46de5d1",
133
+ # "_method"=>"put",
134
+ # "action"=>"update",
135
+ # "controller"=>"app",
136
+ # "response_set_code"=>"T2x8HhCQej",
137
+ # "section"=>"2"
138
+
139
+ # response groups
140
+
141
+ # "24"=>{
142
+ # "0"=>{"response_group"=>"0", "question_id"=>"24", "answer_id"=>"172"}, "1"=>{"response_group"=>"1", "question_id"=>"24", "answer_id"=>"173"},
143
+ # "2"=>{"response_group"=>"2", "question_id"=>"24", "answer_id"=>""}, "3"=>{"response_group"=>"3", "question_id"=>"24", "answer_id"=>""},
144
+ # "4"=>{"response_group"=>"4", "question_id"=>"24", "answer_id"=>""}},
145
+ # where "24" is the question id
146
+
147
+ # Some other examples:
148
+ # "25"=>{
149
+ # "0"=>{"response_group"=>"0", "question_id"=>"25", "179"=>{"string_value"=>"camry"}},
150
+ # "1"=>{"response_group"=>"1", "question_id"=>"25", "179"=>{"string_value"=>"f150"}},
151
+ # "2"=>{"response_group"=>"2", "question_id"=>"25", "179"=>{"string_value"=>""}},
152
+ # "3"=>{"response_group"=>"3", "question_id"=>"25", "179"=>{"string_value"=>""}},
153
+ # "4"=>{"response_group"=>"4", "question_id"=>"25", "179"=>{"string_value"=>""}}},
154
+ #
155
+ # "26"=>{
156
+ # "0"=>{"response_group"=>"0", "question_id"=>"26", "180"=>{"string_value"=>"1999"}},
157
+ # "1"=>{"response_group"=>"1", "question_id"=>"26", "180"=>{"string_value"=>"2004"}},
158
+ # "2"=>{"response_group"=>"2", "question_id"=>"26", "180"=>{"string_value"=>""}},
159
+ # "3"=>{"response_group"=>"3", "question_id"=>"26", "180"=>{"string_value"=>""}},
160
+ # "4"=>{"response_group"=>"4", "question_id"=>"26", "180"=>{"string_value"=>""}}},
161
+ #
162
+ # "27"=>{
163
+ # "0"=>{"182"=>{"integer_value"=>""}, "response_group"=>"0", "question_id"=>"27", "181"=>{"string_value"=>""}},
164
+ # "1"=>{"182"=>{"integer_value"=>""}, "response_group"=>"1", "question_id"=>"27", "181"=>{"string_value"=>""}},
165
+ # "2"=>{"182"=>{"integer_value"=>""}, "response_group"=>"2", "question_id"=>"27", "181"=>{"string_value"=>""}},
166
+ # "3"=>{"182"=>{"integer_value"=>""}, "response_group"=>"3", "question_id"=>"27", "181"=>{"string_value"=>""}},
167
+ # "4"=>{"182"=>{"integer_value"=>""}, "response_group"=>"4", "question_id"=>"27", "181"=>{"string_value"=>""}}}},
168
+
169
+ # 0,1,2,3,4 are the response group numbers
170
+ # and anything else in the response group hash is handled normally
@@ -1,8 +1,8 @@
1
1
  - renderer = answer.renderer(question)
2
+ - response_group ||= nil
2
3
  - hide_label ||= false
3
4
  - disabled ||= false
4
-
5
- - fields_for_response(response_obj) do |response_form|
5
+ - fields_for_response(response_obj, response_group) do |response_form|
6
6
  - case renderer
7
7
  - when :any_answer
8
8
  = response_form.survey_check_box(:selected)
@@ -1,6 +1,5 @@
1
1
  - renderer = question.renderer(question_group ||= nil)
2
2
  - dep_class = question.dep_class(response_set)
3
-
4
3
  - case renderer
5
4
  - when :label
6
5
  - div_for question, :class => "label #{dep_class}" do
@@ -45,11 +44,11 @@
45
44
  - if renderer == :repeater_default
46
45
  - question.answers.each do |answer|
47
46
  - content_tag_for :li, answer do
48
- = render(:partial => "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :response_group => response_group, :hide_label => true, :disabled => disabled})
47
+ = render(:partial => "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id, response_group), :response_group => response_group, :hide_label => true, :disabled => disabled})
49
48
  - else
50
49
  %li.answer
51
- - options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
52
- = select_tag("responses[#{question.id}][answer_id]", ["<option value=''>Select one...</option>"].concat(options))
50
+ - options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id, response_group).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
51
+ = select_tag("response_groups[#{question.id}][#{response_group}][answer_id]", ["<option value=''>Select one...</option>"].concat(options), :disabled => disabled)
53
52
  - when :inline_default, :inline_dropdown
54
53
  - div_for question, :class => "inline #{dep_class}" do
55
54
  = hidden_field_tag("responses[#{question.id}][question_id]", question.id)
@@ -19,11 +19,12 @@
19
19
  - div_for @section do
20
20
  %span.title= @section.title
21
21
  .questions
22
+ - group_questions ||= []
22
23
  - @section.questions.each_with_index do |question, index|
23
24
  - unless question.part_of_group?
24
25
  = render(:partial => "/partials/question", :locals => {:question => question, :response_set => @response_set})
25
26
  - else # gather up the group questions
26
- - (group_questions ||= []) << question
27
+ - group_questions << question
27
28
  - if (index + 1 >= @section.questions.size) or (question.question_group_id != @section.questions[index + 1].question_group_id)
28
29
  - # this is the last question of the section, or the group
29
30
  = render(:partial => "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{surveyor}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.2"
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{2009-10-12}
12
+ s.date = %q{2009-10-13}
13
13
  s.email = %q{yoon@northwestern.edu}
14
14
  s.extra_rdoc_files = [
15
15
  "README.md"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surveyor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Chamberlain
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-12 00:00:00 -05:00
13
+ date: 2009-10-13 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency