Skip to content

Commit

Permalink
names are imported
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 1, 2011
1 parent fd2135d commit ad502d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/unit/account_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8

require 'test_helper'

class AccountTest < ActiveSupport::TestCase
Expand Down Expand Up @@ -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.