Skip to content

Commit

Permalink
Set a publish time on events
Browse files Browse the repository at this point in the history
  • Loading branch information
karmajunkie committed Apr 10, 2014
1 parent 6ece27b commit ffed773
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/replay/event_declarations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def method_missing(name, *args)
def declare_event(base, name, props)
klass = Class.new do
include Replay::EventDecorator

attribute :published_at, Time, default: lambda{|p,a| Time.now}
values do
props.keys.each do |prop|
attribute prop, props[prop]
Expand Down
10 changes: 10 additions & 0 deletions proofs/replay/publisher_proof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def pkey
end

module ReplayTest::Proof
def sets_publish_time
publish SomeEvent(pid: 123)
events.last.published_at != nil && (Time.now - events.last.published_at) < 20
end

def defines_events?
self.class.const_defined?(:SomeEvent) && self.class.const_get(:SomeEvent).is_a?(Class)
end
Expand Down Expand Up @@ -144,6 +149,11 @@ def published?; @published; end
r.prove{ publish([]) == self}
end

proof "sets the publish time on events" do
r = ReplayTest.new
r.prove{ sets_publish_time }
end

proof "Can implement initializer with arguments" do
r = ReplayTest.new(:foo)
r.prove { pkey == :foo }
Expand Down

0 comments on commit ffed773

Please sign in to comment.