Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

starting import function

  • Loading branch information...
commit fd2135d7211fe0b84134467074e801376288bf6b 1 parent 33d79b9
Aaron Patterson authored
5  app/controllers/accounts_controller.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AccountsController < ApplicationController
  2
+  def index
  3
+    @accounts = Account.find :all
  4
+  end
  5
+end
2  app/helpers/accounts_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AccountsHelper
  2
+end
11  app/models/account.rb
@@ -5,4 +5,15 @@ class Account < ActiveRecord::Base
5 5
   has_many :services
6 6
   has_many :portraits
7 7
   has_many :books
  8
+
  9
+  ###
  10
+  # Import +io+ object that contains a YAML representation of the
  11
+  # ruby-committers
  12
+  def self.import io
  13
+    require 'psych'
  14
+    doc = Psych.load io
  15
+    doc.each do |record|
  16
+      Account.create!(:username => record['account'])
  17
+    end
  18
+  end
8 19
 end
15  app/views/accounts/_account.html.erb
... ...
@@ -0,0 +1,15 @@
  1
+<li>
  2
+Account: <%= account.username %>
  3
+Names:
  4
+  <ul>
  5
+    <% account.names.each do |name| %>
  6
+      <li><%= name %></li>
  7
+    <% end %>
  8
+  </ul>
  9
+Nicknames:
  10
+  <ul>
  11
+    <% account.nicks.each do |name| %>
  12
+      <li><%= name %></li>
  13
+    <% end %>
  14
+  </ul>
  15
+</li>
4  app/views/accounts/index.html.erb
... ...
@@ -0,0 +1,4 @@
  1
+<h1>Ruby Committers</h1>
  2
+<ul>
  3
+<%= render :partial => 'account', :collection => @accounts %>
  4
+</ul>
57  config/routes.rb
... ...
@@ -1,58 +1,3 @@
1 1
 Rubycommitters::Application.routes.draw do
2  
-  # The priority is based upon order of creation:
3  
-  # first created -> highest priority.
4  
-
5  
-  # Sample of regular route:
6  
-  #   match 'products/:id' => 'catalog#view'
7  
-  # Keep in mind you can assign values other than :controller and :action
8  
-
9  
-  # Sample of named route:
10  
-  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11  
-  # This route can be invoked with purchase_url(:id => product.id)
12  
-
13  
-  # Sample resource route (maps HTTP verbs to controller actions automatically):
14  
-  #   resources :products
15  
-
16  
-  # Sample resource route with options:
17  
-  #   resources :products do
18  
-  #     member do
19  
-  #       get 'short'
20  
-  #       post 'toggle'
21  
-  #     end
22  
-  #
23  
-  #     collection do
24  
-  #       get 'sold'
25  
-  #     end
26  
-  #   end
27  
-
28  
-  # Sample resource route with sub-resources:
29  
-  #   resources :products do
30  
-  #     resources :comments, :sales
31  
-  #     resource :seller
32  
-  #   end
33  
-
34  
-  # Sample resource route with more complex sub-resources
35  
-  #   resources :products do
36  
-  #     resources :comments
37  
-  #     resources :sales do
38  
-  #       get 'recent', :on => :collection
39  
-  #     end
40  
-  #   end
41  
-
42  
-  # Sample resource route within a namespace:
43  
-  #   namespace :admin do
44  
-  #     # Directs /admin/products/* to Admin::ProductsController
45  
-  #     # (app/controllers/admin/products_controller.rb)
46  
-  #     resources :products
47  
-  #   end
48  
-
49  
-  # You can have the root of your site routed with "root"
50  
-  # just remember to delete public/index.html.
51  
-  # root :to => "welcome#index"
52  
-
53  
-  # See how all your routes lay out with "rake routes"
54  
-
55  
-  # This is a legacy wild controller route that's not recommended for RESTful applications.
56  
-  # Note: This route will make all actions in every controller accessible via GET requests.
57  
-  # match ':controller(/:action(/:id(.:format)))'
  2
+  resources :accounts
58 3
 end
11  test/functional/accounts_controller_test.rb
... ...
@@ -0,0 +1,11 @@
  1
+require 'test_helper'
  2
+
  3
+class AccountsControllerTest < ActionController::TestCase
  4
+  fixtures :accounts
  5
+
  6
+  def test_get_index
  7
+    get :index
  8
+    assert_response :success
  9
+    assert_equal Account.find(:all), assigns(:accounts)
  10
+  end
  11
+end
7  test/unit/account_test.rb
@@ -5,6 +5,7 @@ class AccountTest < ActiveSupport::TestCase
5 5
 
6 6
   def setup
7 7
     @matz = accounts :matz
  8
+    @yml = File.join(File.expand_path(File.dirname(__FILE__)), 'ruby-committers.yml')
8 9
   end
9 10
 
10 11
   def test_has_many_names
@@ -30,4 +31,10 @@ def test_has_many_portraits
30 31
   def test_has_many_books
31 32
     assert_operator 5, :<=, @matz.books.length
32 33
   end
  34
+
  35
+  def test_import_accounts
  36
+    assert_difference('Account.count', 3) do
  37
+      File.open(@yml, 'rb') { |f| Account.import f }
  38
+    end
  39
+  end
33 40
 end
4  test/unit/helpers/accounts_helper_test.rb
... ...
@@ -0,0 +1,4 @@
  1
+require 'test_helper'
  2
+
  3
+class AccountsHelperTest < ActionView::TestCase
  4
+end
53  test/unit/ruby-committers.yml
... ...
@@ -0,0 +1,53 @@
  1
+- account: H_Konishi
  2
+  name:
  3
+    - 小西弘将
  4
+    - KONISHI Hiromasa
  5
+  sites:
  6
+    - title: '小西の物置'
  7
+      url: 'http://www001.upp.so-net.ne.jp/konishi/'
  8
+- account: aamine
  9
+  name:
  10
+    - 青木峰郎
  11
+    - Minero Aoki
  12
+  nick:
  13
+    - 青木さん
  14
+  sites:
  15
+    - title: LoveRubyNet
  16
+      url: 'http://i.loveruby.net/'
  17
+    - title: 青木日記
  18
+      url: 'http://i.loveruby.net/d/'
  19
+      lang: ja
  20
+      feed: 'http://i.loveruby.net/d/index.rdf'
  21
+  portraits:
  22
+    - 'http://jp.rubyist.net/magazine/?c=plugin;plugin=attach_download;p=0017-Hotlinks;file_name=aoki1.jpg'
  23
+  ruby-books:
  24
+    - '9784844317210'
  25
+    - '9784797340044'
  26
+    - '9784756137098'
  27
+    - '9784797324297'
  28
+    - '9784839923204'
  29
+- account: akira
  30
+  name:
  31
+    - やまだあきら
  32
+    - akira yamada
  33
+  nick:
  34
+    - ay
  35
+    - やまださん
  36
+  sites:
  37
+    - title: やまだあきらのサイト
  38
+      url: 'http://arika.org/'
  39
+      lang: ja
  40
+    - title: '\ay diary'
  41
+      url: 'http://arika.org/diary/'
  42
+      lang: ja
  43
+      feed: 'http://arika.org/diary/articles.rss'
  44
+  portraits:
  45
+    - 'http://iddy.jp/userphoto/5baa27c3da176d038ce96ca4baacc7b1c2a66a0f/me96x96s.jpg'
  46
+  services:
  47
+    twitter: arika
  48
+    friendfeed: arika
  49
+    iddy: arika
  50
+    mixi: 1549
  51
+  ruby-books:
  52
+    - '9784274064616'
  53
+    - '9784900813250'

0 notes on commit fd2135d

Please sign in to comment.
Something went wrong with that request. Please try again.