Permalink
Browse files

Scaffold test Page model.

  • Loading branch information...
ejholmes committed Apr 30, 2012
1 parent cfeba75 commit 5572e09ae862fe1932851f1603b9d02ddcd8c5bf
@@ -0,0 +1,3 @@
+ActiveAdmin.register Page do
+
+end
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
@@ -0,0 +1,3 @@
+// Place all the styles related to the Pages controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
@@ -0,0 +1,2 @@
+class PagesController < InheritedResources::Base
+end
@@ -0,0 +1,2 @@
+module PagesHelper
+end
@@ -0,0 +1,3 @@
+class Page < ActiveRecord::Base
+ attr_accessible :content, :title
+end
@@ -0,0 +1,25 @@
+<%= form_for(@page) do |f| %>
+ <% if @page.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@page.errors.count, "error") %> prohibited this page from being saved:</h2>
+
+ <ul>
+ <% @page.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :title %><br />
+ <%= f.text_field :title %>
+ </div>
+ <div class="field">
+ <%= f.label :content %><br />
+ <%= f.text_area :content %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing page</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @page %> |
+<%= link_to 'Back', pages_path %>
@@ -0,0 +1,25 @@
+<h1>Listing pages</h1>
+
+<table>
+ <tr>
+ <th>Title</th>
+ <th>Content</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @pages.each do |page| %>
+ <tr>
+ <td><%= page.title %></td>
+ <td><%= page.content %></td>
+ <td><%= link_to 'Show', page %></td>
+ <td><%= link_to 'Edit', edit_page_path(page) %></td>
+ <td><%= link_to 'Destroy', page, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Page', new_page_path %>
@@ -0,0 +1,5 @@
+<h1>New page</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', pages_path %>
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Title:</b>
+ <%= @page.title %>
+</p>
+
+<p>
+ <b>Content:</b>
+ <%= @page.content %>
+</p>
+
+
+<%= link_to 'Edit', edit_page_path(@page) %> |
+<%= link_to 'Back', pages_path %>
@@ -1,4 +1,6 @@
Dummy::Application.routes.draw do
+ resources :pages
+
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
@@ -0,0 +1,10 @@
+class CreatePages < ActiveRecord::Migration
+ def change
+ create_table :pages do |t|
+ t.string :title
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120430200549) do
+ActiveRecord::Schema.define(:version => 20120430201522) do
create_table "active_admin_comments", :force => true do |t|
t.string "resource_id", :null => false
@@ -46,4 +46,11 @@
add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
+ create_table "pages", :force => true do |t|
+ t.string "title"
+ t.text "content"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
end
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ title: MyString
+ content: MyText
+
+two:
+ title: MyString
+ content: MyText
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PagesControllerTest < ActionController::TestCase
+ setup do
+ @page = pages(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:pages)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create page" do
+ assert_difference('Page.count') do
+ post :create, page: { content: @page.content, title: @page.title }
+ end
+
+ assert_redirected_to page_path(assigns(:page))
+ end
+
+ test "should show page" do
+ get :show, id: @page
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @page
+ assert_response :success
+ end
+
+ test "should update page" do
+ put :update, id: @page, page: { content: @page.content, title: @page.title }
+ assert_redirected_to page_path(assigns(:page))
+ end
+
+ test "should destroy page" do
+ assert_difference('Page.count', -1) do
+ delete :destroy, id: @page
+ end
+
+ assert_redirected_to pages_path
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PagesHelperTest < ActionView::TestCase
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PageTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 5572e09

Please sign in to comment.