-
Notifications
You must be signed in to change notification settings - Fork 0
/
aquqsync_spec.rb
132 lines (104 loc) · 3.5 KB
/
aquqsync_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require_relative '../../spec/spec_helper'
describe "Aquasync" do
context "Book#new" do
let(:book) { Book.new }
it { expect(book.gid).not_to eq nil }
it { expect(book.local_timestamp).not_to eq nil }
it { expect(book.dirty?).to eq true }
end
context "Collection" do
let(:collection) { Aquasync::Collection.new }
let(:book) { Book.new }
let(:master) { Aquasync::MasterCollection.instance }
let(:local_store) { Aquasync::LocalStore.instance }
before(:each) do
local_store.device_token = "testdevicetoken"
local_store.latest_ust = 0
end
it("should be able to add a model") {
collection.push book
expect(collection.size).to eq 1
}
it("should not count deleted model on #size") {
dbook = Book.new
dbook.destroy
collection.push dbook
expect(collection.size).to eq 0
}
context '#push_sync' do
before(:each) do
master.drop_all
book1 = Book.new
book2 = Book.new
collection.push book1
collection.push book2
end
context "one collection" do
it("dirty resources size should eq 2") {
expect(collection.dirty_resources.size).to eq 2
}
it("should push 2 dirty records to master successfully") {
collection.push_sync
expect(master.collection.size).to eq 2
}
it("should undirty resources after #push_sync") {
collection.push_sync
expect(collection.dirty_resources.size).to eq 0
}
it("should not send duplicated deltas for duplicated #push_sync") {
collection.push_sync
collection.push_sync
expect(master.collection.size).to eq 2
}
it("should send deltas which is created after last #push_sync") {
collection.push_sync
book3 = Book.new
collection.push book3
collection.push_sync
expect(master.collection.size).to eq 3
}
it("should pull nothing at #pull_sync after #push_sync performed") {
collection.push_sync
collection.pull_sync
expect(collection.size).to eq 2
}
it("should send deltas which is modified after last #push_sync") {
collection.push_sync
collection.first.update_attribute(:name, "The Little Prince")
collection.push_sync
expect(master.collection.size).to eq 2
}
it("should send deltas which is modified after last #push_sync") {
collection.push_sync
collection.first.update_attribute(:name, "The Little Prince")
collection.push_sync
expect(master.collection.first.name).to eq "The Little Prince"
}
end
context "two collections" do
let(:collection2) { Aquasync::Collection.new }
before(:each) do
book3 = Book.new
book4 = Book.new
book5 = Book.new
collection2.push book3
collection2.push book4
collection2.push book5
end
it("should merge deltas from two collections") {
collection.push_sync
collection2.push_sync
expect(master.collection.size).to eq 5
}
it("should merge merged collections on master to local collection") {
collection.push_sync
collection2.push_sync
collection.pull_sync
collection2.pull_sync
expect(collection.size).to eq 5
expect(collection2.size).to eq 5
}
end
end
end
end