--- /dev/null
+class GamePolicyController < 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
+ @game_policy_pages, @game_policies = paginate :game_policies, :per_page => 10
+ end
+
+ def show
+ @game_policy = GamePolicy.find(params[:id])
+ end
+
+ def new
+ @game_policy = GamePolicy.new
+ end
+
+ def create
+ @game_policy = GamePolicy.new(params[:game_policy])
+ if @game_policy.save
+ flash[:notice] = 'GamePolicy was successfully created.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @game_policy = GamePolicy.find(params[:id])
+ end
+
+ def update
+ @game_policy = GamePolicy.find(params[:id])
+ if @game_policy.update_attributes(params[:game_policy])
+ flash[:notice] = 'GamePolicy was successfully updated.'
+ redirect_to :action => 'show', :id => @game_policy
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ GamePolicy.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end
--- /dev/null
+module GamePolicyHelper
+end
validates_presence_of :platform
def calculated_price
- # FIXME: generate this based on day of week, newrelase
- return 11
+ # FIXME: generate this based on day of week, newrelease
+ day_of_week = Time.now.to_date.wday
+ base_fee = GamePolicy.find_by_day(day_of_week).fee
+
+ # Check for newrelease
+ newrelease_fee = newrelease ? GamePolicy.find_by_day(8).fee : 0.00
+
+ return base_fee + newrelease_fee
end
def due_date
# FIXME: generate this based on the day of week, newrelease
# NOTE: a Date.wday will tell you the day of week (0-6, meaning Sunday-Saturday)
- return Time.now.advance(:days => 2).to_date
+ day_of_week = Time.now.to_date.wday
+ base_period = GamePolicy.find_by_day(day_of_week).period
+ newrelease_period = newrelease ? GamePolicy.find_by_day(8).period : 0
+
+ period = base_period + newrelease_period
+ return Time.now.advance(:days => period).to_date
end
end
--- /dev/null
+class GamePolicy < ActiveRecord::Base
+ validates_presence_of :day
+ validates_presence_of :fee
+ validates_presence_of :period
+ validates_presence_of :description
+
+ validates_numericality_of :day
+ validates_numericality_of :fee
+ validates_numericality_of :period
+
+ protected
+ def validate
+ errors.add(:fee, "must be greater than $0.01") if fee < 0.01
+ end
+end
--- /dev/null
+<%= error_messages_for 'game_policy' %>
+
+<!--[form:game_policy]-->
+<p><label for="game_policy_day">Day</label><br/>
+<%= text_field 'game_policy', 'day' %></p>
+
+<p><label for="game_policy_fee">Fee</label><br/>
+<%= text_field 'game_policy', 'fee' %></p>
+
+<p><label for="game_policy_period">Period</label><br/>
+<%= text_field 'game_policy', 'period' %></p>
+
+<p><label for="game_policy_description">Description</label><br/>
+<%= text_field 'game_policy', 'description' %></p>
+<!--[eoform:game_policy]-->
+
--- /dev/null
+<h1>Editing game_policy</h1>
+
+<% form_tag :action => 'update', :id => @game_policy do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag 'Edit' %>
+<% end %>
+
+<%= link_to 'Show', :action => 'show', :id => @game_policy %> |
+<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<h1>Listing game_policies</h1>
+
+<table>
+ <tr>
+ <% for column in GamePolicy.content_columns %>
+ <th><%= column.human_name %></th>
+ <% end %>
+ </tr>
+
+<% for game_policy in @game_policies %>
+ <tr>
+ <% for column in GamePolicy.content_columns %>
+ <td><%=h game_policy.send(column.name) %></td>
+ <% end %>
+ <td><%= link_to 'Show', :action => 'show', :id => game_policy %></td>
+ <td><%= link_to 'Edit', :action => 'edit', :id => game_policy %></td>
+ <td><%= link_to 'Destroy', { :action => 'destroy', :id => game_policy }, :confirm => 'Are you sure?', :method => :post %></td>
+ </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @game_policy_pages.current.previous } if @game_policy_pages.current.previous %>
+<%= link_to 'Next page', { :page => @game_policy_pages.current.next } if @game_policy_pages.current.next %>
+
+<br />
+
+<%= link_to 'New game_policy', :action => 'new' %>
--- /dev/null
+<h1>New game_policy</h1>
+
+<% form_tag :action => 'create' do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag "Create" %>
+<% end %>
+
+<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<% for column in GamePolicy.content_columns %>
+<p>
+ <b><%= column.human_name %>:</b> <%=h @game_policy.send(column.name) %>
+</p>
+<% end %>
+
+<%= link_to 'Edit', :action => 'edit', :id => @game_policy %> |
+<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>GamePolicy: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
--- /dev/null
+class CreateGamePolicies < ActiveRecord::Migration
+ def self.up
+ create_table :game_policies do |t|
+ t.column :day, :integer, :null => false
+ t.column :fee, :decimal, :precision => 8, :scale => 2, :null => false
+ t.column :period, :integer
+ t.column :description, :string
+ end
+ end
+
+ def self.down
+ drop_table :game_policies
+ end
+end
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 22) do
+ActiveRecord::Schema.define(:version => 23) do
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
t.column "debt", :decimal, :default => 0.0
end
+ create_table "game_policies", :force => true do |t|
+ t.column "day", :integer, :null => false
+ t.column "fee", :decimal, :precision => 8, :scale => 2, :null => false
+ t.column "period", :integer
+ t.column "description", :string
+ end
+
create_table "medias", :force => true do |t|
t.column "name", :string, :null => false
end
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+require 'game_policy_controller'
+
+# Re-raise errors caught by the controller.
+class GamePolicyController; def rescue_action(e) raise e end; end
+
+class GamePolicyControllerTest < Test::Unit::TestCase
+ fixtures :game_policies
+
+ def setup
+ @controller = GamePolicyController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @first_id = game_policies(: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(:game_policies)
+ end
+
+ def test_show
+ get :show, :id => @first_id
+
+ assert_response :success
+ assert_template 'show'
+
+ assert_not_nil assigns(:game_policy)
+ assert assigns(:game_policy).valid?
+ end
+
+ def test_new
+ get :new
+
+ assert_response :success
+ assert_template 'new'
+
+ assert_not_nil assigns(:game_policy)
+ end
+
+ def test_create
+ num_game_policies = GamePolicy.count
+
+ post :create, :game_policy => {}
+
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_equal num_game_policies + 1, GamePolicy.count
+ end
+
+ def test_edit
+ get :edit, :id => @first_id
+
+ assert_response :success
+ assert_template 'edit'
+
+ assert_not_nil assigns(:game_policy)
+ assert assigns(:game_policy).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 {
+ GamePolicy.find(@first_id)
+ }
+
+ post :destroy, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_raise(ActiveRecord::RecordNotFound) {
+ GamePolicy.find(@first_id)
+ }
+ end
+end
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class GamePolicyTest < Test::Unit::TestCase
+ fixtures :game_policies
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end