diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-22 08:17:16 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-22 08:17:16 +0100 |
commit | 17e2024962b84f759b1f2bfb13564d6626f0d6f0 (patch) | |
tree | 70c20452176bfce76ef5a34b698e6ac615f66c23 /spec/models/info_request_spec.rb | |
parent | e3887f042ba1309985e58ce553de0de05227dc56 (diff) | |
parent | 19d6e36039318cdb1f9aa9e0c4731b500b3b0aeb (diff) |
Merge branch 'release/0.6.3' into wdtk
Conflicts:
app/controllers/admin_request_controller.rb
app/views/request/show.rhtml
spec/models/info_request_spec.rb
Diffstat (limited to 'spec/models/info_request_spec.rb')
-rw-r--r-- | spec/models/info_request_spec.rb | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 3d4d2af4b..6de6e1d25 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -426,8 +426,89 @@ describe InfoRequest do @info_request.prominence = 'requester_only' @info_request.all_can_view?.should == false end - 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 end |