Permalink
Browse files

Finalzing a trivial example

  • Loading branch information...
1 parent 1fbe49d commit 4b82c900b3a70ad4f979cb086b930ec3bae65fa8 @jc00ke committed Mar 3, 2010
@@ -19,20 +19,33 @@ def app
last_response.body.should contain 'Home'
end
+ it 'should have a message form' do
+ get '/'
+ last_response.should be_ok
+ last_response.body.should have_selector("form[name='message']")
+ end
+
+ it 'should accept a POST' do
+ post '/',
+ "message" => "yo dawg"
+ last_response.should be_ok
+ last_response.should contain("yo dawg")
+ end
+
end
- context "'/login' route" do
+ context "'/message' route" do
- it 'should have a form' do
- get '/login'
+ it 'should have the formatted message' do
+ get '/message'
last_response.should be_ok
- last_response.body.should include("action='/login'")
+ last_response.body.should contain("***")
end
- it 'should have a legit login form' do
- get '/login'
+ it 'should kill the message' do
+ get '/kill'
last_response.should be_ok
- last_response.body.should have_selector("form[name='login']")
+ last_response.should_not have_selector("#message")
end
end
@@ -0,0 +1,7 @@
+%form{ :method => :post, :action => '/', :name => 'message' }
+
+ %label{ :for => 'message' }Message
+ %input{ :type => 'password', :name => 'message' }
+ %br
+ %input{ :type => 'submit', :value => 'Post the message' }
+
@@ -8,5 +8,9 @@
%h1 Widgets
%nav
%a{ :href => '/' }Home
- %a{ :href => '/login' }Login
+ %a{ :href => '/message' }Message
+ - if session[:message]
+ %a{ :href => '/kill' }Kill the message
+ - if @message
+ #message= @message
= yield
@@ -1 +0,0 @@
-%form{ :method => :post, :action => '/login', :name => 'login' }
@@ -0,0 +1,2 @@
+%h2 The formatted message
+= format_message
@@ -1,9 +1,10 @@
-%w(rubygems sinatra dm-core haml sass).each{ |lib| require lib }
+%w(rubygems sinatra haml sass).each{ |lib| require lib }
configure do
set :views, "#{File.dirname(__FILE__)}/views"
set :haml, { :format => :html5 }
+ enable :sessions
end
configure :development do
@@ -12,12 +13,40 @@
end
+helpers do
+
+ def format_message
+ message = session[:message] if session[:message]
+ "*** #{message} ***"
+ end
+
+end
+
+before do
+
+ if session[:message]
+ puts "this is the message: #{session[:message]}"
+ end
+
+ @message = session[:message]
+
+end
get '/' do
haml :index
end
-get '/login' do
- haml :login
+post '/' do
+ @message = session[:message] = params[:message]
+ haml :index
+end
+
+get '/message' do
+ haml :message
+end
+
+get '/kill' do
+ session[:message] = nil
+ haml :index
end

0 comments on commit 4b82c90

Please sign in to comment.