aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/track_mailer.rb3
-rw-r--r--app/models/user.rb5
-rw-r--r--spec/models/track_mailer_spec.rb25
-rw-r--r--spec/models/user_spec.rb42
4 files changed, 64 insertions, 11 deletions
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 792191bd9..8c87d39c2 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: track_mailer.rb,v 1.16 2009-03-17 23:22:01 francis Exp $
+# $Id: track_mailer.rb,v 1.17 2009-04-09 12:22:46 louise Exp $
class TrackMailer < ApplicationMailer
def event_digest(user, email_about_things)
@@ -95,6 +95,7 @@ class TrackMailer < ApplicationMailer
end
end
user.last_daily_track_email = now
+ user.no_reindex = true
user.save!
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 4638583e2..f7c77af56 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,7 +23,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: user.rb,v 1.88 2009-04-08 07:31:07 francis Exp $
+# $Id: user.rb,v 1.89 2009-04-09 12:22:46 louise Exp $
require 'digest/sha1'
@@ -43,7 +43,7 @@ class User < ActiveRecord::Base
has_many :track_things, :foreign_key => 'tracking_user_id', :order => 'created_at desc'
has_many :comments, :order => 'created_at desc'
- attr_accessor :password_confirmation
+ attr_accessor :password_confirmation, :no_reindex
validates_confirmation_of :password, :message =>"^Please enter the same password twice"
validates_inclusion_of :admin_level, :in => [
@@ -74,6 +74,7 @@ class User < ActiveRecord::Base
# requested_by: and commented_by: search queries also need updating after save
after_save :reindex_referencing_models
def reindex_referencing_models
+ return if no_reindex == true
for comment in self.comments
for info_request_event in comment.info_request_events
info_request_event.xapian_mark_needs_index
diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb
index 11e34c0cc..a2016f3d1 100644
--- a/spec/models/track_mailer_spec.rb
+++ b/spec/models/track_mailer_spec.rb
@@ -18,9 +18,11 @@ describe TrackMailer do
describe 'for each user' do
before do
- @user = mock_model(User, :last_daily_track_email= => true,
- :save! => true)
+ @user = mock_model(User, :no_reindex= => false,
+ :last_daily_track_email= => true,
+ :save! => true)
User.stub!(:find).and_return([@user])
+ @user.stub!(:no_reindex=)
end
it 'should ask for any daily track things for the user' do
@@ -29,6 +31,19 @@ describe TrackMailer do
TrackMailer.alert_tracks
end
+
+ it 'should set the no_reindex flag on the user' do
+ @user.should_receive(:no_reindex=).with(true)
+ TrackMailer.alert_tracks
+ end
+
+ it 'should update the time of the user\'s last daily tracking email' do
+ @user.should_receive(:last_daily_track_email=).with(Time.now)
+ @user.should_receive(:save!)
+ TrackMailer.alert_tracks
+ end
+
+
describe 'for each tracked thing' do
before do
@@ -84,12 +99,6 @@ describe TrackMailer do
TrackMailer.alert_tracks
end
end
-
- it 'should update the time of the user\'s last daily tracking email' do
- @user.should_receive(:last_daily_track_email=).with(Time.now)
- @user.should_receive(:save!)
- TrackMailer.alert_tracks
- end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 46aa046fb..5f29ebeb6 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -84,6 +84,48 @@ describe User, " when saving" do
@user2.email = "flobble2@localhost"
@user2.save!
end
+
+
+end
+
+describe User, "when reindexing referencing models" do
+
+ before do
+ @request_event = mock_model(InfoRequestEvent, :xapian_mark_needs_index => true)
+ @request = mock_model(InfoRequest, :info_request_events => [@request_event])
+ @comment_event = mock_model(InfoRequestEvent, :xapian_mark_needs_index => true)
+ @comment = mock_model(Comment, :info_request_events => [@comment_event])
+ @user = User.new(:comments => [@comment], :info_requests => [@request])
+ end
+
+ it 'should reindex events associated with that user\'s comments' do
+ @comment_event.should_receive(:xapian_mark_needs_index)
+ @user.reindex_referencing_models
+ end
+
+ it 'should reindex events associated with that user\'s requests' do
+ @request_event.should_receive(:xapian_mark_needs_index)
+ @user.reindex_referencing_models
+ end
+
+ describe 'when no_reindex is set' do
+
+ before do
+ @user.no_reindex = true
+ end
+
+ it 'should not reindex events associated with that user\'s comments' do
+ @comment_event.should_not_receive(:xapian_mark_needs_index)
+ @user.reindex_referencing_models
+ end
+
+ it 'should not reindex events associated with that user\'s requests' do
+ @request_event.should_not_receive(:xapian_mark_needs_index)
+ @user.reindex_referencing_models
+ end
+
+ end
+
end
describe User, "when checking abilities" do