-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
$:.unshift '/Users/delano/Projects/opensource/storable/lib' | ||
load 'storable.rb' | ||
require 'storable' | ||
|
||
|
||
class A < Storable | ||
field :one => String | ||
field :two => Integer | ||
field :three => Time | ||
field :four => Boolean | ||
end | ||
class B < Storable | ||
field :one => String | ||
field :two | ||
field :three => Time | ||
end | ||
class C < Storable | ||
field :calc => Proc | ||
end | ||
|
||
tryouts "Basic Usage", :api do | ||
setup do | ||
class A < Storable | ||
field :one => String | ||
field :two => Integer | ||
field :three => Time | ||
field :four => Boolean | ||
end | ||
class B < Storable | ||
field :one => String | ||
field :two | ||
field :three => Time | ||
end | ||
class C < Storable | ||
field :calc => Proc | ||
end | ||
end | ||
|
||
dream ["string", 1, Time.parse("2010-03-04 23:00"), true] | ||
drill "Storable objects have a default initialize method" do | ||
a = A.new "string", 1, Time.parse("2010-03-04 23:00"), true | ||
[a.one, a.two, a.three, a.four] | ||
end | ||
|
||
dream ["string", 1, Time.parse("2010-03-04 23:00")] | ||
drill "Field types are optional" do | ||
b = B.new "string", 1, Time.parse("2010-03-04 23:00") | ||
b = B.from_json b.to_json | ||
[b.one, b.two, b.three] | ||
end | ||
|
||
dream 4 | ||
drill "Can restore a proc" do | ||
calc = Proc.new do | ||
2+2 | ||
end | ||
c = C.new calc | ||
c= C.from_json c.to_json | ||
c.calc.call | ||
end | ||
## "Storable objects have a default initialize method" | ||
a = A.new "string", 1, Time.parse("2010-03-04 23:00"), true | ||
[a.one, a.two, a.three, a.four] | ||
#=> ["string", 1, Time.parse("2010-03-04 23:00"), true] | ||
|
||
## "Field types are optional" | ||
b = B.new "string", 1, Time.parse("2010-03-04 23:00") | ||
b = B.from_json b.to_json | ||
[b.one, b.two, b.three] | ||
#=> ["string", 1, Time.parse("2010-03-04 23:00")] | ||
|
||
## "Can restore a proc" | ||
calc = Proc.new do | ||
2+2 | ||
end | ||
c = C.new calc | ||
c= C.from_json c.to_json | ||
c.calc.call | ||
#=> 4 | ||
|
||
|