notifi 0.0.3 → 0.0.4
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/notifi/subscriber.rb +6 -1
- data/lib/notifi/version.rb +1 -1
- data/spec/subscriber_spec.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce52f781ba0c9caa7fd5278684667cf05534c862
|
4
|
+
data.tar.gz: c0b4d169eb719cccda7b6f2b37aa2783dedf9f36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 760d4930a5bc4ff683ef2c33eb958cdc2f0502ce761a8d0ba70825a30931685a1023ae38295317ee43e521df0d298af7ad7deb407f03d92b523d5c7018338d65
|
7
|
+
data.tar.gz: bb528f7438edb9f41850f4bab51209e2c70082d43e754b74da1f5f684c919928971b226dafa40edbdc2970c03fc52a3d8517cadc55efc7f7e198a3faa958f73b
|
data/lib/notifi/subscriber.rb
CHANGED
@@ -15,7 +15,12 @@ module Notifi
|
|
15
15
|
def subscribe_to(subscribable)
|
16
16
|
reject_non_subscribable! subscribable
|
17
17
|
|
18
|
-
self.subscriptions.
|
18
|
+
sub = self.subscriptions.find_or_initialize_by(subscriber: self, subscribable: subscribable)
|
19
|
+
|
20
|
+
if sub.new_record?
|
21
|
+
sub.save
|
22
|
+
sub
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
def unsubscribe_from(subscribable)
|
data/lib/notifi/version.rb
CHANGED
data/spec/subscriber_spec.rb
CHANGED
@@ -31,11 +31,18 @@ describe 'subscriber' do
|
|
31
31
|
subscriber.subscriptions.count.should eq 1
|
32
32
|
end
|
33
33
|
|
34
|
-
it 'should return a Subscription' do
|
34
|
+
it 'should return a Subscription if subscription create' do
|
35
35
|
subscription = subscriber.subscribe_to subscribable
|
36
36
|
|
37
37
|
subscription.should be_an_instance_of Notifi::Subscription
|
38
38
|
end
|
39
|
+
|
40
|
+
it 'should not return a Subscription if subscription already exists' do
|
41
|
+
subscriber.subscribe_to subscribable
|
42
|
+
subscription = subscriber.subscribe_to subscribable
|
43
|
+
|
44
|
+
subscription.should be nil
|
45
|
+
end
|
39
46
|
end
|
40
47
|
|
41
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hunter Haydel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|