active_git 0.0.3 → 0.0.4
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/.gitignore +19 -18
- data/.travis.yml +7 -0
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/README.md +31 -29
- data/Rakefile +2 -2
- data/active_git.gemspec +25 -25
- data/lib/active_git.rb +47 -46
- data/lib/active_git/active_record_extension.rb +34 -49
- data/lib/active_git/commands.rb +146 -146
- data/lib/active_git/configuration.rb +28 -28
- data/lib/active_git/events/db_create.rb +8 -8
- data/lib/active_git/events/db_delete.rb +12 -12
- data/lib/active_git/events/db_delete_all.rb +15 -15
- data/lib/active_git/events/db_event.rb +28 -27
- data/lib/active_git/events/db_update.rb +14 -14
- data/lib/active_git/events/file_delete.rb +11 -11
- data/lib/active_git/events/file_event.rb +31 -31
- data/lib/active_git/events/file_save.rb +13 -13
- data/lib/active_git/events/folder_remove.rb +15 -15
- data/lib/active_git/inflector.rb +21 -0
- data/lib/active_git/synchronization_error.rb +32 -32
- data/lib/active_git/synchronizer.rb +53 -53
- data/lib/active_git/version.rb +3 -3
- data/spec/active_record_extension_spec.rb +60 -50
- data/spec/commands_spec.rb +245 -245
- data/spec/inflector_spec.rb +37 -0
- data/spec/migrations/20121004135939_create_countries.rb +9 -9
- data/spec/migrations/20121004135940_create_languages.rb +9 -9
- data/spec/migrations/20121030163114_create_brands.rb +9 -9
- data/spec/migrations/20130315192821_create_customers.rb +9 -0
- data/spec/spec_helper.rb +35 -23
- data/spec/support/helpers/file_helper.rb +47 -43
- data/spec/support/models/brand.rb +2 -4
- data/spec/support/models/country.rb +1 -2
- data/spec/support/models/customer.rb +6 -0
- data/spec/support/models/language.rb +2 -4
- data/spec/synchronization_spec.rb +100 -100
- metadata +56 -17
@@ -1,54 +1,54 @@
|
|
1
|
-
module ActiveGit
|
2
|
-
class Synchronizer
|
3
|
-
|
4
|
-
def self.synchronize(*events)
|
5
|
-
batch = self.new
|
6
|
-
|
7
|
-
Array(events).flatten.each do |event|
|
8
|
-
event.synchronize batch
|
9
|
-
end
|
10
|
-
|
11
|
-
batch.run
|
12
|
-
end
|
13
|
-
|
14
|
-
def run
|
15
|
-
unless bulk_inserts.empty?
|
16
|
-
define_job do
|
17
|
-
bulk_inserts.each do |model, records|
|
18
|
-
ActiveGit.configuration.logger.debug "[ActiveGit] Inserting #{model.model_name} models"
|
19
|
-
import_result = model.import records, timestamps: false, validate: false
|
20
|
-
raise SynchronizationError.new(import_result.failed_instances) unless import_result.failed_instances.empty?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
::ActiveRecord::Base.transaction do
|
26
|
-
jobs.each do |job|
|
27
|
-
job.call
|
28
|
-
end
|
29
|
-
end
|
30
|
-
ActiveGit.add_all
|
31
|
-
end
|
32
|
-
|
33
|
-
def bulk_insert(data)
|
34
|
-
bulk_inserts[data.class] ||= [] unless bulk_inserts.has_key? data.class
|
35
|
-
bulk_inserts[data.class] << data
|
36
|
-
end
|
37
|
-
|
38
|
-
def define_job(&block)
|
39
|
-
jobs << Proc.new(&block)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def bulk_inserts
|
45
|
-
@bulk_inserts ||= {}
|
46
|
-
end
|
47
|
-
|
48
|
-
def jobs
|
49
|
-
@jobs ||= []
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
1
|
+
module ActiveGit
|
2
|
+
class Synchronizer
|
3
|
+
|
4
|
+
def self.synchronize(*events)
|
5
|
+
batch = self.new
|
6
|
+
|
7
|
+
Array(events).flatten.each do |event|
|
8
|
+
event.synchronize batch
|
9
|
+
end
|
10
|
+
|
11
|
+
batch.run
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
unless bulk_inserts.empty?
|
16
|
+
define_job do
|
17
|
+
bulk_inserts.each do |model, records|
|
18
|
+
ActiveGit.configuration.logger.debug "[ActiveGit] Inserting #{model.model_name} models"
|
19
|
+
import_result = model.import records, timestamps: false, validate: false
|
20
|
+
raise SynchronizationError.new(import_result.failed_instances) unless import_result.failed_instances.empty?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
::ActiveRecord::Base.transaction do
|
26
|
+
jobs.each do |job|
|
27
|
+
job.call
|
28
|
+
end
|
29
|
+
end
|
30
|
+
ActiveGit.add_all
|
31
|
+
end
|
32
|
+
|
33
|
+
def bulk_insert(data)
|
34
|
+
bulk_inserts[data.class] ||= [] unless bulk_inserts.has_key? data.class
|
35
|
+
bulk_inserts[data.class] << data
|
36
|
+
end
|
37
|
+
|
38
|
+
def define_job(&block)
|
39
|
+
jobs << Proc.new(&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def bulk_inserts
|
45
|
+
@bulk_inserts ||= {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def jobs
|
49
|
+
@jobs ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
54
|
end
|
data/lib/active_git/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module ActiveGit
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
1
|
+
module ActiveGit
|
2
|
+
VERSION = '0.0.4'
|
3
|
+
end
|
@@ -1,51 +1,61 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveGit::ActiveRecord do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
@file_helper = FileHelper.new
|
7
|
-
ActiveGit.configuration.working_path = @file_helper.create_temp_folder
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
@file_helper.remove_temp_folders
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'Registered models' do
|
15
|
-
ActiveGit.models.should include Language
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'Create' do
|
19
|
-
language = Language.create! name: 'Spanish'
|
20
|
-
|
21
|
-
File.exist?(language
|
22
|
-
|
23
|
-
json = JSON.parse(@file_helper.read_file(language
|
24
|
-
|
25
|
-
json['id'].should eq language.id
|
26
|
-
json['name'].should eq language.name
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'Update' do
|
30
|
-
language = Language.create! name: 'Spanish'
|
31
|
-
|
32
|
-
json = JSON.parse(@file_helper.read_file(language
|
33
|
-
json['name'].should eq 'Spanish'
|
34
|
-
|
35
|
-
language.update_attributes name: 'English'
|
36
|
-
|
37
|
-
json = JSON.parse(@file_helper.read_file(language
|
38
|
-
json['name'].should eq 'English'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'Destroy' do
|
42
|
-
language = Language.create! name: 'Spanish'
|
43
|
-
|
44
|
-
File.exist?(language
|
45
|
-
|
46
|
-
language.destroy
|
47
|
-
|
48
|
-
File.exist?(language
|
49
|
-
end
|
50
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveGit::ActiveRecord do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@file_helper = FileHelper.new
|
7
|
+
ActiveGit.configuration.working_path = @file_helper.create_temp_folder
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
@file_helper.remove_temp_folders
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Registered models' do
|
15
|
+
ActiveGit.models.should include Language
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'Create' do
|
19
|
+
language = Language.create! name: 'Spanish'
|
20
|
+
|
21
|
+
File.exist?(git_filename(language)).should be_true
|
22
|
+
|
23
|
+
json = JSON.parse(@file_helper.read_file(git_filename(language)))
|
24
|
+
|
25
|
+
json['id'].should eq language.id
|
26
|
+
json['name'].should eq language.name
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'Update' do
|
30
|
+
language = Language.create! name: 'Spanish'
|
31
|
+
|
32
|
+
json = JSON.parse(@file_helper.read_file(git_filename(language)))
|
33
|
+
json['name'].should eq 'Spanish'
|
34
|
+
|
35
|
+
language.update_attributes name: 'English'
|
36
|
+
|
37
|
+
json = JSON.parse(@file_helper.read_file(git_filename(language)))
|
38
|
+
json['name'].should eq 'English'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Destroy' do
|
42
|
+
language = Language.create! name: 'Spanish'
|
43
|
+
|
44
|
+
File.exist?(git_filename(language)).should be_true
|
45
|
+
|
46
|
+
language.destroy
|
47
|
+
|
48
|
+
File.exist?(git_filename(language)).should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'Load from json' do
|
52
|
+
attributes = {id: 1, name: 'Spanish', created_at: Time.now, updated_at: Time.now}
|
53
|
+
language = Language.from_json attributes.to_json
|
54
|
+
|
55
|
+
language.id.should eq attributes[:id]
|
56
|
+
language.name.should eq attributes[:name]
|
57
|
+
language.created_at.to_i.should eq attributes[:created_at].to_i
|
58
|
+
language.updated_at.to_i.should eq attributes[:updated_at].to_i
|
59
|
+
end
|
60
|
+
|
51
61
|
end
|
data/spec/commands_spec.rb
CHANGED
@@ -1,246 +1,246 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveGit::Commands do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
@file_helper = FileHelper.new
|
7
|
-
ActiveGit.configuration.working_path = @file_helper.create_temp_folder
|
8
|
-
ActiveGit.init
|
9
|
-
end
|
10
|
-
|
11
|
-
after :each do
|
12
|
-
@file_helper.remove_temp_folders
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'Dump and load' do
|
16
|
-
|
17
|
-
it 'Dump complete db to files' do
|
18
|
-
languages = [
|
19
|
-
Language.create!(name: 'Spanish'),
|
20
|
-
Language.create!(name: 'English')
|
21
|
-
]
|
22
|
-
|
23
|
-
@file_helper.write_file "#{ActiveGit.configuration.working_path}/test.txt", 'test'
|
24
|
-
@file_helper.write_file "#{Language
|
25
|
-
|
26
|
-
ActiveGit.dump_db
|
27
|
-
|
28
|
-
File.exist?("#{ActiveGit.configuration.working_path}/test.txt").should be_false
|
29
|
-
|
30
|
-
Dir.glob("#{Language
|
31
|
-
|
32
|
-
languages.each do |language|
|
33
|
-
File.exist?(language
|
34
|
-
json = JSON.parse(@file_helper.read_file(language
|
35
|
-
json['id'].should eq language.id
|
36
|
-
json['name'].should eq language.name
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'Dump single table to files' do
|
41
|
-
language = Language.create! name: 'Spanish'
|
42
|
-
country = Country.create! name: 'Argentina'
|
43
|
-
|
44
|
-
Dir["#{ActiveGit.configuration.working_path}/*"].each { |f| FileUtils.rm_rf f }
|
45
|
-
|
46
|
-
Dir.exists?("#{ActiveGit.configuration.working_path}/languages").should be_false
|
47
|
-
File.exists?("#{ActiveGit.configuration.working_path}/languages/#{language.id}.json").should be_false
|
48
|
-
Dir.exists?("#{ActiveGit.configuration.working_path}/countries").should be_false
|
49
|
-
File.exists?("#{ActiveGit.configuration.working_path}/countries/#{country.id}.json").should be_false
|
50
|
-
|
51
|
-
ActiveGit.dump_db Language
|
52
|
-
|
53
|
-
Dir.exists?("#{ActiveGit.configuration.working_path}/languages").should be_true
|
54
|
-
File.exists?("#{ActiveGit.configuration.working_path}/languages/#{language.id}.json").should be_true
|
55
|
-
Dir.exists?("#{ActiveGit.configuration.working_path}/countries").should be_false
|
56
|
-
File.exists?("#{ActiveGit.configuration.working_path}/countries/#{country.id}.json").should be_false
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'Load all files to db' do
|
60
|
-
languages = [
|
61
|
-
Language.create!(name: 'Spanish'),
|
62
|
-
Language.create!(name: 'English')
|
63
|
-
]
|
64
|
-
|
65
|
-
Language.first.delete
|
66
|
-
|
67
|
-
languages.each do |language|
|
68
|
-
File.exist?(language
|
69
|
-
end
|
70
|
-
|
71
|
-
ActiveGit.load_files
|
72
|
-
|
73
|
-
Language.count.should be 2
|
74
|
-
|
75
|
-
languages.each do |language|
|
76
|
-
language.reload.should be_a Language
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'Load single model files to db' do
|
81
|
-
language = Language.create! name: 'Spanish'
|
82
|
-
brand = Brand.create! name: 'Coca Cola'
|
83
|
-
|
84
|
-
File.exists?(language
|
85
|
-
File.exists?(brand
|
86
|
-
|
87
|
-
language.delete
|
88
|
-
brand.delete
|
89
|
-
|
90
|
-
ActiveGit.load_files Language
|
91
|
-
|
92
|
-
Language.find_by_id(language.id).should_not be_nil
|
93
|
-
Brand.find_by_id(brand.id).should be_nil
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'Git synchronization' do
|
99
|
-
|
100
|
-
it 'Commit all files' do
|
101
|
-
Language.create! name: 'Spanish'
|
102
|
-
|
103
|
-
ActiveGit.status.should_not be_empty
|
104
|
-
|
105
|
-
ActiveGit.commit_all 'Commit for test'
|
106
|
-
|
107
|
-
ActiveGit.status.should be_empty
|
108
|
-
|
109
|
-
ActiveGit.log.first.subject.should eq 'Commit for test'
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'Push and pull' do
|
113
|
-
bare = GitWrapper::Repository.new @file_helper.create_temp_folder
|
114
|
-
bare.init_bare
|
115
|
-
|
116
|
-
spanish = Language.create! name: 'Spanish'
|
117
|
-
english = Language.create! name: 'English'
|
118
|
-
ActiveGit.commit_all 'Local commit'
|
119
|
-
ActiveGit.add_remote 'bare', bare.location
|
120
|
-
ActiveGit.push 'bare'
|
121
|
-
|
122
|
-
remote = GitWrapper::Repository.new @file_helper.create_temp_folder
|
123
|
-
remote.init
|
124
|
-
remote.add_remote 'bare', bare.location
|
125
|
-
remote.pull 'bare'
|
126
|
-
|
127
|
-
to_json = Proc.new do |id, name|
|
128
|
-
JSON.pretty_generate id: id, name: name, created_at: Time.now, updated_at: Time.now
|
129
|
-
end
|
130
|
-
@file_helper.write_file "#{remote.location}/languages/#{spanish.id}.json", to_json.call(spanish.id, 'Spanish 2')
|
131
|
-
@file_helper.write_file "#{remote.location}/languages/888.json", to_json.call(888, 'Portuguese')
|
132
|
-
@file_helper.write_file "#{remote.location}/languages/999.json", to_json.call(999, 'French')
|
133
|
-
FileUtils.rm "#{remote.location}/languages/#{english.id}.json"
|
134
|
-
|
135
|
-
remote.add_all
|
136
|
-
remote.commit 'Remote commit'
|
137
|
-
remote.push 'bare'
|
138
|
-
|
139
|
-
Language.count.should eq 2
|
140
|
-
|
141
|
-
ActiveGit.pull('bare').should be_true
|
142
|
-
|
143
|
-
ActiveGit.log.first.subject.should eq 'Remote commit'
|
144
|
-
Language.count.should eq 3
|
145
|
-
['Spanish 2', 'Portuguese', 'French'].each do |lang_name|
|
146
|
-
File.exist?(Language.find_by_name(lang_name)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'Checkout' do
|
151
|
-
Language.create! name: 'Spanish'
|
152
|
-
Language.create! name: 'English'
|
153
|
-
|
154
|
-
ActiveGit.commit_all 'Commit 1'
|
155
|
-
ActiveGit.branch 'branch_test'
|
156
|
-
ActiveGit.checkout 'branch_test'
|
157
|
-
|
158
|
-
Language.first.destroy
|
159
|
-
ActiveGit.commit_all 'Commit 2'
|
160
|
-
|
161
|
-
Language.count.should eq 1
|
162
|
-
|
163
|
-
ActiveGit.checkout 'master'
|
164
|
-
|
165
|
-
Language.count.should eq 2
|
166
|
-
|
167
|
-
ActiveGit.checkout 'branch_test'
|
168
|
-
|
169
|
-
Language.count.should eq 1
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'Reset to specific commit' do
|
173
|
-
spanish = Language.create! name: 'Spanish'
|
174
|
-
ActiveGit.commit_all 'Commit 1'
|
175
|
-
|
176
|
-
english = Language.create! name: 'English'
|
177
|
-
ActiveGit.commit_all 'Commit 1'
|
178
|
-
|
179
|
-
Language.count.should eq 2
|
180
|
-
File.exist?(spanish
|
181
|
-
File.exist?(english
|
182
|
-
|
183
|
-
ActiveGit.reset ActiveGit.log.last.commit_hash
|
184
|
-
|
185
|
-
Language.count.should eq 1
|
186
|
-
File.exist?(spanish
|
187
|
-
File.exist?(english
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'Reset to HEAD' do
|
191
|
-
spanish = Language.create! name: 'Spanish'
|
192
|
-
ActiveGit.commit_all 'Commit 1'
|
193
|
-
|
194
|
-
english = Language.create! name: 'English'
|
195
|
-
|
196
|
-
Language.count.should eq 2
|
197
|
-
File.exist?(spanish
|
198
|
-
File.exist?(english
|
199
|
-
|
200
|
-
ActiveGit.reset
|
201
|
-
|
202
|
-
Language.count.should eq 1
|
203
|
-
File.exist?(spanish
|
204
|
-
File.exist?(english
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'Resolve version conflicts' do
|
208
|
-
bare = GitWrapper::Repository.new @file_helper.create_temp_folder
|
209
|
-
bare.init_bare
|
210
|
-
|
211
|
-
ActiveGit.add_remote 'bare', bare.location
|
212
|
-
|
213
|
-
spanish = Language.create! name: 'Spanish'
|
214
|
-
|
215
|
-
ActiveGit.commit_all 'Commit v1'
|
216
|
-
ActiveGit.push 'bare'
|
217
|
-
|
218
|
-
other_repo = GitWrapper::Repository.new @file_helper.create_temp_folder
|
219
|
-
other_repo.init
|
220
|
-
other_repo.add_remote 'bare', bare.location
|
221
|
-
other_repo.pull 'bare'
|
222
|
-
|
223
|
-
@file_helper.write_file "#{other_repo.location}/languages/#{spanish.id}.json",
|
224
|
-
JSON.pretty_generate(id: spanish.id, name: 'Spanish 2', created_at: Time.now, updated_at: Time.now)
|
225
|
-
|
226
|
-
other_repo.add_all
|
227
|
-
other_repo.commit 'Commit v2'
|
228
|
-
other_repo.push 'bare'
|
229
|
-
|
230
|
-
spanish.update_attributes name: 'Spanish 3'
|
231
|
-
ActiveGit.commit 'Commit v3'
|
232
|
-
|
233
|
-
ActiveGit.pull 'bare'
|
234
|
-
|
235
|
-
spanish.reload.name.should eq 'Spanish 3'
|
236
|
-
|
237
|
-
ActiveGit.log.should have(4).items
|
238
|
-
ActiveGit.log[0].subject.should eq 'Resolve conflicts'
|
239
|
-
ActiveGit.log[1].subject.should eq 'Commit v3'
|
240
|
-
ActiveGit.log[2].subject.should eq 'Commit v2'
|
241
|
-
ActiveGit.log[3].subject.should eq 'Commit v1'
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveGit::Commands do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@file_helper = FileHelper.new
|
7
|
+
ActiveGit.configuration.working_path = @file_helper.create_temp_folder
|
8
|
+
ActiveGit.init
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
@file_helper.remove_temp_folders
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'Dump and load' do
|
16
|
+
|
17
|
+
it 'Dump complete db to files' do
|
18
|
+
languages = [
|
19
|
+
Language.create!(name: 'Spanish'),
|
20
|
+
Language.create!(name: 'English')
|
21
|
+
]
|
22
|
+
|
23
|
+
@file_helper.write_file "#{ActiveGit.configuration.working_path}/test.txt", 'test'
|
24
|
+
@file_helper.write_file "#{git_dirname(Language)}/0.json", 'test'
|
25
|
+
|
26
|
+
ActiveGit.dump_db
|
27
|
+
|
28
|
+
File.exist?("#{ActiveGit.configuration.working_path}/test.txt").should be_false
|
29
|
+
|
30
|
+
Dir.glob("#{git_dirname(Language)}/*.json").should have(2).items
|
31
|
+
|
32
|
+
languages.each do |language|
|
33
|
+
File.exist?(git_filename(language)).should be_true
|
34
|
+
json = JSON.parse(@file_helper.read_file(git_filename(language)))
|
35
|
+
json['id'].should eq language.id
|
36
|
+
json['name'].should eq language.name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'Dump single table to files' do
|
41
|
+
language = Language.create! name: 'Spanish'
|
42
|
+
country = Country.create! name: 'Argentina'
|
43
|
+
|
44
|
+
Dir["#{ActiveGit.configuration.working_path}/*"].each { |f| FileUtils.rm_rf f }
|
45
|
+
|
46
|
+
Dir.exists?("#{ActiveGit.configuration.working_path}/languages").should be_false
|
47
|
+
File.exists?("#{ActiveGit.configuration.working_path}/languages/#{language.id}.json").should be_false
|
48
|
+
Dir.exists?("#{ActiveGit.configuration.working_path}/countries").should be_false
|
49
|
+
File.exists?("#{ActiveGit.configuration.working_path}/countries/#{country.id}.json").should be_false
|
50
|
+
|
51
|
+
ActiveGit.dump_db Language
|
52
|
+
|
53
|
+
Dir.exists?("#{ActiveGit.configuration.working_path}/languages").should be_true
|
54
|
+
File.exists?("#{ActiveGit.configuration.working_path}/languages/#{language.id}.json").should be_true
|
55
|
+
Dir.exists?("#{ActiveGit.configuration.working_path}/countries").should be_false
|
56
|
+
File.exists?("#{ActiveGit.configuration.working_path}/countries/#{country.id}.json").should be_false
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'Load all files to db' do
|
60
|
+
languages = [
|
61
|
+
Language.create!(name: 'Spanish'),
|
62
|
+
Language.create!(name: 'English')
|
63
|
+
]
|
64
|
+
|
65
|
+
Language.first.delete
|
66
|
+
|
67
|
+
languages.each do |language|
|
68
|
+
File.exist?(git_filename(language)).should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
ActiveGit.load_files
|
72
|
+
|
73
|
+
Language.count.should be 2
|
74
|
+
|
75
|
+
languages.each do |language|
|
76
|
+
language.reload.should be_a Language
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'Load single model files to db' do
|
81
|
+
language = Language.create! name: 'Spanish'
|
82
|
+
brand = Brand.create! name: 'Coca Cola'
|
83
|
+
|
84
|
+
File.exists?(git_filename(language)).should be_true
|
85
|
+
File.exists?(git_filename(brand)).should be_true
|
86
|
+
|
87
|
+
language.delete
|
88
|
+
brand.delete
|
89
|
+
|
90
|
+
ActiveGit.load_files Language
|
91
|
+
|
92
|
+
Language.find_by_id(language.id).should_not be_nil
|
93
|
+
Brand.find_by_id(brand.id).should be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'Git synchronization' do
|
99
|
+
|
100
|
+
it 'Commit all files' do
|
101
|
+
Language.create! name: 'Spanish'
|
102
|
+
|
103
|
+
ActiveGit.status.should_not be_empty
|
104
|
+
|
105
|
+
ActiveGit.commit_all 'Commit for test'
|
106
|
+
|
107
|
+
ActiveGit.status.should be_empty
|
108
|
+
|
109
|
+
ActiveGit.log.first.subject.should eq 'Commit for test'
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'Push and pull' do
|
113
|
+
bare = GitWrapper::Repository.new @file_helper.create_temp_folder
|
114
|
+
bare.init_bare
|
115
|
+
|
116
|
+
spanish = Language.create! name: 'Spanish'
|
117
|
+
english = Language.create! name: 'English'
|
118
|
+
ActiveGit.commit_all 'Local commit'
|
119
|
+
ActiveGit.add_remote 'bare', bare.location
|
120
|
+
ActiveGit.push 'bare'
|
121
|
+
|
122
|
+
remote = GitWrapper::Repository.new @file_helper.create_temp_folder
|
123
|
+
remote.init
|
124
|
+
remote.add_remote 'bare', bare.location
|
125
|
+
remote.pull 'bare'
|
126
|
+
|
127
|
+
to_json = Proc.new do |id, name|
|
128
|
+
JSON.pretty_generate id: id, name: name, created_at: Time.now, updated_at: Time.now
|
129
|
+
end
|
130
|
+
@file_helper.write_file "#{remote.location}/languages/#{spanish.id}.json", to_json.call(spanish.id, 'Spanish 2')
|
131
|
+
@file_helper.write_file "#{remote.location}/languages/888.json", to_json.call(888, 'Portuguese')
|
132
|
+
@file_helper.write_file "#{remote.location}/languages/999.json", to_json.call(999, 'French')
|
133
|
+
FileUtils.rm "#{remote.location}/languages/#{english.id}.json"
|
134
|
+
|
135
|
+
remote.add_all
|
136
|
+
remote.commit 'Remote commit'
|
137
|
+
remote.push 'bare'
|
138
|
+
|
139
|
+
Language.count.should eq 2
|
140
|
+
|
141
|
+
ActiveGit.pull('bare').should be_true
|
142
|
+
|
143
|
+
ActiveGit.log.first.subject.should eq 'Remote commit'
|
144
|
+
Language.count.should eq 3
|
145
|
+
['Spanish 2', 'Portuguese', 'French'].each do |lang_name|
|
146
|
+
File.exist?(git_filename(Language.find_by_name(lang_name))).should be_true
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'Checkout' do
|
151
|
+
Language.create! name: 'Spanish'
|
152
|
+
Language.create! name: 'English'
|
153
|
+
|
154
|
+
ActiveGit.commit_all 'Commit 1'
|
155
|
+
ActiveGit.branch 'branch_test'
|
156
|
+
ActiveGit.checkout 'branch_test'
|
157
|
+
|
158
|
+
Language.first.destroy
|
159
|
+
ActiveGit.commit_all 'Commit 2'
|
160
|
+
|
161
|
+
Language.count.should eq 1
|
162
|
+
|
163
|
+
ActiveGit.checkout 'master'
|
164
|
+
|
165
|
+
Language.count.should eq 2
|
166
|
+
|
167
|
+
ActiveGit.checkout 'branch_test'
|
168
|
+
|
169
|
+
Language.count.should eq 1
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'Reset to specific commit' do
|
173
|
+
spanish = Language.create! name: 'Spanish'
|
174
|
+
ActiveGit.commit_all 'Commit 1'
|
175
|
+
|
176
|
+
english = Language.create! name: 'English'
|
177
|
+
ActiveGit.commit_all 'Commit 1'
|
178
|
+
|
179
|
+
Language.count.should eq 2
|
180
|
+
File.exist?(git_filename(spanish)).should be_true
|
181
|
+
File.exist?(git_filename(english)).should be_true
|
182
|
+
|
183
|
+
ActiveGit.reset ActiveGit.log.last.commit_hash
|
184
|
+
|
185
|
+
Language.count.should eq 1
|
186
|
+
File.exist?(git_filename(spanish)).should be_true
|
187
|
+
File.exist?(git_filename(english)).should be_false
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'Reset to HEAD' do
|
191
|
+
spanish = Language.create! name: 'Spanish'
|
192
|
+
ActiveGit.commit_all 'Commit 1'
|
193
|
+
|
194
|
+
english = Language.create! name: 'English'
|
195
|
+
|
196
|
+
Language.count.should eq 2
|
197
|
+
File.exist?(git_filename(spanish)).should be_true
|
198
|
+
File.exist?(git_filename(english)).should be_true
|
199
|
+
|
200
|
+
ActiveGit.reset
|
201
|
+
|
202
|
+
Language.count.should eq 1
|
203
|
+
File.exist?(git_filename(spanish)).should be_true
|
204
|
+
File.exist?(git_filename(english)).should be_false
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'Resolve version conflicts' do
|
208
|
+
bare = GitWrapper::Repository.new @file_helper.create_temp_folder
|
209
|
+
bare.init_bare
|
210
|
+
|
211
|
+
ActiveGit.add_remote 'bare', bare.location
|
212
|
+
|
213
|
+
spanish = Language.create! name: 'Spanish'
|
214
|
+
|
215
|
+
ActiveGit.commit_all 'Commit v1'
|
216
|
+
ActiveGit.push 'bare'
|
217
|
+
|
218
|
+
other_repo = GitWrapper::Repository.new @file_helper.create_temp_folder
|
219
|
+
other_repo.init
|
220
|
+
other_repo.add_remote 'bare', bare.location
|
221
|
+
other_repo.pull 'bare'
|
222
|
+
|
223
|
+
@file_helper.write_file "#{other_repo.location}/languages/#{spanish.id}.json",
|
224
|
+
JSON.pretty_generate(id: spanish.id, name: 'Spanish 2', created_at: Time.now, updated_at: Time.now)
|
225
|
+
|
226
|
+
other_repo.add_all
|
227
|
+
other_repo.commit 'Commit v2'
|
228
|
+
other_repo.push 'bare'
|
229
|
+
|
230
|
+
spanish.update_attributes name: 'Spanish 3'
|
231
|
+
ActiveGit.commit 'Commit v3'
|
232
|
+
|
233
|
+
ActiveGit.pull 'bare'
|
234
|
+
|
235
|
+
spanish.reload.name.should eq 'Spanish 3'
|
236
|
+
|
237
|
+
ActiveGit.log.should have(4).items
|
238
|
+
ActiveGit.log[0].subject.should eq 'Resolve conflicts'
|
239
|
+
ActiveGit.log[1].subject.should eq 'Commit v3'
|
240
|
+
ActiveGit.log[2].subject.should eq 'Commit v2'
|
241
|
+
ActiveGit.log[3].subject.should eq 'Commit v1'
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
246
|
end
|