Skip to content

Commit

Permalink
sites are imported
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 1, 2011
1 parent e06e00d commit b9f84e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/account.rb
Expand Up @@ -11,6 +11,7 @@ class Account < ActiveRecord::Base
# ruby-committers # ruby-committers
def self.import io def self.import io
require 'psych' require 'psych'

doc = Psych.load io doc = Psych.load io
doc.each do |record| doc.each do |record|
account = Account.create!(:username => record['account']) account = Account.create!(:username => record['account'])
Expand All @@ -21,6 +22,15 @@ def self.import io
(record['nick'] || []).each do |name| (record['nick'] || []).each do |name|
account.nicks.create!(:value => name) account.nicks.create!(:value => name)
end end

(record['sites'] || []).each do |site|
account.sites.create!(
:title => site['title'],
:url => site['url'],
:lang => site['lang'],
:feed => site['feed']
)
end
end end
end end
end end
19 changes: 19 additions & 0 deletions test/unit/account_test.rb
Expand Up @@ -62,4 +62,23 @@ def test_imports_nicks
account = Account.find_by_username('aamine') account = Account.find_by_username('aamine')
assert_equal ['青木さん'], account.nicks.map { |x| x.value } assert_equal ['青木さん'], account.nicks.map { |x| x.value }
end end

def test_imports_sites
assert_difference('Site.count', 5) do
File.open(@yml, 'rb') { |f| Account.import f }
end

account = Account.find_by_username('aamine')
assert_equal 2, account.sites.length

site = account.sites.find_by_title('LoveRubyNet')
assert_nil site.lang
assert_nil site.feed
assert_equal 'http://i.loveruby.net/', site.url

site = account.sites.find_by_title('青木日記')
assert_equal 'http://i.loveruby.net/d/', site.url
assert_equal 'ja', site.lang
assert_equal 'http://i.loveruby.net/d/index.rdf', site.feed
end
end end

0 comments on commit b9f84e8

Please sign in to comment.