Platform and Project core models

This commit is contained in:
Alexey Nayden 2011-03-09 20:38:21 +03:00
parent 340e8697c7
commit 0218f5dfd0
6 changed files with 78 additions and 0 deletions

19
app/models/platform.rb Normal file
View File

@ -0,0 +1,19 @@
class Platform < ActiveRecord::Base
validate :name, :presence => true, :uniqueness => true
validate :unixname, :presence => true, :uniqueness => true
before_validation :generate_unixname
validate :validate_unixname
has_many :projects
has_one :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
protected
def generate_unixname
#TODO: Implement unixname generation
end
def validate_unixname
#TODO: Implement unixname validation
end
end

19
app/models/project.rb Normal file
View File

@ -0,0 +1,19 @@
class Project < ActiveRecord::Base
validate :name, :uniqueness => true, :presence => true
validate :unixname, :uniqueness => true, :presence => true
before_validation :generate_unixname
validate :validate_unixname
belongs_to :platform
protected
def generate_unixname
#TODO: Implement unixname generation
end
def validate_unixname
#TODO: Implement unixname validation
end
end

View File

@ -0,0 +1,15 @@
class CreatePlatforms < ActiveRecord::Migration
def self.up
create_table :platforms do |t|
t.string :name
t.string :unixname
t.integer :parent_platform_id
t.timestamps
end
end
def self.down
drop_table :platforms
end
end

View File

@ -0,0 +1,15 @@
class CreateProjects < ActiveRecord::Migration
def self.up
create_table :projects do |t|
t.string :name
t.string :unixname
t.integer :platform_id
t.timestamps
end
end
def self.down
drop_table :projects
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Platform do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Project do
pending "add some examples to (or delete) #{__FILE__}"
end