Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sites are imported

  • Loading branch information...
commit b9f84e81bea3a52b0196a672d0934be27aabce94 1 parent e06e00d
@tenderlove authored
Showing with 29 additions and 0 deletions.
  1. +10 −0 app/models/account.rb
  2. +19 −0 test/unit/account_test.rb
View
10 app/models/account.rb
@@ -11,6 +11,7 @@ class Account < ActiveRecord::Base
# ruby-committers
def self.import io
require 'psych'
+
doc = Psych.load io
doc.each do |record|
account = Account.create!(:username => record['account'])
@@ -21,6 +22,15 @@ def self.import io
(record['nick'] || []).each do |name|
account.nicks.create!(:value => name)
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
View
19 test/unit/account_test.rb
@@ -62,4 +62,23 @@ def test_imports_nicks
account = Account.find_by_username('aamine')
assert_equal ['青木さん'], account.nicks.map { |x| x.value }
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
Please sign in to comment.
Something went wrong with that request. Please try again.