mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 08:31:36 -04:00
git init
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user