OSDN Git Service

create locations
authornomeu <nomeu@nomeu.org>
Tue, 8 Jun 2010 08:04:42 +0000 (17:04 +0900)
committernomeu <nomeu@nomeu.org>
Tue, 8 Jun 2010 08:04:42 +0000 (17:04 +0900)
21 files changed:
.gitignore [new file with mode: 0644]
app/controllers/locations_controller.rb [new file with mode: 0644]
app/helpers/locations_helper.rb [new file with mode: 0644]
app/models/location.rb [new file with mode: 0644]
app/views/layouts/locations.html.erb [new file with mode: 0644]
app/views/locations/edit.html.erb [new file with mode: 0644]
app/views/locations/index.html.erb [new file with mode: 0644]
app/views/locations/new.html.erb [new file with mode: 0644]
app/views/locations/show.html.erb [new file with mode: 0644]
config/routes.rb
db/migrate/20100608074721_create_locations.rb [new file with mode: 0644]
db/schema.rb
log/development.log [deleted file]
log/production.log [deleted file]
log/server.log [deleted file]
log/test.log [deleted file]
public/stylesheets/scaffold.css [new file with mode: 0644]
test/fixtures/locations.yml [new file with mode: 0644]
test/functional/locations_controller_test.rb [new file with mode: 0644]
test/unit/helpers/locations_helper_test.rb [new file with mode: 0644]
test/unit/location_test.rb [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..5da1ce6
--- /dev/null
@@ -0,0 +1,2 @@
+*.swp
+log/*.log
diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb
new file mode 100644 (file)
index 0000000..bd666a4
--- /dev/null
@@ -0,0 +1,85 @@
+class LocationsController < ApplicationController
+  # GET /locations
+  # GET /locations.xml
+  def index
+    @locations = Location.all
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @locations }
+    end
+  end
+
+  # GET /locations/1
+  # GET /locations/1.xml
+  def show
+    @location = Location.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @location }
+    end
+  end
+
+  # GET /locations/new
+  # GET /locations/new.xml
+  def new
+    @location = Location.new
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.xml  { render :xml => @location }
+    end
+  end
+
+  # GET /locations/1/edit
+  def edit
+    @location = Location.find(params[:id])
+  end
+
+  # POST /locations
+  # POST /locations.xml
+  def create
+    @location = Location.new(params[:location])
+
+    respond_to do |format|
+      if @location.save
+        flash[:notice] = 'Location was successfully created.'
+        format.html { redirect_to(@location) }
+        format.xml  { render :xml => @location, :status => :created, :location => @location }
+      else
+        format.html { render :action => "new" }
+        format.xml  { render :xml => @location.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # PUT /locations/1
+  # PUT /locations/1.xml
+  def update
+    @location = Location.find(params[:id])
+
+    respond_to do |format|
+      if @location.update_attributes(params[:location])
+        flash[:notice] = 'Location was successfully updated.'
+        format.html { redirect_to(@location) }
+        format.xml  { head :ok }
+      else
+        format.html { render :action => "edit" }
+        format.xml  { render :xml => @location.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # DELETE /locations/1
+  # DELETE /locations/1.xml
+  def destroy
+    @location = Location.find(params[:id])
+    @location.destroy
+
+    respond_to do |format|
+      format.html { redirect_to(locations_url) }
+      format.xml  { head :ok }
+    end
+  end
+end
diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb
new file mode 100644 (file)
index 0000000..46f9428
--- /dev/null
@@ -0,0 +1,2 @@
+module LocationsHelper
+end
diff --git a/app/models/location.rb b/app/models/location.rb
new file mode 100644 (file)
index 0000000..e3acd90
--- /dev/null
@@ -0,0 +1,2 @@
+class Location < ActiveRecord::Base
+end
diff --git a/app/views/layouts/locations.html.erb b/app/views/layouts/locations.html.erb
new file mode 100644 (file)
index 0000000..83a536a
--- /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>Locations: <%= controller.action_name %></title>
+  <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
diff --git a/app/views/locations/edit.html.erb b/app/views/locations/edit.html.erb
new file mode 100644 (file)
index 0000000..c3e82ae
--- /dev/null
@@ -0,0 +1,24 @@
+<h1>Editing location</h1>
+
+<% form_for(@location) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :code %><br />
+    <%= f.text_field :code %>
+  </p>
+  <p>
+    <%= f.label :site %><br />
+    <%= f.text_field :site %>
+  </p>
+  <p>
+    <%= f.label :summary %><br />
+    <%= f.text_field :summary %>
+  </p>
+  <p>
+    <%= f.submit 'Update' %>
+  </p>
+<% end %>
+
+<%= link_to 'Show', @location %> |
+<%= link_to 'Back', locations_path %>
\ No newline at end of file
diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb
new file mode 100644 (file)
index 0000000..8137c50
--- /dev/null
@@ -0,0 +1,24 @@
+<h1>Listing locations</h1>
+
+<table>
+  <tr>
+    <th>Code</th>
+    <th>Site</th>
+    <th>Summary</th>
+  </tr>
+
+<% @locations.each do |location| %>
+  <tr>
+    <td><%=h location.code %></td>
+    <td><%=h location.site %></td>
+    <td><%=h location.summary %></td>
+    <td><%= link_to 'Show', location %></td>
+    <td><%= link_to 'Edit', edit_location_path(location) %></td>
+    <td><%= link_to 'Destroy', location, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New location', new_location_path %>
\ No newline at end of file
diff --git a/app/views/locations/new.html.erb b/app/views/locations/new.html.erb
new file mode 100644 (file)
index 0000000..ebb5e2e
--- /dev/null
@@ -0,0 +1,23 @@
+<h1>New location</h1>
+
+<% form_for(@location) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :code %><br />
+    <%= f.text_field :code %>
+  </p>
+  <p>
+    <%= f.label :site %><br />
+    <%= f.text_field :site %>
+  </p>
+  <p>
+    <%= f.label :summary %><br />
+    <%= f.text_field :summary %>
+  </p>
+  <p>
+    <%= f.submit 'Create' %>
+  </p>
+<% end %>
+
+<%= link_to 'Back', locations_path %>
\ No newline at end of file
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb
new file mode 100644 (file)
index 0000000..62418f5
--- /dev/null
@@ -0,0 +1,18 @@
+<p>
+  <b>Code:</b>
+  <%=h @location.code %>
+</p>
+
+<p>
+  <b>Site:</b>
+  <%=h @location.site %>
+</p>
+
+<p>
+  <b>Summary:</b>
+  <%=h @location.summary %>
+</p>
+
+
+<%= link_to 'Edit', edit_location_path(@location) %> |
+<%= link_to 'Back', locations_path %>
\ No newline at end of file
index ea14ce1..a7f6056 100644 (file)
@@ -1,4 +1,6 @@
 ActionController::Routing::Routes.draw do |map|
+  map.resources :locations
+
   # The priority is based upon order of creation: first created -> highest priority.
 
   # Sample of regular route:
diff --git a/db/migrate/20100608074721_create_locations.rb b/db/migrate/20100608074721_create_locations.rb
new file mode 100644 (file)
index 0000000..ec6fb5a
--- /dev/null
@@ -0,0 +1,15 @@
+class CreateLocations < ActiveRecord::Migration
+  def self.up
+    create_table :locations do |t|
+      t.string :code, :null => false, :limit => 10
+      t.string :site, :null => false
+      t.string :summary, :null => false
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :locations
+  end
+end
index b81ae5a..e8ace6c 100644 (file)
@@ -9,6 +9,14 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 20100608074721) do
+
+  create_table "locations", :force => true do |t|
+    t.string   "code",       :limit => 10, :null => false
+    t.string   "site",                     :null => false
+    t.string   "summary",                  :null => false
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
 
 end
diff --git a/log/development.log b/log/development.log
deleted file mode 100644 (file)
index 8cb34f3..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-  \e[4;36;1mSQL (0.1ms)\e[0m   \e[0;1mSET client_min_messages TO 'panic'\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET client_min_messages TO 'notice'\e[0m
-  \e[4;36;1mSQL (4.4ms)\e[0m   \e[0;1mCREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) \e[0m
-  \e[4;35;1mSQL (2.7ms)\e[0m   \e[0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")\e[0m
-  \e[4;36;1mSQL (0.3ms)\e[0m   \e[0;1mSELECT version FROM schema_migrations\e[0m
-  \e[4;36;1mSQL (0.1ms)\e[0m   \e[0;1mSET client_min_messages TO 'panic'\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET client_min_messages TO 'notice'\e[0m
-  \e[4;36;1mSQL (0.3ms)\e[0m   \e[0;1mSELECT version FROM schema_migrations\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET client_min_messages TO 'panic'\e[0m
-  \e[4;36;1mSQL (0.1ms)\e[0m   \e[0;1mSET client_min_messages TO 'notice'\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET search_path TO public\e[0m
-  \e[4;36;1mSQL (205.3ms)\e[0m   \e[0;1mDROP DATABASE IF EXISTS "nimono_test"\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET client_min_messages TO 'panic'\e[0m
-  \e[4;36;1mSQL (0.2ms)\e[0m   \e[0;1mSET client_min_messages TO 'notice'\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET search_path TO public\e[0m
-  \e[4;36;1mSQL (370.9ms)\e[0m   \e[0;1mCREATE DATABASE "nimono_test" ENCODING = 'utf8'\e[0m
-  \e[4;35;1mSQL (0.1ms)\e[0m   \e[0mSET client_min_messages TO 'panic'\e[0m
-  \e[4;36;1mSQL (0.1ms)\e[0m   \e[0;1mSET client_min_messages TO 'notice'\e[0m
-  \e[4;35;1mSQL (3.9ms)\e[0m   \e[0mCREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) \e[0m
-  \e[4;36;1mSQL (2.7ms)\e[0m   \e[0;1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")\e[0m
-  \e[4;35;1mSQL (0.3ms)\e[0m   \e[0mSELECT version FROM "schema_migrations"\e[0m
-  \e[4;36;1mSQL (0.9ms)\e[0m   \e[0;1mINSERT INTO "schema_migrations" (version) VALUES ('0')\e[0m
diff --git a/log/production.log b/log/production.log
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/log/server.log b/log/server.log
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/log/test.log b/log/test.log
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css
new file mode 100644 (file)
index 0000000..093c209
--- /dev/null
@@ -0,0 +1,54 @@
+body { background-color: #fff; color: #333; }
+
+body, 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; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+.fieldWithErrors {
+  padding: 2px;
+  background-color: red;
+  display: table;
+}
+
+#errorExplanation {
+  width: 400px;
+  border: 2px solid red;
+  padding: 7px;
+  padding-bottom: 12px;
+  margin-bottom: 20px;
+  background-color: #f0f0f0;
+}
+
+#errorExplanation h2 {
+  text-align: left;
+  font-weight: bold;
+  padding: 5px 5px 5px 15px;
+  font-size: 12px;
+  margin: -7px;
+  background-color: #c00;
+  color: #fff;
+}
+
+#errorExplanation p {
+  color: #333;
+  margin-bottom: 0;
+  padding: 5px;
+}
+
+#errorExplanation ul li {
+  font-size: 12px;
+  list-style: square;
+}
+
diff --git a/test/fixtures/locations.yml b/test/fixtures/locations.yml
new file mode 100644 (file)
index 0000000..49d02ee
--- /dev/null
@@ -0,0 +1,13 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+  id: 1
+  code: MyString
+  site: MyString
+  summary: MyString
+
+two:
+  id: 2
+  code: MyString
+  site: MyString
+  summary: MyString
diff --git a/test/functional/locations_controller_test.rb b/test/functional/locations_controller_test.rb
new file mode 100644 (file)
index 0000000..c8dc983
--- /dev/null
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class LocationsControllerTest < ActionController::TestCase
+  test "should get index" do
+    get :index
+    assert_response :success
+    assert_not_nil assigns(:locations)
+  end
+
+  test "should get new" do
+    get :new
+    assert_response :success
+  end
+
+  test "should create location" do
+    assert_difference('Location.count') do
+      post :create, :location => { :code => 'mmd', :site => 'http://mmd.nomeu.org', :summary => 'mmd uploader by nomeu' }
+    end
+
+    assert_redirected_to location_path(assigns(:location))
+  end
+
+  test "should show location" do
+    get :show, :id => locations(:one).to_param
+    assert_response :success
+  end
+
+  test "should get edit" do
+    get :edit, :id => locations(:one).to_param
+    assert_response :success
+  end
+
+  test "should update location" do
+    put :update, :id => locations(:one).to_param, :location => { }
+    assert_redirected_to location_path(assigns(:location))
+  end
+
+  test "should destroy location" do
+    assert_difference('Location.count', -1) do
+      delete :destroy, :id => locations(:one).to_param
+    end
+
+    assert_redirected_to locations_path
+  end
+end
diff --git a/test/unit/helpers/locations_helper_test.rb b/test/unit/helpers/locations_helper_test.rb
new file mode 100644 (file)
index 0000000..7c96029
--- /dev/null
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class LocationsHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/location_test.rb b/test/unit/location_test.rb
new file mode 100644 (file)
index 0000000..2511bcd
--- /dev/null
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class LocationTest < ActiveSupport::TestCase
+  # Replace this with your real tests.
+  test "the truth" do
+    assert true
+  end
+end