summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-01-31 13:04:29 +0100
committerhukl <hukl@eight.local>2009-01-31 13:04:29 +0100
commit89d3dc4a676ee82cc6bad4d9d00535897318f1c3 (patch)
tree193c17723e67a2140323bbc9d68985a7f5545b0f
parent71f70cca407fa0dad84c3b8babc63e42e40d8ea2 (diff)
Added Page model scaffold
-rw-r--r--app/controllers/pages_controller.rb85
-rw-r--r--app/helpers/pages_helper.rb2
-rw-r--r--app/models/page.rb7
-rw-r--r--app/views/layouts/pages.html.erb17
-rw-r--r--app/views/pages/edit.html.erb32
-rw-r--r--app/views/pages/index.html.erb28
-rw-r--r--app/views/pages/new.html.erb31
-rw-r--r--app/views/pages/show.html.erb28
-rw-r--r--db/migrate/20090131113802_create_pages.rb17
-rw-r--r--public/stylesheets/scaffold.css54
-rw-r--r--test/fixtures/pages.yml15
-rw-r--r--test/functional/pages_controller_test.rb45
-rw-r--r--test/unit/helpers/pages_helper_test.rb4
-rw-r--r--test/unit/page_test.rb5
14 files changed, 370 insertions, 0 deletions
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
new file mode 100644
index 0000000..7e3f955
--- /dev/null
+++ b/app/controllers/pages_controller.rb
@@ -0,0 +1,85 @@
1class PagesController < ApplicationController
2 # GET /pages
3 # GET /pages.xml
4 def index
5 @pages = Page.find(:all)
6
7 respond_to do |format|
8 format.html # index.html.erb
9 format.xml { render :xml => @pages }
10 end
11 end
12
13 # GET /pages/1
14 # GET /pages/1.xml
15 def show
16 @page = Page.find(params[:id])
17
18 respond_to do |format|
19 format.html # show.html.erb
20 format.xml { render :xml => @page }
21 end
22 end
23
24 # GET /pages/new
25 # GET /pages/new.xml
26 def new
27 @page = Page.new
28
29 respond_to do |format|
30 format.html # new.html.erb
31 format.xml { render :xml => @page }
32 end
33 end
34
35 # GET /pages/1/edit
36 def edit
37 @page = Page.find(params[:id])
38 end
39
40 # POST /pages
41 # POST /pages.xml
42 def create
43 @page = Page.new(params[:page])
44
45 respond_to do |format|
46 if @page.save
47 flash[:notice] = 'Page was successfully created.'
48 format.html { redirect_to(@page) }
49 format.xml { render :xml => @page, :status => :created, :location => @page }
50 else
51 format.html { render :action => "new" }
52 format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
53 end
54 end
55 end
56
57 # PUT /pages/1
58 # PUT /pages/1.xml
59 def update
60 @page = Page.find(params[:id])
61
62 respond_to do |format|
63 if @page.update_attributes(params[:page])
64 flash[:notice] = 'Page was successfully updated.'
65 format.html { redirect_to(@page) }
66 format.xml { head :ok }
67 else
68 format.html { render :action => "edit" }
69 format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
70 end
71 end
72 end
73
74 # DELETE /pages/1
75 # DELETE /pages/1.xml
76 def destroy
77 @page = Page.find(params[:id])
78 @page.destroy
79
80 respond_to do |format|
81 format.html { redirect_to(pages_url) }
82 format.xml { head :ok }
83 end
84 end
85end
diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb
new file mode 100644
index 0000000..2c057fd
--- /dev/null
+++ b/app/helpers/pages_helper.rb
@@ -0,0 +1,2 @@
1module PagesHelper
2end
diff --git a/app/models/page.rb b/app/models/page.rb
new file mode 100644
index 0000000..0fcb4a8
--- /dev/null
+++ b/app/models/page.rb
@@ -0,0 +1,7 @@
1class Page < ActiveRecord::Base
2
3 belongs_to :node
4
5 acts_as_list :column => :revision, :scope => :node_id
6
7end
diff --git a/app/views/layouts/pages.html.erb b/app/views/layouts/pages.html.erb
new file mode 100644
index 0000000..327e0eb
--- /dev/null
+++ b/app/views/layouts/pages.html.erb
@@ -0,0 +1,17 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5<head>
6 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7 <title>Pages: <%= controller.action_name %></title>
8 <%= stylesheet_link_tag 'scaffold' %>
9</head>
10<body>
11
12<p style="color: green"><%= flash[:notice] %></p>
13
14<%= yield %>
15
16</body>
17</html>
diff --git a/app/views/pages/edit.html.erb b/app/views/pages/edit.html.erb
new file mode 100644
index 0000000..a4b285a
--- /dev/null
+++ b/app/views/pages/edit.html.erb
@@ -0,0 +1,32 @@
1<h1>Editing page</h1>
2
3<% form_for(@page) do |f| %>
4 <%= f.error_messages %>
5
6 <p>
7 <%= f.label :node_id %><br />
8 <%= f.text_field :node_id %>
9 </p>
10 <p>
11 <%= f.label :title %><br />
12 <%= f.text_field :title %>
13 </p>
14 <p>
15 <%= f.label :abstract %><br />
16 <%= f.text_area :abstract %>
17 </p>
18 <p>
19 <%= f.label :body %><br />
20 <%= f.text_area :body %>
21 </p>
22 <p>
23 <%= f.label :revision %><br />
24 <%= f.text_field :revision %>
25 </p>
26 <p>
27 <%= f.submit "Update" %>
28 </p>
29<% end %>
30
31<%= link_to 'Show', @page %> |
32<%= link_to 'Back', pages_path %>
diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb
new file mode 100644
index 0000000..41c8bae
--- /dev/null
+++ b/app/views/pages/index.html.erb
@@ -0,0 +1,28 @@
1<h1>Listing pages</h1>
2
3<table>
4 <tr>
5 <th>Node</th>
6 <th>Title</th>
7 <th>Abstract</th>
8 <th>Body</th>
9 <th>Revision</th>
10 </tr>
11
12<% for page in @pages %>
13 <tr>
14 <td><%=h page.node_id %></td>
15 <td><%=h page.title %></td>
16 <td><%=h page.abstract %></td>
17 <td><%=h page.body %></td>
18 <td><%=h page.revision %></td>
19 <td><%= link_to 'Show', page %></td>
20 <td><%= link_to 'Edit', edit_page_path(page) %></td>
21 <td><%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %></td>
22 </tr>
23<% end %>
24</table>
25
26<br />
27
28<%= link_to 'New page', new_page_path %>
diff --git a/app/views/pages/new.html.erb b/app/views/pages/new.html.erb
new file mode 100644
index 0000000..b27dc62
--- /dev/null
+++ b/app/views/pages/new.html.erb
@@ -0,0 +1,31 @@
1<h1>New page</h1>
2
3<% form_for(@page) do |f| %>
4 <%= f.error_messages %>
5
6 <p>
7 <%= f.label :node_id %><br />
8 <%= f.text_field :node_id %>
9 </p>
10 <p>
11 <%= f.label :title %><br />
12 <%= f.text_field :title %>
13 </p>
14 <p>
15 <%= f.label :abstract %><br />
16 <%= f.text_area :abstract %>
17 </p>
18 <p>
19 <%= f.label :body %><br />
20 <%= f.text_area :body %>
21 </p>
22 <p>
23 <%= f.label :revision %><br />
24 <%= f.text_field :revision %>
25 </p>
26 <p>
27 <%= f.submit "Create" %>
28 </p>
29<% end %>
30
31<%= link_to 'Back', pages_path %>
diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb
new file mode 100644
index 0000000..254b940
--- /dev/null
+++ b/app/views/pages/show.html.erb
@@ -0,0 +1,28 @@
1<p>
2 <b>Node:</b>
3 <%=h @page.node_id %>
4</p>
5
6<p>
7 <b>Title:</b>
8 <%=h @page.title %>
9</p>
10
11<p>
12 <b>Abstract:</b>
13 <%=h @page.abstract %>
14</p>
15
16<p>
17 <b>Body:</b>
18 <%=h @page.body %>
19</p>
20
21<p>
22 <b>Revision:</b>
23 <%=h @page.revision %>
24</p>
25
26
27<%= link_to 'Edit', edit_page_path(@page) %> |
28<%= link_to 'Back', pages_path %>
diff --git a/db/migrate/20090131113802_create_pages.rb b/db/migrate/20090131113802_create_pages.rb
new file mode 100644
index 0000000..7493ffc
--- /dev/null
+++ b/db/migrate/20090131113802_create_pages.rb
@@ -0,0 +1,17 @@
1class CreatePages < ActiveRecord::Migration
2 def self.up
3 create_table :pages do |t|
4 t.integer :node_id
5 t.string :title
6 t.text :abstract
7 t.text :body
8 t.integer :revision
9
10 t.timestamps
11 end
12 end
13
14 def self.down
15 drop_table :pages
16 end
17end
diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css
new file mode 100644
index 0000000..093c209
--- /dev/null
+++ b/public/stylesheets/scaffold.css
@@ -0,0 +1,54 @@
1body { background-color: #fff; color: #333; }
2
3body, p, ol, ul, td {
4 font-family: verdana, arial, helvetica, sans-serif;
5 font-size: 13px;
6 line-height: 18px;
7}
8
9pre {
10 background-color: #eee;
11 padding: 10px;
12 font-size: 11px;
13}
14
15a { color: #000; }
16a:visited { color: #666; }
17a:hover { color: #fff; background-color:#000; }
18
19.fieldWithErrors {
20 padding: 2px;
21 background-color: red;
22 display: table;
23}
24
25#errorExplanation {
26 width: 400px;
27 border: 2px solid red;
28 padding: 7px;
29 padding-bottom: 12px;
30 margin-bottom: 20px;
31 background-color: #f0f0f0;
32}
33
34#errorExplanation h2 {
35 text-align: left;
36 font-weight: bold;
37 padding: 5px 5px 5px 15px;
38 font-size: 12px;
39 margin: -7px;
40 background-color: #c00;
41 color: #fff;
42}
43
44#errorExplanation p {
45 color: #333;
46 margin-bottom: 0;
47 padding: 5px;
48}
49
50#errorExplanation ul li {
51 font-size: 12px;
52 list-style: square;
53}
54
diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml
new file mode 100644
index 0000000..2b1cad1
--- /dev/null
+++ b/test/fixtures/pages.yml
@@ -0,0 +1,15 @@
1# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
3one:
4 node_id: 1
5 title: MyString
6 abstract: MyText
7 body: MyText
8 revision: 1
9
10two:
11 node_id: 1
12 title: MyString
13 abstract: MyText
14 body: MyText
15 revision: 1
diff --git a/test/functional/pages_controller_test.rb b/test/functional/pages_controller_test.rb
new file mode 100644
index 0000000..97ca1b6
--- /dev/null
+++ b/test/functional/pages_controller_test.rb
@@ -0,0 +1,45 @@
1require 'test_helper'
2
3class PagesControllerTest < ActionController::TestCase
4 test "should get index" do
5 get :index
6 assert_response :success
7 assert_not_nil assigns(:pages)
8 end
9
10 test "should get new" do
11 get :new
12 assert_response :success
13 end
14
15 test "should create page" do
16 assert_difference('Page.count') do
17 post :create, :page => { }
18 end
19
20 assert_redirected_to page_path(assigns(:page))
21 end
22
23 test "should show page" do
24 get :show, :id => pages(:one).id
25 assert_response :success
26 end
27
28 test "should get edit" do
29 get :edit, :id => pages(:one).id
30 assert_response :success
31 end
32
33 test "should update page" do
34 put :update, :id => pages(:one).id, :page => { }
35 assert_redirected_to page_path(assigns(:page))
36 end
37
38 test "should destroy page" do
39 assert_difference('Page.count', -1) do
40 delete :destroy, :id => pages(:one).id
41 end
42
43 assert_redirected_to pages_path
44 end
45end
diff --git a/test/unit/helpers/pages_helper_test.rb b/test/unit/helpers/pages_helper_test.rb
new file mode 100644
index 0000000..535dfe1
--- /dev/null
+++ b/test/unit/helpers/pages_helper_test.rb
@@ -0,0 +1,4 @@
1require 'test_helper'
2
3class PagesHelperTest < ActionView::TestCase
4end
diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb
new file mode 100644
index 0000000..af62e93
--- /dev/null
+++ b/test/unit/page_test.rb
@@ -0,0 +1,5 @@
1require 'test_helper'
2
3class PageTest < ActiveSupport::TestCase
4
5end