dm-timestamps 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/dm-timestamps.rb +4 -2
- data/lib/dm-timestamps/version.rb +1 -1
- data/spec/integration/timestamps_spec.rb +73 -75
- metadata +3 -3
data/History.txt
CHANGED
data/lib/dm-timestamps.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
gem 'dm-core', '~>0.9.
|
3
|
+
gem 'dm-core', '~>0.9.9'
|
4
4
|
require 'dm-core'
|
5
5
|
|
6
6
|
module DataMapper
|
@@ -39,7 +39,7 @@ module DataMapper
|
|
39
39
|
case name
|
40
40
|
when *TIMESTAMP_PROPERTIES.keys
|
41
41
|
type = TIMESTAMP_PROPERTIES[name].first
|
42
|
-
property name, type, :nullable => false
|
42
|
+
property name, type, :nullable => false, :auto_validation => false
|
43
43
|
when :at
|
44
44
|
timestamps(:created_at, :updated_at)
|
45
45
|
when :on
|
@@ -53,4 +53,6 @@ module DataMapper
|
|
53
53
|
|
54
54
|
class InvalidTimestampName < RuntimeError; end
|
55
55
|
end # module Timestamp
|
56
|
+
# include Timestamp or Timestamps, it still works
|
57
|
+
Timestamps = Timestamp
|
56
58
|
end # module DataMapper
|
@@ -1,92 +1,90 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
3
|
|
4
|
+
# run the specs with dm-validations, if available
|
5
|
+
begin
|
6
|
+
gem 'dm-validations', '~>0.9.9'
|
7
|
+
require 'dm-validations'
|
8
|
+
rescue LoadError
|
9
|
+
# do nothing
|
10
|
+
end
|
11
|
+
|
4
12
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
5
13
|
describe 'DataMapper::Timestamp' do
|
6
14
|
describe "Timestamp (shared behavior)", :shared => true do
|
7
15
|
it "should not set the created_at/on fields if they're already set" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
green_smoothie.created_on.should be_a_kind_of(Date)
|
18
|
-
end
|
16
|
+
green_smoothie = GreenSmoothie.new(:name => 'Banana')
|
17
|
+
time = (DateTime.now - 100)
|
18
|
+
green_smoothie.created_at = time
|
19
|
+
green_smoothie.created_on = time
|
20
|
+
green_smoothie.save
|
21
|
+
green_smoothie.created_at.should == time
|
22
|
+
green_smoothie.created_on.should == time
|
23
|
+
green_smoothie.created_at.should be_a_kind_of(DateTime)
|
24
|
+
green_smoothie.created_on.should be_a_kind_of(Date)
|
19
25
|
end
|
20
26
|
|
21
27
|
it "should set the created_at/on fields on creation" do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
green_smoothie.created_on.should be_a_kind_of(Date)
|
29
|
-
end
|
28
|
+
green_smoothie = GreenSmoothie.new(:name => 'Banana')
|
29
|
+
green_smoothie.created_at.should be_nil
|
30
|
+
green_smoothie.created_on.should be_nil
|
31
|
+
green_smoothie.save
|
32
|
+
green_smoothie.created_at.should be_a_kind_of(DateTime)
|
33
|
+
green_smoothie.created_on.should be_a_kind_of(Date)
|
30
34
|
end
|
31
35
|
|
32
36
|
it "should not alter the create_at/on fields on model updates" do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
green_smoothie.created_on.should eql(original_created_on)
|
44
|
-
end
|
37
|
+
green_smoothie = GreenSmoothie.new(:id => 2, :name => 'Berry')
|
38
|
+
green_smoothie.created_at.should be_nil
|
39
|
+
green_smoothie.created_on.should be_nil
|
40
|
+
green_smoothie.save
|
41
|
+
original_created_at = green_smoothie.created_at
|
42
|
+
original_created_on = green_smoothie.created_on
|
43
|
+
green_smoothie.name = 'Strawberry'
|
44
|
+
green_smoothie.save
|
45
|
+
green_smoothie.created_at.should eql(original_created_at)
|
46
|
+
green_smoothie.created_on.should eql(original_created_on)
|
45
47
|
end
|
46
48
|
|
47
49
|
it "should set the updated_at/on fields on creation and on update" do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
green_smoothie.updated_on.should eql(date_tomorrow)
|
67
|
-
end
|
50
|
+
green_smoothie = GreenSmoothie.new(:name => 'Mango')
|
51
|
+
green_smoothie.updated_at.should be_nil
|
52
|
+
green_smoothie.updated_on.should be_nil
|
53
|
+
green_smoothie.save
|
54
|
+
green_smoothie.updated_at.should be_a_kind_of(DateTime)
|
55
|
+
green_smoothie.updated_on.should be_a_kind_of(Date)
|
56
|
+
original_updated_at = green_smoothie.updated_at
|
57
|
+
original_updated_on = green_smoothie.updated_on
|
58
|
+
time_tomorrow = DateTime.now + 1
|
59
|
+
date_tomorrow = Date.today + 1
|
60
|
+
DateTime.stub!(:now).and_return { time_tomorrow }
|
61
|
+
Date.stub!(:today).and_return { date_tomorrow }
|
62
|
+
green_smoothie.name = 'Cranberry Mango'
|
63
|
+
green_smoothie.save
|
64
|
+
green_smoothie.updated_at.should_not eql(original_updated_at)
|
65
|
+
green_smoothie.updated_on.should_not eql(original_updated_on)
|
66
|
+
green_smoothie.updated_at.should eql(time_tomorrow)
|
67
|
+
green_smoothie.updated_on.should eql(date_tomorrow)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should only set the updated_at/on fields on dirty objects" do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
green_smoothie.updated_on.should eql(original_updated_on)
|
89
|
-
end
|
71
|
+
green_smoothie = GreenSmoothie.new(:name => 'Mango')
|
72
|
+
green_smoothie.updated_at.should be_nil
|
73
|
+
green_smoothie.updated_on.should be_nil
|
74
|
+
green_smoothie.save
|
75
|
+
green_smoothie.updated_at.should be_a_kind_of(DateTime)
|
76
|
+
green_smoothie.updated_on.should be_a_kind_of(Date)
|
77
|
+
original_updated_at = green_smoothie.updated_at
|
78
|
+
original_updated_on = green_smoothie.updated_on
|
79
|
+
time_tomorrow = DateTime.now + 1
|
80
|
+
date_tomorrow = Date.today + 1
|
81
|
+
DateTime.stub!(:now).and_return { time_tomorrow }
|
82
|
+
Date.stub!(:today).and_return { date_tomorrow }
|
83
|
+
green_smoothie.save
|
84
|
+
green_smoothie.updated_at.should_not eql(time_tomorrow)
|
85
|
+
green_smoothie.updated_on.should_not eql(date_tomorrow)
|
86
|
+
green_smoothie.updated_at.should eql(original_updated_at)
|
87
|
+
green_smoothie.updated_on.should eql(original_updated_on)
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
@@ -96,14 +94,14 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
96
94
|
class GreenSmoothie
|
97
95
|
include DataMapper::Resource
|
98
96
|
|
99
|
-
property :id,
|
100
|
-
property :name,
|
97
|
+
property :id, Serial
|
98
|
+
property :name, String
|
101
99
|
property :created_at, DateTime
|
102
100
|
property :created_on, Date
|
103
101
|
property :updated_at, DateTime
|
104
102
|
property :updated_on, Date
|
105
103
|
|
106
|
-
auto_migrate!
|
104
|
+
auto_migrate!
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
@@ -162,12 +160,12 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
162
160
|
class GreenSmoothie
|
163
161
|
include DataMapper::Resource
|
164
162
|
|
165
|
-
property :id,
|
163
|
+
property :id, Serial
|
166
164
|
property :name, String
|
167
165
|
|
168
166
|
timestamps :at, :on
|
169
167
|
|
170
|
-
auto_migrate!
|
168
|
+
auto_migrate!
|
171
169
|
end
|
172
170
|
end
|
173
171
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-timestamps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Foy Savas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.9
|
24
24
|
version:
|
25
25
|
description: DataMapper plugin for magical timestamps
|
26
26
|
email:
|