first version of discussions
git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@44 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7master
parent
d716709a2e
commit
2aadbac5b6
|
@ -0,0 +1,79 @@
|
||||||
|
class DiscussionsController < ApplicationController
|
||||||
|
# GET /discussions
|
||||||
|
# GET /discussions.xml
|
||||||
|
def index
|
||||||
|
@discussions = Discussion.find(:all)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # index.rhtml
|
||||||
|
format.xml { render :xml => @discussions.to_xml }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /discussions/1
|
||||||
|
# GET /discussions/1.xml
|
||||||
|
def show
|
||||||
|
@discussion = Discussion.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # show.rhtml
|
||||||
|
format.xml { render :xml => @discussion.to_xml }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /discussions/new
|
||||||
|
def new
|
||||||
|
@discussion = Discussion.new
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /discussions/1;edit
|
||||||
|
def edit
|
||||||
|
@discussion = Discussion.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /discussions
|
||||||
|
# POST /discussions.xml
|
||||||
|
def create
|
||||||
|
@discussion = Discussion.new(params[:discussion])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @discussion.save
|
||||||
|
flash[:notice] = 'Discussion was successfully created.'
|
||||||
|
format.html { redirect_to discussion_url(@discussion) }
|
||||||
|
format.xml { head :created, :location => discussion_url(@discussion) }
|
||||||
|
else
|
||||||
|
format.html { render :action => "new" }
|
||||||
|
format.xml { render :xml => @discussion.errors.to_xml }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /discussions/1
|
||||||
|
# PUT /discussions/1.xml
|
||||||
|
def update
|
||||||
|
@discussion = Discussion.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @discussion.update_attributes(params[:discussion])
|
||||||
|
flash[:notice] = 'Discussion was successfully updated.'
|
||||||
|
format.html { redirect_to discussion_url(@discussion) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
else
|
||||||
|
format.html { render :action => "edit" }
|
||||||
|
format.xml { render :xml => @discussion.errors.to_xml }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /discussions/1
|
||||||
|
# DELETE /discussions/1.xml
|
||||||
|
def destroy
|
||||||
|
@discussion = Discussion.find(params[:id])
|
||||||
|
@discussion.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to discussions_url }
|
||||||
|
format.xml { head :ok }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
module DiscussionsHelper
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
class Discussion < ActiveRecord::Base
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
<h1>Editing discussion</h1>
|
||||||
|
|
||||||
|
<%= error_messages_for :discussion %>
|
||||||
|
|
||||||
|
<% form_for(:discussion, :url => discussion_path(@discussion), :html => { :method => :put }) do |f| %>
|
||||||
|
<p>
|
||||||
|
<%= submit_tag "Update" %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Show', discussion_path(@discussion) %> |
|
||||||
|
<%= link_to 'Back', discussions_path %>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<h1>Listing discussions</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% for discussion in @discussions %>
|
||||||
|
<tr>
|
||||||
|
<td><%= link_to 'Show', discussion_path(discussion) %></td>
|
||||||
|
<td><%= link_to 'Edit', edit_discussion_path(discussion) %></td>
|
||||||
|
<td><%= link_to 'Destroy', discussion_path(discussion), :confirm => 'Are you sure?', :method => :delete %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<%= link_to 'New discussion', new_discussion_path %>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<h1>New discussion</h1>
|
||||||
|
|
||||||
|
<%= error_messages_for :discussion %>
|
||||||
|
|
||||||
|
<% form_for(:discussion, :url => discussions_path) do |f| %>
|
||||||
|
<p>
|
||||||
|
<%= submit_tag "Create" %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', discussions_path %>
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
<%= link_to 'Edit', edit_discussion_path(@discussion) %> |
|
||||||
|
<%= link_to 'Back', discussions_path %>
|
|
@ -1,5 +1,5 @@
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.resources :beers, :breweries, :pages
|
map.resources :beers, :breweries, :pages, :discussions
|
||||||
|
|
||||||
map.connect ':controller/:action/:id.:format'
|
map.connect ':controller/:action/:id.:format'
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class CreateDiscussions < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :discussions do |t|
|
||||||
|
t.column :page_id, :integer
|
||||||
|
t.column :text, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :discussions
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||||
|
one:
|
||||||
|
id: 1
|
||||||
|
two:
|
||||||
|
id: 2
|
|
@ -0,0 +1,57 @@
|
||||||
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
require 'discussions_controller'
|
||||||
|
|
||||||
|
# Re-raise errors caught by the controller.
|
||||||
|
class DiscussionsController; def rescue_action(e) raise e end; end
|
||||||
|
|
||||||
|
class DiscussionsControllerTest < Test::Unit::TestCase
|
||||||
|
fixtures :discussions
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@controller = DiscussionsController.new
|
||||||
|
@request = ActionController::TestRequest.new
|
||||||
|
@response = ActionController::TestResponse.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_get_index
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert assigns(:discussions)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_get_new
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_create_discussion
|
||||||
|
old_count = Discussion.count
|
||||||
|
post :create, :discussion => { }
|
||||||
|
assert_equal old_count+1, Discussion.count
|
||||||
|
|
||||||
|
assert_redirected_to discussion_path(assigns(:discussion))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_show_discussion
|
||||||
|
get :show, :id => 1
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_get_edit
|
||||||
|
get :edit, :id => 1
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_update_discussion
|
||||||
|
put :update, :id => 1, :discussion => { }
|
||||||
|
assert_redirected_to discussion_path(assigns(:discussion))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_destroy_discussion
|
||||||
|
old_count = Discussion.count
|
||||||
|
delete :destroy, :id => 1
|
||||||
|
assert_equal old_count-1, Discussion.count
|
||||||
|
|
||||||
|
assert_redirected_to discussions_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
|
class DiscussionTest < Test::Unit::TestCase
|
||||||
|
fixtures :discussions
|
||||||
|
|
||||||
|
# Replace this with your real tests.
|
||||||
|
def test_truth
|
||||||
|
assert true
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue