Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for #372 #373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion motion/core/persistence.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Persistence module built on top of NSUserDefaults
module BubbleWrap
module Persistence
class FailSynchronize < RuntimeError; end
module_function

def app_key
Expand All @@ -9,7 +10,11 @@ def app_key

def []=(key, value)
storage.setObject(value, forKey: storage_key(key))
storage.synchronize
if storage.synchronize
value
else
raise FailSynchronize
end
end

def [](key)
Expand Down
15 changes: 15 additions & 0 deletions spec/motion/core/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ def storage.synchronize; @sync_was_called = true; end
BubbleWrap::Persistence['arbitraryNumber'] = 42
storage.instance_variable_get(:@sync_was_called).should.equal true
end

it 'return persisted objects' do
persisted_number = (BubbleWrap::Persistence['arbitraryNumber'] ||= 42)
persisted_number.should.equal 42
end

it 'raise error if fail synchronize.' do
storage = NSUserDefaults.standardUserDefaults
def storage.synchronize; false; end

lambda do
BubbleWrap::Persistence['arbitraryNumber'] = 42
end.
should.raise(BubbleWrap::Persistence::FailSynchronize)
end
end

describe "storing multiple objects" do
Expand Down