Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added email ticket notifications

  • Loading branch information...
commit e8f78b52455b9d7c56452392df7cca8aca2aae41 1 parent ae2ac03
@prakhar1989 authored
View
10 app/mailers/notifier.rb
@@ -0,0 +1,10 @@
+class Notifier < ActionMailer::Base
+ default from: "ticketee@gmail.com"
+
+ def comment_updated(comment, user)
+ @comment = comment
+ @user = user
+ mail(:to => user.email,
+ :subject => "[ticketee] #{comment.ticket.project.name} - #{comment.ticket.title}")
+ end
+end
View
7 app/models/ticket.rb
@@ -16,6 +16,8 @@ class Ticket < ActiveRecord::Base
accepts_nested_attributes_for :assets
has_many :comments
has_and_belongs_to_many :tags
+ has_and_belongs_to_many :watchers, :join_table => "ticket_watchers", :class_name => "User"
+ after_create :creator_watches_me
def tag!(tags)
tags = tags.split(" ").map do |tag|
@@ -23,4 +25,9 @@ def tag!(tags)
end
self.tags << tags
end
+
+ private
+ def creator_watches_me
+ self.watchers << user
+ end
end
View
7 app/observers/comment_observer.rb
@@ -0,0 +1,7 @@
+class CommentObserver < ActiveRecord::Observer
+ def after_create(comment)
+ (comment.ticket.watchers - [comment.user]).each do |user|
+ Notifier.comment_updated(comment, user).deliver
+ end
+ end
+end
View
8 app/views/notifier/comment_updated.text.erb
@@ -0,0 +1,8 @@
+Hello!
+
+<%= @comment.user %> has just updated the <%= @comment.ticket.title %> ticket for <%= @comment.ticket.project.name %>. They wrote:
+
+<%= @comment.text %>
+
+You can view this ticket by going to:
+<%= project_ticket_url(@comment.ticket.project, @comment.ticket) %>
View
34 config/application.rb
@@ -11,27 +11,8 @@
module Tickteee
class Application < Rails::Application
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Custom directories with classes and modules you want to be autoloadable.
- # config.autoload_paths += %W(#{config.root}/extras)
-
- # Only load the plugins named here, in the order given (default is alphabetical).
- # :all can be used as a placeholder for all plugins not explicitly named.
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
-
- # Activate observers that should always be running.
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
+ # referencing custom Observer class
+ config.active_record.observers = :comment_observer
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
@@ -39,17 +20,6 @@ class Application < Rails::Application
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
- # Use SQL instead of Active Record's schema dumper when creating the database.
- # This is necessary if your schema can't be completely dumped by the schema dumper,
- # like if you have constraints or database-specific column types
- # config.active_record.schema_format = :sql
-
- # Enforce whitelist mode for mass assignment.
- # This will create an empty whitelist of attributes available for mass-assignment for all models
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
- # parameters by using an attr_accessible or attr_protected declaration.
- # config.active_record.whitelist_attributes = true
-
# Enable the asset pipeline
config.assets.enabled = true
View
7 db/migrate/20120329053505_create_ticket_watchers_table.rb
@@ -0,0 +1,7 @@
+class CreateTicketWatchersTable < ActiveRecord::Migration
+ def change
+ create_table :ticket_watchers, :id => false do |t|
+ t.integer :user_id, :ticket_id
+ end
+ end
+end
View
7 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120326211039) do
+ActiveRecord::Schema.define(:version => 20120329053505) do
create_table "assets", :force => true do |t|
t.string "asset_file_name"
@@ -64,6 +64,11 @@
t.integer "ticket_id"
end
+ create_table "ticket_watchers", :id => false, :force => true do |t|
+ t.integer "user_id"
+ t.integer "ticket_id"
+ end
+
create_table "tickets", :force => true do |t|
t.string "title"
t.text "description"
View
28 features/ticket_notifications.feature
@@ -0,0 +1,28 @@
+Feature: Ticket Notifications
+ Background:
+ Given there are the following users:
+ | email | password |
+ | alice@ticketee.com | password |
+ | bob@ticketee.com | password |
+ Given a clear email queue
+ Given there is a project called "Textmate 2"
+ And "alice@ticketee.com" can view the "Textmate 2" project
+ And "bob@ticketee.com" can view the "Textmate 2" project
+ And "alice@ticketee.com" has created a ticket for this project:
+ | title | description |
+ | Release date | TBA very shortly |
+ Given I am signed in as "bob@ticketee.com"
+ Given I am on the homepage
+
+ Scenario: Ticket owner is automatically subscribed to a ticket
+ When I follow "Textmate 2"
+ And I follow "Release date"
+ And I fill in "Text" with "Is it out yet?"
+ And I press "Create Comment"
+
+ Then "alice@ticketee.com" should receive an email
+ When "alice@ticketee.com" opens the email
+ Then they should see "updated the Release date ticket" in the email body
+ And they should see "[ticketee] Textmate 2 - Release date" in the email subject
+ Then they click the first link in the email
+ Then I should see "Release date" within "#ticket h2"
View
5 spec/mailers/notifier_spec.rb
@@ -0,0 +1,5 @@
+require "spec_helper"
+
+describe Notifier do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.