Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ doc/

config/database.yml
TODO
.idea
6 changes: 4 additions & 2 deletions api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
Rabl.register!

class LogRequest
attr_reader :text, :time, :created_at
attr_reader :text, :time, :created_at, :execution_time

def initialize(time, text)
@text = text
@time = time
@created_at = Time.now
@execution_time = (@created_at - @time).round(2)
end

@@log = []
Expand All @@ -30,7 +32,7 @@ def self.clear_log!

end

LogRequest.log_request Time.now, "Just do it alreay"
LogRequest.log_request Time.now, "Just do it already"

get '/' do
@logs = LogRequest.log
Expand Down
11 changes: 8 additions & 3 deletions spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def app
log_request.fetch("text").should eq("Hello World")
time_in_utc = Time.parse(log_request.fetch("time"))
time_in_utc.should be_within(1).of(6.seconds.ago.utc)
exec_time = log_request.fetch('execution_time')
exec_time.should be_within(0.5).of(6.seconds)
end

it "not be ok with /wack" do
Expand All @@ -42,24 +44,27 @@ def app
it "should keep the time" do
subject.time.should be_within(0.01).of(45.minutes.ago)
end
it 'should have an execution time' do
subject.should respond_to(:execution_time)
subject.execution_time.should be_within(0.5).of(45.minutes)
end

describe ":log" do
before do
LogRequest.clear_log!
LogRequest.log_request(Time.now, "Now")
LogRequest.log_request(Time.now, "Now")
end

it "should be an array-like thing" do
LogRequest.log.count.should eq(2)
end
it "should request LogRequest" do
it "should return a LogRequest" do
LogRequest.log.first.should be_a(LogRequest)
end

it "can clear out the log" do
LogRequest.clear_log!
LogRequest.log.should be_empty
end

end
end
2 changes: 1 addition & 1 deletion views/logs.rabl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
collection @logs

attributes :time, :text
attributes :time, :text, :execution_time