Permalink
Browse files

Changing 'game' model to 'table' model to better encapsulate concepts

now we have a game_type for a table
  • Loading branch information...
1 parent 365a9ff commit 1013774ff588b4727c590771eb27428500361e34 Ben Feigin committed Feb 16, 2012
View
5 Gemfile
@@ -23,10 +23,15 @@ gem 'database_cleaner', :group => "test"
# Padrino Stable Gem
gem 'padrino', '0.10.5'
+
# Or Padrino Edge
# gem 'padrino', :git => 'git://github.com/padrino/padrino-framework.git'
# Or Individual Gems
# %w(core gen helpers cache mailer admin).each do |g|
# gem 'padrino-' + g, '0.10.5'
# end
+group :development do
+ gem 'guard'
+ gem 'rb-readline'
+end
View
7 Gemfile.lock
@@ -19,9 +19,13 @@ GEM
diff-lcs (1.1.3)
factory_girl (2.5.2)
activesupport (>= 2.3.9)
+ ffi (1.0.11)
grit (2.4.1)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
+ guard (1.0.0)
+ ffi (>= 0.5.0)
+ thor (~> 0.14.6)
haml (3.1.4)
http_router (0.10.2)
rack (>= 1.0.0)
@@ -68,6 +72,7 @@ GEM
rack-test (0.6.1)
rack (>= 1.0)
rake (0.9.2.2)
+ rb-readline (0.4.2)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
@@ -100,10 +105,12 @@ DEPENDENCIES
bcrypt-ruby
database_cleaner
factory_girl
+ guard
haml
padrino (= 0.10.5)
rack-test
rake
+ rb-readline
rspec
sinatra-flash
sqlite3
View
23 Guardfile
@@ -0,0 +1,23 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
+
+
+guard :bundler do
+ watch('Gemfile')
+end
View
2 admin/app.rb
@@ -33,7 +33,7 @@ class Admin < Padrino::Application
access_control.roles_for :admin do |role|
role.project_module :actions, "/actions"
role.project_module :hands, "/hands"
- role.project_module :games, "/games"
+ role.project_module :tables, "/tables"
role.project_module :players, "/players"
role.project_module :tournaments, "/tournaments"
role.project_module :accounts, "/accounts"
View
47 admin/controllers/games.rb
@@ -1,47 +0,0 @@
-Admin.controllers :games do
-
- get :index do
- @games = Game.all
- render 'games/index'
- end
-
- get :new do
- @game = Game.new
- render 'games/new'
- end
-
- post :create do
- @game = Game.new(params[:game])
- if @game.save
- flash[:notice] = 'Game was successfully created.'
- redirect url(:games, :edit, :id => @game.id)
- else
- render 'games/new'
- end
- end
-
- get :edit, :with => :id do
- @game = Game.find(params[:id])
- render 'games/edit'
- end
-
- put :update, :with => :id do
- @game = Game.find(params[:id])
- if @game.update_attributes(params[:game])
- flash[:notice] = 'Game was successfully updated.'
- redirect url(:games, :edit, :id => @game.id)
- else
- render 'games/edit'
- end
- end
-
- delete :destroy, :with => :id do
- game = Game.find(params[:id])
- if game.destroy
- flash[:notice] = 'Game was successfully destroyed.'
- else
- flash[:error] = 'Unable to destroy Game!'
- end
- redirect url(:games, :index)
- end
-end
View
47 admin/controllers/tables.rb
@@ -0,0 +1,47 @@
+Admin.controllers :tables do
+
+ get :index do
+ @tables = Game.all
+ render 'tables/index'
+ end
+
+ get :new do
+ @table = Game.new
+ render 'tables/new'
+ end
+
+ post :create do
+ @table = Game.new(params[:table])
+ if @table.save
+ flash[:notice] = 'Game was successfully created.'
+ redirect url(:tables, :edit, :id => @table.id)
+ else
+ render 'tables/new'
+ end
+ end
+
+ get :edit, :with => :id do
+ @table = Game.find(params[:id])
+ render 'tables/edit'
+ end
+
+ put :update, :with => :id do
+ @table = Game.find(params[:id])
+ if @table.update_attributes(params[:table])
+ flash[:notice] = 'Game was successfully updated.'
+ redirect url(:tables, :edit, :id => @table.id)
+ else
+ render 'tables/edit'
+ end
+ end
+
+ delete :destroy, :with => :id do
+ table = Game.find(params[:id])
+ if table.destroy
+ flash[:notice] = 'Game was successfully destroyed.'
+ else
+ flash[:error] = 'Unable to destroy Game!'
+ end
+ redirect url(:tables, :index)
+ end
+end
View
6 admin/views/actions/_form.haml
@@ -1,7 +1,7 @@
.group
- =f.label :game_id
- =f.error_message_on :game_id
- =f.text_field :game_id, :class => :text_field
+ =f.label :table_id
+ =f.error_message_on :table_id
+ =f.text_field :table_id, :class => :text_field
%span.description Ex: a simple text
.group
View
4 admin/views/actions/index.haml
@@ -11,7 +11,7 @@
%table.table
%tr
%th.first=mat(:action, :id)
- %th=mat(:action, :game_id)
+ %th=mat(:action, :table_id)
%th=mat(:action, :betting_round)
%th=mat(:action, :turn_number)
%th=mat(:action, :action)
@@ -21,7 +21,7 @@
-@actions.each do |action|
%tr
%td.first=action.id
- %td=action.game_id
+ %td=action.table_id
%td=action.betting_round
%td=action.turn_number
%td=action.action
View
15 admin/views/games/edit.haml
@@ -1,15 +0,0 @@
-.block
- .secondary-navigation
- %ul.wat-cf
- %li.first=link_to pat(:list), url(:games, :index)
- %li=link_to pat(:new), url(:games, :new)
- %li.active=link_to pat(:edit), url(:games, :edit, :id => @game.id)
- .content
- %h2.title
- =pat(:edit)
- =mt(:game)
- .inner
- -form_for :game, url(:games, :update, :id => @game.id), :method => :put, :class => :form do |f|
- =partial "games/form", :locals => { :f => f }
-
--content_for :sidebar, partial("base/sidebar")
View
33 admin/views/games/index.haml
@@ -1,33 +0,0 @@
-.block
- .secondary-navigation
- %ul.wat-cf
- %li.first.active=link_to pat(:list), url(:games, :index)
- %li=link_to pat(:new), url(:games, :new)
- .content
- %h2.title
- =pat(:all)
- =mt(:games)
- .inner
- %table.table
- %tr
- %th.first=mat(:game, :id)
- %th=mat(:game, :tournament_id)
- %th=mat(:game, :betting_round)
- %th=mat(:game, :turn)
- %th=mat(:game, :action_to)
- %th.last="&nbsp;"
- -@games.each do |game|
- %tr
- %td.first=game.id
- %td=game.tournament_id
- %td=game.betting_round
- %td=game.turn
- %td=game.action_to
- %td.last
- =button_to pat(:edit), url(:games, :edit, :id => game.id), :method => :get, :class => :button_to
- ="|"
- =button_to pat(:delete), url(:games, :destroy, :id => game.id), :method => :delete, :class => :button_to, :onsubmit => "return confirm('#{pat(:confirm)}')"
- .actions-bar.wat-cf
- .actions="&nbsp;"
-
--content_for :sidebar, partial("base/sidebar")
View
14 admin/views/games/new.haml
@@ -1,14 +0,0 @@
-.block
- .secondary-navigation
- %ul.wat-cf
- %li.first=link_to pat(:list), url(:games, :index)
- %li.active=link_to pat(:new), url(:games, :new)
- .content
- %h2.title
- =pat(:new)
- =mt(:game)
- .inner
- -form_for :game, url(:games, :create), :class => :form do |f|
- =partial "games/form", :locals => { :f => f }
-
--content_for :sidebar, partial("base/sidebar")
View
2 admin/views/games/_form.haml → admin/views/tables/_form.haml
@@ -25,4 +25,4 @@
.group.navform.wat-cf
=f.submit pat(:save), :class => :button
- =f.submit pat(:cancel), :onclick => "window.location='#{url(:games, :index)}';return false", :class => :button
+ =f.submit pat(:cancel), :onclick => "window.location='#{url(:tables, :index)}';return false", :class => :button
View
15 admin/views/tables/edit.haml
@@ -0,0 +1,15 @@
+.block
+ .secondary-navigation
+ %ul.wat-cf
+ %li.first=link_to pat(:list), url(:tables, :index)
+ %li=link_to pat(:new), url(:tables, :new)
+ %li.active=link_to pat(:edit), url(:tables, :edit, :id => @table.id)
+ .content
+ %h2.title
+ =pat(:edit)
+ =mt(:table)
+ .inner
+ -form_for :table, url(:tables, :update, :id => @table.id), :method => :put, :class => :form do |f|
+ =partial "tables/form", :locals => { :f => f }
+
+-content_for :sidebar, partial("base/sidebar")
View
33 admin/views/tables/index.haml
@@ -0,0 +1,33 @@
+.block
+ .secondary-navigation
+ %ul.wat-cf
+ %li.first.active=link_to pat(:list), url(:tables, :index)
+ %li=link_to pat(:new), url(:tables, :new)
+ .content
+ %h2.title
+ =pat(:all)
+ =mt(:tables)
+ .inner
+ %table.table
+ %tr
+ %th.first=mat(:table, :id)
+ %th=mat(:table, :tournament_id)
+ %th=mat(:table, :betting_round)
+ %th=mat(:table, :turn)
+ %th=mat(:table, :action_to)
+ %th.last="&nbsp;"
+ -@tables.each do |table|
+ %tr
+ %td.first=table.id
+ %td=table.tournament_id
+ %td=table.betting_round
+ %td=table.turn
+ %td=table.action_to
+ %td.last
+ =button_to pat(:edit), url(:tables, :edit, :id => table.id), :method => :get, :class => :button_to
+ ="|"
+ =button_to pat(:delete), url(:tables, :destroy, :id => table.id), :method => :delete, :class => :button_to, :onsubmit => "return confirm('#{pat(:confirm)}')"
+ .actions-bar.wat-cf
+ .actions="&nbsp;"
+
+-content_for :sidebar, partial("base/sidebar")
View
14 admin/views/tables/new.haml
@@ -0,0 +1,14 @@
+.block
+ .secondary-navigation
+ %ul.wat-cf
+ %li.first=link_to pat(:list), url(:tables, :index)
+ %li.active=link_to pat(:new), url(:tables, :new)
+ .content
+ %h2.title
+ =pat(:new)
+ =mt(:table)
+ .inner
+ -form_for :table, url(:tables, :create), :class => :form do |f|
+ =partial "tables/form", :locals => { :f => f }
+
+-content_for :sidebar, partial("base/sidebar")
View
BIN db/enova_poker_development.db
Binary file not shown.
View
0 db/enova_poker_production.db
No changes.
View
69 db/schema.rb
@@ -12,59 +12,60 @@
ActiveRecord::Schema.define(:version => 9) do
- create_table "accounts", :force => true do |t|
+ create_table "tournaments", :force => true do |t|
t.string "name"
- t.string "surname"
- t.string "email"
- t.string "crypted_password"
- t.string "role"
end
- create_table "actions", :force => true do |t|
- t.integer "game_id"
- t.string "betting_round"
- t.integer "turn_number"
- t.string "action"
- t.integer "amount"
- t.integer "player_id"
+ create_table "players", :force => true do |t|
+ t.integer "tournament_id"
+ t.string "hostname"
+ t.integer "chips"
+ t.string "name"
end
- create_table "cards", :force => true do |t|
- t.string "value"
- t.string "suit"
+ create_table "seatings", :force => true do |t|
t.integer "player_id"
- t.integer "hand_id"
+ t.integer "table_id"
+ t.integer "seat_number"
+ t.boolean "active"
end
- create_table "games", :force => true do |t|
+ create_table "tables", :force => true do |t|
t.integer "tournament_id"
- t.string "betting_round"
- t.integer "turn"
- t.integer "action_to"
+ t.integer "hands_played"
+ t.string "game_type"
end
create_table "hands", :force => true do |t|
- t.integer "player_id"
+ t.integer "table_id"
t.string "cards"
- t.integer "turn_number"
end
+
+ create_table "rounds", :force => true do |t|
+ t.integer 'hand_id'
+ t.string 'betting_phase'
+ t.boolean 'open'
+ end
- create_table "players", :force => true do |t|
- t.integer "tournament_id"
- t.string "hostname"
- t.integer "chips"
- t.string "name"
+ create_table "actions", :force => true do |t|
+ t.integer "round_id"
+ t.integer "player_id"
+ t.string "action"
+ t.integer "amount"
end
-
- create_table "seatings", :force => true do |t|
+
+ create_table "cards", :force => true do |t|
+ t.string "value"
+ t.string "suit"
t.integer "player_id"
- t.integer "game_id"
- t.integer "seat_number"
- t.boolean "active"
+ t.integer "hand_id"
end
- create_table "tournaments", :force => true do |t|
+ create_table "accounts", :force => true do |t|
t.string "name"
+ t.string "surname"
+ t.string "email"
+ t.string "crypted_password"
+ t.string "role"
end
-
end
View
6 models/game.rb
@@ -1,6 +0,0 @@
-class Game < ActiveRecord::Base
- has_many :hands
- belongs_to :tournament
- has_many :players, :through => :seatings, :conditions => {:active => true}
-
-end
View
3 models/hand.rb
@@ -1,4 +1,3 @@
class Hand < ActiveRecord::Base
- belongs_to :game
-
+ belongs_to :table
end
View
4 models/player.rb
@@ -1,8 +1,8 @@
class Player < ActiveRecord::Base
belongs_to :tournament
has_one :seating
- has_many :games, :through => :seatings do
- def current_game
+ has_many :tables, :through => :seatings do
+ def current_table
where(:active => true)
end
end
View
5 models/round.rb
@@ -2,4 +2,9 @@ class Round < ActiveRecord::Base
belongs_to :hand
has_many :actions
+ def rounds_for(table_type = :texas_holdem)
+ @rounds ||= {:texas_holdem => [:pre_flop, :flop, :turn, :river]}
+ return @rounds[table_type]
+ end
+
end
View
2 models/seating.rb
@@ -1,5 +1,5 @@
class Seating < ActiveRecord::Base
belongs_to :player
- belongs_to :game
+ belongs_to :table
end
View
14 models/table.rb
@@ -0,0 +1,14 @@
+class Table < ActiveRecord::Base
+ has_many :hands
+ belongs_to :tournament
+ has_many :players, :through => :seatings, :conditions => {:active => true}
+
+ def initialize
+ super
+ self.game_type ||= :texas_holdem
+ end
+
+ def begin_new_hand!
+ end
+
+end
View
2 models/tournament.rb
@@ -1,6 +1,6 @@
class Tournament < ActiveRecord::Base
has_many :players
- has_many :games
+ has_many :tables
# Attempt to seat all available players.
def seat!
View
12 spec/models/game_spec.rb
@@ -1,12 +0,0 @@
-require 'spec_helper'
-
-describe "Game Model" do
- let(:game) { Game.new }
- it 'can be created' do
- game.should_not be_nil
- end
-
- it 'should start in the pre_flop betting round' do
- game.betting_round.should == 'pre-flop'
- end
-end
View
1 spec/models/hand_spec.rb
@@ -5,4 +5,5 @@
it 'can be created' do
hand.should_not be_nil
end
+
end
View
5 spec/models/round_spec.rb
@@ -5,4 +5,9 @@
it 'can be created' do
round.should_not be_nil
end
+
+ it 'knows the betting rounds for texas holdem' do
+ round.rounds_for(:texas_holdem).should == [:pre_flop, :flop, :turn, :river]
+ end
+
end
View
16 spec/models/table_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe "Game Model" do
+ let(:table) { Table.new }
+ it 'can be created' do
+ table.should_not be_nil
+ end
+
+ it 'should have a game type' do
+ table.game_type.should_not be_nil
+ end
+
+ it 'can begin a new hand' do
+ table.begin_new_hand!
+ end
+end

0 comments on commit 1013774

Please sign in to comment.