Skip to content

Instantly share code, notes, and snippets.

@evmorov
Created May 3, 2016 06:42
Show Gist options
  • Save evmorov/6b52582ebd3fab7f6cdbc6c1cd697f23 to your computer and use it in GitHub Desktop.
Save evmorov/6b52582ebd3fab7f6cdbc6c1cd697f23 to your computer and use it in GitHub Desktop.
For the article at medium.com
class Student
include HappyMapper
tag 'student'
has_one :name, String
has_one :school_id, String, tag: 'schoolId'
end
class School
include HappyMapper
tag 'school'
has_one :id, String
has_one :name, String
end
let(:schools) { School.parse(xml) }
let(:students) { Student.parse(xml) }
it do
school_id = schools.find { |school| school.name == 'Second school' }.id
student_names = students.select { |student| student.school_id == school_id }.map(&:name)
expect(student_names).to match(%w(Alex Olivia))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment