surveyor 0.21.0 → 0.22.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 +1 -0
- data/Gemfile +0 -6
- data/README.md +40 -14
- data/app/helpers/surveyor_helper.rb +1 -85
- data/app/views/partials/_answer.html.haml +5 -4
- data/app/views/partials/_question.html.haml +7 -5
- data/app/views/partials/_question_group.html.haml +2 -2
- data/app/views/surveyor/export.json.rabl +75 -0
- data/app/views/surveyor/show.html.haml +75 -13
- data/app/views/surveyor/show.json.rabl +14 -0
- data/config/routes.rb +2 -3
- data/doc/surveyor reject or delete decision matrix.png +0 -0
- data/features/export_to_json.feature +96 -0
- data/features/show_survey.feature +42 -0
- data/features/step_definitions/{common_setps.rb → common_steps.rb} +0 -0
- data/features/step_definitions/surveyor_steps.rb +46 -12
- data/features/step_definitions/web_steps.rb +15 -5
- data/features/support/paths.rb +2 -1
- data/features/surveyor.feature +192 -41
- data/features/surveyor_parser.feature +10 -10
- data/features/{redcap_parser.feature → z_redcap_parser.feature} +9 -6
- data/lib/formtastic/surveyor_builder.rb +1 -4
- data/lib/generators/surveyor/install_generator.rb +6 -5
- data/lib/generators/surveyor/templates/db/migrate/add_api_id_to_question_groups.rb +9 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids_to_response_sets_and_responses.rb +11 -0
- data/lib/generators/surveyor/templates/public/javascripts/surveyor/jquery-ui-timepicker-addon.js +1277 -0
- data/lib/generators/surveyor/templates/public/javascripts/surveyor/jquery-ui.js +11729 -0
- data/lib/generators/surveyor/templates/public/javascripts/surveyor/jquery.surveyor.js +54 -10
- data/lib/generators/surveyor/templates/public/stylesheets/sass/surveyor.sass +1 -1
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/jquery-ui-timepicker-addon.css +6 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/jquery-ui.custom.css +572 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-icons_ef8c08_256x240.png +0 -0
- data/lib/generators/surveyor/templates/public/stylesheets/surveyor/ui-icons_ffffff_256x240.png +0 -0
- data/lib/generators/surveyor/templates/surveys/EXTENDING_SURVEYOR.md +14 -0
- data/lib/generators/surveyor/templates/surveys/MODIFYING_SURVEYOR.md +91 -0
- data/lib/generators/surveyor/templates/surveys/date_survey.rb +15 -0
- data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +2 -2
- data/lib/surveyor/common.rb +31 -4
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +99 -0
- data/lib/surveyor/models/answer_methods.rb +6 -5
- data/lib/surveyor/models/dependency_condition_methods.rb +0 -1
- data/lib/surveyor/models/dependency_methods.rb +1 -1
- data/lib/surveyor/models/question_group_methods.rb +5 -0
- data/lib/surveyor/models/question_methods.rb +5 -2
- data/lib/surveyor/models/response_methods.rb +44 -3
- data/lib/surveyor/models/response_set_methods.rb +14 -4
- data/lib/surveyor/models/survey_methods.rb +8 -2
- data/lib/surveyor/models/survey_section_methods.rb +13 -1
- data/lib/surveyor/parser.rb +18 -11
- data/lib/surveyor/render_text.rb +19 -0
- data/lib/surveyor/surveyor_controller_methods.rb +19 -1
- data/lib/surveyor/unparser.rb +1 -1
- data/lib/surveyor/version.rb +1 -1
- data/lib/tasks/surveyor_tasks.rake +1 -1
- data/spec/controllers/surveyor_controller_spec.rb +7 -3
- data/spec/helpers/surveyor_helper_spec.rb +104 -9
- data/spec/lib/chinese_survey.rb +14 -0
- data/spec/lib/common_spec.rb +52 -1
- data/spec/lib/rake_kitchen_sink.rb +40 -0
- data/spec/models/answer_spec.rb +11 -0
- data/spec/models/question_spec.rb +15 -0
- data/spec/models/response_set_spec.rb +45 -1
- data/spec/models/response_spec.rb +7 -4
- data/surveyor.gemspec +4 -2
- metadata +99 -40
- data/app/controllers/results_controller.rb +0 -13
- data/app/views/results/index.html.erb +0 -17
- data/app/views/results/show.html.erb +0 -25
@@ -76,15 +76,18 @@ module Surveyor
|
|
76
76
|
|
77
77
|
def default_args
|
78
78
|
self.started_at ||= Time.now
|
79
|
-
self.access_code
|
79
|
+
self.access_code ||= random_unique_access_code
|
80
|
+
self.api_id ||= Surveyor::Common.generate_api_id
|
80
81
|
end
|
81
|
-
|
82
|
-
def
|
82
|
+
|
83
|
+
def random_unique_access_code
|
84
|
+
val = Surveyor::Common.make_tiny_code
|
83
85
|
while ResponseSet.find_by_access_code(val)
|
84
86
|
val = Surveyor::Common.make_tiny_code
|
85
87
|
end
|
86
|
-
|
88
|
+
val
|
87
89
|
end
|
90
|
+
private :random_unique_access_code
|
88
91
|
|
89
92
|
def to_csv(access_code = false, print_header = true)
|
90
93
|
qcols = Question.content_columns.map(&:name) - %w(created_at updated_at)
|
@@ -99,6 +102,13 @@ module Surveyor
|
|
99
102
|
end
|
100
103
|
result
|
101
104
|
end
|
105
|
+
|
106
|
+
def to_json
|
107
|
+
template_path = ActionController::Base.view_paths.find("show", ["surveyor"], false, {:handlers=>[:rabl], :locale=>[:en], :formats=>[:json]}, [], []).inspect
|
108
|
+
engine = Rabl::Engine.new(File.read(template_path))
|
109
|
+
engine.render(nil, {:object => self})
|
110
|
+
end
|
111
|
+
|
102
112
|
def complete!
|
103
113
|
self.completed_at = Time.now
|
104
114
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'surveyor/common'
|
2
2
|
|
3
3
|
module Surveyor
|
4
4
|
module Models
|
@@ -38,7 +38,7 @@ module Surveyor
|
|
38
38
|
|
39
39
|
def default_args
|
40
40
|
self.inactive_at ||= DateTime.now
|
41
|
-
self.api_id ||=
|
41
|
+
self.api_id ||= Surveyor::Common.generate_api_id
|
42
42
|
self.display_order ||= Survey.count
|
43
43
|
end
|
44
44
|
|
@@ -76,6 +76,12 @@ module Surveyor
|
|
76
76
|
self.active_at = nil if !datetime.nil? and !self.active_at.nil? and self.active_at > datetime
|
77
77
|
super(datetime)
|
78
78
|
end
|
79
|
+
def to_json
|
80
|
+
template_path = ActionController::Base.view_paths.find("export", ["surveyor"], false, {:handlers=>[:rabl], :locale=>[:en], :formats=>[:json]}, [], []).inspect
|
81
|
+
engine = Rabl::Engine.new(File.read(template_path))
|
82
|
+
engine.render(nil, {:object => self})
|
83
|
+
end
|
84
|
+
|
79
85
|
end
|
80
86
|
end
|
81
87
|
end
|
@@ -30,7 +30,19 @@ module Surveyor
|
|
30
30
|
def default_args
|
31
31
|
self.data_export_identifier ||= Surveyor::Common.normalize(title)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
|
+
def questions_and_groups
|
35
|
+
qs = []
|
36
|
+
questions.each_with_index.map do |q,i|
|
37
|
+
if q.part_of_group?
|
38
|
+
if (i+1 >= questions.size) or (q.question_group_id != questions[i+1].question_group_id)
|
39
|
+
q.question_group
|
40
|
+
end
|
41
|
+
else
|
42
|
+
q
|
43
|
+
end
|
44
|
+
end.compact
|
45
|
+
end
|
34
46
|
end
|
35
47
|
end
|
36
48
|
end
|
data/lib/surveyor/parser.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
%w(survey survey_section question_group question dependency dependency_condition answer validation validation_condition).each {|model| require model }
|
2
2
|
module Surveyor
|
3
3
|
class Parser
|
4
|
+
class << self; attr_accessor :options end
|
5
|
+
|
4
6
|
# Attributes
|
5
7
|
attr_accessor :context
|
6
8
|
|
7
9
|
# Class methods
|
8
|
-
def self.parse(str)
|
9
|
-
|
10
|
+
def self.parse(str, options={})
|
11
|
+
self.options = options
|
12
|
+
Surveyor::Parser.rake_trace "\n"
|
10
13
|
Surveyor::Parser.new.parse(str)
|
11
|
-
|
14
|
+
Surveyor::Parser.rake_trace "\n"
|
12
15
|
end
|
13
|
-
|
16
|
+
def self.rake_trace(str)
|
17
|
+
self.options ||= {}
|
18
|
+
print str if self.options[:trace] == true
|
19
|
+
end
|
20
|
+
|
14
21
|
# Instance methods
|
15
22
|
def initialize
|
16
23
|
self.context = {}
|
@@ -24,7 +31,7 @@ module Surveyor
|
|
24
31
|
method_name, reference_identifier = missing_method.to_s.split("_", 2)
|
25
32
|
type = full(method_name)
|
26
33
|
|
27
|
-
|
34
|
+
Surveyor::Parser.rake_trace reference_identifier.blank? ? "#{type} " : "#{type}_#{reference_identifier} "
|
28
35
|
|
29
36
|
# check for blocks
|
30
37
|
raise "Error: A #{type.humanize} cannot be empty" if block_models.include?(type) && !block_given?
|
@@ -37,8 +44,8 @@ module Surveyor
|
|
37
44
|
if block_models.include?(type)
|
38
45
|
self.instance_eval(&block)
|
39
46
|
if type == 'survey'
|
40
|
-
|
41
|
-
|
47
|
+
Surveyor::Parser.rake_trace "\n"
|
48
|
+
Surveyor::Parser.rake_trace context[type.to_sym].save ? "saved. " : " not saved! #{context[type.to_sym].errors.each_full{|x| x }.join(", ")} "
|
42
49
|
end
|
43
50
|
context[type.to_sym].clear(context) unless type == 'survey'
|
44
51
|
end
|
@@ -158,7 +165,7 @@ class Question < ActiveRecord::Base
|
|
158
165
|
unless correct.blank? or reference_identifier.blank? or context_reference.blank?
|
159
166
|
# Looking up references for quiz answers
|
160
167
|
context_reference[:answer_references][reference_identifier] ||= {}
|
161
|
-
|
168
|
+
Surveyor::Parser.rake_trace( (self.correct_answer = context_reference[:answer_references][reference_identifier][correct]) ? "found correct answer:#{correct} " : "lost! correct answer:#{correct} ")
|
162
169
|
end
|
163
170
|
end
|
164
171
|
end
|
@@ -206,9 +213,9 @@ class DependencyCondition < ActiveRecord::Base
|
|
206
213
|
def resolve_references
|
207
214
|
if context_reference
|
208
215
|
# Looking up references to questions and answers for linking the dependency objects
|
209
|
-
|
216
|
+
Surveyor::Parser.rake_trace( (self.question = context_reference[:question_references][question_reference]) ? "found question:#{question_reference} " : "lost! question:#{question_reference} ")
|
210
217
|
context_reference[:answer_references][question_reference] ||= {}
|
211
|
-
|
218
|
+
Surveyor::Parser.rake_trace( (self.answer = context_reference[:answer_references][question_reference][answer_reference]) ? "found answer:#{answer_reference} " : "lost! answer:#{answer_reference} ")
|
212
219
|
end
|
213
220
|
end
|
214
221
|
end
|
@@ -259,7 +266,7 @@ class Answer < ActiveRecord::Base
|
|
259
266
|
self.text_args("Other").merge({:response_class => "string"})
|
260
267
|
when :none, :omit # is_exclusive erases and disables other checkboxes and input elements
|
261
268
|
self.text_args(arg.to_s.humanize).merge({:is_exclusive => true})
|
262
|
-
when :integer, :date, :time, :datetime, :text, :datetime, :string
|
269
|
+
when :integer, :float, :date, :time, :datetime, :text, :datetime, :string
|
263
270
|
self.text_args(arg.to_s.humanize).merge({:response_class => arg.to_s, :display_type => "hidden_label"})
|
264
271
|
end
|
265
272
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Surveyor
|
2
|
+
module RenderText
|
3
|
+
def render_question_text(context = nil)
|
4
|
+
render_text(text, context)
|
5
|
+
end
|
6
|
+
|
7
|
+
def render_help_text(context = nil)
|
8
|
+
render_text(help_text, context)
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_answer_text(text, context = nil)
|
12
|
+
render_text(text, context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def render_text(text, context = nil)
|
16
|
+
context ? context.render(text) : text
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
|
+
require 'rabl'
|
2
|
+
Rabl.register!
|
3
|
+
Rabl.configure {|config| config.include_json_root = false }
|
1
4
|
module Surveyor
|
2
5
|
module SurveyorControllerMethods
|
3
6
|
def self.included(base)
|
4
7
|
base.send :before_filter, :get_current_user, :only => [:new, :create]
|
5
8
|
base.send :before_filter, :determine_if_javascript_is_enabled, :only => [:create, :update]
|
9
|
+
base.send :before_filter, :set_render_context, :only => [:edit]
|
6
10
|
base.send :layout, 'surveyor_default'
|
7
11
|
end
|
8
12
|
|
@@ -25,6 +29,7 @@ module Surveyor
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
|
28
33
|
def show
|
29
34
|
@response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => [:question, :answer]})
|
30
35
|
if @response_set
|
@@ -34,6 +39,7 @@ module Surveyor
|
|
34
39
|
format.csv {
|
35
40
|
send_data(@response_set.to_csv, :type => 'text/csv; charset=utf-8; header=present',:filename => "#{@response_set.updated_at.strftime('%Y-%m-%d')}_#{@response_set.access_code}.csv")
|
36
41
|
}
|
42
|
+
format.json
|
37
43
|
end
|
38
44
|
else
|
39
45
|
flash[:notice] = t('surveyor.unable_to_find_your_responses')
|
@@ -91,14 +97,26 @@ module Surveyor
|
|
91
97
|
end
|
92
98
|
end
|
93
99
|
end
|
94
|
-
|
100
|
+
|
101
|
+
def export
|
102
|
+
@survey = Survey.find_by_access_code(params[:survey_code])
|
103
|
+
end
|
95
104
|
private
|
96
105
|
|
106
|
+
# This is a hoock method for surveyor-using applications to override and provide the context object
|
107
|
+
def render_context
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
97
111
|
# Filters
|
98
112
|
def get_current_user
|
99
113
|
@current_user = self.respond_to?(:current_user) ? self.current_user : nil
|
100
114
|
end
|
101
115
|
|
116
|
+
def set_render_context
|
117
|
+
@render_context = render_context
|
118
|
+
end
|
119
|
+
|
102
120
|
# Params: the name of some submit buttons store the section we'd like to go to. for repeater questions, an anchor to the repeater group is also stored
|
103
121
|
# e.g. params[:section] = {"1"=>{"question_group_1"=>"<= add row"}}
|
104
122
|
def section_id_from(p)
|
data/lib/surveyor/unparser.rb
CHANGED
@@ -48,7 +48,7 @@ class QuestionGroup < ActiveRecord::Base
|
|
48
48
|
# block
|
49
49
|
|
50
50
|
def unparse(dsl)
|
51
|
-
attrs = (self.attributes.diff QuestionGroup.new(:text => text).attributes).delete_if{|k,v| %w(created_at updated_at id).include?(k) or (k == "display_type" && %w(grid repeater default).include?(v))}.symbolize_keys!
|
51
|
+
attrs = (self.attributes.diff QuestionGroup.new(:text => text).attributes).delete_if{|k,v| %w(created_at updated_at id api_id).include?(k) or (k == "display_type" && %w(grid repeater default).include?(v))}.symbolize_keys!
|
52
52
|
method = (%w(grid repeater).include?(display_type) ? display_type : "group")
|
53
53
|
dsl << "\n"
|
54
54
|
dsl << " #{method} \"#{text}\""
|
data/lib/surveyor/version.rb
CHANGED
@@ -7,7 +7,7 @@ namespace :surveyor do
|
|
7
7
|
file = File.join(Rails.root, ENV["FILE"])
|
8
8
|
raise "File does not exist: #{file}" unless FileTest.exists?(file)
|
9
9
|
puts "--- Parsing #{file} ---"
|
10
|
-
Surveyor::Parser.parse
|
10
|
+
Surveyor::Parser.parse(File.read(file), {:trace => Rake.application.options.trace})
|
11
11
|
puts "--- Done #{file} ---"
|
12
12
|
end
|
13
13
|
desc "generate and load survey from REDCap Data Dictionary (specify FILE=surveys/redcap.csv)"
|
@@ -234,11 +234,15 @@ describe SurveyorController do
|
|
234
234
|
|
235
235
|
it "should return an id for new responses" do
|
236
236
|
do_ajax_put({
|
237
|
-
"2"=>{"question_id"=>"4", "answer_id"=>"14"}
|
238
|
-
"4"=>{"question_id"=>"4", "answer_id"=>"15"} #check
|
237
|
+
"2"=>{"question_id"=>"4", "answer_id"=>"14"}
|
239
238
|
})
|
240
239
|
JSON.parse(response.body).
|
241
|
-
should == {"ids" => {"2" => 1
|
240
|
+
should == {"ids" => {"2" => 1}, "remove" => {}, "show" => [], "hide" => []}
|
241
|
+
do_ajax_put({
|
242
|
+
"4"=>{"question_id"=>"4", "answer_id"=>"15"}
|
243
|
+
})
|
244
|
+
JSON.parse(response.body).
|
245
|
+
should == {"ids" => {"4" => 2}, "remove" => {}, "show" => [], "hide" => []}
|
242
246
|
end
|
243
247
|
|
244
248
|
it "should return a delete for when responses are removed" do
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe SurveyorHelper do
|
4
|
+
|
4
5
|
before(:each) do
|
5
|
-
|
6
|
+
|
6
7
|
end
|
7
8
|
it "should return the question text with number" do
|
8
9
|
q1 = Factory(:question)
|
@@ -13,19 +14,58 @@ describe SurveyorHelper do
|
|
13
14
|
helper.q_text(q1).should == "1) #{q1.text}"
|
14
15
|
helper.q_text(q2).should == q2.text
|
15
16
|
helper.q_text(q3).should == q3.text
|
16
|
-
|
17
|
+
|
17
18
|
dir = "images"
|
18
19
|
if Rails.application.config.respond_to?(:assets) && Rails.application.config.assets
|
19
20
|
dir = "assets"
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
helper.q_text(q4).should == %Q(<img alt="Something" src="/#{dir}/something.jpg" />)
|
23
24
|
helper.q_text(q5).should == q5.text
|
24
25
|
end
|
26
|
+
require 'mustache'
|
27
|
+
class FakeMustacheContext < ::Mustache
|
28
|
+
def site
|
29
|
+
"Northwestern"
|
30
|
+
end
|
31
|
+
def somethingElse
|
32
|
+
"something new"
|
33
|
+
end
|
34
|
+
|
35
|
+
def group
|
36
|
+
"NUBIC"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
it "should return text with with substituted value" do
|
40
|
+
q1 = Factory(:question, :text => "You are in {{site}}")
|
41
|
+
label = Factory(:question, :display_type => "label", :text => "Testing {{somethingElse}}")
|
42
|
+
helper.q_text(q1, FakeMustacheContext).should == "1) You are in Northwestern"
|
43
|
+
helper.q_text(label, FakeMustacheContext).should == "Testing something new"
|
44
|
+
end
|
45
|
+
it "should return help_text for question with substituted value" do
|
46
|
+
q2 = Factory(:question, :display_type => "label", :text => "Is you site Northwestern?", :help_text => "If your site is not {{site}}, pick 'no' for the answer")
|
47
|
+
helper.render_help_text(q2, FakeMustacheContext).should == "If your site is not Northwestern, pick 'no' for the answer"
|
48
|
+
end
|
49
|
+
it "should return help_text for group text with number" do
|
50
|
+
g1 = Factory(:question_group, :text => "You are part of the {{group}}")
|
51
|
+
helper.q_text(g1, FakeMustacheContext).should == "1) You are part of the NUBIC"
|
52
|
+
end
|
53
|
+
it "should return help_text for group text" do
|
54
|
+
g1 = Factory(:question_group, :text => "You are part of the {{group}}", :help_text => "Make sure you know what the {{group}} stands for")
|
55
|
+
helper.render_help_text(g1, FakeMustacheContext).should == "Make sure you know what the NUBIC stands for"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return rendered text for answer" do
|
59
|
+
q1 = Factory(:question, :text => "Do you work for {{site}}", :answers => [a1 = Factory(:answer, :text => "No, I don't work for {{site}}"), a2 = Factory(:answer, :text => "Yes, I do work for {{site}}") ])
|
60
|
+
helper.a_text(a1, nil, FakeMustacheContext).should == "No, I don't work for Northwestern"
|
61
|
+
helper.a_text(a2, nil, FakeMustacheContext).should == "Yes, I do work for Northwestern"
|
62
|
+
end
|
63
|
+
|
25
64
|
it "should return the group text with number" do
|
26
65
|
g1 = Factory(:question_group)
|
27
|
-
helper.q_text(g1).should == "1) #{g1.text}"
|
66
|
+
helper.q_text(g1, FakeMustacheContext).should == "1) #{g1.text}"
|
28
67
|
end
|
68
|
+
|
29
69
|
it "should find or create responses, with index" do
|
30
70
|
q1 = Factory(:question, :answers => [a = Factory(:answer, :text => "different")])
|
31
71
|
q2 = Factory(:question, :answers => [b = Factory(:answer, :text => "strokes")])
|
@@ -36,10 +76,10 @@ describe SurveyorHelper do
|
|
36
76
|
helper.response_for(nil, q1).should == nil
|
37
77
|
helper.response_for(rs, q1).should == r1
|
38
78
|
helper.response_for(rs, q1, a).should == r1
|
39
|
-
helper.response_for(rs, q2).attributes.should == Response.new(:question => q2, :response_set => rs).attributes
|
40
|
-
helper.response_for(rs, q2, b).attributes.should == Response.new(:question => q2, :response_set => rs).attributes
|
79
|
+
helper.response_for(rs, q2).attributes.reject{|k,v| k == "api_id"}.should == Response.new(:question => q2, :response_set => rs).attributes.reject{|k,v| k == "api_id"}
|
80
|
+
helper.response_for(rs, q2, b).attributes.reject{|k,v| k == "api_id"}.should == Response.new(:question => q2, :response_set => rs).attributes.reject{|k,v| k == "api_id"}
|
41
81
|
helper.response_for(rs, q3, c, "1").should == r3
|
42
|
-
|
82
|
+
|
43
83
|
end
|
44
84
|
it "should keep an index of responses" do
|
45
85
|
helper.response_idx.should == "1"
|
@@ -53,7 +93,62 @@ describe SurveyorHelper do
|
|
53
93
|
helper.rc_to_attr(:integer).should == :integer_value
|
54
94
|
helper.rc_to_attr(:float).should == :float_value
|
55
95
|
helper.rc_to_attr(:datetime).should == :datetime_value
|
56
|
-
helper.rc_to_attr(:date).should == :
|
57
|
-
helper.rc_to_attr(:time).should == :
|
96
|
+
helper.rc_to_attr(:date).should == :date_value
|
97
|
+
helper.rc_to_attr(:time).should == :time_value
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should translate response class into as" do
|
101
|
+
helper.rc_to_as(:string).should == :string
|
102
|
+
helper.rc_to_as(:text).should == :text
|
103
|
+
helper.rc_to_as(:integer).should == :string
|
104
|
+
helper.rc_to_as(:float).should == :string
|
105
|
+
helper.rc_to_as(:datetime).should == :string
|
106
|
+
helper.rc_to_as(:date).should == :string
|
107
|
+
helper.rc_to_as(:time).should == :string
|
58
108
|
end
|
109
|
+
|
110
|
+
context "overriding methods" do
|
111
|
+
before do
|
112
|
+
module SurveyorHelper
|
113
|
+
include Surveyor::Helpers::SurveyorHelperMethods
|
114
|
+
alias :old_rc_to_as :rc_to_as
|
115
|
+
def rc_to_as(type_sym)
|
116
|
+
case type_sym.to_s
|
117
|
+
when /(integer|float)/ then :string
|
118
|
+
when /(datetime)/ then :datetime
|
119
|
+
else type_sym
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should translate response class into as" do
|
126
|
+
helper.rc_to_as(:string).should == :string
|
127
|
+
helper.rc_to_as(:text).should == :text
|
128
|
+
helper.rc_to_as(:integer).should == :string
|
129
|
+
helper.rc_to_as(:float).should == :string
|
130
|
+
helper.rc_to_as(:datetime).should == :datetime # not string
|
131
|
+
helper.rc_to_as(:date).should == :date # not string
|
132
|
+
helper.rc_to_as(:time).should == :time
|
133
|
+
end
|
134
|
+
|
135
|
+
after do
|
136
|
+
module SurveyorHelper
|
137
|
+
include Surveyor::Helpers::SurveyorHelperMethods
|
138
|
+
def rc_to_as(type_sym)
|
139
|
+
old_rc_to_as(type_sym)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Make sure that this context runs after the previous context 'overriding methods'
|
146
|
+
context "post override test" do
|
147
|
+
# Sanity check
|
148
|
+
it "should translate response class into as after override" do
|
149
|
+
helper.rc_to_as(:datetime).should == :string # back to string
|
150
|
+
helper.rc_to_as(:date).should == :string # back to string
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
59
154
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
survey "青少年人际关系问卷", :access_code => "青少年人际关系问卷" do
|
2
|
+
section "Basic questions" do
|
3
|
+
grid "第二部分:以下列出了一些描述。请您根据自己的实际情况作答。如果“非常不像我”,请选“1”,如果“非常像我”,请选“5”,以此类推。" do
|
4
|
+
a "1"
|
5
|
+
a "2"
|
6
|
+
a "3"
|
7
|
+
a "4"
|
8
|
+
a "5"
|
9
|
+
q "我常常想出新的有趣的点子", :pick => :one
|
10
|
+
q "我比同龄的其他孩子更有想象力", :pick => :one
|
11
|
+
q "即使一个人独处,我也不会觉得无聊", :pick => :one
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|