Skip to content

Commit

Permalink
song shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshuma committed Jan 4, 2010
1 parent a726b1a commit 921258c
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/models/album.rb
@@ -1,4 +1,5 @@
class Album < ActiveRecord::Base
validates_presence_of :name
belongs_to :artist
has_many :songs
end
1 change: 1 addition & 0 deletions app/models/artist.rb
@@ -1,4 +1,5 @@
class Artist < ActiveRecord::Base
validates_presence_of :name
has_many :albums
has_many :songs
end
5 changes: 5 additions & 0 deletions app/models/song.rb
@@ -0,0 +1,5 @@
class Song < ActiveRecord::Base
validates_presence_of :name, :path
belongs_to :artist
belongs_to :album
end
16 changes: 16 additions & 0 deletions db/migrate/20100104185127_create_songs.rb
@@ -0,0 +1,16 @@
class CreateSongs < ActiveRecord::Migration
def self.up
create_table :songs do |t|
t.integer :artist_id
t.integer :album_id
t.string :name
t.string :path

t.timestamps
end
end

def self.down
drop_table :songs
end
end
11 changes: 5 additions & 6 deletions db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100104182024) do
ActiveRecord::Schema.define(:version => 20100104185127) do

create_table "albums", :force => true do |t|
t.integer "artist_id"
Expand All @@ -26,11 +26,10 @@
end

create_table "songs", :force => true do |t|
t.string "artist"
t.string "title"
t.string "album"
t.string "genre"
t.string "path", :null => false
t.integer "artist_id"
t.integer "album_id"
t.string "name"
t.string "path"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down
7 changes: 3 additions & 4 deletions spec/factories.rb
Expand Up @@ -8,9 +8,8 @@
end

Factory.define(:song) do |s|
s.sequence(:title) { |i| "Title #{i}" }
s.sequence(:artist) { |i| "Artist #{i}" }
s.sequence(:album) { |i| "Album #{i}" }
s.sequence(:genre) { |i| "Genre #{i}" }
s.artist { |song| song.association(:artist) }
s.album { |song| song.association(:album) }
s.sequence(:name) { |i| "Song #{i}" }
s.sequence(:path) { |i| create_song("test#{i}.mp3") }
end
1 change: 1 addition & 0 deletions spec/fixtures/songs.yml
@@ -0,0 +1 @@
# Factories.
17 changes: 17 additions & 0 deletions spec/models/song_spec.rb
@@ -0,0 +1,17 @@
require 'spec_helper'

describe Song do

it 'requires a name' do
lambda do
Factory(:song, :name => nil)
end.should raise_error(ActiveRecord::RecordInvalid)
end

it 'requires a path' do
lambda do
Factory(:song, :path => nil)
end.should raise_error(ActiveRecord::RecordInvalid)
end

end

0 comments on commit 921258c

Please sign in to comment.