Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
820b96a
commit 404a799
Showing
6 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Merb | ||
module HomeHelper | ||
|
||
end | ||
end # Merb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= form :action => '/home/rps_calc' do | ||
%input{:name => 'rpd', :size => 40} | ||
=submit 'submit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Requests per day -> Requests per second: | ||
|
||
= partial :rps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- unless message[:error] | ||
= h params[:rpd] | ||
Requests per day is | ||
= @rps | ||
Requests per second | ||
|
||
= partial :rps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |