elastic_record 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Rakefile +2 -2
- data/elastic_record.gemspec +2 -2
- data/lib/elastic_record.rb +1 -0
- data/lib/elastic_record/callbacks.rb +13 -5
- data/lib/elastic_record/connection.rb +7 -8
- data/lib/elastic_record/errors.rb +10 -0
- data/lib/elastic_record/index/deferred.rb +7 -1
- data/lib/elastic_record/index/documents.rb +34 -17
- data/lib/elastic_record/index/manage.rb +8 -0
- data/lib/elastic_record/index/percolator.rb +16 -10
- data/lib/elastic_record/integration/active_record.rb +7 -0
- data/lib/elastic_record/integration/cassandra_object.rb +7 -0
- data/lib/elastic_record/model.rb +5 -10
- data/lib/elastic_record/railtie.rb +10 -0
- data/lib/elastic_record/relation.rb +26 -5
- data/lib/elastic_record/relation/batches.rb +4 -1
- data/lib/elastic_record/relation/finder_methods.rb +13 -3
- data/lib/elastic_record/relation/search_methods.rb +17 -0
- data/lib/elastic_record/relation/value_methods.rb +2 -2
- data/lib/elastic_record/searches_many.rb +1 -1
- data/lib/elastic_record/searches_many/association.rb +14 -10
- data/lib/elastic_record/searches_many/builder.rb +3 -3
- data/lib/elastic_record/searches_many/collection_proxy.rb +9 -3
- data/lib/elastic_record/searches_many/reflection.rb +4 -0
- data/test/elastic_record/callbacks_test.rb +65 -1
- data/test/elastic_record/config_test.rb +3 -3
- data/test/elastic_record/connection_test.rb +1 -1
- data/test/elastic_record/index/configurator_test.rb +1 -1
- data/test/elastic_record/index/documents_test.rb +23 -4
- data/test/elastic_record/index/manage_test.rb +1 -1
- data/test/elastic_record/index/mapping_test.rb +1 -1
- data/test/elastic_record/index/percolator_test.rb +1 -1
- data/test/elastic_record/index/settings_test.rb +1 -1
- data/test/elastic_record/index/warmer_test.rb +1 -1
- data/test/elastic_record/index_test.rb +1 -1
- data/test/elastic_record/integration/active_record_test.rb +39 -0
- data/test/elastic_record/log_subscriber_test.rb +11 -0
- data/test/elastic_record/lucene_test.rb +1 -1
- data/test/elastic_record/model_test.rb +1 -1
- data/test/elastic_record/railties/controller_runtime_test.rb +1 -1
- data/test/elastic_record/relation/admin_test.rb +13 -7
- data/test/elastic_record/relation/batches_test.rb +27 -1
- data/test/elastic_record/relation/delegation_test.rb +1 -1
- data/test/elastic_record/relation/finder_methods_test.rb +23 -8
- data/test/elastic_record/relation/merging_test.rb +1 -1
- data/test/elastic_record/relation/none_test.rb +1 -1
- data/test/elastic_record/relation/search_methods_test.rb +15 -2
- data/test/elastic_record/relation_test.rb +50 -3
- data/test/elastic_record/searches_many/association_test.rb +47 -0
- data/test/elastic_record/searches_many/autosave_test.rb +11 -10
- data/test/elastic_record/searches_many/collection_proxy_test.rb +1 -1
- data/test/elastic_record/searches_many/reflection_test.rb +7 -1
- data/test/elastic_record/searches_many_test.rb +11 -11
- data/test/elastic_record/searching_test.rb +1 -1
- data/test/helper.rb +19 -12
- data/test/support/models/option.rb +24 -0
- data/test/support/models/test_model.rb +22 -1
- data/test/support/models/warehouse.rb +2 -2
- data/test/support/models/widget.rb +4 -2
- data/test/support/query_counter.rb +56 -0
- metadata +10 -5
- data/lib/elastic_record/orm/active_record.rb +0 -7
@@ -26,6 +26,17 @@ class ElasticRecord::LogSubscriberTest < ActiveSupport::TestCase
|
|
26
26
|
assert_match %r['#{ActiveSupport::JSON.encode('foo' => 'bar')}'], @logger.logged(:debug)[0]
|
27
27
|
end
|
28
28
|
|
29
|
+
def test_request_notification_escaping
|
30
|
+
FakeWeb.register_uri(:any, %r[/test?v=%DB], status: ["200", "OK"], body: ActiveSupport::JSON.encode('the' => 'response', 'has %DB' => 'odd %DB stuff'))
|
31
|
+
Widget.elastic_connection.json_get "/test?v=%DB", {'foo' => 'bar', 'escape %DB ' => 'request %DB'}
|
32
|
+
|
33
|
+
wait
|
34
|
+
|
35
|
+
assert_equal 1, @logger.logged(:debug).size
|
36
|
+
assert_match /GET (.*)test/, @logger.logged(:debug)[0]
|
37
|
+
assert_match %r['#{ActiveSupport::JSON.encode('foo' => 'bar', 'escape %DB ' => 'request %DB')}'], @logger.logged(:debug)[0]
|
38
|
+
end
|
39
|
+
|
29
40
|
def test_initializes_runtime
|
30
41
|
Thread.new { assert_equal 0, ElasticRecord::LogSubscriber.runtime }.join
|
31
42
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::LuceneTest < MiniTest::
|
3
|
+
class ElasticRecord::LuceneTest < MiniTest::Unit::TestCase
|
4
4
|
def test_escape
|
5
5
|
assert_equal "\\\\", ElasticRecord::Lucene.escape("\\")
|
6
6
|
assert_equal "Matt \\&& Joe", ElasticRecord::Lucene.escape("Matt && Joe")
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require "elastic_record/railties/controller_runtime"
|
3
3
|
|
4
|
-
class ElasticRecord::Railties::ControllerRuntimeTest < MiniTest::
|
4
|
+
class ElasticRecord::Railties::ControllerRuntimeTest < MiniTest::Unit::TestCase
|
5
5
|
class TestRuntime
|
6
6
|
def self.log_process_action(payload)
|
7
7
|
['sweet']
|
@@ -1,22 +1,28 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::AdminTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::AdminTest < MiniTest::Unit::TestCase
|
4
4
|
def test_create_percolator
|
5
|
-
|
5
|
+
index.delete_percolator('green') if index.percolator_exists?('green')
|
6
6
|
|
7
|
-
Widget.elastic_relation.filter(color
|
8
|
-
|
9
|
-
widget = Widget.new(color: 'green')
|
7
|
+
relation = Widget.elastic_relation.filter('color' => 'green')
|
8
|
+
relation.create_percolator('green')
|
10
9
|
|
11
|
-
assert_equal
|
10
|
+
assert_equal relation.as_elastic, index.get_percolator('green')
|
12
11
|
end
|
13
12
|
|
14
13
|
def test_create_warmer
|
15
|
-
|
14
|
+
index.delete_warmer('green') if index.warmer_exists?('green')
|
16
15
|
|
17
16
|
relation = Widget.elastic_relation.filter('color' => 'green')
|
18
17
|
relation.create_warmer('green')
|
19
18
|
|
20
19
|
assert_equal relation.as_elastic, Widget.elastic_index.get_warmer('green')['source']
|
21
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def index
|
25
|
+
Widget.elastic_index
|
26
|
+
end
|
27
|
+
|
22
28
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::BatchesTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::BatchesTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
super
|
6
6
|
create_widgets
|
@@ -50,6 +50,22 @@ class ElasticRecord::Relation::BatchesTest < MiniTest::Spec
|
|
50
50
|
assert_equal [['5', '10'].to_set], results.map(&:to_set)
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_find_offset_shards
|
54
|
+
create_additional_widgets
|
55
|
+
|
56
|
+
#assert_queries 3 do
|
57
|
+
results = []
|
58
|
+
Widget.elastic_relation.find_ids_in_batches(batch_size: 1) do |ids|
|
59
|
+
results << ids
|
60
|
+
end
|
61
|
+
#end
|
62
|
+
|
63
|
+
assert_equal 8, results.size
|
64
|
+
results.each do |r| assert_equal 1, r.size end
|
65
|
+
assert_equal ['5', '10', '15', '20', '25', '30', '35', '40'].to_set, results.flatten.to_set
|
66
|
+
|
67
|
+
end
|
68
|
+
|
53
69
|
private
|
54
70
|
def create_widgets
|
55
71
|
Widget.elastic_index.bulk_add [
|
@@ -58,4 +74,14 @@ class ElasticRecord::Relation::BatchesTest < MiniTest::Spec
|
|
58
74
|
Widget.new(id: 15, color: 'green'),
|
59
75
|
]
|
60
76
|
end
|
77
|
+
|
78
|
+
def create_additional_widgets
|
79
|
+
Widget.elastic_index.bulk_add [
|
80
|
+
Widget.new(id: 20, color: 'yellow'),
|
81
|
+
Widget.new(id: 25, color: 'violet'),
|
82
|
+
Widget.new(id: 30, color: 'indigo'),
|
83
|
+
Widget.new(id: 35, color: 'orange'),
|
84
|
+
Widget.new(id: 40, color: 'black'),
|
85
|
+
]
|
86
|
+
end
|
61
87
|
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
class RecordNotFound < StandardError
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Spec
|
3
|
+
class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Unit::TestCase
|
9
4
|
def setup
|
10
5
|
super
|
11
6
|
create_widgets
|
@@ -20,6 +15,19 @@ class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Spec
|
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
18
|
+
def test_find_passed_an_array
|
19
|
+
assert_equal 2, Widget.elastic_relation.find(['05', '10']).size
|
20
|
+
assert_equal 2, Widget.elastic_relation.filter('color' => ['red', 'blue']).find(['05', '10']).size
|
21
|
+
assert_equal 0, Widget.elastic_relation.find(['15', '20']).size
|
22
|
+
assert_equal 0, Widget.elastic_relation.filter('color' => ['purple', 'gold']).find(['05', '10']).size
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find_passed_an_empty_args
|
26
|
+
assert_raises ActiveRecord::RecordNotFound do
|
27
|
+
Widget.elastic_relation.find()
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
23
31
|
def test_first
|
24
32
|
assert_equal '10', Widget.elastic_relation.order('color').first.id
|
25
33
|
assert_equal '05', Widget.elastic_relation.order('color').filter('color' => 'red').first.id
|
@@ -27,6 +35,13 @@ class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Spec
|
|
27
35
|
assert_nil Widget.elastic_relation.filter('color' => 'green').first
|
28
36
|
end
|
29
37
|
|
38
|
+
def test_first_with_bang
|
39
|
+
assert_equal '10', Widget.elastic_relation.order('color').first!.id
|
40
|
+
assert_raises ActiveRecord::RecordNotFound do
|
41
|
+
Widget.elastic_relation.filter('color' => 'green').first!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
def test_last
|
31
46
|
assert_equal '05', Widget.elastic_relation.order('color').last.id
|
32
47
|
assert_equal '05', Widget.elastic_relation.order('color' => 'asc').last.id
|
@@ -44,6 +59,6 @@ class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Spec
|
|
44
59
|
Widget.elastic_index.bulk_add [
|
45
60
|
Widget.new(color: 'red', id: '05'),
|
46
61
|
Widget.new(color: 'blue', id: '10'),
|
47
|
-
]
|
62
|
+
]
|
48
63
|
end
|
49
|
-
end
|
64
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::MergingTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::MergingTest < MiniTest::Unit::TestCase
|
4
4
|
def test_merge_single_values
|
5
5
|
relation = Widget.elastic_relation.limit(5)
|
6
6
|
other = Widget.elastic_relation.limit(10)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::SearchMethodsTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Unit::TestCase
|
4
4
|
def test_query_with_no_queries
|
5
5
|
expected = {"match_all" => {}}
|
6
6
|
|
@@ -57,6 +57,19 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
|
|
57
57
|
assert_equal expected, relation.as_elastic['query']
|
58
58
|
end
|
59
59
|
|
60
|
+
def test_find_by
|
61
|
+
Widget.elastic_index.bulk_add [
|
62
|
+
Widget.new(color: 'red', id: '05'),
|
63
|
+
Widget.new(color: 'blue', id: '10'),
|
64
|
+
]
|
65
|
+
|
66
|
+
assert_equal '05', relation.find_by(color: 'red').id
|
67
|
+
assert_equal '05', relation.find_by!(color: 'red').id
|
68
|
+
assert_raises ActiveRecord::RecordNotFound do
|
69
|
+
relation.find_by!(color: 'green')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
60
73
|
def test_query_with_only_query
|
61
74
|
relation.query!('foo')
|
62
75
|
|
@@ -224,4 +237,4 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
|
|
224
237
|
def relation
|
225
238
|
@relation ||= Widget.elastic_relation
|
226
239
|
end
|
227
|
-
end
|
240
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::RelationTest < MiniTest::
|
3
|
+
class ElasticRecord::RelationTest < MiniTest::Unit::TestCase
|
4
4
|
def test_count
|
5
5
|
create_widgets [Widget.new(id: 5, color: 'red'), Widget.new(id: 10, color: 'blue')]
|
6
6
|
|
@@ -25,10 +25,57 @@ class ElasticRecord::RelationTest < MiniTest::Spec
|
|
25
25
|
# assert Widget.elastic_relation.search_results.is_a?(ElasticSearch::Api::Hits)
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_eager_loading?
|
29
|
+
assert Widget.elastic_relation.eager_load(:options).eager_loading?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_eager_loading_is_not_default
|
33
|
+
assert !Widget.elastic_relation.eager_loading?
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_eager_load_on_collection_proxy
|
37
|
+
|
38
|
+
warehouse = Warehouse.new
|
39
|
+
widget = Widget.new(warehouse_id: warehouse.id)
|
40
|
+
Widget.elastic_index.bulk_add [ widget ]
|
41
|
+
|
42
|
+
Option.elastic_index.bulk_add [
|
43
|
+
Option.new(id: 5, widget_id: widget.id),
|
44
|
+
Option.new(id: 10, widget_id: widget.id),
|
45
|
+
]
|
46
|
+
|
47
|
+
widgets = warehouse.widgets.eager_load(:options)
|
48
|
+
widgets = widgets.to_a
|
49
|
+
|
50
|
+
assert_no_queries do
|
51
|
+
assert_equal ["5", "10"].to_set, widgets.first.options.map(&:id).to_set
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_eager_load_on_relation
|
57
|
+
|
58
|
+
widget = Widget.new
|
59
|
+
Widget.elastic_index.bulk_add [ widget ]
|
60
|
+
|
61
|
+
Option.elastic_index.bulk_add [
|
62
|
+
Option.new(id: 5, widget_id: widget.id),
|
63
|
+
Option.new(id: 10, widget_id: widget.id),
|
64
|
+
]
|
65
|
+
|
66
|
+
widgets = Widget.elastic_relation.eager_load(:options)
|
67
|
+
widgets = widgets.to_a
|
68
|
+
|
69
|
+
assert_no_queries do
|
70
|
+
assert_equal ["5", "10"].to_set, widgets.first.options.map(&:id).to_set
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
28
75
|
def test_to_ids
|
29
76
|
create_widgets [Widget.new(id: 5, color: 'red'), Widget.new(id: 10, color: 'blue')]
|
30
77
|
|
31
|
-
assert_equal ['5', '10'], Widget.elastic_relation.to_ids
|
78
|
+
assert_equal ['5', '10'].to_set, Widget.elastic_relation.to_ids.to_set
|
32
79
|
end
|
33
80
|
|
34
81
|
def test_to_a
|
@@ -57,4 +104,4 @@ class ElasticRecord::RelationTest < MiniTest::Spec
|
|
57
104
|
def create_widgets(widgets)
|
58
105
|
Widget.elastic_index.bulk_add(widgets)
|
59
106
|
end
|
60
|
-
end
|
107
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ElasticRecord::SearchesMany::AssociationTest < MiniTest::Spec
|
4
|
+
|
5
|
+
def test_writer_assignment_from_hash
|
6
|
+
warehouse = Warehouse.new
|
7
|
+
warehouse.widgets = [{color: 'blue', name: 'thing'}]
|
8
|
+
|
9
|
+
assert_equal 1, warehouse.widgets.all.count
|
10
|
+
expected = {
|
11
|
+
'color' => 'blue',
|
12
|
+
'name' => 'thing',
|
13
|
+
'warehouse_id' => warehouse.id,
|
14
|
+
}
|
15
|
+
assert_equal expected, warehouse.widgets[0].attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_writer
|
19
|
+
warehouse = Warehouse.new
|
20
|
+
|
21
|
+
warehouse.widgets = [{color: 'blue', name: 'thing'}]
|
22
|
+
|
23
|
+
assert_equal 1, warehouse.widgets.all.count
|
24
|
+
|
25
|
+
warehouse.widgets = [ {color: 'red', name: 'device'}, {color: 'blue', name: 'thing'} ]
|
26
|
+
|
27
|
+
assert_equal 3, warehouse.widgets.all.count
|
28
|
+
assert warehouse.widgets[0].marked_for_destruction?
|
29
|
+
refute warehouse.widgets[1].marked_for_destruction?
|
30
|
+
refute warehouse.widgets[2].marked_for_destruction?
|
31
|
+
|
32
|
+
expected = {
|
33
|
+
'color' => 'red',
|
34
|
+
'name' => 'device',
|
35
|
+
'warehouse_id' => warehouse.id,
|
36
|
+
}
|
37
|
+
assert_equal expected, warehouse.widgets[1].attributes
|
38
|
+
|
39
|
+
expected = {
|
40
|
+
'color' => 'blue',
|
41
|
+
'name' => 'thing',
|
42
|
+
'warehouse_id' => warehouse.id,
|
43
|
+
}
|
44
|
+
assert_equal expected, warehouse.widgets[2].attributes
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -1,31 +1,32 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::SearchesMany::AutosaveTest < MiniTest::
|
4
|
-
def
|
3
|
+
class ElasticRecord::SearchesMany::AutosaveTest < MiniTest::Unit::TestCase
|
4
|
+
def test_save_associations_autosave_callback
|
5
5
|
warehouse = Warehouse.new
|
6
6
|
widget = Widget.new
|
7
7
|
warehouse.widgets = [widget]
|
8
|
+
assert warehouse.new_record?
|
8
9
|
assert widget.new_record?
|
9
|
-
|
10
|
+
|
10
11
|
warehouse.save
|
11
|
-
|
12
|
+
|
12
13
|
assert widget.persisted?
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
+
def test_validate_associations_autosave_callback
|
16
17
|
warehouse = Warehouse.new
|
17
18
|
widget = Widget.new color: 123
|
18
19
|
warehouse.widgets = [widget]
|
19
|
-
|
20
|
+
|
20
21
|
assert warehouse.invalid?
|
21
22
|
assert_equal ["is invalid"], warehouse.errors['widgets.color']
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def test_mark_for_destruction
|
25
26
|
widget = Widget.new
|
26
|
-
|
27
|
+
|
27
28
|
widget.mark_for_destruction
|
28
|
-
|
29
|
+
|
29
30
|
assert widget.marked_for_destruction?
|
30
31
|
end
|
31
|
-
end
|
32
|
+
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::SearchesMany::ReflectionTest < MiniTest::
|
3
|
+
class ElasticRecord::SearchesMany::ReflectionTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_foreiegn_key
|
6
|
+
assert_equal 'warehouse_id', reflection_class.new(Warehouse, :widgets, {}).foreign_key
|
7
|
+
assert_equal 'foo_id', reflection_class.new(Warehouse, :widgets, {:foreign_key => 'foo_id' }).foreign_key
|
8
|
+
end
|
9
|
+
|
4
10
|
def test_klass_name
|
5
11
|
assert_equal 'Product', reflection_class.new(Warehouse, :widgets, {class_name: 'Product'}).klass_name
|
6
12
|
assert_equal 'Widget', reflection_class.new(Warehouse, :widgets, {}).klass_name
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::SearchesManyTest < MiniTest::
|
3
|
+
class ElasticRecord::SearchesManyTest < MiniTest::Unit::TestCase
|
4
4
|
def test_reader
|
5
5
|
warehouse = Warehouse.create
|
6
6
|
related_widget = Widget.create warehouse: warehouse
|
7
7
|
unrelated_widget = Widget.create
|
8
|
-
|
8
|
+
|
9
9
|
assert_equal [related_widget], warehouse.widgets
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_write_with_objects
|
13
13
|
warehouse = Warehouse.new
|
14
14
|
widget = Widget.new
|
15
|
-
|
15
|
+
|
16
16
|
warehouse.widgets = [widget]
|
17
|
-
|
17
|
+
|
18
18
|
assert widget.new_record?
|
19
19
|
assert_equal warehouse.id, widget.warehouse_id
|
20
20
|
# assert_equal 1, warehouse.widgets_count
|
@@ -23,14 +23,14 @@ class ElasticRecord::SearchesManyTest < MiniTest::Spec
|
|
23
23
|
|
24
24
|
def test_write_with_attributes
|
25
25
|
warehouse = Warehouse.new
|
26
|
-
|
26
|
+
|
27
27
|
warehouse.widgets = [
|
28
28
|
{
|
29
29
|
color: 'blue',
|
30
30
|
name: 'Toy'
|
31
31
|
}
|
32
32
|
]
|
33
|
-
|
33
|
+
|
34
34
|
widgets = warehouse.widgets
|
35
35
|
assert_equal 1, widgets.size
|
36
36
|
end
|
@@ -38,9 +38,9 @@ class ElasticRecord::SearchesManyTest < MiniTest::Spec
|
|
38
38
|
def test_write_marks_destroyed
|
39
39
|
warehouse = Warehouse.new
|
40
40
|
widget = Widget.create warehouse: warehouse
|
41
|
-
|
41
|
+
|
42
42
|
warehouse.widgets = []
|
43
|
-
|
43
|
+
|
44
44
|
association = warehouse.searches_many_association(:widgets)
|
45
45
|
assert_equal 1, association.reader.size
|
46
46
|
assert association.reader.first.marked_for_destruction?
|
@@ -49,14 +49,14 @@ class ElasticRecord::SearchesManyTest < MiniTest::Spec
|
|
49
49
|
def test_write_existing_record
|
50
50
|
widget = Widget.create name: 'Toy', color: 'green'
|
51
51
|
warehouse = Warehouse.new widgets: [widget]
|
52
|
-
|
52
|
+
|
53
53
|
warehouse.widgets = [
|
54
54
|
{
|
55
55
|
id: widget.id,
|
56
56
|
color: "blue"
|
57
57
|
}
|
58
58
|
]
|
59
|
-
|
59
|
+
|
60
60
|
widgets = warehouse.widgets
|
61
61
|
assert_equal 1, widgets.size
|
62
62
|
assert_equal "blue", widgets.first.color
|
@@ -73,4 +73,4 @@ class ElasticRecord::SearchesManyTest < MiniTest::Spec
|
|
73
73
|
|
74
74
|
assert_equal [], warehouse.widgets
|
75
75
|
end
|
76
|
-
end
|
76
|
+
end
|