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
app/models/project.rb
1 | 1 | require "grit" |
2 | 2 | |
3 | 3 | class Project < ActiveRecord::Base |
4 | + belongs_to :owner, :class_name => "User" | |
5 | + | |
4 | 6 | has_many :issues, :dependent => :destroy |
5 | 7 | has_many :users_projects, :dependent => :destroy |
6 | 8 | has_many :users, :through => :users_projects |
7 | - belongs_to :owner, :class_name => "User" | |
8 | 9 | has_many :notes, :dependent => :destroy |
9 | 10 | |
10 | 11 | validates :name, |
... | ... | @@ -25,6 +26,9 @@ class Project < ActiveRecord::Base |
25 | 26 | :uniqueness => true, |
26 | 27 | :length => { :within => 3..12 } |
27 | 28 | |
29 | + validates :owner, | |
30 | + :presence => true | |
31 | + | |
28 | 32 | validate :check_limit |
29 | 33 | |
30 | 34 | before_save :format_code |
... | ... | @@ -130,8 +134,10 @@ class Project < ActiveRecord::Base |
130 | 134 | |
131 | 135 | def check_limit |
132 | 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 | 138 | end |
139 | + rescue | |
140 | + errors[:base] << ("Cant check your ability to create project") | |
135 | 141 | end |
136 | 142 | |
137 | 143 | def valid_repo? | ... | ... |
db/schema.rb
... | ... | @@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009111204) do |
70 | 70 | t.datetime "updated_at" |
71 | 71 | t.string "name" |
72 | 72 | t.boolean "admin", :default => false, :null => false |
73 | - t.integer "projects_limit" | |
73 | + t.integer "projects_limit", :default => 10 | |
74 | 74 | end |
75 | 75 | |
76 | 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 | 3 | Factory.add(:project, Project) do |obj| |
4 | 4 | obj.name = Faker::Internet.user_name |
5 | 5 | obj.path = 'legit' |
6 | + obj.owner = Factory(:user) | |
6 | 7 | obj.code = 'LGT' |
7 | 8 | end |
8 | 9 | |
... | ... | @@ -10,6 +11,7 @@ Factory.add(:public_project, Project) do |obj| |
10 | 11 | obj.name = Faker::Internet.user_name |
11 | 12 | obj.path = 'legit' |
12 | 13 | obj.private_flag = false |
14 | + obj.owner = Factory(:user) | |
13 | 15 | obj.code = 'LGT' |
14 | 16 | end |
15 | 17 | ... | ... |