notification_center 0.3.1 → 0.3.2
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.
- data/README.md +8 -0
- data/lib/notification_center.rb +2 -1
- data/lib/notification_center/version.rb +1 -1
- data/spec/lib/notification_center_spec.rb +13 -6
- metadata +1 -1
data/README.md
CHANGED
@@ -14,11 +14,19 @@ In your Gemfile
|
|
14
14
|
gem 'notification_center'
|
15
15
|
```
|
16
16
|
|
17
|
+
# Cache
|
18
|
+
|
19
|
+
To enable cache, in your:
|
20
|
+
|
17
21
|
config/initializers/notification_center.rb
|
18
22
|
|
19
23
|
```ruby
|
20
24
|
NotificationCenter.enable_cache = true # only one event fired in one request scope, default is false
|
21
25
|
```
|
26
|
+
Dont forget to flush cache wach request, for this in your config/application.rb in config section:
|
27
|
+
```ruby
|
28
|
+
config.middleware.use NotificationCenter::Cache
|
29
|
+
```
|
22
30
|
|
23
31
|
## Use
|
24
32
|
|
data/lib/notification_center.rb
CHANGED
@@ -14,14 +14,9 @@ describe NotificationCenter do
|
|
14
14
|
NotificationCenter.post_notification :imaginary_event
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should return listener result" do
|
18
|
-
EventListener = Class.new { observe :event }
|
19
|
-
EventListener.should_receive(:event_handler).and_return(:result)
|
20
|
-
NotificationCenter.post_notification(:event).should eql(:result)
|
21
|
-
end
|
22
|
-
|
23
17
|
context 'when cache disabled' do
|
24
18
|
before { NotificationCenter.enable_cache = false }
|
19
|
+
|
25
20
|
it "should not fire event twice" do
|
26
21
|
EventListener = Class.new { observe :event }
|
27
22
|
EventListener.should_receive(:event_handler).twice
|
@@ -29,6 +24,12 @@ describe NotificationCenter do
|
|
29
24
|
NotificationCenter.post_notification :event
|
30
25
|
NotificationCenter.post_notification :event
|
31
26
|
end
|
27
|
+
|
28
|
+
it "should return result" do
|
29
|
+
EventListener = Class.new { observe :event }
|
30
|
+
EventListener.should_receive(:event_handler).and_return(:result)
|
31
|
+
NotificationCenter.post_notification(:event).should eql(:result)
|
32
|
+
end
|
32
33
|
end
|
33
34
|
|
34
35
|
context 'when cache enabled' do
|
@@ -41,6 +42,12 @@ describe NotificationCenter do
|
|
41
42
|
NotificationCenter.post_notification :event
|
42
43
|
NotificationCenter.post_notification :event
|
43
44
|
end
|
45
|
+
|
46
|
+
it "should return result" do
|
47
|
+
EventListener = Class.new { observe :event }
|
48
|
+
EventListener.should_receive(:event_handler).and_return(:result)
|
49
|
+
NotificationCenter.post_notification(:event).should eql(:result)
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|