diff --git a/test/import_test.rb b/test/import_test.rb index c96dc32a..0feecadb 100644 --- a/test/import_test.rb +++ b/test/import_test.rb @@ -991,4 +991,15 @@ end end end + + describe "aliased attributes" do + it "two column based attributes can be imported" do + topic = FactoryBot.create :topic + new_topic = Topic.new(topic.attributes.except("id")) + new_topic.author_name = "John Doe" + + Topic.import([new_topic]) + assert_equal 2, Topic.count + end + end end diff --git a/test/models/topic.rb b/test/models/topic.rb index dda46fab..993ae99e 100644 --- a/test/models/topic.rb +++ b/test/models/topic.rb @@ -5,6 +5,7 @@ class Topic < ActiveRecord::Base self.ignored_columns = [:priority] end alias_attribute :name, :title + alias_attribute :author_full_name, :author_name validates_presence_of :author_name validates :title, numericality: { only_integer: true }, on: :context_test diff --git a/test/schema/generic_schema.rb b/test/schema/generic_schema.rb index c9dd6fac..983785e6 100644 --- a/test/schema/generic_schema.rb +++ b/test/schema/generic_schema.rb @@ -28,6 +28,7 @@ t.datetime :created_on t.datetime :updated_at t.datetime :updated_on + t.string :author_full_name end create_table :projects, force: :cascade do |t|