acts_as_expirable 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/acts_as_expirable/expirable.rb +7 -4
- data/lib/acts_as_expirable/version.rb +1 -1
- data/test/unit/expirable_test.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fdf6a76474815497492290af24f3f900907cf5f
|
4
|
+
data.tar.gz: 893dc4aa66d73188c51d68029050dd3ac40e4e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93973f0d790aa33efff6e67dd2e1d5a8168d4267a346544069fa4408ab72de255aeadcf0280356d1bd14adc0b83af5db96dac1359a85289a5b64f765c3c5c769
|
7
|
+
data.tar.gz: 556842f38439a63caea40fcdd2990a57048f877c99fc1421e272229ee2e484c9343d5364c5906bf15a38e4920351b816d747284c84c5413f61437c212cb4d8f7
|
@@ -18,7 +18,6 @@ module ActsAsExpirable
|
|
18
18
|
class_attribute :acts_as_expirable_configuration
|
19
19
|
scope :expired, -> { where(["#{acts_as_expirable_configuration[:column]} <= ?", Time.now]) }
|
20
20
|
scope :unexpired, -> { where(["#{acts_as_expirable_configuration[:column]} IS NULL OR #{acts_as_expirable_configuration[:column]} > ?", Time.now]) }
|
21
|
-
delegate :expiry_column, to: :class
|
22
21
|
before_validation :set_expiry_default, on: :create
|
23
22
|
end
|
24
23
|
|
@@ -36,16 +35,20 @@ module ActsAsExpirable
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
38
|
+
def expiry_column
|
39
|
+
self.class.expiry_column
|
40
|
+
end
|
41
|
+
|
39
42
|
def expire
|
40
|
-
write_attribute(
|
43
|
+
write_attribute(expiry_column, Time.now)
|
41
44
|
end
|
42
45
|
|
43
46
|
def expire!
|
44
|
-
update_attribute(
|
47
|
+
update_attribute(expiry_column, Time.now)
|
45
48
|
end
|
46
49
|
|
47
50
|
def expired?
|
48
|
-
expire_time = read_attribute(
|
51
|
+
expire_time = read_attribute(expiry_column)
|
49
52
|
return false if expire_time.nil?
|
50
53
|
expire_time <= Time.now
|
51
54
|
end
|
data/test/unit/expirable_test.rb
CHANGED
@@ -33,11 +33,11 @@ class ExpirableTest < Test::Unit::TestCase
|
|
33
33
|
assert (Time.now.to_i + 1.day) - token.good_until.to_i <= 1, "should be set to nowish"
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def test_expired_scope
|
37
37
|
assert_equal(1, ExpirableName.expired.count)
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def test_unexpired_scope
|
41
41
|
assert_equal(2, ExpirableName.unexpired.count)
|
42
42
|
end
|
43
43
|
|
@@ -84,4 +84,4 @@ class ExpirableTest < Test::Unit::TestCase
|
|
84
84
|
assert name.expired?
|
85
85
|
end
|
86
86
|
|
87
|
-
end
|
87
|
+
end
|