Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import breaks when two column backed attributes are aliased together #817

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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