aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api_controller_spec.rb54
-rw-r--r--spec/models/censor_rule_spec.rb42
-rw-r--r--spec/models/info_request_spec.rb22
-rw-r--r--spec/spec_helper.rb13
-rw-r--r--spec/views/request/_after_actions.rhtml_spec.rb2
-rw-r--r--spec/views/request/_describe_state.rhtml_spec.rb7
-rw-r--r--spec/views/request/show.rhtml_spec.rb2
7 files changed, 139 insertions, 3 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 1f65576b6..98751a93a 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -260,4 +260,58 @@ describe ApiController, "when using the API" do
# assigns them and changing assignment to an equality
# check, which does not really test anything at all.
end
+
+ it "should show an Atom feed of new request events" do
+ get :body_request_events,
+ :id => public_bodies(:geraldine_public_body).id,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :feed_type => "atom"
+
+ response.should be_success
+ response.should render_template("api/request_events.atom")
+ assigns[:events].size.should > 0
+ assigns[:events].each do |event|
+ event.info_request.public_body.should == public_bodies(:geraldine_public_body)
+ event.outgoing_message.should_not be_nil
+ event.event_type.should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)}
+ end
+ end
+
+ it "should show a JSON feed of new request events" do
+ get :body_request_events,
+ :id => public_bodies(:geraldine_public_body).id,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :feed_type => "json"
+
+ response.should be_success
+ assigns[:events].size.should > 0
+ assigns[:events].each do |event|
+ event.info_request.public_body.should == public_bodies(:geraldine_public_body)
+ event.outgoing_message.should_not be_nil
+ event.event_type.should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)}
+ end
+
+ assigns[:event_data].size.should == assigns[:events].size
+ assigns[:event_data].each do |event_record|
+ event_record[:event_type].should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)}
+ end
+ end
+
+ it "should honour the since_event_id parameter" do
+ get :body_request_events,
+ :id => public_bodies(:geraldine_public_body).id,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :feed_type => "json"
+ response.should be_success
+ first_event = assigns[:event_data][0]
+ second_event_id = assigns[:event_data][1][:event_id]
+
+ get :body_request_events,
+ :id => public_bodies(:geraldine_public_body).id,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :feed_type => "json",
+ :since_event_id => second_event_id
+ response.should be_success
+ assigns[:event_data].should == [first_event]
+ end
end
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb
index 44087c5a6..d5797ec74 100644
--- a/spec/models/censor_rule_spec.rb
+++ b/spec/models/censor_rule_spec.rb
@@ -21,5 +21,45 @@ describe CensorRule, "substituting things" do
body.should == "I don't know why you say xxxxxxx"
body.should_not == orig_body # be sure duplicated as expected
end
+
+ context "when regexp type" do
+ before do
+ CensorRule.delete_all
+ CensorRule.create(:last_edit_editor => 1,
+ :last_edit_comment => 'comment')
+ @censor_rule = CensorRule.new(:last_edit_editor => 1,
+ :last_edit_comment => 'comment')
+ @censor_rule.text = "--PRIVATE.*--PRIVATE"
+ @censor_rule.replacement = "--REMOVED\nHidden private info\n--REMOVED"
+ @censor_rule.regexp = true
+ end
+
+ it "replaces with the regexp" do
+ body =
+<<BODY
+Some public information
+--PRIVATE
+Some private information
+--PRIVATE
+BODY
+ @censor_rule.apply_to_text!(body)
+ body.should ==
+<<BODY
+Some public information
+--REMOVED
+Hidden private info
+--REMOVED
+BODY
+ end
+
+ it "validates without info_request, user or public body set" do
+ @censor_rule.save.should be_true
+ end
+
+ it "has scope for regexps" do
+ @censor_rule.save
+ CensorRule.regexps.all.should == [@censor_rule]
+ end
+ end
end
-
+
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index a18a4bd1d..230884c38 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -398,7 +398,27 @@ describe InfoRequest do
it 'should return true if it is awaiting description, isn\'t the holding pen and hasn\'t had an event in 21 days' do
@info_request.is_old_unclassified?.should be_true
end
+ 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
end
-
+
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a7f3020c1..c11c7c5bc 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -206,3 +206,16 @@ def load_test_categories
"Miscellaneous",
[ "other", "Miscellaneous", "miscellaneous" ],])
end
+
+
+# Monkeypatch applicationcontroller because the `render_to_string`
+# method in the original breaks all the rspec test assertions such as
+# `should render_template('foo')`. Same problem as
+# http://stackoverflow.com/questions/8174415/is-it-possible-to-assert-template-or-render-template-against-the-same-partial-wi
+# - a bug in either Rails or Rspec I don't have the time to fix :(
+
+class ApplicationController < ActionController::Base
+ def set_popup_banner
+ @popup_banner = nil
+ end
+end
diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.rhtml_spec.rb
index 6a56e7a71..d04db3fc2 100644
--- a/spec/views/request/_after_actions.rhtml_spec.rb
+++ b/spec/views/request/_after_actions.rhtml_spec.rb
@@ -9,6 +9,8 @@ describe 'when displaying actions that can be taken with regard to a request' do
:url_name => 'test_user')
@mock_request = mock_model(InfoRequest, :title => 'test request',
:user => @mock_user,
+ :user_name => @mock_user.name,
+ :is_external? => false,
:public_body => @mock_body,
:url_title => 'test_request')
assigns[:info_request] = @mock_request
diff --git a/spec/views/request/_describe_state.rhtml_spec.rb b/spec/views/request/_describe_state.rhtml_spec.rb
index ccf653b1b..18778d5d2 100644
--- a/spec/views/request/_describe_state.rhtml_spec.rb
+++ b/spec/views/request/_describe_state.rhtml_spec.rb
@@ -18,7 +18,12 @@ describe 'when showing the form for describing the state of a request' do
before do
@mock_user = mock_model(User, :name => 'test user', :url_name => 'test_user')
- @mock_request = mock_model(InfoRequest, :described_state => '', :user => @mock_user)
+ @mock_request = mock_model(InfoRequest,
+ :described_state => '',
+ :user => @mock_user,
+ :user_name => @mock_user.name,
+ :is_external? => false
+ )
assigns[:info_request] = @mock_request
end
diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb
index ef7d1a47c..4429e9e58 100644
--- a/spec/views/request/show.rhtml_spec.rb
+++ b/spec/views/request/show.rhtml_spec.rb
@@ -15,6 +15,8 @@ describe 'when viewing an information request' do
:law_used_full => 'Freedom of Information',
:public_body => @mock_body,
:user => @mock_user,
+ :user_name => @mock_user.name,
+ :is_external? => false,
:calculate_status => 'waiting_response',
:date_response_required_by => Date.today,
:prominence => 'normal')