| | 111 | def test_disable_ferret_on_class_level |
|---|
| | 112 | Content.disable_ferret |
|---|
| | 113 | content = Content.new(:title => 'should not get saved', :description => 'do not find me') |
|---|
| | 114 | assert !content.ferret_enabled? |
|---|
| | 115 | assert !Content.ferret_enabled? |
|---|
| | 116 | 2.times do |
|---|
| | 117 | content.save |
|---|
| | 118 | assert Content.find_by_contents('"find me"').empty? |
|---|
| | 119 | assert !Content.ferret_enabled? |
|---|
| | 120 | assert !content.ferret_enabled? |
|---|
| | 121 | end |
|---|
| | 122 | content.enable_ferret # record level enabling should have no effect on class level |
|---|
| | 123 | assert !Content.ferret_enabled? |
|---|
| | 124 | assert !content.ferret_enabled? |
|---|
| | 125 | Content.enable_ferret |
|---|
| | 126 | assert Content.ferret_enabled? |
|---|
| | 127 | assert content.ferret_enabled? |
|---|
| | 128 | |
|---|
| | 129 | content.save |
|---|
| | 130 | assert content.ferret_enabled? |
|---|
| | 131 | assert Content.ferret_enabled? |
|---|
| | 132 | assert_equal content, Content.find_by_contents('"find me"').first |
|---|
| | 133 | end |
|---|
| | 134 | |
|---|
| | 157 | |
|---|
| | 158 | def test_disable_ferret_on_class_level_block |
|---|
| | 159 | content = Content.new(:title => 'should not get saved', :description => 'do not find me') |
|---|
| | 160 | Content.disable_ferret do |
|---|
| | 161 | 2.times do |
|---|
| | 162 | content.save |
|---|
| | 163 | assert Content.find_by_contents('"find me"').empty? |
|---|
| | 164 | assert !content.ferret_enabled? |
|---|
| | 165 | assert !Content.ferret_enabled? |
|---|
| | 166 | end |
|---|
| | 167 | end |
|---|
| | 168 | assert content.ferret_enabled? |
|---|
| | 169 | assert Content.ferret_enabled? |
|---|
| | 170 | assert Content.find_by_contents('"find me"').empty? |
|---|
| | 171 | content.save |
|---|
| | 172 | assert_equal content, Content.find_by_contents('"find me"').first |
|---|
| | 173 | end |
|---|
| | 174 | |
|---|
| | 175 | def test_records_for_bulk_index |
|---|
| | 176 | Content.disable_ferret do |
|---|
| | 177 | more_contents |
|---|
| | 178 | end |
|---|
| | 179 | min = Content.find(:all, :order => 'id asc').first.id |
|---|
| | 180 | Content.records_for_bulk_index([min, min+1, min+2, min+3, min+4, min+6], 10) do |records, offset| |
|---|
| | 181 | assert_equal 6, records.size |
|---|
| | 182 | end |
|---|
| | 183 | end |
|---|
| | 184 | |
|---|
| | 185 | def test_bulk_index |
|---|
| | 186 | Content.disable_ferret do |
|---|
| | 187 | more_contents |
|---|
| | 188 | end |
|---|
| | 189 | |
|---|
| | 190 | assert Content.find_with_ferret('title').empty? |
|---|
| | 191 | min = Content.find(:all, :order => 'id asc').first.id |
|---|
| | 192 | Content.bulk_index([min, min+1, min+2, min+3, min+4, min+6]) |
|---|
| | 193 | assert_equal 6, Content.find_with_ferret('title').size |
|---|
| | 194 | end |
|---|
| | 195 | |
|---|