Class: Poodle::TestHelpers::MockClient
- Inherits:
-
Object
- Object
- Poodle::TestHelpers::MockClient
- Defined in:
- lib/poodle/test_helpers.rb
Overview
Mock client that captures emails instead of sending them
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#deliveries ⇒ Object
readonly
Returns the value of attribute deliveries.
Instance Method Summary collapse
-
#clear_deliveries ⇒ Object
Clear all captured deliveries.
- #create_test_config ⇒ Object private
-
#deliveries_to(email_address) ⇒ Object
Get all deliveries sent to a specific address.
-
#deliveries_with_subject(subject) ⇒ Object
Get all deliveries with a specific subject.
-
#initialize(config = nil) ⇒ MockClient
constructor
A new instance of MockClient.
-
#last_delivery ⇒ Object
Get the last delivery.
-
#send(from:, to:, subject:, html: nil, text: nil) ⇒ Object
Mock send method that captures email data.
-
#send_email(email) ⇒ Object
Mock send_email method.
-
#send_html(from:, to:, subject:, html:) ⇒ Object
Mock send_html method.
-
#send_text(from:, to:, subject:, text:) ⇒ Object
Mock send_text method.
-
#sent_to?(email_address) ⇒ Boolean
Check if any emails were sent to a specific address.
-
#version ⇒ Object
Get SDK version.
Constructor Details
#initialize(config = nil) ⇒ MockClient
Returns a new instance of MockClient.
32 33 34 35 |
# File 'lib/poodle/test_helpers.rb', line 32 def initialize(config = nil) @config = config || create_test_config @deliveries = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
30 31 32 |
# File 'lib/poodle/test_helpers.rb', line 30 def config @config end |
#deliveries ⇒ Object (readonly)
Returns the value of attribute deliveries.
30 31 32 |
# File 'lib/poodle/test_helpers.rb', line 30 def deliveries @deliveries end |
Instance Method Details
#clear_deliveries ⇒ Object
Clear all captured deliveries
83 84 85 |
# File 'lib/poodle/test_helpers.rb', line 83 def clear_deliveries @deliveries.clear end |
#create_test_config ⇒ Object (private)
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/poodle/test_helpers.rb', line 114 def create_test_config # Create a simple configuration without triggering validation config = Configuration.allocate config.instance_variable_set(:@api_key, "test_key") config.instance_variable_set(:@base_url, "https://api.usepoodle.com") config.instance_variable_set(:@timeout, 30) config.instance_variable_set(:@connect_timeout, 10) config.instance_variable_set(:@debug, false) config.instance_variable_set(:@http_options, {}) config end |
#deliveries_to(email_address) ⇒ Object
Get all deliveries sent to a specific address
98 99 100 |
# File 'lib/poodle/test_helpers.rb', line 98 def deliveries_to(email_address) @deliveries.select { |delivery| delivery[:to] == email_address } end |
#deliveries_with_subject(subject) ⇒ Object
Get all deliveries with a specific subject
103 104 105 |
# File 'lib/poodle/test_helpers.rb', line 103 def deliveries_with_subject(subject) @deliveries.select { |delivery| delivery[:subject].include?(subject) } end |
#last_delivery ⇒ Object
Get the last delivery
88 89 90 |
# File 'lib/poodle/test_helpers.rb', line 88 def last_delivery @deliveries.last end |
#send(from:, to:, subject:, html: nil, text: nil) ⇒ Object
Mock send method that captures email data
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/poodle/test_helpers.rb', line 38 def send(from:, to:, subject:, html: nil, text: nil) delivery = { from: from, to: to, subject: subject, html: html, text: text, sent_at: Time.now } @deliveries << delivery EmailResponse.new( success: true, message: "Email queued for sending (test mode)", data: { test_mode: true, delivery_id: @deliveries.length } ) end |
#send_email(email) ⇒ Object
Mock send_email method
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/poodle/test_helpers.rb', line 58 def send_email(email) if email.is_a?(Hash) send(**email.transform_keys(&:to_sym)) else send( from: email.from, to: email.to, subject: email.subject, html: email.html, text: email.text ) end end |
#send_html(from:, to:, subject:, html:) ⇒ Object
Mock send_html method
73 74 75 |
# File 'lib/poodle/test_helpers.rb', line 73 def send_html(from:, to:, subject:, html:) send(from: from, to: to, subject: subject, html: html) end |
#send_text(from:, to:, subject:, text:) ⇒ Object
Mock send_text method
78 79 80 |
# File 'lib/poodle/test_helpers.rb', line 78 def send_text(from:, to:, subject:, text:) send(from: from, to: to, subject: subject, text: text) end |
#sent_to?(email_address) ⇒ Boolean
Check if any emails were sent to a specific address
93 94 95 |
# File 'lib/poodle/test_helpers.rb', line 93 def sent_to?(email_address) @deliveries.any? { |delivery| delivery[:to] == email_address } end |