From a37862371235c4c083ba557a8148ab1ea554a3cc Mon Sep 17 00:00:00 2001 From: nomeu Date: Tue, 8 Jun 2010 17:04:42 +0900 Subject: [PATCH] create locations --- .gitignore | 2 + app/controllers/locations_controller.rb | 85 +++++++++++++++++++++++++++ app/helpers/locations_helper.rb | 2 + app/models/location.rb | 2 + app/views/layouts/locations.html.erb | 17 ++++++ app/views/locations/edit.html.erb | 24 ++++++++ app/views/locations/index.html.erb | 24 ++++++++ app/views/locations/new.html.erb | 23 ++++++++ app/views/locations/show.html.erb | 18 ++++++ config/routes.rb | 2 + db/migrate/20100608074721_create_locations.rb | 15 +++++ db/schema.rb | 10 +++- log/development.log | 22 ------- log/production.log | 0 log/server.log | 0 log/test.log | 0 public/stylesheets/scaffold.css | 54 +++++++++++++++++ test/fixtures/locations.yml | 13 ++++ test/functional/locations_controller_test.rb | 45 ++++++++++++++ test/unit/helpers/locations_helper_test.rb | 4 ++ test/unit/location_test.rb | 8 +++ 21 files changed, 347 insertions(+), 23 deletions(-) create mode 100644 .gitignore create mode 100644 app/controllers/locations_controller.rb create mode 100644 app/helpers/locations_helper.rb create mode 100644 app/models/location.rb create mode 100644 app/views/layouts/locations.html.erb create mode 100644 app/views/locations/edit.html.erb create mode 100644 app/views/locations/index.html.erb create mode 100644 app/views/locations/new.html.erb create mode 100644 app/views/locations/show.html.erb create mode 100644 db/migrate/20100608074721_create_locations.rb delete mode 100644 log/development.log delete mode 100644 log/production.log delete mode 100644 log/server.log delete mode 100644 log/test.log create mode 100644 public/stylesheets/scaffold.css create mode 100644 test/fixtures/locations.yml create mode 100644 test/functional/locations_controller_test.rb create mode 100644 test/unit/helpers/locations_helper_test.rb create mode 100644 test/unit/location_test.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5da1ce6 --- /dev/null +++ b/.gitignore @@ -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 index 0000000..bd666a4 --- /dev/null +++ b/app/controllers/locations_controller.rb @@ -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 index 0000000..46f9428 --- /dev/null +++ b/app/helpers/locations_helper.rb @@ -0,0 +1,2 @@ +module LocationsHelper +end diff --git a/app/models/location.rb b/app/models/location.rb new file mode 100644 index 0000000..e3acd90 --- /dev/null +++ b/app/models/location.rb @@ -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 index 0000000..83a536a --- /dev/null +++ b/app/views/layouts/locations.html.erb @@ -0,0 +1,17 @@ + + + + + + Locations: <%= controller.action_name %> + <%= stylesheet_link_tag 'scaffold' %> + + + +

<%= flash[:notice] %>

+ +<%= yield %> + + + diff --git a/app/views/locations/edit.html.erb b/app/views/locations/edit.html.erb new file mode 100644 index 0000000..c3e82ae --- /dev/null +++ b/app/views/locations/edit.html.erb @@ -0,0 +1,24 @@ +

Editing location

+ +<% form_for(@location) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :code %>
+ <%= f.text_field :code %> +

+

+ <%= f.label :site %>
+ <%= f.text_field :site %> +

+

+ <%= f.label :summary %>
+ <%= f.text_field :summary %> +

+

+ <%= f.submit 'Update' %> +

+<% 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 index 0000000..8137c50 --- /dev/null +++ b/app/views/locations/index.html.erb @@ -0,0 +1,24 @@ +

Listing locations

+ + + + + + + + +<% @locations.each do |location| %> + + + + + + + + +<% end %> +
CodeSiteSummary
<%=h location.code %><%=h location.site %><%=h location.summary %><%= link_to 'Show', location %><%= link_to 'Edit', edit_location_path(location) %><%= link_to 'Destroy', location, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= 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 index 0000000..ebb5e2e --- /dev/null +++ b/app/views/locations/new.html.erb @@ -0,0 +1,23 @@ +

New location

+ +<% form_for(@location) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :code %>
+ <%= f.text_field :code %> +

+

+ <%= f.label :site %>
+ <%= f.text_field :site %> +

+

+ <%= f.label :summary %>
+ <%= f.text_field :summary %> +

+

+ <%= f.submit 'Create' %> +

+<% 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 index 0000000..62418f5 --- /dev/null +++ b/app/views/locations/show.html.erb @@ -0,0 +1,18 @@ +

+ Code: + <%=h @location.code %> +

+ +

+ Site: + <%=h @location.site %> +

+ +

+ Summary: + <%=h @location.summary %> +

+ + +<%= link_to 'Edit', edit_location_path(@location) %> | +<%= link_to 'Back', locations_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ea14ce1..a7f6056 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 index 0000000..ec6fb5a --- /dev/null +++ b/db/migrate/20100608074721_create_locations.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b81ae5a..e8ace6c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 index 8cb34f3..0000000 --- a/log/development.log +++ /dev/null @@ -1,22 +0,0 @@ - SQL (0.1ms) SET client_min_messages TO 'panic' - SQL (0.1ms) SET client_min_messages TO 'notice' - SQL (4.4ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)  - SQL (2.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version") - SQL (0.3ms) SELECT version FROM schema_migrations - SQL (0.1ms) SET client_min_messages TO 'panic' - SQL (0.1ms) SET client_min_messages TO 'notice' - SQL (0.3ms) SELECT version FROM schema_migrations - SQL (0.1ms) SET client_min_messages TO 'panic' - SQL (0.1ms) SET client_min_messages TO 'notice' - SQL (0.1ms) SET search_path TO public - SQL (205.3ms) DROP DATABASE IF EXISTS "nimono_test" - SQL (0.1ms) SET client_min_messages TO 'panic' - SQL (0.2ms) SET client_min_messages TO 'notice' - SQL (0.1ms) SET search_path TO public - SQL (370.9ms) CREATE DATABASE "nimono_test" ENCODING = 'utf8' - SQL (0.1ms) SET client_min_messages TO 'panic' - SQL (0.1ms) SET client_min_messages TO 'notice' - SQL (3.9ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)  - SQL (2.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version") - SQL (0.3ms) SELECT version FROM "schema_migrations" - SQL (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('0') diff --git a/log/production.log b/log/production.log deleted file mode 100644 index e69de29..0000000 diff --git a/log/server.log b/log/server.log deleted file mode 100644 index e69de29..0000000 diff --git a/log/test.log b/log/test.log deleted file mode 100644 index e69de29..0000000 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 @@ +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 index 0000000..49d02ee --- /dev/null +++ b/test/fixtures/locations.yml @@ -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 index 0000000..c8dc983 --- /dev/null +++ b/test/functional/locations_controller_test.rb @@ -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 index 0000000..7c96029 --- /dev/null +++ b/test/unit/helpers/locations_helper_test.rb @@ -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 index 0000000..2511bcd --- /dev/null +++ b/test/unit/location_test.rb @@ -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 -- 2.11.0