OSDN Git Service

create thumbs
authornomeu <nomeu@nomeu.org>
Sun, 13 Jun 2010 00:18:18 +0000 (09:18 +0900)
committernomeu <nomeu@nomeu.org>
Sun, 13 Jun 2010 00:18:18 +0000 (09:18 +0900)
15 files changed:
app/controllers/thumbs_controller.rb [new file with mode: 0644]
app/helpers/thumbs_helper.rb [new file with mode: 0644]
app/models/thumb.rb [new file with mode: 0644]
app/views/layouts/thumbs.html.erb [new file with mode: 0644]
app/views/thumbs/edit.html.erb [new file with mode: 0644]
app/views/thumbs/index.html.erb [new file with mode: 0644]
app/views/thumbs/new.html.erb [new file with mode: 0644]
app/views/thumbs/show.html.erb [new file with mode: 0644]
config/routes.rb
db/migrate/20100612234341_create_thumbs.rb [new file with mode: 0644]
db/schema.rb
test/fixtures/thumbs.yml [new file with mode: 0644]
test/functional/thumbs_controller_test.rb [new file with mode: 0644]
test/unit/helpers/thumbs_helper_test.rb [new file with mode: 0644]
test/unit/thumb_test.rb [new file with mode: 0644]

diff --git a/app/controllers/thumbs_controller.rb b/app/controllers/thumbs_controller.rb
new file mode 100644 (file)
index 0000000..75d7343
--- /dev/null
@@ -0,0 +1,86 @@
+class ThumbsController < ApplicationController
+  # GET /thumbs
+  # GET /thumbs.xml
+  def index
+    @thumbs = Thumb.all
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @thumbs }
+    end
+  end
+
+  # GET /thumbs/1
+  # GET /thumbs/1.xml
+  def show
+    @thumb = Thumb.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @thumb }
+    end
+  end
+
+  # GET /thumbs/new
+  # GET /thumbs/new.xml
+  def new
+    @thumb = Thumb.new
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.xml  { render :xml => @thumb }
+    end
+  end
+
+  # GET /thumbs/1/edit
+  def edit
+    @thumb = Thumb.find(params[:id])
+  end
+
+  # POST /thumbs
+  # POST /thumbs.xml
+  def create
+    @thumb = Thumb.new(params[:thumb])
+    @thumb.id = params[:thumb].delete(:id)
+
+    respond_to do |format|
+      if @thumb.save
+        flash[:notice] = 'Thumb was successfully created.'
+        format.html { redirect_to(@thumb) }
+        format.xml  { render :xml => @thumb, :status => :created, :location => @thumb }
+      else
+        format.html { render :action => "new" }
+        format.xml  { render :xml => @thumb.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # PUT /thumbs/1
+  # PUT /thumbs/1.xml
+  def update
+    @thumb = Thumb.find(params[:id])
+
+    respond_to do |format|
+      if @thumb.update_attributes(params[:thumb])
+        flash[:notice] = 'Thumb was successfully updated.'
+        format.html { redirect_to(@thumb) }
+        format.xml  { head :ok }
+      else
+        format.html { render :action => "edit" }
+        format.xml  { render :xml => @thumb.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # DELETE /thumbs/1
+  # DELETE /thumbs/1.xml
+  def destroy
+    @thumb = Thumb.find(params[:id])
+    @thumb.destroy
+
+    respond_to do |format|
+      format.html { redirect_to(thumbs_url) }
+      format.xml  { head :ok }
+    end
+  end
+end
diff --git a/app/helpers/thumbs_helper.rb b/app/helpers/thumbs_helper.rb
new file mode 100644 (file)
index 0000000..8cdeb2e
--- /dev/null
@@ -0,0 +1,2 @@
+module ThumbsHelper
+end
diff --git a/app/models/thumb.rb b/app/models/thumb.rb
new file mode 100644 (file)
index 0000000..6fcaff1
--- /dev/null
@@ -0,0 +1,3 @@
+class Thumb < ActiveRecord::Base
+  set_primary_key :video_id
+end
diff --git a/app/views/layouts/thumbs.html.erb b/app/views/layouts/thumbs.html.erb
new file mode 100644 (file)
index 0000000..e2370af
--- /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>Thumbs: <%= 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/thumbs/edit.html.erb b/app/views/thumbs/edit.html.erb
new file mode 100644 (file)
index 0000000..1c53758
--- /dev/null
@@ -0,0 +1,24 @@
+<h1>Editing thumb</h1>
+
+<% form_for(@thumb) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :video_id %><br />
+    <%= f.text_field :video_id %>
+  </p>
+  <p>
+    <%= f.label :title %><br />
+    <%= f.text_field :title %>
+  </p>
+  <p>
+    <%= f.label :description %><br />
+    <%= f.text_field :description %>
+  </p>
+  <p>
+    <%= f.submit 'Update' %>
+  </p>
+<% end %>
+
+<%= link_to 'Show', @thumb %> |
+<%= link_to 'Back', thumbs_path %>
\ No newline at end of file
diff --git a/app/views/thumbs/index.html.erb b/app/views/thumbs/index.html.erb
new file mode 100644 (file)
index 0000000..e767a29
--- /dev/null
@@ -0,0 +1,24 @@
+<h1>Listing thumbs</h1>
+
+<table>
+  <tr>
+    <th>Video</th>
+    <th>Title</th>
+    <th>Description</th>
+  </tr>
+
+<% @thumbs.each do |thumb| %>
+  <tr>
+    <td><%=h thumb.video_id %></td>
+    <td><%=h thumb.title %></td>
+    <td><%=h thumb.description %></td>
+    <td><%= link_to 'Show', thumb %></td>
+    <td><%= link_to 'Edit', edit_thumb_path(thumb) %></td>
+    <td><%= link_to 'Destroy', thumb, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New thumb', new_thumb_path %>
\ No newline at end of file
diff --git a/app/views/thumbs/new.html.erb b/app/views/thumbs/new.html.erb
new file mode 100644 (file)
index 0000000..a066b0e
--- /dev/null
@@ -0,0 +1,23 @@
+<h1>New thumb</h1>
+
+<% form_for(@thumb) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :video_id %><br />
+    <%= f.text_field :video_id %>
+  </p>
+  <p>
+    <%= f.label :title %><br />
+    <%= f.text_field :title %>
+  </p>
+  <p>
+    <%= f.label :description %><br />
+    <%= f.text_field :description %>
+  </p>
+  <p>
+    <%= f.submit 'Create' %>
+  </p>
+<% end %>
+
+<%= link_to 'Back', thumbs_path %>
\ No newline at end of file
diff --git a/app/views/thumbs/show.html.erb b/app/views/thumbs/show.html.erb
new file mode 100644 (file)
index 0000000..dccc5a6
--- /dev/null
@@ -0,0 +1,18 @@
+<p>
+  <b>Video:</b>
+  <%=h @thumb.video_id %>
+</p>
+
+<p>
+  <b>Title:</b>
+  <%=h @thumb.title %>
+</p>
+
+<p>
+  <b>Description:</b>
+  <%=h @thumb.description %>
+</p>
+
+
+<%= link_to 'Edit', edit_thumb_path(@thumb) %> |
+<%= link_to 'Back', thumbs_path %>
\ No newline at end of file
index 1ba33d7..37b5081 100644 (file)
@@ -1,4 +1,6 @@
 ActionController::Routing::Routes.draw do |map|
+  map.resources :thumbs
+
   map.resources :xes
 
   map.resources :vmds
diff --git a/db/migrate/20100612234341_create_thumbs.rb b/db/migrate/20100612234341_create_thumbs.rb
new file mode 100644 (file)
index 0000000..d3de320
--- /dev/null
@@ -0,0 +1,17 @@
+class CreateThumbs < ActiveRecord::Migration
+  def self.up
+    create_table :thumbs, :id => false do |t|
+      t.string :video_id, :limit => 15, :null => false
+      t.string :title
+      t.text :description
+
+      t.timestamps
+    end
+    add_index :thumbs, [ :video_id ], :unique => true
+  end
+
+  def self.down
+    remove_index :thumbs, :column => [ :video_id ]
+    drop_table :thumbs
+  end
+end
index 206d511..69b38f8 100644 (file)
@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20100608144944) do
+ActiveRecord::Schema.define(:version => 20100612234341) do
 
   create_table "arcs", :force => true do |t|
     t.string   "code",        :limit => 10, :null => false
@@ -36,6 +36,16 @@ ActiveRecord::Schema.define(:version => 20100608144944) do
     t.datetime "updated_at"
   end
 
+  create_table "thumbs", :id => false, :force => true do |t|
+    t.string   "video_id",    :limit => 15, :null => false
+    t.string   "title"
+    t.text     "description"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
+  add_index "thumbs", ["video_id"], :name => "index_thumbs_on_video_id", :unique => true
+
   create_table "vmds", :force => true do |t|
     t.integer  "arc_id"
     t.string   "path",       :null => false
diff --git a/test/fixtures/thumbs.yml b/test/fixtures/thumbs.yml
new file mode 100644 (file)
index 0000000..95107b3
--- /dev/null
@@ -0,0 +1,6 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+  video_id: sm9
+  title: "新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師"
+  description: "レッツゴー!陰陽師(フルコーラスバージョン)"
diff --git a/test/functional/thumbs_controller_test.rb b/test/functional/thumbs_controller_test.rb
new file mode 100644 (file)
index 0000000..8bdbeda
--- /dev/null
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class ThumbsControllerTest < ActionController::TestCase
+  test "should get index" do
+    get :index
+    assert_response :success
+    assert_not_nil assigns(:thumbs)
+  end
+
+  test "should get new" do
+    get :new
+    assert_response :success
+  end
+
+  test "should create thumb" do
+    assert_difference('Thumb.count') do
+      post :create, :thumb => { :id => 'sm9996481', :title => '[MMD]Lat式ちびミクが更にちみっこになったので', :description => 'sm9983872 のあおぽん様とネタ被り記念。真逆、自分と同じ事を実行する人がいるとは思わなかったorz左から順にあおぽん様Lat式ちびミク、6666AAP様Lat式ちびミク、自作Lat式ちみっこミク、ちびミク、ぷちミクと並んでおります。音源データは、sm9201748モデルデータは sm7542126 / sm8620825 / sm9931954 / sm9983872 背景データは、sm8695572以上よりお借り致しました。ありがとうございます。改造データ:http://loda.jp/mikumikudance/?id=236' }
+    end
+
+    assert_redirected_to thumb_path(assigns(:thumb))
+  end
+
+  test "should show thumb" do
+    get :show, :id => thumbs(:one).to_param
+    assert_response :success
+  end
+
+  test "should get edit" do
+    get :edit, :id => thumbs(:one).to_param
+    assert_response :success
+  end
+
+  test "should update thumb" do
+    put :update, :id => thumbs(:one).to_param, :thumb => { }
+    assert_redirected_to thumb_path(assigns(:thumb))
+  end
+
+  test "should destroy thumb" do
+    assert_difference('Thumb.count', -1) do
+      delete :destroy, :id => thumbs(:one).to_param
+    end
+
+    assert_redirected_to thumbs_path
+  end
+end
diff --git a/test/unit/helpers/thumbs_helper_test.rb b/test/unit/helpers/thumbs_helper_test.rb
new file mode 100644 (file)
index 0000000..2872d74
--- /dev/null
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ThumbsHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/thumb_test.rb b/test/unit/thumb_test.rb
new file mode 100644 (file)
index 0000000..4f58764
--- /dev/null
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ThumbTest < ActiveSupport::TestCase
+  # Replace this with your real tests.
+  test "the truth" do
+    assert true
+  end
+end