From 0218f5dfd0f2cd983b7263871ab48ab7c1f819c8 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Wed, 9 Mar 2011 20:38:21 +0300 Subject: [PATCH] Platform and Project core models --- app/models/platform.rb | 19 +++++++++++++++++++ app/models/project.rb | 19 +++++++++++++++++++ db/migrate/20110309173339_create_platforms.rb | 15 +++++++++++++++ db/migrate/20110309173421_create_projects.rb | 15 +++++++++++++++ spec/models/platform_spec.rb | 5 +++++ spec/models/project_spec.rb | 5 +++++ 6 files changed, 78 insertions(+) create mode 100644 app/models/platform.rb create mode 100644 app/models/project.rb create mode 100644 db/migrate/20110309173339_create_platforms.rb create mode 100644 db/migrate/20110309173421_create_projects.rb create mode 100644 spec/models/platform_spec.rb create mode 100644 spec/models/project_spec.rb diff --git a/app/models/platform.rb b/app/models/platform.rb new file mode 100644 index 000000000..77ae72a0e --- /dev/null +++ b/app/models/platform.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb new file mode 100644 index 000000000..e01184770 --- /dev/null +++ b/app/models/project.rb @@ -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 diff --git a/db/migrate/20110309173339_create_platforms.rb b/db/migrate/20110309173339_create_platforms.rb new file mode 100644 index 000000000..787f4a9ed --- /dev/null +++ b/db/migrate/20110309173339_create_platforms.rb @@ -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 diff --git a/db/migrate/20110309173421_create_projects.rb b/db/migrate/20110309173421_create_projects.rb new file mode 100644 index 000000000..06eb3a62d --- /dev/null +++ b/db/migrate/20110309173421_create_projects.rb @@ -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 diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb new file mode 100644 index 000000000..52468b7ae --- /dev/null +++ b/spec/models/platform_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Platform do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb new file mode 100644 index 000000000..9bda4d927 --- /dev/null +++ b/spec/models/project_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Project do + pending "add some examples to (or delete) #{__FILE__}" +end