Skip to content

Commit

Permalink
Make Surveyor::Parser accept Answer#reference_identifier via undersco…
Browse files Browse the repository at this point in the history
…re or hash syntax. closes #439
  • Loading branch information
Mark Yoon committed Apr 5, 2013
1 parent 27d4526 commit a9b68f6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ History for Surveyor

- Remove default order on Response. (#423)
- Bug fix for RedCap Parser for DependencyConditions. thanks @ariel-perez-birchbox
- Make Surveyor::Parser accept Answer#reference_identifier via underscore or hash syntax (#439)

### Dependencies

Expand Down
6 changes: 3 additions & 3 deletions lib/surveyor/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ def parse_and_build(context, args, original_method, reference_identifier)
self.attributes = ({:display_order => context[:question].answers.size}.merge(attrs))
context[:question].answers << context[:answer] = self
# keep reference for dependencies
unless context[:question].reference_identifier.blank? or reference_identifier.blank?
unless context[:question].reference_identifier.blank? or self.reference_identifier.blank?
context[:answer_references][context[:question].reference_identifier] ||= {}
context[:duplicate_references].push "q_#{context[:question].reference_identifier}, a_#{reference_identifier}" if context[:answer_references][context[:question].reference_identifier].has_key?(reference_identifier)
context[:answer_references][context[:question].reference_identifier][reference_identifier] = context[:answer]
context[:duplicate_references].push "q_#{context[:question].reference_identifier}, a_#{self.reference_identifier}" if context[:answer_references][context[:question].reference_identifier].has_key?(self.reference_identifier)
context[:answer_references][context[:question].reference_identifier][self.reference_identifier] = context[:answer]
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/lib/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,39 @@
it "should return a survey object" do
Surveyor::Parser.new.parse("survey 'hi' do\n end").is_a?(Survey).should be_true
end
describe 'reference checking' do
it 'accepts Answer#reference_identifier via underscore or hash syntax' do
survey_text = <<END
survey "Numbers" do
section_one "One" do
q_1 "Select a number", :pick => :one
a "One", {:reference_identifier => "1"}
a_2 "Two"
a_3 "Three"
label_2 "One is the loneliest number..."
dependency :rule => "A"
condition_A :q_1, "==", {:answer_reference => "1"}
label_3 "Two can be as bad as one..."
dependency :rule => "A"
condition_A :q_1, "==", {:answer_reference => "2"}
label_4 "that you'll ever do"
dependency :rule => "A"
condition_A :q_1, "==", :a_1
label_5 "it's the loneliest number since the number one"
dependency :rule => "A"
condition_A :q_1, "==", :a_2
end
end
END
survey = Surveyor::Parser.new.parse(survey_text)
survey.is_a?(Survey).should == true
end

end

describe 'translations' do

Expand Down

0 comments on commit a9b68f6

Please sign in to comment.