Skip to content

Commit

Permalink
Set up application to connect to Gmail to send emails
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Jul 28, 2012
1 parent efee20e commit 4c83864
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -14,3 +14,5 @@
/log/*.log
/tmp
/public/system

config/initializers/mail.rb
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -20,6 +20,7 @@ gem 'jquery-rails'
gem 'debugger'

group :test, :development do
gem 'gmail', '0.4.0'
gem 'rspec-rails', '~> 2.9'
end

Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Expand Up @@ -82,6 +82,12 @@ GEM
factory_girl (2.6.4)
activesupport (>= 2.3.9)
ffi (1.0.11)
gmail (0.4.0)
gmail_xoauth (>= 0.3.0)
mail (>= 2.2.1)
mime (>= 0.1)
gmail_xoauth (0.3.2)
oauth (>= 0.3.6)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
Expand All @@ -95,9 +101,11 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime (0.1)
mime-types (1.18)
multi_json (1.2.0)
nokogiri (1.5.2)
oauth (0.4.6)
orm_adapter (0.0.7)
paperclip (2.7.0)
activerecord (>= 2.3.0)
Expand Down Expand Up @@ -186,6 +194,7 @@ DEPENDENCIES
dynamic_form (= 1.1.4)
email_spec (= 1.2.1)
factory_girl (= 2.6.4)
gmail (= 0.4.0)
jquery-rails
launchy
paperclip (= 2.7.0)
Expand Down
1 change: 1 addition & 0 deletions app/mailers/notifier.rb
@@ -1,4 +1,5 @@
class Notifier < ActionMailer::Base
# default from: "Ticketee App <#{ActionMailer::Base.smtp_settings[:user_name]}>"
default from: "from@example.com"

def comment_updated(comment, user)
Expand Down
16 changes: 16 additions & 0 deletions bin/oauth
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'oauth' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('oauth', 'oauth')
35 changes: 35 additions & 0 deletions spec/integration/gmail_spec.rb
@@ -0,0 +1,35 @@
require 'spec_helper'

feature "Gmail" do
let!(:alice) { Factory(:confirmed_user) }
let!(:me) { Factory(:confirmed_user, :email => "radarlistener@gmail.com") }
let!(:project) { Factory(:project) }
let!(:ticket) do
Factory(:ticket, :project => project,
:user => me)
end

before do
ActionMailer::Base.delivery_method = :smtp
define_permission!(alice, "view", project)
define_permission!(me, "view", project)
end

after do
ActionMailer::Base.delivery_method = :test
end

scenario "Receiving a real-world email" do
sign_in_as!(alice)
visit project_ticket_path(project, ticket)
fill_in "comment_text", :with => "Posting a comment1"
click_button "Create Comment"
page.should have_content("Comment has been created.")

ticketee_emails.count.should == 1
email = ticketee_emails.first
subject = "[ticketee] #{project.name} - #{ticket.title}"
email.subject.should == subject
clear_ticketee_emails!
end
end
20 changes: 20 additions & 0 deletions spec/support/gmail_helpers.rb
@@ -0,0 +1,20 @@
module GmailHelpers
def gmail_connection
settings = ActionMailer::Base.smtp_settings
@gmail_connection ||= Gmail.connect(settings[:user_name],
settings[:password])
end

def ticketee_emails
gmail_connection.inbox.find(:unread,
:from => "Ticketee App")
end

def clear_ticketee_emails!
ticketee_emails.map(&:delete!)
end
end

RSpec.configure do |c|
c.include GmailHelpers
end

0 comments on commit 4c83864

Please sign in to comment.