Commit 035196e7a8c839ce14e280d0c7230b3ce34076fe
1 parent
67f0c62d
Exists in
master
and in
4 other branches
test fix
Showing
4 changed files
with
12 additions
and
3 deletions
Show diff stats
app/controllers/admin/projects_controller.rb
| @@ -35,6 +35,7 @@ class Admin::ProjectsController < ApplicationController | @@ -35,6 +35,7 @@ class Admin::ProjectsController < ApplicationController | ||
| 35 | 35 | ||
| 36 | def create | 36 | def create |
| 37 | @admin_project = Project.new(params[:project]) | 37 | @admin_project = Project.new(params[:project]) |
| 38 | + @admin_project.owner = current_user | ||
| 38 | 39 | ||
| 39 | respond_to do |format| | 40 | respond_to do |format| |
| 40 | if @admin_project.save | 41 | if @admin_project.save |
app/models/project.rb
| 1 | require "grit" | 1 | require "grit" |
| 2 | 2 | ||
| 3 | class Project < ActiveRecord::Base | 3 | class Project < ActiveRecord::Base |
| 4 | + belongs_to :owner, :class_name => "User" | ||
| 5 | + | ||
| 4 | has_many :issues, :dependent => :destroy | 6 | has_many :issues, :dependent => :destroy |
| 5 | has_many :users_projects, :dependent => :destroy | 7 | has_many :users_projects, :dependent => :destroy |
| 6 | has_many :users, :through => :users_projects | 8 | has_many :users, :through => :users_projects |
| 7 | - belongs_to :owner, :class_name => "User" | ||
| 8 | has_many :notes, :dependent => :destroy | 9 | has_many :notes, :dependent => :destroy |
| 9 | 10 | ||
| 10 | validates :name, | 11 | validates :name, |
| @@ -25,6 +26,9 @@ class Project < ActiveRecord::Base | @@ -25,6 +26,9 @@ class Project < ActiveRecord::Base | ||
| 25 | :uniqueness => true, | 26 | :uniqueness => true, |
| 26 | :length => { :within => 3..12 } | 27 | :length => { :within => 3..12 } |
| 27 | 28 | ||
| 29 | + validates :owner, | ||
| 30 | + :presence => true | ||
| 31 | + | ||
| 28 | validate :check_limit | 32 | validate :check_limit |
| 29 | 33 | ||
| 30 | before_save :format_code | 34 | before_save :format_code |
| @@ -130,8 +134,10 @@ class Project < ActiveRecord::Base | @@ -130,8 +134,10 @@ class Project < ActiveRecord::Base | ||
| 130 | 134 | ||
| 131 | def check_limit | 135 | def check_limit |
| 132 | unless owner.can_create_project? | 136 | unless owner.can_create_project? |
| 133 | - errors[:base] << ("You can to have #{owner.projects_limit} your own projects") | 137 | + errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it") |
| 134 | end | 138 | end |
| 139 | + rescue | ||
| 140 | + errors[:base] << ("Cant check your ability to create project") | ||
| 135 | end | 141 | end |
| 136 | 142 | ||
| 137 | def valid_repo? | 143 | def valid_repo? |
db/schema.rb
| @@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009111204) do | @@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009111204) do | ||
| 70 | t.datetime "updated_at" | 70 | t.datetime "updated_at" |
| 71 | t.string "name" | 71 | t.string "name" |
| 72 | t.boolean "admin", :default => false, :null => false | 72 | t.boolean "admin", :default => false, :null => false |
| 73 | - t.integer "projects_limit" | 73 | + t.integer "projects_limit", :default => 10 |
| 74 | end | 74 | end |
| 75 | 75 | ||
| 76 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true | 76 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true |
spec/factories.rb
| @@ -3,6 +3,7 @@ require File.join(Rails.root, 'spec', 'factory') | @@ -3,6 +3,7 @@ require File.join(Rails.root, 'spec', 'factory') | ||
| 3 | Factory.add(:project, Project) do |obj| | 3 | Factory.add(:project, Project) do |obj| |
| 4 | obj.name = Faker::Internet.user_name | 4 | obj.name = Faker::Internet.user_name |
| 5 | obj.path = 'legit' | 5 | obj.path = 'legit' |
| 6 | + obj.owner = Factory(:user) | ||
| 6 | obj.code = 'LGT' | 7 | obj.code = 'LGT' |
| 7 | end | 8 | end |
| 8 | 9 | ||
| @@ -10,6 +11,7 @@ Factory.add(:public_project, Project) do |obj| | @@ -10,6 +11,7 @@ Factory.add(:public_project, Project) do |obj| | ||
| 10 | obj.name = Faker::Internet.user_name | 11 | obj.name = Faker::Internet.user_name |
| 11 | obj.path = 'legit' | 12 | obj.path = 'legit' |
| 12 | obj.private_flag = false | 13 | obj.private_flag = false |
| 14 | + obj.owner = Factory(:user) | ||
| 13 | obj.code = 'LGT' | 15 | obj.code = 'LGT' |
| 14 | end | 16 | end |
| 15 | 17 |