couchbase-model-relationship 0.1.14 → 0.1.15
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.
@@ -11,18 +11,16 @@ module Couchbase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Should this only fire if we had a parent and assigned the id?
|
14
|
-
retried = false
|
15
14
|
begin
|
16
15
|
create_without_parent_id(options)
|
17
16
|
rescue Couchbase::Error::KeyExists => error
|
18
|
-
if
|
19
|
-
retried = true
|
17
|
+
if ok_to_merge_on_key_exists_error?
|
20
18
|
on_key_exists_merge_from_db!
|
21
19
|
|
22
|
-
retry
|
20
|
+
save # Can't retry because that still tries 'add'
|
21
|
+
else
|
22
|
+
raise error
|
23
23
|
end
|
24
|
-
|
25
|
-
raise error
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
data/spec/child_spec.rb
CHANGED
@@ -38,33 +38,51 @@ describe "children" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "with collisions" do
|
41
|
+
|
42
|
+
before(:all) do
|
43
|
+
@mock = start_mock
|
44
|
+
bucket = Couchbase.connect(:hostname => @mock.host, :port => @mock.port)
|
45
|
+
|
46
|
+
ChildMergeTest.bucket = bucket
|
47
|
+
ChildTest.bucket = bucket
|
48
|
+
ChildTestParent.bucket = bucket
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:all) do
|
52
|
+
stop_mock @mock
|
53
|
+
|
54
|
+
ChildMergeTest.bucket = nil
|
55
|
+
ChildTest.bucket = nil
|
56
|
+
ChildTestParent.bucket = nil
|
57
|
+
end
|
58
|
+
|
41
59
|
let(:collider) { ChildMergeTest.new(parent: parent) }
|
42
|
-
let(:
|
60
|
+
let(:existing) { ChildMergeTest.new(parent: parent).save! }
|
43
61
|
|
44
62
|
before do
|
45
|
-
parent.id = "parent:#{Time.now.
|
46
|
-
|
63
|
+
parent.id = "parent:#{Time.now.to_f}"
|
64
|
+
|
65
|
+
subject.parent = parent
|
47
66
|
end
|
48
67
|
|
49
68
|
it "just fails if no merge method" do
|
50
|
-
|
51
|
-
ChildTest.stubs(bucket: bucket)
|
69
|
+
subject.class.new(parent: parent).save!
|
52
70
|
|
53
71
|
expect { subject.save }.to raise_error(Couchbase::Error::KeyExists)
|
54
72
|
end
|
55
73
|
|
56
74
|
it "just fails with no parent" do
|
57
|
-
bucket.expects(:add).raises(Couchbase::Error::KeyExists)
|
58
|
-
|
59
75
|
collider.parent = nil
|
76
|
+
collider.instance_variable_set(:@id, existing.id)
|
60
77
|
collider.expects(:on_key_exists_merge_from_db!).never
|
61
78
|
|
62
79
|
expect { collider.save }.to raise_error(Couchbase::Error::KeyExists)
|
63
80
|
end
|
64
81
|
|
65
82
|
it "just fails with a parent and a non-parent derived id" do
|
66
|
-
|
67
|
-
|
83
|
+
ChildMergeTest.bucket.add("abc-123" => "boo")
|
84
|
+
|
85
|
+
collider.instance_variable_set(:@id, "abc-123")
|
68
86
|
collider.expects(:on_key_exists_merge_from_db!).never
|
69
87
|
|
70
88
|
expect { collider.save }.to raise_error(Couchbase::Error::KeyExists)
|
@@ -72,9 +90,7 @@ describe "children" do
|
|
72
90
|
|
73
91
|
# These should really exercise a real backend
|
74
92
|
it "retries if mergable" do
|
75
|
-
|
76
|
-
bucket.expects(:add).raises(Couchbase::Error::KeyExists).in_sequence(seq)
|
77
|
-
bucket.expects(:add).returns(true).in_sequence(seq)
|
93
|
+
existing
|
78
94
|
|
79
95
|
collider.expects(:on_key_exists_merge_from_db!)
|
80
96
|
|
@@ -83,19 +99,20 @@ describe "children" do
|
|
83
99
|
end
|
84
100
|
|
85
101
|
it "fails is merging fails" do
|
86
|
-
|
102
|
+
existing
|
87
103
|
|
88
104
|
collider.expects(:on_key_exists_merge_from_db!).raises(ArgumentError)
|
89
105
|
|
90
106
|
expect { collider.save }.to raise_error(ArgumentError)
|
91
107
|
end
|
92
108
|
|
93
|
-
it "
|
94
|
-
|
109
|
+
it "raises if save after merge fails" do
|
110
|
+
existing
|
95
111
|
|
96
112
|
collider.expects(:on_key_exists_merge_from_db!)
|
113
|
+
collider.stubs(:save).raises(RuntimeError)
|
97
114
|
|
98
|
-
expect { collider.
|
115
|
+
expect { collider.create }.to raise_error(RuntimeError)
|
99
116
|
end
|
100
117
|
end
|
101
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchbase-model-relationship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
segments:
|
220
220
|
- 0
|
221
|
-
hash: -
|
221
|
+
hash: -837613692810589615
|
222
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
223
|
none: false
|
224
224
|
requirements:
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
version: '0'
|
228
228
|
segments:
|
229
229
|
- 0
|
230
|
-
hash: -
|
230
|
+
hash: -837613692810589615
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
233
|
rubygems_version: 1.8.24
|