mass_insert 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,6 +17,16 @@ Or install it yourself with:
17
17
 
18
18
  $ gem install mass_insert
19
19
 
20
+ ## Advantages
21
+
22
+ Faster. It's depending of the computer but these are some results...
23
+
24
+ * PostgreSQL - Saving 10,000 records in 0.84s
25
+
26
+ ## Attention
27
+
28
+ Since this is a single database insertion your model validation will be ignored, then if you use this gem you need to be sure that information is OK to be persisted.
29
+
20
30
  ## Basic Usage
21
31
 
22
32
  To use MassInsert gem you need to call mass_insert method from your ActiveRecord model and pass it an array with the values that you want to persist into the database.
@@ -77,29 +87,21 @@ OR directly
77
87
 
78
88
  Some options that you can include are...
79
89
 
80
- `:table_name` : Default value is the table name to your model. This options rarely needs to change but you can do it if you pass a string with the table name. Example...
90
+ **table_name**
91
+ - Default value is the table name to your model. This options rarely needs to change but you can do it if you pass a string with the table name. Example...
81
92
 
82
93
  options = {:table_name => "users"}
83
94
 
84
- `:primary_key` : Default value is `:id`. You can change the name of primary key column send it a symbol with the column name.
95
+ **primary_key**
96
+ - Default value is `:id`. You can change the name of primary key column send it a symbol with the column name.
85
97
 
86
98
  options = {:primary_key => :post_id}
87
99
 
88
- `:primary_key_mode` : Default value is `:auto`. When is `:auto` MassInsert knows that the database will generate the value of the primary key column automatically. If you pass `:manual` as primary key mode you need to create your value hashes with the key and value of the primary key column.
100
+ **primary_key_mode**
101
+ - Default value is `:auto`. When is `:auto` MassInsert knows that the database will generate the value of the primary key column automatically. If you pass `:manual` as primary key mode you need to create your value hashes with the key and value of the primary key column.
89
102
 
90
103
  options = {:primary_key_mode => :manual}
91
104
 
92
-
93
- ## Advantages
94
-
95
- Faster. It's depending of the computer but these are some results...
96
-
97
- * PostgreSQL - Saving 10,000 records in 0.84s
98
-
99
- ## Attention
100
-
101
- Since this is a single database insertion your model validation will be ignored, then if you use this gem you need to be sure that information is OK to be persisted.
102
-
103
105
  ## Contributing
104
106
 
105
107
  1. Fork it
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ namespace :spec do
5
5
  task :prepare do
6
6
  system("
7
7
  bundle install
8
+ cd spec/active_record_dummy
8
9
  rake db:drop db:create db:migrate RAILS_ENV=mysql2
9
10
  rake db:drop db:create db:migrate RAILS_ENV=postgresql
10
11
  rake db:drop db:create db:migrate RAILS_ENV=sqlite3
@@ -1,45 +1,24 @@
1
1
  module MassInsert
2
2
  module Adapters
3
3
  class Adapter
4
- include Helpers::AbstractQuery
5
- include Helpers::Timestamp
6
- include Helpers::Sanitizer
4
+ include AdapterHelpers
7
5
 
8
- attr_accessor :values, :options, :column_names
6
+ attr_accessor :values, :options, :columns
9
7
 
10
8
  def initialize values, options
11
9
  @values = values
12
10
  @options = options
13
11
  end
14
12
 
15
- # Returns the class like a constant that invokes the mass insert.
16
- # Should be a class that inherits from ActiveRecord::Base.
17
- def class_name
18
- options[:class_name]
13
+ # Returns the options according to the method that wasn't found.
14
+ def method_missing method, *args
15
+ @options.has_key?(method) ? @options[method] : super
19
16
  end
20
17
 
21
- # Returns a string with the database table name where all the records
22
- # will be saved.
23
- def table_name
24
- options[:table_name]
25
- end
26
-
27
- # Returns the array with the column names valid to be included into the
28
- # query string according to the options.
29
- def column_names
30
- @column_names ||= sanitized_columns
31
- end
32
-
33
- # Returns the primary_key column that was configured by the user.
34
- # Default primary_key it's id
35
- def primary_key
36
- options[:primary_key]
37
- end
38
-
39
- # Returns the primary key mode according to the user configuration.
40
- # Default primary key mode it's automatic.
41
- def primary_key_mode
42
- options[:primary_key_mode]
18
+ # Returns the array with the column names valid to be included into
19
+ # the query string according to the options.
20
+ def columns
21
+ @columns ||= sanitized_columns
43
22
  end
44
23
 
45
24
  end
@@ -1,6 +1,6 @@
1
1
  module MassInsert
2
2
  module Adapters
3
- module Helpers
3
+ module AdapterHelpers
4
4
  module AbstractQuery
5
5
 
6
6
  # Returns a begin string to a basic mysql query insertion. Include
@@ -12,7 +12,7 @@ module MassInsert
12
12
  # Returns a string with the column names to the class table name
13
13
  # and divided by commas.
14
14
  def string_columns
15
- "(#{column_names.join(", ")}) "
15
+ "(#{columns.join(", ")}) "
16
16
  end
17
17
 
18
18
  # Returns the string with all the row values that will be included
@@ -32,14 +32,14 @@ module MassInsert
32
32
  # according to the type column and values.
33
33
  # Before that row is prepared with the correct values.
34
34
  def string_single_row_values row
35
- row.merge!(timestamp_values) if timestamp?
36
- column_names.map{ |col| string_single_value(row, col) }.join(", ")
35
+ row.merge!(timestamp_hash) if timestamp?
36
+ columns.map{ |col| string_single_value(row, col) }.join(", ")
37
37
  end
38
38
 
39
39
  # Returns a single column string value with the correct format and
40
40
  # according to the database configuration, column type and presence.
41
41
  def string_single_value row, column
42
- ColumnValue.new(row, column, options).build
42
+ ColumnValue.new(row, column, class_name).build
43
43
  end
44
44
 
45
45
  # This functions calls the necessary functions to create a complete
@@ -1,20 +1,14 @@
1
1
  module MassInsert
2
2
  module Adapters
3
- module Helpers
3
+ module AdapterHelpers
4
4
  class ColumnValue
5
5
 
6
- attr_accessor :row, :column, :options
6
+ attr_accessor :row, :column, :class_name
7
7
 
8
- def initialize row, column, options
9
- @row = row
10
- @column = column
11
- @options = options
12
- end
13
-
14
- # Returns the class that invokes the mass insert process. The class
15
- # is in the options hash.
16
- def class_name
17
- options[:class_name]
8
+ def initialize row, column, class_name
9
+ @row = row
10
+ @column = column
11
+ @class_name = class_name
18
12
  end
19
13
 
20
14
  # Returns a symbol with the column type in the database. The column or
@@ -29,7 +23,7 @@ module MassInsert
29
23
  # if the symbol key doesn't exist it will try to find it by string
30
24
  # key. Otherwise it will return nil.
31
25
  def column_value
32
- row.fetch(column.to_sym){row[column.to_s]}
26
+ row.fetch(column){row[@column.to_s]}
33
27
  end
34
28
 
35
29
  # Returns the string with the database adapter name usually in the
@@ -1,16 +1,14 @@
1
1
  module MassInsert
2
2
  module Adapters
3
- module Helpers
3
+ module AdapterHelpers
4
4
  module Sanitizer
5
5
 
6
- # Returns an array with the column names in the database table like
7
- # a symbols.
6
+ # Returns an array with the columns in the table like symbols.
8
7
  def table_columns
9
8
  class_name.column_names.map(&:to_sym)
10
9
  end
11
10
 
12
- # Update the array with the columns names according to the options
13
- # and prepare the columns array with only valid columns.
11
+ # Prepare array with the column names according to the options.
14
12
  def sanitized_columns
15
13
  columns = table_columns
16
14
  columns.delete(primary_key) if primary_key_mode == :auto
@@ -0,0 +1,33 @@
1
+ module MassInsert
2
+ module Adapters
3
+ module AdapterHelpers
4
+ module Timestamp
5
+
6
+ # Returns true o false if the database table has timestamp columns.
7
+ def timestamp?
8
+ columns.include?(:created_at) && columns.include?(:updated_at)
9
+ end
10
+
11
+ # Returns timestamp format according to the database adapter. This
12
+ # function can be overwrite in database adapters classes.
13
+ def timestamp_format
14
+ "%Y-%m-%d %H:%M:%S.%6N"
15
+ end
16
+
17
+ # Returns the timestamp value according to the correct timestamp
18
+ # format to that database engine.
19
+ def timestamp
20
+ Time.now.strftime(timestamp_format)
21
+ end
22
+
23
+ # Returns the timestamp hash to be merge into row values that will
24
+ # be saved in the database.
25
+ def timestamp_hash
26
+ timestamp_value = timestamp
27
+ {:created_at => timestamp_value, :updated_at => timestamp_value}
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ Dir[File.dirname(__FILE__) + '/adapter_helpers/*.rb'].each{ |file| require file }
2
+
3
+ module MassInsert
4
+ module Adapters
5
+ module AdapterHelpers
6
+ include AbstractQuery
7
+ include Timestamp
8
+ include Sanitizer
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,5 @@
1
1
  module MassInsert
2
2
  module Adapters
3
- class PostgreSQLAdapter < Adapter
4
-
5
- end
3
+ class PostgreSQLAdapter < Adapter; end
6
4
  end
7
5
  end
@@ -1,7 +1,7 @@
1
1
  module MassInsert
2
2
  module Adapters
3
3
  autoload :Adapter, 'mass_insert/adapters/adapter.rb'
4
- autoload :Helpers, 'mass_insert/adapters/helpers.rb'
4
+ autoload :AdapterHelpers, 'mass_insert/adapters/adapter_helpers.rb'
5
5
  autoload :Mysql2Adapter, 'mass_insert/adapters/mysql2_adapter.rb'
6
6
  autoload :PostgreSQLAdapter, 'mass_insert/adapters/postgresql_adapter.rb'
7
7
  autoload :SQLite3Adapter, 'mass_insert/adapters/sqlite3_adapter.rb'
@@ -15,9 +15,7 @@ module MassInsert
15
15
  # complete the mass insertion process and save the time each method
16
16
  # takes being executed.
17
17
  def start
18
- # Calls the method that build the query.
19
18
  @build_time = Benchmark.measure{ build_query }
20
- # Calls the method that execute the query.
21
19
  @execute_time = Benchmark.measure{ execute_query }
22
20
  end
23
21
 
@@ -8,9 +8,8 @@ module MassInsert
8
8
  @options = options
9
9
  end
10
10
 
11
- # This function calls the correct adapter class and returns the
12
- # sql string ready to be executed and returns it to be execute in
13
- # the QueryExecution class.
11
+ # This function gets the correct adapter class and returns the
12
+ # sql string ready to be executed.
14
13
  def build
15
14
  adapter_class.new(values, options).execute
16
15
  end
@@ -21,10 +20,8 @@ module MassInsert
21
20
  ActiveRecord::Base.connection.instance_values["config"][:adapter]
22
21
  end
23
22
 
24
- # Returns an instance of the correct database adapter and this
25
- # instance will be called to generate the sql string. The values
26
- # and options are passed by params when the correct adapter class
27
- # is instanced.
23
+ # Returns the class of the correct database adapter according to the
24
+ # database engine that is used in Rails project.
28
25
  def adapter_class
29
26
  case adapter
30
27
  when "mysql2"
@@ -10,15 +10,15 @@ module MassInsert
10
10
  # class instances this class. The query can be a string or an array,
11
11
  # therefore to be sure that the query_container attribute is an array
12
12
  # the param passed to this class is converted to array. The query
13
- # container attribute will be iterated in execute method in this class
14
- # to execute each query that it contains.
13
+ # container attribute will be iterated in execute method to execute
14
+ # each query that it contains.
15
15
  def initialize query_container
16
16
  @query_container = Array(query_container)
17
17
  end
18
18
 
19
- # Saves queries contained in query_container attributes into database.
20
- # Use the helper that ActiveRecord provides. Query container attribute
21
- # is iterated to save each query that it contains.
19
+ # Saves queries contained in query_container attribute into database.
20
+ # Use the helper that ActiveRecord provides. The query_container
21
+ # attribute is iterated to save each query that it contains.
22
22
  def execute
23
23
  @query_container.each do |query|
24
24
  ActiveRecord::Base.connection.execute(query)
@@ -1,3 +1,3 @@
1
1
  module MassInsert
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,8 +1,9 @@
1
1
  require './spec/spec_helper'
2
2
  require "./lib/mass_insert"
3
3
 
4
- describe MassInsert::Adapters::Helpers::AbstractQuery do
5
- let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
4
+ describe MassInsert::Adapters::AdapterHelpers::AbstractQuery do
5
+ let!(:options){ {:class_name => "SomeClassName"} }
6
+ let!(:subject){ MassInsert::Adapters::Adapter.new([], options) }
6
7
 
7
8
  describe "#begin_string" do
8
9
  it "should respond to begin_string method" do
@@ -21,7 +22,7 @@ describe MassInsert::Adapters::Helpers::AbstractQuery do
21
22
  end
22
23
 
23
24
  it "should returns correct string to columns" do
24
- subject.stub(:column_names).and_return([:name, :email])
25
+ subject.stub(:columns).and_return([:name, :email])
25
26
  expect(subject.string_columns).to eq("(name, email) ")
26
27
  end
27
28
  end
@@ -69,23 +70,23 @@ describe MassInsert::Adapters::Helpers::AbstractQuery do
69
70
  end
70
71
 
71
72
  it "should returns the correct string" do
72
- subject.stub(:column_names).and_return([:name, :email])
73
+ subject.stub(:columns).and_return([:name, :email])
73
74
  expect(subject.string_single_row_values({})).to eq("value, value")
74
75
  end
75
76
 
76
77
  context "when respond to timestamp attributes" do
77
78
  it "should call timestamp_values method" do
78
- subject.stub(:column_names).and_return([:created_at, :updated_at])
79
- subject.stub(:timestamp_values).and_return(:test => "test")
80
- subject.should_receive(:timestamp_values).exactly(1).times
79
+ subject.stub(:columns).and_return([:created_at, :updated_at])
80
+ subject.stub(:timestamp_hash).and_return(:test => "test")
81
+ subject.should_receive(:timestamp_hash).exactly(1).times
81
82
  subject.string_single_row_values({})
82
83
  end
83
84
  end
84
85
 
85
86
  context "when not respond to timestamp attributes" do
86
87
  it "should returns the correct string" do
87
- subject.stub(:column_names).and_return([:name, :email])
88
- subject.should_receive(:timestamp_values).exactly(0).times
88
+ subject.stub(:columns).and_return([:name, :email])
89
+ subject.should_receive(:timestamp_hash).exactly(0).times
89
90
  subject.string_single_row_values({})
90
91
  end
91
92
  end
@@ -97,7 +98,7 @@ describe MassInsert::Adapters::Helpers::AbstractQuery do
97
98
  end
98
99
 
99
100
  it "should call build method in ColumnValue class" do
100
- column_value = MassInsert::Adapters::Helpers::ColumnValue.any_instance
101
+ column_value = MassInsert::Adapters::AdapterHelpers::ColumnValue.any_instance
101
102
  column_value.stub(:build).and_return("value")
102
103
  expect(subject.string_single_value({}, :name)).to eq("value")
103
104
  end
@@ -1,15 +1,15 @@
1
1
  require './spec/spec_helper'
2
2
  require "./lib/mass_insert"
3
3
 
4
- describe MassInsert::Adapters::Helpers::ColumnValue do
5
- let(:options) {{ :class_name => User }}
4
+ describe MassInsert::Adapters::AdapterHelpers::ColumnValue do
5
+ let(:class_name) { User }
6
6
  let(:row) {{ :name => "name", :age => 10 }}
7
7
  let(:column){ :name }
8
- let!(:subject){ MassInsert::Adapters::Helpers::ColumnValue.new(row, column, options) }
8
+ let!(:subject){ MassInsert::Adapters::AdapterHelpers::ColumnValue.new(row, column, class_name) }
9
9
 
10
10
  describe "#initialize" do
11
- it "should assign options param to option attribute" do
12
- expect(subject.options).to eq(options)
11
+ it "should assign class_name param to class_name attribute" do
12
+ expect(subject.class_name).to eq(class_name)
13
13
  end
14
14
 
15
15
  it "should assign column param to column attribute" do
@@ -21,23 +21,16 @@ describe MassInsert::Adapters::Helpers::ColumnValue do
21
21
  end
22
22
  end
23
23
 
24
- describe "#class_name" do
25
- it "should respond to class_name method" do
26
- expect(subject).to respond_to(:class_name)
27
- end
28
-
29
- it "should return the class_name in options" do
30
- expect(subject.class_name).to eq(User)
31
- end
32
- end
33
-
34
24
  describe "#column_type" do
35
25
  it "should respond to column_type method" do
36
26
  expect(subject).to respond_to(:column_type)
37
27
  end
38
28
 
39
29
  it "should return symbol :string" do
40
- expect(subject.column_type).to eq(:string)
30
+ subject.stub(:class_name).and_return("ClassName")
31
+ subject.class_name.stub(:columns_hash).and_return({"name" => "SomeObject"})
32
+ subject.class_name.columns_hash["name"].stub(:type).and_return(:column_type)
33
+ expect(subject.column_type).to eq(:column_type)
41
34
  end
42
35
  end
43
36
 
@@ -90,7 +83,10 @@ describe MassInsert::Adapters::Helpers::ColumnValue do
90
83
  end
91
84
 
92
85
  it "should return the default database value" do
93
- expect(subject.default_db_value).to eq(nil)
86
+ subject.stub(:class_name).and_return("ClassName")
87
+ subject.class_name.stub(:columns_hash).and_return({"name" => "SomeObject"})
88
+ subject.class_name.columns_hash["name"].stub(:default).and_return(:default_db_value)
89
+ expect(subject.default_db_value).to eq(:default_db_value)
94
90
  end
95
91
  end
96
92
 
@@ -1,7 +1,7 @@
1
1
  require './spec/spec_helper'
2
2
  require "./lib/mass_insert"
3
3
 
4
- describe MassInsert::Adapters::Helpers::Sanitizer do
4
+ describe MassInsert::Adapters::AdapterHelpers::Sanitizer do
5
5
  let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
6
6
 
7
7
  describe "#sanitized_columns" do
@@ -1,7 +1,7 @@
1
1
  require './spec/spec_helper'
2
2
  require "./lib/mass_insert"
3
3
 
4
- describe MassInsert::Adapters::Helpers::Timestamp do
4
+ describe MassInsert::Adapters::AdapterHelpers::Timestamp do
5
5
  let!(:subject){ MassInsert::Adapters::Adapter.new([], {}) }
6
6
 
7
7
  describe "#timestamp?" do
@@ -11,14 +11,14 @@ describe MassInsert::Adapters::Helpers::Timestamp do
11
11
 
12
12
  context "when respond to timestamp columns" do
13
13
  it "should return true" do
14
- subject.stub(:column_names).and_return([:updated_at, :created_at])
14
+ subject.stub(:columns).and_return([:updated_at, :created_at])
15
15
  expect(subject.timestamp?).to be_true
16
16
  end
17
17
  end
18
18
 
19
19
  context "when not respond to timestamp columns" do
20
20
  it "should return false" do
21
- subject.stub(:column_names).and_return([:created_at])
21
+ subject.stub(:columns).and_return([:created_at])
22
22
  expect(subject.timestamp?).to be_false
23
23
  end
24
24
  end
@@ -46,29 +46,29 @@ describe MassInsert::Adapters::Helpers::Timestamp do
46
46
  end
47
47
  end
48
48
 
49
- describe "#timestamp_values" do
50
- it "should respond_to timestamp_values method" do
51
- expect(subject).to respond_to(:timestamp_values)
49
+ describe "#timestamp_hash" do
50
+ it "should respond_to timestamp_hash method" do
51
+ expect(subject).to respond_to(:timestamp_hash)
52
52
  end
53
53
 
54
54
  context "when have high precision" do
55
55
  it "should no be equals" do
56
- timestamp_values = {
56
+ timestamp_hash_expected = {
57
57
  :created_at => subject.timestamp,
58
58
  :updated_at => subject.timestamp
59
59
  }
60
- expect(subject.timestamp_values).not_to eq(timestamp_values)
60
+ expect(subject.timestamp_hash).not_to eq(timestamp_hash_expected)
61
61
  end
62
62
  end
63
63
 
64
64
  context "when do not have precision" do
65
65
  it "should be equals" do
66
66
  subject.stub(:timestamp_format).and_return("%Y-%m-%d %H:%M:%S")
67
- timestamp_values = {
67
+ timestamp_hash_expected = {
68
68
  :created_at => subject.timestamp,
69
69
  :updated_at => subject.timestamp
70
70
  }
71
- expect(subject.timestamp_values).to eq(timestamp_values)
71
+ expect(subject.timestamp_hash).to eq(timestamp_hash_expected)
72
72
  end
73
73
  end
74
74
  end
@@ -0,0 +1,24 @@
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
@@ -19,10 +19,6 @@ describe MassInsert::Adapters::Adapter do
19
19
  end
20
20
 
21
21
  describe "#class_name" do
22
- it "should respond to class name method" do
23
- expect(subject).to respond_to(:class_name)
24
- end
25
-
26
22
  it "should returns the class_name in options" do
27
23
  subject.options = {:class_name => Test}
28
24
  expect(subject.class_name).to eq(Test)
@@ -30,17 +26,13 @@ describe MassInsert::Adapters::Adapter do
30
26
  end
31
27
 
32
28
  describe "#table_name" do
33
- it "should respond to table_name method" do
34
- expect(subject).to respond_to(:table_name)
35
- end
36
-
37
29
  it "should returns the table_name in options" do
38
30
  subject.options = {:table_name => "users"}
39
31
  expect(subject.table_name).to eq("users")
40
32
  end
41
33
  end
42
34
 
43
- describe "#column_names" do
35
+ describe "#columns" do
44
36
  before :each do
45
37
  subject.options.merge!({
46
38
  :class_name => Test,
@@ -49,31 +41,27 @@ describe MassInsert::Adapters::Adapter do
49
41
  })
50
42
  end
51
43
 
52
- it "should respond to column_names method" do
53
- expect(subject).to respond_to(:column_names)
44
+ it "should respond to columns method" do
45
+ expect(subject).to respond_to(:columns)
54
46
  end
55
47
 
56
48
  context "when primary_key is auto" do
57
49
  it "should return an array without primary key column" do
58
50
  column_names = [:name, :email]
59
- expect(subject.column_names).to eq(column_names)
51
+ expect(subject.columns).to eq(column_names)
60
52
  end
61
53
  end
62
54
 
63
55
  context "when primary key is manual" do
64
56
  it "should return an array with primary key column" do
65
57
  subject.options.merge!({:primary_key_mode => :manual})
66
- column_names = [:id, :name, :email]
67
- expect(subject.column_names).to eq(column_names)
58
+ columns_expected = [:id, :name, :email]
59
+ expect(subject.columns).to eq(columns_expected)
68
60
  end
69
61
  end
70
62
  end
71
63
 
72
64
  describe "#primary_key" do
73
- it "should respond to primary_key method" do
74
- expect(subject).to respond_to(:primary_key)
75
- end
76
-
77
65
  it "should returns the primary_key in options" do
78
66
  subject.options = {:primary_key => :user_id}
79
67
  expect(subject.primary_key).to eq(:user_id)
@@ -81,10 +69,6 @@ describe MassInsert::Adapters::Adapter do
81
69
  end
82
70
 
83
71
  describe "#primary_key_mode" do
84
- it "should respond to primary_key_mode method" do
85
- expect(subject).to respond_to(:primary_key_mode)
86
- end
87
-
88
72
  it "should returns the primary_key_mode in options" do
89
73
  subject.options = {:primary_key_mode => :auto}
90
74
  expect(subject.primary_key_mode).to eq(:auto)
@@ -11,7 +11,7 @@ describe MassInsert::Adapters do
11
11
  end
12
12
 
13
13
  it 'should define ColumnValue class' do
14
- expect(MassInsert::Adapters::Helpers).to be
14
+ expect(MassInsert::Adapters::AdapterHelpers).to be
15
15
  end
16
16
 
17
17
  it 'should define MysqlAdapter class' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mass_insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-01 00:00:00.000000000 Z
12
+ date: 2013-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -61,11 +61,11 @@ files:
61
61
  - lib/mass_insert.rb
62
62
  - lib/mass_insert/adapters.rb
63
63
  - lib/mass_insert/adapters/adapter.rb
64
- - lib/mass_insert/adapters/helpers.rb
65
- - lib/mass_insert/adapters/helpers/abstract_query.rb
66
- - lib/mass_insert/adapters/helpers/column_value.rb
67
- - lib/mass_insert/adapters/helpers/sanitizer.rb
68
- - lib/mass_insert/adapters/helpers/timestamp.rb
64
+ - lib/mass_insert/adapters/adapter_helpers.rb
65
+ - lib/mass_insert/adapters/adapter_helpers/abstract_query.rb
66
+ - lib/mass_insert/adapters/adapter_helpers/column_value.rb
67
+ - lib/mass_insert/adapters/adapter_helpers/sanitizer.rb
68
+ - lib/mass_insert/adapters/adapter_helpers/timestamp.rb
69
69
  - lib/mass_insert/adapters/mysql2_adapter.rb
70
70
  - lib/mass_insert/adapters/postgresql_adapter.rb
71
71
  - lib/mass_insert/adapters/sqlite3_adapter.rb
@@ -131,12 +131,12 @@ files:
131
131
  - spec/active_record_models/column_types/string_spec.rb
132
132
  - spec/active_record_models/model_spec.rb
133
133
  - spec/dummy_models/test.rb
134
+ - spec/mass_insert/adapters/adapter_helpers/abstract_query_spec.rb
135
+ - spec/mass_insert/adapters/adapter_helpers/column_value_spec.rb
136
+ - spec/mass_insert/adapters/adapter_helpers/sanitizer_spec.rb
137
+ - spec/mass_insert/adapters/adapter_helpers/timestamp_spec.rb
138
+ - spec/mass_insert/adapters/adapter_helpers_spec.rb
134
139
  - spec/mass_insert/adapters/adapter_spec.rb
135
- - spec/mass_insert/adapters/helpers/abstract_query_spec.rb
136
- - spec/mass_insert/adapters/helpers/column_value_spec.rb
137
- - spec/mass_insert/adapters/helpers/sanitizer_spec.rb
138
- - spec/mass_insert/adapters/helpers/timestamp_spec.rb
139
- - spec/mass_insert/adapters/helpers_spec.rb
140
140
  - spec/mass_insert/adapters/mysql_adapter_spec.rb
141
141
  - spec/mass_insert/adapters/postgresql_adapter_spec.rb
142
142
  - spec/mass_insert/adapters/sqlite3_adapter_spec.rb
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: -4593774517207519689
165
+ hash: -2888572193486115102
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements:
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: -4593774517207519689
174
+ hash: -2888572193486115102
175
175
  requirements: []
176
176
  rubyforge_project:
177
177
  rubygems_version: 1.8.25
@@ -235,12 +235,12 @@ test_files:
235
235
  - spec/active_record_models/column_types/string_spec.rb
236
236
  - spec/active_record_models/model_spec.rb
237
237
  - spec/dummy_models/test.rb
238
+ - spec/mass_insert/adapters/adapter_helpers/abstract_query_spec.rb
239
+ - spec/mass_insert/adapters/adapter_helpers/column_value_spec.rb
240
+ - spec/mass_insert/adapters/adapter_helpers/sanitizer_spec.rb
241
+ - spec/mass_insert/adapters/adapter_helpers/timestamp_spec.rb
242
+ - spec/mass_insert/adapters/adapter_helpers_spec.rb
238
243
  - spec/mass_insert/adapters/adapter_spec.rb
239
- - spec/mass_insert/adapters/helpers/abstract_query_spec.rb
240
- - spec/mass_insert/adapters/helpers/column_value_spec.rb
241
- - spec/mass_insert/adapters/helpers/sanitizer_spec.rb
242
- - spec/mass_insert/adapters/helpers/timestamp_spec.rb
243
- - spec/mass_insert/adapters/helpers_spec.rb
244
244
  - spec/mass_insert/adapters/mysql_adapter_spec.rb
245
245
  - spec/mass_insert/adapters/postgresql_adapter_spec.rb
246
246
  - spec/mass_insert/adapters/sqlite3_adapter_spec.rb
@@ -1,38 +0,0 @@
1
- module MassInsert
2
- module Adapters
3
- module Helpers
4
- module Timestamp
5
-
6
- # Returns true o false if the database table has the
7
- # timestamp columns.
8
- def timestamp?
9
- column_names.include?(:created_at) &&
10
- column_names.include?(:updated_at)
11
- end
12
-
13
- # Returns timestamp format according to the database adapter. This
14
- # function can be overwrite in database adapters classes to put the
15
- # correct format to that database.
16
- def timestamp_format
17
- "%Y-%m-%d %H:%M:%S.%6N"
18
- end
19
-
20
- # Returns the timestamp value with specific format according to the
21
- # correct timestamp format to that database.
22
- def timestamp
23
- Time.now.strftime(timestamp_format)
24
- end
25
-
26
- # Returns the timestamp values to be merge into row values that
27
- # will be saved in the database.
28
- def timestamp_values
29
- {
30
- :created_at => timestamp,
31
- :updated_at => timestamp
32
- }
33
- end
34
-
35
- end
36
- end
37
- end
38
- end
@@ -1,10 +0,0 @@
1
- module MassInsert
2
- module Adapters
3
- module Helpers
4
- autoload :AbstractQuery, 'mass_insert/adapters/helpers/abstract_query.rb'
5
- autoload :ColumnValue, 'mass_insert/adapters/helpers/column_value.rb'
6
- autoload :Timestamp, 'mass_insert/adapters/helpers/timestamp.rb'
7
- autoload :Sanitizer, 'mass_insert/adapters/helpers/sanitizer.rb'
8
- end
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- require './spec/spec_helper'
2
- require "./lib/mass_insert"
3
-
4
- describe MassInsert::Adapters::Helpers do
5
- it 'should be defined' do
6
- expect(MassInsert::Adapters::Helpers).to be
7
- end
8
-
9
- it 'should define AbstractQuery module' do
10
- expect(MassInsert::Adapters::Helpers::AbstractQuery).to be
11
- end
12
-
13
- it 'should define ColumnValue class' do
14
- expect(MassInsert::Adapters::Helpers::ColumnValue).to be
15
- end
16
-
17
- it 'should define Timestamp module' do
18
- expect(MassInsert::Adapters::Helpers::Timestamp).to be
19
- end
20
-
21
- it 'should define Sanitizer module' do
22
- expect(MassInsert::Adapters::Helpers::Sanitizer).to be
23
- end
24
- end