Skip to content
This repository has been archived by the owner on Aug 13, 2018. It is now read-only.

Commit

Permalink
Return our own Message object from the repository, not a Mail object
Browse files Browse the repository at this point in the history
  • Loading branch information
tomafro committed Mar 27, 2012
1 parent 7fc571e commit 609d067
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/message_repository.rb
@@ -1,6 +1,19 @@
require 'mail'

class MessageRepository
class Message
attr_reader :mail
delegate :subject, :date, :from, to: :mail

def initialize(body)
@mail = Mail.new(body)
end

def ==(message)
message.is_a?(Message) && message.mail == mail
end
end

class << self
attr_writer :instance

Expand All @@ -27,7 +40,7 @@ def exists?(key)

def messages
message_store.values.map do |message|
Mail.new message
Message.new message
end
end
end
2 changes: 1 addition & 1 deletion test/unit/message_repository_test.rb
Expand Up @@ -28,6 +28,6 @@ class MessageRepositoryTest < ActiveSupport::TestCase
store = stub('message-store')
repository = MessageRepository.new(store)
store.stubs(:values).returns(["Subject: One", "Subject: Two"])
assert_equal [Mail.new("Subject: One"), Mail.new("Subject: Two")], repository.messages
assert_equal [MessageRepository::Message.new("Subject: One"), MessageRepository::Message.new("Subject: Two")], repository.messages
end
end

0 comments on commit 609d067

Please sign in to comment.