wupee 1.1.4 → 2.0.0.beta1
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/controllers/wupee/api/notifications_controller.rb +15 -14
- data/app/mailers/wupee/notifications_mailer.rb +11 -5
- data/app/models/concerns/wupee/receiver.rb +0 -7
- data/app/models/wupee/notification.rb +5 -2
- data/app/models/wupee/notification_type.rb +0 -13
- data/config/routes.rb +3 -2
- data/db/migrate/20151029113107_create_wupee_notifications.rb +4 -3
- data/lib/generators/wupee/install/templates/wupee.rb +12 -1
- data/lib/tasks/wupee.rake +0 -14
- data/lib/wupee.rb +1 -7
- data/lib/wupee/notifier.rb +45 -8
- data/lib/wupee/version.rb +1 -1
- data/spec/controllers/notifications_controller_spec.rb +7 -2
- data/spec/dummy/config/initializers/wupee.rb +8 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +5 -12
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +804 -0
- data/spec/dummy/log/test.log +35767 -0
- data/spec/models/concerns/receiver_spec.rb +0 -22
- data/spec/models/notification_spec.rb +0 -15
- data/spec/models/notification_type_spec.rb +1 -15
- data/spec/models/notifier_spec.rb +12 -8
- metadata +4 -10
- data/app/models/wupee/notification_type_configuration.rb +0 -17
- data/db/migrate/20151029113101_create_wupee_notification_type_configurations.rb +0 -14
- data/spec/factories/notification_type_configuration.rb +0 -6
- data/spec/models/notification_type_configuration_spec.rb +0 -43
@@ -7,31 +7,9 @@ shared_examples_for "Wupee::Receiver" do
|
|
7
7
|
expect(model.new).to respond_to(:notifications)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "has many notification_type_configurations" do
|
11
|
-
expect(model.new).to respond_to(:notification_type_configurations)
|
12
|
-
end
|
13
|
-
|
14
10
|
it "destroys notification on destroy" do
|
15
11
|
receiver = create model.name.underscore
|
16
12
|
create :notification, receiver: receiver
|
17
13
|
expect { receiver.destroy }.to change { Wupee::Notification.count }.by(-1)
|
18
14
|
end
|
19
|
-
|
20
|
-
it "destroys notification_type_configurations on destroy" do
|
21
|
-
receiver = create model.name.underscore
|
22
|
-
Wupee::NotificationTypeConfiguration.create(receiver: receiver, notification_type: Wupee::NotificationType.create(name: 'abc'))
|
23
|
-
expect { receiver.destroy }.to change { Wupee::NotificationTypeConfiguration.count }.by(-1)
|
24
|
-
end
|
25
|
-
|
26
|
-
context "there are already notification type created" do
|
27
|
-
it "has no notification_type_configurations associated to notification_type" do
|
28
|
-
expect(Wupee::NotificationTypeConfiguration.count).to eq 0
|
29
|
-
end
|
30
|
-
|
31
|
-
it "creates notification_type_configurations after model is created" do
|
32
|
-
create :notification_type
|
33
|
-
expect { create model.name.underscore }.to change { Wupee::NotificationTypeConfiguration.count }.by(1)
|
34
|
-
expect(Wupee::NotificationTypeConfiguration.last.receiver).to eq model.last
|
35
|
-
end
|
36
|
-
end
|
37
15
|
end
|
@@ -36,19 +36,4 @@ RSpec.describe Wupee::Notification, type: :model do
|
|
36
36
|
it { expect(create(:notification).is_read).to be false }
|
37
37
|
it { expect(create(:notification).is_sent).to be false }
|
38
38
|
end
|
39
|
-
|
40
|
-
# it '#deliver_now should send a mail' do
|
41
|
-
# notification = Wupee::Notification.new.send_notification(type: notification_type_name, attached_object: message)
|
42
|
-
# .to(receiver)
|
43
|
-
# expect(notification.deliver_now).to be_a(Mail::Message)
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# it '#deliver_later should send later a mail' do
|
47
|
-
# notification = Wupee::Notification.new.send_notification(type: notification_type_name, attached_object: message)
|
48
|
-
# .to(receiver)
|
49
|
-
# expect(notification.deliver_later).to be_a(ActionMailer::DeliveryJob)
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
39
|
end
|
@@ -21,28 +21,14 @@ RSpec.describe Wupee::NotificationType, type: :model do
|
|
21
21
|
end
|
22
22
|
|
23
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
24
|
it "responds to notifications" do
|
29
25
|
expect(notification_type).to respond_to(:notifications)
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
|
-
context "class methods" do
|
34
|
-
it "has a method create_configurations_for which creates NotificationTypeConfiguration objects" do
|
35
|
-
expect { create :notification_type, name: "random_notif_type_2" }.to change { Wupee::NotificationTypeConfiguration.count }.by(User.count)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
29
|
context "associations" do
|
40
|
-
it "destroys notification_type_configurations on destroy" do
|
41
|
-
expect { notification_type.destroy! }.to change { Wupee::Notification.count }.by(-1)
|
42
|
-
end
|
43
|
-
|
44
30
|
it "destroys notifications on destroy" do
|
45
|
-
expect { notification_type.destroy! }.to change { Wupee::
|
31
|
+
expect { notification_type.destroy! }.to change { Wupee::Notification.count }.by(-1)
|
46
32
|
end
|
47
33
|
end
|
48
34
|
end
|
@@ -23,22 +23,26 @@ RSpec.describe Wupee::Notifier, type: :model do
|
|
23
23
|
expect(wupee_notifier.notification_type).to eq notif_type
|
24
24
|
end
|
25
25
|
|
26
|
-
it "has a method execute to send notifications and mails
|
26
|
+
it "has a method execute to send notifications and mails" do
|
27
27
|
user_1 = create :user
|
28
28
|
user_2 = create :user
|
29
29
|
user_3 = create :user
|
30
30
|
user_4 = create :user
|
31
31
|
|
32
|
-
Wupee::NotificationTypeConfiguration.find_by(receiver: user_2, notification_type: notif_type).update(value: :nothing)
|
33
|
-
Wupee::NotificationTypeConfiguration.find_by(receiver: user_3, notification_type: notif_type).update(value: :email)
|
34
|
-
Wupee::NotificationTypeConfiguration.find_by(receiver: user_4, notification_type: notif_type).update(value: :notification)
|
35
|
-
|
36
32
|
wupee_notifier = Wupee::Notifier.new(receivers: [user_1, user_2, user_3, user_4], notif_type: notif_type)
|
37
33
|
|
38
|
-
expect { wupee_notifier.execute }.to change { ActionMailer::Base.deliveries.size }.by(
|
39
|
-
expect { wupee_notifier.execute }.to change { Wupee::Notification.where(is_read:
|
34
|
+
expect { wupee_notifier.execute }.to change { ActionMailer::Base.deliveries.size }.by(4)
|
35
|
+
expect { wupee_notifier.execute }.to change { Wupee::Notification.where(is_read: false).count }.by(4)
|
40
36
|
expect { wupee_notifier.execute }.to change { Wupee::Notification.count }.by(4)
|
41
|
-
|
37
|
+
|
38
|
+
Wupee.email_sending_rule = false
|
39
|
+
expect { wupee_notifier.execute }.not_to change { ActionMailer::Base.deliveries.size }
|
40
|
+
expect { wupee_notifier.execute }.to change { Wupee::Notification.count }.by(4)
|
41
|
+
|
42
|
+
Wupee.notification_sending_rule = false
|
43
|
+
expect { wupee_notifier.execute }.not_to change { Wupee::Notification.wanted.count }
|
44
|
+
expect { wupee_notifier.execute }.to change { Wupee::Notification.unwanted.count }.by(4)
|
45
|
+
end
|
42
46
|
|
43
47
|
it "raises ArgumentError if receiver or receivers is missing" do
|
44
48
|
expect { Wupee::Notifier.new(notif_type: notif_type).execute }.to raise_error(ArgumentError)
|
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:
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peng DU
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -98,13 +98,11 @@ files:
|
|
98
98
|
- app/models/concerns/wupee/receiver.rb
|
99
99
|
- app/models/wupee/notification.rb
|
100
100
|
- app/models/wupee/notification_type.rb
|
101
|
-
- app/models/wupee/notification_type_configuration.rb
|
102
101
|
- app/views/wupee/api/notifications/_notification.json.jbuilder
|
103
102
|
- app/views/wupee/api/notifications/index.json.jbuilder
|
104
103
|
- app/views/wupee/api/notifications/show.json.jbuilder
|
105
104
|
- config/routes.rb
|
106
105
|
- db/migrate/20151029113100_create_wupee_notification_types.rb
|
107
|
-
- db/migrate/20151029113101_create_wupee_notification_type_configurations.rb
|
108
106
|
- db/migrate/20151029113107_create_wupee_notifications.rb
|
109
107
|
- lib/generators/wupee/install/USAGE
|
110
108
|
- lib/generators/wupee/install/install_generator.rb
|
@@ -175,14 +173,12 @@ files:
|
|
175
173
|
- spec/factories/message.rb
|
176
174
|
- spec/factories/notification.rb
|
177
175
|
- spec/factories/notification_type.rb
|
178
|
-
- spec/factories/notification_type_configuration.rb
|
179
176
|
- spec/factories/user.rb
|
180
177
|
- spec/mailers/notifications_mailer_spec.rb
|
181
178
|
- spec/models/concerns/attached_object_spec.rb
|
182
179
|
- spec/models/concerns/receiver_spec.rb
|
183
180
|
- spec/models/message_spec.rb
|
184
181
|
- spec/models/notification_spec.rb
|
185
|
-
- spec/models/notification_type_configuration_spec.rb
|
186
182
|
- spec/models/notification_type_spec.rb
|
187
183
|
- spec/models/notifier_spec.rb
|
188
184
|
- spec/models/user_spec.rb
|
@@ -205,9 +201,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
201
|
version: '0'
|
206
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
203
|
requirements:
|
208
|
-
- - "
|
204
|
+
- - ">"
|
209
205
|
- !ruby/object:Gem::Version
|
210
|
-
version:
|
206
|
+
version: 1.3.1
|
211
207
|
requirements: []
|
212
208
|
rubyforge_project:
|
213
209
|
rubygems_version: 2.4.8
|
@@ -273,14 +269,12 @@ test_files:
|
|
273
269
|
- spec/factories/message.rb
|
274
270
|
- spec/factories/notification.rb
|
275
271
|
- spec/factories/notification_type.rb
|
276
|
-
- spec/factories/notification_type_configuration.rb
|
277
272
|
- spec/factories/user.rb
|
278
273
|
- spec/mailers/notifications_mailer_spec.rb
|
279
274
|
- spec/models/concerns/attached_object_spec.rb
|
280
275
|
- spec/models/concerns/receiver_spec.rb
|
281
276
|
- spec/models/message_spec.rb
|
282
277
|
- spec/models/notification_spec.rb
|
283
|
-
- spec/models/notification_type_configuration_spec.rb
|
284
278
|
- spec/models/notification_type_spec.rb
|
285
279
|
- spec/models/notifier_spec.rb
|
286
280
|
- spec/models/user_spec.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class Wupee::NotificationTypeConfiguration < ActiveRecord::Base
|
2
|
-
belongs_to :receiver, polymorphic: true
|
3
|
-
belongs_to :notification_type, class_name: "Wupee::NotificationType"
|
4
|
-
|
5
|
-
validates :notification_type, uniqueness: { scope: [:receiver] }
|
6
|
-
validates :receiver, :notification_type, presence: true
|
7
|
-
|
8
|
-
enum value: { both: 0, nothing: 1, email: 2, notification: 3 }
|
9
|
-
|
10
|
-
def wants_email?
|
11
|
-
['both', 'email'].include?(value)
|
12
|
-
end
|
13
|
-
|
14
|
-
def wants_notification?
|
15
|
-
['both', 'notification'].include?(value)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class CreateWupeeNotificationTypeConfigurations < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :wupee_notification_type_configurations do |t|
|
4
|
-
t.belongs_to :notification_type
|
5
|
-
t.belongs_to :receiver, polymorphic: true
|
6
|
-
t.integer :value, default: 0
|
7
|
-
t.timestamps null: false
|
8
|
-
end
|
9
|
-
|
10
|
-
add_foreign_key :wupee_notification_type_configurations, :wupee_notification_types, column: :notification_type_id
|
11
|
-
add_index :wupee_notification_type_configurations, [:notification_type_id], name: "idx_wupee_notif_type_config_on_notification_type_id"
|
12
|
-
add_index :wupee_notification_type_configurations, [:receiver_type, :receiver_id], name: "idx_wupee_notif_typ_config_on_receiver_type_and_receiver_id"
|
13
|
-
end
|
14
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe Wupee::NotificationTypeConfiguration, type: :model do
|
4
|
-
let!(:receiver) { create :user }
|
5
|
-
let!(:notification_type) { create :notification_type }
|
6
|
-
|
7
|
-
context "validations" do
|
8
|
-
it "validates presence of receiver" do
|
9
|
-
notification_type_conf = Wupee::NotificationTypeConfiguration.new
|
10
|
-
notification_type_conf.valid?
|
11
|
-
expect(notification_type_conf.errors).to have_key :receiver
|
12
|
-
end
|
13
|
-
|
14
|
-
it "validates presence of notification_type" do
|
15
|
-
notification_type_conf = Wupee::NotificationTypeConfiguration.new
|
16
|
-
notification_type_conf.valid?
|
17
|
-
expect(notification_type_conf.errors).to have_key :notification_type
|
18
|
-
end
|
19
|
-
|
20
|
-
it "validates uniqueness of [receiver, notification_type]" do
|
21
|
-
notification_type_conf_same = Wupee::NotificationTypeConfiguration.create(receiver: receiver, notification_type: notification_type)
|
22
|
-
expect(notification_type_conf_same).to be_invalid
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "methods" do
|
27
|
-
it "has method wants_email?" do
|
28
|
-
notification_type_conf = Wupee::NotificationTypeConfiguration.new(value: :both)
|
29
|
-
expect(notification_type_conf.wants_email?).to eq true
|
30
|
-
|
31
|
-
notification_type_conf = Wupee::NotificationTypeConfiguration.new(value: :email)
|
32
|
-
expect(notification_type_conf.wants_email?).to eq true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "has method wants_notification?" do
|
36
|
-
notification_type_conf = Wupee::NotificationTypeConfiguration.new(value: :both)
|
37
|
-
expect(notification_type_conf.wants_notification?).to eq true
|
38
|
-
|
39
|
-
notification_type_conf = Wupee::NotificationTypeConfiguration.new(value: :notification)
|
40
|
-
expect(notification_type_conf.wants_notification?).to eq true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|