diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-22 18:12:21 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-22 18:12:21 +0100 |
commit | 47e617e0fd4562aa19e7862f66600ad4098222c4 (patch) | |
tree | 302216a6cf7206a763e629baed68900cd908c91e /spec/models/info_request_spec.rb | |
parent | 1374da2477cf96eb3d751c1909bbc7b77e7dc0e2 (diff) | |
parent | bc73110b230e607d4d7e5acae467790845784704 (diff) |
Merge branch 'release/0.6.3' into develop
Conflicts:
app/controllers/admin_public_body_controller.rb
app/views/admin_public_body/import_csv.rhtml
spec/controllers/admin_public_body_controller_spec.rb
spec/models/info_request_spec.rb
Diffstat (limited to 'spec/models/info_request_spec.rb')
-rw-r--r-- | spec/models/info_request_spec.rb | 100 |
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 |