activerecord-import 0.17.1 → 0.17.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3e8c2443ad40d5d2a2b22c304ebc88780834b0b
4
- data.tar.gz: f55f0a5b40c6ba2dee599c13a2c2de83eeeefc6b
3
+ metadata.gz: 5482a79b112f9689eee0261baa906028abd8575f
4
+ data.tar.gz: 2f3e76132e6110a5ed17db800f173b5291ddfe8d
5
5
  SHA512:
6
- metadata.gz: 967eb0e53dd4bb1c8267263788d9dea872f8c4f431dfc5516d819fad1cbc5c6bae20000bf0bb29c6c045012c8f61cdfd93232e5f46a34ef78216247a179ae811
7
- data.tar.gz: 73f3dd915a1ad43f22d0d0cc03dc7ccc717191180e05cbce8d35ddbe91ea3a747730f655443cfac34a8aae036a2117bf54bd347c6fbb3998193169fc9175dcdf
6
+ metadata.gz: 509fe999b0343506f4b1263909d24079394d82d8d3aa16fa5210f35a88b92f40954141949ee7a5f979a81f6105838f0471c5c8cdcfa75a30a5abd38fc96cd1f8
7
+ data.tar.gz: 517d7de4678ddf9361647f18d08d95c2256e244ae3e6241413abde6b83992e62f4640279c42abdea8bbc710855800840fd2bf941bdca1b447693f2d82cbaa987
data/.travis.yml CHANGED
@@ -16,11 +16,10 @@ env:
16
16
 
17
17
  matrix:
18
18
  include:
19
- - rvm: jruby-9.0.5.0
19
+ - rvm: jruby-9.1.7.0
20
20
  env: AR_VERSION=4.2
21
21
  before_install:
22
- - gem uninstall -i /home/travis/.rvm/gems/jruby-9.0.5.0@global bundler
23
- - gem install bundler -v 1.13.7 --no-rdoc --no-ri --no-document
22
+ - gem update --system
24
23
 
25
24
  script:
26
25
  - bundle exec rake test:jdbcsqlite3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## Changes in 0.17.2
2
+
3
+ ### Fixes
4
+
5
+ * Fix issue where PostgreSQL cannot recognize columns if names
6
+ include mixed case characters. Thanks to @hugobgranja via \#379.
7
+ * Fix an issue for ActiveRecord 5 where serialized fields with
8
+ default values were not being typecast. Thanks to @whistlerbrk,
9
+ @jkowens via \#386.
10
+ * Add option :force_single_insert for MySQL to make sure a single
11
+ insert is attempted instead of performing multiple inserts based
12
+ on max_allowed_packet. Thanks to @mtparet via \#387.
13
+
1
14
  ## Changes in 0.17.1
2
15
 
3
16
  ### Fixes
@@ -59,12 +59,6 @@ module ActiveRecord::Import::AbstractAdapter
59
59
  post_sql_statements
60
60
  end
61
61
 
62
- # Returns the maximum number of bytes that the server will allow
63
- # in a single packet
64
- def max_allowed_packet
65
- NO_MAX_PACKET
66
- end
67
-
68
62
  def supports_on_duplicate_key_update?
69
63
  false
70
64
  end
@@ -7,7 +7,7 @@ module ActiveRecord::Import::MysqlAdapter
7
7
 
8
8
  # +sql+ can be a single string or an array. If it is an array all
9
9
  # elements that are in position >= 1 will be appended to the final SQL.
10
- def insert_many( sql, values, _options = {}, *args ) # :nodoc:
10
+ def insert_many( sql, values, options = {}, *args ) # :nodoc:
11
11
  # the number of inserts default
12
12
  number_of_inserts = 0
13
13
 
@@ -31,7 +31,7 @@ module ActiveRecord::Import::MysqlAdapter
31
31
  max = max_allowed_packet
32
32
 
33
33
  # if we can insert it all as one statement
34
- if NO_MAX_PACKET == max || total_bytes <= max
34
+ if NO_MAX_PACKET == max || total_bytes <= max || options[:force_single_insert]
35
35
  number_of_inserts += 1
36
36
  sql2insert = base_sql + values.join( ',' ) + post_sql
37
37
  insert( sql2insert, *args )
@@ -52,7 +52,7 @@ module ActiveRecord::Import::PostgreSQLAdapter
52
52
 
53
53
  unless options[:no_returning] || options[:primary_key].blank?
54
54
  primary_key = Array(options[:primary_key])
55
- sql << " RETURNING #{primary_key.join(', ')}"
55
+ sql << " RETURNING \"#{primary_key.join('", "')}\""
56
56
  end
57
57
 
58
58
  sql
@@ -384,10 +384,12 @@ class ActiveRecord::Base
384
384
  end
385
385
 
386
386
  stored_attrs = respond_to?(:stored_attributes) ? stored_attributes : {}
387
+ default_values = column_defaults
387
388
 
388
389
  array_of_attributes = models.map do |model|
389
390
  column_names.map do |name|
390
- if stored_attrs.any? && stored_attrs.key?(name.to_sym)
391
+ is_stored_attr = stored_attrs.any? && stored_attrs.key?(name.to_sym)
392
+ if is_stored_attr || default_values[name].is_a?(Hash)
391
393
  model.read_attribute(name.to_s)
392
394
  else
393
395
  model.read_attribute_before_type_cast(name.to_s)
@@ -681,9 +683,9 @@ class ActiveRecord::Base
681
683
  elsif column
682
684
  if defined?(type_caster_memo) && type_caster_memo.respond_to?(:type_cast_for_database) # Rails 5.0 and higher
683
685
  connection_memo.quote(type_caster_memo.type_cast_for_database(column.name, val))
684
- elsif column.respond_to?(:type_cast_from_user) # Rails 4.2 and higher
686
+ elsif column.respond_to?(:type_cast_from_user) # Rails 4.2 and higher
685
687
  connection_memo.quote(column.type_cast_from_user(val), column)
686
- else # Rails 3.2, 4.0 and 4.1
688
+ else # Rails 3.2, 4.0 and 4.1
687
689
  if serialized_attributes.include?(column.name)
688
690
  val = serialized_attributes[column.name].dump(val)
689
691
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Import
3
- VERSION = "0.17.1".freeze
3
+ VERSION = "0.17.2".freeze
4
4
  end
5
5
  end
data/test/import_test.rb CHANGED
@@ -48,6 +48,14 @@ describe "#import" do
48
48
  Widget.import Build(3, :widgets)
49
49
  end
50
50
  end
51
+
52
+ context "with uppercase letters" do
53
+ it "should import models successfully" do
54
+ assert_difference "Car.count", +3 do
55
+ Car.import Build(3, :cars)
56
+ end
57
+ end
58
+ end
51
59
  end
52
60
 
53
61
  context "that have no primary key" do
@@ -0,0 +1,3 @@
1
+ class Car < ActiveRecord::Base
2
+ self.primary_key = :Name
3
+ end
@@ -154,6 +154,13 @@ ActiveRecord::Schema.define do
154
154
  t.text :settings
155
155
  end
156
156
 
157
+ create_table :cars, id: false, force: :cascade do |t|
158
+ t.string :Name, null: true
159
+ t.string :Features
160
+ end
161
+
162
+ add_index :cars, :Name, unique: true
163
+
157
164
  execute %(
158
165
  CREATE TABLE IF NOT EXISTS tags (
159
166
  tag_id INT NOT NULL,
@@ -20,8 +20,10 @@ ActiveRecord::Schema.define do
20
20
 
21
21
  if t.respond_to?(:jsonb)
22
22
  t.jsonb :settings
23
+ t.jsonb :json_data, null: false, default: {}
23
24
  else
24
25
  t.text :settings
26
+ t.text :json_data
25
27
  end
26
28
 
27
29
  t.datetime :created_at
@@ -55,4 +55,9 @@ FactoryGirl.define do
55
55
  title 'Tortilla Flat'
56
56
  author_name 'John Steinbeck'
57
57
  end
58
+
59
+ factory :car do
60
+ sequence(:Name) { |n| n }
61
+ sequence(:Features) { |n| "Feature #{n}" }
62
+ end
58
63
  end
@@ -123,6 +123,18 @@ def should_support_postgresql_import_functionality
123
123
  end
124
124
  end
125
125
  end
126
+
127
+ if ENV['AR_VERSION'].to_f >= 4.2
128
+ describe "with serializable fields" do
129
+ it "imports default values as correct data type" do
130
+ vendors = [Vendor.new(name: 'Vendor 1')]
131
+ assert_difference "Vendor.count", +1 do
132
+ Vendor.import vendors
133
+ end
134
+ assert_equal({}, Vendor.first.json_data)
135
+ end
136
+ end
137
+ end
126
138
  end
127
139
 
128
140
  def should_support_postgresql_upsert_functionality
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.17.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: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -115,6 +115,7 @@ files:
115
115
  - test/jdbcsqlite3/import_test.rb
116
116
  - test/models/alarm.rb
117
117
  - test/models/book.rb
118
+ - test/models/car.rb
118
119
  - test/models/chapter.rb
119
120
  - test/models/dictionary.rb
120
121
  - test/models/discount.rb
@@ -198,6 +199,7 @@ test_files:
198
199
  - test/jdbcsqlite3/import_test.rb
199
200
  - test/models/alarm.rb
200
201
  - test/models/book.rb
202
+ - test/models/car.rb
201
203
  - test/models/chapter.rb
202
204
  - test/models/dictionary.rb
203
205
  - test/models/discount.rb