Skip to content
Snippets Groups Projects
Commit 47f3c6cf authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Scaffold for RecurringItems

parent 323953d8
Branches
No related tags found
No related merge requests found
class RecurringItemsController < 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
@recurring_items_pages, @recurring_items = paginate :recurring_items, :per_page => 10
end
def show
@recurring_items = RecurringItems.find(params[:id])
end
def new
@recurring_items = RecurringItems.new
end
def create
@recurring_items = RecurringItems.new(params[:recurring_items])
if @recurring_items.save
flash[:notice] = 'RecurringItems was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@recurring_items = RecurringItems.find(params[:id])
end
def update
@recurring_items = RecurringItems.find(params[:id])
if @recurring_items.update_attributes(params[:recurring_items])
flash[:notice] = 'RecurringItems was successfully updated.'
redirect_to :action => 'show', :id => @recurring_items
else
render :action => 'edit'
end
end
def destroy
RecurringItems.find(params[:id]).destroy
redirect_to :action => 'list'
end
end
module RecurringItemsHelper
end
class RecurringItems < ActiveRecord::Base
end
<html>
<head>
<title>RecurringItems: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= @content_for_layout %>
</body>
</html>
<%= error_messages_for 'recurring_items' %>
<!--[form:recurring_items]-->
<p><label for="recurring_items_description">Description</label><br/>
<%= text_field 'recurring_items', 'description' %></p>
<p><label for="recurring_items_amount">Amount</label><br/>
<%= text_field 'recurring_items', 'amount' %></p>
<p><label for="recurring_items_startdate">Startdate</label><br/>
<%= date_select 'recurring_items', 'startdate' %></p>
<p><label for="recurring_items_enddate">Enddate</label><br/>
<%= date_select 'recurring_items', 'enddate' %></p>
<p><label for="recurring_items_created_on">Created on</label><br/>
<%= datetime_select 'recurring_items', 'created_on' %></p>
<p><label for="recurring_items_updated_on">Updated on</label><br/>
<%= datetime_select 'recurring_items', 'updated_on' %></p>
<!--[eoform:recurring_items]-->
<h1>Editing recurring_items</h1>
<%= start_form_tag :action => 'update', :id => @recurring_items %>
<%= render :partial => 'form' %>
<%= submit_tag 'Edit' %>
<%= end_form_tag %>
<%= link_to 'Show', :action => 'show', :id => @recurring_items %> |
<%= link_to 'Back', :action => 'list' %>
<h1>Listing recurring_items</h1>
<table>
<tr>
<% for column in RecurringItems.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<% for recurring_items in @recurring_items %>
<tr>
<% for column in RecurringItems.content_columns %>
<td><%=h recurring_items.send(column.name) %></td>
<% end %>
<td><%= link_to 'Show', :action => 'show', :id => recurring_items %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => recurring_items %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => recurring_items }, :confirm => 'Are you sure?', :post => true %></td>
</tr>
<% end %>
</table>
<%= link_to 'Previous page', { :page => @recurring_items_pages.current.previous } if @recurring_items_pages.current.previous %>
<%= link_to 'Next page', { :page => @recurring_items_pages.current.next } if @recurring_items_pages.current.next %>
<br />
<%= link_to 'New recurring_items', :action => 'new' %>
<h1>New recurring_items</h1>
<%= start_form_tag :action => 'create' %>
<%= render :partial => 'form' %>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', :action => 'list' %>
<% for column in RecurringItems.content_columns %>
<p>
<b><%= column.human_name %>:</b> <%=h @recurring_items.send(column.name) %>
</p>
<% end %>
<%= link_to 'Edit', :action => 'edit', :id => @recurring_items %> |
<%= link_to 'Back', :action => 'list' %>
require File.dirname(__FILE__) + '/../test_helper'
require 'recurring_items_controller'
# Re-raise errors caught by the controller.
class RecurringItemsController; def rescue_action(e) raise e end; end
class RecurringItemsControllerTest < Test::Unit::TestCase
fixtures :recurring_items
def setup
@controller = RecurringItemsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
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(:recurring_items)
end
def test_show
get :show, :id => 1
assert_response :success
assert_template 'show'
assert_not_nil assigns(:recurring_items)
assert assigns(:recurring_items).valid?
end
def test_new
get :new
assert_response :success
assert_template 'new'
assert_not_nil assigns(:recurring_items)
end
def test_create
num_recurring_items = RecurringItems.count
post :create, :recurring_items => {}
assert_response :redirect
assert_redirected_to :action => 'list'
assert_equal num_recurring_items + 1, RecurringItems.count
end
def test_edit
get :edit, :id => 1
assert_response :success
assert_template 'edit'
assert_not_nil assigns(:recurring_items)
assert assigns(:recurring_items).valid?
end
def test_update
post :update, :id => 1
assert_response :redirect
assert_redirected_to :action => 'show', :id => 1
end
def test_destroy
assert_not_nil RecurringItems.find(1)
post :destroy, :id => 1
assert_response :redirect
assert_redirected_to :action => 'list'
assert_raise(ActiveRecord::RecordNotFound) {
RecurringItems.find(1)
}
end
end
require File.dirname(__FILE__) + '/../test_helper'
class RecurringItemsTest < Test::Unit::TestCase
fixtures :recurring_items
# Replace this with your real tests.
def test_truth
assert true
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment