Skip to content

Commit

Permalink
Add specs for :delete_after_find option to the find method and the fi…
Browse files Browse the repository at this point in the history
…nd_and_delete method itself
  • Loading branch information
dball committed Oct 22, 2010
1 parent f0a88e7 commit c0d843c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/mail/network/retriever_methods/pop3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@

messages.size.should == 10
end

it "should handle the delete_after_find option" do
Mail.find(:delete_after_find => false)
MockPOP3.popmails.each { |message| message.should_not be_deleted }

Mail.find(:delete_after_find => true)
MockPOP3.popmails.first(10).each { |message| message.should be_deleted }
MockPOP3.popmails.last(10).each { |message| message.should_not be_deleted }
end

it "should handle the find_and_delete method" do
Mail.find_and_delete(:count => 15)
MockPOP3.popmails.first(15).each { |message| message.should be_deleted }
MockPOP3.popmails.last(5).each { |message| message.should_not be_deleted }
end

end

Expand Down
11 changes: 10 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class MockPopMail
def initialize(rfc2822, number)
@rfc2822 = rfc2822
@number = number
@deleted = false
end

def pop
Expand All @@ -103,6 +104,14 @@ def number
def to_s
"#{number}: #{pop}"
end

def delete
@deleted = true
end

def deleted?
@deleted
end
end

class MockPOP3
Expand All @@ -119,7 +128,7 @@ def initialize
def self.popmails
@@popmails.clone
end

def each_mail(*args)
@@popmails.each do |popmail|
yield popmail
Expand Down

0 comments on commit c0d843c

Please sign in to comment.