aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlouise <louise>2009-04-06 08:34:35 +0000
committerlouise <louise>2009-04-06 08:34:35 +0000
commited6861f787408e603c238a5e1c8e7c8297a58206 (patch)
tree389a5b3570fe0f2e070d4c2970747f107583400c
parent74978e4c4c79941a5f763d90e66df8fcca3bdc42 (diff)
Adding is_owning_user? method to info request to replace logic in RequestController
-rw-r--r--app/models/info_request.rb7
-rw-r--r--spec/models/info_request_spec.rb29
2 files changed, 35 insertions, 1 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 2208de90e..a7ff58c28 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.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: info_request.rb,v 1.179 2009-04-03 15:28:58 louise Exp $
+# $Id: info_request.rb,v 1.180 2009-04-06 08:34:35 louise Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -700,12 +700,17 @@ public
end
return text
end
+
def apply_censor_rules_to_binary(binary)
for censor_rule in self.censor_rules
binary = censor_rule.apply_to_binary(binary)
end
return binary
end
+
+ def is_owning_user?(user)
+ !user.nil? && (user.id == user_id || user.owns_every_request?)
+ end
end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 41470fda4..51d2d559f 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -123,4 +123,33 @@ describe InfoRequest do
@ir.calculate_status.should == 'waiting_response_overdue'
end
end
+
+ describe 'when asked if a user is the owning user for this request' do
+
+ before do
+ @mock_user = mock_model(User)
+ @info_request = InfoRequest.new(:user => @mock_user)
+ @other_mock_user = mock_model(User)
+ end
+
+ it 'should return false if a nil object is passed to it' do
+ @info_request.is_owning_user?(nil).should be_false
+ end
+
+ it 'should return true if the user is the request\'s user' do
+ @info_request.is_owning_user?(@mock_user).should be_true
+ end
+
+ it 'should return false for a user that is not the owner and does not own every request' do
+ @other_mock_user.stub!(:owns_every_request?).and_return(false)
+ @info_request.is_owning_user?(@other_mock_user).should be_false
+ end
+
+ it 'should return true if the user owns every request' do
+ @other_mock_user.stub!(:owns_every_request?).and_return(true)
+ @info_request.is_owning_user?(@other_mock_user).should be_true
+ end
+
+ end
+
end \ No newline at end of file