Skip to content

Instantly share code, notes, and snippets.

@sandeep45
Created October 17, 2014 01:32
Show Gist options
  • Save sandeep45/5bafb1eef331ccd74c56 to your computer and use it in GitHub Desktop.
Save sandeep45/5bafb1eef331ccd74c56 to your computer and use it in GitHub Desktop.
class MessageDetail
include ActiveModel::Validations
attr_accessor :body, :length
validates :body, presence: true, length: { minimum: 1 }
validates :length, presence: true, :numericality => {:greater_than => 0}
def initialize(body,length)
@body = body
@length = length
end
def self.build(body,length)
message_detail = self.new(body,length)
if message_detail.valid? == false
raise StandardError, "Invalid Message Detail Passed"
end
return message_detail
end
end
@sandeep45
Copy link
Author

is build reserved in terms of rspec. From inside my rspec tests, after some painful debugging i realized that my build function never ran and i always got nil as return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment