Sha256: 5dd4ef3d7f0dc6d769102ec3876ff56ba8760551b3f9c6845b1cc6350e2ed4d0

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

describe "roadie integration" do
  class TestApplication
    def config
      OpenStruct.new(:action_mailer => OpenStruct.new(:default_url_options => {:host => "example.app.org"}))
    end
  end

  class IntegrationMailer < ActionMailer::Base
    default :css => :integration, :from => 'john@example.com'
    append_view_path Pathname.new(__FILE__).dirname.join('fixtures').join('views')

    def notification(to, reason)
      @reason = reason
      mail(:subject => 'Notification for you', :to => to) { |format| format.html; format.text }
    end
  end

  before(:each) do
    Rails.stub!(:root => Pathname.new(__FILE__).dirname.join('fixtures'), :application => TestApplication.new)
    IntegrationMailer.delivery_method = :test
  end

  it "should inline styles for an email" do
    email = IntegrationMailer.notification('doe@example.com', 'your quota limit has been reached')

    email.to.should == ['doe@example.com']
    email.from.should == ['john@example.com']
    email.should have(2).parts

    email.parts.find { |part| part.mime_type == 'text/html' }.tap do |html_part|
      document = Nokogiri::HTML.parse(html_part.body.decoded)
      document.should have_selector('html > head + body')
      document.should have_selector('body #message h1')
      document.should have_styling('background' => 'url(http://example.app.org/images/dots.png) repeat-x').at_selector('body')
      document.should have_selector('strong[contains("quota")]')
    end

    email.parts.find { |part| part.mime_type == 'text/plain' }.tap do |plain_part|
      plain_part.body.decoded.should_not match(/<.*>/)
    end

    email.deliver
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roadie-1.0.0.pre2 spec/integration_spec.rb
roadie-1.0.0.pre1 spec/integration_spec.rb