fulltext_searchable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,17 +80,8 @@ class FulltextIndex < ActiveRecord::Base
80
80
  # 結果を取得し、インデックス元モデルの配列に変換。
81
81
  #
82
82
  def items(*args)
83
- begin
84
- # ActiveRecordの参照テーブル判定処理がおかしいので、SQLクエリ内にピリオドが現れる際に
85
- # ピリオドの前の文字列を参照テーブル名と誤認し、eager loadをjoinの方針に切り替えて
86
- # polymorphic associationをjoinでeager loadできず例外を吐く。
87
- # なのでrescueしてeager loadなしで再度クエリを試みておく。
88
- select('`_id`, `item_type`, `item_id`').
89
- includes(:item).all(*args).map{|i| i.item }
90
- rescue ActiveRecord::EagerLoadPolymorphicError
91
- # eager loadなしで試みる
92
- select('`_id`, `item_type`, `item_id`').all(*args).map{|i| i.item }
93
- end
83
+ select('`_id`, `item_type`, `item_id`').
84
+ preload(:item).all(*args).map{|i| i.item }.compact
94
85
  end
95
86
  ##
96
87
  # 特定レコードの更新をインデックスに非同期で反映する。
@@ -102,7 +93,7 @@ class FulltextIndex < ActiveRecord::Base
102
93
  next unless record.item
103
94
  record.text = record.item.fulltext_keywords
104
95
  record.save
105
- end
96
+ end
106
97
  end
107
98
  if FulltextSearchable::Engine.config.respond_to?(:async) &&
108
99
  FulltextSearchable::Engine.config.async
@@ -1,3 +1,3 @@
1
1
  module FulltextSearchable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -75,9 +75,14 @@ describe FulltextIndex do
75
75
  FulltextIndex.match('天気', :with => [@taro, @jiro], :model => [Blog, User]).items.count.should == 5
76
76
  end
77
77
 
78
- it "should perform workaround with ActiveRecord's string-followed-by-period bug" do
78
+ it "should not break with ActiveRecord's eager loading behavior" do
79
79
  FulltextIndex.match('ab.').items.should_not raise_error ActiveRecord::EagerLoadPolymorphicError
80
80
  end
81
+
82
+ it "should not contain nil in items" do
83
+ Blog.delete_all :id => @jiro.blogs.map(&:id)
84
+ FulltextIndex.match('天気').items.should_not include(nil)
85
+ end
81
86
  end
82
87
 
83
88
  context "optimization" do
@@ -60,7 +60,7 @@ describe News do
60
60
  end
61
61
  end
62
62
 
63
- context "deletion",f:true do
63
+ context "deletion" do
64
64
  before do
65
65
  @news = FactoryGirl.create(:taisyaku)
66
66
  end
data/spec/spec_helper.rb CHANGED
@@ -39,6 +39,5 @@ RSpec.configure do |config|
39
39
  end
40
40
  config.before(:each){ DatabaseCleaner.clean }
41
41
  # filtering
42
- config.filter_run :focus => true
43
42
  config.run_all_when_everything_filtered = true
44
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulltext_searchable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -296,12 +296,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
296
296
  - - ! '>='
297
297
  - !ruby/object:Gem::Version
298
298
  version: '0'
299
+ segments:
300
+ - 0
301
+ hash: 2065254535944603589
299
302
  required_rubygems_version: !ruby/object:Gem::Requirement
300
303
  none: false
301
304
  requirements:
302
305
  - - ! '>='
303
306
  - !ruby/object:Gem::Version
304
307
  version: '0'
308
+ segments:
309
+ - 0
310
+ hash: 2065254535944603589
305
311
  requirements: []
306
312
  rubyforge_project:
307
313
  rubygems_version: 1.8.25