aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-09-28 10:49:31 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-11-09 21:11:02 +0100
commit8a67fb2aa9b9b3424fbd05edbab5d404ab62e871 (patch)
tree31c009592ab39dd1370d06b5e5c7854ba179815f
parentUse bundler to manage gems for application (diff)
downloadrecruiting-webapp-8a67fb2aa9b9b3424fbd05edbab5d404ab62e871.tar.gz
recruiting-webapp-8a67fb2aa9b9b3424fbd05edbab5d404ab62e871.tar.bz2
recruiting-webapp-8a67fb2aa9b9b3424fbd05edbab5d404ab62e871.zip
Send emails as delayed job
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock4
-rw-r--r--app/models/answer.rb4
-rw-r--r--app/models/comment.rb2
-rw-r--r--app/models/email_answer.rb2
-rw-r--r--app/models/job.rb18
-rw-r--r--app/models/question.rb2
-rw-r--r--db/schema.rb15
-rw-r--r--spec/models/answer_spec.rb4
-rw-r--r--spec/models/comment_spec.rb2
-rw-r--r--spec/models/email_answer_spec.rb4
-rw-r--r--spec/models/question_spec.rb4
12 files changed, 49 insertions, 13 deletions
diff --git a/Gemfile b/Gemfile
index d1ad142..ed5a399 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,6 +5,7 @@ gem 'hobo'
gem 'hobo_openid', '>=0.4.2'
gem 'bluecloth'
gem 'mysql'
+gem 'delayed_job'
group :test do
gem 'database_cleaner'
diff --git a/Gemfile.lock b/Gemfile.lock
index aae58bb..0892b21 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -22,7 +22,10 @@ GEM
term-ansicolor (~> 1.0.5)
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
+ daemons (1.1.0)
database_cleaner (0.6.0)
+ delayed_job (2.0.3)
+ daemons
diff-lcs (1.1.2)
email_spec (0.6.2)
factory_girl (1.3.2)
@@ -81,6 +84,7 @@ DEPENDENCIES
bluecloth
cucumber-rails
database_cleaner
+ delayed_job
email_spec (= 0.6.2)
factory_girl
hobo
diff --git a/app/models/answer.rb b/app/models/answer.rb
index 47544b3..d477e26 100644
--- a/app/models/answer.rb
+++ b/app/models/answer.rb
@@ -149,12 +149,12 @@ class Answer < ActiveRecord::Base
protected
# Sends email notification about new answer to mentor of owner
def notify_new_answer
- UserMailer.deliver_new_answer(owner.mentor, self) unless owner._?.mentor.nil?
+ UserMailer.send_later(:deliver_new_answer, owner.mentor, self) unless owner._?.mentor.nil?
end
# Sends email notification about changed answer to mentor of owner
def notify_changed_answer
- UserMailer.deliver_changed_answer(owner.mentor, self) unless owner._?.mentor.nil?
+ UserMailer.send_later(:deliver_changed_answer, owner.mentor, self) unless owner._?.mentor.nil?
end
end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 83d5f9f..c10a8f2 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -47,6 +47,6 @@ class Comment < ActiveRecord::Base
protected
# Sends notification about new comment to owner of mentor
def notify_new_comment
- UserMailer.deliver_new_comment(answer.owner, self)
+ UserMailer.send_later(:deliver_new_comment, answer.owner, self)
end
end
diff --git a/app/models/email_answer.rb b/app/models/email_answer.rb
index f1bd4a5..ffec1ac 100644
--- a/app/models/email_answer.rb
+++ b/app/models/email_answer.rb
@@ -36,7 +36,7 @@ class EmailAnswer < Answer
question = Question.first :conditions => { :id => subject.captures[0] }
if(question.nil? || !question.content.is_a?(QuestionContentEmail))
- UserMailer.deliver_unrecognized_email(user, email)
+ UserMailer.send_later(:deliver_unrecognized_email, user, email)
return
end
diff --git a/app/models/job.rb b/app/models/job.rb
new file mode 100644
index 0000000..7afa6f7
--- /dev/null
+++ b/app/models/job.rb
@@ -0,0 +1,18 @@
+# Don't use this class.
+#
+# Only purpose of this class is to let hobo_migration generator know that it
+# should create delayed_jobs table.
+class Job < ActiveRecord::Base
+ set_table_name "delayed_jobs"
+ fields do
+ priority :integer, :default => 0
+ attempts :integer, :default => 0
+ handler :text
+ last_error :string
+ run_at :datetime
+ locked_at :datetime
+ failed_at :datetime
+ locked_by :string
+ timestamps
+ end
+end
diff --git a/app/models/question.rb b/app/models/question.rb
index 294e03e..c377d5e 100644
--- a/app/models/question.rb
+++ b/app/models/question.rb
@@ -186,7 +186,7 @@ class Question < ActiveRecord::Base
# If question category isn't assigned don't try to access it
if question_category && approved
for user in question_category.users
- UserMailer.deliver_new_question user, self
+ UserMailer.send_later(:deliver_new_question, user, self)
end
end
end
diff --git a/db/schema.rb b/db/schema.rb
index aee7dbd..9fcf580 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100811164808) do
+ActiveRecord::Schema.define(:version => 20101005121508) do
create_table "answers", :force => true do |t|
t.text "content", :default => "", :null => false
@@ -39,6 +39,19 @@ ActiveRecord::Schema.define(:version => 20100811164808) do
add_index "comments", ["answer_id"], :name => "index_comments_on_answer_id"
add_index "comments", ["owner_id"], :name => "index_comments_on_owner_id"
+ create_table "delayed_jobs", :force => true do |t|
+ t.integer "priority", :default => 0
+ t.integer "attempts", :default => 0
+ t.text "handler"
+ t.string "last_error"
+ t.datetime "run_at"
+ t.datetime "locked_at"
+ t.datetime "failed_at"
+ t.string "locked_by"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "options", :force => true do |t|
t.string "content", :null => false
t.datetime "created_at"
diff --git a/spec/models/answer_spec.rb b/spec/models/answer_spec.rb
index b9cdb05..200077d 100644
--- a/spec/models/answer_spec.rb
+++ b/spec/models/answer_spec.rb
@@ -141,14 +141,14 @@ describe Answer do
#can't use Factory Girl here, because we want to save it after setting expectation to get email
answer = Answer.new(:owner => recruit, :question => question, :content => "Some answer.")
- UserMailer.should_receive(:deliver_new_answer).with(recruit.mentor, answer)
+ UserMailer.should_receive(:send_later).with(:deliver_new_answer, recruit.mentor, answer)
answer.save!
end
it "should send email notification to mentor when changed" do
answer = Factory(:answer)
- UserMailer.should_receive(:deliver_changed_answer).with(answer.owner.mentor, answer)
+ UserMailer.should_receive(:send_later).with(:deliver_changed_answer, answer.owner.mentor, answer)
answer.content = "changed"
answer.save!
end
diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb
index f3a52b1..8a071c6 100644
--- a/spec/models/comment_spec.rb
+++ b/spec/models/comment_spec.rb
@@ -49,7 +49,7 @@ describe Comment do
answer = Factory(:answer)
comment = Comment.new(:owner => answer.owner.mentor, :answer => answer, :content => "some comment")
- UserMailer.should_receive(:deliver_new_comment).with(answer.owner, comment)
+ UserMailer.should_receive(:send_later).with(:deliver_new_comment, answer.owner, comment)
comment.save!
end
diff --git a/spec/models/email_answer_spec.rb b/spec/models/email_answer_spec.rb
index d4ec177..b452a19 100644
--- a/spec/models/email_answer_spec.rb
+++ b/spec/models/email_answer_spec.rb
@@ -7,7 +7,7 @@ describe EmailAnswer do
mail.subject = "#{question.id + 1}-#{recruit.token}"
mail.from = recruit.email_address
- UserMailer.should_receive(:deliver_unrecognized_email).with(recruit, mail)
+ UserMailer.should_receive(:send_later).with(:deliver_unrecognized_email, recruit, mail)
EmailAnswer.answer_from_email(mail)
end
@@ -18,7 +18,7 @@ describe EmailAnswer do
mail.subject = "#{question.id}-#{recruit.token}"
mail.from = recruit.email_address
- UserMailer.should_receive(:deliver_unrecognized_email).with(recruit, mail)
+ UserMailer.should_receive(:send_later).with(:deliver_unrecognized_email, recruit, mail)
EmailAnswer.answer_from_email(mail)
end
diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb
index 710342f..b8ff206 100644
--- a/spec/models/question_spec.rb
+++ b/spec/models/question_spec.rb
@@ -71,7 +71,7 @@ describe Question do
question = Question.new(:title => "new question",
:question_category => category)
- UserMailer.should_receive(:deliver_new_question).with(recruit, question)
+ UserMailer.should_receive(:send_later).with(:deliver_new_question, recruit, question)
question.save!
end
@@ -82,7 +82,7 @@ describe Question do
question = Factory(:question, :title => "new question",
:question_category => category, :user => Factory(:recruit))
- UserMailer.should_receive(:deliver_new_question).with(recruit, question)
+ UserMailer.should_receive(:send_later).with(:deliver_new_question, recruit, question)
question.approved = true
question.save!
end