Permalink
Browse files

books are imported

  • Loading branch information...
1 parent d4dfcfc commit 41dadb927403adeb9fbc0cd7515756eb8722c212 @tenderlove committed Jan 1, 2011
Showing with 19 additions and 0 deletions.
  1. +4 −0 app/models/account.rb
  2. +15 −0 test/unit/account_test.rb
@@ -39,6 +39,10 @@ def self.import io
(record['services'] || []).each do |name, key|
account.services.create!(:name => name, :key => key)
end
+
+ (record['ruby-books'] || []).each do |key|
+ account.books.create!(:key => key)
+ end
end
end
end
@@ -106,4 +106,19 @@ def test_imports_services
['mixi', '1549'],
].sort, account.services.map { |x| [x.name, x.key] }.sort
end
+
+ def test_imports_books
+ assert_difference('Book.count', 7) do
+ File.open(@yml, 'rb') { |f| Account.import f }
+ end
+
+ account = Account.find_by_username 'aamine'
+ assert_equal %w{
+ 9784844317210
+ 9784797340044
+ 9784756137098
+ 9784797324297
+ 9784839923204
+ }.sort, account.books.map { |x| x.key }.sort
+ end
end

0 comments on commit 41dadb9

Please sign in to comment.