Skip to content

Commit

Permalink
books are imported
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 1, 2011
1 parent d4dfcfc commit 41dadb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions test/unit/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.