Skip to content
Browse files

names are imported

  • Loading branch information...
1 parent fd2135d commit ad502d5ad307c91fd6cc260a25e6966a5e01f723 @tenderlove committed
Showing with 17 additions and 1 deletion.
  1. +4 −1 app/models/account.rb
  2. +13 −0 test/unit/account_test.rb
View
5 app/models/account.rb
@@ -13,7 +13,10 @@ def self.import io
require 'psych'
doc = Psych.load io
doc.each do |record|
- Account.create!(:username => record['account'])
+ account = Account.create!(:username => record['account'])
+ record['name'].each do |name|
+ account.names.create!(:value => name)
+ end
end
end
end
View
13 test/unit/account_test.rb
@@ -1,3 +1,5 @@
+# coding: utf-8
+
require 'test_helper'
class AccountTest < ActiveSupport::TestCase
@@ -37,4 +39,15 @@ def test_import_accounts
File.open(@yml, 'rb') { |f| Account.import f }
end
end
+
+ def test_imports_names
+ assert_difference('Name.count', 6) do
+ File.open(@yml, 'rb') { |f| Account.import f }
+ end
+
+ account = Account.find_by_username('H_Konishi')
+ assert_equal ['小西弘将', 'KONISHI Hiromasa'].sort, account.names.map { |n|
+ n.value
+ }.sort
+ end
end

0 comments on commit ad502d5

Please sign in to comment.
Something went wrong with that request. Please try again.