Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

associations set up

  • Loading branch information...
commit 33d79b97a87ef8cc5768aa998e3006b841635b60 1 parent ca34860
@tenderlove tenderlove authored
View
6 app/models/account.rb
@@ -1,2 +1,8 @@
class Account < ActiveRecord::Base
+ has_many :names
+ has_many :nicks
+ has_many :sites
+ has_many :services
+ has_many :portraits
+ has_many :books
end
View
1  app/models/book.rb
@@ -1,2 +1,3 @@
class Book < ActiveRecord::Base
+ belongs_to :account
end
View
1  app/models/name.rb
@@ -1,2 +1,3 @@
class Name < ActiveRecord::Base
+ belongs_to :account
end
View
3  app/models/nick.rb
@@ -0,0 +1,3 @@
+class Nick < ActiveRecord::Base
+ belongs_to :account
+end
View
1  app/models/portrait.rb
@@ -1,2 +1,3 @@
class Portrait < ActiveRecord::Base
+ belongs_to :account
end
View
1  app/models/service.rb
@@ -1,2 +1,3 @@
class Service < ActiveRecord::Base
+ belongs_to :account
end
View
1  app/models/site.rb
@@ -1,2 +1,3 @@
class Site < ActiveRecord::Base
+ belongs_to :account
end
View
2  db/migrate/20110101001535_create_names.rb
@@ -2,7 +2,7 @@ class CreateNames < ActiveRecord::Migration
def self.up
create_table :names do |t|
t.string :value
- t.string :type
+ t.references :account
t.timestamps
end
View
1  db/migrate/20110101001612_create_sites.rb
@@ -5,6 +5,7 @@ def self.up
t.string :url
t.string :feed
t.string :lang
+ t.references :account
t.timestamps
end
View
2  db/migrate/20110101001639_create_services.rb
@@ -2,8 +2,8 @@ class CreateServices < ActiveRecord::Migration
def self.up
create_table :services do |t|
t.string :name
- t.string :type
t.string :key
+ t.references :account
t.timestamps
end
View
1  db/migrate/20110101001654_create_portraits.rb
@@ -2,6 +2,7 @@ class CreatePortraits < ActiveRecord::Migration
def self.up
create_table :portraits do |t|
t.string :url
+ t.references :account
t.timestamps
end
View
1  db/migrate/20110101001709_create_books.rb
@@ -2,6 +2,7 @@ class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.string :key
+ t.references :account
t.timestamps
end
View
14 db/migrate/20110101002342_create_nicks.rb
@@ -0,0 +1,14 @@
+class CreateNicks < ActiveRecord::Migration
+ def self.up
+ create_table :nicks do |t|
+ t.string :value
+ t.references :account
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :nicks
+ end
+end
View
67 db/schema.rb
@@ -0,0 +1,67 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20110101002342) do
+
+ create_table "accounts", :force => true do |t|
+ t.string "username"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "books", :force => true do |t|
+ t.string "key"
+ t.integer "account_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "names", :force => true do |t|
+ t.string "value"
+ t.integer "account_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "nicks", :force => true do |t|
+ t.string "value"
+ t.integer "account_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "portraits", :force => true do |t|
+ t.string "url"
+ t.integer "account_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "services", :force => true do |t|
+ t.string "name"
+ t.string "key"
+ t.integer "account_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "sites", :force => true do |t|
+ t.string "title"
+ t.string "url"
+ t.string "feed"
+ t.string "lang"
+ t.integer "account_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
8 test/fixtures/accounts.yml
@@ -1,7 +1,3 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+matz:
+ username: matz
-one:
- username: MyString
-
-two:
- username: MyString
View
20 test/fixtures/books.yml
@@ -1,7 +1,19 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
one:
- key: MyString
+ key: '9780596516178'
+ account: matz
two:
- key: MyString
+ key: '9780596002145'
+ account: matz
+
+three:
+ key: '9784756132543'
+ account: matz
+
+four:
+ key: '9784274064616'
+ account: matz
+
+five:
+ key: '9784873110233'
+ account: matz
View
16 test/fixtures/names.yml
@@ -1,9 +1,11 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+matz_kanji:
+ value: 松本行弘
+ account: matz
-one:
- value: MyString
- type: MyString
+matz_hiragana:
+ value: まつもとゆきひろ
+ account: matz
-two:
- value: MyString
- type: MyString
+matz_romaji:
+ value: Yukihiro Matsumoto
+ account: matz
View
4 test/fixtures/nicks.yml
@@ -0,0 +1,4 @@
+matz:
+ value: Matz
+ account: matz
+
View
10 test/fixtures/portraits.yml
@@ -1,7 +1,3 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- url: MyString
-
-two:
- url: MyString
+matz:
+ url: 'http://upload.wikimedia.org/wikipedia/commons/7/76/Yukihiro_Matsumoto.JPG'
+ account: matz
View
31 test/fixtures/services.yml
@@ -1,11 +1,24 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+twitter:
+ name: twitter
+ key: yukihiro_matz
+ account: matz
-one:
- name: MyString
- type: MyString
- key: MyString
+friendfeed:
+ name: friendfeed
+ key: matz
+ account: matz
-two:
- name: MyString
- type: MyString
- key: MyString
+facebook:
+ name: facebook
+ key: 650036336
+ account: matz
+
+mixi:
+ name: mixi
+ key: 1653
+ account: matz
+
+github:
+ name: github
+ key: matz
+ account: matz
View
19 test/fixtures/sites.yml
@@ -1,13 +1,6 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- title: MyString
- url: MyString
- feed: MyString
- lang: MyString
-
-two:
- title: MyString
- url: MyString
- feed: MyString
- lang: MyString
+matz_nikki:
+ title: Matzにっき
+ url: http://www.rubyist.net/~matz/
+ feed: http://www.rubyist.net/~matz/comments.rdf
+ lang: ja
+ account: matz
View
31 test/unit/account_test.rb
@@ -1,8 +1,33 @@
require 'test_helper'
class AccountTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ fixtures :accounts, :names, :nicks, :sites
+
+ def setup
+ @matz = accounts :matz
+ end
+
+ def test_has_many_names
+ assert_operator 3, :<=, @matz.names.length
+ end
+
+ def test_has_many_nicks
+ assert_operator 1, :<=, @matz.nicks.length
+ end
+
+ def test_has_many_sites
+ assert_operator 1, :<=, @matz.sites.length
+ end
+
+ def test_has_many_services
+ assert_operator 5, :<=, @matz.services.length
+ end
+
+ def test_has_many_portraits
+ assert_operator 1, :<=, @matz.portraits.length
+ end
+
+ def test_has_many_books
+ assert_operator 5, :<=, @matz.books.length
end
end
View
8 test/unit/book_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class BookTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 test/unit/name_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class NameTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 test/unit/portrait_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class PortraitTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 test/unit/service_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class ServiceTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 test/unit/site_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class SiteTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.