Commit 9ac1c8a9093214633fcc3d29f46836f895a84adf
1 parent
fa84aa58
Exists in
master
and in
2 other branches
Moved default scope tests to separate file [skip ci]
Showing
5 changed files
with
35 additions
and
18 deletions
Show diff stats
... | ... | @@ -0,0 +1,31 @@ |
1 | +require_relative "test_helper" | |
2 | + | |
3 | +class DefaultScopeTest < Minitest::Test | |
4 | + def setup | |
5 | + Band.destroy_all | |
6 | + end | |
7 | + | |
8 | + def test_reindex | |
9 | + store [ | |
10 | + {name: "Test", active: true}, | |
11 | + {name: "Test 2", active: false} | |
12 | + ], reindex: false | |
13 | + | |
14 | + Band.reindex | |
15 | + assert_search "*", ["Test"], {load: false} | |
16 | + end | |
17 | + | |
18 | + def test_search | |
19 | + Band.reindex | |
20 | + Band.search("*") # test works | |
21 | + | |
22 | + error = assert_raises(Searchkick::Error) do | |
23 | + Band.all.search("*") | |
24 | + end | |
25 | + assert_equal "search must be called on model, not relation", error.message | |
26 | + end | |
27 | + | |
28 | + def default_model | |
29 | + Band | |
30 | + end | |
31 | +end | ... | ... |
test/reindex_test.rb
... | ... | @@ -185,12 +185,6 @@ class ReindexTest < Minitest::Test |
185 | 185 | assert_match "unsupported keywords: :async", error.message |
186 | 186 | end |
187 | 187 | |
188 | - def test_full_default_scope | |
189 | - store_names ["Test", "Test 2"], Band, reindex: false | |
190 | - Band.reindex | |
191 | - assert_search "*", ["Test"], {load: false}, Band | |
192 | - end | |
193 | - | |
194 | 188 | def test_callbacks_false |
195 | 189 | Searchkick.callbacks(false) do |
196 | 190 | store_names ["Product A", "Product B"] | ... | ... |
test/search_test.rb
... | ... | @@ -8,16 +8,6 @@ class SearchTest < Minitest::Test |
8 | 8 | assert_equal "search must be called on model, not relation", error.message |
9 | 9 | end |
10 | 10 | |
11 | - def test_search_relation_default_scope | |
12 | - Band.reindex | |
13 | - Band.search("*") # test works | |
14 | - | |
15 | - error = assert_raises(Searchkick::Error) do | |
16 | - Band.all.search("*") | |
17 | - end | |
18 | - assert_equal "search must be called on model, not relation", error.message | |
19 | - end | |
20 | - | |
21 | 11 | def test_body |
22 | 12 | store_names ["Dollar Tree"], Store |
23 | 13 | assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "dollar"}}}, load: false).map(&:name) | ... | ... |
test/support/activerecord.rb
... | ... | @@ -63,6 +63,7 @@ ActiveRecord::Schema.define do |
63 | 63 | |
64 | 64 | create_table :bands do |t| |
65 | 65 | t.string :name |
66 | + t.boolean :active | |
66 | 67 | end |
67 | 68 | end |
68 | 69 | |
... | ... | @@ -96,5 +97,5 @@ class Song < ActiveRecord::Base |
96 | 97 | end |
97 | 98 | |
98 | 99 | class Band < ActiveRecord::Base |
99 | - default_scope { where(name: "Test") } | |
100 | + default_scope { where(active: true).order(:name) } | |
100 | 101 | end | ... | ... |
test/support/mongoid.rb