This commit is contained in:
Jason Denney
2012-12-04 00:46:15 -05:00
commit aa3ed3d43b
97 changed files with 2398 additions and 0 deletions
View File
+17
View File
@@ -0,0 +1,17 @@
class Team < ActiveRecord::Base
attr_accessible :name, :max_members, :private_team
belongs_to :captain, :class_name => 'User'
has_many :team_memberships
has_many :members, :through => :team_memberships, :source => :user
validates :name, :presence => true, :uniqueness => true, :length => { :minimum => 3 }
validates :max_members, :presence => true, :numericality => { :only_integer => true, :greater_than => 0 }
validates :captain, :presence => true
self.per_page = 15
def to_s
"#{name}#{private_team? ? '*' : ''}"
end
end
+18
View File
@@ -0,0 +1,18 @@
class TeamMembership < ActiveRecord::Base
belongs_to :team
belongs_to :user
validates :user, :presence => true
validates :team, :presence => true
validates :user_id, :uniqueness => { :scope => :team_id }
validate :no_captains_allowed
private
def no_captains_allowed
if user.present? && team.present? && team.captain == user
errors.add(:user, "Captain is already a member.")
end
end
end
+17
View File
@@ -0,0 +1,17 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :lockable #TODO ,:confirmable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :nickname
validates :first_name, :presence => true
validates :last_name, :presence => true
def to_s
"#{first_name} #{last_name}"
end
end