Skip to content

Commit

Permalink
created hello resource
Browse files Browse the repository at this point in the history
  • Loading branch information
James Deville committed Oct 20, 2008
1 parent 0a4b491 commit 2d89e4a
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
57 changes: 57 additions & 0 deletions app/controllers/hellos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Hellos < Application
# provides :xml, :yaml, :js

def index
@hellos = Hello.all
display @hellos
end

def show(id)
@hello = Hello.get(id)
raise NotFound unless @hello
display @hello
end

def new
only_provides :html
@hello = Hello.new
display Hello
end

def edit(id)
only_provides :html
@hello = Hello.get(id)
raise NotFound unless @hello
display @hello
end

def create(hello)
@hello = Hello.new(params[:hello])
if @hello.save
redirect resource(@hello), :message => {:notice => "Hello was successfully created"}
else
render :new
end
end

def update(hello)
@hello = Hello.get(hello[:id] )
raise NotFound unless @hello
if @hello.update_attributes(hello)
redirect resource(@hello)
else
display @hello, :edit
end
end

def destroy(id)
@hello = Hello.get(id)
raise NotFound unless @hello
if @hello.destroy
redirect resource(@hellos)
else
raise InternalServerError
end
end

end # Hellos
5 changes: 5 additions & 0 deletions app/helpers/hellos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Merb
module HellosHelper

end
end # Merb
7 changes: 7 additions & 0 deletions app/models/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Hello
include DataMapper::Resource

property :id, Serial


end
3 changes: 3 additions & 0 deletions app/views/hellos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Hellos controller, edit action</h1>

<p>Edit this file in <tt>app/views/hellos/edit.html.erb</tt></p>
3 changes: 3 additions & 0 deletions app/views/hellos/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Hellos controller, index action</h1>

<p>Edit this file in <tt>app/views/hellos/index.html.erb</tt></p>
3 changes: 3 additions & 0 deletions app/views/hellos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Hellos controller, new action</h1>

<p>Edit this file in <tt>app/views/hellos/new.html.erb</tt></p>
3 changes: 3 additions & 0 deletions app/views/hellos/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Hellos controller, show action</h1>

<p>Edit this file in <tt>app/views/hellos/show.html.erb</tt></p>
7 changes: 7 additions & 0 deletions spec/models/hello_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require File.join( File.dirname(__FILE__), '..', "spec_helper" )

describe Hello do

it "should have specs"

end
49 changes: 49 additions & 0 deletions spec/requests/hellos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')

given "a hello exists" do
request(resource(:hellos), :method => "POST",
:params => { :hello => { }})
end

describe "resource(:hellos)" do
describe "GET" do

before(:each) do
@response = request(resource(:hellos))
end

it "responds successfully" do
@response.should be_successful
end

it "contains a list of speakers" do
pending
@response.should have_xpath("//ul")
end

end

describe "GET", :given => "a hello exists" do
before(:each) do
@response = request(resource(:hellos))
end

it "has a list of hellos" do
pending
@response.should have_xpath("//ul/li")
end
end

describe "a successful POST" do
before(:each) do
@response = request(resource(:hellos), :method => "POST",
:params => { :hello => { }})
end

it "redirects to resource(:hellos)" do
@response.should redirect_to(resource(Hello.first), :message => {:notice => "hello was successfully created"})
end

end
end

0 comments on commit 2d89e4a

Please sign in to comment.