Skip to content

Commit 62ae911

Browse files
committed
Updated gitignore, added player count check and controller existence check for teams
1 parent 5bc4260 commit 62ae911

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
db/*.sqlite3
33
log/*.log
44
tmp/
5+
Gemfile.lock

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'rails', '3.0.7'
44

55
# Bundle edge Rails instead:
66
# gem 'rails', :git => 'git://github.com/rails/rails.git'
7-
7+
gem 'heroku'
88
gem 'sqlite3'
99
gem 'rake', '0.8.7'
1010
# Use unicorn as the web server

Gemfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ GEM
3030
activesupport (3.0.7)
3131
arel (2.0.10)
3232
builder (2.1.2)
33+
configuration (1.2.0)
3334
erubis (2.6.6)
3435
abstract (>= 1.0.0)
36+
heroku (2.1.4)
37+
launchy (>= 0.3.2)
38+
rest-client (~> 1.6.1)
39+
term-ansicolor (~> 1.0.5)
3540
i18n (0.5.0)
41+
launchy (0.4.0)
42+
configuration (>= 0.0.5)
43+
rake (>= 0.8.1)
3644
mail (2.2.19)
3745
activesupport (>= 2.3.6)
3846
i18n (>= 0.4.0)
@@ -59,7 +67,10 @@ GEM
5967
rake (>= 0.8.7)
6068
thor (~> 0.14.4)
6169
rake (0.8.7)
70+
rest-client (1.6.1)
71+
mime-types (>= 1.16)
6272
sqlite3 (1.3.3)
73+
term-ansicolor (1.0.5)
6374
thor (0.14.6)
6475
treetop (1.4.9)
6576
polyglot (>= 0.3.1)
@@ -69,6 +80,7 @@ PLATFORMS
6980
ruby
7081

7182
DEPENDENCIES
83+
heroku
7284
rails (= 3.0.7)
7385
rake (= 0.8.7)
7486
sqlite3

app/controllers/players_controller.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ def update
7979
def join_team
8080
@player = Player.find(params[:id])
8181

82-
@team = Team.find(params[:team_id])
83-
84-
if @team.valid?
85-
@player.team_id = @team.id
86-
end
82+
@player.team_id = params[:team_id]
8783

8884
respond_to do |format|
8985
if @player.save

app/models/team.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
class Team < ActiveRecord::Base
22
belongs_to :game
33
has_one :controller, :class_name => "Player"
4+
has_many :players
45

56
validates_associated :controller
67
validates_presence_of :name
8+
9+
validate :ensure_controller_exists
10+
validate :ensure_team_limit
11+
12+
#Teams must have at least 1 player and no more than 4
13+
#We check for >= 2 and <= 5 because the controller counts as a player, and we don't want to include them
14+
def ensure_team_limit
15+
errors.add(self, 'cannot have more than 4 or less than 1 player') unless self.players.count >= 2 and self.players.count <= 5
16+
end
17+
18+
def ensure_controller_exists
19+
errors.add(:controller,'must exist') unless self.controller
20+
end
721
end

0 commit comments

Comments
 (0)