mostly implemented users

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@51 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2007-12-03 08:47:21 +00:00
parent e2ab72143f
commit 070aa7b3e5
14 changed files with 248 additions and 0 deletions

View File

@ -0,0 +1,94 @@
class PeoplesController < ApplicationController
append_before_filter :fetch_people_and_page, :only => [ :show, :edit,
:update, :destroy ]
# GET /peoples
# GET /peoples.xml
def index
@secondary_title = 'Browsing all Peoples'
@pages, @peoples = paginate :people, :per_page => 25, :order => 'title ASC',
:singular_name => 'people'
@tags = Page.tags(:limit => 25, :order => "name DESC",
:owner_type => 'People')
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @people.to_xml }
end
end
# GET /peoples/1
# GET /peoples/1.xml
def show
@secondary_title = 'Detailed Information'
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @people.to_xml }
end
end
# GET /peoples/new
def new
@secondary_title = 'Sign up for BarleySodas!'
@people = People.new
@page = Page.new
end
# GET /peoples/1;edit
def edit
end
# POST /peoples
# POST /peoples.xml
def create
@people = People.new(params[:people])
@page = Page.new(params[:page])
@people.page = @page
respond_to do |format|
if @people.save
flash[:notice] = 'People was successfully created.'
format.html { redirect_to people_url(@people.page.title_for_url) }
format.xml { head :created,
:location => people_url(@people.page.title_for_url) }
else
format.html { render :action => "new" }
format.xml { render :xml => @people.errors.to_xml }
end
end
end
# PUT /peoples/1
# PUT /peoples/1.xml
def update
@people.attributes = params[:people]
@page.attributes = params[:page]
respond_to do |format|
if @people.update_attributes(params[:people])
flash[:notice] = 'People was successfully updated.'
format.html { redirect_to people_url(@people.page.title_for_url) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @people.errors.to_xml }
end
end
end
# DELETE /peoples/1
# DELETE /peoples/1.xml
def destroy
@people.destroy
respond_to do |format|
format.html { redirect_to peoples_url }
format.xml { head :ok }
end
end
protected
def fetch_people_and_page
@people = People.find_by_title(Page.title_from_url(params[:id]),
:include => [ 'page' ])
raise ActiveRecord::RecordNotFound.new if @people.nil?
@page = @people.page
end
end

View File

@ -0,0 +1,15 @@
module PeoplesHelper
def new_people_link
link_to 'Sign Up!', new_people_path, { :title => 'Sign Up!' }
end
def show_people_link(people)
link_to people.title, people_path(people.page.title_for_url),
{ :title => people.title }
end
def edit_people_link(people)
link_to 'Edit People', edit_people_path(people.page.title_for_url),
{ :title => "Edit #{people.title}" }
end
end

6
app/models/people.rb Normal file
View File

@ -0,0 +1,6 @@
##
# This model represents a user in the system.
#
class People < ActiveRecord::Base
has_one_tuxwiki_page :owner_class => 'People'
end

View File

@ -32,6 +32,7 @@
<%= link_to_unless_current 'Browse Beers', beers_path -%><br /> <%= link_to_unless_current 'Browse Beers', beers_path -%><br />
<%= link_to_unless_current 'Browse Breweries', breweries_path -%><br /> <%= link_to_unless_current 'Browse Breweries', breweries_path -%><br />
<%= link_to_unless_current 'Discussions', discussions_path -%><br /> <%= link_to_unless_current 'Discussions', discussions_path -%><br />
<%= link_to_unless_current 'Peoples', peoples_path -%><br />
<hr /> <hr />
<%= yield :sidebar %> <%= yield :sidebar %>
</div> </div>

View File

@ -0,0 +1,10 @@
<%= error_messages_for :people %>
<% form_for(:people, :url => people_path(@people), :html => { :method => :put }) do |f| %>
<p>
<%= submit_tag "Update" %>
</p>
<% end %>
<%= link_to 'Show', people_path(@people) %> |
<%= link_to 'Back', peoples_path %>

View File

@ -0,0 +1,14 @@
<ul>
<% unless @peoples.empty? -%>
<% for people in @peoples -%><li><%= show_people_link(people) -%></li><% end %>
<% else -%>
<li>No people, yet!</li>
<% end -%>
</ul>
<%= render :partial => 'shared/pagination_links' %>
<% content_for :sidebar do -%>
<%= link_to 'Create a new person', new_people_path %><br />
<%= render :partial => 'shared/tag_cloud' %>
<% end -%>

View File

@ -0,0 +1,11 @@
<h1>New people</h1>
<%= error_messages_for :people %>
<% form_for(:people, :url => peoples_path) do |f| %>
<p>
<%= submit_tag "Create" %>
</p>
<% end %>
<%= link_to 'Back', peoples_path %>

View File

@ -0,0 +1,7 @@
<%= render :partial => 'pages/page' %>
<% content_for :sidebar do -%>
<%= new_people_link -%><br />
<%= edit_people_link(@people) %><br />
<%= link_to 'Destroy', people_path(@people.page.title_for_url), :confirm => 'Are you sure?', :method => :delete %><br />
<% end -%>

View File

@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.resources :peoples
map.resources :beers, :breweries, :pages, :discussions map.resources :beers, :breweries, :pages, :discussions
map.connect ':controller/:action/:id.:format' map.connect ':controller/:action/:id.:format'

View File

@ -0,0 +1,11 @@
class CreatePeoples < ActiveRecord::Migration
def self.up
create_table :peoples do |t|
t.column :title, :string
end
end
def self.down
drop_table :peoples
end
end

View File

@ -13,3 +13,8 @@ homepage:
id: 3 id: 3
title: HomePage title: HomePage
redcloth: Homepage Text redcloth: Homepage Text
personal_description:
id: 4
title: penguin coder
owner_id: 1
owner_type: People

4
test/fixtures/peoples.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
id: 1
title: penguin coder

View File

@ -0,0 +1,58 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'peoples_controller'
# Re-raise errors caught by the controller.
class PeoplesController; def rescue_action(e) raise e end; end
class PeoplesControllerTest < Test::Unit::TestCase
fixtures :peoples
def setup
@controller = PeoplesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_should_get_index
get :index
assert_response :success
assert assigns(:peoples)
end
def test_should_get_new
get :new
assert_response :success
end
def test_should_create_people
old_count = People.count
post :create, :people => { :title => '1' }
assert_equal old_count+1, People.count
assert_redirected_to people_path(assigns(:people).page.title_for_url)
end
def test_should_show_people
get :show, :id => 'penguin_coder'
assert_response :success
end
def test_should_get_edit
get :edit, :id => 'penguin_coder'
assert_response :success
end
def test_should_update_people
put :update, :id => 'penguin_coder',
:people => { :title => 'penguin coder' }
assert_redirected_to people_path(assigns(:people).page.title_for_url)
end
def test_should_destroy_people
old_count = People.count
delete :destroy, :id => 'penguin_coder'
assert_equal old_count-1, People.count
assert_redirected_to peoples_path
end
end

10
test/unit/people_test.rb Normal file
View File

@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../test_helper'
class PeopleTest < Test::Unit::TestCase
fixtures :peoples
# Replace this with your real tests.
def test_truth
assert true
end
end