notificon 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.
@@ -137,11 +137,21 @@ module Notificon
137
137
  raise ArgumentError.new("action must be a Symbol") unless action.is_a? Symbol
138
138
  raise ArgumentError.new("occured_at must be a Time") unless occured_at .is_a? Time
139
139
 
140
- notification_store.add(Notification.new(:username => username, :item_url => item_url,
140
+ id = notification_store.add(Notification.new(:username => username, :item_url => item_url,
141
141
  :item_text => item_text, :actor => actor, :action => action, :occured_at => occured_at, :item_id => item_id))
142
142
  update_user_unread_counts(username)
143
+ id
143
144
  end
144
145
 
146
+ # Public : Retrieve a specific notification
147
+ #
148
+ # id - String id of the notification
149
+ #
150
+ # Returns Notification
151
+ def get_notification(id)
152
+ notification_store.get(id)
153
+ end
154
+
145
155
  # Public: Retrieve the most recent Notifications for user
146
156
  #
147
157
  # username - The String identifying the user
@@ -1,3 +1,3 @@
1
1
  module Notificon
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Notificon do
4
+ describe "add and retrieve notificaton" do
5
+ before(:each) do
6
+ @username = random_string
7
+ @item_url = random_string
8
+ @item_text = random_string
9
+ @actor = random_string
10
+ @action = random_string.to_sym
11
+ @occured_at = random_time
12
+
13
+ @id = Notificon.add_notification(@username, @item_url, @item_text, @actor, @action, @occured_at)
14
+ end
15
+
16
+ subject { Notificon.get_notification(@id) }
17
+
18
+ it "notification should have username" do
19
+ subject.username.should eq(@username)
20
+ end
21
+ end
22
+
23
+ end
@@ -41,6 +41,9 @@ describe NotificationStore do
41
41
  it "creates a record with item_id set" do
42
42
  @store.get(subject).item_id.should eq(@item_id)
43
43
  end
44
+ it "returns the id" do
45
+ subject.should_not be_nil
46
+ end
44
47
  end
45
48
 
46
49
  describe "#get_for_user" do
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe Notificon do
4
4
  before(:each) do
5
- @notification = Notification.new(:id => @id = random_string, :username => @username = random_string)
5
+ @notification = Notification.new(:id => @id = random_object_id, :username => @username = random_string)
6
6
  Notification.stub(:new) { @notification }
7
7
 
8
8
  @unread_count = random_integer
9
- @notification_store = mock(NotificationStore, :add => true, :unread_count_for_user => @unread_count, :mark_as_read => @notification)
9
+ @notification_store = mock(NotificationStore, :add => @id, :unread_count_for_user => @unread_count, :mark_as_read => @notification)
10
10
  Notificon.stub(:notification_store) { @notification_store }
11
11
  @user_state_store = mock(UserStateStore, :set_notifications => true)
12
12
  Notificon.stub(:user_state_store) { @user_state_store }
@@ -35,6 +35,9 @@ describe Notificon do
35
35
  @user_state_store.should_receive(:set_notifications).with(@username, @unread_count)
36
36
  subject
37
37
  end
38
+ it "returns the id of the items" do
39
+ subject.should eq(@id)
40
+ end
38
41
  context "when item id passed" do
39
42
  before(:each) do
40
43
  @item_id = random_string
@@ -119,4 +122,20 @@ describe Notificon do
119
122
  subject
120
123
  end
121
124
  end
125
+
126
+ describe ".get_notification" do
127
+ before(:each) do
128
+ @notification_store.stub(:get) { @notification }
129
+ end
130
+
131
+ subject { Notificon.get_notification(@notification.id) }
132
+
133
+ it "should get the notification from the store" do
134
+ @notification_store.should_receive(:get).with(@notification.id)
135
+ subject
136
+ end
137
+ it "should return the notification" do
138
+ subject.should eq(@notification)
139
+ end
140
+ end
122
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notificon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-07 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
@@ -74,6 +74,7 @@ files:
74
74
  - lib/notificon/user_state_store.rb
75
75
  - lib/notificon/version.rb
76
76
  - lib/notificon.rb
77
+ - spec/integration/notificon_spec.rb
77
78
  - spec/notificon/controller_spec.rb
78
79
  - spec/notificon/notification_spec.rb
79
80
  - spec/notificon/notification_store_spec.rb
@@ -105,6 +106,7 @@ signing_key:
105
106
  specification_version: 3
106
107
  summary: Gem for tracking and managing application notifications
107
108
  test_files:
109
+ - spec/integration/notificon_spec.rb
108
110
  - spec/notificon/controller_spec.rb
109
111
  - spec/notificon/notification_spec.rb
110
112
  - spec/notificon/notification_store_spec.rb