mass_insert 0.0.1
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 +17 -0
- data/.rspec +1 -0
- data/.rvmrc +53 -0
- data/.travis.yml +4 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +45 -0
- data/lib/mass_insert.rb +13 -0
- data/lib/mass_insert/adapters.rb +12 -0
- data/lib/mass_insert/adapters/abstract_query.rb +47 -0
- data/lib/mass_insert/adapters/adapter.rb +56 -0
- data/lib/mass_insert/adapters/column_value.rb +107 -0
- data/lib/mass_insert/adapters/helpers.rb +8 -0
- data/lib/mass_insert/adapters/helpers/sanitizer.rb +17 -0
- data/lib/mass_insert/adapters/helpers/timestamp.rb +38 -0
- data/lib/mass_insert/adapters/mysql2_adapter.rb +21 -0
- data/lib/mass_insert/adapters/postgresql_adapter.rb +15 -0
- data/lib/mass_insert/adapters/sqlite3_adapter.rb +37 -0
- data/lib/mass_insert/adapters/sqlserver_adapter.rb +23 -0
- data/lib/mass_insert/base.rb +43 -0
- data/lib/mass_insert/process_control.rb +24 -0
- data/lib/mass_insert/query_builder.rb +42 -0
- data/lib/mass_insert/query_execution.rb +29 -0
- data/lib/mass_insert/version.rb +3 -0
- data/mass_insert.gemspec +22 -0
- data/spec/active_record_dummy/.gitignore +15 -0
- data/spec/active_record_dummy/Gemfile +40 -0
- data/spec/active_record_dummy/README.rdoc +261 -0
- data/spec/active_record_dummy/Rakefile +7 -0
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +15 -0
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/active_record_dummy/app/controllers/application_controller.rb +3 -0
- data/spec/active_record_dummy/app/helpers/application_helper.rb +2 -0
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/.gitkeep +0 -0
- data/spec/active_record_dummy/app/models/user.rb +3 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/active_record_dummy/config.ru +4 -0
- data/spec/active_record_dummy/config/application.rb +68 -0
- data/spec/active_record_dummy/config/boot.rb +6 -0
- data/spec/active_record_dummy/config/database.yml +54 -0
- data/spec/active_record_dummy/config/environment.rb +5 -0
- data/spec/active_record_dummy/config/environments/development.rb +37 -0
- data/spec/active_record_dummy/config/environments/mysql2.rb +37 -0
- data/spec/active_record_dummy/config/environments/postgresql.rb +37 -0
- data/spec/active_record_dummy/config/environments/production.rb +67 -0
- data/spec/active_record_dummy/config/environments/sqlite3.rb +37 -0
- data/spec/active_record_dummy/config/environments/test.rb +37 -0
- data/spec/active_record_dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/active_record_dummy/config/initializers/inflections.rb +15 -0
- data/spec/active_record_dummy/config/initializers/mime_types.rb +5 -0
- data/spec/active_record_dummy/config/initializers/secret_token.rb +7 -0
- data/spec/active_record_dummy/config/initializers/session_store.rb +8 -0
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/active_record_dummy/config/locales/en.yml +5 -0
- data/spec/active_record_dummy/config/routes.rb +58 -0
- data/spec/active_record_dummy/db/migrate/20130412154541_create_users.rb +14 -0
- data/spec/active_record_dummy/db/schema.rb +27 -0
- data/spec/active_record_dummy/db/seeds.rb +7 -0
- data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
- data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/active_record_dummy/log/.gitkeep +0 -0
- data/spec/active_record_dummy/public/404.html +26 -0
- data/spec/active_record_dummy/public/422.html +26 -0
- data/spec/active_record_dummy/public/500.html +25 -0
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +241 -0
- data/spec/active_record_dummy/public/robots.txt +5 -0
- data/spec/active_record_dummy/script/rails +6 -0
- data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/active_record_models/column_types/binary_spec.rb +60 -0
- data/spec/active_record_models/column_types/boolean_spec.rb +52 -0
- data/spec/active_record_models/column_types/decimal_spec.rb +49 -0
- data/spec/active_record_models/column_types/integer_spec.rb +49 -0
- data/spec/active_record_models/column_types/string_spec.rb +50 -0
- data/spec/active_record_models/model_spec.rb +50 -0
- data/spec/dummy_models/test.rb +5 -0
- data/spec/mass_insert/adapters/abstract_query_spec.rb +109 -0
- data/spec/mass_insert/adapters/adapter_spec.rb +117 -0
- data/spec/mass_insert/adapters/column_value_spec.rb +292 -0
- data/spec/mass_insert/adapters/helpers/sanitizer_spec.rb +39 -0
- data/spec/mass_insert/adapters/helpers/timestamp_spec.rb +79 -0
- data/spec/mass_insert/adapters/helpers_spec.rb +16 -0
- data/spec/mass_insert/adapters/mysql_adapter_spec.rb +39 -0
- data/spec/mass_insert/adapters/postgresql_adapter_spec.rb +29 -0
- data/spec/mass_insert/adapters/sqlite3_adapter_spec.rb +90 -0
- data/spec/mass_insert/adapters/sqlserver_adapter_spec.rb +56 -0
- data/spec/mass_insert/adapters_spec.rb +40 -0
- data/spec/mass_insert/base_spec.rb +98 -0
- data/spec/mass_insert/process_control_spec.rb +56 -0
- data/spec/mass_insert/query_builder_spec.rb +88 -0
- data/spec/mass_insert/query_execution_spec.rb +53 -0
- data/spec/mass_insert_spec.rb +28 -0
- data/spec/spec_helper.rb +6 -0
- metadata +254 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
require 'rails/commands'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
|
|
4
|
+
describe "Binary" do
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
@values, @options = [{:checked => 1}], {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when exist in values hashes" do
|
|
11
|
+
context "when contains binary value" do
|
|
12
|
+
context "when is 1" do
|
|
13
|
+
it "should be saved correctly" do
|
|
14
|
+
User.mass_insert(@values, @options)
|
|
15
|
+
User.last.checked.should eq("1")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when is 0" do
|
|
20
|
+
it "should be saved correctly" do
|
|
21
|
+
@values.first.merge!(:checked => 0)
|
|
22
|
+
User.mass_insert(@values, @options)
|
|
23
|
+
User.last.checked.should eq("0")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when contains a string" do
|
|
29
|
+
it "should convert string value to binary" do
|
|
30
|
+
@values.first.merge!(:checked => "string")
|
|
31
|
+
User.mass_insert(@values, @options)
|
|
32
|
+
User.last.checked.should eq("string")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when contains a decimal" do
|
|
37
|
+
it "should convert decimal value to binary" do
|
|
38
|
+
@values.first.merge!(:checked => 25.34)
|
|
39
|
+
User.mass_insert(@values, @options)
|
|
40
|
+
User.last.checked.should eq("25.34")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when contains a boolean" do
|
|
45
|
+
it "should convert boolean value to binary" do
|
|
46
|
+
@values.first.merge!(:checked => true)
|
|
47
|
+
User.mass_insert(@values, @options)
|
|
48
|
+
User.last.checked.should eq("true")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "when not exist in values hashes" do
|
|
54
|
+
it "should save the default value" do
|
|
55
|
+
@values.first.delete(:checked)
|
|
56
|
+
User.mass_insert(@values, @options)
|
|
57
|
+
User.last.checked.should eq(nil)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
|
|
4
|
+
describe "Boolean" do
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
@values, @options = [{:active => true}], {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when exist in values hashes" do
|
|
11
|
+
context "when contains boolean value" do
|
|
12
|
+
context "when is true" do
|
|
13
|
+
it "should be saved correctly" do
|
|
14
|
+
User.mass_insert(@values, @options)
|
|
15
|
+
User.last.active.should eq(true)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when is false" do
|
|
20
|
+
it "should be saved correctly" do
|
|
21
|
+
@values.first.merge!(:active => false)
|
|
22
|
+
User.mass_insert(@values, @options)
|
|
23
|
+
User.last.active.should eq(false)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when contains a string" do
|
|
29
|
+
it "should convert string value to boolean" do
|
|
30
|
+
@values.first.merge!(:active => "string")
|
|
31
|
+
User.mass_insert(@values, @options)
|
|
32
|
+
User.last.active.should eq(true)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when contains a decimal" do
|
|
37
|
+
it "should convert decimal value to boolean" do
|
|
38
|
+
@values.first.merge!(:active => 25.34)
|
|
39
|
+
User.mass_insert(@values, @options)
|
|
40
|
+
User.last.active.should eq(true)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when not exist in values hashes" do
|
|
46
|
+
it "should save the default value" do
|
|
47
|
+
@values.first.delete(:active)
|
|
48
|
+
User.mass_insert(@values, @options)
|
|
49
|
+
User.last.active.should eq(nil)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
|
|
4
|
+
describe "Decimal" do
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
@values, @options = [{:money => 20.50}], {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when exist in values hashes" do
|
|
11
|
+
context "when contains an integer" do
|
|
12
|
+
it "should convert integer value to decimal" do
|
|
13
|
+
@values.first.merge!(:money => 10)
|
|
14
|
+
User.mass_insert(@values, @options)
|
|
15
|
+
User.last.money.should eq(10.0)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when contains a string" do
|
|
20
|
+
it "should convert string value to decimal" do
|
|
21
|
+
@values.first.merge!(:money => "string")
|
|
22
|
+
User.mass_insert(@values, @options)
|
|
23
|
+
User.last.money.should eq(0.0)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when contains a decimal" do
|
|
28
|
+
it "should save the correct value" do
|
|
29
|
+
User.mass_insert(@values, @options)
|
|
30
|
+
User.last.money.should eq(20.50)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when contains a boolean" do
|
|
35
|
+
it "should raise an exception" do
|
|
36
|
+
@values.first.merge!(:money => true)
|
|
37
|
+
lambda{ User.mass_insert(@values, @options) }.should raise_exception
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "when not exist in values hashes" do
|
|
43
|
+
it "should save the default value" do
|
|
44
|
+
@values.first.delete(:money)
|
|
45
|
+
User.mass_insert(@values, @options)
|
|
46
|
+
User.last.money.should eq(nil)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
|
|
4
|
+
describe "Integer" do
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
@values, @options = [{:age => 20}], {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when exist in values hashes" do
|
|
11
|
+
context "when contains an integer" do
|
|
12
|
+
it "should be saved correctly" do
|
|
13
|
+
User.mass_insert(@values, @options)
|
|
14
|
+
User.last.age.should eq(20)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when contains a string" do
|
|
19
|
+
it "should convert string value to integer" do
|
|
20
|
+
@values.first.merge!(:age => "string")
|
|
21
|
+
User.mass_insert(@values, @options)
|
|
22
|
+
User.last.age.should eq(0)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "when contains a decimal" do
|
|
27
|
+
it "should convert decimal value to integer" do
|
|
28
|
+
@values.first.merge!(:age => 25.69)
|
|
29
|
+
User.mass_insert(@values, @options)
|
|
30
|
+
User.last.age.should eq(25)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when contains a boolean" do
|
|
35
|
+
it "should raise an exception" do
|
|
36
|
+
@values.first.merge!(:age => true)
|
|
37
|
+
lambda{ User.mass_insert(@values, @options) }.should raise_exception
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "when not exist in values hashes" do
|
|
43
|
+
it "should save the default value" do
|
|
44
|
+
@values.first.delete(:age)
|
|
45
|
+
User.mass_insert(@values, @options)
|
|
46
|
+
User.last.age.should eq(nil)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
|
|
4
|
+
describe "String" do
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
@values, @options = [{:name => "some name"}], {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when exist in values hashes" do
|
|
11
|
+
context "when contains a string" do
|
|
12
|
+
it "should be saved correctly" do
|
|
13
|
+
User.mass_insert(@values, @options)
|
|
14
|
+
User.last.name.should eq("some name")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when contains a integer" do
|
|
19
|
+
it "should convert integer value to string" do
|
|
20
|
+
@values.first.merge!(:name => 10)
|
|
21
|
+
User.mass_insert(@values, @options)
|
|
22
|
+
User.last.name.should eq("10")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "when contains a decimal" do
|
|
27
|
+
it "should convert decimal value to string" do
|
|
28
|
+
@values.first.merge!(:name => 25.69)
|
|
29
|
+
User.mass_insert(@values, @options)
|
|
30
|
+
User.last.name.should eq("25.69")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when contains a boolean" do
|
|
35
|
+
it "should convert boolean value to string" do
|
|
36
|
+
@values.first.merge!(:name => true)
|
|
37
|
+
User.mass_insert(@values, @options)
|
|
38
|
+
User.last.name.should eq("true")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "when not exist in values hashes" do
|
|
44
|
+
it "should save the default value" do
|
|
45
|
+
@values.first.delete(:name)
|
|
46
|
+
User.mass_insert(@values, @options)
|
|
47
|
+
User.last.name.should eq(nil)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
require "./spec/dummy_models/test"
|
|
4
|
+
|
|
5
|
+
describe "Model" do
|
|
6
|
+
|
|
7
|
+
before :each do
|
|
8
|
+
@values, @options = [], {}
|
|
9
|
+
@value_hash = {
|
|
10
|
+
:name => "some_name",
|
|
11
|
+
:email => "some_email",
|
|
12
|
+
:age => 20,
|
|
13
|
+
:active => true,
|
|
14
|
+
:checked => true
|
|
15
|
+
}
|
|
16
|
+
User.delete_all
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "when is used without options" do
|
|
20
|
+
it "should save 5 record into users table" do
|
|
21
|
+
5.times{ @values << @value_hash }
|
|
22
|
+
User.mass_insert(@values, @options)
|
|
23
|
+
User.count.should eq(5)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should save if values cointains 1500 records" do
|
|
27
|
+
1500.times{ @values << @value_hash }
|
|
28
|
+
User.mass_insert(@values, @options)
|
|
29
|
+
User.count.should eq(1500)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "when is used with options" do
|
|
34
|
+
context "when the table name doesn't exit" do
|
|
35
|
+
it "should not save any record" do
|
|
36
|
+
5.times{ @values << @value_hash }
|
|
37
|
+
@options.merge!(:table_name => "countries")
|
|
38
|
+
lambda{ User.mass_insert(@values, @options) }.should raise_exception
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "when the class name not inherit from ActiveRecord" do
|
|
43
|
+
it "should not save any record" do
|
|
44
|
+
5.times{ @values << @value_hash }
|
|
45
|
+
@options.merge!(:class_name => Test)
|
|
46
|
+
lambda{ User.mass_insert(@values, @options) }.should raise_exception
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require './spec/spec_helper'
|
|
2
|
+
require "./lib/mass_insert"
|
|
3
|
+
|
|
4
|
+
describe MassInsert::Adapters::AbstractQuery do
|
|
5
|
+
before :each do
|
|
6
|
+
@adapter = MassInsert::Adapters::Adapter.new([], {})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
subject{ @adapter }
|
|
10
|
+
|
|
11
|
+
describe "#begin_string" do
|
|
12
|
+
it "should respond to begin_string method" do
|
|
13
|
+
subject.respond_to?(:begin_string).should be_true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should returns the correct string" do
|
|
17
|
+
subject.stub(:table_name).and_return("users")
|
|
18
|
+
string = "INSERT INTO users "
|
|
19
|
+
subject.begin_string.should eq(string)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "#string_columns" do
|
|
24
|
+
it "should respond to string_columns method" do
|
|
25
|
+
subject.respond_to?(:string_columns).should be_true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should returns correct string to columns" do
|
|
29
|
+
subject.stub(:column_names).and_return([:name, :email])
|
|
30
|
+
subject.string_columns.should eq("(name, email) ")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#string_values" do
|
|
35
|
+
it "should respond to string_values method" do
|
|
36
|
+
subject.respond_to?(:string_values).should be_true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should returns correct string to values" do
|
|
40
|
+
subject.stub(:string_rows_values).and_return("string_rows_values")
|
|
41
|
+
subject.string_values.should eq("VALUES (string_rows_values);")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "#string_rows_values" do
|
|
46
|
+
it "should respond to string_rows_values method" do
|
|
47
|
+
subject.respond_to?(:string_rows_values).should be_true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "when only have one value hash" do
|
|
51
|
+
it "should returns the correct string" do
|
|
52
|
+
subject.stub(:string_single_row_values).and_return("single_row")
|
|
53
|
+
subject.values = [{}]
|
|
54
|
+
subject.string_rows_values.should eq("single_row")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when have two or more value hashes" do
|
|
59
|
+
it "should returns the correct string" do
|
|
60
|
+
subject.stub(:string_single_row_values).and_return("single_row")
|
|
61
|
+
subject.values = [{}, {}]
|
|
62
|
+
subject.string_rows_values.should eq("single_row), (single_row")
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe "#string_single_row_values" do
|
|
68
|
+
it "should respond to string_single_row_values method" do
|
|
69
|
+
subject.respond_to?(:string_single_row_values).should be_true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should returns the correct string" do
|
|
73
|
+
subject.stub(:string_single_value).and_return("single_value")
|
|
74
|
+
subject.stub(:column_names).and_return([:name, :email])
|
|
75
|
+
subject.string_single_row_values({}).should eq("single_value, single_value")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "when respond to timestamp attributes" do
|
|
79
|
+
it "should call timestamp_values method" do
|
|
80
|
+
subject.stub(:string_single_value).and_return("single_value")
|
|
81
|
+
subject.stub(:column_names).and_return([:created_at, :updated_at])
|
|
82
|
+
subject.stub(:timestamp_values).and_return(:test => "test")
|
|
83
|
+
subject.should_receive(:timestamp_values).exactly(1).times
|
|
84
|
+
subject.string_single_row_values({})
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "when not respond to timestamp attributes" do
|
|
89
|
+
it "should returns the correct string" do
|
|
90
|
+
subject.stub(:string_single_value).and_return("single_value")
|
|
91
|
+
subject.stub(:column_names).and_return([:name, :email])
|
|
92
|
+
subject.should_receive(:timestamp_values).exactly(0).times
|
|
93
|
+
subject.string_single_row_values({})
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "#string_single_value" do
|
|
99
|
+
it "should respond to string_single_value method" do
|
|
100
|
+
subject.respond_to?(:string_single_value).should be_true
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should call build method in ColumnValue class" do
|
|
104
|
+
column_value = MassInsert::Adapters::ColumnValue.any_instance
|
|
105
|
+
column_value.stub(:build).and_return("single_value")
|
|
106
|
+
subject.string_single_value({}, :name).should eq("single_value")
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|