wupee 1.0.4 → 1.1.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.
@@ -0,0 +1,42 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Wupee::NotificationType, type: :model do
4
+ let!(:receiver) { create :user }
5
+ let!(:notification_type_name) { 'notify_new_message' }
6
+ let!(:notification_type) { create :notification_type, name: notification_type_name }
7
+ let!(:notification) { create :notification, notification_type: notification_type, receiver: receiver }
8
+
9
+ context "validations" do
10
+ it "validates presence of name" do
11
+ notification_type = Wupee::NotificationType.new
12
+ notification_type.valid?
13
+ expect(notification_type.errors).to have_key :name
14
+ end
15
+
16
+ it "validates presence of uniqueness of name" do
17
+ notification_type = Wupee::NotificationType.new(name: notification_type_name)
18
+ notification_type.valid?
19
+ expect(notification_type.errors).to have_key :name
20
+ end
21
+ end
22
+
23
+ context "methods" do
24
+ it "responds to notification_type_configurations" do
25
+ expect(notification_type).to respond_to(:notification_type_configurations)
26
+ end
27
+
28
+ it "responds to notifications" do
29
+ expect(notification_type).to respond_to(:notifications)
30
+ end
31
+ end
32
+
33
+ context "associations" do
34
+ it "destroys notification_type_configurations on destroy" do
35
+ expect { notification_type.destroy! }.to change { Wupee::Notification.count }.by(-1)
36
+ end
37
+
38
+ it "destroys notifications on destroy" do
39
+ expect { notification_type.destroy! }.to change { Wupee::NotificationTypeConfiguration.count }.by(-1)
40
+ end
41
+ end
42
+ end
@@ -1,6 +1,9 @@
1
1
  require 'rails_helper'
2
+ require_relative '../../lib/wupee/notifier'
2
3
 
3
4
  RSpec.describe Wupee::Notifier, type: :model do
5
+ let!(:notif_type) { Wupee::NotificationType.create!(name: "notify_new_message") }
6
+ let!(:user) { create :user }
4
7
 
5
8
  context "methods defined" do
6
9
  it { expect(subject).to respond_to(:notif_type) }
@@ -12,7 +15,6 @@ RSpec.describe Wupee::Notifier, type: :model do
12
15
  end
13
16
 
14
17
  it "has a method notif_type that can take Wupee::NotificationType instance or string/symbol as argument" do
15
- notif_type = create :notification_type
16
18
  wupee_notifier = Wupee::Notifier.new
17
19
  wupee_notifier.notif_type(notif_type.name)
18
20
  expect(wupee_notifier.notification_type).to eq notif_type
@@ -22,8 +24,6 @@ RSpec.describe Wupee::Notifier, type: :model do
22
24
  end
23
25
 
24
26
  it "has a method execute to send notifications and mails depending on notification_type_configurations of the users" do
25
- notif_type = Wupee::NotificationType.create!(name: "notify_new_message")
26
-
27
27
  user_1 = create :user
28
28
  user_2 = create :user
29
29
  user_3 = create :user
@@ -39,4 +39,21 @@ RSpec.describe Wupee::Notifier, type: :model do
39
39
  expect { wupee_notifier.execute }.to change { Wupee::Notification.where(is_read: true).count }.by(2)
40
40
  expect { wupee_notifier.execute }.to change { Wupee::Notification.count }.by(4)
41
41
  end
42
+
43
+ it "raises ArgumentError if receiver or receivers is missing" do
44
+ expect { Wupee::Notifier.new(notif_type: notif_type).execute }.to raise_error(ArgumentError)
45
+ end
46
+
47
+ it "doesn't raise ArgumentError if receiver or receivers is present" do
48
+ expect { Wupee::Notifier.new(notif_type: notif_type, receiver: user).execute }.not_to raise_error
49
+ expect { Wupee::Notifier.new(notif_type: notif_type, receivers: user).execute }.not_to raise_error
50
+ end
51
+
52
+ it "doesn't raise ArgumentError if receivers is an empty array" do
53
+ expect { Wupee::Notifier.new(notif_type: notif_type, receivers: []).execute }.not_to raise_error
54
+ end
55
+
56
+ it "raises ArgumentError if notif_type is missing" do
57
+ expect { Wupee::Notifier.new(receiver: user).execute }.to raise_error(ArgumentError)
58
+ end
42
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wupee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peng DU
@@ -9,15 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-24 00:00:00.000000000 Z
12
+ date: 2016-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '4.2'
21
18
  - - ">="
22
19
  - !ruby/object:Gem::Version
23
20
  version: 4.2.0
@@ -25,9 +22,6 @@ dependencies:
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: '4.2'
31
25
  - - ">="
32
26
  - !ruby/object:Gem::Version
33
27
  version: 4.2.0
@@ -105,7 +99,6 @@ files:
105
99
  - app/models/wupee/notification.rb
106
100
  - app/models/wupee/notification_type.rb
107
101
  - app/models/wupee/notification_type_configuration.rb
108
- - app/models/wupee/notifier.rb
109
102
  - app/views/wupee/api/notifications/_notification.json.jbuilder
110
103
  - app/views/wupee/api/notifications/index.json.jbuilder
111
104
  - app/views/wupee/api/notifications/show.json.jbuilder
@@ -118,9 +111,10 @@ files:
118
111
  - lib/generators/wupee/install/templates/wupee.rb
119
112
  - lib/generators/wupee/notification_type/USAGE
120
113
  - lib/generators/wupee/notification_type/notification_type_generator.rb
121
- - lib/tasks/wupee_tasks.rake
114
+ - lib/tasks/wupee.rake
122
115
  - lib/wupee.rb
123
116
  - lib/wupee/engine.rb
117
+ - lib/wupee/notifier.rb
124
118
  - lib/wupee/version.rb
125
119
  - spec/controllers/notifications_controller_spec.rb
126
120
  - spec/dummy/README.rdoc
@@ -188,6 +182,7 @@ files:
188
182
  - spec/models/message_spec.rb
189
183
  - spec/models/notification_spec.rb
190
184
  - spec/models/notification_type_configuration_spec.rb
185
+ - spec/models/notification_type_spec.rb
191
186
  - spec/models/notifier_spec.rb
192
187
  - spec/models/user_spec.rb
193
188
  - spec/rails_helper.rb
@@ -285,9 +280,11 @@ test_files:
285
280
  - spec/models/message_spec.rb
286
281
  - spec/models/notification_spec.rb
287
282
  - spec/models/notification_type_configuration_spec.rb
283
+ - spec/models/notification_type_spec.rb
288
284
  - spec/models/notifier_spec.rb
289
285
  - spec/models/user_spec.rb
290
286
  - spec/rails_helper.rb
291
287
  - spec/spec_helper.rb
292
288
  - spec/support/factory_girl.rb
293
289
  - spec/wupee_spec.rb
290
+ has_rdoc:
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :wupee do
3
- # # Task goes here
4
- # end