id 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/id.gemspec +1 -1
- data/lib/id/all.rb +1 -0
- data/lib/id/model.rb +1 -1
- data/lib/id/timestamps.rb +23 -0
- data/spec/lib/id/timestamps_spec.rb +35 -0
- data/spec/lib/mike_spec.rb +20 -0
- metadata +6 -1
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
id (0.0.
|
4
|
+
id (0.0.7)
|
5
5
|
activesupport
|
6
6
|
money
|
7
7
|
optional
|
@@ -17,7 +17,7 @@ GEM
|
|
17
17
|
money (5.1.1)
|
18
18
|
i18n (~> 0.6.0)
|
19
19
|
multi_json (1.7.2)
|
20
|
-
optional (0.0.
|
20
|
+
optional (0.0.4)
|
21
21
|
rspec (2.13.0)
|
22
22
|
rspec-core (~> 2.13.0)
|
23
23
|
rspec-expectations (~> 2.13.0)
|
data/id.gemspec
CHANGED
data/lib/id/all.rb
CHANGED
data/lib/id/model.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Id
|
2
|
+
module Timestamps
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.field :created_at
|
6
|
+
base.field :updated_at
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(data = {})
|
10
|
+
super data.merge(_timestamps data)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def _timestamps(data, now=Time.now)
|
16
|
+
{
|
17
|
+
created_at: data.fetch('created_at', now),
|
18
|
+
updated_at: now
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TimeStampedModel
|
4
|
+
include Id::Model
|
5
|
+
include Id::Timestamps
|
6
|
+
|
7
|
+
field :foo
|
8
|
+
field :bar
|
9
|
+
end
|
10
|
+
|
11
|
+
module Id
|
12
|
+
describe Timestamps do
|
13
|
+
|
14
|
+
let (:model) { TimeStampedModel.new(foo: 999, bar: 666) }
|
15
|
+
|
16
|
+
it 'should have a created_at date' do
|
17
|
+
model.created_at.should be_a Time
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have an updated_at date' do
|
21
|
+
model.updated_at.should be_a Time
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should update the updated at when set is called' do
|
25
|
+
updated = model.set(foo: 123)
|
26
|
+
expect(updated.created_at).to be < updated.updated_at
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should update the updated at when unset is called' do
|
30
|
+
updated = model.unset(:foo)
|
31
|
+
expect(updated.created_at).to be < updated.updated_at
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Mike
|
4
|
+
include Id::Model
|
5
|
+
|
6
|
+
field :cat
|
7
|
+
field :dog, optional: true
|
8
|
+
|
9
|
+
def catdog
|
10
|
+
dog.value_or cat
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Foobar" do
|
16
|
+
let (:mike) { Mike.new(cat: 'pooface') }
|
17
|
+
it 'returns cat' do
|
18
|
+
mike.catdog.should eq 'pooface'
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -119,11 +119,14 @@ files:
|
|
119
119
|
- lib/id/model/has_many.rb
|
120
120
|
- lib/id/model/has_one.rb
|
121
121
|
- lib/id/model/type_casts.rb
|
122
|
+
- lib/id/timestamps.rb
|
122
123
|
- spec/lib/id/model/association_spec.rb
|
123
124
|
- spec/lib/id/model/builder_spec.rb
|
124
125
|
- spec/lib/id/model/has_one_spec.rb
|
125
126
|
- spec/lib/id/model/type_casts_spec.rb
|
126
127
|
- spec/lib/id/model_spec.rb
|
128
|
+
- spec/lib/id/timestamps_spec.rb
|
129
|
+
- spec/lib/mike_spec.rb
|
127
130
|
- spec/spec_helper.rb
|
128
131
|
homepage: http://github.com/onthebeach/id
|
129
132
|
licenses: []
|
@@ -155,5 +158,7 @@ test_files:
|
|
155
158
|
- spec/lib/id/model/has_one_spec.rb
|
156
159
|
- spec/lib/id/model/type_casts_spec.rb
|
157
160
|
- spec/lib/id/model_spec.rb
|
161
|
+
- spec/lib/id/timestamps_spec.rb
|
162
|
+
- spec/lib/mike_spec.rb
|
158
163
|
- spec/spec_helper.rb
|
159
164
|
has_rdoc:
|