Sha256: ca7420c2dfc6f70c618c61995915671f47642d5e5a7d2e034d45b59ff5a9850f

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe Mail::Postmark do
  let(:message) do
    Mail.new do
      from    "sheldon@bigbangtheory.com"
      to      "lenard@bigbangtheory.com"
      subject "Hello!"
      body    "Hello Sheldon!"
    end
  end

  it "can be set as delivery_method" do
    message.delivery_method Mail::Postmark
  end

  it "wraps Postmark.send_through_postmark" do
    allow_any_instance_of(Postmark::ApiClient).to receive(:deliver_message).with(message)
    message.delivery_method Mail::Postmark
    message.deliver
  end

  it "returns self by default" do
    allow_any_instance_of(Postmark::ApiClient).to receive(:deliver_message).with(message)
    message.delivery_method Mail::Postmark
    message.deliver.should eq message
  end

  it "returns the actual response if :return_response setting is present" do
    allow_any_instance_of(Postmark::ApiClient).to receive(:deliver_message).with(message)
    message.delivery_method Mail::Postmark, :return_response => true
    message.deliver.should eq message
  end

  it "allows setting the api token" do
    message.delivery_method Mail::Postmark, :api_token => 'api-token'
    message.delivery_method.settings[:api_token].should == 'api-token'
  end

  it 'uses provided API token' do
    message.delivery_method Mail::Postmark, :api_token => 'api-token'
    expect(Postmark::ApiClient).to receive(:new).with('api-token', {}).and_return(double(:deliver_message => true))
    message.deliver
  end

  it 'uses API token provided as legacy api_key' do
    message.delivery_method Mail::Postmark, :api_key => 'api-token'
    expect(Postmark::ApiClient).to receive(:new).with('api-token', {}).and_return(double(:deliver_message => true))
    message.deliver
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
postmark-1.14.0 spec/unit/postmark/handlers/mail_spec.rb
postmark-1.13.0 spec/unit/postmark/handlers/mail_spec.rb
postmark-1.12.0 spec/unit/postmark/handlers/mail_spec.rb
postmark-1.11.0 spec/unit/postmark/handlers/mail_spec.rb