Skip to content

Commit

Permalink
starting import function
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 1, 2011
1 parent 33d79b9 commit fd2135d
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 56 deletions.
5 changes: 5 additions & 0 deletions app/controllers/accounts_controller.rb
@@ -0,0 +1,5 @@
class AccountsController < ApplicationController
def index
@accounts = Account.find :all
end
end
2 changes: 2 additions & 0 deletions app/helpers/accounts_helper.rb
@@ -0,0 +1,2 @@
module AccountsHelper
end
11 changes: 11 additions & 0 deletions app/models/account.rb
Expand Up @@ -5,4 +5,15 @@ class Account < ActiveRecord::Base
has_many :services
has_many :portraits
has_many :books

###
# Import +io+ object that contains a YAML representation of the
# ruby-committers
def self.import io
require 'psych'
doc = Psych.load io
doc.each do |record|
Account.create!(:username => record['account'])
end
end
end
15 changes: 15 additions & 0 deletions app/views/accounts/_account.html.erb
@@ -0,0 +1,15 @@
<li>
Account: <%= account.username %>
Names:
<ul>
<% account.names.each do |name| %>
<li><%= name %></li>
<% end %>
</ul>
Nicknames:
<ul>
<% account.nicks.each do |name| %>
<li><%= name %></li>
<% end %>
</ul>
</li>
4 changes: 4 additions & 0 deletions app/views/accounts/index.html.erb
@@ -0,0 +1,4 @@
<h1>Ruby Committers</h1>
<ul>
<%= render :partial => 'account', :collection => @accounts %>
</ul>
57 changes: 1 addition & 56 deletions config/routes.rb
@@ -1,58 +1,3 @@
Rubycommitters::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.

# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end

# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"

# See how all your routes lay out with "rake routes"

# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
resources :accounts
end
11 changes: 11 additions & 0 deletions test/functional/accounts_controller_test.rb
@@ -0,0 +1,11 @@
require 'test_helper'

class AccountsControllerTest < ActionController::TestCase
fixtures :accounts

def test_get_index
get :index
assert_response :success
assert_equal Account.find(:all), assigns(:accounts)
end
end
7 changes: 7 additions & 0 deletions test/unit/account_test.rb
Expand Up @@ -5,6 +5,7 @@ class AccountTest < ActiveSupport::TestCase

def setup
@matz = accounts :matz
@yml = File.join(File.expand_path(File.dirname(__FILE__)), 'ruby-committers.yml')
end

def test_has_many_names
Expand All @@ -30,4 +31,10 @@ def test_has_many_portraits
def test_has_many_books
assert_operator 5, :<=, @matz.books.length
end

def test_import_accounts
assert_difference('Account.count', 3) do
File.open(@yml, 'rb') { |f| Account.import f }
end
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/accounts_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class AccountsHelperTest < ActionView::TestCase
end
53 changes: 53 additions & 0 deletions test/unit/ruby-committers.yml
@@ -0,0 +1,53 @@
- account: H_Konishi
name:
- 小西弘将
- KONISHI Hiromasa
sites:
- title: '小西の物置'
url: 'http://www001.upp.so-net.ne.jp/konishi/'
- account: aamine
name:
- 青木峰郎
- Minero Aoki
nick:
- 青木さん
sites:
- title: LoveRubyNet
url: 'http://i.loveruby.net/'
- title: 青木日記
url: 'http://i.loveruby.net/d/'
lang: ja
feed: 'http://i.loveruby.net/d/index.rdf'
portraits:
- 'http://jp.rubyist.net/magazine/?c=plugin;plugin=attach_download;p=0017-Hotlinks;file_name=aoki1.jpg'
ruby-books:
- '9784844317210'
- '9784797340044'
- '9784756137098'
- '9784797324297'
- '9784839923204'
- account: akira
name:
- やまだあきら
- akira yamada
nick:
- ay
- やまださん
sites:
- title: やまだあきらのサイト
url: 'http://arika.org/'
lang: ja
- title: '\ay diary'
url: 'http://arika.org/diary/'
lang: ja
feed: 'http://arika.org/diary/articles.rss'
portraits:
- 'http://iddy.jp/userphoto/5baa27c3da176d038ce96ca4baacc7b1c2a66a0f/me96x96s.jpg'
services:
twitter: arika
friendfeed: arika
iddy: arika
mixi: 1549
ruby-books:
- '9784274064616'
- '9784900813250'

0 comments on commit fd2135d

Please sign in to comment.