Skip to content

Commit

Permalink
clock.rb side of #for(user) now working
Browse files Browse the repository at this point in the history
  • Loading branch information
jfredett committed Dec 6, 2011
1 parent 6a07c55 commit 6039ec6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
12 changes: 8 additions & 4 deletions lib/percival/clock/clock.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class Clock
def self.reset!(user_name)
def self.reset!(username)

end

def self.for(user_name)
[]
def for(username)
(timesheet_manager.for(username) || []).sort
end

def clock_in(username)
timesheet_manager.entry(username, :in, )
timesheet_manager.entry(username, :in)
end

def clock_out(username)
Expand All @@ -33,3 +33,7 @@ def initialize(timesheet_manager = Timesheet)
private
attr_reader :timesheet_manager
end

def Clock(timesheet_manager = Timesheet)
Clock.new(timesheet_manager)
end
6 changes: 6 additions & 0 deletions lib/percival/clock/tick.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'yaml'
class Tick
include Comparable

def self.in
new(Time.now, :in)
end
Expand All @@ -22,6 +24,10 @@ def ==(other)
self.dump == other.dump
end

def <=>(other)
time <=> other.send(:time) #a little bit cheaty
end

def initialize(time, type)
@time = time
@type = type
Expand Down
55 changes: 39 additions & 16 deletions spec/clock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
end
}

let(:timesheet) { mock("timesheet class").tap { |t| t.stub!(:entry) } }
let(:timesheet) {
mock("timesheet class").tap { |t|
t.stub!(:entry)
t.stub!(:for)
}
}

subject { Clock.new(timesheet) }

Expand Down Expand Up @@ -66,32 +71,40 @@
subject.execute(cinch_mock, 'flurble')
end
end
end

describe Clock do #class methods
subject { Clock }

describe ".reset!(user)" do
it "takes a single user as an argument" do
expect { subject.reset!("foo") }.should_not raise_error
end
end

describe ".for(user)" do
describe "#for(user)" do
it "takes a single user as an argument" do
expect { subject.for("foo") }.should_not raise_error
end

it "should return an empty list if no ticks are present" do
timesheet.should_receive(:for).with('foo').and_return([])
subject.for("foo").should == []
end

it "returns all the clock-tick objects for a given user"

it "returns the tick object in chronological order"
it "returns all the clock-tick objects for a given user" do
timesheet.should_receive(:for).with('test_user')
subject.for('test_user')
end

it "returns the tick object in chronological order" do
fake_times = [Tick.new(Time.now + 60, :out), Tick.new(Time.now - 60, :in)]
timesheet.should_receive(:for).with('test_user').and_return(fake_times)
subject.for('test_user').should == fake_times.reverse #the above times are in reverse order
end
end
end

describe Clock do #class methods
subject { Clock }

let(:timesheet) { mock("timesheet class").tap { |t| t.stub!(:entry) } }

describe ".reset!(user)" do
it "takes a single user as an argument" do
expect { subject.reset!("foo") }.should_not raise_error
end
end
end


Expand Down Expand Up @@ -139,10 +152,20 @@
run!
end

pending "design" do
pending ":: waiting for design" do
it "allows for review and editing of times for a given day"

it "messages you if your time is out of the ordinary via email"
end
end

describe "Clock as a method" do
it "should be an alias for Clock.new" do
Clock.should_receive(:new).with(Timesheet).once
Clock()

mock = mock("timesheet")
Clock.should_receive(:new).with(mock).once
Clock(mock)
end
end
5 changes: 5 additions & 0 deletions spec/tick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
tick2 = Tick.new(Time.now + 1, :in)
tick1.should_not == tick2
end
end

describe "<=>" do
it "determines inequality by timestamp" do
Tick.new(Time.now + 50, :in).should be > Tick.new(Time.now - 50, :out)
end
end
end

Expand Down

0 comments on commit 6039ec6

Please sign in to comment.