Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/import_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/schema/generic_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down