Module: Pickle::Email
- Defined in:
- lib/pickle/email.rb,
lib/pickle/email/parser.rb
Defined Under Namespace
Modules: Parser
Instance Method Summary collapse
- #click_first_link_in_email(email) ⇒ Object
- #email(ref, fields = nil) ⇒ Object
- #email_has_fields?(email, fields) ⇒ Boolean
-
#emails(fields = nil) ⇒ Object
return the deliveries array, optionally selected by the passed fields.
- #visit_in_email(email, link_text) ⇒ Object
Instance Method Details
#click_first_link_in_email(email) ⇒ Object
26 27 28 29 |
# File 'lib/pickle/email.rb', line 26 def click_first_link_in_email(email) link = links_in_email(email).first visit link end |
#email(ref, fields = nil) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/pickle/email.rb', line 8 def email(ref, fields = nil) (match = ref.match(/^#{capture_index_in_email}$/)) or raise ArgumentError, "argument should match #{match_email}" @emails or raise RuntimeError, "Call #emails before calling #email" index = parse_index(match[1]) email_has_fields?(@emails[index], fields) ? @emails[index] : nil end |
#email_has_fields?(email, fields) ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/pickle/email.rb', line 15 def email_has_fields?(email, fields) parse_fields(fields).each do |key, val| return false unless (Array(email.send(key)) & Array(val)).any? end true end |
#emails(fields = nil) ⇒ Object
return the deliveries array, optionally selected by the passed fields
4 5 6 |
# File 'lib/pickle/email.rb', line 4 def emails(fields = nil) @emails = ActionMailer::Base.deliveries.select {|m| email_has_fields?(m, fields)} end |
#visit_in_email(email, link_text) ⇒ Object
22 23 24 |
# File 'lib/pickle/email.rb', line 22 def visit_in_email(email, link_text) visit(parse_email_for_link(email, link_text)) end |