aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/general_controller_spec.rb1
-rw-r--r--spec/controllers/reports_controller_spec.rb104
-rw-r--r--spec/controllers/request_controller_spec.rb312
-rw-r--r--spec/mailers/outgoing_mailer_spec.rb111
-rw-r--r--spec/mailers/track_mailer_spec.rb8
-rw-r--r--spec/models/info_request_spec.rb29
-rw-r--r--spec/models/outgoing_message_spec.rb19
-rw-r--r--spec/models/xapian_spec.rb129
-rw-r--r--spec/spec_helper.rb12
-rw-r--r--spec/views/reports/new.erb_spec.rb29
10 files changed, 494 insertions, 260 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 4a1c8b134..bce12248b 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -348,4 +348,3 @@ describe GeneralController, 'when using xapian search' do
end
end
-
diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb
new file mode 100644
index 000000000..fa8c72eaa
--- /dev/null
+++ b/spec/controllers/reports_controller_spec.rb
@@ -0,0 +1,104 @@
+require 'spec_helper'
+
+describe ReportsController, "when reporting a request when not logged in" do
+ it "should only allow logged-in users to report requests" do
+ post :create, :request_id => info_requests(:badger_request).url_title, :reason => "my reason"
+
+ flash[:notice].should =~ /You need to be logged in/
+ response.should redirect_to show_request_path(:url_title => info_requests(:badger_request).url_title)
+ end
+end
+
+describe ReportsController, "when reporting a request (logged in)" do
+ render_views
+
+ before do
+ @user = users(:robin_user)
+ session[:user_id] = @user.id
+ end
+
+ it "should 404 for non-existent requests" do
+ lambda {
+ post :create, :request_id => "hjksfdhjk_louytu_qqxxx"
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ it "should mark a request as having been reported" do
+ ir = info_requests(:badger_request)
+ title = ir.url_title
+ ir.attention_requested.should == false
+
+ post :create, :request_id => title, :reason => "my reason"
+ response.should redirect_to show_request_path(:url_title => title)
+
+ ir.reload
+ ir.attention_requested.should == true
+ ir.described_state.should == "attention_requested"
+ end
+
+ it "should pass on the reason and message" do
+ info_request = mock_model(InfoRequest, :url_title => "foo", :attention_requested= => nil, :save! => nil)
+ InfoRequest.should_receive(:find_by_url_title!).with("foo").and_return(info_request)
+ info_request.should_receive(:report!).with("Not valid request", "It's just not", @user)
+ post :create, :request_id => "foo", :reason => "Not valid request", :message => "It's just not"
+ end
+
+ it "should not allow a request to be reported twice" do
+ title = info_requests(:badger_request).url_title
+
+ post :create, :request_id => title, :reason => "my reason"
+ response.should redirect_to show_request_url(:url_title => title)
+
+ post :create, :request_id => title, :reason => "my reason"
+ response.should redirect_to show_request_url(:url_title => title)
+ flash[:notice].should =~ /has already been reported/
+ end
+
+ it "should send an email from the reporter to admins" do
+ ir = info_requests(:badger_request)
+ title = ir.url_title
+ post :create, :request_id => title, :reason => "my reason"
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should =~ /attention_requested/
+ mail.from.should include(@user.email)
+ mail.body.should include(@user.name)
+ end
+
+ it "should force the user to pick a reason" do
+ info_request = mock_model(InfoRequest, :report! => nil, :url_title => "foo",
+ :report_reasons => ["Not FOIish enough"])
+ InfoRequest.should_receive(:find_by_url_title!).with("foo").and_return(info_request)
+
+ post :create, :request_id => "foo", :reason => ""
+ response.should render_template("new")
+ flash[:error].should == "Please choose a reason"
+ end
+end
+
+describe ReportsController, "#new_report_request" do
+ let(:info_request) { mock_model(InfoRequest, :url_title => "foo") }
+ before :each do
+ InfoRequest.should_receive(:find_by_url_title!).with("foo").and_return(info_request)
+ end
+
+ context "not logged in" do
+ it "should require the user to be logged in" do
+ get :new, :request_id => "foo"
+ response.should_not render_template("new")
+ end
+ end
+
+ context "logged in" do
+ before :each do
+ session[:user_id] = users(:bob_smith_user).id
+ end
+ it "should show the form" do
+ get :new, :request_id => "foo"
+ response.should render_template("new")
+ end
+ end
+end
+
+
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 83e2b1767..a4e6fcffc 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -93,8 +93,10 @@ describe RequestController, "when listing recent requests" do
:results => (1..25).to_a.map { |m| { :model => m } },
:matches_estimated => 1000000)
- InfoRequest.should_receive(:full_search).
- with([InfoRequestEvent]," (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)", "created_at", anything, anything, anything, anything).
+ ActsAsXapian::Search.should_receive(:new).
+ with([InfoRequestEvent]," (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)",
+ :sort_by_prefix => "created_at", :offset => 0, :limit => 25, :sort_by_ascending => true,
+ :collapse_by_prefix => "request_collapse").
and_return(xap_results)
get :list, :view => 'all'
assigns[:list_results].size.should == 25
@@ -134,7 +136,7 @@ describe RequestController, "when changing things that appear on the request pag
it "should purge the downstream cache when a followup is made" do
session[:user_id] = users(:bob_smith_user).id
ir = info_requests(:fancy_dog_request)
- post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1
+ post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :submitted_followup => 1
PurgeRequest.all().first.model_id.should == ir.id
end
it "should purge the downstream cache when the request is categorised" do
@@ -239,6 +241,36 @@ describe RequestController, "when showing one request" do
end
end
+ context "when the request has not yet been reported" do
+ it "should allow the user to report" do
+ title = info_requests(:badger_request).url_title
+ get :show, :url_title => title
+ response.should_not contain("This request has been reported")
+ response.should contain("Offensive?")
+ end
+ end
+
+ context "when the request has been reported for admin attention" do
+ before :each do
+ info_requests(:fancy_dog_request).report!("", "", nil)
+ end
+ it "should inform the user" do
+ get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
+ response.should contain("This request has been reported")
+ response.should_not contain("Offensive?")
+ end
+
+ context "and then deemed okay and left to complete" do
+ before :each do
+ info_requests(:fancy_dog_request).set_described_state("successful")
+ end
+ it "should let the user know that the administrators have not hidden this request" do
+ get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
+ response.body.should =~ (/the site administrators.*have not hidden it/)
+ end
+ end
+ end
+
describe 'when the request is being viewed by an admin' do
describe 'if the request is awaiting description' do
@@ -1605,7 +1637,7 @@ describe RequestController, "when classifying an information request" do
end
end
- describe 'when redirecting after a successful status update by the request owner' do
+ describe 'after a successful status update by the request owner' do
before do
@request_owner = users(:bob_smith_user)
@@ -1632,87 +1664,161 @@ describe RequestController, "when classifying an information request" do
response.should redirect_to("http://test.host/#{redirect_path}")
end
- it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do
- @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1)
- @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
+ context 'when status is updated to "waiting_response"' do
- expect_redirect("waiting_response", "request/#{@dog_request.url_title}")
- flash[:notice].should match(/should get a response/)
- end
+ it 'should redirect to the "request url" with a message in the right tense when
+ the response is not overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1)
+ @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
- it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
- @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1)
- @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
- expect_redirect('waiting_response', request_url)
- flash[:notice].should match(/should have got a response/)
- end
+ expect_redirect("waiting_response", "request/#{@dog_request.url_title}")
+ flash[:notice].should match(/should get a response/)
+ end
- it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
- @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-2)
- @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date-1)
- expect_redirect('waiting_response', unhappy_url)
- flash[:notice].should match(/is long overdue/)
- flash[:notice].should match(/by more than 40 working days/)
- flash[:notice].should match(/within 20 working days/)
- end
+ it 'should redirect to the "request url" with a message in the right tense when
+ the response is overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1)
+ @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
+ expect_redirect('waiting_response', request_url)
+ flash[:notice].should match(/should have got a response/)
+ end
- it 'should redirect to the "request url" when status is updated to "not held"' do
- expect_redirect('not_held', request_url)
+ it 'should redirect to the "request url" with a message in the right tense when
+ the response is overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-2)
+ @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date-1)
+ expect_redirect('waiting_response', unhappy_url)
+ flash[:notice].should match(/is long overdue/)
+ flash[:notice].should match(/by more than 40 working days/)
+ flash[:notice].should match(/within 20 working days/)
+ end
end
- it 'should redirect to the "request url" when status is updated to "successful"' do
- expect_redirect('successful', request_url)
- end
+ context 'when status is updated to "not held"' do
+
+ it 'should redirect to the "request url"' do
+ expect_redirect('not_held', request_url)
+ end
- it 'should redirect to the "unhappy url" when status is updated to "rejected"' do
- expect_redirect('rejected', "help/unhappy/#{@dog_request.url_title}")
end
- it 'should redirect to the "unhappy url" when status is updated to "partially successful"' do
- expect_redirect('partially_successful', "help/unhappy/#{@dog_request.url_title}")
+ context 'when status is updated to "successful"' do
+
+ it 'should redirect to the "request url"' do
+ expect_redirect('successful', request_url)
+ end
+
+ it 'should show a message including the donation url if there is one' do
+ AlaveteliConfiguration.stub!(:donation_url).and_return('http://donations.example.com')
+ post_status('successful')
+ flash[:notice].should match('make a donation')
+ flash[:notice].should match('http://donations.example.com')
+ end
+
+ it 'should show a message without reference to donations if there is no
+ donation url' do
+ AlaveteliConfiguration.stub!(:donation_url).and_return('')
+ post_status('successful')
+ flash[:notice].should_not match('make a donation')
+ end
+
end
- it 'should redirect to the "response url" when status is updated to "waiting clarification" and there is a last response' do
- incoming_message = mock_model(IncomingMessage)
- @dog_request.stub!(:get_last_response).and_return(incoming_message)
- expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}")
+ context 'when status is updated to "waiting clarification"' do
+
+ it 'should redirect to the "response url" when there is a last response' do
+ incoming_message = mock_model(IncomingMessage)
+ @dog_request.stub!(:get_last_response).and_return(incoming_message)
+ expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}")
+ end
+
+ it 'should redirect to the "response no followup url" when there are no events
+ needing description' do
+ @dog_request.stub!(:get_last_response).and_return(nil)
+ expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response")
+ end
+
end
- it 'should redirect to the "response no followup url" when status is updated to "waiting clarification" and there are no events needing description' do
- @dog_request.stub!(:get_last_response).and_return(nil)
- expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response")
+ context 'when status is updated to "rejected"' do
+
+ it 'should redirect to the "unhappy url"' do
+ expect_redirect('rejected', "help/unhappy/#{@dog_request.url_title}")
+ end
+
end
- it 'should redirect to the "respond to last url" when status is updated to "gone postal"' do
- expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}?gone_postal=1")
+ context 'when status is updated to "partially successful"' do
+
+ it 'should redirect to the "unhappy url"' do
+ expect_redirect('partially_successful', "help/unhappy/#{@dog_request.url_title}")
+ end
+
+ it 'should show a message including the donation url if there is one' do
+ AlaveteliConfiguration.stub!(:donation_url).and_return('http://donations.example.com')
+ post_status('successful')
+ flash[:notice].should match('make a donation')
+ flash[:notice].should match('http://donations.example.com')
+ end
+
+ it 'should show a message without reference to donations if there is no
+ donation url' do
+ AlaveteliConfiguration.stub!(:donation_url).and_return('')
+ post_status('successful')
+ flash[:notice].should_not match('make a donation')
+ end
+
end
- it 'should redirect to the "request url" when status is updated to "internal review"' do
- expect_redirect('internal_review', request_url)
+ context 'when status is updated to "gone postal"' do
+
+ it 'should redirect to the "respond to last url"' do
+ expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}?gone_postal=1")
+ end
+
end
- it 'should redirect to the "request url" when status is updated to "requires admin"' do
- post :describe_state, :incoming_message => {
- :described_state => 'requires_admin',
- :message => "A message" },
- :id => @dog_request.id,
- :last_info_request_event_id => @dog_request.last_event_id_needing_description
- response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ context 'when status updated to "internal review"' do
+
+ it 'should redirect to the "request url"' do
+ expect_redirect('internal_review', request_url)
+ end
+
end
- it 'should redirect to the "request url" when status is updated to "error message"' do
- post :describe_state, :incoming_message => {
- :described_state => 'error_message',
- :message => "A message" },
- :id => @dog_request.id,
- :last_info_request_event_id => @dog_request.last_event_id_needing_description
- response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ context 'when status is updated to "requires admin"' do
+
+ it 'should redirect to the "request url"' do
+ post :describe_state, :incoming_message => {
+ :described_state => 'requires_admin',
+ :message => "A message" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ end
+
end
- it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do
- expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}")
+ context 'when status is updated to "error message"' do
+
+ it 'should redirect to the "request url"' do
+ post :describe_state, :incoming_message => {
+ :described_state => 'error_message',
+ :message => "A message" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ end
+
end
+ context 'when status is updated to "user_withdrawn"' do
+
+ it 'should redirect to the "respond to last url url" ' do
+ expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}")
+ end
+
+ end
end
end
@@ -2342,91 +2448,6 @@ describe RequestController, "when showing similar requests" do
end
-
-describe RequestController, "when reporting a request when not logged in" do
- it "should only allow logged-in users to report requests" do
- get :report_request, :url_title => info_requests(:badger_request).url_title
- post_redirect = PostRedirect.get_last_post_redirect
- response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
- end
-end
-
-describe RequestController, "when reporting a request (logged in)" do
- render_views
-
- before do
- @user = users(:robin_user)
- session[:user_id] = @user.id
- end
-
- it "should 404 for non-existent requests" do
- lambda {
- post :report_request, :url_title => "hjksfdhjk_louytu_qqxxx"
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
-
- it "should mark a request as having been reported" do
- ir = info_requests(:badger_request)
- title = ir.url_title
- get :show, :url_title => title
- assigns[:info_request].attention_requested.should == false
-
- post :report_request, :url_title => title
- response.should redirect_to(:action => :show, :url_title => title)
-
- get :show, :url_title => title
- response.should be_success
- assigns[:info_request].attention_requested.should == true
- assigns[:info_request].described_state.should == "attention_requested"
- end
-
- it "should not allow a request to be reported twice" do
- title = info_requests(:badger_request).url_title
-
- post :report_request, :url_title => title
- response.should redirect_to(:action => :show, :url_title => title)
- get :show, :url_title => title
- response.should be_success
- response.body.should include("has been reported")
-
- post :report_request, :url_title => title
- response.should redirect_to(:action => :show, :url_title => title)
- get :show, :url_title => title
- response.should be_success
- response.body.should include("has already been reported")
- end
-
- it "should let users know a request has been reported" do
- title = info_requests(:badger_request).url_title
- get :show, :url_title => title
- response.body.should include("Offensive?")
-
- post :report_request, :url_title => title
- response.should redirect_to(:action => :show, :url_title => title)
-
- get :show, :url_title => title
- response.body.should_not include("Offensive?")
- response.body.should include("This request has been reported")
-
- info_requests(:badger_request).set_described_state("successful")
- get :show, :url_title => title
- response.body.should_not include("This request has been reported")
- response.body.should =~ (/the site administrators.*have not hidden it/)
- end
-
- it "should send an email from the reporter to admins" do
- ir = info_requests(:badger_request)
- title = ir.url_title
- post :report_request, :url_title => title
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 1
- mail = deliveries[0]
- mail.subject.should =~ /attention_requested/
- mail.from.should include(@user.email)
- mail.body.should include(@user.name)
- end
-end
-
describe RequestController, "when caching fragments" do
it "should not fail with long filenames" do
long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt"
@@ -2454,4 +2475,3 @@ describe RequestController, "when caching fragments" do
end
-
diff --git a/spec/mailers/outgoing_mailer_spec.rb b/spec/mailers/outgoing_mailer_spec.rb
index 5d1ea2dfb..a11d56dd3 100644
--- a/spec/mailers/outgoing_mailer_spec.rb
+++ b/spec/mailers/outgoing_mailer_spec.rb
@@ -1,73 +1,66 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe OutgoingMailer, " when working out follow up addresses" do
- # This is done with fixtures as the code is a bit tangled with the way it
- # calls TMail. XXX untangle it and make these tests spread out and using
- # mocks. Put parts of the tests in spec/lib/tmail_extensions.rb
- before(:each) do
- load_raw_emails_data
+describe OutgoingMailer, " when working out follow up names and addresses" do
+
+ before do
+ @info_request = mock_model(InfoRequest,
+ :recipient_name_and_email => 'test <test@example.com>',
+ :recipient_email => 'test@example.com')
+ @info_request.stub_chain(:public_body, :name).and_return("Test Authority")
+ @incoming_message = mock_model(IncomingMessage,
+ :from_email => 'specific@example.com',
+ :safe_mail_from => 'Specific Person')
end
- it "should parse them right" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
-
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "FOI Person <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
+ def expect_address(info_request, incoming_message, expected_result)
+ mail = create_message_from(from_line)
+ name = MailHandler.get_from_name(mail)
+ email = MailHandler.get_from_address(mail)
+ address = MailHandler.address_from_name_and_email(name, email).to_s
+ [name, email, address].should == expected_result
end
- it "should work when there is only an email address" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ describe 'if there is no incoming message being replied to' do
- im.raw_email.data = im.raw_email.data.sub("\"FOI Person\" <foiperson@localhost>", "foiperson@localhost")
- im.parse_raw_email! true
+ it 'should return the name and email address of the public body' do
+ OutgoingMailer.name_and_email_for_followup(@info_request, nil).should == 'test <test@example.com>'
+ OutgoingMailer.name_for_followup(@info_request, nil).should == 'Test Authority'
+ OutgoingMailer.email_for_followup(@info_request, nil).should == 'test@example.com'
+ end
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "foiperson@localhost"
- OutgoingMailer.name_for_followup(ir, im).should == "Geraldine Quango"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
end
- it "should quote funny characters" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ describe 'if the incoming message being replied to is not valid to reply to' do
- im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI [ Person")
- im.parse_raw_email! true
+ before do
+ @incoming_message.stub!(:valid_to_reply_to?).and_return(false)
+ end
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI [ Person\" <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI [ Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
+ it 'should return the safe name and email address of the public body' do
+ OutgoingMailer.name_and_email_for_followup(@info_request, @incoming_message).should == 'test <test@example.com>'
+ OutgoingMailer.name_for_followup(@info_request, @incoming_message).should == 'Test Authority'
+ OutgoingMailer.email_for_followup(@info_request, @incoming_message).should == 'test@example.com'
+ end
end
- it "should quote quotes" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ describe 'if the incoming message is valid to reply to' do
- im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI \\\" Person")
- im.parse_raw_email! true
+ before do
+ @incoming_message.stub!(:valid_to_reply_to?).and_return(true)
+ end
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI \\\" Person\" <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI \" Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
- end
+ it 'should return the name and email address from the incoming message' do
+ OutgoingMailer.name_and_email_for_followup(@info_request, @incoming_message).should == 'Specific Person <specific@example.com>'
+ OutgoingMailer.name_for_followup(@info_request, @incoming_message).should == 'Specific Person'
+ OutgoingMailer.email_for_followup(@info_request, @incoming_message).should == 'specific@example.com'
+ end
- it "should quote @ signs" do
- ir = info_requests(:fancy_dog_request)
- im = ir.incoming_messages[0]
+ it 'should return the name of the public body if the incoming message does not have
+ a safe name' do
+ @incoming_message.stub!(:safe_mail_from).and_return(nil)
+ OutgoingMailer.name_for_followup(@info_request, @incoming_message).should == 'Test Authority'
+ end
- im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI @ Person")
- im.parse_raw_email! true
-
- # check the basic entry in the fixture is fine
- OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI @ Person\" <foiperson@localhost>"
- OutgoingMailer.name_for_followup(ir, im).should == "FOI @ Person"
- OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
end
end
@@ -79,21 +72,21 @@ describe OutgoingMailer, "when working out follow up subjects" do
end
it "should prefix the title with 'Freedom of Information request -' for initial requests" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
ir.email_subject_request.should == "Freedom of Information request - Why do you have & such a fancy dog?"
end
it "should use 'Re:' and inital request subject for followups which aren't replies to particular messages" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
om = outgoing_messages(:useless_outgoing_message)
OutgoingMailer.subject_for_followup(ir, om).should == "Re: Freedom of Information request - Why do you have & such a fancy dog?"
end
it "should prefix with Re: the subject of the message being replied to" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
@@ -102,7 +95,7 @@ describe OutgoingMailer, "when working out follow up subjects" do
end
it "should not add Re: prefix if there already is such a prefix" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
@@ -112,19 +105,19 @@ describe OutgoingMailer, "when working out follow up subjects" do
end
it "should not add Re: prefix if there already is a lower case re: prefix" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: re: Geraldine FOI Code AZXB421")
im.parse_raw_email! true
-
+
OutgoingMailer.subject_for_followup(ir, om).should == "re: Geraldine FOI Code AZXB421"
end
it "should use 'Re:' and initial request subject when replying to failed delivery notifications" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
im = ir.incoming_messages[0]
om = outgoing_messages(:useless_outgoing_message)
om.incoming_message_followup = im
diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb
index a3b849980..509d08331 100644
--- a/spec/mailers/track_mailer_spec.rb
+++ b/spec/mailers/track_mailer_spec.rb
@@ -69,11 +69,15 @@ describe TrackMailer do
@xapian_search = mock('xapian search', :results => [])
@found_event = mock_model(InfoRequestEvent, :described_at => @track_thing.created_at + 1.day)
@search_result = {:model => @found_event}
- InfoRequest.stub!(:full_search).and_return(@xapian_search)
+ ActsAsXapian::Search.stub!(:new).and_return(@xapian_search)
end
it 'should ask for the events returned by the tracking query' do
- InfoRequest.should_receive(:full_search).with([InfoRequestEvent], 'test query', 'described_at', true, nil, 100, 1).and_return(@xapian_search)
+ ActsAsXapian::Search.should_receive(:new).with([InfoRequestEvent], 'test query',
+ :sort_by_prefix => 'described_at',
+ :sort_by_ascending => true,
+ :collapse_by_prefix => nil,
+ :limit => 100).and_return(@xapian_search)
TrackMailer.alert_tracks
end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 3eb88b2bb..b193f8bc2 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -562,7 +562,36 @@ describe InfoRequest do
@info_request.prominence = 'requester_only'
@info_request.all_can_view?.should == false
end
+ end
+end
+
+describe InfoRequest, 'when generating json for the api' do
+
+ before do
+ @user = mock_model(User, :json_for_api => { :id => 20,
+ :url_name => 'alaveteli_user',
+ :name => 'Alaveteli User',
+ :ban_text => '',
+ :about_me => 'Hi' })
+ end
+
+ it 'should return full user info for an internal request' do
+ @info_request = InfoRequest.new(:user => @user)
+ @info_request.user_json_for_api.should == { :id => 20,
+ :url_name => 'alaveteli_user',
+ :name => 'Alaveteli User',
+ :ban_text => '',
+ :about_me => 'Hi' }
+ end
+ it "should return a hash with the user's name for an external request" do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'External User')
+ @info_request.user_json_for_api.should == {:name => 'External User'}
end
+ it 'should return "Anonymous user" for an anonymous external user' do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com')
+ @info_request.user_json_for_api.should == {:name => 'Anonymous user'}
+ end
end
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 51bb6fdf5..60164fb31 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -16,7 +16,7 @@ describe OutgoingMessage, " when making an outgoing message" do
it "should not index the email addresses" do
# also used for track emails
@outgoing_message.get_text_for_indexing.should_not include("foo@bar.com")
- end
+ end
it "should not display email addresses on page" do
@outgoing_message.get_body_for_html_display.should_not include("foo@bar.com")
@@ -33,6 +33,23 @@ describe OutgoingMessage, " when making an outgoing message" do
it "should work out a salutation" do
@om.get_salutation.should == "Dear Geraldine Quango,"
end
+
+ it 'should produce the expected text for an internal review request' do
+ public_body = mock_model(PublicBody, :name => 'A test public body')
+ info_request = mock_model(InfoRequest, :public_body => public_body,
+ :url_title => 'a_test_title',
+ :title => 'A test title',
+ :apply_censor_rules_to_text! => nil)
+ outgoing_message = OutgoingMessage.new({
+ :status => 'ready',
+ :message_type => 'followup',
+ :what_doing => 'internal_review',
+ :info_request => info_request
+ })
+ expected_text = "I am writing to request an internal review of A test public body's handling of my FOI request 'A test title'."
+ outgoing_message.body.should include(expected_text)
+ end
+
end
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index 8c99d550f..c40334142 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe User, " when indexing users with Xapian" do
@@ -8,8 +9,7 @@ describe User, " when indexing users with Xapian" do
end
it "should search by name" do
- # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
- xapian_object = InfoRequest.full_search([User], "Silly", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([User], "Silly", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == users(:silly_name_user)
end
@@ -17,8 +17,7 @@ describe User, " when indexing users with Xapian" do
it "should search by 'about me' text" do
user = users(:bob_smith_user)
- # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
- xapian_object = InfoRequest.full_search([User], "stuff", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([User], "stuff", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == user
@@ -26,10 +25,10 @@ describe User, " when indexing users with Xapian" do
user.save!
update_xapian_index
- xapian_object = InfoRequest.full_search([User], "stuff", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([User], "stuff", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([User], "aardvark", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([User], "aardvark", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == user
end
@@ -42,26 +41,26 @@ describe PublicBody, " when indexing public bodies with Xapian" do
end
it "should search index the main name field" do
- xapian_object = InfoRequest.full_search([PublicBody], "humpadinking", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "humpadinking", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
end
it "should search index the notes field" do
- xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "albatross", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
end
it "should delete public bodies from the index when they are destroyed" do
- xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "albatross", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
public_bodies(:forlorn_public_body).destroy
update_xapian_index
- xapian_object = InfoRequest.full_search([PublicBody], "lonely", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "lonely", :limit => 100)
xapian_object.results.should == []
end
@@ -75,13 +74,13 @@ describe PublicBody, " when indexing requests by body they are to" do
end
it "should find requests to the body" do
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:tgq", :limit => 100)
xapian_object.results.size.should == PublicBody.find_by_url_name("tgq").info_requests.map(&:info_request_events).flatten.size
end
it "should update index correctly when URL name of body changes" do
# initial search
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:tgq", :limit => 100)
xapian_object.results.size.should == PublicBody.find_by_url_name("tgq").info_requests.map(&:info_request_events).flatten.size
models_found_before = xapian_object.results.map { |x| x[:model] }
@@ -93,9 +92,9 @@ describe PublicBody, " when indexing requests by body they are to" do
update_xapian_index
# check we get results expected
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:tgq", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:gq", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:gq", :limit => 100)
xapian_object.results.size.should == PublicBody.find_by_url_name("gq").info_requests.map(&:info_request_events).flatten.size
models_found_after = xapian_object.results.map { |x| x[:model] }
@@ -113,11 +112,11 @@ describe PublicBody, " when indexing requests by body they are to" do
update_xapian_index
# check we get results expected
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:tgq", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:gq", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:gq", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:" + body.url_name, 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_from:#{body.url_name}", :limit => 100)
xapian_object.results.size.should == public_bodies(:geraldine_public_body).info_requests.map(&:info_request_events).flatten.size
models_found_after = xapian_object.results.map { |x| x[:model] }
end
@@ -130,13 +129,14 @@ describe User, " when indexing requests by user they are from" do
end
it "should find requests from the user" do
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:bob_smith",
+ :sort_by_prefix => 'created_at', :sort_by_ascending => true, :limit => 100)
xapian_object.results.map{|x|x[:model]}.should =~ InfoRequestEvent.all(:conditions => "info_request_id in (select id from info_requests where user_id = #{users(:bob_smith_user).id})")
end
it "should find just the sent message events from a particular user" do
- # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:bob_smith variety:sent",
+ :sort_by_prefix => 'created_at', :sort_by_ascending => true, :limit => 100)
xapian_object.results.map{|x|x[:model]}.should =~ InfoRequestEvent.all(:conditions => "info_request_id in (select id from info_requests where user_id = #{users(:bob_smith_user).id}) and event_type = 'sent'")
xapian_object.results[2][:model].should == info_request_events(:useless_outgoing_message_event)
xapian_object.results[1][:model].should == info_request_events(:silly_outgoing_message_event)
@@ -150,8 +150,9 @@ describe User, " when indexing requests by user they are from" do
update_xapian_index
- # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, 'request_collapse', 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:bob_smith",
+ :sort_by_prefix => 'created_at', :sort_by_ascending => true,
+ :collapse_by_prefix => 'request_collapse', :limit => 100)
xapian_object.results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(:conditions => "user_id = #{users(:bob_smith_user).id}")
end
@@ -172,8 +173,7 @@ describe User, " when indexing requests by user they are from" do
update_xapian_index
- # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:john_k", 'created_at', true, 'request_collapse', 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:john_k", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event)
end
@@ -181,7 +181,8 @@ describe User, " when indexing requests by user they are from" do
it "should update index correctly when URL name of user changes" do
# initial search
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:bob_smith",
+ :sort_by_prefix => 'created_at', :sort_by_ascending => true, :limit => 100)
xapian_object.results.map{|x|x[:model]}.should =~ InfoRequestEvent.all(:conditions => "info_request_id in (select id from info_requests where user_id = #{users(:bob_smith_user).id})")
models_found_before = xapian_object.results.map { |x| x[:model] }
@@ -193,9 +194,10 @@ describe User, " when indexing requests by user they are from" do
update_xapian_index
# check we get results expected
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:bob_smith", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:robert_smith", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "requested_by:robert_smith",
+ :sort_by_prefix => 'created_at', :sort_by_ascending => true, :limit => 100)
models_found_after = xapian_object.results.map { |x| x[:model] }
models_found_before.should == models_found_after
end
@@ -208,13 +210,13 @@ describe User, " when indexing comments by user they are by" do
end
it "should find requests from the user" do
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "commented_by:silly_emnameem", :limit => 100)
xapian_object.results.size.should == 1
end
it "should update index correctly when URL name of user changes" do
# initial search
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "commented_by:silly_emnameem", :limit => 100)
xapian_object.results.size.should == 1
models_found_before = xapian_object.results.map { |x| x[:model] }
@@ -226,9 +228,9 @@ describe User, " when indexing comments by user they are by" do
update_xapian_index
# check we get results expected
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "commented_by:silly_emnameem", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_name", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "commented_by:silly_name", :limit => 100)
xapian_object.results.size.should == 1
models_found_after = xapian_object.results.map { |x| x[:model] }
@@ -243,7 +245,7 @@ describe InfoRequest, " when indexing requests by their title" do
end
it "should find events for the request" do
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model] == info_request_events(:silly_outgoing_message_event)
end
@@ -257,9 +259,9 @@ describe InfoRequest, " when indexing requests by their title" do
update_xapian_index
# check we get results expected
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:really_naughty", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "request:really_naughty", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model] == info_request_events(:silly_outgoing_message_event)
end
@@ -277,11 +279,11 @@ describe InfoRequest, " when indexing requests by tag" do
ir.save!
update_xapian_index
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "tag:bunnyrabbit", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "tag:bunnyrabbit", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model] == info_request_events(:silly_outgoing_message_event)
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "tag:orangeaardvark", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], "tag:orangeaardvark", :limit => 100)
xapian_object.results.size.should == 0
end
end
@@ -298,14 +300,14 @@ describe PublicBody, " when indexing authorities by tag" do
body.save!
update_xapian_index
- xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:mice", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model] == public_bodies(:geraldine_public_body)
- xapian_object = InfoRequest.full_search([PublicBody], "tag:mice:3", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:mice:3", :limit => 100)
xapian_object.results.size.should == 1
xapian_object.results[0][:model] == public_bodies(:geraldine_public_body)
- xapian_object = InfoRequest.full_search([PublicBody], "tag:orangeaardvark", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:orangeaardvark", :limit => 100)
xapian_object.results.size.should == 0
end
end
@@ -327,11 +329,11 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
values = false
texts = false
rebuild_xapian_index(terms, values, texts, dropfirst)
- xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:mice", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "frobzn", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "variety:authority", :limit => 100)
xapian_object.results.map{|x|x[:model]}.should =~ PublicBody.all
# only reindex 'tag' and text
dropfirst = true
@@ -339,32 +341,57 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
values = false
texts = true
rebuild_xapian_index(terms, values, texts, dropfirst)
- xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:mice", :limit => 100)
xapian_object.results.size.should == 1
- xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "frobzn", :limit => 100)
xapian_object.results.size.should == 1
- xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "variety:authority", :limit => 100)
xapian_object.results.size.should == 0
# only reindex 'variety' term, but keeping the existing data in-place
dropfirst = false
terms = "V"
texts = false
rebuild_xapian_index(terms, values, texts, dropfirst)
- xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:mice", :limit => 100)
xapian_object.results.size.should == 1
- xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "frobzn", :limit => 100)
xapian_object.results.size.should == 1
- xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "variety:authority", :limit => 100)
xapian_object.results.map{|x|x[:model]}.should =~ PublicBody.all
# only reindex 'variety' term, blowing away existing data
dropfirst = true
rebuild_xapian_index(terms, values, texts, dropfirst)
- xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "tag:mice", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "frobzn", :limit => 100)
xapian_object.results.size.should == 0
- xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([PublicBody], "variety:authority", :limit => 100)
xapian_object.results.map{|x|x[:model]}.should =~ PublicBody.all
end
end
+# I would expect ActsAsXapian to have some tests under vendor/plugins/acts_as_xapian, but
+# it looks like this is not the case. Putting a test here instead.
+describe ActsAsXapian::Search, "#words_to_highlight" do
+ it "should return a list of words used in the search" do
+ s = ActsAsXapian::Search.new([PublicBody], "albatross words", :limit => 100)
+ s.words_to_highlight.should == ["albatross", "words"]
+ end
+
+ it "should remove any operators" do
+ s = ActsAsXapian::Search.new([PublicBody], "albatross words tag:mice", :limit => 100)
+ s.words_to_highlight.should == ["albatross", "words"]
+ end
+
+ # This is the current behaviour but it seems a little simplistic to me
+ it "should separate punctuation" do
+ s = ActsAsXapian::Search.new([PublicBody], "The doctor's patient", :limit => 100)
+ s.words_to_highlight.should == ["The", "doctor", "s", "patient"]
+ end
+
+ it "should handle non-ascii characters" do
+ s = ActsAsXapian::Search.new([PublicBody], "adatigénylés words tag:mice", :limit => 100)
+ s.words_to_highlight.should == ["adatigénylés", "words"]
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 57ab88da2..a3b06cea8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,7 +1,19 @@
require 'rubygems'
require 'spork'
+
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
+require 'simplecov'
+require 'coveralls'
+# Generate coverage locally in html as well as in coveralls.io
+SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+ SimpleCov::Formatter::HTMLFormatter,
+ Coveralls::SimpleCov::Formatter
+]
+SimpleCov.start('rails') do
+ add_filter 'commonlib'
+ add_filter 'vendor/plugins'
+end
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
diff --git a/spec/views/reports/new.erb_spec.rb b/spec/views/reports/new.erb_spec.rb
new file mode 100644
index 000000000..66b738261
--- /dev/null
+++ b/spec/views/reports/new.erb_spec.rb
@@ -0,0 +1,29 @@
+require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)
+
+describe 'reports/new.html.erb' do
+ let(:info_request) { mock_model(InfoRequest, :url_title => "foo", :report_reasons => ["Weird"]) }
+ before :each do
+ assign(:info_request, info_request)
+ end
+
+ it "should show a form" do
+ render
+ rendered.should have_selector("form")
+ end
+
+ context "request has already been reported" do
+ before :each do
+ info_request.stub!(:attention_requested).and_return(true)
+ end
+
+ it "should not show a form" do
+ render
+ rendered.should_not have_selector("form")
+ end
+
+ it "should say it's already been reported" do
+ render
+ rendered.should contain("This request has already been reported")
+ end
+ end
+end