aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request.rb14
-rw-r--r--spec/models/info_request_spec.rb55
2 files changed, 65 insertions, 4 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index a7ff58c28..bc7247806 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.180 2009-04-06 08:34:35 louise Exp $
+# $Id: info_request.rb,v 1.181 2009-04-06 10:58:03 louise Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -330,6 +330,11 @@ public
return ['requires_admin', 'error_message']
end
+ def requires_admin?
+ return true if InfoRequest.requires_admin_states.include?(described_state)
+ return false
+ end
+
# change status, including for last event for later historical purposes
def set_described_state(new_state)
ActiveRecord::Base.transaction do
@@ -343,7 +348,7 @@ public
self.calculate_event_states
- if InfoRequest.requires_admin_states.include?(new_state)
+ if self.requires_admin?
RequestMailer.deliver_requires_admin(self)
end
end
@@ -711,6 +716,11 @@ public
def is_owning_user?(user)
!user.nil? && (user.id == user_id || user.owns_every_request?)
end
+
+ def is_real_owning_user?(user)
+ !user.nil? && (user.id == user_id)
+ end
+
end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 51d2d559f..299a9656e 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -136,7 +136,7 @@ describe InfoRequest do
@info_request.is_owning_user?(nil).should be_false
end
- it 'should return true if the user is the request\'s user' do
+ it 'should return true if the user is the request\'s owner' do
@info_request.is_owning_user?(@mock_user).should be_true
end
@@ -145,11 +145,62 @@ describe InfoRequest do
@info_request.is_owning_user?(@other_mock_user).should be_false
end
- it 'should return true if the user owns every request' do
+ it 'should return true if the user is not the owner but 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
+ describe 'when asked if a user is the real owner of 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_real_owning_user?(nil).should be_false
+ end
+
+ it 'should return true if the user is the request\'s owner' do
+ @info_request.is_real_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_real_owning_user?(@other_mock_user).should be_false
+ end
+
+ it 'should return false if the user is not the owner but owns every request' do
+ @other_mock_user.stub!(:owns_every_request?).and_return(true)
+ @info_request.is_real_owning_user?(@other_mock_user).should be_false
+ end
+
+ end
+
+ describe 'when asked if it requires admin' do
+
+ before do
+ @info_request = InfoRequest.new
+ end
+
+ it 'should return true if it\'s described state is error_message' do
+ @info_request.described_state = 'error_message'
+ @info_request.requires_admin?.should be_true
+ end
+
+ it 'should return true if it\'s described state is requires_admin' do
+ @info_request.described_state = 'requires_admin'
+ @info_request.requires_admin?.should be_true
+ end
+
+ it 'should return false if it\'s described state is waiting_response' do
+ @info_request.described_state = 'waiting_response'
+ @info_request.requires_admin?.should be_false
+ end
+
+ end
+
end \ No newline at end of file