mass_insert 0.1.3 → 0.2.0
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.
- checksums.yaml +5 -13
- data/.gitignore +2 -0
- data/.travis.yml +12 -10
- data/Gemfile +9 -8
- data/LICENSE.txt +1 -1
- data/README.md +34 -78
- data/Rakefile +19 -24
- data/lib/mass_insert/adapters/abstract_adapter.rb +54 -0
- data/lib/mass_insert/adapters/mysql2_adapter.rb +5 -0
- data/lib/mass_insert/adapters/postgresql_adapter.rb +5 -0
- data/lib/mass_insert/adapters/sqlite3_adapter.rb +5 -0
- data/lib/mass_insert/base.rb +3 -84
- data/lib/mass_insert/builder.rb +8 -0
- data/lib/mass_insert/executer.rb +2 -6
- data/lib/mass_insert/process.rb +14 -14
- data/lib/mass_insert/utilities.rb +25 -0
- data/lib/mass_insert/version.rb +1 -1
- data/lib/mass_insert.rb +9 -5
- data/mass_insert.gemspec +10 -10
- data/test/adapters/mysql2/example_test.rb +3 -0
- data/test/adapters/postgresql/example_test.rb +3 -0
- data/test/adapters/sqlite3/example_test.rb +3 -0
- data/test/database.yml.example +18 -0
- data/test/models/user.rb +2 -0
- data/test/schema.rb +11 -0
- data/test/support/adapters/mysql2.rb +1 -0
- data/test/support/adapters/postgresql.rb +1 -0
- data/test/support/adapters/sqlite3.rb +1 -0
- data/test/support/shared_examples.rb +57 -0
- data/test/test_helper.rb +20 -0
- metadata +42 -188
- data/.rvmrc +0 -62
- data/lib/mass_insert/builder/adapters/adapter.rb +0 -52
- data/lib/mass_insert/builder/adapters/helpers/abstract_query.rb +0 -52
- data/lib/mass_insert/builder/adapters/helpers/column_value.rb +0 -90
- data/lib/mass_insert/builder/adapters/mysql2_adapter.rb +0 -7
- data/lib/mass_insert/builder/adapters/postgresql_adapter.rb +0 -7
- data/lib/mass_insert/builder/adapters/sqlite3_adapter.rb +0 -27
- data/lib/mass_insert/builder/adapters/sqlserver_adapter.rb +0 -20
- data/lib/mass_insert/builder/adapters.rb +0 -16
- data/lib/mass_insert/builder/base.rb +0 -28
- data/lib/mass_insert/builder/utilities.rb +0 -13
- data/lib/mass_insert/result.rb +0 -33
- data/spec/adapters/column_types/binary_spec.rb +0 -64
- data/spec/adapters/column_types/boolean_spec.rb +0 -48
- data/spec/adapters/column_types/date_spec.rb +0 -14
- data/spec/adapters/column_types/datetime_spec.rb +0 -14
- data/spec/adapters/column_types/decimal_spec.rb +0 -59
- data/spec/adapters/column_types/integer_spec.rb +0 -59
- data/spec/adapters/column_types/string_spec.rb +0 -46
- data/spec/adapters/column_types/time_spec.rb +0 -14
- data/spec/adapters/model_spec.rb +0 -83
- data/spec/dummy/.gitignore +0 -15
- data/spec/dummy/Gemfile +0 -40
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/user.rb +0 -3
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config/application.rb +0 -68
- data/spec/dummy/config/boot.rb +0 -6
- data/spec/dummy/config/database.yml +0 -49
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/mysql2.rb +0 -37
- data/spec/dummy/config/environments/postgresql.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/sqlite3.rb +0 -37
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20130412154541_create_users.rb +0 -16
- data/spec/dummy/db/schema.rb +0 -29
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +0 -241
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/lib/mass_insert/base_spec.rb +0 -40
- data/spec/lib/mass_insert/builder/adapters/adapter_spec.rb +0 -116
- data/spec/lib/mass_insert/builder/adapters/helpers/abstract_query_spec.rb +0 -130
- data/spec/lib/mass_insert/builder/adapters/helpers/column_value_spec.rb +0 -222
- data/spec/lib/mass_insert/builder/adapters/mysql_adapter_spec.rb +0 -9
- data/spec/lib/mass_insert/builder/adapters/postgresql_adapter_spec.rb +0 -9
- data/spec/lib/mass_insert/builder/adapters/sqlite3_adapter_spec.rb +0 -52
- data/spec/lib/mass_insert/builder/adapters/sqlserver_adapter_spec.rb +0 -32
- data/spec/lib/mass_insert/builder/adapters_spec.rb +0 -31
- data/spec/lib/mass_insert/builder/base_spec.rb +0 -28
- data/spec/lib/mass_insert/builder/utilities_spec.rb +0 -11
- data/spec/lib/mass_insert/executer_spec.rb +0 -33
- data/spec/lib/mass_insert/process_spec.rb +0 -58
- data/spec/lib/mass_insert/result_spec.rb +0 -45
- data/spec/lib/mass_insert_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -15
- data/spec/support/mass_insert_support.rb +0 -12
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Builder::Adapters::Adapter do
|
|
4
|
-
let!(:subject){ described_class.new([], {}) }
|
|
5
|
-
|
|
6
|
-
describe "#initialize" do
|
|
7
|
-
it "initializes values" do
|
|
8
|
-
expect(subject.values).to eq([])
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "initializes options" do
|
|
12
|
-
expect(subject.options).to eq({})
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#class_name" do
|
|
17
|
-
it "returns class_name option value" do
|
|
18
|
-
subject.options = {:class_name => "FakeModel"}
|
|
19
|
-
expect(subject.class_name).to eq("FakeModel")
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "#primary_key" do
|
|
24
|
-
it "returns primary_key option value" do
|
|
25
|
-
subject.options = {:primary_key => true}
|
|
26
|
-
expect(subject.primary_key).to be_true
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "#each_slice" do
|
|
31
|
-
it "returns each_slice option value" do
|
|
32
|
-
subject.options = {:each_slice => 10000}
|
|
33
|
-
expect(subject.each_slice).to be 10000
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe "#columns" do
|
|
38
|
-
context "when instance columns variable isn't defined" do
|
|
39
|
-
it "returns sanitized_columns result" do
|
|
40
|
-
subject.stub(:sanitized_columns).and_return("sanitized_columns")
|
|
41
|
-
expect(subject.columns).to eq("sanitized_columns")
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context "when instance columns variable has been defined" do
|
|
46
|
-
it "returns instance columns variable" do
|
|
47
|
-
subject.stub(:sanitized_columns).and_return("sanitized_columns")
|
|
48
|
-
subject.columns
|
|
49
|
-
subject.stub(:sanitized_columns).and_return("sanitized_columns_other")
|
|
50
|
-
expect(subject.columns).to eq("sanitized_columns")
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
describe "#sanitized_columns" do
|
|
56
|
-
before :each do
|
|
57
|
-
subject.options.merge!({:class_name => User})
|
|
58
|
-
User.stub(:column_names).and_return(["id", "name", "email"])
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context "when primary_key is false" do
|
|
62
|
-
it "returns the columns array without primary key column" do
|
|
63
|
-
subject.options.merge!({:primary_key => false})
|
|
64
|
-
expect(subject.columns).to eq([:name, :email])
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
context "when primary key is true" do
|
|
69
|
-
it "returns the columns array with primary key column" do
|
|
70
|
-
subject.options.merge!({:primary_key => true})
|
|
71
|
-
expect(subject.columns).to eq([:id, :name, :email])
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "#timestamp?" do
|
|
77
|
-
context "when respond to timestamp columns" do
|
|
78
|
-
it "returns true" do
|
|
79
|
-
subject.stub(:columns).and_return([:updated_at, :created_at])
|
|
80
|
-
expect(subject.timestamp?).to be_true
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
context "when doesn't respond to timestamp columns" do
|
|
85
|
-
it "returns false" do
|
|
86
|
-
subject.stub(:columns).and_return([:created_at])
|
|
87
|
-
expect(subject.timestamp?).to be_false
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe "#timestamp_hash" do
|
|
93
|
-
it "returns a timestamp hash" do
|
|
94
|
-
time = Time.now
|
|
95
|
-
Time.stub(:now).and_return(time)
|
|
96
|
-
expect(subject.timestamp_hash).to eq({:created_at => Time.now, :updated_at => Time.now})
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
describe "#values_per_insertion" do
|
|
101
|
-
context "when each_slice option is not false" do
|
|
102
|
-
it "returns each_slice value" do
|
|
103
|
-
subject.options.merge!(each_slice: 10)
|
|
104
|
-
expect(subject.values_per_insertion).to eq(10)
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
context "when each_slice option is false" do
|
|
109
|
-
it "returns length of values" do
|
|
110
|
-
subject.values = [{}, {}]
|
|
111
|
-
subject.options.merge!(each_slice: false)
|
|
112
|
-
expect(subject.values_per_insertion).to eq(2)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,130 +0,0 @@
|
|
|
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,222 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Builder::Adapters::Helpers::ColumnValue do
|
|
4
|
-
let(:class_name) { User }
|
|
5
|
-
let(:row) {{ :name => "name", :age => 10 }}
|
|
6
|
-
let(:column){ :name }
|
|
7
|
-
let!(:subject){ described_class.new(row, column, class_name) }
|
|
8
|
-
|
|
9
|
-
describe "#initialize" do
|
|
10
|
-
it "sets class_name attribute" do
|
|
11
|
-
expect(subject.class_name).to eq(class_name)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "sets column attribute" do
|
|
15
|
-
expect(subject.column).to eq(column)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "sets row attribute" do
|
|
19
|
-
expect(subject.row).to eq(row)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "#column_type" do
|
|
24
|
-
it "returns column type symbol" do
|
|
25
|
-
subject.stub(:class_name).and_return(User)
|
|
26
|
-
subject.class_name.stub(:columns_hash).and_return({"name" => "SomeObject"})
|
|
27
|
-
subject.class_name.columns_hash["name"].stub(:type).and_return(:column_type)
|
|
28
|
-
expect(subject.column_type).to eq(:column_type)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "#colum_value" do
|
|
33
|
-
it "returns row value to this column" do
|
|
34
|
-
expect(subject.column_value).to eq("name")
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "#default_value" do
|
|
39
|
-
context "when default_db_value is nil" do
|
|
40
|
-
it "returns 'null' string" do
|
|
41
|
-
subject.stub(:default_db_value).and_return(nil)
|
|
42
|
-
expect(subject.default_value).to eq("null")
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "when default_db_value is not nil" do
|
|
47
|
-
it "returns the correct value" do
|
|
48
|
-
subject.stub(:default_db_value).and_return("default_value")
|
|
49
|
-
expect(subject.default_value).to eq("default_value")
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "#default_db_value" do
|
|
55
|
-
it "returns the default database value" do
|
|
56
|
-
subject.stub(:class_name).and_return(User)
|
|
57
|
-
subject.class_name.stub(:columns_hash).and_return({"name" => "SomeObject"})
|
|
58
|
-
subject.class_name.columns_hash["name"].stub(:default).and_return(:default_db_value)
|
|
59
|
-
expect(subject.default_db_value).to eq(:default_db_value)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
describe "#build" do
|
|
64
|
-
context "when column_value is nil" do
|
|
65
|
-
it "returns the default value" do
|
|
66
|
-
subject.stub(:column_value).and_return(nil)
|
|
67
|
-
subject.stub(:default_value).and_return("default_value")
|
|
68
|
-
expect(subject.build).to eq("default_value")
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context "when column_value is not nil" do
|
|
73
|
-
it "calls a method according to column type" do
|
|
74
|
-
subject.stub(:column_type).and_return("string")
|
|
75
|
-
subject.stub(:column_value_string).and_return("column_value_string")
|
|
76
|
-
expect(subject.build).to eq("column_value_string")
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
[
|
|
82
|
-
:string,
|
|
83
|
-
:text,
|
|
84
|
-
:date,
|
|
85
|
-
:binary
|
|
86
|
-
].each do |column_type|
|
|
87
|
-
method = :"column_value_#{column_type}"
|
|
88
|
-
|
|
89
|
-
describe "##{method.to_s}" do
|
|
90
|
-
it "returns the column value" do
|
|
91
|
-
subject.stub(:column_value).and_return("name")
|
|
92
|
-
expect(subject.send(method)).to eq("'name'")
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
[
|
|
98
|
-
:time,
|
|
99
|
-
:datetime,
|
|
100
|
-
:timestamp,
|
|
101
|
-
].each do |column_type|
|
|
102
|
-
method = :"column_value_#{column_type}"
|
|
103
|
-
|
|
104
|
-
describe "##{method.to_s}" do
|
|
105
|
-
before :each do
|
|
106
|
-
time = Time.now
|
|
107
|
-
Time.stub(:now).and_return(time)
|
|
108
|
-
subject.stub(:column_value).and_return(Time.now)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
context "when adapter is mysql2" do
|
|
112
|
-
it "returns date with the correct format" do
|
|
113
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return('mysql2')
|
|
114
|
-
expect(subject.send(method)).to eq("'#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}'")
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
context "when adapter is sqlserver" do
|
|
119
|
-
it "returns date with the correct format" do
|
|
120
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return('sqlserver')
|
|
121
|
-
expect(subject.send(method)).to eq("'#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%3N")}'")
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
context "when adapter is sqlite3" do
|
|
126
|
-
it "returns date with the correct format" do
|
|
127
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return('sqlite3')
|
|
128
|
-
expect(subject.send(method)).to eq("'#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%6N")}'")
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
context "when adapter is postgresql" do
|
|
133
|
-
it "returns date with the correct format" do
|
|
134
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return('postgresql')
|
|
135
|
-
expect(subject.send(method)).to eq("'#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%6N")}'")
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
describe "#column_value_integer" do
|
|
142
|
-
context "when is a integer value" do
|
|
143
|
-
it "returns the same integer value" do
|
|
144
|
-
subject.stub(:column_value).and_return(20)
|
|
145
|
-
expect(subject.column_value_integer).to eq("20")
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
context "when is not a integer value" do
|
|
150
|
-
it "converts it to integer value" do
|
|
151
|
-
subject.stub(:column_value).and_return("name")
|
|
152
|
-
expect(subject.column_value_integer).to eq("0")
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
[:decimal, :float].each do |column_type|
|
|
158
|
-
method = :"column_value_#{column_type}"
|
|
159
|
-
|
|
160
|
-
describe "##{method.to_s}" do
|
|
161
|
-
context "when is a decimal value" do
|
|
162
|
-
it "returns the same decimal value" do
|
|
163
|
-
subject.stub(:column_value).and_return(20.5)
|
|
164
|
-
expect(subject.send(method)).to eq("20.5")
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
context "when is not a decimal value" do
|
|
169
|
-
it "converts it to decimal value" do
|
|
170
|
-
subject.stub(:column_value).and_return("name")
|
|
171
|
-
expect(subject.send(method)).to eq("0.0")
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
describe "#column_value_boolean" do
|
|
178
|
-
[:mysql2, :postgresql].each do |adapter|
|
|
179
|
-
context "when the adapter is #{adapter}" do
|
|
180
|
-
before :each do
|
|
181
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return(adapter.to_s)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
context "when the column value evals to true" do
|
|
185
|
-
it "returns true" do
|
|
186
|
-
subject.stub(:column_value).and_return(true)
|
|
187
|
-
expect(subject.column_value_boolean).to eq("true")
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
context "when the column value evals to false" do
|
|
192
|
-
it "returns false" do
|
|
193
|
-
subject.stub(:column_value).and_return(false)
|
|
194
|
-
expect(subject.column_value_boolean).to eq("false")
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
[:sqlite3, :sqlserver].each do |adapter|
|
|
201
|
-
context "when the adapter is #{adapter}" do
|
|
202
|
-
before :each do
|
|
203
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return(adapter.to_s)
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
context "when the column value evals to true" do
|
|
207
|
-
it "returns true" do
|
|
208
|
-
subject.stub(:column_value).and_return(true)
|
|
209
|
-
expect(subject.column_value_boolean).to eq("1")
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
context "when the column value evals to false" do
|
|
214
|
-
it "returns false" do
|
|
215
|
-
subject.stub(:column_value).and_return(false)
|
|
216
|
-
expect(subject.column_value_boolean).to eq("0")
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
end
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Builder::Adapters::SQLServerAdapter 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 "#string_columns" do
|
|
11
|
-
it "returns the correct columns string to SQLServer" do
|
|
12
|
-
subject.stub(:columns).and_return([:name, :email])
|
|
13
|
-
expect(subject.string_columns).to eq("([name], [email]) ")
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#values_per_insertion" do
|
|
18
|
-
context "when each_slice option isn't false" do
|
|
19
|
-
it "returns each_slice option value" do
|
|
20
|
-
subject.options.merge!(each_slice: 10)
|
|
21
|
-
expect(subject.values_per_insertion).to eq(10)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when each_slice option is false" do
|
|
26
|
-
it "returns 1000" do
|
|
27
|
-
subject.options.merge!(each_slice: false)
|
|
28
|
-
expect(subject.values_per_insertion).to eq(1000)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Builder::Adapters do
|
|
4
|
-
it 'loads Adapter class' do
|
|
5
|
-
expect(described_class::Adapter).to be
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it 'loads MysqlAdapter class' do
|
|
9
|
-
expect(described_class::Mysql2Adapter).to be
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'loads PostgreSQLAdapter class' do
|
|
13
|
-
expect(described_class::PostgreSQLAdapter).to be
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'loads SQLite3Adapter class' do
|
|
17
|
-
expect(described_class::SQLite3Adapter).to be
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'loads SQLServerAdapter class' do
|
|
21
|
-
expect(described_class::SQLServerAdapter).to be
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'loads Helpers AbstractQuery module' do
|
|
25
|
-
expect(described_class::Helpers::AbstractQuery).to be
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'loads Helpers ColumnValue class' do
|
|
29
|
-
expect(described_class::Helpers::ColumnValue).to be
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Builder::Base do
|
|
4
|
-
describe "#build" do
|
|
5
|
-
adapters_supported.each do |adapter_type, adapter_class|
|
|
6
|
-
context "when adapter_class is #{adapter_class}" do
|
|
7
|
-
it "returns the queries" do
|
|
8
|
-
adapter = "MassInsert::Builder::Adapters::#{adapter_class}".constantize
|
|
9
|
-
adapter.any_instance.stub(:execute).and_return("#{adapter_type}_queries")
|
|
10
|
-
subject.stub(:adapter_class).and_return(adapter)
|
|
11
|
-
expect(subject.build("values", "options")).to eq("#{adapter_type}_queries")
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#adapter_class" do
|
|
18
|
-
adapters_supported.each do |adapter_type, adapter_class|
|
|
19
|
-
context "when adapter is #{adapter_type}" do
|
|
20
|
-
it "returns #{adapter_class}" do
|
|
21
|
-
MassInsert::Builder::Utilities.stub(:adapter).and_return(adapter_type)
|
|
22
|
-
adapter = "MassInsert::Builder::Adapters::#{adapter_class}".constantize
|
|
23
|
-
expect(subject.adapter_class).to eq(adapter)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Builder::Utilities do
|
|
4
|
-
describe ".adapter" do
|
|
5
|
-
it "returns adapter type" do
|
|
6
|
-
connection = ActiveRecord::Base.connection
|
|
7
|
-
connection.stub(:instance_values => {"config" => {:adapter => "mysql2"}})
|
|
8
|
-
expect(described_class.adapter).to eq("mysql2")
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe MassInsert::Executer do
|
|
4
|
-
let!(:subject){ MassInsert::Executer.new }
|
|
5
|
-
|
|
6
|
-
describe "#execute" do
|
|
7
|
-
before :each do
|
|
8
|
-
@connection = ActiveRecord::Base.connection
|
|
9
|
-
@connection.stub(:execute)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context "when receives an array without queries" do
|
|
13
|
-
it "doesn't call ActiveRecord::Base.connection.execute" do
|
|
14
|
-
@connection.should_not_receive(:execute)
|
|
15
|
-
subject.execute([])
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context "when receives an array with one query" do
|
|
20
|
-
it "calls ActiveRecord::Base.connection.execute one time" do
|
|
21
|
-
@connection.should_receive(:execute).exactly(1).times
|
|
22
|
-
subject.execute("one")
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when receives an array with more than one query" do
|
|
27
|
-
it "calls ActiveRecord::Base.connection.execute two times" do
|
|
28
|
-
@connection.should_receive(:execute).exactly(2).times
|
|
29
|
-
subject.execute(["one", "two"])
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|