Skip to content

Commit

Permalink
add in ability to convert rps -> rpd; rework layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdempsey committed Nov 15, 2008
1 parent 5b5aea9 commit 3d763e1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 30 deletions.
14 changes: 9 additions & 5 deletions app/controllers/home.rb
Expand Up @@ -8,12 +8,16 @@ def index

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
if params[:requests_per]
@requests_per = params[:requests_per].tr(',','').to_i
if params[:convert_to] == 'rpd'
@answer = @requests_per * 86_400 # number of seconds in a day
else
message[:error] = "You need a number greater than 86,400"
if @requests_per >= 86_400
@answer = @requests_per / 86_400 # number of seconds in a day
else
message[:error] = "You need a number greater than 86,400"
end
end
end
render
Expand Down
9 changes: 8 additions & 1 deletion app/helpers/home_helper.rb
@@ -1,5 +1,12 @@
module Merb
module HomeHelper

def show_conversion_message(convert_to)
conversion_string = if convert_to == 'rpd'
"reqs/sec is #{@answer} reqs/day"
else
"reqs/day is #{@answer} reqs/sec"
end
"#{h params[:requests_per]} #{conversion_string}"
end
end
end # Merb
9 changes: 7 additions & 2 deletions app/views/home/_rps.html.haml
@@ -1,3 +1,8 @@
%h2 Convert to:
= form :action => '/home/rps_calc' do
%input{:name => 'rpd', :size => 40}
=submit 'submit'
= radio_group :convert_to, [{:value => :rps, :label => 'reqs/sec'}, {:value => :rpd, :label => 'reqs/day'}]
%p
= show_conversion_message(params[:convert_to])
%p
%input{:name => 'requests_per', :size => 40}
= submit 'submit'
3 changes: 0 additions & 3 deletions app/views/home/index.html.haml
@@ -1,4 +1 @@

Requests per day -> Requests per second:

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

= partial :rps
= partial :rps
4 changes: 2 additions & 2 deletions app/views/shared/_header_links.html.haml
@@ -1,3 +1,3 @@
= link_to 'about', 'http://github.com/jackdempsey/builtbythenet/tree/master'
= link_to 'about', 'http://github.com/jackdempsey/builtbythenet/tree/master', :target => :blank
|
= link_to 'request a feature', 'http://builtbythenet.uservoice.com/'
= link_to 'request a feature', 'http://builtbythenet.uservoice.com/', :target => :blank
31 changes: 20 additions & 11 deletions spec/requests/home_spec.rb
@@ -1,24 +1,33 @@
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')

it "should redirect to / if request is a GET" do
request("/home/rps_calc").should redirect
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')
it "should convert to RPS by default" do
request("/home/rps_calc", :params => {:requests_per => 8_640_000}).should contain('reqs/day is 100 reqs/sec')
end

it "should handle numbers with commas in them" do
request("/home/rps_calc", :params => {:rpd => '8,640,000'}).should contain('100')
request("/home/rps_calc", :params => {:requests_per => '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')
describe "converting into RPS" do
it "should return 100 RPS for a input of 8.64 million" do
request("/home/rps_calc", :params => {:requests_per => 8_640_000}).should contain('100')
end

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

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

describe "converting into RPD" do
it "should return 8.64 million reqs/day for a input of 100 reqs/sec" do
request("/home/rps_calc", :params => {:requests_per => 100, :convert_to => 'rpd'}).should contain('100 reqs/sec is 8640000 reqs/day')
end
end

end

0 comments on commit 3d763e1

Please sign in to comment.