Merge branch 'master' of github.com:evilmartians/rosa-build

This commit is contained in:
Timothy N. Tsvetkov 2011-03-11 19:31:16 +03:00
commit 7cce8520a9
18 changed files with 195 additions and 23 deletions

View File

@ -6,8 +6,8 @@ class PlatformsController < ApplicationController
end
def show
@platform = Platform.find params[:id], :include => :projects
@projects = @platform.projects
@platform = Platform.find params[:id], :include => :repositories
@repositories = @platform.repositories
end
def new

View File

@ -1,20 +1,21 @@
class ProjectsController < ApplicationController
before_filter :authenticate_user!
before_filter :find_platform
before_filter :find_repository
before_filter :find_project, :only => [:show]
def new
@project = @platform.projects.new
@project = @repository.projects.new
end
def show
end
def create
@project = @platform.projects.new params[:project]
@project = @repository.projects.new params[:project]
if @project.save
flash[:notice] = t('flash.project.saved')
redirect_to @platform
redirect_to [@platform, @repository]
else
flash[:error] = t('flash.project.save_error')
render :action => :new
@ -27,7 +28,11 @@ class ProjectsController < ApplicationController
@platform = Platform.find params[:platform_id]
end
def find_repository
@repository = @platform.repositories.find(params[:repository_id])
end
def find_project
@project = @platform.projects.find params[:id]
@project = @repository.projects.find params[:id]
end
end

View File

@ -0,0 +1,53 @@
class RepositoriesController < ApplicationController
before_filter :authenticate_user!
before_filter :find_platform
def index
@repositories = @platform.repositories
end
def show
@repository = @platform.repositories.find params[:id], :include => :projects
@projects = @repository.projects
end
def new
@repository = @platform.repositories.new
end
def edit
@repository = @platform.repositories.find params[:id]
end
def destroy
Repository.destroy params[:id]
end
def update
@repository = @platform.repositories.find params[:id]
if @repository.update_attributes params[:repository]
flash[:notice] = ''
redirect_to @repository
else
flash[:error] = ''
render :action => :edit
end
end
def create
@repository = @platform.repositories.new(params[:repository])
if @repository.save
flash[:notice] = ''
redirect_to @platform, @repository
else
flash[:error] = ''
render :action => :new
end
end
protected
def find_platform
@platform = Platform.find params[:platform_id]
end
end

View File

@ -1,6 +1,6 @@
class Platform < ActiveRecord::Base
has_many :projects, :dependent => :destroy
has_one :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
has_many :repositories, :dependent => :destroy
validate :name, :presence => true, :uniqueness => true
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false

View File

@ -1,5 +1,5 @@
class Project < ActiveRecord::Base
belongs_to :platform
belongs_to :repository
validate :name, :uniqueness => true, :presence => true, :allow_nil => false, :allow_blank => false
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false
@ -10,7 +10,7 @@ class Project < ActiveRecord::Base
# Redefining a method from Project::HasRepository module to reflect current situation
def git_repo_path
@git_repo_path ||= File.join(APP_CONFIG['root_path'], platform.unixname, unixname, unixname + '.git')
@git_repo_path ||= File.join(path, unixname + ".git")
end
def path
@ -20,7 +20,7 @@ class Project < ActiveRecord::Base
protected
def build_path(dir)
File.join(APP_CONFIG['root_path'], platform.unixname, dir)
File.join(repository.path, dir)
end
#TODO: Spec me

31
app/models/repository.rb Normal file
View File

@ -0,0 +1,31 @@
class Repository < ActiveRecord::Base
belongs_to :platform
has_many :projects, :dependent => :destroy
validate :name, :presence => true, :uniqueness => true
validate :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }
before_create :create_directory
def path
build_path(unixname)
end
protected
def build_path(dir)
File.join(platform.path, dir)
end
#TODO: Spec me
def create_directory
exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} already exists" if exists
if new_record?
FileUtils.mkdir_p(path)
elsif unixname_changed?
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
end
end
end

View File

@ -7,10 +7,11 @@
= @platform.path
%h2= t('layout.platforms.projects')
- @projects.each do |project|
= div_for project do
= link_to project.name, [@platform, project]
= link_to t('layout.projects.new'), new_platform_project_path(@platform)
%h2= t('layout.platforms.repositories')
- @repositories.each do |repository|
= div_for repository do
= link_to repository.name, [@platform, repository]
= link_to t('layout.repositories.new'), new_platform_repository_path(@platform)
%h2= t('layout.platforms.products')
TBD

View File

@ -1,5 +1,5 @@
%h1= t('layout.projects.new')
= form_for [@platform, @project] do |f|
= form_for [@platform, @repository, @project] do |f|
%p
= f.label :name
= f.text_field :name
@ -8,4 +8,4 @@
= f.text_field :unixname
%p
= f.submit t('layout.create')
= link_to t('layout.cancel'), platform_path(@platform)
= link_to t('layout.cancel'), platform_repository_path(@platform, @repository)

View File

@ -7,6 +7,6 @@
= t('layout.projects.git_repo_location')
= @project.git_repo_path
= link_to t('layout.projects.back_to_the_list'), platform_path(@platform)
= link_to t('layout.projects.back_to_the_list'), platform_repository_path(@repository, @platform)
%br/
= link_to "git-repo", platform_project_repo_path(@platform, @project)
= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project)

View File

@ -0,0 +1,12 @@
%h1= t('layout.repositories.new_header')
= form_for [@platform, @repository] do |f|
%p
= f.label :name
= f.text_field :name
%p
= f.label :unixname
= f.text_field :unixname
%p
= f.submit t('layout.create')
= link_to t('layout.cancel'), platform_repositories_path(@platform)

View File

@ -0,0 +1,14 @@
%h1
= t('layout.repositories.show')
= @repository.name
= link_to t('layout.repositories.back_to_the_list'), platform_path(@platform)
.location
= t('layout.repositories.location')
= @repository.path
%h2= t('layout.repositories.projects')
- @projects.each do |project|
= div_for project do
= link_to project.name, [@platform, @repository, project]
= link_to t('layout.projects.new'), new_platform_repository_project_path(@platform, @repository)

View File

@ -2,8 +2,10 @@ Rosa::Application.routes.draw do
devise_for :users
resources :platforms do
resources :projects do
resource :repo, :controller => "git/repositories", :only => [:show]
resources :repositories do
resources :projects do
resource :repo, :controller => "git/repositories", :only => [:show]
end
end
end

View File

@ -0,0 +1,14 @@
class CreateRepositories < ActiveRecord::Migration
def self.up
create_table :repositories do |t|
t.string :name, :null => false
t.integer :platform_id, :null => false
t.timestamps
end
end
def self.down
drop_table :repositories
end
end

View File

@ -0,0 +1,9 @@
class RemovePlatformIdFromProjects < ActiveRecord::Migration
def self.up
remove_column :projects, :platform_id
end
def self.down
add_column :projects, :platform_id, :integer, :null => false
end
end

View File

@ -0,0 +1,9 @@
class AddRepositoryIdToProjects < ActiveRecord::Migration
def self.up
add_column :projects, :repository_id, :integer, :null => false
end
def self.down
remove_column :projects, :repository_id
end
end

View File

@ -0,0 +1,9 @@
class AddUnixnameToRepositories < ActiveRecord::Migration
def self.up
add_column :repositories, :unixname, :string, :null => false
end
def self.down
remove_column :repositories, :unixname
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110309173421) do
ActiveRecord::Schema.define(:version => 20110311154929) do
create_table "platforms", :force => true do |t|
t.string "name"
@ -23,9 +23,17 @@ ActiveRecord::Schema.define(:version => 20110309173421) do
create_table "projects", :force => true do |t|
t.string "name"
t.string "unixname"
t.integer "platform_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "repository_id", :null => false
end
create_table "repositories", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "unixname", :null => false
end
create_table "users", :force => true do |t|

View File

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