user_notifier 0.0.2 → 0.0.3
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/app/mailers/user_notifier/{base_mailer.rb → mailer.rb} +2 -2
- data/app/models/user_notifier/base.rb +13 -6
- data/app/workers/user_notifier/email_worker.rb +1 -1
- data/lib/generators/user_notifier/notification/USAGE +2 -0
- data/lib/generators/user_notifier/notification/notification_generator.rb +26 -0
- data/lib/generators/user_notifier/notification/templates/migration.rb +13 -0
- data/lib/user_notifier/configuration.rb +1 -1
- data/lib/user_notifier/models/has_notifications.rb +16 -3
- data/lib/user_notifier/version.rb +1 -1
- data/spec/dummy/app/models/order.rb +3 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140709164530_create_orders.rb +10 -0
- data/spec/dummy/db/migrate/20140709170259_create_order_notifications.rb +13 -0
- data/spec/dummy/db/schema.rb +18 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +76 -0
- data/spec/dummy/log/test.log +5684 -0
- data/spec/models/user_notifier/base_spec.rb +37 -5
- metadata +12 -4
- data/README.rdoc +0 -3
@@ -2,12 +2,46 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe UserNotifier::Base do
|
4
4
|
let(:user){ User.create email: 'foo@bar.com' }
|
5
|
+
let(:order){ Order.create user_id: user.id, title: 'test' }
|
5
6
|
let(:notification){ UserNotification.notify('test', user) }
|
6
|
-
before{
|
7
|
+
before{ order }
|
8
|
+
|
7
9
|
|
8
10
|
describe "associations" do
|
9
|
-
|
10
|
-
|
11
|
+
context "in user model" do
|
12
|
+
subject{ user }
|
13
|
+
it{ should have_many :notifications }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "in notifications model" do
|
17
|
+
subject{ notification }
|
18
|
+
it{ should belong_to :user }
|
19
|
+
end
|
20
|
+
context "in notifications model when notification source is not the user" do
|
21
|
+
let(:notification){ OrderNotification.notify('test', user, order) }
|
22
|
+
subject{ notification }
|
23
|
+
it{ should belong_to :user }
|
24
|
+
it{ should belong_to :order }
|
25
|
+
it{ should belong_to :source } # just an alias for order
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".notify_once" do
|
30
|
+
before{ notification }
|
31
|
+
|
32
|
+
it "should create notification in the database" do
|
33
|
+
expect(UserNotification.last).to be_present
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not create notification for same association and different template name" do
|
37
|
+
UserNotification.notify_once('another_test', user)
|
38
|
+
expect(UserNotification.count(:all)).to eq 2
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not create duplicate notification for same association and template name" do
|
42
|
+
UserNotification.notify_once('test', user)
|
43
|
+
expect(UserNotification.count(:all)).to eq 1
|
44
|
+
end
|
11
45
|
end
|
12
46
|
|
13
47
|
describe ".notify" do
|
@@ -49,7 +83,5 @@ describe UserNotifier::Base do
|
|
49
83
|
before do
|
50
84
|
notification.deliver!
|
51
85
|
end
|
52
|
-
subject{ notification }
|
53
|
-
its(:sent_at){ should be_present }
|
54
86
|
end
|
55
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo Biazus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -102,15 +102,17 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- MIT-LICENSE
|
105
|
-
- README.rdoc
|
106
105
|
- Rakefile
|
107
|
-
- app/mailers/user_notifier/
|
106
|
+
- app/mailers/user_notifier/mailer.rb
|
108
107
|
- app/models/user_notifier/base.rb
|
109
108
|
- app/workers/user_notifier/email_worker.rb
|
110
109
|
- config/routes.rb
|
111
110
|
- lib/generators/user_notifier/install/USAGE
|
112
111
|
- lib/generators/user_notifier/install/install_generator.rb
|
113
112
|
- lib/generators/user_notifier/install/templates/user_notifier.rb
|
113
|
+
- lib/generators/user_notifier/notification/USAGE
|
114
|
+
- lib/generators/user_notifier/notification/notification_generator.rb
|
115
|
+
- lib/generators/user_notifier/notification/templates/migration.rb
|
114
116
|
- lib/tasks/user_notifier_tasks.rake
|
115
117
|
- lib/user_notifier.rb
|
116
118
|
- lib/user_notifier/configuration.rb
|
@@ -123,6 +125,7 @@ files:
|
|
123
125
|
- spec/dummy/app/assets/stylesheets/application.css
|
124
126
|
- spec/dummy/app/controllers/application_controller.rb
|
125
127
|
- spec/dummy/app/helpers/application_helper.rb
|
128
|
+
- spec/dummy/app/models/order.rb
|
126
129
|
- spec/dummy/app/models/user.rb
|
127
130
|
- spec/dummy/app/views/layouts/application.html.erb
|
128
131
|
- spec/dummy/bin/bundle
|
@@ -148,6 +151,8 @@ files:
|
|
148
151
|
- spec/dummy/db/development.sqlite3
|
149
152
|
- spec/dummy/db/migrate/20140625163719_create_users.rb
|
150
153
|
- spec/dummy/db/migrate/20140625183616_create_user_notifications.rb
|
154
|
+
- spec/dummy/db/migrate/20140709164530_create_orders.rb
|
155
|
+
- spec/dummy/db/migrate/20140709170259_create_order_notifications.rb
|
151
156
|
- spec/dummy/db/schema.rb
|
152
157
|
- spec/dummy/db/test.sqlite3
|
153
158
|
- spec/dummy/log/development.log
|
@@ -189,6 +194,7 @@ test_files:
|
|
189
194
|
- spec/dummy/log/test.log
|
190
195
|
- spec/dummy/log/development.log
|
191
196
|
- spec/dummy/config.ru
|
197
|
+
- spec/dummy/app/models/order.rb
|
192
198
|
- spec/dummy/app/models/user.rb
|
193
199
|
- spec/dummy/app/views/layouts/application.html.erb
|
194
200
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -220,7 +226,9 @@ test_files:
|
|
220
226
|
- spec/dummy/bin/rake
|
221
227
|
- spec/dummy/db/development.sqlite3
|
222
228
|
- spec/dummy/db/schema.rb
|
229
|
+
- spec/dummy/db/migrate/20140709164530_create_orders.rb
|
223
230
|
- spec/dummy/db/migrate/20140625183616_create_user_notifications.rb
|
231
|
+
- spec/dummy/db/migrate/20140709170259_create_order_notifications.rb
|
224
232
|
- spec/dummy/db/migrate/20140625163719_create_users.rb
|
225
233
|
- spec/dummy/db/test.sqlite3
|
226
234
|
- spec/dummy/Rakefile
|
data/README.rdoc
DELETED