Skip to content

Instantly share code, notes, and snippets.

@cheald
Last active December 19, 2015 09:59
Show Gist options
  • Save cheald/5936864 to your computer and use it in GitHub Desktop.
Save cheald/5936864 to your computer and use it in GitHub Desktop.
[1] pry(#<MongoMapper::Plugins::Keys::Key>)> show-source @default
From: /var/www/repos/mongomapper/spec/unit/keys_spec.rb
Number of lines: 1
generator = lambda { raise Exception }
[3] pry(#<MongoMapper::Plugins::Keys::Key>)> @default.call
=> nil
[4] pry(#<MongoMapper::Plugins::Keys::Key>)> lambda { raise Exception }.call
Exception: Exception
from (pry):3:in `block in default_value'
context "when loading from the database" do
it "should not set default values for keys that already exist" do
generator = lambda { raise Exception }
klass = Doc do
key :value, Integer, :default => generator
end
generator.should_receive(:call).exactly(2).times
puts "Starting"
instance = klass.create
puts "Finding"
instance.reload.value.should == 3
instance.value = 4
instance.save
instance.reload.value.should == 4
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment