Skip to content

Commit

Permalink
add in rps calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdempsey committed Nov 14, 2008
1 parent 820b96a commit 404a799
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/controllers/home.rb
@@ -0,0 +1,21 @@
class Home < Application

# ...and remember, everything returned from an action
# goes to the client...
def index
render
end

def rps_calc
redirect '/' if request.get?
if params[:rpd]
@rpd = params[:rpd].tr(',','').to_i
if @rpd >= 86_400
@rps = @rpd / 86_400 # number of seconds in a day
else
message[:error] = "You need a number greater than 86,400"
end
end
render
end
end
5 changes: 5 additions & 0 deletions app/helpers/home_helper.rb
@@ -0,0 +1,5 @@
module Merb
module HomeHelper

end
end # Merb
3 changes: 3 additions & 0 deletions app/views/home/_rps.html.haml
@@ -0,0 +1,3 @@
= form :action => '/home/rps_calc' do
%input{:name => 'rpd', :size => 40}
=submit 'submit'
3 changes: 3 additions & 0 deletions app/views/home/index.html.haml
@@ -0,0 +1,3 @@
Requests per day -> Requests per second:

= partial :rps
7 changes: 7 additions & 0 deletions app/views/home/rps_calc.html.haml
@@ -0,0 +1,7 @@
- unless message[:error]
= h params[:rpd]
Requests per day is
= @rps
Requests per second

= partial :rps
24 changes: 24 additions & 0 deletions spec/requests/home_spec.rb
@@ -0,0 +1,24 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')

describe "/home/rps_calc" do

it "should return 100 RPS for a input of 8.64 million" do
request("/home/rps_calc", :params => {:rpd => 8_640_000}).should contain('100')
end

it "should show an error message if RPD is < 86,400" do
request("/home/rps_calc", :params => {:rpd => 86399}).should have_selector('div#error')
end

it "should handle numbers with commas in them" do
request("/home/rps_calc", :params => {:rpd => '8,640,000'}).should contain('100')
end

it "should show the RPD and RPS" do
request("/home/rps_calc", :params => {:rpd => '8,640,000'}).should contain('8,640,000')
end

it "should redirect to / if request is a GET" do
request("/home/rps_calc").should redirect
end
end

0 comments on commit 404a799

Please sign in to comment.