Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up application to connect to Gmail to send emails
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ | |
/log/*.log | ||
/tmp | ||
/public/system | ||
|
||
config/initializers/mail.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |