activerecord-import 0.9.0 → 0.10.0
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 +4 -4
- data/lib/activerecord-import/import.rb +1 -1
- data/lib/activerecord-import/version.rb +1 -1
- data/test/import_test.rb +28 -0
- data/test/models/book.rb +3 -0
- data/test/schema/generic_schema.rb +1 -0
- data/test/schema/mysql_schema.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb77d17b829e2ac21c8816b01c3d365b4f9ddc6e
|
4
|
+
data.tar.gz: 301500da2b010aaac8473af8c5436124c59c0ca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242c10dbb23c6236cd2e2f10328a6c63e567c3fa55bb899c05771b37c7bc3507632495779deffdf52dcd8798c7785398be1493330d32f69953a20d3e0a1348be
|
7
|
+
data.tar.gz: 1c8eccfa18fef779eb2c6c86cde365cd6254efc453b09734e19ceafe62d93af445de0042e0ef6d840f7c7e9e5546f93432ff2a3fe9bde3f4a97d6319031be2f5
|
@@ -270,7 +270,7 @@ class ActiveRecord::Base
|
|
270
270
|
# this next line breaks sqlite.so with a segmentation fault
|
271
271
|
# if model.new_record? || options[:on_duplicate_key_update]
|
272
272
|
column_names.map do |name|
|
273
|
-
model.
|
273
|
+
model.read_attribute_before_type_cast(name.to_s)
|
274
274
|
end
|
275
275
|
# end
|
276
276
|
end
|
data/test/import_test.rb
CHANGED
@@ -365,6 +365,34 @@ describe "#import" do
|
|
365
365
|
|
366
366
|
end
|
367
367
|
|
368
|
+
context 'When importing models with Enum fields' do
|
369
|
+
it 'should be able to import enum fields' do
|
370
|
+
Book.delete_all if Book.count > 0
|
371
|
+
books = [
|
372
|
+
Book.new(:author_name => "Foo", :title => "Baz", status: 0),
|
373
|
+
Book.new(:author_name => "Foo2", :title => "Baz2", status: 1),
|
374
|
+
]
|
375
|
+
Book.import books
|
376
|
+
assert_equal 2, Book.count
|
377
|
+
assert_equal 0, Book.first.read_attribute('status')
|
378
|
+
assert_equal 1, Book.last.read_attribute('status')
|
379
|
+
end
|
380
|
+
|
381
|
+
if ENV['AR_VERSION'].to_i > 4.1
|
382
|
+
it 'should be able to import enum fields by name' do
|
383
|
+
Book.delete_all if Book.count > 0
|
384
|
+
books = [
|
385
|
+
Book.new(:author_name => "Foo", :title => "Baz", status: :draft),
|
386
|
+
Book.new(:author_name => "Foo2", :title => "Baz2", status: :published),
|
387
|
+
]
|
388
|
+
Book.import books
|
389
|
+
assert_equal 2, Book.count
|
390
|
+
assert_equal 0, Book.first.read_attribute('status')
|
391
|
+
assert_equal 1, Book.last.read_attribute('status')
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
368
396
|
describe "importing when model has default_scope" do
|
369
397
|
it "doesn't import the default scope values" do
|
370
398
|
assert_difference "Widget.unscoped.count", +2 do
|
data/test/models/book.rb
CHANGED
@@ -2,4 +2,7 @@ class Book < ActiveRecord::Base
|
|
2
2
|
belongs_to :topic, :inverse_of=>:books
|
3
3
|
has_many :chapters, :autosave => true, :inverse_of => :book
|
4
4
|
has_many :end_notes, :autosave => true, :inverse_of => :book
|
5
|
+
if ENV['AR_VERSION'].to_i >= 4.1
|
6
|
+
enum status: [:draft, :published]
|
7
|
+
end
|
5
8
|
end
|
data/test/schema/mysql_schema.rb
CHANGED
@@ -11,6 +11,7 @@ ActiveRecord::Schema.define do
|
|
11
11
|
t.column :publish_date, :date
|
12
12
|
t.column :topic_id, :integer
|
13
13
|
t.column :for_sale, :boolean, :default => true
|
14
|
+
t.column :status, :integer
|
14
15
|
end
|
15
16
|
execute "ALTER TABLE books ADD FULLTEXT( `title`, `publisher`, `author_name` )"
|
16
17
|
|
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.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -213,3 +213,4 @@ test_files:
|
|
213
213
|
- test/travis/database.yml
|
214
214
|
- test/value_sets_bytes_parser_test.rb
|
215
215
|
- test/value_sets_records_parser_test.rb
|
216
|
+
has_rdoc:
|