From: Ira W. Snyder
Date: Sat, 24 Nov 2007 01:25:23 +0000 (-0800)
Subject: Add the Gameplatform MVC to handle the different game platforms
X-Git-Tag: turned-in~46
X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=f96a0f6949f29078cd2c5e3c81d3ac48ac710fbe;p=cs356-p2-videostore.git
Add the Gameplatform MVC to handle the different game platforms
Signed-off-by: Ira W. Snyder
---
diff --git a/app/controllers/gameplatform_controller.rb b/app/controllers/gameplatform_controller.rb
new file mode 100644
index 0000000..30aadf9
--- /dev/null
+++ b/app/controllers/gameplatform_controller.rb
@@ -0,0 +1,51 @@
+class GameplatformController < ApplicationController
+ def index
+ list
+ render :action => 'list'
+ end
+
+ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+ verify :method => :post, :only => [ :destroy, :create, :update ],
+ :redirect_to => { :action => :list }
+
+ def list
+ @gameplatform_pages, @gameplatforms = paginate :gameplatforms, :per_page => 10
+ end
+
+ def show
+ @gameplatform = Gameplatform.find(params[:id])
+ end
+
+ def new
+ @gameplatform = Gameplatform.new
+ end
+
+ def create
+ @gameplatform = Gameplatform.new(params[:gameplatform])
+ if @gameplatform.save
+ flash[:notice] = 'Gameplatform was successfully created.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @gameplatform = Gameplatform.find(params[:id])
+ end
+
+ def update
+ @gameplatform = Gameplatform.find(params[:id])
+ if @gameplatform.update_attributes(params[:gameplatform])
+ flash[:notice] = 'Gameplatform was successfully updated.'
+ redirect_to :action => 'show', :id => @gameplatform
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ Gameplatform.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end
diff --git a/app/helpers/gameplatform_helper.rb b/app/helpers/gameplatform_helper.rb
new file mode 100644
index 0000000..a8bb6d0
--- /dev/null
+++ b/app/helpers/gameplatform_helper.rb
@@ -0,0 +1,2 @@
+module GameplatformHelper
+end
diff --git a/app/models/game.rb b/app/models/game.rb
index 15bf8e0..ed7f30b 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -6,6 +6,10 @@ class Game < Rentable
return Gamegenre.find(game_genre).name
end
+ def game_platform
+ return Gameplatform.find(platform).name
+ end
+
def calculated_price
# FIXME: generate this based on day of week, newrelease
day_of_week = Time.now.to_date.wday
diff --git a/app/models/gameplatform.rb b/app/models/gameplatform.rb
new file mode 100644
index 0000000..340470f
--- /dev/null
+++ b/app/models/gameplatform.rb
@@ -0,0 +1,2 @@
+class Gameplatform < ActiveRecord::Base
+end
diff --git a/app/views/game/_form.rhtml b/app/views/game/_form.rhtml
index b65208f..69c3904 100644
--- a/app/views/game/_form.rhtml
+++ b/app/views/game/_form.rhtml
@@ -8,7 +8,7 @@
<%= check_box 'game', 'newrelease' %>
-<%= text_field 'game', 'platform' %>
+<%= select 'game', 'platform', Gameplatform.find(:all).collect {|c| [c.name.to_s, c.id] } %>
<%= select 'game', 'game_genre', Gamegenre.find(:all).collect {|c| [c.name.to_s, c.id] } %>
diff --git a/app/views/game/list.rhtml b/app/views/game/list.rhtml
index fce55da..d35c1eb 100644
--- a/app/views/game/list.rhtml
+++ b/app/views/game/list.rhtml
@@ -17,7 +17,7 @@
<%=h game.title %> |
<%=h game.newrelease %> |
<%=h game.genre %> |
- FIXME |
+ <%=h game.game_platform %> |
<%= link_to 'Show', :action => 'show', :id => game %> |
<%= link_to 'Edit', :action => 'edit', :id => game %> |
<%= link_to 'Destroy', { :action => 'destroy', :id => game }, :confirm => 'Are you sure?', :method => :post %> |
diff --git a/app/views/gameplatform/_form.rhtml b/app/views/gameplatform/_form.rhtml
new file mode 100644
index 0000000..7ea8d9b
--- /dev/null
+++ b/app/views/gameplatform/_form.rhtml
@@ -0,0 +1,7 @@
+<%= error_messages_for 'gameplatform' %>
+
+
+
+<%= text_field 'gameplatform', 'name' %>
+
+
diff --git a/app/views/gameplatform/edit.rhtml b/app/views/gameplatform/edit.rhtml
new file mode 100644
index 0000000..5eb3cbd
--- /dev/null
+++ b/app/views/gameplatform/edit.rhtml
@@ -0,0 +1,9 @@
+Editing gameplatform
+
+<% form_tag :action => 'update', :id => @gameplatform do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag 'Edit' %>
+<% end %>
+
+<%= link_to 'Show', :action => 'show', :id => @gameplatform %> |
+<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/gameplatform/list.rhtml b/app/views/gameplatform/list.rhtml
new file mode 100644
index 0000000..e2be35d
--- /dev/null
+++ b/app/views/gameplatform/list.rhtml
@@ -0,0 +1,27 @@
+Listing gameplatforms
+
+
+
+ <% for column in Gameplatform.content_columns %>
+ <%= column.human_name %> |
+ <% end %>
+
+
+<% for gameplatform in @gameplatforms %>
+
+ <% for column in Gameplatform.content_columns %>
+ <%=h gameplatform.send(column.name) %> |
+ <% end %>
+ <%= link_to 'Show', :action => 'show', :id => gameplatform %> |
+ <%= link_to 'Edit', :action => 'edit', :id => gameplatform %> |
+ <%= link_to 'Destroy', { :action => 'destroy', :id => gameplatform }, :confirm => 'Are you sure?', :method => :post %> |
+
+<% end %>
+
+
+<%= link_to 'Previous page', { :page => @gameplatform_pages.current.previous } if @gameplatform_pages.current.previous %>
+<%= link_to 'Next page', { :page => @gameplatform_pages.current.next } if @gameplatform_pages.current.next %>
+
+
+
+<%= link_to 'New gameplatform', :action => 'new' %>
diff --git a/app/views/gameplatform/new.rhtml b/app/views/gameplatform/new.rhtml
new file mode 100644
index 0000000..7341fb4
--- /dev/null
+++ b/app/views/gameplatform/new.rhtml
@@ -0,0 +1,8 @@
+New gameplatform
+
+<% form_tag :action => 'create' do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag "Create" %>
+<% end %>
+
+<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/gameplatform/show.rhtml b/app/views/gameplatform/show.rhtml
new file mode 100644
index 0000000..12b8ce5
--- /dev/null
+++ b/app/views/gameplatform/show.rhtml
@@ -0,0 +1,8 @@
+<% for column in Gameplatform.content_columns %>
+
+ <%= column.human_name %>: <%=h @gameplatform.send(column.name) %>
+
+<% end %>
+
+<%= link_to 'Edit', :action => 'edit', :id => @gameplatform %> |
+<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/layouts/gameplatform.rhtml b/app/views/layouts/gameplatform.rhtml
new file mode 100644
index 0000000..8abc654
--- /dev/null
+++ b/app/views/layouts/gameplatform.rhtml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Gameplatform: <%= controller.action_name %>
+ <%= stylesheet_link_tag 'scaffold' %>
+
+
+
+<%= flash[:notice] %>
+
+<%= yield %>
+
+
+
diff --git a/db/development.sqlite3 b/db/development.sqlite3
index 6285c9d..92a8e4b 100644
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ
diff --git a/db/migrate/025_create_gameplatforms.rb b/db/migrate/025_create_gameplatforms.rb
new file mode 100644
index 0000000..854dce8
--- /dev/null
+++ b/db/migrate/025_create_gameplatforms.rb
@@ -0,0 +1,11 @@
+class CreateGameplatforms < ActiveRecord::Migration
+ def self.up
+ create_table :gameplatforms do |t|
+ t.column :name, :string, :null => false
+ end
+ end
+
+ def self.down
+ drop_table :gameplatforms
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d372187..ef94c3e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -2,7 +2,7 @@
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 24) do
+ActiveRecord::Schema.define(:version => 25) do
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
@@ -36,6 +36,10 @@ ActiveRecord::Schema.define(:version => 24) do
t.column "name", :string, :null => false
end
+ create_table "gameplatforms", :force => true do |t|
+ t.column "name", :string, :null => false
+ end
+
create_table "medias", :force => true do |t|
t.column "name", :string, :null => false
end
diff --git a/test/fixtures/gameplatforms.yml b/test/fixtures/gameplatforms.yml
new file mode 100644
index 0000000..b49c4eb
--- /dev/null
+++ b/test/fixtures/gameplatforms.yml
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
diff --git a/test/functional/gameplatform_controller_test.rb b/test/functional/gameplatform_controller_test.rb
new file mode 100644
index 0000000..f170664
--- /dev/null
+++ b/test/functional/gameplatform_controller_test.rb
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'gameplatform_controller'
+
+# Re-raise errors caught by the controller.
+class GameplatformController; def rescue_action(e) raise e end; end
+
+class GameplatformControllerTest < Test::Unit::TestCase
+ fixtures :gameplatforms
+
+ def setup
+ @controller = GameplatformController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @first_id = gameplatforms(:first).id
+ end
+
+ def test_index
+ get :index
+ assert_response :success
+ assert_template 'list'
+ end
+
+ def test_list
+ get :list
+
+ assert_response :success
+ assert_template 'list'
+
+ assert_not_nil assigns(:gameplatforms)
+ end
+
+ def test_show
+ get :show, :id => @first_id
+
+ assert_response :success
+ assert_template 'show'
+
+ assert_not_nil assigns(:gameplatform)
+ assert assigns(:gameplatform).valid?
+ end
+
+ def test_new
+ get :new
+
+ assert_response :success
+ assert_template 'new'
+
+ assert_not_nil assigns(:gameplatform)
+ end
+
+ def test_create
+ num_gameplatforms = Gameplatform.count
+
+ post :create, :gameplatform => {}
+
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_equal num_gameplatforms + 1, Gameplatform.count
+ end
+
+ def test_edit
+ get :edit, :id => @first_id
+
+ assert_response :success
+ assert_template 'edit'
+
+ assert_not_nil assigns(:gameplatform)
+ assert assigns(:gameplatform).valid?
+ end
+
+ def test_update
+ post :update, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'show', :id => @first_id
+ end
+
+ def test_destroy
+ assert_nothing_raised {
+ Gameplatform.find(@first_id)
+ }
+
+ post :destroy, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_raise(ActiveRecord::RecordNotFound) {
+ Gameplatform.find(@first_id)
+ }
+ end
+end
diff --git a/test/unit/gameplatform_test.rb b/test/unit/gameplatform_test.rb
new file mode 100644
index 0000000..a796e92
--- /dev/null
+++ b/test/unit/gameplatform_test.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class GameplatformTest < Test::Unit::TestCase
+ fixtures :gameplatforms
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end