aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api_controller_spec.rb3
-rw-r--r--spec/controllers/public_body_controller_spec.rb109
-rw-r--r--spec/controllers/request_controller_spec.rb2
-rw-r--r--spec/fixtures/files/fake-authority-type.csv1
-rw-r--r--spec/fixtures/public_bodies.yml18
-rw-r--r--spec/lib/confidence_intervals.rb30
-rw-r--r--spec/models/info_request_spec.rb146
-rw-r--r--spec/models/public_body_spec.rb78
-rw-r--r--spec/models/xapian_spec.rb31
9 files changed, 377 insertions, 41 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 66b8e33f0..8e9d17fbe 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -83,6 +83,9 @@ describe ApiController, "when using the API" do
new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data["body"].strip
new_request.public_body_id.should == public_bodies(:geraldine_public_body).id
+ new_request.info_request_events.size.should == 1
+ new_request.info_request_events[0].event_type.should == 'sent'
+ new_request.info_request_events[0].calculated_state.should == 'waiting_response'
end
def _create_request
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 4e1841164..2d1b1466f 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -1,6 +1,8 @@
# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'nokogiri'
+
describe PublicBodyController, "when showing a body" do
render_views
@@ -78,24 +80,80 @@ describe PublicBodyController, "when listing bodies" do
response.should be_success
end
- it "should list all bodies from default locale, even when there are no translations for selected locale" do
- I18n.with_locale(:en) do
- @english_only = PublicBody.new(:name => 'English only',
- :short_name => 'EO',
- :request_email => 'english@flourish.org',
- :last_edit_editor => 'test',
- :last_edit_comment => '')
- @english_only.save
+ def make_single_language_example(locale)
+ result = nil
+ I18n.with_locale(locale) do
+ case locale
+ when :en
+ result = PublicBody.new(:name => 'English only',
+ :short_name => 'EO')
+ when :es
+ result = PublicBody.new(:name => 'Español Solamente',
+ :short_name => 'ES')
+ else
+ raise StandardError.new "Unknown locale #{locale}"
+ end
+ result.request_email = "#{locale}@example.org"
+ result.last_edit_editor = 'test'
+ result.last_edit_comment = ''
+ result.save
end
+ result
+ end
+
+ it "with no fallback, should only return bodies from the current locale" do
+ @english_only = make_single_language_example :en
+ @spanish_only = make_single_language_example :es
+ get :list, {:locale => 'es'}
+ assigns[:public_bodies].include?(@english_only).should == false
+ assigns[:public_bodies].include?(@spanish_only).should == true
+ end
+
+ it "if fallback is requested, should list all bodies from default locale, even when there are no translations for selected locale" do
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ @english_only = make_single_language_example :en
get :list, {:locale => 'es'}
assigns[:public_bodies].include?(@english_only).should == true
end
+ it 'if fallback is requested, should still list public bodies only with translations in the current locale' do
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ @spanish_only = make_single_language_example :es
+ get :list, {:locale => 'es'}
+ assigns[:public_bodies].include?(@spanish_only).should == true
+ end
+
+ it "if fallback is requested, make sure that there are no duplicates listed" do
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ get :list, {:locale => 'es'}
+ pb_ids = assigns[:public_bodies].map { |pb| pb.id }
+ unique_pb_ids = pb_ids.uniq
+ pb_ids.sort.should === unique_pb_ids.sort
+ end
+
it 'should show public body names in the selected locale language if present' do
get :list, {:locale => 'es'}
response.should contain('El Department for Humpadinking')
end
+ it 'should not show the internal admin authority' do
+ PublicBody.internal_admin_body
+ get :list, {:locale => 'en'}
+ response.should_not contain('Internal admin authority')
+ end
+
+ it 'should order on the translated name, even with the fallback' do
+ # The names of each public body is in:
+ # <span class="head"><a>Public Body Name</a></span>
+ # ... eo extract all of those, and check that they are ordered:
+ AlaveteliConfiguration.stub!(:public_body_list_fallback_to_default_locale).and_return(true)
+ get :list, {:locale => 'es'}
+ parsed = Nokogiri::HTML(response.body)
+ public_body_names = parsed.xpath '//span[@class="head"]/a/text()'
+ public_body_names = public_body_names.map { |pb| pb.to_s }
+ public_body_names.should == public_body_names.sort
+ end
+
it 'should show public body names in the selected locale language if present for a locale with underscores' do
AlaveteliLocalization.set_locales('he_IL en', 'en')
get :list, {:locale => 'he_IL'}
@@ -208,6 +266,41 @@ describe PublicBodyController, "when showing JSON version for API" do
end
+describe PublicBodyController, "when showing public body statistics" do
+
+ it "should render the right template with the right data" do
+ config = MySociety::Config.load_default()
+ config['MINIMUM_REQUESTS_FOR_STATISTICS'] = 1
+ config['PUBLIC_BODY_STATISTICS_PAGE'] = true
+ get :statistics
+ response.should render_template('public_body/statistics')
+ # There are 5 different graphs we're creating at the moment.
+ assigns[:graph_list].length.should == 5
+ # The first is the only one with raw values, the rest are
+ # percentages with error bars:
+ assigns[:graph_list].each_with_index do |graph, index|
+ if index == 0
+ graph['errorbars'].should be_false
+ graph['x_values'].length.should == 4
+ graph['x_values'].should == [0, 1, 2, 3]
+ graph['y_values'].should == [1, 2, 2, 4]
+ else
+ graph['errorbars'].should be_true
+ # Just check the first one:
+ if index == 1
+ graph['x_values'].should == [0, 1, 2, 3]
+ graph['y_values'].should == [0, 50, 100, 100]
+ end
+ # Check that at least every confidence interval value is
+ # a Float (rather than NilClass, say):
+ graph['cis_below'].each { |v| v.should be_instance_of(Float) }
+ graph['cis_above'].each { |v| v.should be_instance_of(Float) }
+ end
+ end
+ end
+
+end
+
describe PublicBodyController, "when doing type ahead searches" do
render_views
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index d324670c4..d190b0db7 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -174,7 +174,7 @@ describe RequestController, "when changing things that appear on the request pag
ir.save!
PurgeRequest.all().first.model_id.should == ir.id
end
- it "should not create more than one entry for any given resourcce" do
+ it "should not create more than one entry for any given resource" do
ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
ir.save!
diff --git a/spec/fixtures/files/fake-authority-type.csv b/spec/fixtures/files/fake-authority-type.csv
index 4aa618ad1..cb25050c6 100644
--- a/spec/fixtures/files/fake-authority-type.csv
+++ b/spec/fixtures/files/fake-authority-type.csv
@@ -1,3 +1,4 @@
,North West Fake Authority,north_west_foi@localhost
,Scottish Fake Authority,scottish_foi@localhost
,Fake Authority of Northern Ireland,ni_foi@localhost
+,Gobierno de Aragón,spain_foi@localhost
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index 6d16a91ea..1fa016d3a 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -35,6 +35,9 @@ geraldine_public_body:
created_at: 2007-10-24 10:51:01.161639
api_key: 1
info_requests_count: 4
+ info_requests_successful_count: 0
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 3
humpadink_public_body:
name: "Department for Humpadinking"
first_letter: D
@@ -50,6 +53,9 @@ humpadink_public_body:
notes: An albatross told me!!!
api_key: 2
info_requests_count: 2
+ info_requests_successful_count: 1
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 1
forlorn_public_body:
name: "Department of Loneliness"
first_letter: D
@@ -65,6 +71,9 @@ forlorn_public_body:
notes: A very lonely public body that no one has corresponded with
api_key: 3
info_requests_count: 0
+ info_requests_successful_count: 0
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 0
silly_walks_public_body:
id: 5
version: 1
@@ -80,6 +89,9 @@ silly_walks_public_body:
notes: You know the one.
api_key: 4
info_requests_count: 2
+ info_requests_successful_count: 2
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 0
sensible_walks_public_body:
id: 6
version: 1
@@ -95,6 +107,9 @@ sensible_walks_public_body:
created_at: 2008-10-25 10:51:01.161639
api_key: 5
info_requests_count: 1
+ info_requests_successful_count: 1
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 0
other_public_body:
id: 7
version: 1
@@ -110,3 +125,6 @@ other_public_body:
created_at: 2008-10-25 10:51:01.161639
api_key: 6
info_requests_count: 0
+ info_requests_successful_count: 0
+ info_requests_not_held_count: 0
+ info_requests_overdue_count: 0
diff --git a/spec/lib/confidence_intervals.rb b/spec/lib/confidence_intervals.rb
new file mode 100644
index 000000000..cb8717f3d
--- /dev/null
+++ b/spec/lib/confidence_intervals.rb
@@ -0,0 +1,30 @@
+require 'confidence_intervals'
+
+describe "ci_bounds" do
+
+ describe "when passed all successes" do
+ it "should never return a high CI above 1" do
+ ci = ci_bounds 16, 16, 0.01
+ ci[1].should be <= 1
+ end
+ end
+
+ describe "when passed all failures" do
+ it "should never return a low CI below 0" do
+ ci = ci_bounds 0, 10, 0.05
+ ci[0].should be >= 0
+ end
+ end
+
+ describe "when passed 4 out of 10 successes (with 0.05 power)" do
+ it "should return the correct Wilson's interval" do
+ # The expected results here were taken from an online
+ # calculator:
+ # http://www.vassarstats.net/prop1.html
+ ci = ci_bounds 7, 10, 0.05
+ ci[0].should be_within(0.001).of(0.3968)
+ ci[1].should be_within(0.001).of(0.8922)
+ end
+ end
+
+end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index d80eabace..fac89109c 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
# == Schema Information
#
# Table name: info_requests
@@ -26,6 +27,27 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe InfoRequest do
+ describe 'when validating', :focus => true do
+
+ it 'should accept a summary with ascii characters' do
+ info_request = InfoRequest.new(:title => 'abcde')
+ info_request.valid?
+ info_request.errors[:title].should be_empty
+ end
+
+ it 'should accept a summary with unicode characters' do
+ info_request = InfoRequest.new(:title => 'кажете')
+ info_request.valid?
+ info_request.errors[:title].should be_empty
+ end
+
+ it 'should not accept a summary with no ascii or unicode characters' do
+ info_request = InfoRequest.new(:title => '55555')
+ info_request.valid?
+ info_request.errors[:title].should_not be_empty
+ end
+ end
+
describe 'when generating a user name slug' do
before do
@@ -796,7 +818,7 @@ describe InfoRequest do
events[0].calculated_state.should == "waiting_response"
events[1].event_type.should == "response"
events[1].described_state.should be_nil
- events[1].calculated_state.should be_nil
+ events[1].calculated_state.should == 'waiting_response'
events[2].event_type.should == "status_update"
events[2].described_state.should == "waiting_response"
events[2].calculated_state.should == "waiting_response"
@@ -824,7 +846,7 @@ describe InfoRequest do
events[0].calculated_state.should == "waiting_response"
events[1].event_type.should == "response"
events[1].described_state.should be_nil
- events[1].calculated_state.should be_nil
+ events[1].calculated_state.should == 'waiting_response'
events[2].event_type.should == "status_update"
events[2].described_state.should == "waiting_response"
events[2].calculated_state.should == "waiting_response"
@@ -857,7 +879,7 @@ describe InfoRequest do
events[0].calculated_state.should == "waiting_response"
events[1].event_type.should == "response"
events[1].described_state.should be_nil
- events[1].calculated_state.should be_nil
+ events[1].calculated_state.should == 'waiting_response'
events[2].event_type.should == "status_update"
events[2].described_state.should == "waiting_response"
events[2].calculated_state.should == "waiting_response"
@@ -933,7 +955,125 @@ describe InfoRequest do
events[1].described_state.should == "successful"
events[1].calculated_state.should == "successful"
end
+
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+
+ # The user marks the request as successful
+ request.log_event("status_update", {})
+ request.set_described_state("successful")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should == "successful"
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "successful"
+ events[2].calculated_state.should == "successful"
+ end
+ end
+
+ context "another series of events on a request", :focus => true do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An admin sets the status of the request to 'gone postal' using
+ # the admin interface
+ request.log_event("edit", {})
+ request.set_described_state("gone_postal")
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "edit"
+ events[1].described_state.should == "gone_postal"
+ events[1].calculated_state.should == "gone_postal"
+ end
end
end
end
+
+ describe 'when saving an info_request' do
+
+ before do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'Example User',
+ :title => 'Some request or other',
+ :public_body => public_bodies(:geraldine_public_body))
+ end
+
+ it "should call purge_in_cache and update_counter_cache" do
+ @info_request.should_receive(:purge_in_cache)
+ # Twice - once for save, once for destroy:
+ @info_request.should_receive(:update_counter_cache).twice
+ @info_request.save!
+ @info_request.destroy
+ end
+
+ end
+
+ describe 'when destroying an info_request' do
+
+ before do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'Example User',
+ :title => 'Some request or other',
+ :public_body => public_bodies(:geraldine_public_body))
+ end
+
+ it "should call update_counter_cache" do
+ @info_request.save!
+ @info_request.should_receive(:update_counter_cache)
+ @info_request.destroy
+ end
+
+ end
+
+ describe 'when changing a described_state' do
+
+ it "should change the counts on its PublicBody without saving a new version" do
+ pb = public_bodies(:geraldine_public_body)
+ old_version_count = pb.versions.count
+ old_successful_count = pb.info_requests_successful_count
+ old_not_held_count = pb.info_requests_not_held_count
+ ir = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'Example User',
+ :title => 'Some request or other',
+ :described_state => 'partially_successful',
+ :public_body => pb)
+ ir.save!
+ pb.info_requests_successful_count.should == (old_successful_count + 1)
+ ir.described_state = 'not_held'
+ ir.save!
+ pb.reload
+ pb.info_requests_successful_count.should == old_successful_count
+ pb.info_requests_not_held_count.should == (old_not_held_count + 1)
+ ir.described_state = 'successful'
+ ir.save!
+ pb.reload
+ pb.info_requests_successful_count.should == (old_successful_count + 1)
+ pb.info_requests_not_held_count.should == old_not_held_count
+ ir.destroy
+ pb.reload
+ pb.info_requests_successful_count.should == old_successful_count
+ pb.info_requests_successful_count.should == old_not_held_count
+ pb.versions.count.should == old_version_count
+ end
+
+ end
+
+
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index d1fdd2c47..582f1430e 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
# == Schema Information
#
# Table name: public_bodies
@@ -158,36 +159,32 @@ describe PublicBody, " when saving" do
@public_body = PublicBody.new
end
+ def set_default_attributes(public_body)
+ public_body.name = "Testing Public Body"
+ public_body.short_name = "TPB"
+ public_body.request_email = "request@localhost"
+ public_body.last_edit_editor = "*test*"
+ public_body.last_edit_comment = "This is a test"
+ end
+
it "should not be valid without setting some parameters" do
@public_body.should_not be_valid
end
it "should not be valid with misformatted request email" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
+ set_default_attributes(@public_body)
@public_body.request_email = "requestBOOlocalhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
@public_body.should_not be_valid
@public_body.should have(1).errors_on(:request_email)
end
it "should save" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
- @public_body.request_email = "request@localhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
+ set_default_attributes(@public_body)
@public_body.save!
end
it "should update first_letter" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
- @public_body.request_email = "request@localhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
-
+ set_default_attributes(@public_body)
@public_body.first_letter.should be_nil
@public_body.save!
@public_body.first_letter.should == 'T'
@@ -200,6 +197,26 @@ describe PublicBody, " when saving" do
public_body.name.should == "Mark's Public Body"
end
+
+ it 'should not create a new version when nothing has changed' do
+ @public_body.versions.size.should == 0
+ set_default_attributes(@public_body)
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ end
+
+ it 'should create a new version if something has changed' do
+ @public_body.versions.size.should == 0
+ set_default_attributes(@public_body)
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ @public_body.name = 'Test'
+ @public_body.save!
+ @public_body.versions.size.should == 2
+ end
+
end
describe PublicBody, "when searching" do
@@ -289,16 +306,17 @@ describe PublicBody, " when loading CSV files" do
it "should do a dry run successfully" do
original_count = PublicBody.count
- csv_contents = load_file_fixture("fake-authority-type.csv")
+ csv_contents = normalize_string_to_utf8(load_file_fixture("fake-authority-type.csv"))
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run
errors.should == []
- notes.size.should == 4
- notes[0..2].should == [
+ notes.size.should == 5
+ notes[0..3].should == [
"line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
"line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
+ "line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -306,34 +324,36 @@ describe PublicBody, " when loading CSV files" do
it "should do full run successfully" do
original_count = PublicBody.count
- csv_contents = load_file_fixture("fake-authority-type.csv")
+ csv_contents = normalize_string_to_utf8(load_file_fixture("fake-authority-type.csv"))
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
- notes.size.should == 4
- notes[0..2].should == [
+ notes.size.should == 5
+ notes[0..3].should == [
"line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
"line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
+ "line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
- PublicBody.count.should == original_count + 3
+ PublicBody.count.should == original_count + 4
end
it "should do imports without a tag successfully" do
original_count = PublicBody.count
- csv_contents = load_file_fixture("fake-authority-type.csv")
+ csv_contents = normalize_string_to_utf8(load_file_fixture("fake-authority-type.csv"))
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
- notes.size.should == 4
- notes[0..2].should == [
+ notes.size.should == 5
+ notes[0..3].should == [
"line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
"line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
+ "line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
- PublicBody.count.should == original_count + 3
+ notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ PublicBody.count.should == original_count + 4
end
it "should handle a field list and fields out of order" do
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index 7aab9cdc6..c7c21e3a0 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -400,3 +400,34 @@ describe ActsAsXapian::Search, "#words_to_highlight" do
end
end
+
+describe InfoRequestEvent, " when faced with a race condition during xapian_mark_needs_index" do
+
+ before(:each) do
+ load_raw_emails_data
+ get_fixtures_xapian_index
+ # Use the before create job hook to simulate a race condition with another process
+ # by creating an acts_as_xapian_job record for the same model
+ class InfoRequestEvent
+ def xapian_before_create_job_hook(action, model, model_id)
+ ActsAsXapian::ActsAsXapianJob.create!(:model => model,
+ :model_id => model_id,
+ :action => action)
+ end
+ end
+ end
+
+ after(:each) do
+ # Reset the before create job hook
+ class InfoRequestEvent
+ def xapian_before_create_job_hook(action, model, model_id)
+ end
+ end
+ end
+
+ it 'should not raise an error but should fail silently' do
+ ir = info_requests(:naughty_chicken_request)
+ ir.reindex_request_events
+ end
+
+end