Skip to content

Commit

Permalink
Broken storage specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnall committed Sep 19, 2010
1 parent dec2201 commit addda17
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/pwnbus/configdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.open(name, options = {})
begin
return_value = yield db.proxy
if db.dirty?
Files.write_file db_path do |wf|
Files.write_db db_path, options do |wf|
db.write wf
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/pwnbus/configdb/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def [](key)
# Returns value.
def []=(key, value)
@dirty = true
@data[key.to_s] = value.dup
if value.nil?
@data.delete key.to_s
else
@data[key.to_s] = (value.kind_of?(Numeric) || value.kind_of?(Symbol) ||
value == true || value == false) ? value : value.dup
end
value
end

Expand All @@ -75,7 +80,8 @@ def dirty?
# key doesn't exist. This makes it possible to have .-separated keys, like
# db.user.name = 'abc'.
def proxy_get(key)
(value = self[key]) ? value : Proxy.new(self, key + '.')
value = self[key]
value.nil? ? Proxy.new(self, key + '.') : value
end

# Inserts or updates
Expand Down
33 changes: 33 additions & 0 deletions spec/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,39 @@
end
end

describe "with saved db" do
before do
Configdb.open('persistence') do |p|
p.really.long.flag = true
p.really.long.number = 41
p.really.long.string = 'something'
end
end

it "should report variables correctly" do
Configdb.open('persistence') do |p|
p.really.long.flag.should == true
p.really.long.number.should == 41
p.really.long.string.should == 'something'
end
end

describe "after overwriting some vars" do
Configdb.open('persistence') do |p|
p.really.long.number = 42
p.really.long.flag = false
end

it "should report changes correctly" do
Configdb.open('persistence') do |p|
p.really.long.flag.should == false
p.really.long.number.should == 42
p.really.long.string.should == 'something'
end
end
end
end

describe "after crash" do
before do
@crash_path = @user_dir + '/crash.yml'
Expand Down

0 comments on commit addda17

Please sign in to comment.