Skip to content

Commit

Permalink
Add tests for Mailer support
Browse files Browse the repository at this point in the history
  • Loading branch information
vnegrisolo committed Sep 23, 2016
1 parent f0dcbca commit 831ba99
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions decent_exposure.gemspec
Expand Up @@ -24,5 +24,6 @@ Gem::Specification.new do |spec|

spec.add_dependency "activesupport", ">= 4.0"
spec.add_development_dependency "railties", ">= 4.0"
spec.add_development_dependency "actionmailer"
spec.add_development_dependency "rspec-rails", "~> 3.0"
end
46 changes: 46 additions & 0 deletions spec/features/birds_mailer_spec.rb
@@ -0,0 +1,46 @@
require "spec_helper"
require "support/rails_app"
require "rspec/rails"
require "action_mailer"

class BirdsMailer < ActionMailer::Base
end

RSpec.describe BirdsMailer, type: :mailer do
let(:bird){ double :bird }
let(:birds) { double :birds }

context "when birds relation is exposed" do
class BirdsMailer
expose(:birds, -> { Bird.all })

def hello_birds
mail { |format| format.text { render plain: "Hello #{birds}" } }
end
end

it "sends the email with exposed birds" do
expect(Bird).to receive(:all).and_return(birds)
expect(described_class.hello_birds.body.to_s)
.to include("Hello #{birds}")
end
end

context "when bird is exposed" do
class BirdsMailer
attr_accessor :bird_id
expose(:bird, id: -> { bird_id })

def hello_bird(id)
self.bird_id = id
mail { |format| format.text { render plain: "Hello #{bird}" } }
end
end

it "sends the email with exposed bird" do
expect(Bird).to receive(:find).with('some-id').and_return(bird)
expect(described_class.hello_bird('some-id').body.to_s)
.to include("Hello #{bird}")
end
end
end
4 changes: 4 additions & 0 deletions spec/support/rails_app.rb
Expand Up @@ -23,6 +23,10 @@ def routes
end
end

def self.root
''
end

def self.application
@app ||= App.new
end
Expand Down

0 comments on commit 831ba99

Please sign in to comment.