Skip to content

Commit

Permalink
associations set up
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 1, 2011
1 parent ca34860 commit 33d79b9
Show file tree
Hide file tree
Showing 27 changed files with 190 additions and 91 deletions.
6 changes: 6 additions & 0 deletions 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
1 change: 1 addition & 0 deletions app/models/book.rb
@@ -1,2 +1,3 @@
class Book < ActiveRecord::Base
belongs_to :account
end
1 change: 1 addition & 0 deletions app/models/name.rb
@@ -1,2 +1,3 @@
class Name < ActiveRecord::Base
belongs_to :account
end
3 changes: 3 additions & 0 deletions app/models/nick.rb
@@ -0,0 +1,3 @@
class Nick < ActiveRecord::Base
belongs_to :account
end
1 change: 1 addition & 0 deletions app/models/portrait.rb
@@ -1,2 +1,3 @@
class Portrait < ActiveRecord::Base
belongs_to :account
end
1 change: 1 addition & 0 deletions app/models/service.rb
@@ -1,2 +1,3 @@
class Service < ActiveRecord::Base
belongs_to :account
end
1 change: 1 addition & 0 deletions app/models/site.rb
@@ -1,2 +1,3 @@
class Site < ActiveRecord::Base
belongs_to :account
end
2 changes: 1 addition & 1 deletion db/migrate/20110101001535_create_names.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20110101001612_create_sites.rb
Expand Up @@ -5,6 +5,7 @@ def self.up
t.string :url
t.string :feed
t.string :lang
t.references :account

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20110101001639_create_services.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20110101001654_create_portraits.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20110101001709_create_books.rb
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions 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
67 changes: 67 additions & 0 deletions 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
8 changes: 2 additions & 6 deletions 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
20 changes: 16 additions & 4 deletions 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
16 changes: 9 additions & 7 deletions 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
4 changes: 4 additions & 0 deletions test/fixtures/nicks.yml
@@ -0,0 +1,4 @@
matz:
value: Matz
account: matz

10 changes: 3 additions & 7 deletions 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
31 changes: 22 additions & 9 deletions 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
19 changes: 6 additions & 13 deletions 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
31 changes: 28 additions & 3 deletions 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
8 changes: 0 additions & 8 deletions test/unit/book_test.rb

This file was deleted.

8 changes: 0 additions & 8 deletions test/unit/name_test.rb

This file was deleted.

8 changes: 0 additions & 8 deletions test/unit/portrait_test.rb

This file was deleted.

8 changes: 0 additions & 8 deletions test/unit/service_test.rb

This file was deleted.

8 changes: 0 additions & 8 deletions test/unit/site_test.rb

This file was deleted.

0 comments on commit 33d79b9

Please sign in to comment.