active_git 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_git.rb +3 -2
- data/lib/active_git/configuration.rb +6 -0
- data/lib/active_git/events/db_event.rb +2 -2
- data/lib/active_git/synchronizer.rb +7 -6
- data/lib/active_git/version.rb +1 -1
- data/spec/configuration_spec.rb +63 -0
- data/spec/inflector_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -3
- data/spec/synchronization_spec.rb +25 -0
- metadata +4 -8
data/lib/active_git.rb
CHANGED
@@ -21,7 +21,7 @@ module ActiveGit
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def data
|
24
|
-
json = File.open(@file_name, 'r') { |f| f.
|
24
|
+
json = File.open(@file_name, 'r') { |f| f.read }
|
25
25
|
model.from_json(json)
|
26
26
|
end
|
27
27
|
|
@@ -38,4 +38,4 @@ module ActiveGit
|
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
@@ -15,9 +15,11 @@ module ActiveGit
|
|
15
15
|
if bulk_inserts.any?
|
16
16
|
define_job do
|
17
17
|
bulk_inserts.each do |model, records|
|
18
|
-
ActiveGit.configuration.
|
19
|
-
|
20
|
-
|
18
|
+
records.each_slice(ActiveGit.configuration.sync_batch_size) do |batch_records|
|
19
|
+
ActiveGit.configuration.logger.debug "[ActiveGit] Inserting #{model.model_name} models"
|
20
|
+
import_result = model.import batch_records, timestamps: false, validate: false
|
21
|
+
raise SynchronizationError.new(import_result.failed_instances) unless import_result.failed_instances.empty?
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -30,18 +32,17 @@ module ActiveGit
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def bulk_insert(data)
|
33
|
-
bulk_inserts[data.class] ||= [] unless bulk_inserts.has_key? data.class
|
34
35
|
bulk_inserts[data.class] << data
|
35
36
|
end
|
36
37
|
|
37
38
|
def define_job(&block)
|
38
|
-
jobs <<
|
39
|
+
jobs << block
|
39
40
|
end
|
40
41
|
|
41
42
|
private
|
42
43
|
|
43
44
|
def bulk_inserts
|
44
|
-
@bulk_inserts ||= {}
|
45
|
+
@bulk_inserts ||= Hash.new{|h,k| h[k] = []}
|
45
46
|
end
|
46
47
|
|
47
48
|
def jobs
|
data/lib/active_git/version.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveGit::Configuration do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@working_path = ActiveGit.configuration.working_path
|
7
|
+
@bare_path = ActiveGit.configuration.bare_path
|
8
|
+
@logger = ActiveGit.configuration.logger
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
ActiveGit.configuration.working_path = @working_path
|
13
|
+
ActiveGit.configuration.bare_path = @bare_path
|
14
|
+
ActiveGit.configuration.logger = @logger
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'default sync_batch_size' do
|
18
|
+
ActiveGit.configuration.sync_batch_size.should eq 10000
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'set sync_batch_size' do
|
22
|
+
ActiveGit.configuration.sync_batch_size = 100
|
23
|
+
ActiveGit.configuration.sync_batch_size.should eq 100
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'set working_path with string' do
|
27
|
+
ActiveGit.configuration.working_path = "/path_to_test"
|
28
|
+
ActiveGit.configuration.working_path.should eq "/path_to_test"
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'set working_path with block' do
|
32
|
+
ActiveGit.configuration.working_path = lambda do
|
33
|
+
path_home = '/home'
|
34
|
+
"#{path_home}/path_to_test"
|
35
|
+
end
|
36
|
+
ActiveGit.configuration.working_path.should eq "/home/path_to_test"
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'set bare_path with string' do
|
40
|
+
ActiveGit.configuration.bare_path = "/path_to_test"
|
41
|
+
ActiveGit.configuration.bare_path.should eq "/path_to_test"
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'set bare_path with block' do
|
45
|
+
ActiveGit.configuration.bare_path = lambda do
|
46
|
+
path_home = '/home'
|
47
|
+
"#{path_home}/path_to_test"
|
48
|
+
end
|
49
|
+
ActiveGit.configuration.bare_path.should eq "/home/path_to_test"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'get default logger' do
|
53
|
+
ActiveGit.configuration.logger.should be_a Logger
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'set logger' do
|
57
|
+
logger = Logger.new($stdout)
|
58
|
+
ActiveGit.configuration.logger.should_not eq logger
|
59
|
+
ActiveGit.configuration.logger = logger
|
60
|
+
ActiveGit.configuration.logger.should eq logger
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/spec/inflector_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe ActiveGit::Inflector do
|
|
35
35
|
ActiveGit::Inflector.model("#{working_path}/countries/1.json", working_path).should be Country
|
36
36
|
end
|
37
37
|
|
38
|
-
it '
|
38
|
+
it 'Nested model from filename' do
|
39
39
|
ActiveGit::Inflector.model("#{working_path}/crm/customers/1.json", working_path).should be Crm::Customer
|
40
40
|
end
|
41
41
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,11 +4,14 @@ require 'logger'
|
|
4
4
|
|
5
5
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
6
6
|
|
7
|
-
ActiveRecord::Base.logger = Logger.new($stdout)
|
8
|
-
ActiveRecord::Base.logger.level = Logger::Severity::ERROR
|
9
7
|
ActiveRecord::Migrator.migrations_path = "#{File.dirname(__FILE__)}/migrations"
|
8
|
+
ActiveRecord::Migration.verbose = false
|
10
9
|
|
11
|
-
|
10
|
+
logger = Logger.new($stdout)
|
11
|
+
logger.level = Logger::Severity::FATAL
|
12
|
+
|
13
|
+
ActiveRecord::Base.logger = logger
|
14
|
+
ActiveGit.configuration.logger = logger
|
12
15
|
|
13
16
|
module InflectorHelper
|
14
17
|
def git_dirname(model, working_path=nil)
|
@@ -96,6 +96,31 @@ describe ActiveGit::Synchronizer do
|
|
96
96
|
Country.find_by_id(country.id).should be_nil
|
97
97
|
end
|
98
98
|
|
99
|
+
it 'Batch size' do
|
100
|
+
ActiveGit.configuration.sync_batch_size = 2
|
101
|
+
|
102
|
+
working_path = @file_helper.create_temp_folder
|
103
|
+
|
104
|
+
countries = 10.times.map do |i|
|
105
|
+
Country.new(name: "Country #{i}") do |country|
|
106
|
+
country.id = i.to_s
|
107
|
+
country.created_at = Time.now
|
108
|
+
country.updated_at = Time.now
|
109
|
+
end
|
110
|
+
end
|
111
|
+
ActiveGit::Synchronizer.synchronize countries.map {|c| ActiveGit::FileSave.new(c, working_path)}
|
112
|
+
|
113
|
+
events = countries.map do |country|
|
114
|
+
ActiveGit::DbCreate.new(ActiveGit::Inflector.filename(country, working_path), working_path)
|
115
|
+
end
|
116
|
+
|
117
|
+
Country.should_receive(:import).
|
118
|
+
exactly(5).times.
|
119
|
+
and_return(double(failed_instances: []))
|
120
|
+
|
121
|
+
ActiveGit::Synchronizer.synchronize events
|
122
|
+
end
|
123
|
+
|
99
124
|
end
|
100
125
|
|
101
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
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: 2013-08-
|
12
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- spec/active_record_extension_spec.rb
|
207
207
|
- spec/batch_synchronization_spec.rb
|
208
208
|
- spec/commands_spec.rb
|
209
|
+
- spec/configuration_spec.rb
|
209
210
|
- spec/coverage_helper.rb
|
210
211
|
- spec/inflector_spec.rb
|
211
212
|
- spec/migrations/20121004135939_create_countries.rb
|
@@ -231,18 +232,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
232
|
- - ! '>='
|
232
233
|
- !ruby/object:Gem::Version
|
233
234
|
version: '0'
|
234
|
-
segments:
|
235
|
-
- 0
|
236
|
-
hash: -181325600156632224
|
237
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
236
|
none: false
|
239
237
|
requirements:
|
240
238
|
- - ! '>='
|
241
239
|
- !ruby/object:Gem::Version
|
242
240
|
version: '0'
|
243
|
-
segments:
|
244
|
-
- 0
|
245
|
-
hash: -181325600156632224
|
246
241
|
requirements: []
|
247
242
|
rubyforge_project:
|
248
243
|
rubygems_version: 1.8.25
|
@@ -253,6 +248,7 @@ test_files:
|
|
253
248
|
- spec/active_record_extension_spec.rb
|
254
249
|
- spec/batch_synchronization_spec.rb
|
255
250
|
- spec/commands_spec.rb
|
251
|
+
- spec/configuration_spec.rb
|
256
252
|
- spec/coverage_helper.rb
|
257
253
|
- spec/inflector_spec.rb
|
258
254
|
- spec/migrations/20121004135939_create_countries.rb
|