eventifier 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2071b87e51e9744870630017008eab9348b7d4fe
4
- data.tar.gz: 005ab9667e45c84e6772482af80145e047d2ed0d
3
+ metadata.gz: 0b2058a8b8853d745b422702127a30d6f813782f
4
+ data.tar.gz: 15cc3e4c382f87e2fabb2e39c9491564125de1c1
5
5
  SHA512:
6
- metadata.gz: a19f718a1c2e30dfe1861c46738c171f753c71cd358a737f79f4a4e657015a4f547afe10474ea18492e79e3b8e48c909cf3a3c1e3e5fe4ea5d5f1e54e9087c7b
7
- data.tar.gz: 5aab6adecdd25f9fdd5879c240c1c7f485ea725cd068b5f74b71fb12f40929a3577ab3bbce3d59924d94cee95b562d93784c24a4cdfffe6aadfa6b0dbb056848
6
+ metadata.gz: 1c97b31eafca299de510fac186d067513d7172110217bc989b9e65fc44af6a3907cc056f39a4bda8f6b8f3ec70ec076bb11d19d809a5e1d5659e1ef78ec52054
7
+ data.tar.gz: 09fe86cdb9b773bd3bbeeec95a575a20ec99b957d534e44474c2188b87a03c0fc491ee2e7cbe070bd7b7b451fd669ba93fc8b861fb072979ad7ec4e447e944be
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
5
6
  # - jruby-19mode # JRuby in 1.9 mode
6
7
  before_script:
7
8
  - psql -c 'create database eventifier;' -U postgres
@@ -78,9 +78,10 @@ class window.NotificationDropdown
78
78
  else
79
79
  @el
80
80
  .find('ol')
81
- .prepend @lastInserted = $("<li />")
81
+ .prepend( @lastInserted = $("<li />")
82
82
  .addClass('unread')
83
83
  .html(notification.html)
84
+ )
84
85
  else
85
86
  @el
86
87
  .find('ol')
@@ -5,8 +5,9 @@ module Eventifier
5
5
  end
6
6
 
7
7
  def partial_path notification, context = nil
8
- if lookup_context.exists?(notification.event.eventable_type.underscore, [[:eventifier, context].compact.join("/")], true)
9
- [:eventifier, context, notification.event.eventable_type.underscore].compact.join("/")
8
+ eventable_path = notification.event.eventable_type.underscore.gsub('/', '_')
9
+ if lookup_context.exists?(eventable_path, [[:eventifier, context].compact.join("/")], true)
10
+ [:eventifier, context, eventable_path].compact.join("/")
10
11
  else
11
12
  [:eventifier, context, 'notification'].compact.join("/")
12
13
  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.1.1'
4
+ s.version = '0.1.2'
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"
@@ -22,8 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency 'haml_coffee_assets'
23
23
  s.add_runtime_dependency 'coffee-rails', '~> 4.0.0'
24
24
  s.add_runtime_dependency 'compass-rails'
25
- s.add_runtime_dependency 'multi_json', '~> 1.7.4'
26
- s.add_runtime_dependency 'jbuilder', '~> 2.0.4'
25
+ s.add_runtime_dependency 'multi_json', '>= 1.7.4'
26
+ s.add_runtime_dependency 'jbuilder', '>= 2.0.4'
27
27
  s.add_runtime_dependency 'rails-observers', '~> 0.1.2'
28
28
 
29
29
  s.add_development_dependency 'combustion', '~> 0.5.0'
@@ -13,10 +13,9 @@ class Eventifier::EventSubscriber
13
13
  return if notifications.notifier.listening?(name)
14
14
 
15
15
  notifications.subscribe(name) do |*args|
16
- event = EventTranslator.new(*args).translate
17
-
16
+ event = Eventifier::EventTranslator.new(*args).translate
18
17
  notifications.instrument "#{prefix}.notification.eventifier",
19
- verb: :create, event: event, object: event.eventable
18
+ verb: :create, event: event, object: event.eventable unless event.nil?
20
19
  end
21
20
  end
22
21
 
@@ -18,15 +18,15 @@ module Eventifier
18
18
  Eventifier.tracked_classes.uniq!
19
19
  end
20
20
 
21
- def track_on methods, options = {}
21
+ def track_on(methods, options = {})
22
22
  Eventifier::Tracker.new @klasses, methods, options
23
23
  end
24
24
 
25
- def notify *args
25
+ def notify(*args)
26
26
  Eventifier::Notifier.new @klasses, *args
27
27
  end
28
28
 
29
- def url url_proc
29
+ def url(url_proc)
30
30
  @klasses.each do |target_klass|
31
31
  Eventifier::EventTracking.url_mappings[target_klass.name.underscore.to_sym] = url_proc
32
32
  end
@@ -36,4 +36,4 @@ module Eventifier
36
36
  @url_mapppings ||= {}
37
37
  end
38
38
  end
39
- end
39
+ end
@@ -1,11 +1,13 @@
1
- class EventTranslator
1
+ class Eventifier::EventTranslator
2
2
  def initialize(*args)
3
3
  @event = ActiveSupport::Notifications::Event.new *args
4
4
  end
5
5
 
6
6
  def translate
7
+ return unless conditional_call
8
+
7
9
  Eventifier::EventBuilder.store payload[:object], user, payload[:event],
8
- groupable, payload[:options]
10
+ groupable, options.except(:if, :unless)
9
11
  end
10
12
 
11
13
  private
@@ -14,10 +16,28 @@ class EventTranslator
14
16
 
15
17
  delegate :payload, to: :event
16
18
 
19
+ def conditional
20
+ options[:if] || options[:unless]
21
+ end
22
+
23
+ def conditional_call
24
+ if options[:if]
25
+ conditional.call payload[:object]
26
+ elsif options[:unless]
27
+ !conditional.call payload[:object]
28
+ else
29
+ true
30
+ end
31
+ end
32
+
17
33
  def groupable
18
34
  payload[:group_by] ? relationship(payload[:group_by]) : payload[:object]
19
35
  end
20
36
 
37
+ def options
38
+ payload[:options] || {}
39
+ end
40
+
21
41
  def relationship(key)
22
42
  Eventifier::Relationship.new(payload[:object], key).users.first
23
43
  end
@@ -1,6 +1,6 @@
1
1
  module Eventifier
2
2
  class Tracker
3
- def initialize klasses, methods, options
3
+ def initialize(klasses, methods, options)
4
4
  @klasses = klasses
5
5
  methods = methods.kind_of?(Array) ? methods : [methods]
6
6
  raise 'No events defined to track' if methods.compact.empty?
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Eventifier::EventTranslator do
4
+ let(:event) { double payload: {object: eventable, event: :update,
5
+ options: {foo: :bar}} }
6
+ let(:eventable) { double 'Eventable', user: user }
7
+ let(:user) { double 'User' }
8
+ let(:relationship) { double 'Relationship', users: [group] }
9
+ let(:group) { double 'Group' }
10
+
11
+ before :each do
12
+ allow(ActiveSupport::Notifications::Event).to receive(:new).and_return event
13
+ allow(Eventifier::EventBuilder).to receive(:store).and_return(true)
14
+ allow(Eventifier::Relationship).to receive(:new).and_return(relationship)
15
+ end
16
+
17
+ describe '#translate' do
18
+ it 'builds a new event' do
19
+ expect(Eventifier::EventBuilder).to receive(:store).with(
20
+ eventable, user, :update, eventable, {foo: :bar}
21
+ )
22
+
23
+ Eventifier::EventTranslator.new.translate
24
+ end
25
+
26
+ it 'calculates the groupable object if a group_by option is provided' do
27
+ event.payload[:group_by] = :groupable
28
+
29
+ expect(Eventifier::EventBuilder).to receive(:store).with(
30
+ eventable, user, :update, group, {foo: :bar}
31
+ )
32
+
33
+ Eventifier::EventTranslator.new.translate
34
+ end
35
+
36
+ it 'finds the user via an association if provided' do
37
+ event.payload[:user] = :person
38
+
39
+ expect(Eventifier::EventBuilder).to receive(:store).with(
40
+ eventable, group, :update, eventable, {foo: :bar}
41
+ )
42
+
43
+ Eventifier::EventTranslator.new.translate
44
+ end
45
+
46
+ it "creates an event when :if is set and returns true" do
47
+ event.payload[:options][:if] = Proc.new { |object| true }
48
+
49
+ expect(Eventifier::EventBuilder).to receive(:store).with(
50
+ eventable, user, :update, eventable, {foo: :bar}
51
+ )
52
+
53
+ Eventifier::EventTranslator.new.translate
54
+ end
55
+
56
+ it "does not create an event when :if is set and returns false" do
57
+ event.payload[:options][:if] = Proc.new { |object| false }
58
+
59
+ expect(Eventifier::EventBuilder).to_not receive(:store)
60
+
61
+ Eventifier::EventTranslator.new.translate
62
+ end
63
+
64
+ it "creates an event when :unless is set and returns false" do
65
+ event.payload[:options][:unless] = Proc.new { |object| false }
66
+
67
+ expect(Eventifier::EventBuilder).to receive(:store).with(
68
+ eventable, user, :update, eventable, {foo: :bar}
69
+ )
70
+
71
+ Eventifier::EventTranslator.new.translate
72
+ end
73
+
74
+ it "does not create an event when :unless is set and returns true" do
75
+ event.payload[:options][:unless] = Proc.new { |object| true }
76
+
77
+ expect(Eventifier::EventBuilder).to_not receive(:store)
78
+
79
+ Eventifier::EventTranslator.new.translate
80
+ end
81
+ end
82
+ end
@@ -31,7 +31,7 @@ describe Eventifier::NotificationTranslator do
31
31
  translator.translate
32
32
  end
33
33
 
34
- it "does not create an event for the originator's user" do
34
+ it "does not create a notification for the originator's user" do
35
35
  event.stub user: user_a
36
36
 
37
37
  Eventifier::Notification.should_not_receive(:create).
@@ -55,7 +55,7 @@ describe Eventifier::NotificationTranslator do
55
55
  translator.translate
56
56
  end
57
57
 
58
- it "creates an event when :if is set and returns true" do
58
+ it "creates a notification when :if is set and returns true" do
59
59
  options[:if] = Proc.new { |event, user| true }
60
60
 
61
61
  Eventifier::Notification.should_receive(:create).
@@ -66,7 +66,7 @@ describe Eventifier::NotificationTranslator do
66
66
  translator.translate
67
67
  end
68
68
 
69
- it "does not create an event when :if is set and returns false" do
69
+ it "does not create a notification when :if is set and returns false" do
70
70
  options[:if] = Proc.new { |event, user| false }
71
71
 
72
72
  Eventifier::Notification.should_not_receive(:create).
@@ -77,7 +77,7 @@ describe Eventifier::NotificationTranslator do
77
77
  translator.translate
78
78
  end
79
79
 
80
- it "creates an event when :unless is set and returns false" do
80
+ it "creates a notification when :unless is set and returns false" do
81
81
  options[:unless] = Proc.new { |event, user| false }
82
82
 
83
83
  Eventifier::Notification.should_receive(:create).
@@ -88,7 +88,7 @@ describe Eventifier::NotificationTranslator do
88
88
  translator.translate
89
89
  end
90
90
 
91
- it "does not create an event when :unless is set and returns true" do
91
+ it "does not create a notification when :unless is set and returns true" do
92
92
  options[:unless] = Proc.new { |event, user| true }
93
93
 
94
94
  Eventifier::Notification.should_not_receive(:create).
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.1.1
4
+ version: 0.1.2
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: 2014-04-02 00:00:00.000000000 Z
13
+ date: 2014-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -100,28 +100,28 @@ dependencies:
100
100
  name: multi_json
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - "~>"
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
105
  version: 1.7.4
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - "~>"
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: 1.7.4
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: jbuilder
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - "~>"
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: 2.0.4
120
120
  type: :runtime
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - "~>"
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: 2.0.4
127
127
  - !ruby/object:Gem::Dependency
@@ -262,6 +262,7 @@ files:
262
262
  - spec/controllers/eventifier/preferences_controller_spec.rb
263
263
  - spec/event_tracking_spec.rb
264
264
  - spec/eventifier/delivery_spec.rb
265
+ - spec/eventifier/event_translator_spec.rb
265
266
  - spec/eventifier/notification_translator_spec.rb
266
267
  - spec/eventifier/preferences_spec.rb
267
268
  - spec/eventifier/relationship_spec.rb
@@ -324,6 +325,7 @@ test_files:
324
325
  - spec/controllers/eventifier/preferences_controller_spec.rb
325
326
  - spec/event_tracking_spec.rb
326
327
  - spec/eventifier/delivery_spec.rb
328
+ - spec/eventifier/event_translator_spec.rb
327
329
  - spec/eventifier/notification_translator_spec.rb
328
330
  - spec/eventifier/preferences_spec.rb
329
331
  - spec/eventifier/relationship_spec.rb