mass_insert 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,20 +0,0 @@
|
|
1
|
-
module MassInsert
|
2
|
-
module Builder
|
3
|
-
module Adapters
|
4
|
-
class SQLServerAdapter < Adapter
|
5
|
-
|
6
|
-
# Returns a basic part of the query with the columns definition.
|
7
|
-
def string_columns
|
8
|
-
"([#{columns.join("], [")}]) "
|
9
|
-
end
|
10
|
-
|
11
|
-
# Returns the amount of records to each query. Tries to take the
|
12
|
-
# each_slice option value or 1000 due it's a standard in SQLServer.
|
13
|
-
def values_per_insertion
|
14
|
-
each_slice || 1000
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module MassInsert
|
2
|
-
module Builder
|
3
|
-
module Adapters
|
4
|
-
autoload :Adapter, 'mass_insert/builder/adapters/adapter.rb'
|
5
|
-
autoload :Mysql2Adapter, 'mass_insert/builder/adapters/mysql2_adapter.rb'
|
6
|
-
autoload :PostgreSQLAdapter, 'mass_insert/builder/adapters/postgresql_adapter.rb'
|
7
|
-
autoload :SQLite3Adapter, 'mass_insert/builder/adapters/sqlite3_adapter.rb'
|
8
|
-
autoload :SQLServerAdapter, 'mass_insert/builder/adapters/sqlserver_adapter.rb'
|
9
|
-
|
10
|
-
module Helpers
|
11
|
-
autoload :AbstractQuery, 'mass_insert/builder/adapters/helpers/abstract_query.rb'
|
12
|
-
autoload :ColumnValue, 'mass_insert/builder/adapters/helpers/column_value.rb'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module MassInsert
|
2
|
-
module Builder
|
3
|
-
class Base
|
4
|
-
|
5
|
-
# Supported adapters hash. Key is the adapter name and value
|
6
|
-
# is its adapter class.
|
7
|
-
ADAPTERS = {
|
8
|
-
'mysql2' => Adapters::Mysql2Adapter,
|
9
|
-
'postgresql' => Adapters::PostgreSQLAdapter,
|
10
|
-
'sqlite3' => Adapters::SQLite3Adapter,
|
11
|
-
'sqlserver' => Adapters::SQLServerAdapter
|
12
|
-
}
|
13
|
-
|
14
|
-
# This function gets the correct adapter class and returns the
|
15
|
-
# sql string ready to be executed.
|
16
|
-
def build values, options
|
17
|
-
adapter_class.new(values, options).execute
|
18
|
-
end
|
19
|
-
|
20
|
-
# Returns the class of the correct database adapter according to the
|
21
|
-
# database engine that is used in Rails project.
|
22
|
-
def adapter_class
|
23
|
-
ADAPTERS[Utilities.adapter]
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module MassInsert
|
2
|
-
module Builder
|
3
|
-
module Utilities
|
4
|
-
|
5
|
-
# Returns a string that contains the adapter type previosly
|
6
|
-
# configured in Rails project usually in the database.yml file.
|
7
|
-
def self.adapter
|
8
|
-
ActiveRecord::Base.connection.instance_values["config"][:adapter]
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/mass_insert/result.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module MassInsert
|
2
|
-
# This class is responsible to provides the mass insert process
|
3
|
-
# results according to the Process class instance.
|
4
|
-
class Result
|
5
|
-
|
6
|
-
def initialize process
|
7
|
-
@process = process
|
8
|
-
end
|
9
|
-
|
10
|
-
# Returns the time that took to create the query or queries
|
11
|
-
# string that was persisted.
|
12
|
-
def building_time
|
13
|
-
@process.instance_variable_get(:@building_time).total
|
14
|
-
end
|
15
|
-
|
16
|
-
# Returns the time that took to execute the query or queries
|
17
|
-
# string that was persisted.
|
18
|
-
def execution_time
|
19
|
-
@process.instance_variable_get(:@execution_time).total
|
20
|
-
end
|
21
|
-
|
22
|
-
# Returns the time that took to do all the MassInsert process.
|
23
|
-
def time
|
24
|
-
building_time + execution_time
|
25
|
-
end
|
26
|
-
|
27
|
-
# Returns the amount of records that were persisted.
|
28
|
-
def records
|
29
|
-
@process.instance_variable_get(:@values).count
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Binary" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains binary value" do
|
8
|
-
context "when is 1" do
|
9
|
-
it "saves the value correctly" do
|
10
|
-
values.first.merge!(checked: 1)
|
11
|
-
User.mass_insert(values, options)
|
12
|
-
expect(User.last.checked).to eq("1")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when is 0" do
|
17
|
-
it "saves the value correctly" do
|
18
|
-
values.first.merge!(checked: 0)
|
19
|
-
User.mass_insert(values, options)
|
20
|
-
expect(User.last.checked).to eq("0")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when contains a string" do
|
26
|
-
it "converts string value to binary" do
|
27
|
-
values.first.merge!(checked: "string")
|
28
|
-
User.mass_insert(values, options)
|
29
|
-
expect(User.last.checked).to eq("string")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when contains a integer greater than 1" do
|
34
|
-
it "converts integer value to binary" do
|
35
|
-
values.first.merge!(checked: 150)
|
36
|
-
User.mass_insert(values, options)
|
37
|
-
expect(User.last.checked).to eq("150")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when contains a decimal" do
|
42
|
-
it "converts decimal value to binary" do
|
43
|
-
values.first.merge!(checked: 25.34)
|
44
|
-
User.mass_insert(values, options)
|
45
|
-
expect(User.last.checked).to eq("25.34")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when contains a boolean" do
|
50
|
-
it "converts boolean value to binary" do
|
51
|
-
values.first.merge!(checked: true)
|
52
|
-
User.mass_insert(values, options)
|
53
|
-
expect(User.last.checked).to eq("true")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when not exist in values hashes" do
|
58
|
-
it "saves the default value" do
|
59
|
-
values.first.delete(:checked)
|
60
|
-
User.mass_insert(values, options)
|
61
|
-
expect(User.last.checked).to eq(nil)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Boolean" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains boolean value" do
|
8
|
-
context "when is true" do
|
9
|
-
it "saves the true value correctly" do
|
10
|
-
values.first.merge!(active: true)
|
11
|
-
User.mass_insert(values, options)
|
12
|
-
expect(User.last.active).to eq(true)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when is false" do
|
17
|
-
it "saves the false value correctly" do
|
18
|
-
values.first.merge!(active: false)
|
19
|
-
User.mass_insert(values, options)
|
20
|
-
expect(User.last.active).to eq(false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when contains a string" do
|
26
|
-
it "converts string value to boolean" do
|
27
|
-
values.first.merge!(active: "string")
|
28
|
-
User.mass_insert(values, options)
|
29
|
-
expect(User.last.active).to eq(true)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when contains a decimal" do
|
34
|
-
it "converts decimal value to boolean" do
|
35
|
-
values.first.merge!(active: 25.34)
|
36
|
-
User.mass_insert(values, options)
|
37
|
-
expect(User.last.active).to eq(true)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when not exist in values hashes" do
|
42
|
-
it "saves the default value" do
|
43
|
-
values.first.delete(:active)
|
44
|
-
User.mass_insert(values, options)
|
45
|
-
expect(User.last.active).to eq(nil)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Date" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains date value" do
|
8
|
-
it "saves the date value correctly" do
|
9
|
-
values.first.merge!(birthday: Date.today)
|
10
|
-
User.mass_insert(values, options)
|
11
|
-
expect(User.last.birthday).to eq(Date.today)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Datetime" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains datetime value" do
|
8
|
-
it "saves the datetime value correctly" do
|
9
|
-
values.first.merge!(created_at: DateTime.now)
|
10
|
-
User.mass_insert(values, options)
|
11
|
-
expect(User.last.created_at.strftime("%Y-%m-%d %H:%M")).to eq(DateTime.now.strftime("%Y-%m-%d %H:%M"))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Decimal" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains an integer" do
|
8
|
-
it "converts integer value to decimal" do
|
9
|
-
values.first.merge!(money: 10)
|
10
|
-
User.mass_insert(values, options)
|
11
|
-
expect(User.last.money).to eq(10.0)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when contains a string without digits" do
|
16
|
-
it "converts string value to decimal" do
|
17
|
-
values.first.merge!(money: "string")
|
18
|
-
User.mass_insert(values, options)
|
19
|
-
expect(User.last.money).to eq(0.0)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when contains a digits string" do
|
24
|
-
it "converts string value to decimal" do
|
25
|
-
values.first.merge!(money: "100")
|
26
|
-
User.mass_insert(values, options)
|
27
|
-
expect(User.last.money).to eq(100.0)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "converts string value to decimal" do
|
31
|
-
values.first.merge!(money: "200.50")
|
32
|
-
User.mass_insert(values, options)
|
33
|
-
expect(User.last.money).to eq(200.50)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when contains a decimal" do
|
38
|
-
it "saves the correct value" do
|
39
|
-
values.first.merge!(money: 20.50)
|
40
|
-
User.mass_insert(values, options)
|
41
|
-
expect(User.last.money).to eq(20.50)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when contains a boolean" do
|
46
|
-
it "raises an exception" do
|
47
|
-
values.first.merge!(money: true)
|
48
|
-
expect(lambda{ User.mass_insert(values, options) }).to raise_exception
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when not exist in values hashes" do
|
53
|
-
it "saves the default value" do
|
54
|
-
values.first.delete(:money)
|
55
|
-
User.mass_insert(values, options)
|
56
|
-
expect(User.last.money).to eq(nil)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Integer" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains an integer" do
|
8
|
-
it "saves the value correctly" do
|
9
|
-
values.first.merge!(age: 20)
|
10
|
-
User.mass_insert(values, options)
|
11
|
-
expect(User.last.age).to eq(20)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when contains a string without digits" do
|
16
|
-
it "converts string value to integer" do
|
17
|
-
values.first.merge!(age: "string")
|
18
|
-
User.mass_insert(values, options)
|
19
|
-
expect(User.last.age).to eq(0)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when contains a digits string" do
|
24
|
-
it "converts string value to integer" do
|
25
|
-
values.first.merge!(age: "100")
|
26
|
-
User.mass_insert(values, options)
|
27
|
-
expect(User.last.age).to eq(100)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "converts string value to integer" do
|
31
|
-
values.first.merge!(age: "200.45")
|
32
|
-
User.mass_insert(values, options)
|
33
|
-
expect(User.last.age).to eq(200)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when contains a decimal" do
|
38
|
-
it "converts decimal value to integer" do
|
39
|
-
values.first.merge!(age: 25.69)
|
40
|
-
User.mass_insert(values, options)
|
41
|
-
expect(User.last.age).to eq(25)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when contains a boolean" do
|
46
|
-
it "raises an exception" do
|
47
|
-
values.first.merge!(age: true)
|
48
|
-
expect(lambda{ User.mass_insert(values, options) }).to raise_exception
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when not exist in values hashes" do
|
53
|
-
it "saves the default value" do
|
54
|
-
values.first.delete(:age)
|
55
|
-
User.mass_insert(values, options)
|
56
|
-
expect(User.last.age).to eq(nil)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "String" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains a string" do
|
8
|
-
it "saves the value correctly" do
|
9
|
-
values.first.merge!(name: "name")
|
10
|
-
User.mass_insert(values, options)
|
11
|
-
expect(User.last.name).to eq("name")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when contains a integer" do
|
16
|
-
it "converts integer value to string" do
|
17
|
-
values.first.merge!(name: 10)
|
18
|
-
User.mass_insert(values, options)
|
19
|
-
expect(User.last.name).to eq("10")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when contains a decimal" do
|
24
|
-
it "converts decimal value to string" do
|
25
|
-
values.first.merge!(name: 25.69)
|
26
|
-
User.mass_insert(values, options)
|
27
|
-
expect(User.last.name).to eq("25.69")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when contains a boolean" do
|
32
|
-
it "converts boolean value to string" do
|
33
|
-
values.first.merge!(name: true)
|
34
|
-
User.mass_insert(values, options)
|
35
|
-
expect(User.last.name).to eq("true")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when not exist in values hashes" do
|
40
|
-
it "saves the default value" do
|
41
|
-
values.first.delete(:name)
|
42
|
-
User.mass_insert(values, options)
|
43
|
-
expect(User.last.name).to eq(nil)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Time" do
|
4
|
-
let!(:values){ [{}] }
|
5
|
-
let!(:options){ Hash.new }
|
6
|
-
|
7
|
-
context "when contains time value" do
|
8
|
-
it "saves the time value correctly" do
|
9
|
-
values.first.merge!(birthtime: Time.now)
|
10
|
-
User.mass_insert(values, options)
|
11
|
-
expect(User.last.birthtime.strftime("%H:%M")).to eq(Time.now.strftime("%H:%M"))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/spec/adapters/model_spec.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Model" do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
@values, @options = [], {}
|
7
|
-
@value_hash = {
|
8
|
-
:name => "some_name",
|
9
|
-
:email => "some_email",
|
10
|
-
:age => 20,
|
11
|
-
:active => true,
|
12
|
-
:checked => true
|
13
|
-
}
|
14
|
-
User.delete_all
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when is used without options" do
|
18
|
-
context "when value hashes have string keys" do
|
19
|
-
before :each do
|
20
|
-
value_hash = {
|
21
|
-
"name" => "some_name",
|
22
|
-
"email" => "some_email",
|
23
|
-
"age" => 20,
|
24
|
-
"active" => true,
|
25
|
-
"checked" => true
|
26
|
-
}
|
27
|
-
5.times{ @values << value_hash }
|
28
|
-
User.mass_insert(@values, @options)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should save correct values" do
|
32
|
-
expect(User.first.name).to eq("some_name")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should have saved 5 records" do
|
36
|
-
expect(User.count).to eq(5)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when value hashes have symbol keys" do
|
41
|
-
before :each do
|
42
|
-
5.times{ @values << @value_hash }
|
43
|
-
User.mass_insert(@values, @options)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should save correct values" do
|
47
|
-
expect(User.first.age).to eq(20)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should have saved 5 records" do
|
51
|
-
expect(User.count).to eq(5)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when value hashes have symbol and string keys" do
|
56
|
-
before :each do
|
57
|
-
value_hash = {
|
58
|
-
"name" => "some_name",
|
59
|
-
:email => "some_email",
|
60
|
-
"age" => 20,
|
61
|
-
:active => true,
|
62
|
-
"checked" => true
|
63
|
-
}
|
64
|
-
5.times{ @values << value_hash }
|
65
|
-
User.mass_insert(@values, @options)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should save correct values" do
|
69
|
-
expect(User.first.email).to eq("some_email")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should have saved 5 records" do
|
73
|
-
expect(User.count).to eq(5)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should save if values cointains 1200 records" do
|
78
|
-
1200.times{ @values << @value_hash }
|
79
|
-
User.mass_insert(@values, @options)
|
80
|
-
expect(User.count).to eq(1200)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/spec/dummy/.gitignore
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
-
#
|
3
|
-
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
-
# or operating system, you probably want to add a global ignore instead:
|
5
|
-
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
-
|
7
|
-
# Ignore bundler config
|
8
|
-
/.bundle
|
9
|
-
|
10
|
-
# Ignore the default SQLite database.
|
11
|
-
/db/*.sqlite3
|
12
|
-
|
13
|
-
# Ignore all logfiles and tempfiles.
|
14
|
-
/log/*.log
|
15
|
-
/tmp
|
data/spec/dummy/Gemfile
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'rails', '3.2.13'
|
4
|
-
|
5
|
-
# Bundle edge Rails instead:
|
6
|
-
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
-
|
8
|
-
gem 'sqlite3'
|
9
|
-
gem 'mysql2'
|
10
|
-
gem 'pg'
|
11
|
-
gem 'mass_insert', :path => '../../../mass_insert'
|
12
|
-
|
13
|
-
# Gems used only for assets and not required
|
14
|
-
# in production environments by default.
|
15
|
-
group :assets do
|
16
|
-
gem 'sass-rails', '~> 3.2.3'
|
17
|
-
gem 'coffee-rails', '~> 3.2.1'
|
18
|
-
|
19
|
-
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
20
|
-
# gem 'therubyracer', :platforms => :ruby
|
21
|
-
|
22
|
-
gem 'uglifier', '>= 1.0.3'
|
23
|
-
end
|
24
|
-
|
25
|
-
gem 'jquery-rails'
|
26
|
-
|
27
|
-
# To use ActiveModel has_secure_password
|
28
|
-
# gem 'bcrypt-ruby', '~> 3.0.0'
|
29
|
-
|
30
|
-
# To use Jbuilder templates for JSON
|
31
|
-
# gem 'jbuilder'
|
32
|
-
|
33
|
-
# Use unicorn as the app server
|
34
|
-
# gem 'unicorn'
|
35
|
-
|
36
|
-
# Deploy with Capistrano
|
37
|
-
# gem 'capistrano'
|
38
|
-
|
39
|
-
# To use debugger
|
40
|
-
# gem 'debugger'
|