OSDN Git Service

create arcs
authornomeu <nomeu@nomeu.org>
Tue, 8 Jun 2010 08:12:03 +0000 (17:12 +0900)
committernomeu <nomeu@nomeu.org>
Tue, 8 Jun 2010 08:12:03 +0000 (17:12 +0900)
15 files changed:
app/controllers/arcs_controller.rb [new file with mode: 0644]
app/helpers/arcs_helper.rb [new file with mode: 0644]
app/models/arc.rb [new file with mode: 0644]
app/views/arcs/edit.html.erb [new file with mode: 0644]
app/views/arcs/index.html.erb [new file with mode: 0644]
app/views/arcs/new.html.erb [new file with mode: 0644]
app/views/arcs/show.html.erb [new file with mode: 0644]
app/views/layouts/arcs.html.erb [new file with mode: 0644]
config/routes.rb
db/migrate/20100608080758_create_arcs.rb [new file with mode: 0644]
db/schema.rb
test/fixtures/arcs.yml [new file with mode: 0644]
test/functional/arcs_controller_test.rb [new file with mode: 0644]
test/unit/arc_test.rb [new file with mode: 0644]
test/unit/helpers/arcs_helper_test.rb [new file with mode: 0644]

diff --git a/app/controllers/arcs_controller.rb b/app/controllers/arcs_controller.rb
new file mode 100644 (file)
index 0000000..17aa345
--- /dev/null
@@ -0,0 +1,85 @@
+class ArcsController < ApplicationController
+  # GET /arcs
+  # GET /arcs.xml
+  def index
+    @arcs = Arc.all
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @arcs }
+    end
+  end
+
+  # GET /arcs/1
+  # GET /arcs/1.xml
+  def show
+    @arc = Arc.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @arc }
+    end
+  end
+
+  # GET /arcs/new
+  # GET /arcs/new.xml
+  def new
+    @arc = Arc.new
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.xml  { render :xml => @arc }
+    end
+  end
+
+  # GET /arcs/1/edit
+  def edit
+    @arc = Arc.find(params[:id])
+  end
+
+  # POST /arcs
+  # POST /arcs.xml
+  def create
+    @arc = Arc.new(params[:arc])
+
+    respond_to do |format|
+      if @arc.save
+        flash[:notice] = 'Arc was successfully created.'
+        format.html { redirect_to(@arc) }
+        format.xml  { render :xml => @arc, :status => :created, :location => @arc }
+      else
+        format.html { render :action => "new" }
+        format.xml  { render :xml => @arc.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # PUT /arcs/1
+  # PUT /arcs/1.xml
+  def update
+    @arc = Arc.find(params[:id])
+
+    respond_to do |format|
+      if @arc.update_attributes(params[:arc])
+        flash[:notice] = 'Arc was successfully updated.'
+        format.html { redirect_to(@arc) }
+        format.xml  { head :ok }
+      else
+        format.html { render :action => "edit" }
+        format.xml  { render :xml => @arc.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # DELETE /arcs/1
+  # DELETE /arcs/1.xml
+  def destroy
+    @arc = Arc.find(params[:id])
+    @arc.destroy
+
+    respond_to do |format|
+      format.html { redirect_to(arcs_url) }
+      format.xml  { head :ok }
+    end
+  end
+end
diff --git a/app/helpers/arcs_helper.rb b/app/helpers/arcs_helper.rb
new file mode 100644 (file)
index 0000000..d341c93
--- /dev/null
@@ -0,0 +1,2 @@
+module ArcsHelper
+end
diff --git a/app/models/arc.rb b/app/models/arc.rb
new file mode 100644 (file)
index 0000000..0557fb7
--- /dev/null
@@ -0,0 +1,3 @@
+class Arc < ActiveRecord::Base
+  belongs_to :location
+end
diff --git a/app/views/arcs/edit.html.erb b/app/views/arcs/edit.html.erb
new file mode 100644 (file)
index 0000000..c7f6586
--- /dev/null
@@ -0,0 +1,32 @@
+<h1>Editing arc</h1>
+
+<% form_for(@arc) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :code %><br />
+    <%= f.text_field :code %>
+  </p>
+  <p>
+    <%= f.label :extname %><br />
+    <%= f.text_field :extname %>
+  </p>
+  <p>
+    <%= f.label :location %><br />
+    <%= f.text_field :location %>
+  </p>
+  <p>
+    <%= f.label :summary %><br />
+    <%= f.text_field :summary %>
+  </p>
+  <p>
+    <%= f.label :origname %><br />
+    <%= f.text_field :origname %>
+  </p>
+  <p>
+    <%= f.submit 'Update' %>
+  </p>
+<% end %>
+
+<%= link_to 'Show', @arc %> |
+<%= link_to 'Back', arcs_path %>
\ No newline at end of file
diff --git a/app/views/arcs/index.html.erb b/app/views/arcs/index.html.erb
new file mode 100644 (file)
index 0000000..1dee33e
--- /dev/null
@@ -0,0 +1,28 @@
+<h1>Listing arcs</h1>
+
+<table>
+  <tr>
+    <th>Code</th>
+    <th>Extname</th>
+    <th>Location</th>
+    <th>Summary</th>
+    <th>Origname</th>
+  </tr>
+
+<% @arcs.each do |arc| %>
+  <tr>
+    <td><%=h arc.code %></td>
+    <td><%=h arc.extname %></td>
+    <td><%=h arc.location %></td>
+    <td><%=h arc.summary %></td>
+    <td><%=h arc.origname %></td>
+    <td><%= link_to 'Show', arc %></td>
+    <td><%= link_to 'Edit', edit_arc_path(arc) %></td>
+    <td><%= link_to 'Destroy', arc, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New arc', new_arc_path %>
\ No newline at end of file
diff --git a/app/views/arcs/new.html.erb b/app/views/arcs/new.html.erb
new file mode 100644 (file)
index 0000000..0d05874
--- /dev/null
@@ -0,0 +1,31 @@
+<h1>New arc</h1>
+
+<% form_for(@arc) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :code %><br />
+    <%= f.text_field :code %>
+  </p>
+  <p>
+    <%= f.label :extname %><br />
+    <%= f.text_field :extname %>
+  </p>
+  <p>
+    <%= f.label :location %><br />
+    <%= f.text_field :location %>
+  </p>
+  <p>
+    <%= f.label :summary %><br />
+    <%= f.text_field :summary %>
+  </p>
+  <p>
+    <%= f.label :origname %><br />
+    <%= f.text_field :origname %>
+  </p>
+  <p>
+    <%= f.submit 'Create' %>
+  </p>
+<% end %>
+
+<%= link_to 'Back', arcs_path %>
\ No newline at end of file
diff --git a/app/views/arcs/show.html.erb b/app/views/arcs/show.html.erb
new file mode 100644 (file)
index 0000000..421036f
--- /dev/null
@@ -0,0 +1,28 @@
+<p>
+  <b>Code:</b>
+  <%=h @arc.code %>
+</p>
+
+<p>
+  <b>Extname:</b>
+  <%=h @arc.extname %>
+</p>
+
+<p>
+  <b>Location:</b>
+  <%=h @arc.location %>
+</p>
+
+<p>
+  <b>Summary:</b>
+  <%=h @arc.summary %>
+</p>
+
+<p>
+  <b>Origname:</b>
+  <%=h @arc.origname %>
+</p>
+
+
+<%= link_to 'Edit', edit_arc_path(@arc) %> |
+<%= link_to 'Back', arcs_path %>
\ No newline at end of file
diff --git a/app/views/layouts/arcs.html.erb b/app/views/layouts/arcs.html.erb
new file mode 100644 (file)
index 0000000..b25c4ab
--- /dev/null
@@ -0,0 +1,17 @@
+<!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>Arcs: <%= controller.action_name %></title>
+  <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
index a7f6056..52e83f8 100644 (file)
@@ -1,4 +1,6 @@
 ActionController::Routing::Routes.draw do |map|
+  map.resources :arcs
+
   map.resources :locations
 
   # The priority is based upon order of creation: first created -> highest priority.
diff --git a/db/migrate/20100608080758_create_arcs.rb b/db/migrate/20100608080758_create_arcs.rb
new file mode 100644 (file)
index 0000000..7f6838d
--- /dev/null
@@ -0,0 +1,17 @@
+class CreateArcs < ActiveRecord::Migration
+  def self.up
+    create_table :arcs do |t|
+      t.string :code, :null => false, :limit => 10
+      t.string :extname, :null => false, :limit => 10
+      t.references :location
+      t.string :summary
+      t.string :origname
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :arcs
+  end
+end
index e8ace6c..440449d 100644 (file)
@@ -9,7 +9,17 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20100608074721) do
+ActiveRecord::Schema.define(:version => 20100608080758) do
+
+  create_table "arcs", :force => true do |t|
+    t.string   "code",        :limit => 10, :null => false
+    t.string   "extname",     :limit => 10, :null => false
+    t.integer  "location_id"
+    t.string   "summary"
+    t.string   "origname"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
 
   create_table "locations", :force => true do |t|
     t.string   "code",       :limit => 10, :null => false
diff --git a/test/fixtures/arcs.yml b/test/fixtures/arcs.yml
new file mode 100644 (file)
index 0000000..725fe7e
--- /dev/null
@@ -0,0 +1,17 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+  id: 1
+  code: MyString
+  extname: MyString
+  location_id: 1
+  summary: MyString
+  origname: MyString
+
+two:
+  id: 2
+  code: MyString
+  extname: MyString
+  location_id: 1
+  summary: MyString
+  origname: MyString
diff --git a/test/functional/arcs_controller_test.rb b/test/functional/arcs_controller_test.rb
new file mode 100644 (file)
index 0000000..494d9d7
--- /dev/null
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class ArcsControllerTest < ActionController::TestCase
+  test "should get index" do
+    get :index
+    assert_response :success
+    assert_not_nil assigns(:arcs)
+  end
+
+  test "should get new" do
+    get :new
+    assert_response :success
+  end
+
+  test "should create arc" do
+    assert_difference('Arc.count') do
+      post :create, :arc => { :code => 'up0001', :extname => 'zip' }
+    end
+
+    assert_redirected_to arc_path(assigns(:arc))
+  end
+
+  test "should show arc" do
+    get :show, :id => arcs(:one).to_param
+    assert_response :success
+  end
+
+  test "should get edit" do
+    get :edit, :id => arcs(:one).to_param
+    assert_response :success
+  end
+
+  test "should update arc" do
+    put :update, :id => arcs(:one).to_param, :arc => { }
+    assert_redirected_to arc_path(assigns(:arc))
+  end
+
+  test "should destroy arc" do
+    assert_difference('Arc.count', -1) do
+      delete :destroy, :id => arcs(:one).to_param
+    end
+
+    assert_redirected_to arcs_path
+  end
+end
diff --git a/test/unit/arc_test.rb b/test/unit/arc_test.rb
new file mode 100644 (file)
index 0000000..bb524e9
--- /dev/null
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ArcTest < ActiveSupport::TestCase
+  # Replace this with your real tests.
+  test "the truth" do
+    assert true
+  end
+end
diff --git a/test/unit/helpers/arcs_helper_test.rb b/test/unit/helpers/arcs_helper_test.rb
new file mode 100644 (file)
index 0000000..2e5b4aa
--- /dev/null
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ArcsHelperTest < ActionView::TestCase
+end