notify_user 0.0.9 → 0.0.10

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: 8a470e0d509c286f8776d2dfa71a3517282a11a1
4
- data.tar.gz: d55423eee03a893bbb8f1dfc52481d3773faf3b1
3
+ metadata.gz: e2b5085ee8851c7794ce513ecd8a39306b99a617
4
+ data.tar.gz: 0899ee588ee35b8e57ca2775eee227e9b7bc7b90
5
5
  SHA512:
6
- metadata.gz: 744a1fbaec414b5d906c450d7aa1698fd0190ed76e2632f257c27f3381ba4c6842b1af14a734757e3b3c8869d8450a81f45fc690e40e9923d9da4ee2a0119229
7
- data.tar.gz: acca9ec95baa1668e47083abbb2d71a59c014341e6c6326a97236eedb44acfc283124ded02c230a33420b908e20a075fdcd19b9fba8957011f3e754f0678e69c
6
+ metadata.gz: 6eb6b9dacbf04d55add8f2410cbe666b28abe41c689a65b9f85862b62c6285577267fe3a21298ed41e376c66cc99fac0f58eb4e5e148be78200b4fcdc2eda1d5
7
+ data.tar.gz: 81644a729e2499c788d44b0d9497eac0c90bfad60a193980fa326277899e803d8212a75727cea5abbf624e413fdab247da1dfecb9d1dc4308b67434527174659
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ notify_user
2
+ ===========
3
+
4
+
5
+ Install:
6
+ ```
7
+ gem 'notify_user'
8
+ rails g notify_user:install
9
+ ```
10
+
11
+ Getting started:
12
+ ```
13
+ rails g notify_user:notification NewMyProperty
14
+ ```
15
+
16
+ Edit views/notify_user/new_my_property/action_mailer/notification.html.erb, e.g.
17
+ ```
18
+ <h3>We added <%= @notification.params[:listing_address] %> to your My Properties.</h3>
19
+ ```
20
+
21
+ Then send:
22
+ ```
23
+ NotifyUser.send_notification('new_my_property').to(user).with("listing_address" => "123 Main St").notify
24
+ ```
25
+
26
+ To enable APNS add this line to your app/notification/notification_type.rb
27
+ ```
28
+ channel :apns,
29
+ aggregate_per: false
30
+ ```
31
+
32
+ To run the tests:
33
+ ```
34
+ BUNDLE_GEMFILE=gemfiles/rails40.gemfile bundle install
35
+ BUNDLE_GEMFILE=gemfiles/rails40.gemfile bundle exec rspec spec
36
+ ```
37
+
38
+ To run the tests like Travis:
39
+ ```
40
+ gem install wwtd
41
+ wwtd
42
+ ```
43
+
44
+ ##Web interface
45
+ Display a list of notifications for a logged in user
46
+ ```
47
+ visit /notify_user/notifications
48
+ ```
49
+ Clicking on a notification gets marked as read and taken to the redirect_logic action (notifications_controller.rb)
50
+ ```
51
+ def redirect_logic(notification)
52
+ class = notification.params[:type].capitalize.constantize
53
+ object = class.find(@notification.params[:id])
54
+ redirect_to property_url(object)
55
+ end
56
+ ```
57
+ Add line to environment.rb file to configure host url for mail notifications
58
+ ```
59
+ config.action_mailer.default_url_options = { :host => "http://example.com" }
60
+ ```
61
+
62
+ ##Subscriptions
63
+ Unsubscribing from a notification type, first add it to the notify_user.rb initilizer
64
+ ```
65
+ # Override the default notification type
66
+ config.unsubscribable_notifications = ['NewPostNotification','NewSale']
67
+ ```
68
+ Users can manage their subscription statuses through the web interface
69
+ ```
70
+ visit notify_user/notifications/unsubscribe
71
+ ```
72
+ Unsubscribe link helper - add this to your views/notify_user/layouts/action_mailer.html.erb
73
+ ```
74
+ <% if is_unsubscribeable? @notification %>
75
+ <p style="text-align: center;">
76
+ <%= unsubscribe_link(@notification, "Unsubscribe") %>
77
+ </p>
78
+ <% end %>
79
+ ```
80
+
81
+ ##Upgrading to JSON params data type
82
+ Run json_update generator which generates the migrations to change the params datatype to json as well as convert the current data to json
83
+ ```
84
+ rails generate notify_user:json_update
85
+ rake db:migrate
86
+ ```
87
+
88
+ ##Changes
89
+ Notification description and aggregates has changed syntax slighly from
90
+ ```
91
+ @@description = "please override this type description"
92
+ @@aggregate_per = 10.minutes
93
+ ```
94
+ to
95
+ ```
96
+ self.description = "please override this type description"
97
+ self.aggregate_per = 10.minutes
98
+ ```
99
+
@@ -45,7 +45,7 @@ class NotifyUser::BaseNotificationsController < ApplicationController
45
45
  #get
46
46
  def read
47
47
  @notification = NotifyUser::BaseNotification.for_target(@user).where('id = ?', params[:id]).first
48
- @notification.mark_as_read
48
+ @notification.mark_as_read!
49
49
  redirect_logic(@notification)
50
50
  end
51
51
 
@@ -58,6 +58,7 @@ class NotifyUser::BaseNotificationsController < ApplicationController
58
58
  unsubscribe_from(params[:type])
59
59
  redirect_to notify_user_notifications_unsubscribe_path
60
60
  end
61
+ @types = build_notification_types
61
62
  @unsubscribale_types = NotifyUser.unsubscribable_notifications
62
63
  @unsubscribale_channels = NotifyUser::BaseNotification.channels
63
64
  end
@@ -1,9 +1,10 @@
1
- require 'state_machine'
1
+ require 'aasm'
2
2
  require 'sidekiq'
3
3
 
4
4
  module NotifyUser
5
5
  class BaseNotification < ActiveRecord::Base
6
6
  include ActionView::Helpers::TextHelper
7
+ include AASM
7
8
 
8
9
  if ActiveRecord::VERSION::MAJOR < 4
9
10
  attr_accessible :params, :target, :type, :state
@@ -16,37 +17,36 @@ module NotifyUser
16
17
  validate :unsubscribed_validation
17
18
 
18
19
  # Params for creating the notification message.
19
- # serialize :params, Hash
20
+ if ActiveRecord::VERSION::MAJOR < 4
21
+ serialize :params, JSON
22
+ end
20
23
 
21
24
  # The user to send the notification to
22
25
  belongs_to :target, polymorphic: true
23
26
 
24
27
  validates_presence_of :target_id, :target_type, :target, :type, :state
25
28
 
26
- state_machine :state, initial: :pending do
29
+ aasm column: :state do
27
30
 
28
31
  # Created, not sent yet. Possibly waiting for aggregation.
29
- state :pending do
30
- end
32
+ state :pending, initial: true
31
33
 
32
34
  # Email/SMS/APNS has been sent.
33
- state :sent do
34
- end
35
+ state :sent
35
36
 
36
37
  # The user has seen this notification.
37
- state :read do
38
- end
38
+ state :read
39
39
 
40
40
  # Record that we have sent message(s) to the user about this notification.
41
41
  event :mark_as_sent do
42
- transition :pending => :sent
42
+ transitions from: :pending, to: :sent
43
43
  end
44
44
 
45
45
  # Record that the user has seen this notification, usually on a page or in the app.
46
46
  # A notification can go straight from pending to read if it's seen in a view before
47
47
  # sent in an email.
48
48
  event :mark_as_read do
49
- transition [:pending, :sent] => :read
49
+ transitions from: [:pending, :sent], to: :read
50
50
  end
51
51
  end
52
52
 
@@ -93,17 +93,19 @@ module NotifyUser
93
93
  # Send any Emails/SMS/APNS
94
94
  def notify
95
95
 
96
- save
96
+ if save
97
97
 
98
- #if aggregation is false bypass aggregation completely
99
- self.channels.each do |channel_name, options|
100
- if(options[:aggregate_per] == false)
101
- self.class.delay.deliver_notification_channel(self.id, channel_name)
102
- else
103
- if not aggregation_pending?
104
- self.class.delay_for(options[:aggregate_per] || self.aggregate_per).notify_aggregated_channel(self.id, channel_name)
98
+ #if aggregation is false bypass aggregation completely
99
+ self.channels.each do |channel_name, options|
100
+ if(options[:aggregate_per] == false)
101
+ self.class.delay.deliver_notification_channel(self.id, channel_name)
102
+ else
103
+ if not aggregation_pending?
104
+ self.class.delay_for(options[:aggregate_per] || self.aggregate_per).notify_aggregated_channel(self.id, channel_name)
105
+ end
105
106
  end
106
107
  end
108
+
107
109
  end
108
110
 
109
111
  end
@@ -1,3 +1,3 @@
1
1
  module NotifyUser
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -12,7 +12,7 @@ describe NotifyUser::NotificationsController do
12
12
 
13
13
  it "delegates authentication to Devise" do
14
14
  subject.should_receive(:authenticate_user!).and_return(true)
15
- subject.should_receive(:current_user).any_number_of_times.and_return(user)
15
+ subject.stub(:current_user).and_return(user)
16
16
  get :index
17
17
  end
18
18
 
@@ -92,12 +92,6 @@ describe NotifyUser::NotificationsController do
92
92
  notification.save
93
93
  end
94
94
 
95
- xit "endpoint for toggling subscriptions statuses" do
96
- # NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should eq []
97
- put :subscriptions, :types => ['NewPostNotification']
98
- NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should_not eq []
99
- end
100
-
101
95
  it "endpoint for updating notification subscription statuses" do
102
96
  NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should eq []
103
97
  put :subscriptions, :types => [{
@@ -18,6 +18,11 @@ module NotifyUser
18
18
  notification.errors[:target].first.should eq " has unsubscribed from this type"
19
19
  end
20
20
 
21
+ it "doesn't queue an aggregation background worker if unsubscribed" do
22
+ notification.class.should_not_receive(:delay_for)
23
+ notification.notify
24
+ end
25
+
21
26
  it "doesnt create object if notification type isn't unsubscribable" do
22
27
  unsubscribe = NotifyUser::Unsubscribe.create({target: user, type: "UnsubscribableNotification"})
23
28
  NotifyUser::Unsubscribe.last.type.should_not eq "UnsubscribableNotification"
@@ -2,6 +2,7 @@ development:
2
2
  adapter: postgresql
3
3
  encoding: unicode
4
4
  database: notify_user_development
5
+ host: localhost
5
6
  pool: 5
6
7
  timeout: 5000
7
8
 
@@ -9,6 +10,7 @@ test:
9
10
  adapter: postgresql
10
11
  encoding: unicode
11
12
  database: notify_user_test
13
+ host: localhost
12
14
  pool: 5
13
15
  timeout: 5000
14
16
 
@@ -17,5 +19,6 @@ production:
17
19
  adapter: postgresql
18
20
  encoding: unicode
19
21
  database: notify_user_production
22
+ host: localhost
20
23
  pool: 5
21
24
  timeout: 5000
@@ -1,6 +1,6 @@
1
1
  #removes the username and password fields from database.yml
2
- system("cat #{ENV['RAILS_ROOT']}/config/database.yml | grep -v 'username' > #{ENV['RAILS_ROOT']}/config/database2.yml ")
3
- system("cat #{ENV['RAILS_ROOT']}/config/database2.yml | grep -v 'password' > #{ENV['RAILS_ROOT']}/config/database.yml ")
2
+ remove_file "#{ENV['RAILS_ROOT']}/config/database.yml"
3
+ copy_file File.expand_path('../../support/database.yml'), "#{ENV['RAILS_ROOT']}/config/database.yml"
4
4
 
5
5
  rake "db:drop:all"
6
6
  rake "db:create:all"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notify_user
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Spacek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: state_machine
28
+ name: aasm
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -188,7 +188,7 @@ extensions: []
188
188
  extra_rdoc_files: []
189
189
  files:
190
190
  - MIT-LICENSE
191
- - README.rdoc
191
+ - README.md
192
192
  - Rakefile
193
193
  - app/assets/javascripts/notify_user/application.js
194
194
  - app/assets/javascripts/notify_user/notification.js
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = NotifyUser
2
-
3
- This project rocks and uses MIT-LICENSE.