eternity 0.0.1

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.
data/spec/push_spec.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Repository, 'Push' do
4
+
5
+ let(:repository) { Repository.new :test }
6
+
7
+ it 'New branch' do
8
+ repository[:countries].insert 'AR', name: 'Argentina'
9
+ commit = repository.commit author: 'User', message: 'Commit message'
10
+
11
+ Branch.wont_be :exists?, :master
12
+
13
+ repository.push
14
+
15
+ Branch[:master].id.must_equal commit.id
16
+ end
17
+
18
+ it 'Without commit' do
19
+ error = proc { repository.push }.must_raise RuntimeError
20
+ error.message.must_equal "Can't push without commit"
21
+ end
22
+
23
+ it 'Fast-forward' do
24
+ repository[:countries].insert 'AR', name: 'Argentina'
25
+ commit_1 = repository.commit author: 'User', message: 'Commit 1'
26
+ repository.push
27
+
28
+ repository[:countries].insert 'UY', name: 'Uruguay'
29
+ commit_2 = repository.commit author: 'User', message: 'Commit 2'
30
+ repository.push
31
+
32
+ Branch[:master].id.must_equal commit_2.id
33
+ end
34
+
35
+ it 'Rejected' do
36
+ repository[:countries].insert 'AR', name: 'Argentina'
37
+ repository.commit author: 'User', message: 'Commit message'
38
+
39
+ Branch[:master] = '123456789'
40
+
41
+ error = proc { repository.push }.must_raise RuntimeError
42
+ error.message.must_equal 'Push rejected (non fast forward)'
43
+ end
44
+
45
+ it 'Forced' do
46
+ repository[:countries].insert 'AR', name: 'Argentina'
47
+ commit = repository.commit author: 'User', message: 'Commit message'
48
+
49
+ Branch[:master] = '123456789'
50
+
51
+ repository.push!
52
+
53
+ Branch[:master].id.must_equal commit.id
54
+ end
55
+
56
+ it 'Merge' do
57
+ repository[:countries].insert 'AR', name: 'Argentina'
58
+ commit_1 = repository.commit author: 'User', message: 'Commit 1'
59
+ repository.push
60
+
61
+ other_repository = Repository.new :other
62
+ other_repository[:countries].insert 'BR', name: 'Brasil'
63
+ commit_2 = other_repository.commit author: 'User', message: 'Commit 2'
64
+
65
+ other_repository.pull
66
+ other_repository.push
67
+
68
+ Branch[:master].id.must_equal other_repository.current_commit.id
69
+ Branch[:master].parent_ids.must_equal [commit_2.id, commit_1.id]
70
+ end
71
+
72
+ end
@@ -0,0 +1,73 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Repository do
4
+
5
+ let(:repository) { Repository.new :test }
6
+
7
+ it 'Initial status' do
8
+ repository.wont_be :changes?
9
+ repository.changes_count.must_equal 0
10
+ repository.wont_be :current_commit?
11
+ repository.current_branch.must_equal 'master'
12
+ repository.branches.must_be_empty
13
+ end
14
+
15
+ it 'Empty' do
16
+ repository.must_be_empty
17
+
18
+ repository[:countries].insert 'AR', name: 'Argentina'
19
+ repository.commit author: 'User', message: 'Commit message'
20
+
21
+ repository.wont_be_empty
22
+ end
23
+
24
+ it 'Default branch' do
25
+ Repository.new(:test, default_branch: 'test').current_branch.must_equal 'test'
26
+ end
27
+
28
+ it 'Destroy' do
29
+ repository[:countries].insert 'AR', name: 'Argentina'
30
+ repository.commit author: 'User', message: 'Commit message'
31
+
32
+ repository.destroy
33
+
34
+ repository.must_be_empty
35
+ end
36
+
37
+ it 'Replace delta' do
38
+ repository[:countries].insert 'AR', name: 'Argentina'
39
+
40
+ repository.delta = {'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}}
41
+
42
+ repository.to_h['delta'].must_equal 'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}
43
+ end
44
+
45
+ ['To hash', 'Dump'].each do |test|
46
+ it test do
47
+ repository[:countries].insert 'AR', name: 'Argentina'
48
+ repository.commit author: 'User', message: 'Commit message'
49
+ repository[:countries].insert 'UY', name: 'Uruguay'
50
+
51
+ repository.to_h.must_equal 'current' => {'commit' => repository.current_commit.id, 'branch' => 'master'},
52
+ 'branches' => {'master' => repository.current_commit.id},
53
+ 'delta' => {'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}}
54
+ end
55
+ end
56
+
57
+ it 'Restore' do
58
+ repository[:countries].insert 'AR', name: 'Argentina'
59
+ commit = repository.commit author: 'User', message: 'Commit message'
60
+ repository[:countries].insert 'UY', name: 'Uruguay'
61
+
62
+ dump = repository.dump
63
+ repository.destroy
64
+
65
+ repository.must_be_empty
66
+
67
+ repository.restore dump
68
+
69
+ repository.current_commit.must_equal commit
70
+ repository.delta.must_equal 'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}
71
+ end
72
+
73
+ end
@@ -0,0 +1,40 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Repository, 'Revert' do
4
+
5
+ let(:repository) { Repository.new :test }
6
+
7
+ it 'Insert' do
8
+ repository[:countries].insert 'AR', name: 'Argentina'
9
+
10
+ reverted_delta = repository.revert
11
+
12
+ reverted_delta.must_equal 'countries' => {'AR' => {'action' => 'delete'}}
13
+ repository.wont_be :changes?
14
+ end
15
+
16
+ it 'Update' do
17
+ repository[:countries].insert 'AR', name: 'Argentina'
18
+ repository.commit author: 'User', message: 'Commit message'
19
+
20
+ repository[:countries].update 'AR', name: 'Republica Argentina'
21
+
22
+ reverted_delta = repository.revert
23
+
24
+ reverted_delta.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina'}}}
25
+ repository.wont_be :changes?
26
+ end
27
+
28
+ it 'Delete' do
29
+ repository[:countries].insert 'AR', name: 'Argentina'
30
+ repository.commit author: 'User', message: 'Commit message'
31
+
32
+ repository[:countries].delete 'AR'
33
+
34
+ reverted_delta = repository.revert
35
+
36
+ reverted_delta.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
37
+ repository.wont_be :changes?
38
+ end
39
+
40
+ end
@@ -0,0 +1,143 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Tracker do
4
+
5
+ let(:tracker) { Tracker.new Repository.new(:test) }
6
+
7
+ it 'Initial status' do
8
+ tracker.must_be_empty
9
+ tracker.flatten.must_be_empty
10
+ end
11
+
12
+ it 'Insert' do
13
+ tracker[:countries].insert 'AR', name: 'Argentina'
14
+
15
+ tracker.to_h.must_equal 'countries' => {'AR' => [{'action' => 'insert', 'blob' => digest(name: 'Argentina')}]}
16
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina'}}}
17
+ end
18
+
19
+ it 'Insert -> Update' do
20
+ tracker[:countries].insert 'AR', name: 'Argentina'
21
+ tracker[:countries].update 'AR', name: 'Argentina', code: 'ARG'
22
+
23
+ tracker.to_h.must_equal 'countries' => {'AR' => [
24
+ {'action' => 'insert', 'blob' => digest(name: 'Argentina')},
25
+ {'action' => 'update', 'blob' => digest(name: 'Argentina', code: 'ARG')}
26
+ ]}
27
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'insert', 'data' => {'name' => 'Argentina', 'code' => 'ARG'}}}
28
+ end
29
+
30
+ it 'Insert -> Delete' do
31
+ tracker[:countries].insert 'AR', name: 'Argentina'
32
+ tracker[:countries].delete 'AR'
33
+
34
+ tracker.to_h.must_equal 'countries' => {
35
+ 'AR' => [
36
+ {'action' => 'insert', 'blob' => digest(name: 'Argentina')},
37
+ {'action' => 'delete'}
38
+ ]
39
+ }
40
+ tracker.flatten.must_be_empty
41
+ end
42
+
43
+ it 'Update' do
44
+ tracker[:countries].update 'AR', name: 'Argentina', code: 'ARG'
45
+
46
+ tracker.to_h.must_equal 'countries' => {'AR' => [{'action' => 'update', 'blob' => digest(name: 'Argentina', code: 'ARG')}]}
47
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina', 'code' => 'ARG'}}}
48
+ end
49
+
50
+ it 'Update -> Delete' do
51
+ tracker[:countries].update 'AR', name: 'Argentina', code: 'ARG'
52
+ tracker[:countries].delete 'AR'
53
+
54
+ tracker.to_h.must_equal 'countries' => {
55
+ 'AR' => [
56
+ {'action' => 'update', 'blob' => digest(name: 'Argentina', code: 'ARG')},
57
+ {'action' => 'delete'}
58
+ ]
59
+ }
60
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'delete'}}
61
+ end
62
+
63
+ it 'Update -> Delete -> Insert' do
64
+ tracker[:countries].update 'AR', name: 'Argentina', code: 'ARG'
65
+ tracker[:countries].delete 'AR'
66
+ tracker[:countries].insert 'AR', name: 'Argentina'
67
+
68
+ tracker.to_h.must_equal 'countries' => {
69
+ 'AR' => [
70
+ {'action' => 'update', 'blob' => digest(name: 'Argentina', code: 'ARG')},
71
+ {'action' => 'delete'},
72
+ {'action' => 'insert', 'blob' => digest(name: 'Argentina')}
73
+ ]
74
+ }
75
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina'}}}
76
+ end
77
+
78
+ it 'Delete' do
79
+ tracker[:countries].delete 'AR'
80
+
81
+ tracker.to_h.must_equal 'countries' => {'AR' => [{'action' => 'delete'}]}
82
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'delete'}}
83
+ end
84
+
85
+ it 'Delete -> Insert' do
86
+ tracker[:countries].delete 'AR'
87
+ tracker[:countries].insert 'AR', name: 'Argentina'
88
+
89
+ tracker.to_h.must_equal 'countries' => {
90
+ 'AR' => [
91
+ {'action' => 'delete'},
92
+ {'action' => 'insert', 'blob' => digest(name: 'Argentina')}
93
+ ]
94
+ }
95
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina'}}}
96
+ end
97
+
98
+ it 'Delete -> Insert -> Update' do
99
+ tracker[:countries].delete 'AR'
100
+ tracker[:countries].insert 'AR', name: 'Argentina'
101
+ tracker[:countries].update 'AR', name: 'Argentina', code: 'ARG'
102
+
103
+ tracker.to_h.must_equal 'countries' => {
104
+ 'AR' => [
105
+ {'action' => 'delete'},
106
+ {'action' => 'insert', 'blob' => digest(name: 'Argentina')},
107
+ {'action' => 'update', 'blob' => digest(name: 'Argentina', code: 'ARG')}
108
+ ]
109
+ }
110
+ tracker.flatten.must_equal 'countries' => {'AR' => {'action' => 'update', 'data' => {'name' => 'Argentina', 'code' => 'ARG'}}}
111
+ end
112
+
113
+ it 'Revert' do
114
+ tracker[:countries].insert 'AR', name: 'Argentina'
115
+ tracker[:countries].insert 'UY', name: 'Uruguay'
116
+
117
+ tracker[:countries].revert 'AR'
118
+
119
+ tracker.to_h.must_equal 'countries' => {'UY' => [{'action' => 'insert', 'blob' => digest(name: 'Uruguay')}]}
120
+ tracker.flatten.must_equal 'countries' => {'UY' => {'action' => 'insert', 'data' => {'name' => 'Uruguay'}}}
121
+ end
122
+
123
+ it 'Revert collection' do
124
+ tracker[:countries].insert 'AR', name: 'Argentina'
125
+ tracker[:cities].insert 'CABA', name: 'Ciudad Autonoma de Buenos Aires'
126
+
127
+ tracker[:countries].revert_all
128
+
129
+ tracker.to_h.must_equal 'cities' => {'CABA' => [{'action' => 'insert', 'blob' => digest(name: 'Ciudad Autonoma de Buenos Aires')}]}
130
+ tracker.flatten.must_equal 'cities' => {'CABA' => {'action' => 'insert', 'data' => {'name' => 'Ciudad Autonoma de Buenos Aires'}}}
131
+ end
132
+
133
+ it 'Revert all' do
134
+ tracker[:countries].insert 'AR', name: 'Argentina'
135
+ tracker[:cities].insert 'CABA', name: 'Ciudad Autonoma de Buenos Aires'
136
+
137
+ tracker.revert
138
+
139
+ tracker.must_be_empty
140
+ tracker.flatten.must_be_empty
141
+ end
142
+
143
+ end
metadata ADDED
@@ -0,0 +1,270 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eternity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: restruct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: class_config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: locky
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: transparent_proxy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: msgpack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.5.9
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.5.9
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.5'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: turn
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry-nav
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Distributed database version control system
182
+ email:
183
+ - gabynaiman@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".coveralls.yml"
189
+ - ".gitignore"
190
+ - ".ruby-gemset"
191
+ - ".ruby-version"
192
+ - ".travis.yml"
193
+ - Gemfile
194
+ - LICENSE.txt
195
+ - README.md
196
+ - Rakefile
197
+ - eternity.gemspec
198
+ - lib/eternity.rb
199
+ - lib/eternity/blob.rb
200
+ - lib/eternity/branch.rb
201
+ - lib/eternity/collection_index.rb
202
+ - lib/eternity/collection_tracker.rb
203
+ - lib/eternity/commit.rb
204
+ - lib/eternity/conflict_resolver.rb
205
+ - lib/eternity/delta.rb
206
+ - lib/eternity/index.rb
207
+ - lib/eternity/log.rb
208
+ - lib/eternity/object_tracker.rb
209
+ - lib/eternity/patch.rb
210
+ - lib/eternity/repository.rb
211
+ - lib/eternity/track_flatter.rb
212
+ - lib/eternity/tracker.rb
213
+ - lib/eternity/version.rb
214
+ - spec/blob_spec.rb
215
+ - spec/branch_spec.rb
216
+ - spec/checkout_spec.rb
217
+ - spec/commit_spec.rb
218
+ - spec/coverage_helper.rb
219
+ - spec/delta_spec.rb
220
+ - spec/index_spec.rb
221
+ - spec/locking_spec.rb
222
+ - spec/log_spec.rb
223
+ - spec/minitest_helper.rb
224
+ - spec/patch_spec.rb
225
+ - spec/pull_spec.rb
226
+ - spec/push_spec.rb
227
+ - spec/repository_spec.rb
228
+ - spec/revert_spec.rb
229
+ - spec/tracker_spec.rb
230
+ homepage: https://github.com/gabynaiman/eternity
231
+ licenses:
232
+ - MIT
233
+ metadata: {}
234
+ post_install_message:
235
+ rdoc_options: []
236
+ require_paths:
237
+ - lib
238
+ required_ruby_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ required_rubygems_version: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ version: '0'
248
+ requirements: []
249
+ rubyforge_project:
250
+ rubygems_version: 2.2.2
251
+ signing_key:
252
+ specification_version: 4
253
+ summary: Distributed database version control system
254
+ test_files:
255
+ - spec/blob_spec.rb
256
+ - spec/branch_spec.rb
257
+ - spec/checkout_spec.rb
258
+ - spec/commit_spec.rb
259
+ - spec/coverage_helper.rb
260
+ - spec/delta_spec.rb
261
+ - spec/index_spec.rb
262
+ - spec/locking_spec.rb
263
+ - spec/log_spec.rb
264
+ - spec/minitest_helper.rb
265
+ - spec/patch_spec.rb
266
+ - spec/pull_spec.rb
267
+ - spec/push_spec.rb
268
+ - spec/repository_spec.rb
269
+ - spec/revert_spec.rb
270
+ - spec/tracker_spec.rb