eventifier 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/eventifier/notifications_controller.rb +4 -4
- data/app/models/eventifier/event.rb +4 -2
- data/app/models/eventifier/notification.rb +5 -1
- data/app/models/eventifier/notification_setting.rb +2 -0
- data/db/migrate/1_eventifier_setup.rb +7 -7
- data/db/migrate/2_eventifier_notification_settings.rb +2 -2
- data/db/migrate/3_notification_sent_status.rb +5 -5
- data/db/migrate/4_event_groupable.rb +6 -6
- data/eventifier.gemspec +1 -1
- data/lib/eventifier.rb +8 -2
- data/lib/eventifier/delivery.rb +4 -0
- data/lib/eventifier/event_builder.rb +33 -0
- data/lib/eventifier/event_subscriber.rb +26 -32
- data/lib/eventifier/event_translator.rb +28 -0
- data/lib/eventifier/notification_translator.rb +25 -0
- data/lib/eventifier/notifier/notification_subscriber.rb +26 -16
- data/lib/eventifier/notifier/notifier.rb +13 -12
- data/lib/generators/eventifier/install/templates/event_tracking.rb +1 -3
- data/spec/eventifier_spec.rb +10 -28
- data/spec/integration/eventifier_spec.rb +23 -0
- data/spec/internal/app/models/like.rb +4 -0
- data/spec/internal/db/schema.rb +9 -3
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ddc5253dc949cf041ed9ff68c7225b234750fd4
|
4
|
+
data.tar.gz: 81a0e4e9121a62a2de35453c7a301450e28d1ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bf60d92b16aed0434bcfec3b9ab981eeec35b1b1c8c9d16595025f44124f41dc7c32ff061ac454fe768761fa5dfe27c31a5547199d80edcd3c017760c0a10e9
|
7
|
+
data.tar.gz: a025c89c3fb8f3f07a8d778de602d030bda0cb3d7f86f13261dbf06bc281418528bea49d4f6d7c4ecd1538bdbf6afd6e34c2275c9d9a395b3572dd216a78c5dd
|
@@ -12,11 +12,11 @@ class Eventifier::NotificationsController < Eventifier::ApplicationController
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def notifications
|
15
|
-
scope = current_user.notifications.order("
|
16
|
-
scope = scope.where("
|
17
|
-
scope = scope.where("
|
15
|
+
scope = current_user.notifications.order("eventifier_notifications.created_at DESC").limit(per_page)
|
16
|
+
scope = scope.where("eventifier_notifications.created_at < ?", after) if params[:after]
|
17
|
+
scope = scope.where("eventifier_notifications.created_at > ?", since) if params[:since]
|
18
18
|
scope = scope.where(
|
19
|
-
"
|
19
|
+
"eventifier_notifications.created_at > ?", current_user.notifications_last_read_at
|
20
20
|
) if params[:recent]
|
21
21
|
|
22
22
|
scope
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module Eventifier
|
2
2
|
class Event < ActiveRecord::Base
|
3
|
+
self.table_name = 'eventifier_events'
|
4
|
+
|
3
5
|
attr_accessible :user, :eventable, :verb, :change_data, :groupable
|
4
6
|
|
5
|
-
belongs_to :user
|
7
|
+
belongs_to :user, class_name: Eventifier.user_model_name
|
6
8
|
belongs_to :eventable, polymorphic: true
|
7
9
|
belongs_to :groupable, polymorphic: true
|
8
10
|
has_many :notifications, class_name: 'Eventifier::Notification',
|
@@ -19,4 +21,4 @@ module Eventifier
|
|
19
21
|
where :eventable_id => object.id, :eventable_type => object.class.name
|
20
22
|
end
|
21
23
|
end
|
22
|
-
end
|
24
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Eventifier
|
2
2
|
class Notification < ActiveRecord::Base
|
3
|
+
self.table_name = 'eventifier_notifications'
|
4
|
+
|
3
5
|
attr_accessible :event, :user, :relations, :event_id, :user_id
|
4
6
|
|
5
7
|
belongs_to :event, :class_name => 'Eventifier::Event'
|
@@ -14,7 +16,9 @@ module Eventifier
|
|
14
16
|
scope :for_events, -> ids { where(event_id: ids) }
|
15
17
|
scope :for_user, -> user { where(user_id: user.id) }
|
16
18
|
scope :since, -> date { where("created_at > ?", date) }
|
17
|
-
scope :latest,
|
19
|
+
scope :latest, -> {
|
20
|
+
order('eventifier_notifications.created_at DESC').limit(5)
|
21
|
+
}
|
18
22
|
scope :unsent, -> { where(sent: false) }
|
19
23
|
|
20
24
|
def self.expire_for_past_events!(time_limit = 1.day.ago)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class EventifierSetup < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :eventifier_events do |t|
|
4
4
|
t.integer :user_id
|
5
5
|
t.string :eventable_type
|
6
6
|
t.integer :eventable_id
|
@@ -10,19 +10,19 @@ class EventifierSetup < ActiveRecord::Migration
|
|
10
10
|
t.timestamps
|
11
11
|
end
|
12
12
|
|
13
|
-
add_index :
|
14
|
-
add_index :
|
13
|
+
add_index :eventifier_events, :user_id
|
14
|
+
add_index :eventifier_events, [:eventable_id, :eventable_type]
|
15
15
|
|
16
|
-
create_table :
|
16
|
+
create_table :eventifier_notifications do |t|
|
17
17
|
t.integer :event_id
|
18
18
|
t.integer :user_id
|
19
19
|
t.integer :parent_id
|
20
20
|
|
21
21
|
t.timestamps
|
22
22
|
end
|
23
|
-
add_index :
|
24
|
-
add_index :
|
25
|
-
add_index :
|
23
|
+
add_index :eventifier_notifications, :event_id
|
24
|
+
add_index :eventifier_notifications, :user_id
|
25
|
+
add_index :eventifier_notifications, :parent_id
|
26
26
|
|
27
27
|
add_column :users, :notifications_last_read_at, :datetime
|
28
28
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class EventifierNotificationSettings < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :eventifier_notification_settings do |t|
|
4
4
|
t.integer :user_id, :null => false
|
5
5
|
t.text :preferences, :null => false, :default => '{}'
|
6
6
|
t.timestamps
|
7
7
|
end
|
8
8
|
|
9
|
-
add_index :
|
9
|
+
add_index :eventifier_notification_settings, :user_id, :unique => true
|
10
10
|
end
|
11
11
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
class NotificationSentStatus < ActiveRecord::Migration
|
2
2
|
def up
|
3
|
-
add_column :
|
4
|
-
add_column :
|
5
|
-
add_index :
|
3
|
+
add_column :eventifier_notifications, :sent, :boolean, default: false
|
4
|
+
add_column :eventifier_notifications, :relations, :text, default: '[]'
|
5
|
+
add_index :eventifier_notifications, :sent
|
6
6
|
|
7
7
|
Eventifier::Notification.reset_column_information
|
8
8
|
Eventifier::Notification.update_all :sent => true
|
9
9
|
end
|
10
10
|
|
11
11
|
def down
|
12
|
-
remove_column :
|
13
|
-
remove_column :
|
12
|
+
remove_column :eventifier_notifications, :sent
|
13
|
+
remove_column :eventifier_notifications, :relations
|
14
14
|
end
|
15
15
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
class EventGroupable < ActiveRecord::Migration
|
2
2
|
def up
|
3
|
-
add_column :
|
4
|
-
add_column :
|
3
|
+
add_column :eventifier_events, :groupable_id, :integer
|
4
|
+
add_column :eventifier_events, :groupable_type, :string
|
5
5
|
|
6
6
|
Eventifier::Event.reset_column_information
|
7
7
|
Eventifier::Event.update_all(
|
8
8
|
'groupable_id = eventable_id, groupable_type = eventable_type'
|
9
9
|
)
|
10
10
|
|
11
|
-
change_column :
|
12
|
-
change_column :
|
11
|
+
change_column :eventifier_events, :groupable_id, :integer, :null => false
|
12
|
+
change_column :eventifier_events, :groupable_type, :string, :null => false
|
13
13
|
end
|
14
14
|
|
15
15
|
def down
|
16
|
-
remove_column :
|
17
|
-
remove_column :
|
16
|
+
remove_column :eventifier_events, :groupable_id
|
17
|
+
remove_column :eventifier_events, :groupable_type
|
18
18
|
end
|
19
19
|
end
|
data/eventifier.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = "eventifier"
|
4
|
-
s.version = '0.0.
|
4
|
+
s.version = '0.0.14'
|
5
5
|
s.authors = ["Nathan Sampimon", "Peter Murray", "Pat Allan"]
|
6
6
|
s.email = ["nathan@inspire9.com"]
|
7
7
|
s.homepage = "http://github.com/inspire9/eventifier"
|
data/lib/eventifier.rb
CHANGED
@@ -24,6 +24,9 @@ module Eventifier
|
|
24
24
|
mattr_accessor :mailer_name
|
25
25
|
self.mailer_name = "::Eventifier::Mailer"
|
26
26
|
|
27
|
+
mattr_accessor :user_model_name
|
28
|
+
self.user_model_name = 'User'
|
29
|
+
|
27
30
|
def self.setup
|
28
31
|
yield self
|
29
32
|
end
|
@@ -56,13 +59,16 @@ module Eventifier
|
|
56
59
|
end
|
57
60
|
|
58
61
|
|
59
|
-
require 'eventifier/tracker'
|
60
62
|
require 'eventifier/delivery'
|
61
63
|
require 'eventifier/event_tracking'
|
62
|
-
require 'eventifier/
|
64
|
+
require 'eventifier/event_builder'
|
65
|
+
require 'eventifier/event_translator'
|
63
66
|
require 'eventifier/event_subscriber'
|
67
|
+
require 'eventifier/notification_translator'
|
64
68
|
require 'eventifier/preferences'
|
65
69
|
require 'eventifier/relationship'
|
70
|
+
require 'eventifier/trackable_class'
|
71
|
+
require 'eventifier/tracker'
|
66
72
|
|
67
73
|
require 'eventifier/notifier/notification_mapping'
|
68
74
|
require 'eventifier/notifier/notification_subscriber'
|
data/lib/eventifier/delivery.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Eventifier::EventBuilder
|
2
|
+
def self.store(object, user, verb, groupable = nil, options = {})
|
3
|
+
new(object, user, verb, groupable || object, options).store
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(object, user, verb, groupable, options)
|
7
|
+
@object, @user, @verb, @groupable, @options = object, user, verb,
|
8
|
+
groupable, options
|
9
|
+
end
|
10
|
+
|
11
|
+
def store
|
12
|
+
Eventifier::Event.create user: user, eventable: object,
|
13
|
+
groupable: groupable, verb: verb, change_data: change_data
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :object, :user, :verb, :groupable, :options
|
19
|
+
|
20
|
+
def change_data
|
21
|
+
changes = object.changes.stringify_keys
|
22
|
+
|
23
|
+
changes.reject! { |attribute, value|
|
24
|
+
options[:except].include?(attribute)
|
25
|
+
} if options[:except]
|
26
|
+
|
27
|
+
changes.select! { |attribute, value|
|
28
|
+
options[:only].include?(attribute)
|
29
|
+
} if options[:only]
|
30
|
+
|
31
|
+
changes.symbolize_keys
|
32
|
+
end
|
33
|
+
end
|
@@ -1,44 +1,38 @@
|
|
1
1
|
class Eventifier::EventSubscriber
|
2
|
-
def self.subscribe_to_all
|
2
|
+
def self.subscribe_to_all(klass, names)
|
3
3
|
names.each do |method_name|
|
4
|
-
new
|
4
|
+
new(klass, method_name).subscribe_to_method
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
groupable = event.payload[:object]
|
21
|
-
groupable = Eventifier::Relationship.new(groupable, event.payload[:group_by]).users.first if event.payload[:group_by]
|
22
|
-
|
23
|
-
eventifier_event = Eventifier::Event.create(
|
24
|
-
user: event_user,
|
25
|
-
eventable: event.payload[:object],
|
26
|
-
groupable: groupable,
|
27
|
-
verb: event.payload[:event],
|
28
|
-
change_data: change_data(event.payload[:object], event.payload[:options])
|
29
|
-
)
|
30
|
-
|
31
|
-
ActiveSupport::Notifications.instrument("#{method_name}.#{klass.name.tableize}.notification.eventifier", verb: :create, event: eventifier_event, object: event.payload[:object])
|
8
|
+
def initialize(klass, method_name)
|
9
|
+
@klass, @method_name = klass, method_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def subscribe_to_method
|
13
|
+
return if notifications.notifier.listening?(name)
|
14
|
+
|
15
|
+
notifications.subscribe(name) do |*args|
|
16
|
+
event = EventTranslator.new(*args).translate
|
17
|
+
|
18
|
+
notifications.instrument "#{prefix}.notification.eventifier",
|
19
|
+
verb: :create, event: event, object: event.eventable
|
32
20
|
end
|
33
21
|
end
|
34
22
|
|
35
23
|
private
|
36
|
-
def change_data object, options
|
37
|
-
change_data = object.changes.stringify_keys
|
38
24
|
|
39
|
-
|
40
|
-
|
25
|
+
attr_reader :klass, :method_name
|
26
|
+
|
27
|
+
def name
|
28
|
+
"#{prefix}.event.eventifier"
|
29
|
+
end
|
30
|
+
|
31
|
+
def notifications
|
32
|
+
ActiveSupport::Notifications
|
33
|
+
end
|
41
34
|
|
42
|
-
|
35
|
+
def prefix
|
36
|
+
"#{method_name}.#{klass.name.tableize}"
|
43
37
|
end
|
44
|
-
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class EventTranslator
|
2
|
+
def initialize(*args)
|
3
|
+
@event = ActiveSupport::Notifications::Event.new *args
|
4
|
+
end
|
5
|
+
|
6
|
+
def translate
|
7
|
+
Eventifier::EventBuilder.store payload[:object], user, payload[:event],
|
8
|
+
groupable, payload[:options]
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
attr_reader :event
|
14
|
+
|
15
|
+
delegate :payload, to: :event
|
16
|
+
|
17
|
+
def groupable
|
18
|
+
payload[:group_by] ? relationship(payload[:group_by]) : payload[:object]
|
19
|
+
end
|
20
|
+
|
21
|
+
def relationship(key)
|
22
|
+
Eventifier::Relationship.new(payload[:object], key).users.first
|
23
|
+
end
|
24
|
+
|
25
|
+
def user
|
26
|
+
payload[:user] ? relationship(payload[:user]) : payload[:object].user
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Eventifier::NotificationTranslator
|
2
|
+
def initialize(prefix, delivery, *args)
|
3
|
+
@prefix, @delivery = prefix, delivery
|
4
|
+
@event = ActiveSupport::Notifications::Event.new(*args).payload[:event]
|
5
|
+
end
|
6
|
+
|
7
|
+
def translate
|
8
|
+
users_and_relations do |user, relations|
|
9
|
+
next if user == event.user
|
10
|
+
|
11
|
+
Eventifier::Notification.create event: event, user: user,
|
12
|
+
relations: relations
|
13
|
+
|
14
|
+
Eventifier::Delivery.deliver_for user if delivery == :immediate
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :event, :prefix, :delivery
|
21
|
+
|
22
|
+
def users_and_relations(&block)
|
23
|
+
Eventifier::NotificationMapping.users_and_relations event, prefix, &block
|
24
|
+
end
|
25
|
+
end
|
@@ -1,23 +1,33 @@
|
|
1
1
|
class Eventifier::NotificationSubscriber
|
2
|
-
def self.subscribe_to_method
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
return if ActiveSupport::Notifications.notifier.listening?(name)
|
2
|
+
def self.subscribe_to_method(klass, method_name, delivery)
|
3
|
+
new(klass, method_name, delivery).subscribe_to_method
|
4
|
+
end
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def initialize(klass, method_name, delivery)
|
7
|
+
@klass, @method_name, @delivery = klass, method_name, delivery
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
def subscribe_to_method
|
11
|
+
return if notifications.notifier.listening?(name)
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
user: user,
|
18
|
-
relations: relations
|
19
|
-
)
|
20
|
-
end
|
13
|
+
notifications.subscribe(name) do |*args|
|
14
|
+
Eventifier::NotificationTranslator.new(prefix, delivery, *args).translate
|
21
15
|
end
|
22
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :klass, :method_name, :delivery
|
21
|
+
|
22
|
+
def name
|
23
|
+
"#{prefix}.notification.eventifier"
|
24
|
+
end
|
25
|
+
|
26
|
+
def notifications
|
27
|
+
ActiveSupport::Notifications
|
28
|
+
end
|
29
|
+
|
30
|
+
def prefix
|
31
|
+
"#{method_name}.#{klass.name.tableize}"
|
32
|
+
end
|
23
33
|
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
class Eventifier::Notifier
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
# arguments will either be [:relation, {:on => :create}] or
|
3
|
+
# [{:relation => :second_relation, :on => :create}]
|
4
|
+
# If it's the first one, relation is the first in the array, otherwise treat
|
5
|
+
# the whole thing like a hash
|
6
|
+
def initialize(klasses, *arguments)
|
7
|
+
relation = arguments.shift if arguments.length == 2
|
8
|
+
arguments = arguments.first || {}
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
args = args.first || {}
|
10
|
+
methods = Array arguments.delete(:on)
|
11
|
+
delivery = arguments.delete(:email) || :delayed
|
9
12
|
|
10
|
-
|
11
|
-
methods = methods.kind_of?(Array) ? methods : [methods]
|
12
|
-
relation ||= args
|
13
|
+
relation ||= arguments
|
13
14
|
|
14
|
-
|
15
|
+
klasses.each do |target_klass|
|
15
16
|
methods.each do |method_name|
|
16
17
|
Eventifier::NotificationMapping.add "#{method_name}.#{target_klass.name.tableize}", relation
|
17
|
-
Eventifier::NotificationSubscriber.subscribe_to_method target_klass, method_name
|
18
|
+
Eventifier::NotificationSubscriber.subscribe_to_method target_klass, method_name, delivery
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
21
|
-
end
|
22
|
+
end
|
data/spec/eventifier_spec.rb
CHANGED
@@ -1,21 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
describe Eventifier::EventTracking do
|
3
2
|
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:
|
3
|
+
describe Eventifier::EventTracking do
|
4
|
+
let(:user) { Fabricate(:user) }
|
5
|
+
let(:test_class) { Post }
|
6
|
+
let(:object) { Fabricate.build(:post) }
|
7
7
|
let(:event_tracker) { Object.new.extend(Eventifier::EventTracking) }
|
8
|
-
|
9
|
-
describe ".initialize" do
|
10
|
-
|
11
|
-
it "should start" do
|
12
|
-
event_tracker
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
8
|
+
let(:event) { double eventable: double }
|
16
9
|
|
17
10
|
describe ".events_for" do
|
18
|
-
|
19
11
|
it "should create the relation notifications for Users" do
|
20
12
|
event_tracker.events_for test_class,
|
21
13
|
:track_on => [:create, :update, :destroy],
|
@@ -23,16 +15,11 @@ describe Eventifier::EventTracking do
|
|
23
15
|
|
24
16
|
user.should respond_to(:notifications)
|
25
17
|
end
|
26
|
-
|
27
18
|
end
|
28
19
|
|
29
20
|
describe "hash syntax" do
|
30
|
-
|
31
21
|
describe "creating events" do
|
32
|
-
|
33
|
-
let(:subject) do
|
34
|
-
object.save
|
35
|
-
end
|
22
|
+
let(:subject) { object.save }
|
36
23
|
|
37
24
|
before do
|
38
25
|
object.stub(:user).and_return(user)
|
@@ -41,25 +28,20 @@ describe Eventifier::EventTracking do
|
|
41
28
|
:attributes => { :except => %w(updated_at) }
|
42
29
|
end
|
43
30
|
|
44
|
-
|
45
31
|
it "should create an event with the relevant info" do
|
46
32
|
changes = { :foo => 'bar', :bar => 'baz' }
|
47
33
|
object.stub(:changes).and_return(changes)
|
48
34
|
|
49
|
-
Eventifier::Event.should_receive(:create).with(:user => user, :eventable => object, :verb => :create, :change_data => changes, :groupable => object)
|
35
|
+
Eventifier::Event.should_receive(:create).with(:user => user, :eventable => object, :verb => :create, :change_data => changes, :groupable => object).and_return(event)
|
50
36
|
|
51
37
|
subject
|
52
38
|
end
|
53
39
|
end
|
54
|
-
|
55
40
|
end
|
56
41
|
|
57
42
|
context "block syntax" do
|
58
|
-
|
59
43
|
context "tracking" do
|
60
|
-
let(:subject)
|
61
|
-
object.save
|
62
|
-
end
|
44
|
+
let(:subject) { object.save }
|
63
45
|
|
64
46
|
before do
|
65
47
|
object.stub(:user).and_return(user)
|
@@ -73,7 +55,7 @@ describe Eventifier::EventTracking do
|
|
73
55
|
track_on :update, :attributes => { :except => %w(updated_at) }
|
74
56
|
end
|
75
57
|
|
76
|
-
Eventifier::Event.should_receive(:create).with(:user => user, :eventable => object, :verb => :create, :change_data => changes, :groupable => object)
|
58
|
+
Eventifier::Event.should_receive(:create).with(:user => user, :eventable => object, :verb => :create, :change_data => changes, :groupable => object).and_return(event)
|
77
59
|
|
78
60
|
subject
|
79
61
|
end
|
@@ -130,4 +112,4 @@ describe Eventifier::EventTracking do
|
|
130
112
|
end
|
131
113
|
|
132
114
|
end
|
133
|
-
end
|
115
|
+
end
|
@@ -149,3 +149,26 @@ describe 'event tracking' do
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
152
|
+
|
153
|
+
describe 'immediate email delivery' do
|
154
|
+
let(:author) { Fabricate :user }
|
155
|
+
let(:post) { Fabricate :post, author: author }
|
156
|
+
|
157
|
+
before do
|
158
|
+
ActionMailer::Base.deliveries.clear
|
159
|
+
|
160
|
+
Object.new.extend(Eventifier::EventTracking).events_for Like do
|
161
|
+
track_on [:create]
|
162
|
+
notify likeable: :user, on: [:create], email: :immediate
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "emails the readers with a notification automatically" do
|
167
|
+
Like.create! user: Fabricate(:user), likeable: post
|
168
|
+
|
169
|
+
ActionMailer::Base.deliveries.detect { |email|
|
170
|
+
email.to == [author.email] &&
|
171
|
+
email.subject == 'You have received notifications'
|
172
|
+
}.should be_present
|
173
|
+
end
|
174
|
+
end
|
data/spec/internal/db/schema.rb
CHANGED
@@ -12,9 +12,10 @@ ActiveRecord::Schema.define do
|
|
12
12
|
t.timestamps
|
13
13
|
end
|
14
14
|
|
15
|
-
create_table :
|
16
|
-
t.
|
17
|
-
t.
|
15
|
+
create_table :likes, :force => true do |t|
|
16
|
+
t.integer :user_id
|
17
|
+
t.string :likeable_type
|
18
|
+
t.integer :likeable_id
|
18
19
|
end
|
19
20
|
|
20
21
|
create_table :posts, :force => true do |t|
|
@@ -28,4 +29,9 @@ ActiveRecord::Schema.define do
|
|
28
29
|
t.column :user_id, :integer
|
29
30
|
t.column :post_id, :integer
|
30
31
|
end
|
32
|
+
|
33
|
+
create_table :users, :force => true do |t|
|
34
|
+
t.column :name, :string
|
35
|
+
t.column :email, :string
|
36
|
+
end
|
31
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Sampimon
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -225,10 +225,13 @@ files:
|
|
225
225
|
- lib/eventifier.rb
|
226
226
|
- lib/eventifier/delivery.rb
|
227
227
|
- lib/eventifier/engine.rb
|
228
|
+
- lib/eventifier/event_builder.rb
|
228
229
|
- lib/eventifier/event_subscriber.rb
|
229
230
|
- lib/eventifier/event_tracking.rb
|
231
|
+
- lib/eventifier/event_translator.rb
|
230
232
|
- lib/eventifier/mailers/helpers.rb
|
231
233
|
- lib/eventifier/matchers.rb
|
234
|
+
- lib/eventifier/notification_translator.rb
|
232
235
|
- lib/eventifier/notifier/notification_mapping.rb
|
233
236
|
- lib/eventifier/notifier/notification_subscriber.rb
|
234
237
|
- lib/eventifier/notifier/notifier.rb
|
@@ -255,6 +258,7 @@ files:
|
|
255
258
|
- spec/internal/app/controllers/application_controller.rb
|
256
259
|
- spec/internal/app/lib/event_tracking.rb
|
257
260
|
- spec/internal/app/models/category.rb
|
261
|
+
- spec/internal/app/models/like.rb
|
258
262
|
- spec/internal/app/models/post.rb
|
259
263
|
- spec/internal/app/models/subscription.rb
|
260
264
|
- spec/internal/app/models/user.rb
|
@@ -313,6 +317,7 @@ test_files:
|
|
313
317
|
- spec/internal/app/controllers/application_controller.rb
|
314
318
|
- spec/internal/app/lib/event_tracking.rb
|
315
319
|
- spec/internal/app/models/category.rb
|
320
|
+
- spec/internal/app/models/like.rb
|
316
321
|
- spec/internal/app/models/post.rb
|
317
322
|
- spec/internal/app/models/subscription.rb
|
318
323
|
- spec/internal/app/models/user.rb
|