mass_insert 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/mass_insert/adapters.rb +0 -1
- data/lib/mass_insert/adapters/adapter.rb +1 -7
- data/lib/mass_insert/adapters/column_value.rb +33 -29
- data/lib/mass_insert/adapters/helpers.rb +3 -2
- data/lib/mass_insert/adapters/helpers/abstract_query.rb +48 -0
- data/lib/mass_insert/adapters/helpers/sanitizer.rb +6 -0
- data/lib/mass_insert/adapters/mysql2_adapter.rb +1 -1
- data/lib/mass_insert/base.rb +49 -20
- data/lib/mass_insert/query_builder.rb +6 -6
- data/lib/mass_insert/version.rb +1 -1
- data/spec/active_record_dummy/Gemfile +1 -1
- data/spec/active_record_dummy/config/database.yml +1 -1
- data/spec/mass_insert/adapters/adapter_spec.rb +23 -45
- data/spec/mass_insert/adapters/column_value_spec.rb +107 -154
- data/spec/mass_insert/adapters/{abstract_query_spec.rb → helpers/abstract_query_spec.rb} +23 -27
- data/spec/mass_insert/adapters/helpers/sanitizer_spec.rb +16 -9
- data/spec/mass_insert/adapters/helpers/timestamp_spec.rb +11 -15
- data/spec/mass_insert/adapters/helpers_spec.rb +7 -3
- data/spec/mass_insert/adapters/mysql_adapter_spec.rb +6 -10
- data/spec/mass_insert/adapters/postgresql_adapter_spec.rb +4 -8
- data/spec/mass_insert/adapters/sqlite3_adapter_spec.rb +24 -30
- data/spec/mass_insert/adapters/sqlserver_adapter_spec.rb +16 -21
- data/spec/mass_insert/adapters_spec.rb +8 -12
- data/spec/mass_insert/base_spec.rb +13 -13
- data/spec/mass_insert/process_control_spec.rb +33 -40
- data/spec/mass_insert/query_builder_spec.rb +20 -24
- data/spec/mass_insert/query_execution_spec.rb +13 -16
- data/spec/mass_insert_spec.rb +6 -6
- metadata +7 -7
- data/lib/mass_insert/adapters/abstract_query.rb +0 -47
@@ -2,12 +2,7 @@ require './spec/spec_helper'
|
|
2
2
|
require "./lib/mass_insert"
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::Helpers::Sanitizer do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
@adapter = MassInsert::Adapters::Adapter.new([], {})
|
8
|
-
end
|
9
|
-
|
10
|
-
subject{ @adapter }
|
5
|
+
let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
|
11
6
|
|
12
7
|
describe "#sanitized_columns" do
|
13
8
|
before :each do
|
@@ -20,20 +15,32 @@ describe MassInsert::Adapters::Helpers::Sanitizer do
|
|
20
15
|
end
|
21
16
|
|
22
17
|
it "should respond to sanitized_columns" do
|
23
|
-
subject.respond_to
|
18
|
+
expect(subject).to respond_to(:sanitized_columns)
|
24
19
|
end
|
25
20
|
|
26
21
|
context "when primary_key_mode is automatic" do
|
27
22
|
it "should returns the column without primary_key" do
|
28
|
-
subject.sanitized_columns.
|
23
|
+
expect(subject.sanitized_columns).to eq([:name])
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
32
27
|
context "when primary_key_mode is not automatic" do
|
33
28
|
it "should returns the columns including primary_key" do
|
34
29
|
subject.options.merge!(:primary_key_mode => :manual)
|
35
|
-
subject.sanitized_columns.
|
30
|
+
expect(subject.sanitized_columns).to eq([:id, :name])
|
36
31
|
end
|
37
32
|
end
|
38
33
|
end
|
34
|
+
|
35
|
+
describe "#table_columns" do
|
36
|
+
it "should respond to table_columns method" do
|
37
|
+
expect(subject).to respond_to(:table_columns)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should returns the table_columns in ActiveRecord class" do
|
41
|
+
subject.options = {:class_name => Test}
|
42
|
+
columns = [:id, :name, :email]
|
43
|
+
expect(subject.table_columns).to eq(columns)
|
44
|
+
end
|
45
|
+
end
|
39
46
|
end
|
@@ -2,57 +2,53 @@ require './spec/spec_helper'
|
|
2
2
|
require "./lib/mass_insert"
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::Helpers::Timestamp do
|
5
|
-
|
6
|
-
@adapter = MassInsert::Adapters::Adapter.new([], {})
|
7
|
-
end
|
8
|
-
|
9
|
-
subject{ @adapter }
|
5
|
+
let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
|
10
6
|
|
11
7
|
describe "#timestamp?" do
|
12
8
|
it "should respond_to timestamp? method" do
|
13
|
-
subject.respond_to
|
9
|
+
expect(subject).to respond_to(:timestamp?)
|
14
10
|
end
|
15
11
|
|
16
12
|
context "when respond to timestamp columns" do
|
17
13
|
it "should return true" do
|
18
14
|
subject.stub(:column_names).and_return([:updated_at, :created_at])
|
19
|
-
subject.timestamp
|
15
|
+
expect(subject.timestamp?).to be_true
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
19
|
context "when not respond to timestamp columns" do
|
24
20
|
it "should return false" do
|
25
21
|
subject.stub(:column_names).and_return([:created_at])
|
26
|
-
subject.timestamp
|
22
|
+
expect(subject.timestamp?).to be_false
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
27
|
describe "#timestamp_format" do
|
32
28
|
it "should respond_to timestamp_format method" do
|
33
|
-
subject.respond_to
|
29
|
+
expect(subject).to respond_to(:timestamp_format)
|
34
30
|
end
|
35
31
|
|
36
32
|
it "should return the default timestamp format" do
|
37
|
-
subject.timestamp_format.
|
33
|
+
expect(subject.timestamp_format).to eq("%Y-%m-%d %H:%M:%S.%6N")
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
37
|
describe "#timestamp" do
|
42
38
|
it "should respond_to timestamp method" do
|
43
|
-
subject.respond_to
|
39
|
+
expect(subject).to respond_to(:timestamp)
|
44
40
|
end
|
45
41
|
|
46
42
|
it "should return the default timestamp value with correct format" do
|
47
43
|
subject.stub(:timestamp_format).and_return("%Y-%m-%d %H:%M:%S")
|
48
44
|
timestamp_value = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
49
|
-
subject.timestamp.
|
45
|
+
expect(subject.timestamp).to eq(timestamp_value)
|
50
46
|
end
|
51
47
|
end
|
52
48
|
|
53
49
|
describe "#timestamp_values" do
|
54
50
|
it "should respond_to timestamp_values method" do
|
55
|
-
subject.respond_to
|
51
|
+
expect(subject).to respond_to(:timestamp_values)
|
56
52
|
end
|
57
53
|
|
58
54
|
context "when have high precision" do
|
@@ -61,7 +57,7 @@ describe MassInsert::Adapters::Helpers::Timestamp do
|
|
61
57
|
:created_at => subject.timestamp,
|
62
58
|
:updated_at => subject.timestamp
|
63
59
|
}
|
64
|
-
subject.timestamp_values.
|
60
|
+
expect(subject.timestamp_values).not_to eq(timestamp_values)
|
65
61
|
end
|
66
62
|
end
|
67
63
|
|
@@ -72,7 +68,7 @@ describe MassInsert::Adapters::Helpers::Timestamp do
|
|
72
68
|
:created_at => subject.timestamp,
|
73
69
|
:updated_at => subject.timestamp
|
74
70
|
}
|
75
|
-
subject.timestamp_values.
|
71
|
+
expect(subject.timestamp_values).to eq(timestamp_values)
|
76
72
|
end
|
77
73
|
end
|
78
74
|
end
|
@@ -3,14 +3,18 @@ require "./lib/mass_insert"
|
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::Helpers do
|
5
5
|
it 'should be defined' do
|
6
|
-
|
6
|
+
expect(MassInsert::Adapters::Helpers).to be
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should define AbstractQuery class' do
|
10
|
+
expect(MassInsert::Adapters::Helpers::AbstractQuery).to be
|
7
11
|
end
|
8
12
|
|
9
13
|
it 'should define Timestamp module' do
|
10
|
-
MassInsert::Adapters::Helpers::Timestamp.
|
14
|
+
expect(MassInsert::Adapters::Helpers::Timestamp).to be
|
11
15
|
end
|
12
16
|
|
13
17
|
it 'should define Sanitizer module' do
|
14
|
-
MassInsert::Adapters::Helpers::Sanitizer.
|
18
|
+
expect(MassInsert::Adapters::Helpers::Sanitizer).to be
|
15
19
|
end
|
16
20
|
end
|
@@ -2,37 +2,33 @@ require './spec/spec_helper'
|
|
2
2
|
require "./lib/mass_insert"
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::Mysql2Adapter do
|
5
|
-
|
6
|
-
@adapter = MassInsert::Adapters::Mysql2Adapter.new([], {})
|
7
|
-
end
|
8
|
-
|
9
|
-
subject{ @adapter }
|
5
|
+
let!(:subject){ MassInsert::Adapters::Mysql2Adapter.new([], {}) }
|
10
6
|
|
11
7
|
it "should inherit from Adapter class" do
|
12
|
-
subject.
|
8
|
+
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
13
9
|
end
|
14
10
|
|
15
11
|
describe "instance methods" do
|
16
12
|
describe "#timestamp_format" do
|
17
13
|
it "should respond to timestamp_format method" do
|
18
|
-
subject.respond_to
|
14
|
+
expect(subject).to respond_to(:timestamp_format)
|
19
15
|
end
|
20
16
|
|
21
17
|
it "should return the format string" do
|
22
|
-
subject.timestamp_format.
|
18
|
+
expect(subject.timestamp_format).to eq("%Y-%m-%d %H:%M:%S")
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
26
22
|
describe "#execute" do
|
27
23
|
it "should respond to execute method" do
|
28
|
-
subject.respond_to
|
24
|
+
expect(subject).to respond_to(:execute)
|
29
25
|
end
|
30
26
|
|
31
27
|
it "call methods and returns their values concatenated" do
|
32
28
|
subject.stub(:begin_string).and_return("a")
|
33
29
|
subject.stub(:string_columns).and_return("b")
|
34
30
|
subject.stub(:string_values).and_return("c")
|
35
|
-
subject.execute.
|
31
|
+
expect(subject.execute).to eq("abc")
|
36
32
|
end
|
37
33
|
end
|
38
34
|
end
|
@@ -2,27 +2,23 @@ require './spec/spec_helper'
|
|
2
2
|
require "./lib/mass_insert"
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::PostgreSQLAdapter do
|
5
|
-
|
6
|
-
@adapter = MassInsert::Adapters::PostgreSQLAdapter.new([], {})
|
7
|
-
end
|
8
|
-
|
9
|
-
subject{ @adapter }
|
5
|
+
let!(:subject){ MassInsert::Adapters::PostgreSQLAdapter.new([], {}) }
|
10
6
|
|
11
7
|
it "should inherit from Adapter class" do
|
12
|
-
subject.
|
8
|
+
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
13
9
|
end
|
14
10
|
|
15
11
|
describe "instance methods" do
|
16
12
|
describe "#execute" do
|
17
13
|
it "should respond to execute method" do
|
18
|
-
subject.respond_to
|
14
|
+
expect(subject).to respond_to(:execute)
|
19
15
|
end
|
20
16
|
|
21
17
|
it "call methods and returns their values concatenated" do
|
22
18
|
subject.stub(:begin_string).and_return("a")
|
23
19
|
subject.stub(:string_columns).and_return("b")
|
24
20
|
subject.stub(:string_values).and_return("c")
|
25
|
-
subject.execute.
|
21
|
+
expect(subject.execute).to eq("abc")
|
26
22
|
end
|
27
23
|
end
|
28
24
|
end
|
@@ -2,89 +2,83 @@ require './spec/spec_helper'
|
|
2
2
|
require "./lib/mass_insert"
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::SQLite3Adapter do
|
5
|
-
|
6
|
-
@adapter = MassInsert::Adapters::SQLite3Adapter.new([], {})
|
7
|
-
end
|
8
|
-
|
9
|
-
subject{ @adapter }
|
5
|
+
let!(:subject){ MassInsert::Adapters::SQLite3Adapter.new([], {}) }
|
10
6
|
|
11
7
|
it "should inherit from Adapter class" do
|
12
|
-
subject.
|
8
|
+
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
13
9
|
end
|
14
10
|
|
15
11
|
describe "instance methods" do
|
16
12
|
describe "#string_values" do
|
17
13
|
it "should respond to string_values method" do
|
18
|
-
subject.respond_to
|
14
|
+
expect(subject).to respond_to(:string_values)
|
19
15
|
end
|
20
16
|
|
21
17
|
it "should returns correct string to values" do
|
22
|
-
subject.stub(:string_rows_values).and_return("
|
23
|
-
subject.string_values.
|
18
|
+
subject.stub(:string_rows_values).and_return("rows_values")
|
19
|
+
expect(subject.string_values).to eq("SELECT rows_values;")
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
23
|
describe "#string_rows_values" do
|
28
24
|
it "should respond to string_rows_values method" do
|
29
|
-
subject.respond_to
|
25
|
+
expect(subject).to respond_to(:string_rows_values)
|
30
26
|
end
|
31
27
|
|
32
28
|
context "when only have one value hash" do
|
33
29
|
it "should returns the correct string" do
|
34
|
-
subject.stub(:string_single_row_values).and_return("
|
30
|
+
subject.stub(:string_single_row_values).and_return("row")
|
35
31
|
subject.values = [{}]
|
36
|
-
subject.string_rows_values.
|
32
|
+
expect(subject.string_rows_values).to eq("row")
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
40
36
|
context "when have two or more value hashes" do
|
41
37
|
it "should returns the correct string" do
|
42
|
-
subject.stub(:string_single_row_values).and_return("
|
38
|
+
subject.stub(:string_single_row_values).and_return("row")
|
43
39
|
subject.values = [{}, {}]
|
44
|
-
|
45
|
-
subject.string_rows_values.should eq(string)
|
40
|
+
expect(subject.string_rows_values).to eq("row UNION SELECT row")
|
46
41
|
end
|
47
42
|
end
|
48
43
|
end
|
49
44
|
|
50
45
|
describe "#execute" do
|
46
|
+
before :each do
|
47
|
+
subject.stub(:begin_string).and_return("a")
|
48
|
+
subject.stub(:string_columns).and_return("b")
|
49
|
+
subject.stub(:string_values).and_return("c")
|
50
|
+
end
|
51
|
+
|
51
52
|
it "should respond to execute method" do
|
52
|
-
subject.respond_to
|
53
|
+
expect(subject).to respond_to(:execute)
|
53
54
|
end
|
54
55
|
|
55
56
|
context "when have less than 500 values" do
|
56
57
|
it "call methods and returns their values concatenated" do
|
57
58
|
subject.values = [{}]
|
58
|
-
subject.
|
59
|
-
subject.stub(:string_columns).and_return("b")
|
60
|
-
subject.stub(:string_values).and_return("c")
|
61
|
-
subject.execute.should eq(["abc"])
|
59
|
+
expect(subject.execute).to eq(["abc"])
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
65
63
|
context "when have more than 500 values" do
|
66
64
|
it "call methods and returns their values concatenated" do
|
67
|
-
subject.values = []
|
68
65
|
800.times{ subject.values << {} }
|
69
|
-
subject.
|
70
|
-
subject.stub(:string_columns).and_return("b")
|
71
|
-
subject.stub(:string_values).and_return("c")
|
72
|
-
subject.execute.should eq(["abc", "abc"])
|
66
|
+
expect(subject.execute).to eq(["abc", "abc"])
|
73
67
|
end
|
74
68
|
end
|
75
69
|
end
|
76
70
|
end
|
77
71
|
|
78
72
|
describe "MAX_VALUES_PER_INSERTION" do
|
73
|
+
let(:class_name){ MassInsert::Adapters::SQLite3Adapter }
|
74
|
+
|
79
75
|
it "should respond_to" do
|
80
|
-
|
81
|
-
constant
|
82
|
-
class_name.const_defined?(constant).should be_true
|
76
|
+
constant = :MAX_VALUES_PER_INSERTION
|
77
|
+
expect(class_name.const_defined?(constant)).to be_true
|
83
78
|
end
|
84
79
|
|
85
80
|
it "should return 1000" do
|
86
|
-
class_name
|
87
|
-
class_name::MAX_VALUES_PER_INSERTION.should eq(500)
|
81
|
+
expect(class_name::MAX_VALUES_PER_INSERTION).to eq(500)
|
88
82
|
end
|
89
83
|
end
|
90
84
|
end
|
@@ -2,55 +2,50 @@ require './spec/spec_helper'
|
|
2
2
|
require "./lib/mass_insert"
|
3
3
|
|
4
4
|
describe MassInsert::Adapters::SQLServerAdapter do
|
5
|
-
|
6
|
-
@adapter = MassInsert::Adapters::SQLServerAdapter.new([], {})
|
7
|
-
end
|
8
|
-
|
9
|
-
subject{ @adapter }
|
5
|
+
let!(:subject){ MassInsert::Adapters::SQLServerAdapter.new([], {}) }
|
10
6
|
|
11
7
|
it "should inherit from Adapter class" do
|
12
|
-
subject.
|
8
|
+
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
13
9
|
end
|
14
10
|
|
15
11
|
describe "instance methods" do
|
16
12
|
describe "#execute" do
|
13
|
+
before :each do
|
14
|
+
subject.stub(:begin_string).and_return("a")
|
15
|
+
subject.stub(:string_columns).and_return("b")
|
16
|
+
subject.stub(:string_values).and_return("c")
|
17
|
+
end
|
18
|
+
|
17
19
|
it "should respond to execute method" do
|
18
|
-
subject.respond_to
|
20
|
+
expect(subject).to respond_to(:execute)
|
19
21
|
end
|
20
22
|
|
21
23
|
context "when have less than 1000 values" do
|
22
24
|
it "call methods and returns their values concatenated" do
|
23
25
|
subject.values = [{}]
|
24
|
-
subject.
|
25
|
-
subject.stub(:string_columns).and_return("b")
|
26
|
-
subject.stub(:string_values).and_return("c")
|
27
|
-
subject.execute.should eq(["abc"])
|
26
|
+
expect(subject.execute).to eq(["abc"])
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
context "when have more than 1000 values" do
|
32
31
|
it "call methods and returns their values concatenated" do
|
33
|
-
subject.values = []
|
34
32
|
1500.times{ subject.values << {} }
|
35
|
-
subject.
|
36
|
-
subject.stub(:string_columns).and_return("b")
|
37
|
-
subject.stub(:string_values).and_return("c")
|
38
|
-
subject.execute.should eq(["abc", "abc"])
|
33
|
+
expect(subject.execute).to eq(["abc", "abc"])
|
39
34
|
end
|
40
35
|
end
|
41
36
|
end
|
42
37
|
end
|
43
38
|
|
44
39
|
describe "MAX_VALUES_PER_INSERTION" do
|
40
|
+
let(:class_name){ MassInsert::Adapters::SQLServerAdapter }
|
41
|
+
|
45
42
|
it "should respond_to" do
|
46
|
-
|
47
|
-
constant
|
48
|
-
class_name.const_defined?(constant).should be_true
|
43
|
+
constant = :MAX_VALUES_PER_INSERTION
|
44
|
+
expect(class_name.const_defined?(constant)).to be_true
|
49
45
|
end
|
50
46
|
|
51
47
|
it "should return 1000" do
|
52
|
-
class_name
|
53
|
-
class_name::MAX_VALUES_PER_INSERTION.should eq(1000)
|
48
|
+
expect(class_name::MAX_VALUES_PER_INSERTION).to eq(1000)
|
54
49
|
end
|
55
50
|
end
|
56
51
|
end
|
@@ -3,38 +3,34 @@ require "./lib/mass_insert"
|
|
3
3
|
|
4
4
|
describe MassInsert::Adapters do
|
5
5
|
it 'should be defined' do
|
6
|
-
|
6
|
+
expect(MassInsert::Adapters).to be
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should define Adapter class' do
|
10
|
-
MassInsert::Adapters::Adapter.
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should define AbstractQuery class' do
|
14
|
-
MassInsert::Adapters::AbstractQuery.should be
|
10
|
+
expect(MassInsert::Adapters::Adapter).to be
|
15
11
|
end
|
16
12
|
|
17
13
|
it 'should define ColumnValue class' do
|
18
|
-
MassInsert::Adapters::ColumnValue.
|
14
|
+
expect(MassInsert::Adapters::ColumnValue).to be
|
19
15
|
end
|
20
16
|
|
21
17
|
it 'should define ColumnValue class' do
|
22
|
-
MassInsert::Adapters::Helpers.
|
18
|
+
expect(MassInsert::Adapters::Helpers).to be
|
23
19
|
end
|
24
20
|
|
25
21
|
it 'should define MysqlAdapter class' do
|
26
|
-
MassInsert::Adapters::Mysql2Adapter.
|
22
|
+
expect(MassInsert::Adapters::Mysql2Adapter).to be
|
27
23
|
end
|
28
24
|
|
29
25
|
it 'should define PostgreSQLAdapter class' do
|
30
|
-
MassInsert::Adapters::PostgreSQLAdapter.
|
26
|
+
expect(MassInsert::Adapters::PostgreSQLAdapter).to be
|
31
27
|
end
|
32
28
|
|
33
29
|
it 'should define SQLite3Adapter class' do
|
34
|
-
MassInsert::Adapters::SQLite3Adapter.
|
30
|
+
expect(MassInsert::Adapters::SQLite3Adapter).to be
|
35
31
|
end
|
36
32
|
|
37
33
|
it 'should define SQLServerAdapter class' do
|
38
|
-
MassInsert::Adapters::SQLServerAdapter.
|
34
|
+
expect(MassInsert::Adapters::SQLServerAdapter).to be
|
39
35
|
end
|
40
36
|
end
|