surveyor 0.14.5 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/README.md +12 -4
  2. data/VERSION +1 -1
  3. data/features/step_definitions/surveyor_steps.rb +64 -4
  4. data/features/surveyor.feature +144 -11
  5. data/lib/surveyor.rb +0 -4
  6. data/lib/surveyor/acts_as_response.rb +13 -29
  7. data/lib/surveyor/common.rb +2 -2
  8. data/lib/surveyor/models/answer_methods.rb +14 -1
  9. data/lib/surveyor/models/dependency_condition_methods.rb +4 -3
  10. data/lib/surveyor/models/question_methods.rb +11 -1
  11. data/lib/surveyor/models/response_methods.rb +2 -1
  12. data/lib/surveyor/models/survey_methods.rb +10 -2
  13. data/lib/surveyor/models/survey_section_methods.rb +11 -1
  14. data/lib/surveyor/models/validation_condition_methods.rb +3 -2
  15. data/lib/surveyor/models/validation_methods.rb +2 -2
  16. data/lib/surveyor/parser.rb +274 -0
  17. data/lib/tasks/surveyor_tasks.rake +25 -25
  18. data/spec/factories.rb +1 -1
  19. data/spec/lib/common_spec.rb +22 -0
  20. data/spec/lib/parser_spec.rb +30 -0
  21. data/spec/models/answer_spec.rb +6 -5
  22. data/spec/models/dependency_condition_spec.rb +7 -6
  23. data/spec/models/question_spec.rb +12 -10
  24. data/spec/models/survey_section_spec.rb +3 -2
  25. data/spec/models/survey_spec.rb +11 -0
  26. data/spec/models/validation_condition_spec.rb +5 -5
  27. data/spec/models/validation_spec.rb +5 -4
  28. data/surveyor.gemspec +7 -23
  29. metadata +10 -26
  30. data/lib/fixtures_extensions.rb +0 -6
  31. data/script/surveyor/answer.rb +0 -54
  32. data/script/surveyor/base.rb +0 -75
  33. data/script/surveyor/dependency.rb +0 -13
  34. data/script/surveyor/dependency_condition.rb +0 -40
  35. data/script/surveyor/parser.rb +0 -223
  36. data/script/surveyor/question.rb +0 -59
  37. data/script/surveyor/question_group.rb +0 -26
  38. data/script/surveyor/specs/answer_spec.rb +0 -29
  39. data/script/surveyor/specs/question_spec.rb +0 -63
  40. data/script/surveyor/specs/spec_helper.rb +0 -7
  41. data/script/surveyor/specs/survey_section_spec.rb +0 -23
  42. data/script/surveyor/specs/validation_condition_spec.rb +0 -20
  43. data/script/surveyor/specs/validation_spec.rb +0 -20
  44. data/script/surveyor/survey.rb +0 -34
  45. data/script/surveyor/survey_section.rb +0 -21
  46. data/script/surveyor/validation.rb +0 -21
  47. data/script/surveyor/validation_condition.rb +0 -21
  48. data/script/surveyor/whr_dsl.tmproj +0 -244
  49. data/spec/lib/surveyor_spec.rb +0 -44
@@ -17,12 +17,13 @@ describe DependencyCondition, "instance" do
17
17
  end
18
18
 
19
19
  it "should be invalid without a parent dependency_id, question_id, answer_id" do
20
- @dependency_condition.dependency_id = nil
21
- @dependency_condition.should have(1).errors_on(:dependency_id)
22
- @dependency_condition.question_id = nil
23
- @dependency_condition.should have(1).errors_on(:question_id)
24
- @dependency_condition.answer_id = nil
25
- @dependency_condition.should have(1).errors_on(:answer_id)
20
+ # this causes issues with building and saving
21
+ # @dependency_condition.dependency_id = nil
22
+ # @dependency_condition.should have(1).errors_on(:dependency_id)
23
+ # @dependency_condition.question_id = nil
24
+ # @dependency_condition.should have(1).errors_on(:question_id)
25
+ # @dependency_condition.answer_id = nil
26
+ # @dependency_condition.should have(1).errors_on(:answer_id)
26
27
  end
27
28
 
28
29
  it "should be invalid without an operator" do
@@ -6,24 +6,28 @@ describe Question, "when creating a new question" do
6
6
  @question = Question.new(:text => "What is your favorite color?", :survey_section => @ss, :is_mandatory => true, :display_order => 1)
7
7
  end
8
8
 
9
- it "should be valid" do
10
- @question.should be_valid
11
- end
12
-
13
9
  it "should be invalid without text" do
14
10
  @question.text = nil
15
11
  @question.should have(1).error_on(:text)
16
12
  end
17
13
 
18
14
  it "should have a parent survey section" do
19
- @question.survey_section = nil
20
- @question.should have(1).error_on(:survey_section_id)
15
+ # this causes issues with building and saving
16
+ # @question.survey_section = nil
17
+ # @question.should have(1).error_on(:survey_section_id)
21
18
  end
22
19
 
23
20
  it "should be mandatory by default" do
24
21
  @question.mandatory?.should be_true
25
22
  end
26
23
 
24
+ it "should convert pick attribute to string" do
25
+ @question.pick.should == "none"
26
+ @question.pick = :one
27
+ @question.pick.should == "one"
28
+ @question.pick = nil
29
+ @question.pick.should == nil
30
+ end
27
31
  end
28
32
 
29
33
  describe Question, "that has answers" do
@@ -47,8 +51,7 @@ end
47
51
  describe Question, "when interacting with an instance" do
48
52
 
49
53
  before(:each) do
50
- @ss = mock_model(SurveySection)
51
- @question = Question.new(:text => "What is your favorite color?", :survey_section => @ss)
54
+ @question = Factory(:question)
52
55
  end
53
56
 
54
57
  it "should return 'default' for nil display type" do
@@ -60,9 +63,8 @@ end
60
63
 
61
64
  describe Question, "with dependencies" do
62
65
  before(:each) do
63
- @ss = mock_model(SurveySection)
64
66
  @rs = mock_model(ResponseSet)
65
- @question = Question.new(:text => "Which island?", :survey_section => @ss)
67
+ @question = Factory(:question)
66
68
  end
67
69
 
68
70
  it "should check its dependency" do
@@ -12,8 +12,9 @@ describe SurveySection, "when saving a survey_section" do
12
12
  end
13
13
 
14
14
  it "should have a parent survey" do
15
- @survey_section.survey_id = nil
16
- @survey_section.should have(1).error_on(:survey)
15
+ # this causes issues with building and saving
16
+ # @survey_section.survey_id = nil
17
+ # @survey_section.should have(1).error_on(:survey)
17
18
  end
18
19
  end
19
20
 
@@ -10,6 +10,17 @@ describe Survey, "when saving a new one" do
10
10
  @survey.title = nil
11
11
  @survey.should have(1).error_on(:title)
12
12
  end
13
+
14
+ it "should adjust the title to save unique titles" do
15
+ original = Survey.new(:title => "Foo")
16
+ original.save.should be_true
17
+ imposter = Survey.new(:title => "Foo")
18
+ imposter.save.should be_true
19
+ imposter.title.should == "Foo 1"
20
+ bandwagoneer = Survey.new(:title => "Foo")
21
+ bandwagoneer.save.should be_true
22
+ bandwagoneer.title.should == "Foo 2"
23
+ end
13
24
  end
14
25
 
15
26
  # Associations
@@ -14,11 +14,11 @@ describe ValidationCondition do
14
14
  it "should be valid" do
15
15
  @validation_condition.should be_valid
16
16
  end
17
-
18
- it "should be invalid without a parent validation_id" do
19
- @validation_condition.validation_id = nil
20
- @validation_condition.should have(1).errors_on(:validation_id)
21
- end
17
+ # this causes issues with building and saving
18
+ # it "should be invalid without a parent validation_id" do
19
+ # @validation_condition.validation_id = nil
20
+ # @validation_condition.should have(1).errors_on(:validation_id)
21
+ # end
22
22
 
23
23
  it "should be invalid without an operator" do
24
24
  @validation_condition.operator = nil
@@ -16,10 +16,11 @@ describe Validation do
16
16
  @validation.should have(1).errors_on(:rule)
17
17
  end
18
18
 
19
- it "should be invalid without a answer_id" do
20
- @validation.answer_id = nil
21
- @validation.should have(1).error_on(:answer_id)
22
- end
19
+ # this causes issues with building and saving
20
+ # it "should be invalid without a answer_id" do
21
+ # @validation.answer_id = nil
22
+ # @validation.should have(1).error_on(:answer_id)
23
+ # end
23
24
 
24
25
  it "should be invalid unless rule composed of only references and operators" do
25
26
  @validation.rule = "foo"
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.14.5"
8
+ s.version = "0.15.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-09-01}
12
+ s.date = %q{2010-09-14}
13
13
  s.email = %q{yoon@northwestern.edu}
14
14
  s.extra_rdoc_files = [
15
15
  "README.md"
@@ -138,7 +138,6 @@ Gem::Specification.new do |s|
138
138
  "generators/test_surveyor/test_surveyor_generator.rb",
139
139
  "init.rb",
140
140
  "install.rb",
141
- "lib/fixtures_extensions.rb",
142
141
  "lib/surveyor.rb",
143
142
  "lib/surveyor/acts_as_response.rb",
144
143
  "lib/surveyor/common.rb",
@@ -153,30 +152,14 @@ Gem::Specification.new do |s|
153
152
  "lib/surveyor/models/survey_section_methods.rb",
154
153
  "lib/surveyor/models/validation_condition_methods.rb",
155
154
  "lib/surveyor/models/validation_methods.rb",
155
+ "lib/surveyor/parser.rb",
156
156
  "lib/surveyor/surveyor_controller_methods.rb",
157
157
  "lib/tasks/surveyor_tasks.rake",
158
158
  "rails/init.rb",
159
- "script/surveyor/answer.rb",
160
- "script/surveyor/base.rb",
161
- "script/surveyor/dependency.rb",
162
- "script/surveyor/dependency_condition.rb",
163
- "script/surveyor/parser.rb",
164
- "script/surveyor/question.rb",
165
- "script/surveyor/question_group.rb",
166
- "script/surveyor/specs/answer_spec.rb",
167
- "script/surveyor/specs/question_spec.rb",
168
- "script/surveyor/specs/spec_helper.rb",
169
- "script/surveyor/specs/survey_section_spec.rb",
170
- "script/surveyor/specs/validation_condition_spec.rb",
171
- "script/surveyor/specs/validation_spec.rb",
172
- "script/surveyor/survey.rb",
173
- "script/surveyor/survey_section.rb",
174
- "script/surveyor/validation.rb",
175
- "script/surveyor/validation_condition.rb",
176
- "script/surveyor/whr_dsl.tmproj",
177
159
  "spec/controllers/surveyor_controller_spec.rb",
178
160
  "spec/factories.rb",
179
- "spec/lib/surveyor_spec.rb",
161
+ "spec/lib/common_spec.rb",
162
+ "spec/lib/parser_spec.rb",
180
163
  "spec/models/answer_spec.rb",
181
164
  "spec/models/dependency_condition_spec.rb",
182
165
  "spec/models/dependency_spec.rb",
@@ -203,7 +186,8 @@ Gem::Specification.new do |s|
203
186
  s.test_files = [
204
187
  "spec/controllers/surveyor_controller_spec.rb",
205
188
  "spec/factories.rb",
206
- "spec/lib/surveyor_spec.rb",
189
+ "spec/lib/common_spec.rb",
190
+ "spec/lib/parser_spec.rb",
207
191
  "spec/models/answer_spec.rb",
208
192
  "spec/models/dependency_condition_spec.rb",
209
193
  "spec/models/dependency_spec.rb",
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: 45
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 14
9
- - 5
10
- version: 0.14.5
8
+ - 15
9
+ - 0
10
+ version: 0.15.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-09-01 00:00:00 -05:00
19
+ date: 2010-09-14 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -179,7 +179,6 @@ files:
179
179
  - generators/test_surveyor/test_surveyor_generator.rb
180
180
  - init.rb
181
181
  - install.rb
182
- - lib/fixtures_extensions.rb
183
182
  - lib/surveyor.rb
184
183
  - lib/surveyor/acts_as_response.rb
185
184
  - lib/surveyor/common.rb
@@ -194,30 +193,14 @@ files:
194
193
  - lib/surveyor/models/survey_section_methods.rb
195
194
  - lib/surveyor/models/validation_condition_methods.rb
196
195
  - lib/surveyor/models/validation_methods.rb
196
+ - lib/surveyor/parser.rb
197
197
  - lib/surveyor/surveyor_controller_methods.rb
198
198
  - lib/tasks/surveyor_tasks.rake
199
199
  - rails/init.rb
200
- - script/surveyor/answer.rb
201
- - script/surveyor/base.rb
202
- - script/surveyor/dependency.rb
203
- - script/surveyor/dependency_condition.rb
204
- - script/surveyor/parser.rb
205
- - script/surveyor/question.rb
206
- - script/surveyor/question_group.rb
207
- - script/surveyor/specs/answer_spec.rb
208
- - script/surveyor/specs/question_spec.rb
209
- - script/surveyor/specs/spec_helper.rb
210
- - script/surveyor/specs/survey_section_spec.rb
211
- - script/surveyor/specs/validation_condition_spec.rb
212
- - script/surveyor/specs/validation_spec.rb
213
- - script/surveyor/survey.rb
214
- - script/surveyor/survey_section.rb
215
- - script/surveyor/validation.rb
216
- - script/surveyor/validation_condition.rb
217
- - script/surveyor/whr_dsl.tmproj
218
200
  - spec/controllers/surveyor_controller_spec.rb
219
201
  - spec/factories.rb
220
- - spec/lib/surveyor_spec.rb
202
+ - spec/lib/common_spec.rb
203
+ - spec/lib/parser_spec.rb
221
204
  - spec/models/answer_spec.rb
222
205
  - spec/models/dependency_condition_spec.rb
223
206
  - spec/models/dependency_spec.rb
@@ -272,7 +255,8 @@ summary: A rails (gem) plugin to enable surveys in your application
272
255
  test_files:
273
256
  - spec/controllers/surveyor_controller_spec.rb
274
257
  - spec/factories.rb
275
- - spec/lib/surveyor_spec.rb
258
+ - spec/lib/common_spec.rb
259
+ - spec/lib/parser_spec.rb
276
260
  - spec/models/answer_spec.rb
277
261
  - spec/models/dependency_condition_spec.rb
278
262
  - spec/models/dependency_spec.rb
@@ -1,6 +0,0 @@
1
- class Fixtures
2
- def delete_existing_fixtures
3
- # @connection.delete "DELETE FROM #{@connection.quote_table_name(table_name)}", 'Fixture Delete'
4
- puts "Appending, skipping delete..."
5
- end
6
- end
@@ -1,54 +0,0 @@
1
- module SurveyParser
2
- class Answer < SurveyParser::Base
3
- # Context, Content, Reference, Display
4
- attr_accessor :id, :parser, :question_id
5
- attr_accessor :text, :short_text, :help_text, :weight, :response_class
6
- attr_accessor :reference_identifier, :data_export_identifier, :common_namespace, :common_identitier
7
- attr_accessor :display_order, :is_exclusive, :hide_label, :display_length, :custom_class, :custom_renderer
8
- attr_accessor :validation
9
-
10
- def default_options
11
- { :is_exclusive => false,
12
- :hide_label => false,
13
- :response_class => "answer"
14
- }
15
- end
16
-
17
- def parse_args(args)
18
- case args[0]
19
- when Hash # Hash
20
- text_args(args[0][:text]).merge(args[0])
21
- when String # (String, Hash) or (String, Symbol, Hash)
22
- text_args(args[0]).merge(hash_from args[1]).merge(args[2] || {})
23
- when Symbol # (Symbol, Hash) or (Symbol, Symbol, Hash)
24
- symbol_args(args[0]).merge(hash_from args[1]).merge(args[2] || {})
25
- else
26
- text_args(nil)
27
- end
28
- end
29
-
30
- def text_args(text = "Answer")
31
- {:text => text.to_s, :short_text => text, :data_export_identifier => Surveyor::Common.to_normalized_string(text)}
32
- end
33
- def hash_from(arg)
34
- arg.is_a?(Symbol) ? {:response_class => arg.to_s} : arg.is_a?(Hash) ? arg : {}
35
- end
36
- def symbol_args(arg)
37
- case arg
38
- when :other
39
- text_args("Other")
40
- when :other_and_string
41
- text_args("Other").merge({:response_class => "string"})
42
- when :none, :omit # is_exclusive erases and disables other checkboxes and input elements
43
- text_args(arg.to_s.humanize).merge({:is_exclusive => true})
44
- when :integer, :date, :time, :datetime, :text, :datetime, :string
45
- text_args(arg.to_s.humanize).merge({:response_class => arg.to_s, :hide_label => true})
46
- end
47
- end
48
- def to_file
49
- super
50
- if self.validation then self.validation.to_file end
51
- end
52
-
53
- end
54
- end
@@ -1,75 +0,0 @@
1
- module SurveyParser
2
- class Base
3
-
4
- # Class level instance variable, because class variable are shared with subclasses
5
- class << self
6
- attr_accessor :children
7
- end
8
-
9
- @children = []
10
-
11
- # Class methods
12
- def self.inherited(subclass)
13
- # set the class level instance variable default on subclasses
14
- subclass.instance_variable_set(:@children, self.instance_variable_get(:@children))
15
- end
16
-
17
- def self.has_children(*args)
18
- args.each{|model| attr_accessor model}
19
- self.instance_variable_set(:@children, args)
20
- end
21
-
22
- # Instance methods
23
- def initialize(obj, args, opts)
24
- # inherit the parser from parent (obj)
25
- self.parser = (obj.nil? ? nil : obj.class == SurveyParser::Parser ? obj : obj.parser)
26
- # get a new id from the parser
27
- self.id = parser.nil? ? nil : parser.send("new_#{self.class.name.demodulize.underscore}_id")
28
- # set [parent]_id to obj.id, if we have that attribute
29
- self.send("#{obj.class.name.demodulize.underscore}_id=", obj.nil? ? nil : obj.id) if self.respond_to?("#{obj.class.name.demodulize.underscore}_id=")
30
- # initialize descendant models
31
- self.class.children.each{|model| self.send("#{model}=", [])}
32
- # combine default options, parsed opts, parsed args, and initialize instance variables
33
- self.default_options.merge(parse_opts(opts)).merge(parse_args(args)).each{|k,v| self.send("#{k.to_s}=", v)}
34
- # print to the log
35
- print "#{self.class.name.demodulize.gsub(/[a-z]/, "")[-1,1]}#{self.id} "
36
- end
37
- def default_options
38
- {}
39
- end
40
- def parse_opts(opts)
41
- opts.reject{|k,v| k == :method_name} # toss the method name by default
42
- end
43
- def parse_args(args)
44
- args[0] || {}
45
- end
46
-
47
- # Filter out attributes that shouldn't be in fixtures, including children, parser, placeholders
48
- def yml_attrs
49
- instance_variables.sort.map(&:to_s) - self.class.children.map{|model| "@#{model.to_s}"} - %w(@id @parser @dependency @validation @question_reference @answer_reference)
50
- end
51
-
52
- def to_yml
53
- out = [ %(#{self.parser.salt}_#{self.class.name.demodulize.underscore}_#{@id}:) ]
54
- yml_attrs.each{|a| out << associate_and_format(a)}
55
- (out << nil ).join("\r\n")
56
- end
57
-
58
- def associate_and_format(a)
59
- if a =~ /_id$/ # a foreign key, e.g. survey_id
60
- " #{property_name_map(a[1..-4])}: " + (instance_variable_get(a).nil? ? "" : "#{self.parser.salt}_#{a[1..-4]}_#{instance_variable_get(a)}")
61
- else # quote strings
62
- " #{property_name_map(a[1..-1])}: #{instance_variable_get(a).is_a?(String) ? "\"#{instance_variable_get(a)}\"" : instance_variable_get(a) }"
63
- end
64
- end
65
-
66
- def property_name_map(property)
67
- return property
68
- end
69
-
70
- def to_file
71
- File.open(self.parser.send("#{self.class.name.demodulize.underscore.pluralize}_yml"), File::CREAT|File::APPEND|File::WRONLY) {|f| f << to_yml}
72
- self.class.children.each{|model| self.send(model).compact.map(&:to_file)}
73
- end
74
- end
75
- end
@@ -1,13 +0,0 @@
1
- module SurveyParser
2
- class Dependency < SurveyParser::Base
3
- # Context, Conditional, Children
4
- attr_accessor :id, :question_id, :question_group_id, :parser
5
- attr_accessor :rule
6
- has_children :dependency_conditions
7
-
8
- def parse_opts(opts)
9
- {} # toss the method name and reference identifier by default
10
- end
11
-
12
- end
13
- end
@@ -1,40 +0,0 @@
1
- module SurveyParser
2
- class DependencyCondition < SurveyParser::Base
3
-
4
- # Context, Conditional, Value
5
- attr_accessor :id, :dependency_id, :rule_key, :parser
6
- attr_accessor :question_id, :operator
7
- attr_accessor :answer_id, :datetime_value, :integer_value, :float_value, :unit, :text_value, :string_value, :response_other
8
- attr_accessor :question_reference, :answer_reference
9
-
10
- def default_options
11
- { :operator => "==" }
12
- end
13
- def parse_args(args)
14
- a0, a1, a2 = args
15
- {:question_reference => a0.to_s.gsub("q_", ""), :operator => a1}.merge(a2.is_a?(Hash) ? a2 : {:answer_reference => a2.to_s.gsub("a_", "")})
16
- end
17
- def parse_opts(opts)
18
- {:rule_key => opts[:reference_identifier]}
19
- end
20
-
21
- def reconcile_dependencies
22
- # Looking up references to questions and answers for linking the dependency objects
23
- print "Lookup Q ref #{@question_reference}:"
24
- if (ref_question = parser.current_survey.find_question_by_reference(@question_reference))
25
- print " found Q#{ref_question.id} "
26
- @question_id = ref_question.id
27
- print "Lookup A ref #{@answer_reference}"
28
- if (ref_answer = ref_question.find_answer_by_reference(@answer_reference))
29
- print " found A#{ref_answer.id} "
30
- @answer_id = ref_answer.id
31
- else
32
- raise "Could not find referenced answer #{@answer_reference}"
33
- end
34
- else
35
- raise "Could not find referenced question #{@question_reference}"
36
- end
37
- end
38
-
39
- end
40
- end