Skip to content

Commit

Permalink
dup Definition#current_time
Browse files Browse the repository at this point in the history
git-svn-id: http://ar-code.svn.engineyard.com/plugins/model_stubbing@72 d98f8484-0aa7-43af-80ea-302c351499d6
  • Loading branch information
rick committed Nov 23, 2007
1 parent d82de2e commit 2a34888
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/model_stubbing/definition.rb
Expand Up @@ -3,9 +3,9 @@ module ModelStubbing
# can set the current time for your tests. You typically create one per test case or
# rspec example.
class Definition
attr_reader :current_time
attr_reader :models
attr_reader :stubs
attr_accessor :current_time
attr_reader :models
attr_reader :stubs

# Sets the time that Time.now is mocked to (in UTC)
def time(*args)
Expand All @@ -29,6 +29,7 @@ def initialize(&block)

def dup
copy = self.class.new
copy.current_time = @current_time
models.each do |name, model|
copy.models[name] = model.dup(copy)
end
Expand All @@ -40,7 +41,7 @@ def dup

def ==(defn)
(defn.object_id == object_id) ||
(defn.is_a?(Definition))# && defn.models == @models && defn.stubs == @stubs)
(defn.is_a?(Definition) && defn.models == @models && defn.stubs == @stubs)
end

# Sets up the given class for this definition. Adds a few helper methods:
Expand Down
4 changes: 4 additions & 0 deletions spec/definition_spec.rb
Expand Up @@ -60,6 +60,10 @@
@copy = @defn.dup
end

it "dups @current_time" do
@defn.current_time.should == @copy.current_time
end

it "dups each model" do
@defn.models.each do |name, model|
duped_model = @copy.models[name]
Expand Down

0 comments on commit 2a34888

Please sign in to comment.