aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/info_request_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/info_request_spec.rb')
-rw-r--r--spec/models/info_request_spec.rb100
1 files changed, 81 insertions, 19 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 41d01c89a..c55127992 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -401,25 +401,87 @@ describe InfoRequest do
end
- context "with regexp censor rule" do
- before do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
- @info_request = InfoRequest.create!(:prominence => 'normal',
- :awaiting_description => true,
- :title => 'title',
- :public_body => public_bodies(:geraldine_public_body),
- :user_id => 1)
- @censor_rule = CensorRule.create(:last_edit_editor => 1,
- :last_edit_comment => 'comment',
- :text => 'text',
- :replacement => 'replacement',
- :regexp => true)
- end
- it "applies regexp censor rule" do
- body = 'text'
- @info_request.apply_censor_rules_to_text!(body)
- body.should == 'replacement'
- end
+ describe 'when applying censor rules' do
+
+ before do
+ @global_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @user_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @request_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @body_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @user = mock_model(User, :censor_rules => [@user_rule])
+ @body = mock_model(PublicBody, :censor_rules => [@body_rule])
+ @info_request = InfoRequest.new(:prominence => 'normal',
+ :awaiting_description => true,
+ :title => 'title')
+ @info_request.stub!(:user).and_return(@user)
+ @info_request.stub!(:censor_rules).and_return([@request_rule])
+ @info_request.stub!(:public_body).and_return(@body)
+ @text = 'some text'
+ CensorRule.stub!(:global).and_return(mock('global context', :all => [@global_rule]))
+ end
+
+ context "when applying censor rules to text" do
+
+ it "should apply a global censor rule" do
+ @global_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ it 'should apply a user rule' do
+ @user_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ it 'should not raise an error if there is no user' do
+ @info_request.user_id = nil
+ lambda{ @info_request.apply_censor_rules_to_text!(@text) }.should_not raise_error
+ end
+
+ it 'should apply a rule from the body associated with the request' do
+ @body_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ it 'should apply a request rule' do
+ @request_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ end
+
+ context 'when applying censor rules to binary files' do
+
+ it "should apply a global censor rule" do
+ @global_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ it 'should apply a user rule' do
+ @user_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ it 'should not raise an error if there is no user' do
+ @info_request.user_id = nil
+ lambda{ @info_request.apply_censor_rules_to_binary!(@text) }.should_not raise_error
+ end
+
+ it 'should apply a rule from the body associated with the request' do
+ @body_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ it 'should apply a request rule' do
+ @request_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ end
+
end
describe 'when an instance is asked if all can view it' do