From da97eb4cf75c174151d60c48249b7cc991173aec Mon Sep 17 00:00:00 2001 From: Jordan Owens Date: Mon, 4 Apr 2016 21:07:30 -0400 Subject: [PATCH] Add test for importing arrays of values for model with enum --- test/import_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/import_test.rb b/test/import_test.rb index e8ea5d7b..566db556 100644 --- a/test/import_test.rb +++ b/test/import_test.rb @@ -451,6 +451,25 @@ end end + context 'When importing arrays of values with Enum fields' do + let(:columns) { [:author_name, :title, :status] } + let(:values) { [['Author #1', 'Book #1', 0], ['Author #2', 'Book #2', 1]] } + + it 'should be able to import enum fields' do + Book.delete_all if Book.count > 0 + Book.import columns, values + assert_equal 2, Book.count + + if ENV['AR_VERSION'].to_i >= 5.0 + assert_equal 'draft', Book.first.read_attribute('status') + assert_equal 'published', Book.last.read_attribute('status') + else + assert_equal 0, Book.first.read_attribute('status') + assert_equal 1, Book.last.read_attribute('status') + end + end + end + describe "importing when model has default_scope" do it "doesn't import the default scope values" do assert_difference "Widget.unscoped.count", +2 do