dm-is-temporal 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/dm-is-temporal/is/temporal.rb +10 -0
- data/spec/hooks_spec.rb +69 -0
- metadata +5 -3
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -7,12 +7,22 @@ module DataMapper
|
|
7
7
|
def initialize(base)
|
8
8
|
@__properties__ = []
|
9
9
|
@__base__ = base
|
10
|
+
@__before__ = []
|
11
|
+
@__after__ = []
|
10
12
|
end
|
11
13
|
|
12
14
|
def property(*args)
|
13
15
|
@__properties__ << args
|
14
16
|
end
|
15
17
|
|
18
|
+
def before(*args, &block)
|
19
|
+
@__before__ << [args, block]
|
20
|
+
end
|
21
|
+
|
22
|
+
def after(*args, &block)
|
23
|
+
@__after__ << [args, block]
|
24
|
+
end
|
25
|
+
|
16
26
|
def has(*args)
|
17
27
|
raise 'Temporal associations are not supported yet!'
|
18
28
|
end
|
data/spec/hooks_spec.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class MyModel
|
5
|
+
include DataMapper::Resource
|
6
|
+
|
7
|
+
property :id, Serial
|
8
|
+
property :name, String
|
9
|
+
|
10
|
+
is_temporal do
|
11
|
+
property :foo, Integer
|
12
|
+
property :bar, String
|
13
|
+
|
14
|
+
before(:save) do |m|
|
15
|
+
m.foo = 42
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:create) do |m|
|
19
|
+
m.bar = 'hello'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe DataMapper::Is::Temporal do
|
25
|
+
|
26
|
+
before(:all) do
|
27
|
+
DataMapper.setup(:default, "sqlite3::memory:")
|
28
|
+
DataMapper.setup(:test, "sqlite3::memory:")
|
29
|
+
DataMapper.auto_migrate!
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#before" do
|
33
|
+
|
34
|
+
subject do
|
35
|
+
MyModel.create
|
36
|
+
end
|
37
|
+
|
38
|
+
it "before hook sets foo to 42" do
|
39
|
+
subject.foo = 10
|
40
|
+
subject.save
|
41
|
+
subject.foo.should == 42
|
42
|
+
end
|
43
|
+
|
44
|
+
it "bar should == 'hello'" do
|
45
|
+
subject.foo = 10
|
46
|
+
subject.save
|
47
|
+
subject.bar.should == 'hello'
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
it "bar should == 'hello' even if changed" do
|
52
|
+
oldish = DateTime.parse('-4712-01-01T00:00:00+00:00')
|
53
|
+
nowish = DateTime.parse('2011-03-01T00:00:00+00:00')
|
54
|
+
|
55
|
+
subject.at(oldish).bar = 'quack'
|
56
|
+
subject.save
|
57
|
+
subject.at(oldish).bar.should == 'hello'
|
58
|
+
|
59
|
+
subject.instance_eval { puts self.temporal_versions.size.should == 1}
|
60
|
+
|
61
|
+
subject.at(nowish).bar = 'quack'
|
62
|
+
subject.save
|
63
|
+
subject.at(nowish).bar.should == 'quack'
|
64
|
+
subject.at(oldish).bar.should == 'hello'
|
65
|
+
|
66
|
+
subject.instance_eval { puts self.temporal_versions.size.should == 2}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joe Kutner
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-11 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- VERSION
|
35
35
|
- lib/dm-is-temporal.rb
|
36
36
|
- lib/dm-is-temporal/is/temporal.rb
|
37
|
+
- spec/hooks_spec.rb
|
37
38
|
- spec/spec.opts
|
38
39
|
- spec/spec_helper.rb
|
39
40
|
- spec/temporal_spec.rb
|
@@ -68,5 +69,6 @@ signing_key:
|
|
68
69
|
specification_version: 3
|
69
70
|
summary: DataMapper plugin implementing temporal patterns
|
70
71
|
test_files:
|
72
|
+
- spec/hooks_spec.rb
|
71
73
|
- spec/spec_helper.rb
|
72
74
|
- spec/temporal_spec.rb
|