Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

set display order in parser, not model. closes #264

  • Loading branch information...
commit 5fe9712da73bc1a81e4f27d9d4c49fb9ae98ff8b 1 parent f89a9f9
Mark Yoon authored
View
7 features/step_definitions/parser_steps.rb
@@ -13,6 +13,13 @@
end
end
+Then /^there should be (\d+) section(?:s?) with:$/ do |x, table|
+ SurveySection.count.should == x.to_i
+ table.hashes.each do |hash|
+ SurveySection.find(:first, :conditions => hash).should_not be_nil
+ end
+end
+
Then /^there should be (\d+) question groups with:$/ do |x, table|
QuestionGroup.count.should == x.to_i
table.hashes.each do |hash|
View
49 features/surveyor_parser.feature
@@ -2,7 +2,7 @@ Feature: Survey creation
As a
I want to write out the survey in the DSL
So that I can give it to survey participants
-
+
Scenario: Basic questions
Given I parse
"""
@@ -17,31 +17,40 @@ Feature: Survey creation
answer :other
q_2b "Choose the colors you don't like", :pick => :any
- a_1 "orange"
- a_2 "purple"
- a_3 "brown"
+ a_1 "orange", :display_order => 1
+ a_2 "purple", :display_order => 2
+ a_3 "brown", :display_order => 0
a :omit
end
+ section "Second section" do
+ end
+ end
+ survey "Second survey" do
end
"""
- Then there should be 1 survey with:
- | title |
- | Simple survey |
+ Then there should be 2 surveys with:
+ | title | display_order |
+ | Simple survey | 0 |
+ | Second survey | 1 |
+ And there should be 2 sections with:
+ | title | display_order |
+ | Basic questions | 0 |
+ | Second section | 1 |
And there should be 3 questions with:
- | reference_identifier | text | pick | display_type |
- | nil | These questions are examples of the basic supported input types | none | label |
- | 1 | What is your favorite color? | one | default |
- | 2b | Choose the colors you don't like | any | default |
+ | reference_identifier | text | pick | display_type | display_order |
+ | nil | These questions are examples of the basic supported input types | none | label | 0 |
+ | 1 | What is your favorite color? | one | default | 1 |
+ | 2b | Choose the colors you don't like | any | default | 2 |
And there should be 8 answers with:
- | reference_identifier | text | response_class |
- | nil | red | answer |
- | nil | blue | answer |
- | nil | green | answer |
- | nil | Other | answer |
- | 1 | orange | answer |
- | 2 | purple | answer |
- | 3 | brown | answer |
- | nil | Omit | answer |
+ | reference_identifier | text | response_class | display_order |
+ | nil | red | answer | 0 |
+ | nil | blue | answer | 1 |
+ | nil | green | answer | 2 |
+ | nil | Other | answer | 3 |
+ | 1 | orange | answer | 1 |
+ | 2 | purple | answer | 2 |
+ | 3 | brown | answer | 0 |
+ | nil | Omit | answer | 3 |
Scenario: More complex questions
Given I parse
View
1  lib/surveyor/models/answer_methods.rb
@@ -29,7 +29,6 @@ def initialize(*args)
end
def default_args
- self.display_order ||= self.question ? self.question.answers.count : 0
self.is_exclusive ||= false
self.display_type ||= "default"
self.response_class ||= "answer"
View
1  lib/surveyor/models/question_methods.rb
@@ -36,7 +36,6 @@ def default_args
self.is_mandatory ||= true
self.display_type ||= "default"
self.pick ||= "none"
- self.display_order ||= self.survey_section ? self.survey_section.questions.count : 0
self.data_export_identifier ||= Surveyor::Common.normalize(text)
self.short_text ||= text
self.api_id ||= UUID.generate
View
1  lib/surveyor/models/survey_methods.rb
@@ -39,6 +39,7 @@ def initialize(*args)
def default_args
self.inactive_at ||= DateTime.now
self.api_id ||= UUID.generate
+ self.display_order ||= Survey.count
end
def title=(value)
View
1  lib/surveyor/models/survey_section_methods.rb
@@ -28,7 +28,6 @@ def initialize(*args)
end
def default_args
- self.display_order ||= survey ? survey.sections.count : 0
self.data_export_identifier ||= Surveyor::Common.normalize(title)
end
View
10 lib/surveyor/parser.rb
@@ -80,7 +80,7 @@ def self.parse_and_build(context, args, original_method, reference_identifier)
# build and set context
title = args[0]
context[:survey] = new({ :title => title,
- :reference_identifier => reference_identifier}.merge(args[1] || {}))
+ :reference_identifier => reference_identifier }.merge(args[1] || {}))
end
def clear(context)
context.delete_if{|k,v| true }
@@ -97,7 +97,8 @@ def self.parse_and_build(context, args, original_method, reference_identifier)
# build and set context
title = args[0]
- context[:survey_section] = context[:survey].sections.build({ :title => title }.merge(args[1] || {}))
+ context[:survey_section] = context[:survey].sections.build({ :title => title,
+ :display_order => context[:survey].sections.size }.merge(args[1] || {}))
end
def clear(context)
context.delete_if{|k,v| !%w(survey question_references answer_references).map(&:to_sym).include?(k)}
@@ -137,7 +138,8 @@ def self.parse_and_build(context, args, original_method, reference_identifier)
:question_group => context[:question_group],
:reference_identifier => reference_identifier,
:text => text,
- :display_type => (original_method =~ /label|image/ ? original_method : "default")}.merge(args[1] || {}))
+ :display_type => (original_method =~ /label|image/ ? original_method : "default"),
+ :display_order => context[:survey_section].questions.size }.merge(args[1] || {}))
# keep reference for dependencies
context[:question_references][reference_identifier] = context[:question] unless reference_identifier.blank?
@@ -218,7 +220,7 @@ def self.parse_and_build(context, args, original_method, reference_identifier)
# clear context
context.delete_if{|k,v| %w(answer validation validation_condition reference_identifier).map(&:to_sym).include? k}
- attrs = { :reference_identifier => reference_identifier}.merge(self.parse_args(args))
+ attrs = { :reference_identifier => reference_identifier, :display_order => context[:question].answers.size }.merge(self.parse_args(args))
# add answers to grid
if context[:question_group] && context[:question_group].display_type == "grid"
Please sign in to comment.
Something went wrong with that request. Please try again.