mass_insert 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +0 -2
- data/README.md +15 -23
- data/Rakefile +22 -33
- data/lib/mass_insert.rb +11 -7
- data/lib/mass_insert/base.rb +22 -58
- data/lib/mass_insert/builder/adapters.rb +16 -0
- data/lib/mass_insert/builder/adapters/adapter.rb +65 -0
- data/lib/mass_insert/builder/adapters/helpers/abstract_query.rb +52 -0
- data/lib/mass_insert/builder/adapters/helpers/column_value.rb +90 -0
- data/lib/mass_insert/builder/adapters/mysql2_adapter.rb +15 -0
- data/lib/mass_insert/builder/adapters/postgresql_adapter.rb +7 -0
- data/lib/mass_insert/builder/adapters/sqlite3_adapter.rb +27 -0
- data/lib/mass_insert/builder/adapters/sqlserver_adapter.rb +26 -0
- data/lib/mass_insert/builder/base.rb +28 -0
- data/lib/mass_insert/builder/utilities.rb +13 -0
- data/lib/mass_insert/executer.rb +13 -0
- data/lib/mass_insert/process.rb +24 -0
- data/lib/mass_insert/result.rb +33 -0
- data/lib/mass_insert/version.rb +1 -1
- data/mass_insert.gemspec +2 -2
- data/spec/adapters/column_types/binary_spec.rb +64 -0
- data/spec/adapters/column_types/boolean_spec.rb +48 -0
- data/spec/adapters/column_types/decimal_spec.rb +59 -0
- data/spec/adapters/column_types/integer_spec.rb +59 -0
- data/spec/adapters/column_types/string_spec.rb +46 -0
- data/spec/{active_record_models → adapters}/model_spec.rb +1 -21
- data/spec/{active_record_dummy → dummy}/.gitignore +0 -0
- data/spec/{active_record_dummy → dummy}/Gemfile +1 -1
- data/spec/{active_record_dummy → dummy}/README.rdoc +0 -0
- data/spec/{active_record_dummy → dummy}/Rakefile +0 -0
- data/spec/{active_record_dummy → dummy}/app/assets/images/rails.png +0 -0
- data/spec/{active_record_dummy → dummy}/app/assets/javascripts/application.js +0 -0
- data/spec/{active_record_dummy → dummy}/app/assets/stylesheets/application.css +0 -0
- data/spec/{active_record_dummy → dummy}/app/controllers/application_controller.rb +0 -0
- data/spec/{active_record_dummy → dummy}/app/helpers/application_helper.rb +0 -0
- data/spec/{active_record_dummy → dummy}/app/mailers/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/app/models/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/app/models/user.rb +0 -0
- data/spec/{active_record_dummy → dummy}/app/views/layouts/application.html.erb +0 -0
- data/spec/{active_record_dummy → dummy}/config.ru +0 -0
- data/spec/{active_record_dummy → dummy}/config/application.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/boot.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/database.yml +3 -8
- data/spec/{active_record_dummy → dummy}/config/environment.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/environments/development.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/environments/mysql2.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/environments/postgresql.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/environments/production.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/environments/sqlite3.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/environments/test.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/initializers/inflections.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/initializers/mime_types.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/initializers/secret_token.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/initializers/session_store.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/{active_record_dummy → dummy}/config/locales/en.yml +0 -0
- data/spec/{active_record_dummy → dummy}/config/routes.rb +0 -0
- data/spec/{active_record_dummy → dummy}/db/migrate/20130412154541_create_users.rb +0 -0
- data/spec/{active_record_dummy → dummy}/db/schema.rb +0 -0
- data/spec/{active_record_dummy → dummy}/db/seeds.rb +0 -0
- data/spec/{active_record_dummy → dummy}/lib/assets/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/lib/tasks/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/log/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/public/404.html +0 -0
- data/spec/{active_record_dummy → dummy}/public/422.html +0 -0
- data/spec/{active_record_dummy → dummy}/public/500.html +0 -0
- data/spec/{active_record_dummy → dummy}/public/favicon.ico +0 -0
- data/spec/{active_record_dummy → dummy}/public/index.html +0 -0
- data/spec/{active_record_dummy → dummy}/public/robots.txt +0 -0
- data/spec/{active_record_dummy → dummy}/script/rails +0 -0
- data/spec/{active_record_dummy → dummy}/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/{active_record_dummy → dummy}/vendor/plugins/.gitkeep +0 -0
- data/spec/lib/mass_insert/base_spec.rb +40 -0
- data/spec/lib/mass_insert/builder/adapters/adapter_spec.rb +129 -0
- data/spec/lib/mass_insert/builder/adapters/helpers/abstract_query_spec.rb +130 -0
- data/spec/{mass_insert/adapters/adapter_helpers → lib/mass_insert/builder/adapters/helpers}/column_value_spec.rb +42 -94
- data/spec/lib/mass_insert/builder/adapters/mysql_adapter_spec.rb +15 -0
- data/spec/lib/mass_insert/builder/adapters/postgresql_adapter_spec.rb +9 -0
- data/spec/lib/mass_insert/builder/adapters/sqlite3_adapter_spec.rb +52 -0
- data/spec/lib/mass_insert/builder/adapters/sqlserver_adapter_spec.rb +38 -0
- data/spec/lib/mass_insert/builder/adapters_spec.rb +31 -0
- data/spec/lib/mass_insert/builder/base_spec.rb +28 -0
- data/spec/lib/mass_insert/builder/utilities_spec.rb +11 -0
- data/spec/lib/mass_insert/executer_spec.rb +33 -0
- data/spec/lib/mass_insert/process_spec.rb +44 -0
- data/spec/lib/mass_insert/result_spec.rb +45 -0
- data/spec/lib/mass_insert_spec.rb +35 -0
- data/spec/spec_helper.rb +7 -2
- data/spec/support/mass_insert_support.rb +12 -0
- metadata +160 -163
- data/lib/mass_insert/adapters.rb +0 -10
- data/lib/mass_insert/adapters/adapter.rb +0 -26
- data/lib/mass_insert/adapters/adapter_helpers.rb +0 -11
- data/lib/mass_insert/adapters/adapter_helpers/abstract_query.rb +0 -56
- data/lib/mass_insert/adapters/adapter_helpers/column_value.rb +0 -110
- data/lib/mass_insert/adapters/adapter_helpers/sanitizer.rb +0 -21
- data/lib/mass_insert/adapters/adapter_helpers/timestamp.rb +0 -33
- data/lib/mass_insert/adapters/mysql2_adapter.rb +0 -13
- data/lib/mass_insert/adapters/postgresql_adapter.rb +0 -5
- data/lib/mass_insert/adapters/sqlite3_adapter.rb +0 -37
- data/lib/mass_insert/adapters/sqlserver_adapter.rb +0 -29
- data/lib/mass_insert/process_control.rb +0 -46
- data/lib/mass_insert/query_builder.rb +0 -39
- data/lib/mass_insert/query_execution.rb +0 -29
- data/spec/active_record_models/column_types/binary_spec.rb +0 -60
- data/spec/active_record_models/column_types/boolean_spec.rb +0 -52
- data/spec/active_record_models/column_types/decimal_spec.rb +0 -49
- data/spec/active_record_models/column_types/integer_spec.rb +0 -49
- data/spec/active_record_models/column_types/string_spec.rb +0 -50
- data/spec/dummy_models/test.rb +0 -5
- data/spec/mass_insert/adapters/adapter_helpers/abstract_query_spec.rb +0 -119
- data/spec/mass_insert/adapters/adapter_helpers/sanitizer_spec.rb +0 -46
- data/spec/mass_insert/adapters/adapter_helpers/timestamp_spec.rb +0 -75
- data/spec/mass_insert/adapters/adapter_helpers_spec.rb +0 -24
- data/spec/mass_insert/adapters/adapter_spec.rb +0 -79
- data/spec/mass_insert/adapters/mysql_adapter_spec.rb +0 -22
- data/spec/mass_insert/adapters/postgresql_adapter_spec.rb +0 -11
- data/spec/mass_insert/adapters/sqlite3_adapter_spec.rb +0 -84
- data/spec/mass_insert/adapters/sqlserver_adapter_spec.rb +0 -61
- data/spec/mass_insert/adapters_spec.rb +0 -32
- data/spec/mass_insert/base_spec.rb +0 -114
- data/spec/mass_insert/process_control_spec.rb +0 -125
- data/spec/mass_insert/query_builder_spec.rb +0 -84
- data/spec/mass_insert/query_execution_spec.rb +0 -50
- data/spec/mass_insert_spec.rb +0 -28
@@ -1,75 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters::AdapterHelpers::Timestamp do
|
5
|
-
let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
|
6
|
-
|
7
|
-
describe "#timestamp?" do
|
8
|
-
it "should respond_to timestamp? method" do
|
9
|
-
expect(subject).to respond_to(:timestamp?)
|
10
|
-
end
|
11
|
-
|
12
|
-
context "when respond to timestamp columns" do
|
13
|
-
it "should return true" do
|
14
|
-
subject.stub(:columns).and_return([:updated_at, :created_at])
|
15
|
-
expect(subject.timestamp?).to be_true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when not respond to timestamp columns" do
|
20
|
-
it "should return false" do
|
21
|
-
subject.stub(:columns).and_return([:created_at])
|
22
|
-
expect(subject.timestamp?).to be_false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#timestamp_format" do
|
28
|
-
it "should respond_to timestamp_format method" do
|
29
|
-
expect(subject).to respond_to(:timestamp_format)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return the default timestamp format" do
|
33
|
-
expect(subject.timestamp_format).to eq("%Y-%m-%d %H:%M:%S.%6N")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#timestamp" do
|
38
|
-
it "should respond_to timestamp method" do
|
39
|
-
expect(subject).to respond_to(:timestamp)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return the default timestamp value with correct format" do
|
43
|
-
subject.stub(:timestamp_format).and_return("%Y-%m-%d %H:%M:%S")
|
44
|
-
timestamp_value = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
45
|
-
expect(subject.timestamp).to eq(timestamp_value)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#timestamp_hash" do
|
50
|
-
it "should respond_to timestamp_hash method" do
|
51
|
-
expect(subject).to respond_to(:timestamp_hash)
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when have high precision" do
|
55
|
-
it "should no be equals" do
|
56
|
-
timestamp_hash_expected = {
|
57
|
-
:created_at => subject.timestamp,
|
58
|
-
:updated_at => subject.timestamp
|
59
|
-
}
|
60
|
-
expect(subject.timestamp_hash).not_to eq(timestamp_hash_expected)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when do not have precision" do
|
65
|
-
it "should be equals" do
|
66
|
-
subject.stub(:timestamp_format).and_return("%Y-%m-%d %H:%M:%S")
|
67
|
-
timestamp_hash_expected = {
|
68
|
-
:created_at => subject.timestamp,
|
69
|
-
:updated_at => subject.timestamp
|
70
|
-
}
|
71
|
-
expect(subject.timestamp_hash).to eq(timestamp_hash_expected)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters::AdapterHelpers do
|
5
|
-
it 'should be defined' do
|
6
|
-
expect(MassInsert::Adapters::AdapterHelpers).to be
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should define AbstractQuery module' do
|
10
|
-
expect(MassInsert::Adapters::AdapterHelpers::AbstractQuery).to be
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should define ColumnValue class' do
|
14
|
-
expect(MassInsert::Adapters::AdapterHelpers::ColumnValue).to be
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should define Timestamp module' do
|
18
|
-
expect(MassInsert::Adapters::AdapterHelpers::Timestamp).to be
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should define Sanitizer module' do
|
22
|
-
expect(MassInsert::Adapters::AdapterHelpers::Sanitizer).to be
|
23
|
-
end
|
24
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
require "./spec/dummy_models/test"
|
4
|
-
|
5
|
-
describe MassInsert::Adapters::Adapter do
|
6
|
-
let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
|
7
|
-
|
8
|
-
describe "instance methods" do
|
9
|
-
describe "#initialize" do
|
10
|
-
let(:adapter){MassInsert::Adapters::Adapter.new("values", "options")}
|
11
|
-
|
12
|
-
it "should initialize the values" do
|
13
|
-
expect(adapter.values).to eq("values")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should initialize the options" do
|
17
|
-
expect(adapter.options).to eq("options")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#class_name" do
|
22
|
-
it "should returns the class_name in options" do
|
23
|
-
subject.options = {:class_name => Test}
|
24
|
-
expect(subject.class_name).to eq(Test)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#table_name" do
|
29
|
-
it "should returns the table_name in options" do
|
30
|
-
subject.options = {:table_name => "users"}
|
31
|
-
expect(subject.table_name).to eq("users")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#columns" do
|
36
|
-
before :each do
|
37
|
-
subject.options.merge!({
|
38
|
-
:class_name => Test,
|
39
|
-
:primary_key => :id,
|
40
|
-
:primary_key_mode => :auto
|
41
|
-
})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should respond to columns method" do
|
45
|
-
expect(subject).to respond_to(:columns)
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when primary_key is auto" do
|
49
|
-
it "should return an array without primary key column" do
|
50
|
-
column_names = [:name, :email]
|
51
|
-
expect(subject.columns).to eq(column_names)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when primary key is manual" do
|
56
|
-
it "should return an array with primary key column" do
|
57
|
-
subject.options.merge!({:primary_key_mode => :manual})
|
58
|
-
columns_expected = [:id, :name, :email]
|
59
|
-
expect(subject.columns).to eq(columns_expected)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#primary_key" do
|
65
|
-
it "should returns the primary_key in options" do
|
66
|
-
subject.options = {:primary_key => :user_id}
|
67
|
-
expect(subject.primary_key).to eq(:user_id)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#primary_key_mode" do
|
72
|
-
it "should returns the primary_key_mode in options" do
|
73
|
-
subject.options = {:primary_key_mode => :auto}
|
74
|
-
expect(subject.primary_key_mode).to eq(:auto)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters::Mysql2Adapter do
|
5
|
-
let!(:subject){ MassInsert::Adapters::Mysql2Adapter.new([], {}) }
|
6
|
-
|
7
|
-
it "should inherit from Adapter class" do
|
8
|
-
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "instance methods" do
|
12
|
-
describe "#timestamp_format" do
|
13
|
-
it "should respond to timestamp_format method" do
|
14
|
-
expect(subject).to respond_to(:timestamp_format)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should return the format string" do
|
18
|
-
expect(subject.timestamp_format).to eq("%Y-%m-%d %H:%M:%S")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters::PostgreSQLAdapter do
|
5
|
-
let!(:subject){ MassInsert::Adapters::PostgreSQLAdapter.new([], {}) }
|
6
|
-
|
7
|
-
it "should inherit from Adapter class" do
|
8
|
-
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters::SQLite3Adapter do
|
5
|
-
let!(:subject){ MassInsert::Adapters::SQLite3Adapter.new([], {}) }
|
6
|
-
|
7
|
-
it "should inherit from Adapter class" do
|
8
|
-
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "instance methods" do
|
12
|
-
describe "#string_values" do
|
13
|
-
it "should respond to string_values method" do
|
14
|
-
expect(subject).to respond_to(:string_values)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should returns correct string to values" do
|
18
|
-
subject.stub(:string_rows_values).and_return("rows_values")
|
19
|
-
expect(subject.string_values).to eq("SELECT rows_values;")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#string_rows_values" do
|
24
|
-
it "should respond to string_rows_values method" do
|
25
|
-
expect(subject).to respond_to(:string_rows_values)
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when only have one value hash" do
|
29
|
-
it "should returns the correct string" do
|
30
|
-
subject.stub(:string_single_row_values).and_return("row")
|
31
|
-
subject.values = [{}]
|
32
|
-
expect(subject.string_rows_values).to eq("row")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when have two or more value hashes" do
|
37
|
-
it "should returns the correct string" do
|
38
|
-
subject.stub(:string_single_row_values).and_return("row")
|
39
|
-
subject.values = [{}, {}]
|
40
|
-
expect(subject.string_rows_values).to eq("row UNION SELECT row")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
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
|
-
|
52
|
-
it "should respond to execute method" do
|
53
|
-
expect(subject).to respond_to(:execute)
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when have less than 500 values" do
|
57
|
-
it "call methods and returns their values concatenated" do
|
58
|
-
subject.values = [{}]
|
59
|
-
expect(subject.execute).to eq(["abc"])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when have more than 500 values" do
|
64
|
-
it "call methods and returns their values concatenated" do
|
65
|
-
800.times{ subject.values << {} }
|
66
|
-
expect(subject.execute).to eq(["abc", "abc"])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "MAX_VALUES_PER_INSERTION" do
|
73
|
-
let(:class_name){ MassInsert::Adapters::SQLite3Adapter }
|
74
|
-
|
75
|
-
it "should respond_to" do
|
76
|
-
constant = :MAX_VALUES_PER_INSERTION
|
77
|
-
expect(class_name.const_defined?(constant)).to be_true
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should return 1000" do
|
81
|
-
expect(class_name::MAX_VALUES_PER_INSERTION).to eq(500)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters::SQLServerAdapter do
|
5
|
-
let!(:subject){ MassInsert::Adapters::SQLServerAdapter.new([], {}) }
|
6
|
-
|
7
|
-
it "should inherit from Adapter class" do
|
8
|
-
expect(subject).to be_a(MassInsert::Adapters::Adapter)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "instance methods" do
|
12
|
-
describe "#timestamp_format" do
|
13
|
-
it "should respond to timestamp_format method" do
|
14
|
-
expect(subject).to respond_to(:timestamp_format)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should return the format string" do
|
18
|
-
expect(subject.timestamp_format).to eq("%Y-%m-%d %H:%M:%S.%3N")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#execute" do
|
23
|
-
before :each do
|
24
|
-
subject.stub(:begin_string).and_return("a")
|
25
|
-
subject.stub(:string_columns).and_return("b")
|
26
|
-
subject.stub(:string_values).and_return("c")
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should respond to execute method" do
|
30
|
-
expect(subject).to respond_to(:execute)
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when have less than 1000 values" do
|
34
|
-
it "call methods and returns their values concatenated" do
|
35
|
-
subject.values = [{}]
|
36
|
-
expect(subject.execute).to eq(["abc"])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when have more than 1000 values" do
|
41
|
-
it "call methods and returns their values concatenated" do
|
42
|
-
1500.times{ subject.values << {} }
|
43
|
-
expect(subject.execute).to eq(["abc", "abc"])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "MAX_VALUES_PER_INSERTION" do
|
50
|
-
let(:class_name){ MassInsert::Adapters::SQLServerAdapter }
|
51
|
-
|
52
|
-
it "should respond_to" do
|
53
|
-
constant = :MAX_VALUES_PER_INSERTION
|
54
|
-
expect(class_name.const_defined?(constant)).to be_true
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should return 1000" do
|
58
|
-
expect(class_name::MAX_VALUES_PER_INSERTION).to eq(1000)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
|
4
|
-
describe MassInsert::Adapters do
|
5
|
-
it 'should be defined' do
|
6
|
-
expect(MassInsert::Adapters).to be
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should define Adapter class' do
|
10
|
-
expect(MassInsert::Adapters::Adapter).to be
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should define ColumnValue class' do
|
14
|
-
expect(MassInsert::Adapters::AdapterHelpers).to be
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should define MysqlAdapter class' do
|
18
|
-
expect(MassInsert::Adapters::Mysql2Adapter).to be
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should define PostgreSQLAdapter class' do
|
22
|
-
expect(MassInsert::Adapters::PostgreSQLAdapter).to be
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should define SQLite3Adapter class' do
|
26
|
-
expect(MassInsert::Adapters::SQLite3Adapter).to be
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should define SQLServerAdapter class' do
|
30
|
-
expect(MassInsert::Adapters::SQLServerAdapter).to be
|
31
|
-
end
|
32
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
require "./lib/mass_insert"
|
3
|
-
require "./spec/dummy_models/test"
|
4
|
-
|
5
|
-
describe MassInsert::Base do
|
6
|
-
describe "class methods" do
|
7
|
-
describe ".mass_insert" do
|
8
|
-
before :each do
|
9
|
-
MassInsert::ProcessControl.any_instance.stub(:start => true)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should respond to mass_insert class method" do
|
13
|
-
expect(Test).to respond_to(:mass_insert)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should can receive values and many options" do
|
17
|
-
values = [{:name => "name"}]
|
18
|
-
options = {:option_one => "one", :option_two => "two"}
|
19
|
-
expect(Test.mass_insert(values, options)).to be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should can receive only values" do
|
23
|
-
values = [{:name => "name"}]
|
24
|
-
expect(Test.mass_insert(values)).to be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should not can called with values" do
|
28
|
-
expect(lambda{ Test.mass_insert }).to raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should call execute ProcessControl method" do
|
32
|
-
process = MassInsert::ProcessControl.any_instance
|
33
|
-
process.should_receive(:start).exactly(1).times
|
34
|
-
Test.mass_insert([], {})
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should call mass_insert_options method" do
|
38
|
-
Test.any_instance.stub(:mass_insert_options)
|
39
|
-
Test.should_receive(:mass_insert_options).exactly(1).times
|
40
|
-
Test.mass_insert([], {})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe ".mass_insert_results" do
|
45
|
-
it "should respond to mass_insert_results class method" do
|
46
|
-
expect(Test).to respond_to(:mass_insert_results)
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when mass_insert_process instance variable exists" do
|
50
|
-
it "should call results method in ProcessControl class" do
|
51
|
-
process = MassInsert::ProcessControl
|
52
|
-
process.any_instance.stub(:results).and_return(true)
|
53
|
-
process.any_instance.should_receive(:results).exactly(1).times
|
54
|
-
Test.mass_insert([], {})
|
55
|
-
Test.mass_insert_results
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe ".mass_insert_options" do
|
61
|
-
describe "class_name" do
|
62
|
-
it "returns class name that call if that option doesn't exist" do
|
63
|
-
options = Test.send(:mass_insert_options)
|
64
|
-
expect(options[:class_name]).to eq(Test)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns class_name option if is in the options" do
|
68
|
-
args = {:class_name => "OtherClass"}
|
69
|
-
options = Test.send(:mass_insert_options, args)
|
70
|
-
expect(options[:class_name]).to eq("OtherClass")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "table_name" do
|
75
|
-
it "returns class table_name that call if options doesn't exist" do
|
76
|
-
options = Test.send(:mass_insert_options)
|
77
|
-
expect(options[:table_name]).to eq(Test.table_name)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "returns table_name option if is in the options" do
|
81
|
-
args = {:table_name => "OtherTable"}
|
82
|
-
options = Test.send(:mass_insert_options, args)
|
83
|
-
expect(options[:table_name]).to eq("OtherTable")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "primary_key" do
|
88
|
-
it "returns :id if option primary_key doesn't exist" do
|
89
|
-
options = Test.send(:mass_insert_options)
|
90
|
-
expect(options[:primary_key]).to eq(:id)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "returns primary_key option if is in the options" do
|
94
|
-
args = {:primary_key => :user_id}
|
95
|
-
options = Test.send(:mass_insert_options, args)
|
96
|
-
expect(options[:primary_key]).to eq(:user_id)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "primary_key_mode" do
|
101
|
-
it "returns :auto if option primary_key_mode doesn't exist" do
|
102
|
-
options = Test.send(:mass_insert_options)
|
103
|
-
expect(options[:primary_key_mode]).to eq(:auto)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "returns primary_key_mode option if is in the options" do
|
107
|
-
args = {:primary_key_mode => :manual}
|
108
|
-
options = Test.send(:mass_insert_options, args)
|
109
|
-
expect(options[:primary_key_mode]).to eq(:manual)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|