Class: EmailHelper::EmailCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/watirmark/cucumber/email_helper.rb

Class Method Summary collapse

Class Method Details

.[](model) ⇒ Object

Access a cached copy of an email



66
67
68
# File 'lib/watirmark/cucumber/email_helper.rb', line 66

def [](model)
  email[model.model_name]
end

.delete(model) ⇒ Object

Remove our cached copy of the email



71
72
73
# File 'lib/watirmark/cucumber/email_helper.rb', line 71

def delete(model)
  email[model.model_name] = nil
end

.emailObject



15
16
17
# File 'lib/watirmark/cucumber/email_helper.rb', line 15

def email
  @email ||= {}
end

.email_address(model) ⇒ Object

Format the email address so we’re always referring to the qasendmail domain



76
77
78
# File 'lib/watirmark/cucumber/email_helper.rb', line 76

def email_address(model)
  model.email.gsub(/\+.+/,'').gsub(/@.+/, '@qasendmail.corp.convio.com')
end

.found_email(model) ⇒ Object

Return an email if we’ve seen it



25
26
27
# File 'lib/watirmark/cucumber/email_helper.rb', line 25

def found_email(model)
  email[model.model_name]
end

.log_email(model) ⇒ Object



60
61
62
63
# File 'lib/watirmark/cucumber/email_helper.rb', line 60

def log_email(model)
  Watirmark.logger.info "Email Received"
  Watirmark.logger.info email[model.model_name].body.inspect
end

.options_hash_to_array(hash_of_search_params) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/watirmark/cucumber/email_helper.rb', line 37

def options_hash_to_array(hash_of_search_params)
  converted_array = Array.new
  hash_of_search_params.each do | search_key, search_value |
    converted_array << search_key.to_s.upcase
    converted_array << search_value.to_s
  end
  converted_array
end

.qa_inbox(model) ⇒ Object

Connect to the INBOX



20
21
22
# File 'lib/watirmark/cucumber/email_helper.rb', line 20

def qa_inbox(model)
  WatirmarkEmail::QAMail.new(email_address(model) )
end

.read_email(model, options_hash, timeout = 30) ⇒ Object

Read the contents of an email, cache it and delete the email



30
31
32
33
34
35
# File 'lib/watirmark/cucumber/email_helper.rb', line 30

def read_email(model, options_hash, timeout=30)
  Kernel.raise ArgumentError, 'The options provided are not in the form of a hash, i.e. {:subject => "subject"}' unless options_hash.is_a?(Hash)
  search_array = options_hash_to_array(options_hash)
  email_content = qa_inbox(model).get_email_text(search_array, timeout)
  email[model.model_name] = EmailBody.new(email_content)
end

.read_email_from(model, from, timeout = 30) ⇒ Object



46
47
48
49
# File 'lib/watirmark/cucumber/email_helper.rb', line 46

def read_email_from(model, from, timeout=30)
  Kernel.warn(self.to_s + ':>' + Kernel.__callee__.to_s + ': This method is deprecated, please use read_email')
  read_email(model, {:from => from, :to => model.email}, timeout)
end

.read_email_replyto(model, from, timeout = 30) ⇒ Object



51
52
53
# File 'lib/watirmark/cucumber/email_helper.rb', line 51

def read_email_replyto(model, from, timeout=30)
  qa_inbox(model).get_email_replyto(["FROM", from, "TO", model.email], timeout)
end

.read_email_subject_and_from(model, from, subject, timeout = 30) ⇒ Object



55
56
57
58
# File 'lib/watirmark/cucumber/email_helper.rb', line 55

def read_email_subject_and_from(model, from, subject, timeout=30)
  Kernel.warn(self.to_s + ':>' + Kernel.__callee__.to_s + ': This method is deprecated, please use read_email')
  read_email(model, {:from => from, :to => model.email, :subject => subject}, timeout)
end