Permalink
Browse files

Routes,views,specs and redis integration for the push page

  • Loading branch information...
1 parent 30a5cd5 commit ceb43f484ad92146cecfc4e2abe3d4cd6cad94d4 Edmore Moyo committed May 21, 2012
Showing with 78 additions and 6 deletions.
  1. +26 −1 peekaboo.rb
  2. +30 −2 spec/peekaboo_spec.rb
  3. +8 −3 views/index.haml
  4. +14 −0 views/push.haml
View
@@ -1,8 +1,33 @@
require 'sinatra'
+require 'haml'
+require 'pry'
+require 'redis'
set :haml, :format => :html5
+
+redis = Redis.new
get "/" do
- "Peekaboo I see you!"
haml :index
end
+
+get "/push" do
+ status = params[:status] if params[:status]
+ unless status.nil?
+ notice = (status == "success") ? "Successfully added." : "Oops, please enter text."
+ end
+ haml :push, :locals => {:notice => notice}
+end
+
+post "/push" do
+ title = params[:question]
+ status = ""
+ unless title == ""
+ redis.incr "question:id"
+ question_id = redis.get("question:id")
+ redis.rpush("questions", question_id)
+ redis.set("question:#{question_id}:title", params[:question])
+ status = :success
+ end
+ redirect "/push?status=#{status}"
+end
View
@@ -16,10 +16,38 @@ def setup
conf.include Rack::Test::Methods
end
-feature "Index page" do
+feature "Index page" do
setup
scenario "should display an index page" do
visit("/")
- page.should have_css("h1", :text => "Peekaboo")
+ page.should have_content("Peekaboo I see you")
+ end
+
+ scenario "should link to push page" do
+ visit("/")
+ click_link("Push")
+ page.should have_content("Push")
+ end
+end
+
+feature "Push page" do
+ setup
+ scenario "should display a push page" do
+ visit("/push")
+ page.should have_content("Push")
+ end
+
+ scenario "adding data" do
+ visit("/push")
+ fill_in('question', :with => "What's your name")
+ click_button("Push")
+ page.should have_css("p.notice", :text => "Successfully added.")
+ end
+
+ scenario "should error if text field empty" do
+ visit("/push")
+ fill_in('question', :with => "")
+ click_button("Push")
+ page.should have_css("p.notice", :text => "Oops, please enter text.")
end
end
View
@@ -1,6 +1,11 @@
%html
%head
%title
- %h1 Peekaboo
-%body
- Peekaboo I see you!!
+ Peekaboo
+ %body
+ %p
+ Peekaboo I see you!!
+ %nav
+ %ul
+ %li
+ %a{:href => "/push"} Push
View
@@ -0,0 +1,14 @@
+%html
+ %head
+ %title
+ Peekaboo | Push
+%body
+ %p
+ Push
+ %p.notice
+ = notice
+ %form{:name => "question_form", :method => "post", :action => "/push"}
+ %label{:for => "question"} Question:
+ %input{:type => "text", :name => "question", :class => "text"}
+
+ %input{:type => "submit", :value => "Push"}

0 comments on commit ceb43f4

Please sign in to comment.