aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-08-28 15:43:46 +0100
committerGareth Rees <gareth@mysociety.org>2014-08-28 15:43:46 +0100
commitd801fff4325a42f1bbbb273ac0a4597c32b4dd4b (patch)
tree5b9d4828b2c6bf8415ccabb0140eb730ed12ceca /spec/models
parent0b511943ef5a8835af34842291725d1dce74b25a (diff)
parent533f0ab5f402e110f42d50fb6906a6b58ae312f7 (diff)
Merge remote-tracking branch 'origin/release/0.19'0.19
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/customstates.rb2
-rw-r--r--spec/models/public_body_spec.rb16
-rw-r--r--spec/models/raw_email_spec.rb2
-rw-r--r--spec/models/user_spec.rb2
-rw-r--r--spec/models/xapian_spec.rb50
5 files changed, 63 insertions, 9 deletions
diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb
index bffbe86fb..942e1fcde 100644
--- a/spec/models/customstates.rb
+++ b/spec/models/customstates.rb
@@ -24,7 +24,7 @@ module InfoRequestCustomStates
end
def date_deadline_extended
- # XXX shouldn't this be 15 days after the date the status was
+ # TODO: shouldn't this be 15 days after the date the status was
# changed to "deadline extended"? Or perhaps 15 days ater the
# initial request due date?
return Holiday.due_date_from_working_days(self.date_response_required_by, 15)
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 38e31783d..a7544c218 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -493,7 +493,7 @@ describe PublicBody, " when loading CSV files" do
PublicBody.count.should == original_count + 3
- # XXX Not sure why trying to do a I18n.with_locale fails here. Seems related to
+ # TODO: Not sure why trying to do a I18n.with_locale fails here. Seems related to
# the way categories are loaded every time from the PublicBody class. For now we just
# test some translation was done.
body = PublicBody.find_by_name('North West Fake Authority')
@@ -594,6 +594,20 @@ describe PublicBody do
end
+ describe :site_administration? do
+
+ it 'is true when the body has the site_administration tag' do
+ p = FactoryGirl.build(:public_body, :tag_string => 'site_administration')
+ p.site_administration?.should be_true
+ end
+
+ it 'is false when the body does not have the site_administration tag' do
+ p = FactoryGirl.build(:public_body)
+ p.site_administration?.should be_false
+ end
+
+ end
+
end
describe PublicBody, " when override all public body request emails set" do
diff --git a/spec/models/raw_email_spec.rb b/spec/models/raw_email_spec.rb
index f86b35e99..aa82b0bc3 100644
--- a/spec/models/raw_email_spec.rb
+++ b/spec/models/raw_email_spec.rb
@@ -23,7 +23,7 @@ describe User, "manipulating a raw email" do
@raw_email.data.should == "Hello, world!"
end
- # XXX this test fails, hopefully will be fixed in later Rails.
+ # TODO: this test fails, hopefully will be fixed in later Rails.
# Doesn't matter too much for us for storing raw_emails, it would seem,
# but keep an eye out.
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index c54043092..7dcd3ab8a 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -284,7 +284,7 @@ describe User, " when making name and email address" do
end
end
-# XXX not finished
+# TODO: not finished
describe User, "when setting a profile photo" do
before do
@user = User.new
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index a1e060d8e..678e3a2dc 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -380,23 +380,63 @@ 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"]
+ s.words_to_highlight.should == ["albatross", "word"]
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"]
+ s.words_to_highlight.should == ["albatross", "word"]
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"]
+ s.words_to_highlight.should == ["the", "doctor", "patient"].sort
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"]
+ s.words_to_highlight.should == ["adatigénylé", "word"]
+ end
+
+ it "should ignore stopwords" do
+ s = ActsAsXapian::Search.new([PublicBody], "department of humpadinking", :limit => 100)
+ s.words_to_highlight.should_not include('of')
+ end
+
+ it "uses stemming" do
+ s = ActsAsXapian::Search.new([PublicBody], 'department of humpadinking', :limit => 100)
+ s.words_to_highlight.should == ["depart", "humpadink"]
+ end
+
+ it "doesn't stem proper nouns" do
+ s = ActsAsXapian::Search.new([PublicBody], 'department of Humpadinking', :limit => 1)
+ s.words_to_highlight.should == ["depart", "humpadinking"]
+ end
+
+ it "includes the original search terms if requested" do
+ s = ActsAsXapian::Search.new([PublicBody], 'boring', :limit => 1)
+ s.words_to_highlight(:include_original => true).should == ['bore', 'boring']
+ end
+
+ it "does not return duplicate terms" do
+ s = ActsAsXapian::Search.new([PublicBody], 'boring boring', :limit => 1)
+ s.words_to_highlight.should == ['bore']
+ end
+
+ context 'the :regex option' do
+
+ it 'wraps each words in a regex that matches the full word' do
+ expected = [/\b(albatross)\b/iu]
+ s = ActsAsXapian::Search.new([PublicBody], 'Albatross', :limit => 1)
+ s.words_to_highlight(:regex => true).should == expected
+ end
+
+ it 'wraps each stem in a regex' do
+ expected = [/\b(depart)\w*\b/iu]
+ s = ActsAsXapian::Search.new([PublicBody], 'department', :limit => 1)
+ s.words_to_highlight(:regex => true).should == expected
+ end
+
end
end