Commit 2eb4301ba4563ce078231185ec2603b6f96d419f
- Date: Sun Feb 17 20:20:47 +0000 2008
- Committer: Yurii Rashkovskii (yrashk@gmail.com)
- Author: Yurii Rashkovskii (yrashk@gmail.com)
- Commit SHA1: 2eb4301ba4563ce078231185ec2603b6f96d419f
- Tree SHA1: a0fade0f9d73c90314676e693dadd8aea5cd8fca
Bugfixes for callback stuff (when_slot_not_found behaves properly now)
Commit diff
| |   |
| 267 | 267 | send(:[]=,sym.chomp('='),*args) |
| 268 | 268 | else |
| 269 | 269 | unless slotnames.include?(sym) |
| 270 | | raise SlotNotFoundError.new(sym) if (callbacks[:when_slot_not_found]||[]).empty? |
| 270 | raise SlotNotFoundError.new(sym) if (callbacks['when_slot_not_found']||[]).empty? |
| 271 | 271 | execute_callbacks(:when_slot_not_found,sym) |
| 272 | else |
| 273 | send(:[],sym) |
| 272 | 274 | end |
| 273 | | send(:[],sym) |
| 274 | 275 | end |
| 275 | 276 | end |
| 276 | 277 | |
| toggle raw diff |
--- a/strokedb-ruby/lib/document/document.rb
+++ b/strokedb-ruby/lib/document/document.rb
@@ -267,10 +267,11 @@ module StrokeDB
send(:[]=,sym.chomp('='),*args)
else
unless slotnames.include?(sym)
- raise SlotNotFoundError.new(sym) if (callbacks[:when_slot_not_found]||[]).empty?
+ raise SlotNotFoundError.new(sym) if (callbacks['when_slot_not_found']||[]).empty?
execute_callbacks(:when_slot_not_found,sym)
+ else
+ send(:[],sym)
end
- send(:[],sym)
end
end
|
| |   |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | it "should call when_slot_not_found callback on missing slot" do |
| 26 | | @document.callbacks[:when_slot_not_found] = [mock("callback")] |
| 27 | | @document.should_receive(:execute_callbacks).with(:when_slot_not_found,'slot_that_surely_does_not_exist') |
| 28 | | @document.slot_that_surely_does_not_exist |
| 26 | @document.callbacks['when_slot_not_found'] = [mock("callback")] |
| 27 | @document.should_receive(:execute_callbacks).with(:when_slot_not_found,'slot_that_surely_does_not_exist').and_return("Yes!") |
| 28 | @document.slot_that_surely_does_not_exist.should == "Yes!" |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | 31 | it "should raise an exception if slot not found when trying to read it" do |
| toggle raw diff |
--- a/strokedb-ruby/spec/document/document_spec.rb
+++ b/strokedb-ruby/spec/document/document_spec.rb
@@ -23,9 +23,9 @@ describe "Document", :shared => true do
it "should call when_slot_not_found callback on missing slot" do
- @document.callbacks[:when_slot_not_found] = [mock("callback")]
- @document.should_receive(:execute_callbacks).with(:when_slot_not_found,'slot_that_surely_does_not_exist')
- @document.slot_that_surely_does_not_exist
+ @document.callbacks['when_slot_not_found'] = [mock("callback")]
+ @document.should_receive(:execute_callbacks).with(:when_slot_not_found,'slot_that_surely_does_not_exist').and_return("Yes!")
+ @document.slot_that_surely_does_not_exist.should == "Yes!"
end
it "should raise an exception if slot not found when trying to read it" do |