eventifier 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +7 -8
  4. data/Gemfile +1 -1
  5. data/README.textile +44 -3
  6. data/app/assets/images/eventifier/notifications-bell.png +0 -0
  7. data/app/assets/images/eventifier/notifications-tower.png +0 -0
  8. data/app/assets/javascripts/eventifier/notifications.coffee +196 -0
  9. data/app/assets/javascripts/eventifier/templates/dropdown.hamlc +10 -0
  10. data/app/assets/javascripts/eventifier/templates/settings.hamlc +11 -0
  11. data/app/assets/stylesheets/eventifier/notifications.scss +167 -0
  12. data/app/controllers/eventifier/application_controller.rb +4 -0
  13. data/app/controllers/eventifier/notifications_controller.rb +36 -0
  14. data/app/controllers/eventifier/preferences_controller.rb +19 -0
  15. data/app/helpers/eventifier/notification_helper.rb +87 -0
  16. data/app/helpers/eventifier/path_helper.rb +15 -0
  17. data/app/mailers/eventifier/mailer.rb +12 -0
  18. data/app/models/event_tracking.rb +3 -0
  19. data/app/models/eventifier/event.rb +22 -0
  20. data/app/models/eventifier/ghost.rb +21 -0
  21. data/app/models/eventifier/notification.rb +38 -0
  22. data/app/models/eventifier/notification_setting.rb +14 -0
  23. data/app/views/eventifier/_notification.haml +1 -0
  24. data/app/views/eventifier/email/_notification.haml +2 -0
  25. data/app/views/eventifier/mailer/notifications.haml +5 -0
  26. data/app/views/eventifier/notifications/index.jbuilder +6 -0
  27. data/config/routes.rb +7 -0
  28. data/config.ru +7 -0
  29. data/{lib/generators/eventifier/install/templates/migration.rb → db/migrate/1_eventifier_setup.rb} +2 -3
  30. data/db/migrate/2_eventifier_notification_settings.rb +11 -0
  31. data/db/migrate/3_notification_sent_status.rb +15 -0
  32. data/db/migrate/4_event_groupable.rb +19 -0
  33. data/eventifier.gemspec +12 -15
  34. data/lib/eventifier/delivery.rb +59 -0
  35. data/lib/eventifier/{railtie.rb → engine.rb} +4 -2
  36. data/lib/eventifier/event_subscriber.rb +44 -0
  37. data/lib/eventifier/event_tracking.rb +5 -58
  38. data/lib/eventifier/mailers/helpers.rb +70 -0
  39. data/lib/eventifier/notifier/notification_mapping.rb +34 -0
  40. data/lib/eventifier/notifier/notification_subscriber.rb +23 -0
  41. data/lib/eventifier/notifier/notifier.rb +21 -0
  42. data/lib/eventifier/preferences.rb +44 -0
  43. data/lib/eventifier/relationship.rb +36 -0
  44. data/lib/eventifier/trackable_class.rb +74 -0
  45. data/lib/eventifier/tracker.rb +18 -0
  46. data/lib/eventifier.rb +35 -11
  47. data/lib/generators/eventifier/install/install_generator.rb +2 -5
  48. data/lib/generators/eventifier/install/templates/events.en.yaml +1 -0
  49. data/lib/tasks/email.rake +8 -0
  50. data/spec/controllers/eventifier/notifications_controller_spec.rb +24 -0
  51. data/spec/controllers/eventifier/preferences_controller_spec.rb +56 -0
  52. data/spec/eventifier/delivery_spec.rb +110 -0
  53. data/spec/eventifier/preferences_spec.rb +69 -0
  54. data/spec/eventifier/relationship_spec.rb +33 -0
  55. data/spec/eventifier_spec.rb +6 -48
  56. data/spec/fabricators/fabricator.rb +11 -11
  57. data/spec/helpers/eventifier/notification_helper_spec.rb +169 -0
  58. data/spec/helpers/eventifier/path_helper_spec.rb +19 -0
  59. data/spec/integration/eventifier_spec.rb +113 -70
  60. data/spec/integration/internationalisation_spec.rb +39 -0
  61. data/spec/internal/app/controllers/application_controller.rb +3 -0
  62. data/spec/internal/app/lib/event_tracking.rb +12 -0
  63. data/spec/internal/app/models/category.rb +3 -0
  64. data/spec/internal/app/models/post.rb +8 -0
  65. data/spec/internal/app/models/subscription.rb +4 -0
  66. data/spec/internal/app/models/user.rb +4 -0
  67. data/spec/internal/app/views/eventifier/dropdown/_awesome_object.haml +0 -0
  68. data/spec/internal/config/database.yml +4 -0
  69. data/spec/internal/config/initializers/eventifier.rb +1 -0
  70. data/spec/internal/config/locales/events.en.yml +20 -0
  71. data/spec/internal/config/routes.rb +5 -0
  72. data/spec/internal/db/schema.rb +31 -0
  73. data/spec/internal/log/.gitignore +1 -0
  74. data/spec/internal/public/favicon.ico +0 -0
  75. data/spec/models/eventifier/event_spec.rb +23 -0
  76. data/spec/{ghost_spec.rb → models/eventifier/ghost_spec.rb} +3 -3
  77. data/spec/{notification_spec.rb → models/eventifier/notification_spec.rb} +1 -9
  78. data/spec/notification_mailer_spec.rb +8 -4
  79. data/spec/notifier/notification_mapping_spec.rb +28 -0
  80. data/spec/spec_helper.rb +14 -8
  81. data/spec/support/controller_helpers.rb +14 -0
  82. metadata +205 -128
  83. data/Gemfile.lock +0 -97
  84. data/lib/eventifier/active_record/event.rb +0 -10
  85. data/lib/eventifier/active_record/event_observer.rb +0 -8
  86. data/lib/eventifier/active_record/event_tracking.rb +0 -11
  87. data/lib/eventifier/active_record/ghost.rb +0 -9
  88. data/lib/eventifier/active_record/notification.rb +0 -13
  89. data/lib/eventifier/active_record_support.rb +0 -5
  90. data/lib/eventifier/event_helper.rb +0 -40
  91. data/lib/eventifier/event_mixin.rb +0 -45
  92. data/lib/eventifier/event_observer_mixin.rb +0 -44
  93. data/lib/eventifier/ghost_mixin.rb +0 -27
  94. data/lib/eventifier/helper_methods.rb +0 -36
  95. data/lib/eventifier/mongoid/event.rb +0 -16
  96. data/lib/eventifier/mongoid/event_observer.rb +0 -7
  97. data/lib/eventifier/mongoid/event_tracking.rb +0 -13
  98. data/lib/eventifier/mongoid/ghost.rb +0 -15
  99. data/lib/eventifier/mongoid/notification.rb +0 -19
  100. data/lib/eventifier/mongoid/user_patch.rb +0 -3
  101. data/lib/eventifier/mongoid_support.rb +0 -6
  102. data/lib/eventifier/notification_helper.rb +0 -42
  103. data/lib/eventifier/notification_mailer.rb +0 -18
  104. data/lib/eventifier/notification_mixin.rb +0 -50
  105. data/lib/eventifier/version.rb +0 -3
  106. data/spec/event_helper_spec.rb +0 -67
  107. data/spec/event_observer_spec.rb +0 -20
  108. data/spec/event_spec.rb +0 -39
  109. data/spec/helper_methods_spec.rb +0 -36
  110. data/spec/notification_helper_spec.rb +0 -65
  111. data/spec/support/action_mailer.rb +0 -3
  112. data/spec/support/database_cleaner.rb +0 -3
  113. data/spec/test_classes/active_record_support.rb +0 -72
  114. data/spec/test_classes/mongoid_support.rb +0 -34
@@ -1,13 +0,0 @@
1
- require 'eventifier/notification_mixin'
2
-
3
- module Eventifier
4
- class Notification < ActiveRecord::Base
5
- include Eventifier::NotificationMixin
6
-
7
- default_scope order("notifications.created_at DESC")
8
- scope :for_events, -> ids { where(event_id: ids) }
9
- scope :for_user, -> user { where(user_id: user.id) }
10
- scope :since, -> date { where("created_at > ?", date) }
11
- scope :latest, order('notifications.created_at DESC').limit(5)
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- require 'eventifier/active_record/event_tracking'
2
- require 'eventifier/active_record/event'
3
- require 'eventifier/active_record/notification'
4
- require 'eventifier/active_record/event_observer'
5
- require 'eventifier/active_record/ghost'
@@ -1,40 +0,0 @@
1
- module Eventifier
2
- module EventHelper
3
- include Eventifier::HelperMethods
4
-
5
- # A helper for outputting an event message.
6
- #
7
- # Uses I18n messages from config/locales/events.en.yml to generate these messages, or defaults to a standard.
8
- #
9
- # Example:
10
- #
11
- # %ul#events
12
- # - post.events.each do |event|
13
- # %li= event_message event
14
-
15
- def event_message event
16
- if event.verb.to_sym == :update
17
- if event.change_data.keys.count == 1
18
- key = "events.#{event.eventable_type.downcase}.#{event.verb}.single"
19
- else
20
- key = "events.#{event.eventable_type.downcase}.#{event.verb}.multiple"
21
- end
22
- else
23
- key = "events.#{event.eventable_type.downcase}.#{event.verb}"
24
- end
25
- message = I18n.translate key, :default => :"events.default.#{event.verb}", "user.name" => event.user.name, :"event.type" => event.eventable_type
26
-
27
- replace_vars(message, event).html_safe
28
- end
29
-
30
- def self.included(base)
31
- base.helper_method :event_message
32
- end
33
- end
34
- end
35
-
36
- if defined? ActionController::Base
37
- ActionController::Base.class_eval do
38
- include Eventifier::EventHelper
39
- end
40
- end
@@ -1,45 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- module Eventifier
4
- module EventMixin
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- belongs_to :user
10
- belongs_to :eventable, polymorphic: true
11
- has_many :notifications, class_name: 'Eventifier::Notification', dependent: :destroy
12
-
13
- validates :user, presence: true
14
- validates :eventable, presence: true
15
- validates :verb, presence: true
16
- end
17
-
18
- module ClassMethods
19
-
20
- def add_notification(*arg)
21
- observer_instances.each { |observer| observer.add_notification(*arg) }
22
- end
23
-
24
- def add_url(*arg)
25
- observer_instances.each { |observer| observer.add_url(*arg) }
26
- end
27
-
28
- def create_event(verb, object, options = { })
29
- changed_data = object.changes.stringify_keys
30
- changed_data = changed_data.reject { |attribute, value| options[:except].include?(attribute) } if options[:except]
31
- changed_data = changed_data.select { |attribute, value| options[:only].include?(attribute) } if options[:only]
32
- self.create(
33
- :user => object.user,
34
- :eventable => object,
35
- :verb => verb,
36
- :change_data => changed_data.symbolize_keys
37
- )
38
- end
39
-
40
- def find_all_by_eventable object
41
- where :eventable_id => object.id, :eventable_type => object.class.name
42
- end
43
- end
44
- end
45
- end
@@ -1,44 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- module Eventifier
4
- module EventObserverMixin
5
- extend ActiveSupport::Concern
6
-
7
- include do
8
- observe Eventifier::Event
9
- end
10
-
11
- module InstanceMethods
12
- def add_notification klass_name, relation, method
13
- observed_classes.each do |observed_class|
14
- notification_mappings[klass_name.name] ||= { }
15
- notification_mappings[klass_name.name][method] = relation
16
- end
17
- end
18
-
19
- def after_create event
20
- Rails.logger.info "Firing #{event.eventable_type}##{event.verb} - #{notification_mappings[event.eventable_type][event.verb]}" if notification_mappings.has_key?(event.eventable_type) and notification_mappings[event.eventable_type].has_key?(event.verb) and defined?(Rails)
21
-
22
- method_from_relation(event.eventable, notification_mappings[event.eventable_type][event.verb]).each do |user|
23
- next if user == event.user
24
- Eventifier::Notification.create event: event, user: user
25
- end if notification_mappings.has_key?(event.eventable_type) and notification_mappings[event.eventable_type].has_key?(event.verb)
26
- end
27
-
28
- def method_from_relation object, relation
29
- if relation.kind_of?(Hash)
30
- method_from_relation(proc { |object, method| object.send(method) }.call(object, relation.keys.first), relation.values.first)
31
- else
32
- send_to = proc { |object, method| object.send(method) }.call(object, relation)
33
- send_to = send_to.kind_of?(Array) ? send_to : [send_to]
34
- end
35
- end
36
-
37
- private
38
-
39
- def notification_mappings
40
- @notification_mapppings ||= { }
41
- end
42
- end
43
- end
44
- end
@@ -1,27 +0,0 @@
1
- module Eventifier
2
- module GhostMixin
3
-
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
-
8
- validates :ghost_class, :presence => true
9
- validates :ghost_id, :presence => true
10
- validates :data_hash, :presence => true
11
- end
12
-
13
- module ClassMethods
14
- def create_from_object object
15
- create :ghost_class => object.class.name, :ghost_id => object.id, :data_hash => object.serializable_hash
16
- end
17
- end
18
-
19
- def ghost
20
- klass = Object.const_get(ghost_class)
21
- ghost_object = klass.new data_hash
22
- ghost_object.id = ghost_id
23
-
24
- ghost_object
25
- end
26
- end
27
- end
@@ -1,36 +0,0 @@
1
- module Eventifier
2
- module HelperMethods
3
- # Used to replace {{variables}} in I18n messages
4
-
5
- def replace_vars message, event
6
- event = load_event_for_template event
7
- message.scan(/{{[^}]*}}/) do |replaceable|
8
- method = "event."+replaceable.to_s.gsub(/[{|}]/, '').to_s
9
- replace_text = eval(method) rescue ""
10
-
11
- case replaceable.to_s
12
- when "{{object.name}}"
13
- replace_text = "<strong class='target'>#{replace_text}</strong>"
14
- when "{{object.title}}"
15
- replace_text = "<strong class='target'>#{replace_text}</strong>"
16
- when "{{user.name}}"
17
- replace_text = "<strong class='user'>#{replace_text}</strong>"
18
- else
19
- replace_text = "<strong>#{replace_text}</strong>"
20
- end
21
-
22
- message = message.gsub(replaceable.to_s, replace_text.to_s.gsub("_", " "))
23
- end
24
- message
25
- end
26
-
27
- # Make is so you can include object in the I18n descriptions and it refers to the eventable object the event is referring to.
28
-
29
- def load_event_for_template event
30
- def event.object; eventable; end
31
- def event.object_type; eventable_type; end
32
-
33
- event
34
- end
35
- end
36
- end
@@ -1,16 +0,0 @@
1
- require 'eventifier/event_mixin'
2
-
3
- module Eventifier
4
- class Event
5
- include Mongoid::Document
6
- include Mongoid::Timestamps
7
- include Eventifier::EventMixin
8
-
9
- field :change_data, :type => Hash
10
- field :eventable_type, :type => String
11
- field :verb, :type => Symbol
12
-
13
- index({ user_id: 1 })
14
- index({ eventable_id: 1, eventable_type: 1 })
15
- end
16
- end
@@ -1,7 +0,0 @@
1
- require 'eventifier/event_observer_mixin'
2
-
3
- module Eventifier
4
- class EventObserver < Mongoid::Observer
5
- include Eventifier::EventObserverMixin
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- module Eventifier
2
- module EventTracking
3
- OBSERVER_CLASS = Mongoid::Observer
4
-
5
- def add_notification_association target_klass
6
- target_klass.class_eval do
7
- define_method :notifications do
8
- events.map(&:notifications).flatten.compact
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- require 'eventifier/ghost_mixin'
2
-
3
- module Eventifier
4
- class Ghost
5
- include Mongoid::Document
6
- include Mongoid::Timestamps
7
- include Eventifier::GhostMixin
8
-
9
- field :ghost_id, :type => BSON::ObjectId
10
- field :ghost_class, :type => String
11
- field :data_hash, :type => Hash
12
-
13
- index({ ghost_class: 1, ghost_id: 1 })
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- require 'eventifier/notification_mixin'
2
-
3
- module Eventifier
4
- class Notification
5
- include Mongoid::Document
6
- include Mongoid::Timestamps
7
- include Eventifier::NotificationMixin
8
-
9
- default_scope order_by([:created_at, :desc])
10
- scope :for_events, ->(ids) { where(event_id: ids) }
11
- scope :for_user, ->(user) { where(user_id: user.id) }
12
- scope :since, ->(date) { where(:created_at.gt => date) }
13
- scope :latest, order_by([:created_at, :desc]).limit(5)
14
-
15
- index({ user_id: 1 })
16
- index({ event_id: 1 })
17
- #index({ parent_id: 1})
18
- end
19
- end
@@ -1,3 +0,0 @@
1
- class User
2
- field :notifications_last_read_at, :type => DateTime
3
- end
@@ -1,6 +0,0 @@
1
- require 'eventifier/mongoid/event_tracking'
2
- require 'eventifier/mongoid/user_patch'
3
- require 'eventifier/mongoid/event'
4
- require 'eventifier/mongoid/notification'
5
- require 'eventifier/mongoid/event_observer'
6
- require 'eventifier/mongoid/ghost'
@@ -1,42 +0,0 @@
1
- module Eventifier
2
- module NotificationHelper
3
- include Eventifier::HelperMethods
4
-
5
- # A helper for outputting a notification message.
6
- #
7
- # Uses I18n messages from config/locales/events.en.yml to generate these messages, or defaults to a standard.
8
- #
9
- # Example:
10
- #
11
- # %ul#recent_notifications
12
- # - current_user.notifications.each do |notification|
13
- # %li= notification_message notification.event
14
-
15
- def notification_message event
16
- default = "notifications.default.#{event.verb}".to_sym
17
- if event.verb.to_sym == :update
18
- if event.change_data.keys.count == 1
19
- key = "notifications.#{event.eventable_type.downcase}.#{event.verb}.attributes.#{event.change_data.keys.first}"
20
- default = ["notifications.#{event.eventable_type.downcase}.#{event.verb}.single".to_sym, default]
21
- else
22
- key = "notifications.#{event.eventable_type.downcase}.#{event.verb}.multiple"
23
- end
24
- else
25
- key = "notifications.#{event.eventable_type.downcase}.#{event.verb}"
26
- end
27
- message = I18n.translate key, :default => default, "user.name" => event.user.name, :"event.type" => event.eventable_type
28
-
29
- replace_vars(message, event).html_safe
30
- end
31
-
32
- def self.included(base)
33
- base.helper_method :notification_message, :notification_url
34
- end
35
- end
36
- end
37
-
38
- if defined? ActionController::Base
39
- ActionController::Base.class_eval do
40
- include Eventifier::NotificationHelper
41
- end
42
- end
@@ -1,18 +0,0 @@
1
- require 'eventifier/notification_helper'
2
-
3
- module Eventifier
4
- class NotificationMailer < ActionMailer::Base
5
- include Eventifier::NotificationHelper
6
- layout 'email'
7
-
8
- def notification_email(notification)
9
- @notification = notification
10
- @notification_url = main_app.url_for notification.url
11
- @notification_message = notification_message(notification.event)
12
-
13
- mail :to => notification.user.email,
14
- :subject => "You have new notifications"
15
-
16
- end
17
- end
18
- end
@@ -1,50 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- module Eventifier
4
-
5
- module NotificationMixin
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- belongs_to :event, :class_name => 'Eventifier::Event'
10
- belongs_to :user
11
-
12
- validates :event, :presence => true
13
- validates :user, :presence => true
14
- validates :event_id, :uniqueness => { :scope => :user_id }
15
-
16
- after_create :send_email
17
- end
18
-
19
- module ClassMethods
20
- def expire_for_past_events!(time_limit = 1.day.ago)
21
- self.for_events(Event.expired_ids(time_limit)).each &:expire!
22
- end
23
-
24
- def unread_for(user)
25
- if user.notifications_last_read_at
26
- for_user(user).since(user.notifications_last_read_at)
27
- else
28
- for_user(user)
29
- end
30
- end
31
- end
32
-
33
- def url
34
- if Eventifier::EventTracking.url_mappings[event.eventable_type.underscore.to_sym]
35
- Eventifier::EventTracking.url_mappings[event.eventable_type.underscore.to_sym].call(event.eventable)
36
- else
37
- event.eventable
38
- end
39
- end
40
-
41
- def unread_for?(user)
42
- return true if user.notifications_last_read_at.nil?
43
- created_at > user.notifications_last_read_at
44
- end
45
-
46
- def send_email
47
- Eventifier::NotificationMailer.notification_email(self).deliver
48
- end
49
- end
50
- end
@@ -1,3 +0,0 @@
1
- module Eventifier
2
- VERSION = "0.0.7"
3
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::EventHelper do
4
-
5
- class TestClass
6
- def self.helper_method(*args)
7
- end
8
-
9
- include Eventifier::EventHelper
10
- end
11
-
12
- let(:verb) { "update" }
13
- let(:change_data) { { } }
14
- let(:event) { double("Event", :verb => verb, :eventable_type => "Object", :change_data => change_data, :user => double("user", :name => "Willy")) }
15
- let!(:helper) { TestClass.new }
16
-
17
- before do
18
- helper.stub :replace_vars => double("String", :html_safe => true)
19
- end
20
-
21
- describe ".event_message" do
22
- subject { helper.event_message event }
23
-
24
- context "with event verb create" do
25
- let(:verb) { "create" }
26
-
27
- it "should hit the I18n verb definition for create & destroy" do
28
- I18n.should_receive(:translate).with("events.object.create", :default => :"events.default.create", "user.name" => "Willy", :"event.type" => "Object")
29
-
30
- subject
31
- end
32
-
33
- it "should pass the I18n translation to the replace_vars method" do
34
- I18n.should_receive(:translate).with("events.object.create", :default => :"events.default.create", "user.name" => "Willy", :"event.type" => "Object").and_return("A message")
35
- helper.should_receive(:replace_vars).with "A message", event
36
-
37
- subject
38
- end
39
- end
40
-
41
- context "with event verb update" do
42
- let(:verb) { "update" }
43
-
44
- context "multiple updates" do
45
- let(:change_data) { { :name => ["Lol", "Omg Lol"] } }
46
-
47
- it "should specify single on the verb for the I18n definition on update when there are just a single change" do
48
- I18n.should_receive(:translate).with("events.object.update.single", :default => :"events.default.update", "user.name" => "Willy", :"event.type" => "Object")
49
-
50
- subject
51
- end
52
- end
53
-
54
- context "multiple updates" do
55
- let(:change_data) { { :name => ["Lol", "Omg Lol"], :address => ["old", "new"] } }
56
-
57
- it "should specify single on the verb for the I18n definition on update when there are just a single change" do
58
- I18n.should_receive(:translate).with("events.object.update.multiple", :default => :"events.default.update", "user.name" => "Willy", :"event.type" => "Object")
59
-
60
- subject
61
- end
62
-
63
- end
64
- end
65
-
66
- end
67
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::EventObserver do
4
- subject { Eventifier::EventObserver.instance }
5
-
6
- describe "#method_from_relation" do
7
- it "should call the string as a method when passed a string" do
8
- object = double('object', :mouse => 5)
9
-
10
- subject.method_from_relation(object, :mouse).should == [5]
11
- end
12
-
13
- it "should string the methods when passed a hash" do
14
- object = double('object', :cat => (cat = double('cat', :mouse => 5)))
15
-
16
- subject.method_from_relation(object, :cat => :mouse).should == [5]
17
- end
18
- end
19
-
20
- end
data/spec/event_spec.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::Event do
4
- let(:event) { Fabricate(:event) }
5
-
6
- describe "#valid?" do
7
- pending
8
- #it_requires_a :user
9
- #it_requires_an :eventable
10
- #it_requires_a :verb
11
- end
12
-
13
- describe '.add_url' do
14
- it "should send add_url to each of it's observers with params" do
15
- url_proc = -> activity { [activity.group, activity] }
16
- observer = double('Observer')
17
- Eventifier::Event.stub :observer_instances => [observer]
18
-
19
- observer.should_receive(:add_url).with(Object, url_proc)
20
-
21
- Eventifier::Event.add_url Object, url_proc
22
- end
23
- end
24
-
25
- describe ".find_all_by_eventable" do
26
- let!(:eventable) { Fabricate(:post) }
27
- let(:event) { Fabricate(:event, :eventable => eventable) }
28
-
29
- it "should find the associated polymorphic eventable object" do
30
- lambda do
31
- Fabricate(:event, :eventable => Fabricate(:post))
32
- event
33
- end.should change(Eventifier::Event, :count).by(2)
34
-
35
- Eventifier::Event.find_all_by_eventable(eventable).length.should == 1
36
- end
37
- end
38
-
39
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::EventHelper do
4
-
5
- class TestClass
6
- def self.helper_method(*args); end
7
- include Eventifier::HelperMethods
8
- end
9
-
10
- let!(:helper) { TestClass.new }
11
-
12
- describe ".replace_vars" do
13
- let(:event) { Fabricate.build(:event)}
14
-
15
- it "should replace {{stuff}} with awesome" do
16
- message = "I'm really loving {{eventable.title}}"
17
- helper.replace_vars(message, event).should == "I'm really loving <strong>#{event.eventable.title}</strong>"
18
- end
19
-
20
- it "should replace multiple {{stuff}} with multiple awesome" do
21
- message = "I'm really loving {{eventable.title}} and all {{eventable.class.name}}s"
22
- helper.replace_vars(message, event).should == "I'm really loving <strong>#{event.eventable.title}</strong> and all <strong>Post</strong>s"
23
- end
24
- end
25
-
26
- describe ".load_event_for_template" do
27
-
28
- it "should add some handy methods to an event instance" do
29
- event = Fabricate(:event)
30
- event = helper.load_event_for_template event
31
- event.object.should == event.eventable
32
- event.object_type.should == event.eventable_type
33
- end
34
-
35
- end
36
- end
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eventifier::NotificationHelper do
4
-
5
- class TestClass
6
- def self.helper_method(*args); end
7
- include Eventifier::NotificationHelper
8
- end
9
-
10
- let!(:helper) {TestClass.new}
11
-
12
- before do
13
- @notification_strings = {
14
- :post => {
15
- :create => "{{user.name}} just created an Post - you should check it out",
16
- :destroy => "{{user.name}} just deleted an Post",
17
- :update => {
18
- :single => "{{user.name}} made a change to their Post",
19
- :multiple => "{{user.name}} made some changes to their Post",
20
- :attributes => {
21
- :deleted_at => "{{user.name}} deleted their Post"
22
- }
23
- }
24
- }
25
- }
26
- I18n.backend.store_translations :en, :notifications => @notification_strings
27
- end
28
-
29
- describe "#notification_message" do
30
- it "should return the I18n message for that event" do
31
-
32
- event = Fabricate(:event, :eventable => Fabricate(:post), :verb => :create)
33
- helper.notification_message(event).should == "<strong class='user'>#{event.user.name}</strong> just created an Post - you should check it out"
34
- end
35
-
36
- it "should return a message specific to a single change if only 1 change has been made" do
37
- event = Fabricate(:event, :eventable => Fabricate(:post), :verb => :update, :change_data => { :name => ["Fred", "Mike"] })
38
- helper.notification_message(event).should == "<strong class='user'>#{event.user.name}</strong> made a change to their Post"
39
- end
40
- it "should return a message specific to a particular field change if configuration is present" do
41
- event = Fabricate(:event, :eventable => Fabricate(:post), :verb => :update, :change_data => { :deleted_at => [nil, Time.now] })
42
- helper.notification_message(event).should == "<strong class='user'>#{event.user.name}</strong> deleted their Post"
43
- end
44
-
45
- it "should return a message specific to multiple changes if more than 1 change has been made" do
46
- event = Fabricate(:event, :eventable => Fabricate(:post), :verb => :update, :change_data => { :name => ["Fred", "Mike"], :age => [55, 65] })
47
- helper.notification_message(event).should == "<strong class='user'>#{event.user.name}</strong> made some changes to their Post"
48
- end
49
-
50
- it "should return the default I18n message if one doesn't exist" do
51
- I18n.backend.reload!
52
- @notification_strings = {
53
- :default => {
54
- :create => "{{user.name}} created a {{eventable_type}}",
55
- :update => "{{user.name}} updated a {{eventable_type}}"
56
- }
57
- }
58
- I18n.backend.store_translations :test, :notifications => @notification_strings
59
- I18n.with_locale("test") do
60
- event = Fabricate(:event, :eventable => Fabricate(:post), :verb => :create)
61
- helper.notification_message(event).should == "<strong class='user'>#{event.user.name}</strong> created a <strong>Post</strong>"
62
- end
63
- end
64
- end
65
- end
@@ -1,3 +0,0 @@
1
- require 'action_mailer'
2
-
3
- ActionMailer::Base.delivery_method = :test
@@ -1,3 +0,0 @@
1
- require 'database_cleaner'
2
- DatabaseCleaner.strategy = :truncation
3
- DatabaseCleaner.clean