mass_insert 0.1.1 → 0.1.2
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 +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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe MassInsert::Builder::Adapters::Helpers::AbstractQuery do
|
|
4
|
+
let!(:subject){ MassInsert::Builder::Adapters::Adapter.new([], {}) }
|
|
5
|
+
|
|
6
|
+
describe "#begin_string" do
|
|
7
|
+
it "returns the basic beginning of the query" do
|
|
8
|
+
subject.stub(:class_name).and_return(User)
|
|
9
|
+
expect(subject.begin_string).to eq("INSERT INTO users ")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "#string_columns" do
|
|
14
|
+
it "returns the correct columns string" do
|
|
15
|
+
subject.stub(:columns).and_return([:name, :email])
|
|
16
|
+
expect(subject.string_columns).to eq("(name, email) ")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#string_values" do
|
|
21
|
+
it "returns the correct values string" do
|
|
22
|
+
subject.stub(:string_rows_values).and_return("rows_values")
|
|
23
|
+
expect(subject.string_values).to eq("VALUES (rows_values);")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "#string_rows_values" do
|
|
28
|
+
context "when is one value" do
|
|
29
|
+
it "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 are two or more values" do
|
|
37
|
+
it "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), (row")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "#string_single_row_values" do
|
|
46
|
+
before :each do
|
|
47
|
+
subject.stub(:string_single_value).and_return("value")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "returns the correct string" do
|
|
51
|
+
subject.stub(:columns).and_return([:name, :email])
|
|
52
|
+
expect(subject.string_single_row_values({})).to eq("value, value")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "when responds to timestamp attributes" do
|
|
56
|
+
it "calls timestamp_values method" do
|
|
57
|
+
subject.stub(:columns).and_return([:created_at, :updated_at])
|
|
58
|
+
subject.stub(:timestamp_hash).and_return(:test => "test")
|
|
59
|
+
subject.should_receive(:timestamp_hash).exactly(1).times
|
|
60
|
+
subject.string_single_row_values({})
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "when not respond to timestamp attributes" do
|
|
65
|
+
it "should returns the correct string" do
|
|
66
|
+
subject.stub(:columns).and_return([:name, :email])
|
|
67
|
+
subject.should_receive(:timestamp_hash).exactly(0).times
|
|
68
|
+
subject.string_single_row_values({})
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe "#string_single_value" do
|
|
74
|
+
let(:row){ Hash.new }
|
|
75
|
+
let(:column){ :name }
|
|
76
|
+
let(:column_value_class){ MassInsert::Builder::Adapters::Helpers::ColumnValue }
|
|
77
|
+
|
|
78
|
+
before :each do
|
|
79
|
+
subject.stub(:class_name).and_return(User)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "instances ColumnValue class exactly one time" do
|
|
83
|
+
column_value_class.stub(:new).and_return("column_value_instance")
|
|
84
|
+
column_value_class.new.stub(:build).and_return("column_value")
|
|
85
|
+
column_value_class.should_receive(:new).exactly(1).times
|
|
86
|
+
subject.string_single_value(row, column)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "instances ColumnValue class with the correct params" do
|
|
90
|
+
column_value_class.stub(:new).and_return("column_value_instance")
|
|
91
|
+
column_value_class.new.stub(:build).and_return("column_value")
|
|
92
|
+
column_value_class.should_receive(:new).with(row, column, User)
|
|
93
|
+
subject.string_single_value(row, column)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "calls ColumnValue#build exactly one time" do
|
|
97
|
+
column_value_class.any_instance.should_receive(:build).exactly(1).times
|
|
98
|
+
subject.string_single_value(row, column)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "returns ColumnValue#build method result" do
|
|
102
|
+
column_value_class.any_instance.stub(:build).and_return("column_value1")
|
|
103
|
+
expect(subject.string_single_value(row, column)).to eq("column_value1")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "#execute" do
|
|
108
|
+
before :each do
|
|
109
|
+
subject.stub(:begin_string).and_return("a")
|
|
110
|
+
subject.stub(:string_columns).and_return("b")
|
|
111
|
+
subject.stub(:string_values).and_return("c")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "when have less or equal values than values_per_insertion" do
|
|
115
|
+
it "generates one query" do
|
|
116
|
+
subject.values = [{}]
|
|
117
|
+
subject.stub(:values_per_insertion).and_return(1)
|
|
118
|
+
expect(subject.execute).to eq(["abc"])
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context "when have more values than values_per_insertion" do
|
|
123
|
+
it "generates queries according to the slices" do
|
|
124
|
+
subject.values = [{}, {}]
|
|
125
|
+
subject.stub(:values_per_insertion).and_return(1)
|
|
126
|
+
expect(subject.execute).to eq(["abc", "abc"])
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require "./lib/mass_insert"
|
|
1
|
+
require 'spec_helper'
|
|
3
2
|
|
|
4
|
-
describe MassInsert::Adapters::
|
|
3
|
+
describe MassInsert::Builder::Adapters::Helpers::ColumnValue do
|
|
5
4
|
let(:class_name) { User }
|
|
6
5
|
let(:row) {{ :name => "name", :age => 10 }}
|
|
7
6
|
let(:column){ :name }
|
|
8
|
-
let!(:subject){
|
|
7
|
+
let!(:subject){ described_class.new(row, column, class_name) }
|
|
9
8
|
|
|
10
9
|
describe "#initialize" do
|
|
11
|
-
it "
|
|
10
|
+
it "sets class_name attribute" do
|
|
12
11
|
expect(subject.class_name).to eq(class_name)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
it "
|
|
14
|
+
it "sets column attribute" do
|
|
16
15
|
expect(subject.column).to eq(column)
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
it "
|
|
18
|
+
it "sets row attribute" do
|
|
20
19
|
expect(subject.row).to eq(row)
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
describe "#column_type" do
|
|
25
|
-
it "
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should return symbol :string" do
|
|
30
|
-
subject.stub(:class_name).and_return("ClassName")
|
|
24
|
+
it "returns column type symbol" do
|
|
25
|
+
subject.stub(:class_name).and_return(User)
|
|
31
26
|
subject.class_name.stub(:columns_hash).and_return({"name" => "SomeObject"})
|
|
32
27
|
subject.class_name.columns_hash["name"].stub(:type).and_return(:column_type)
|
|
33
28
|
expect(subject.column_type).to eq(:column_type)
|
|
@@ -35,42 +30,21 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
35
30
|
end
|
|
36
31
|
|
|
37
32
|
describe "#colum_value" do
|
|
38
|
-
it "
|
|
39
|
-
expect(subject).to respond_to(:column_value)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should return row value to this column" do
|
|
33
|
+
it "returns row value to this column" do
|
|
43
34
|
expect(subject.column_value).to eq("name")
|
|
44
35
|
end
|
|
45
36
|
end
|
|
46
37
|
|
|
47
|
-
describe "#adapter" do
|
|
48
|
-
it "should respond to adapter method" do
|
|
49
|
-
expect(subject).to respond_to(:adapter)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "should return the adapter type" do
|
|
53
|
-
config = {"config" => {:adapter => "sql"}}
|
|
54
|
-
connection = ActiveRecord::Base.connection
|
|
55
|
-
connection.stub(:instance_values).and_return(config)
|
|
56
|
-
expect(subject.adapter).to eq("sql")
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
38
|
describe "#default_value" do
|
|
61
|
-
it "should respond to default_value method" do
|
|
62
|
-
expect(subject).to respond_to(:default_value)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
39
|
context "when default_db_value is nil" do
|
|
66
|
-
it "
|
|
40
|
+
it "returns 'null' string" do
|
|
67
41
|
subject.stub(:default_db_value).and_return(nil)
|
|
68
42
|
expect(subject.default_value).to eq("null")
|
|
69
43
|
end
|
|
70
44
|
end
|
|
71
45
|
|
|
72
46
|
context "when default_db_value is not nil" do
|
|
73
|
-
it "
|
|
47
|
+
it "returns the correct value" do
|
|
74
48
|
subject.stub(:default_db_value).and_return("default_value")
|
|
75
49
|
expect(subject.default_value).to eq("default_value")
|
|
76
50
|
end
|
|
@@ -78,12 +52,8 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
78
52
|
end
|
|
79
53
|
|
|
80
54
|
describe "#default_db_value" do
|
|
81
|
-
it "
|
|
82
|
-
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should return the default database value" do
|
|
86
|
-
subject.stub(:class_name).and_return("ClassName")
|
|
55
|
+
it "returns the default database value" do
|
|
56
|
+
subject.stub(:class_name).and_return(User)
|
|
87
57
|
subject.class_name.stub(:columns_hash).and_return({"name" => "SomeObject"})
|
|
88
58
|
subject.class_name.columns_hash["name"].stub(:default).and_return(:default_db_value)
|
|
89
59
|
expect(subject.default_db_value).to eq(:default_db_value)
|
|
@@ -91,12 +61,8 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
91
61
|
end
|
|
92
62
|
|
|
93
63
|
describe "#build" do
|
|
94
|
-
it "should respond to build method" do
|
|
95
|
-
expect(subject).to respond_to(:build)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
64
|
context "when column_value is nil" do
|
|
99
|
-
it "
|
|
65
|
+
it "returns the default value" do
|
|
100
66
|
subject.stub(:column_value).and_return(nil)
|
|
101
67
|
subject.stub(:default_value).and_return("default_value")
|
|
102
68
|
expect(subject.build).to eq("default_value")
|
|
@@ -104,7 +70,7 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
104
70
|
end
|
|
105
71
|
|
|
106
72
|
context "when column_value is not nil" do
|
|
107
|
-
it "
|
|
73
|
+
it "calls a method according to column type" do
|
|
108
74
|
subject.stub(:column_type).and_return("string")
|
|
109
75
|
subject.stub(:column_value_string).and_return("column_value_string")
|
|
110
76
|
expect(subject.build).to eq("column_value_string")
|
|
@@ -124,11 +90,7 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
124
90
|
method = :"column_value_#{column_type}"
|
|
125
91
|
|
|
126
92
|
describe "##{method.to_s}" do
|
|
127
|
-
it "
|
|
128
|
-
expect(subject).to respond_to(method)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "should return the column value" do
|
|
93
|
+
it "returns the column value" do
|
|
132
94
|
subject.stub(:column_value).and_return("name")
|
|
133
95
|
expect(subject.send(method)).to eq("'name'")
|
|
134
96
|
end
|
|
@@ -136,19 +98,15 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
136
98
|
end
|
|
137
99
|
|
|
138
100
|
describe "#column_value_integer" do
|
|
139
|
-
it "should respond to column_value_integer method" do
|
|
140
|
-
expect(subject).to respond_to(:column_value_integer)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
101
|
context "when is a integer value" do
|
|
144
|
-
it "
|
|
102
|
+
it "returns the same integer value" do
|
|
145
103
|
subject.stub(:column_value).and_return(20)
|
|
146
104
|
expect(subject.column_value_integer).to eq("20")
|
|
147
105
|
end
|
|
148
106
|
end
|
|
149
107
|
|
|
150
108
|
context "when is not a integer value" do
|
|
151
|
-
it "
|
|
109
|
+
it "converts it to integer value" do
|
|
152
110
|
subject.stub(:column_value).and_return("name")
|
|
153
111
|
expect(subject.column_value_integer).to eq("0")
|
|
154
112
|
end
|
|
@@ -159,19 +117,15 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
159
117
|
method = :"column_value_#{column_type}"
|
|
160
118
|
|
|
161
119
|
describe "##{method.to_s}" do
|
|
162
|
-
it "should respond to #{method.to_s} method" do
|
|
163
|
-
expect(subject).to respond_to(method)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
120
|
context "when is a decimal value" do
|
|
167
|
-
it "
|
|
121
|
+
it "returns the same decimal value" do
|
|
168
122
|
subject.stub(:column_value).and_return(20.5)
|
|
169
123
|
expect(subject.send(method)).to eq("20.5")
|
|
170
124
|
end
|
|
171
125
|
end
|
|
172
126
|
|
|
173
127
|
context "when is not a decimal value" do
|
|
174
|
-
it "
|
|
128
|
+
it "converts it to decimal value" do
|
|
175
129
|
subject.stub(:column_value).and_return("name")
|
|
176
130
|
expect(subject.send(method)).to eq("0.0")
|
|
177
131
|
end
|
|
@@ -180,12 +134,8 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
180
134
|
end
|
|
181
135
|
|
|
182
136
|
describe "#column_value_boolean" do
|
|
183
|
-
it "
|
|
184
|
-
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it "should call a method according to database adapter" do
|
|
188
|
-
subject.stub(:adapter).and_return("mysql2")
|
|
137
|
+
it "calls a method according to database adapter" do
|
|
138
|
+
MassInsert::Builder::Utilities.stub(:adapter).and_return("mysql2")
|
|
189
139
|
subject.stub(:mysql2_column_value_boolean).and_return("boolean_value")
|
|
190
140
|
expect(subject.column_value_boolean).to eq("boolean_value")
|
|
191
141
|
end
|
|
@@ -194,24 +144,19 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
194
144
|
[
|
|
195
145
|
:mysql2,
|
|
196
146
|
:postgresql,
|
|
197
|
-
:sqlserver,
|
|
198
147
|
].each do |adapter|
|
|
199
148
|
method = :"#{adapter}_column_value_boolean"
|
|
200
149
|
|
|
201
150
|
describe "##{method.to_s}" do
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
context "when column_value method return true value" do
|
|
207
|
-
it "should return true string" do
|
|
151
|
+
context "when column_value method return true" do
|
|
152
|
+
it "returns true string" do
|
|
208
153
|
subject.stub(:column_value).and_return(true)
|
|
209
154
|
expect(subject.send(method)).to eq("true")
|
|
210
155
|
end
|
|
211
156
|
end
|
|
212
157
|
|
|
213
|
-
context "when column_value method return false
|
|
214
|
-
it "
|
|
158
|
+
context "when column_value method return false" do
|
|
159
|
+
it "returns false string" do
|
|
215
160
|
subject.stub(:column_value).and_return(false)
|
|
216
161
|
expect(subject.send(method)).to eq("false")
|
|
217
162
|
end
|
|
@@ -219,22 +164,25 @@ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
|
|
|
219
164
|
end
|
|
220
165
|
end
|
|
221
166
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
167
|
+
[
|
|
168
|
+
:sqlite3,
|
|
169
|
+
:sqlserver,
|
|
170
|
+
].each do |adapter|
|
|
171
|
+
method = :"#{adapter}_column_value_boolean"
|
|
226
172
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
173
|
+
describe "##{method.to_s}" do
|
|
174
|
+
context "when column_value method return true" do
|
|
175
|
+
it "returns true string" do
|
|
176
|
+
subject.stub(:column_value).and_return(true)
|
|
177
|
+
expect(subject.send(method)).to eq("1")
|
|
178
|
+
end
|
|
231
179
|
end
|
|
232
|
-
end
|
|
233
180
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
181
|
+
context "when column_value method return false" do
|
|
182
|
+
it "returns false string" do
|
|
183
|
+
subject.stub(:column_value).and_return(false)
|
|
184
|
+
expect(subject.send(method)).to eq("0")
|
|
185
|
+
end
|
|
238
186
|
end
|
|
239
187
|
end
|
|
240
188
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe MassInsert::Builder::Adapters::Mysql2Adapter do
|
|
4
|
+
let!(:subject){ described_class.new([], {}) }
|
|
5
|
+
|
|
6
|
+
it "inherits from Adapter class" do
|
|
7
|
+
expect(described_class < MassInsert::Builder::Adapters::Adapter).to be_true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "#timestamp_format" do
|
|
11
|
+
it "returns format string" do
|
|
12
|
+
expect(subject.timestamp_format).to eq("%Y-%m-%d %H:%M:%S")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe MassInsert::Builder::Adapters::PostgreSQLAdapter do
|
|
4
|
+
let!(:subject){ described_class.new([], {}) }
|
|
5
|
+
|
|
6
|
+
it "inherits from Adapter class" do
|
|
7
|
+
expect(described_class < MassInsert::Builder::Adapters::Adapter).to be_true
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe MassInsert::Builder::Adapters::SQLite3Adapter do
|
|
4
|
+
let!(:subject){ described_class.new([], {}) }
|
|
5
|
+
|
|
6
|
+
it "inherits from Adapter class" do
|
|
7
|
+
expect(described_class < MassInsert::Builder::Adapters::Adapter).to be_true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "#values_per_insertion" do
|
|
11
|
+
context "when each_slice option isn't false" do
|
|
12
|
+
it "returns each_slice option value" do
|
|
13
|
+
subject.options.merge!(each_slice: 10)
|
|
14
|
+
expect(subject.values_per_insertion).to eq(10)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when each_slice option is false" do
|
|
19
|
+
it "returns 500" do
|
|
20
|
+
subject.options.merge!(each_slice: false)
|
|
21
|
+
expect(subject.values_per_insertion).to eq(500)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#string_values" do
|
|
27
|
+
it "returns the correct values string" do
|
|
28
|
+
subject.stub(:string_rows_values).and_return("rows_values")
|
|
29
|
+
expect(subject.string_values).to eq("SELECT rows_values;")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "#string_rows_values" do
|
|
34
|
+
before :each do
|
|
35
|
+
subject.stub(:string_single_row_values).and_return("row_values")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when is one value" do
|
|
39
|
+
it "returns the correct string" do
|
|
40
|
+
subject.values = [{}]
|
|
41
|
+
expect(subject.string_rows_values).to eq("row_values")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when are two values" do
|
|
46
|
+
it "returns the correct string" do
|
|
47
|
+
subject.values = [{}, {}]
|
|
48
|
+
expect(subject.string_rows_values).to eq("row_values UNION SELECT row_values")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|