From ca84f7b51f9c95fea57aca9ab5b1d911b467831f Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 26 May 2015 13:47:57 +0100 Subject: Make sure spelling corrections are encoded as UTF-8 --- spec/lib/acts_as_xapian_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/acts_as_xapian_spec.rb b/spec/lib/acts_as_xapian_spec.rb index 24ca47452..d411bf856 100644 --- a/spec/lib/acts_as_xapian_spec.rb +++ b/spec/lib/acts_as_xapian_spec.rb @@ -72,4 +72,33 @@ describe ActsAsXapian::Search do end end + describe :spelling_correction do + + before :all do + @alice = FactoryGirl.create(:public_body, :name => 'alice') + @bob = FactoryGirl.create(:public_body, :name => 'bôbby') + ActsAsXapian.update_index + end + + it 'returns a UTF-8 encoded string' do + s = ActsAsXapian::Search.new([PublicBody], "alece", :limit => 100) + s.spelling_correction.should == "alice" + if s.spelling_correction.respond_to? :encoding + s.spelling_correction.encoding.to_s.should == 'UTF-8' + end + end + + it 'handles non-ASCII characters' do + s = ActsAsXapian::Search.new([PublicBody], "bobby", :limit => 100) + s.spelling_correction.should == "bôbby" + end + + after :all do + @alice.destroy + @bob.destroy + ActsAsXapian.update_index + end + + end + end \ No newline at end of file -- cgit v1.2.3