norton 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/norton/timestamp.rb +2 -2
- data/lib/norton/version.rb +1 -1
- data/norton.gemspec +1 -0
- data/spec/norton/timestamp_spec.rb +21 -3
- data/spec/spec_helper.rb +6 -5
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b5906f15562fcd49ad8fcd7a1328a12758984b5
|
4
|
+
data.tar.gz: bd7baed316f3532ece1c2567959ea1f7e408d7ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ae278996ed1de62b9a54024ea6fb26c7a823c0a1eeb8afa61ba6807153b7812aeef1903193c77033df6e9a8c4edeb59816c7857d63e563225e4fbf262b69638
|
7
|
+
data.tar.gz: 3ae1acec911911dc8943814071bfd0c8f845e0139e2897b523a67f461c60ec90bb3367b651b621bdb2db0a2f1910650fdb9969c3cb3cfc7883ebafc3a660aee6
|
data/lib/norton/timestamp.rb
CHANGED
@@ -16,7 +16,7 @@ module Norton
|
|
16
16
|
Norton.redis.with do |conn|
|
17
17
|
ts = conn.get("#{self.class.to_s.pluralize.underscore}:#{self.id}:#{name}").try(:to_i)
|
18
18
|
|
19
|
-
if ts.nil?
|
19
|
+
if !options[:allow_nil] && ts.nil?
|
20
20
|
ts = Time.now.to_i
|
21
21
|
conn.set("#{self.class.to_s.pluralize.underscore}:#{self.id}:#{name}", ts)
|
22
22
|
end
|
@@ -44,4 +44,4 @@ module Norton
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
data/lib/norton/version.rb
CHANGED
data/norton.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "fuubar"
|
29
29
|
spec.add_development_dependency "pry"
|
30
30
|
spec.add_development_dependency "pry-nav"
|
31
|
+
spec.add_development_dependency "timecop"
|
31
32
|
spec.add_development_dependency "activerecord", "~> 4.1"
|
32
33
|
spec.add_development_dependency "activerecord-nulldb-adapter"
|
33
34
|
end
|
@@ -4,6 +4,7 @@ class Dummy
|
|
4
4
|
include Norton::Timestamp
|
5
5
|
|
6
6
|
timestamp :born_at
|
7
|
+
timestamp :first_kissed_at, :allow_nil => true
|
7
8
|
# timestamp :graduated_at, before_save: -> { title_changed? || content_changed? }
|
8
9
|
|
9
10
|
def id
|
@@ -12,7 +13,7 @@ class Dummy
|
|
12
13
|
end
|
13
14
|
|
14
15
|
describe Norton::Timestamp do
|
15
|
-
describe "
|
16
|
+
describe ".timestamp" do
|
16
17
|
it "should add a class method timestamp to the class" do
|
17
18
|
expect(Dummy).to respond_to(:timestamp)
|
18
19
|
end
|
@@ -25,7 +26,7 @@ describe Norton::Timestamp do
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
describe "
|
29
|
+
describe "#touch_born_at" do
|
29
30
|
it 'should set timestamp in redis' do
|
30
31
|
dummy = Dummy.new
|
31
32
|
dummy.touch_born_at
|
@@ -37,12 +38,29 @@ describe Norton::Timestamp do
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
describe "
|
41
|
+
describe "#born_at" do
|
41
42
|
it 'should get the timestamp' do
|
42
43
|
dummy = Dummy.new
|
43
44
|
dummy.touch_born_at
|
44
45
|
expect(dummy.born_at).not_to be_nil
|
45
46
|
expect(dummy.born_at).to be_a(Fixnum)
|
46
47
|
end
|
48
|
+
|
49
|
+
it "should get current time as a default if timestamp is not touched" do
|
50
|
+
dummy = Dummy.new
|
51
|
+
t = Time.now
|
52
|
+
|
53
|
+
Timecop.freeze(t) do
|
54
|
+
expect(dummy.born_at).to eq(t.to_i)
|
55
|
+
expect(dummy.born_at).to eq(t.to_i)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#first_kissed_at" do
|
61
|
+
it "should return nil if not set before because it allows nil" do
|
62
|
+
dummy = Dummy.new
|
63
|
+
expect(dummy.first_kissed_at).to be_nil
|
64
|
+
end
|
47
65
|
end
|
48
66
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "active_record"
|
2
|
+
require "nulldb"
|
3
|
+
require "norton"
|
4
|
+
require "rspec"
|
5
|
+
require "timecop"
|
5
6
|
|
6
7
|
RSpec.configure do |config|
|
7
8
|
config.expect_with :rspec do |expectations|
|
@@ -21,6 +22,6 @@ RSpec.configure do |config|
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
Norton.setup url:
|
25
|
+
Norton.setup url: "redis://localhost:6379/0"
|
25
26
|
|
26
27
|
ActiveRecord::Base.establish_connection :adapter => :nulldb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: timecop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: activerecord
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
229
|
version: '0'
|
216
230
|
requirements: []
|
217
231
|
rubyforge_project:
|
218
|
-
rubygems_version: 2.
|
232
|
+
rubygems_version: 2.6.11
|
219
233
|
signing_key:
|
220
234
|
specification_version: 4
|
221
235
|
summary: Provide simple helpers on persist values in redis for performance. Works
|