Skip to content

Instantly share code, notes, and snippets.

@bnadlerjr
Created June 12, 2010 00:39
Show Gist options
  • Save bnadlerjr/435245 to your computer and use it in GitHub Desktop.
Save bnadlerjr/435245 to your computer and use it in GitHub Desktop.
class Contact
include ActiveModel::Validations
include ActiveModel::Serialization # should be => include ActiveModel::Serializers::Xml
validates_presence_of :email, :subject, :body
validates :email, :format => {
:with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
attr_accessor :email
attr_accessor :subject
attr_accessor :body
def initialize(email, subject, body)
@email = email
@subject = subject
@body = body
end
def attributes
@attributes ||= { 'email' => 'nil', 'subject' => 'nil', 'body' => 'nil' }
end
end
According to step #2 in the extra credit section of the README for lab4, we need to include
ActiveModel::Serialization; but the file contact.rb above throws the following error when
running rake test:extra
1) Error:
test_should_be_serializable_to_xml(ContactTest):
NoMethodError: undefined method `to_xml' for #<Contact:0x103438a60>
/test/extra/contact_test.rb:15:in `test_should_be_serializable_to_xml'
If I change line #3 to
include ActiveModel::Serializers::Xml
then all tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment