diff options
author | louise <louise> | 2009-04-14 11:04:52 +0000 |
---|---|---|
committer | louise <louise> | 2009-04-14 11:04:52 +0000 |
commit | 1b306cc7e959cf69a0f3e5a388522a240c770cd9 (patch) | |
tree | ece1fd53152c4084efb613494dcf0bbeec3af2cf | |
parent | 57b0fc86d03fe2ecf1036d6453391c4763eba6b4 (diff) |
Allowing xapian reindexing to be skipped if a no_xapian_reindex flag is set on the model
-rw-r--r-- | app/models/track_mailer.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 6 | ||||
-rw-r--r-- | spec/models/info_request_event_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 33 | ||||
-rw-r--r-- | vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb | 9 |
6 files changed, 70 insertions, 21 deletions
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 8c87d39c2..8b0ad2767 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.17 2009-04-09 12:22:46 louise Exp $ +# $Id: track_mailer.rb,v 1.18 2009-04-14 11:04:55 louise Exp $ class TrackMailer < ApplicationMailer def event_digest(user, email_about_things) @@ -95,7 +95,7 @@ class TrackMailer < ApplicationMailer end end user.last_daily_track_email = now - user.no_reindex = true + user.no_xapian_reindex = true user.save! end end diff --git a/app/models/user.rb b/app/models/user.rb index 995786596..c9df7bf5c 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.90 2009-04-13 09:18:48 tony Exp $ +# $Id: user.rb,v 1.91 2009-04-14 11:04:55 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, :no_reindex + attr_accessor :password_confirmation, :no_xapian_reindex validates_confirmation_of :password, :message =>"^Please enter the same password twice" validates_inclusion_of :admin_level, :in => [ @@ -74,7 +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 + return if no_xapian_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/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index be3ec77c2..428887c8b 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -1,14 +1,29 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe InfoRequestEvent, " when " do - - it "should convert event parameters into YAML and back successfully" do - ire = InfoRequestEvent.new - example_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" } - ire.params = example_params - ire.params_yaml.should == example_params.to_yaml - ire.params.should == example_params +describe InfoRequestEvent do + + describe "when storing serialized parameters" do + + it "should convert event parameters into YAML and back successfully" do + ire = InfoRequestEvent.new + example_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" } + ire.params = example_params + ire.params_yaml.should == example_params.to_yaml + ire.params.should == example_params + end + end + describe 'when saving' do + + it 'should mark the model for reindexing in xapian if there is no no_xapian_reindex flag on the object' do + event = InfoRequestEvent.new(:info_request => mock_model(InfoRequest), + :event_type => 'sent', + :params => {}) + event.should_receive(:xapian_mark_needs_index) + event.save! + end + + end end diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index a2016f3d1..c4b3e4723 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -18,11 +18,11 @@ describe TrackMailer do describe 'for each user' do before do - @user = mock_model(User, :no_reindex= => false, + @user = mock_model(User, :no_xapian_reindex= => false, :last_daily_track_email= => true, :save! => true) User.stub!(:find).and_return([@user]) - @user.stub!(:no_reindex=) + @user.stub!(:no_xapian_reindex=) end it 'should ask for any daily track things for the user' do @@ -32,8 +32,8 @@ describe TrackMailer do end - it 'should set the no_reindex flag on the user' do - @user.should_receive(:no_reindex=).with(true) + it 'should set the no_xapian_reindex flag on the user' do + @user.should_receive(:no_xapian_reindex=).with(true) TrackMailer.alert_tracks end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5f29ebeb6..bf90ffdfb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -84,10 +84,37 @@ describe User, " when saving" do @user2.email = "flobble2@localhost" @user2.save! end - + + it 'should mark the model for reindexing in xapian if the no_xapian_reindex flag is set to false' do + @user.name = "Mr. First" + @user.password = "insecurepassword" + @user.email = "reasonable@localhost" + @user.no_xapian_reindex = false + @user.should_receive(:xapian_mark_needs_index) + @user.save! + end + + it 'should mark the model for reindexing in xapian if the no_xapian_reindex flag is not set' do + @user.name = "Mr. Second" + @user.password = "insecurepassword" + @user.email = "reasonable@localhost" + @user.no_xapian_reindex = nil + @user.should_receive(:xapian_mark_needs_index) + @user.save! + end + + it 'should not mark the model for reindexing in xapian if the no_xapian_reindex flag is set' do + @user.name = "Mr. Third" + @user.password = "insecurepassword" + @user.email = "reasonable@localhost" + @user.no_xapian_reindex = true + @user.should_not_receive(:xapian_mark_needs_index) + @user.save! + end end + describe User, "when reindexing referencing models" do before do @@ -108,10 +135,10 @@ describe User, "when reindexing referencing models" do @user.reindex_referencing_models end - describe 'when no_reindex is set' do + describe 'when no_xapian_reindex is set' do before do - @user.no_reindex = true + @user.no_xapian_reindex = true end it 'should not reindex events associated with that user\'s comments' do diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb index 852669ed8..8be42ccde 100644 --- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb +++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb @@ -711,6 +711,13 @@ module ActsAsXapian job.save! end end + + # Allow reindexing to be skipped if a flag is set + def xapian_mark_needs_index_if_reindex + return true if (self.respond_to?(:no_xapian_reindex) && self.no_xapian_reindex == true) + xapian_mark_needs_index + end + def xapian_mark_needs_destroy model = self.class.base_class.to_s model_id = self.id @@ -743,7 +750,7 @@ module ActsAsXapian ActsAsXapian.init(self.class.to_s, options) - after_save :xapian_mark_needs_index + after_save :xapian_mark_needs_index_if_reindex after_destroy :xapian_mark_needs_destroy end end |