Permalink
Browse files

Set up application to connect to Gmail to send emails

  • Loading branch information...
1 parent efee20e commit 4c838649a733d549d45391f45e437be1b6dbec6a @radar radar committed Jul 28, 2012
Showing with 84 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 Gemfile
  3. +9 −0 Gemfile.lock
  4. +1 −0 app/mailers/notifier.rb
  5. +16 −0 bin/oauth
  6. +35 −0 spec/integration/gmail_spec.rb
  7. +20 −0 spec/support/gmail_helpers.rb
View
@@ -14,3 +14,5 @@
/log/*.log
/tmp
/public/system
+
+config/initializers/mail.rb
View
@@ -20,6 +20,7 @@ gem 'jquery-rails'
gem 'debugger'
group :test, :development do
+ gem 'gmail', '0.4.0'
gem 'rspec-rails', '~> 2.9'
end
View
@@ -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)
@@ -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)
@@ -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)
View
@@ -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)
View
@@ -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')
@@ -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
@@ -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.