activerecord-import 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 90f09939f85ac5eea9961edb723ad60f0f44d4a8
4
- data.tar.gz: d50f35bc63818c96ffa772d157189d96a738784b
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzExZGVjNzkyYjBhNmZiMDE4MmQ4NTBmMTNiMGFlOTg3M2ZjMjcyOA==
5
+ data.tar.gz: !binary |-
6
+ MDRjY2QxYTc1NmViOGI5MDM1Yjg5ODY1YmY3ZjU0ZGJkMGRiOTFhZA==
5
7
  SHA512:
6
- metadata.gz: 4f4cf1a65474d658e5091b60b12756f70c6fe1af84d0b2477777f27cc76d137eb1bc7064ab8d33d548c0c8de01df494ec0fdddf73d7e55416fc772750bb9899a
7
- data.tar.gz: 0b3a592bdbe01be8dd244f52643875825b2c52d8a8ec283f9825cf17012feddb394f131aa9a0722cdf89d9a8a6835ddff0a219b86e4d4049b70f8aca1f808b50
8
+ metadata.gz: !binary |-
9
+ YmUyZGIyZWQ1MjI1MGZkN2VkZTk0NGZlZmUyZWFmZDY0OTc3NjU3OTQzZWI5
10
+ ZTk2NGFkNjc1MjVkOGE2MGQyNTM2OTc1N2YzYjQyYmFlNjA0M2FhNjRiMDEz
11
+ YTgyNTk4MjIxOTUwYzYwOWM1ZmE5ZGQ0NDcyODkzNGNkNGYwMWU=
12
+ data.tar.gz: !binary |-
13
+ ZmRlNTc0NjhhNmYxZmNiNDFjNzZlNTM1ODcxNTNiNzE3NmUyYjhjMjliYjU4
14
+ MGY5NmYyN2JhY2FjMmQ3ZWFiODE3ZTY3OTgxMDA5M2Y5MTkwZjIyNWU2Y2Ni
15
+ MWUyYTRlODNiMzg1YzYyNDEzMmFjZTBhZTEwMzFkZGU0MDI5ZTE=
@@ -1,3 +1,14 @@
1
+ ## Changes in 0.16.2
2
+
3
+ ### Fixes
4
+
5
+ * Fixes issue clearing query cache on wrong connection when using
6
+ multiple databases. Thanks to @KentoMoriwaki via \#337
7
+ * Raises an ArgumentError on incorrect usage of nested arrays. Thanks
8
+ to @Nitrodist via \#340
9
+ * Fixes issue that prevented uuid primary keys from being set manually.
10
+ Thanks to @Dclusin-og, @jkowens via \#342
11
+
1
12
  ## Changes in 0.16.1
2
13
 
3
14
  ### Fixes
@@ -29,7 +29,11 @@ Use activerecord-import 0.11.0 or higher.
29
29
 
30
30
  Use activerecord-import 0.4.0 or higher.
31
31
 
32
- ### Rails 3.1.x up to, but not including 4.0
32
+ ### Rails 3.2.x up to, but not including 4.0
33
+
34
+ Use activerecord-import 0.3.0 or higher.
35
+
36
+ ### Rails 3.1.x up to, but not including 3.2
33
37
 
34
38
  Use the latest in the activerecord-import 0.3.x series.
35
39
 
@@ -60,7 +64,7 @@ To understand how rubygems loads code you can reference the following:
60
64
  And an example of how active_record dynamically load adapters:
61
65
  https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/connection_specification.rb
62
66
 
63
- In summary, when a gem is loaded rubygems adds the `lib` folder of the gem to the global load path `$LOAD_PATH` so that all `require` lookups will not propegate through all of the folders on the load path. When a `require` is issued each folder on the `$LOAD_PATH` is checked for the file and/or folder referenced. This allows a gem (like activerecord-import) to define push the activerecord-import folder (or namespace) on the `$LOAD_PATH` and any adapters provided by activerecord-import will be found by rubygems when the require is issued.
67
+ In summary, when a gem is loaded rubygems adds the `lib` folder of the gem to the global load path `$LOAD_PATH` so that all `require` lookups will not propagate through all of the folders on the load path. When a `require` is issued each folder on the `$LOAD_PATH` is checked for the file and/or folder referenced. This allows a gem (like activerecord-import) to define push the activerecord-import folder (or namespace) on the `$LOAD_PATH` and any adapters provided by activerecord-import will be found by rubygems when the require is issued.
64
68
 
65
69
  If `fake_name` adapter is needed by a gem (potentially called `activerecord-import-fake_name`) then the folder structure should look as follows:
66
70
 
@@ -17,12 +17,11 @@ module ActiveRecord::Import::PostgreSQLAdapter
17
17
  sql2insert = base_sql + values.join( ',' ) + post_sql
18
18
  if post_sql =~ /RETURNING\s/
19
19
  ids = select_values( sql2insert, *args )
20
+ query_cache.clear if query_cache_enabled
20
21
  else
21
22
  insert( sql2insert, *args )
22
23
  end
23
24
 
24
- ActiveRecord::Base.connection.query_cache.clear
25
-
26
25
  [number_of_inserts, ids]
27
26
  end
28
27
 
@@ -367,15 +367,13 @@ class ActiveRecord::Base
367
367
  column_names = self.column_names.dup
368
368
  end
369
369
 
370
- if column_names.include?(primary_key) && columns_hash[primary_key].type == :uuid
370
+ if models.first.id.nil? && column_names.include?(primary_key) && columns_hash[primary_key].type == :uuid
371
371
  column_names.delete(primary_key)
372
372
  end
373
373
 
374
374
  stored_attrs = respond_to?(:stored_attributes) ? stored_attributes : {}
375
375
 
376
376
  array_of_attributes = models.map do |model|
377
- # this next line breaks sqlite.so with a segmentation fault
378
- # if model.new_record? || options[:on_duplicate_key_update]
379
377
  column_names.map do |name|
380
378
  if stored_attrs.any? && stored_attrs.key?(name.to_sym)
381
379
  model.read_attribute(name.to_s)
@@ -383,13 +381,17 @@ class ActiveRecord::Base
383
381
  model.read_attribute_before_type_cast(name.to_s)
384
382
  end
385
383
  end
386
- # end
387
384
  end
388
385
  # supports empty array
389
386
  elsif args.last.is_a?( Array ) && args.last.empty?
390
387
  return ActiveRecord::Import::Result.new([], 0, [])
391
388
  # supports 2-element array and array
392
389
  elsif args.size == 2 && args.first.is_a?( Array ) && args.last.is_a?( Array )
390
+
391
+ unless args.last.first.is_a?(Array)
392
+ raise ArgumentError, "Last argument should be a two dimensional array '[[]]'. First element in array was a #{args.last.first.class}"
393
+ end
394
+
393
395
  column_names, array_of_attributes = args
394
396
 
395
397
  # dup the passed args so we don't modify unintentionally
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "0.16.1".freeze
3
+ VERSION = "0.16.2".freeze
4
4
  end
5
5
  end
@@ -12,6 +12,11 @@ describe "#import" do
12
12
  end
13
13
  end
14
14
 
15
+ it "warns you that you're using the library wrong" do
16
+ error = assert_raise(ArgumentError) { Topic.import %w(title author_name), ['Author #1', 'Book #1', 0] }
17
+ assert_equal error.message, "Last argument should be a two dimensional array '[[]]'. First element in array was a String"
18
+ end
19
+
15
20
  it "should not produce an error when importing empty arrays" do
16
21
  assert_nothing_raised do
17
22
  Topic.import []
@@ -59,19 +59,34 @@ def should_support_postgresql_import_functionality
59
59
  end
60
60
  end
61
61
 
62
- describe "with a uuid primary key" do
63
- let(:vendor) { Vendor.new(name: "foo") }
64
- let(:vendors) { [vendor] }
62
+ if ENV['AR_VERSION'].to_f >= 4.0
63
+ describe "with a uuid primary key" do
64
+ let(:vendor) { Vendor.new(name: "foo") }
65
+ let(:vendors) { [vendor] }
65
66
 
66
- it "creates records" do
67
- assert_difference "Vendor.count", +1 do
67
+ it "creates records" do
68
+ assert_difference "Vendor.count", +1 do
69
+ Vendor.import vendors
70
+ end
71
+ end
72
+
73
+ it "assigns an id to the model objects" do
68
74
  Vendor.import vendors
75
+ assert_not_nil vendor.id
69
76
  end
70
77
  end
71
78
 
72
- it "assigns an id to the model objects" do
73
- Vendor.import vendors
74
- assert_not_nil vendor.id
79
+ describe "with an assigned uuid primary key" do
80
+ let(:id) { SecureRandom.uuid }
81
+ let(:vendor) { Vendor.new(id: id, name: "foo") }
82
+ let(:vendors) { [vendor] }
83
+
84
+ it "creates records with correct id" do
85
+ assert_difference "Vendor.count", +1 do
86
+ Vendor.import vendors
87
+ end
88
+ assert_equal id, vendor.id
89
+ end
75
90
  end
76
91
  end
77
92
 
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-11 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Extraction of the ActiveRecord::Base#import functionality from ar-extensions
@@ -46,10 +46,10 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".gitignore"
50
- - ".rubocop.yml"
51
- - ".rubocop_todo.yml"
52
- - ".travis.yml"
49
+ - .gitignore
50
+ - .rubocop.yml
51
+ - .rubocop_todo.yml
52
+ - .travis.yml
53
53
  - Brewfile
54
54
  - CHANGELOG.md
55
55
  - Gemfile
@@ -160,12 +160,12 @@ require_paths:
160
160
  - lib
161
161
  required_ruby_version: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - ">="
163
+ - - ! '>='
164
164
  - !ruby/object:Gem::Version
165
165
  version: 1.9.2
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
- - - ">="
168
+ - - ! '>='
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  requirements: []