notify_user 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +12 -0
- data/app/assets/javascripts/notify_user/application.js +15 -0
- data/app/assets/stylesheets/notify_user/application.css +13 -0
- data/app/controllers/notify_user/notifications_controller.rb +33 -0
- data/app/helpers/notify_user/application_helper.rb +4 -0
- data/app/mailers/notify_user/notification_mailer.rb +28 -0
- data/app/models/notify_user/base_notification.rb +187 -0
- data/app/serializers/notify_user/notification_serializer.rb +15 -0
- data/app/views/layouts/notify_user/application.html.erb +14 -0
- data/app/views/notify_user/action_mailer/aggregate_notification.html.erb +5 -0
- data/app/views/notify_user/action_mailer/notification.html.erb +1 -0
- data/config/routes.rb +6 -0
- data/lib/generators/notify_user/install/USAGE +8 -0
- data/lib/generators/notify_user/install/install_generator.rb +28 -0
- data/lib/generators/notify_user/install/templates/initializer.rb +12 -0
- data/lib/generators/notify_user/install/templates/migration.rb +13 -0
- data/lib/generators/notify_user/notification/USAGE +8 -0
- data/lib/generators/notify_user/notification/notification_generator.rb +16 -0
- data/lib/generators/notify_user/notification/templates/email_layout_template.html.erb.erb +33 -0
- data/lib/generators/notify_user/notification/templates/email_template.html.erb.erb +1 -0
- data/lib/generators/notify_user/notification/templates/mobile_sdk_template.html.erb.erb +1 -0
- data/lib/generators/notify_user/notification/templates/notification.rb.erb +10 -0
- data/lib/notify_user/channels/action_mailer/action_mailer_channel.rb +24 -0
- data/lib/notify_user/engine.rb +11 -0
- data/lib/notify_user/version.rb +3 -0
- data/lib/notify_user.rb +26 -0
- data/spec/controllers/notify_user/notifications_controller_spec.rb +54 -0
- data/spec/dummy/rails-4.0.2/Gemfile +45 -0
- data/spec/dummy/rails-4.0.2/README.rdoc +28 -0
- data/spec/dummy/rails-4.0.2/Rakefile +6 -0
- data/spec/dummy/rails-4.0.2/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/rails-4.0.2/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/rails-4.0.2/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/rails-4.0.2/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/rails-4.0.2/app/models/user.rb +2 -0
- data/spec/dummy/rails-4.0.2/app/notifications/new_post_notification.rb +10 -0
- data/spec/dummy/rails-4.0.2/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/rails-4.0.2/app/views/notify_user/layouts/action_mailer.html.erb +33 -0
- data/spec/dummy/rails-4.0.2/app/views/notify_user/new_post_notification/action_mailer/notification.html.erb +1 -0
- data/spec/dummy/rails-4.0.2/app/views/notify_user/new_post_notification/mobile_sdk/notification.html.erb +1 -0
- data/spec/dummy/rails-4.0.2/bin/bundle +3 -0
- data/spec/dummy/rails-4.0.2/bin/rails +4 -0
- data/spec/dummy/rails-4.0.2/bin/rake +4 -0
- data/spec/dummy/rails-4.0.2/config/application.rb +23 -0
- data/spec/dummy/rails-4.0.2/config/boot.rb +4 -0
- data/spec/dummy/rails-4.0.2/config/database.yml +25 -0
- data/spec/dummy/rails-4.0.2/config/environment.rb +5 -0
- data/spec/dummy/rails-4.0.2/config/environments/development.rb +29 -0
- data/spec/dummy/rails-4.0.2/config/environments/production.rb +80 -0
- data/spec/dummy/rails-4.0.2/config/environments/test.rb +36 -0
- data/spec/dummy/rails-4.0.2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/rails-4.0.2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/rails-4.0.2/config/initializers/inflections.rb +16 -0
- data/spec/dummy/rails-4.0.2/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/rails-4.0.2/config/initializers/notify_user.rb +12 -0
- data/spec/dummy/rails-4.0.2/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/rails-4.0.2/config/initializers/session_store.rb +3 -0
- data/spec/dummy/rails-4.0.2/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/rails-4.0.2/config/locales/en.yml +23 -0
- data/spec/dummy/rails-4.0.2/config/routes.rb +56 -0
- data/spec/dummy/rails-4.0.2/config.ru +4 -0
- data/spec/dummy/rails-4.0.2/db/migrate/20140105070446_create_users.rb +9 -0
- data/spec/dummy/rails-4.0.2/db/migrate/20140105070448_create_notify_user_notifications.rb +13 -0
- data/spec/dummy/rails-4.0.2/db/schema.rb +32 -0
- data/spec/dummy/rails-4.0.2/db/seeds.rb +7 -0
- data/spec/dummy/rails-4.0.2/db/test.sqlite3 +0 -0
- data/spec/dummy/rails-4.0.2/log/test.log +1701 -0
- data/spec/dummy/rails-4.0.2/public/404.html +58 -0
- data/spec/dummy/rails-4.0.2/public/422.html +58 -0
- data/spec/dummy/rails-4.0.2/public/500.html +57 -0
- data/spec/dummy/rails-4.0.2/public/favicon.ico +0 -0
- data/spec/dummy/rails-4.0.2/public/robots.txt +5 -0
- data/spec/dummy/rails-4.0.2/test/fixtures/users.yml +7 -0
- data/spec/dummy/rails-4.0.2/test/models/user_test.rb +7 -0
- data/spec/dummy/rails-4.0.2/test/test_helper.rb +15 -0
- data/spec/factories/notify_user_notifications.rb +10 -0
- data/spec/fixtures/notify_user/notification_mailer/notification_email +3 -0
- data/spec/mailers/notify_user/notification_mailer_spec.rb +31 -0
- data/spec/models/notify_user/notification_spec.rb +71 -0
- data/spec/serializers/notify_user/notification_serializer_spec.rb +10 -0
- data/spec/setup_spec.rb +17 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/rails_template.rb +8 -0
- metadata +289 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module NotifyUser
|
2
|
+
class NotificationGenerator < Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
class_option :skip, default: true
|
5
|
+
|
6
|
+
def generate_notification
|
7
|
+
template "notification.rb.erb", "app/notifications/#{name.underscore}.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_view_scaffolds
|
11
|
+
template "email_template.html.erb.erb", "app/views/notify_user/#{name.underscore}/action_mailer/notification.html.erb"
|
12
|
+
template "mobile_sdk_template.html.erb.erb", "app/views/notify_user/#{name.underscore}/mobile_sdk/notification.html.erb"
|
13
|
+
template "email_layout_template.html.erb.erb", "app/views/notify_user/layouts/action_mailer.html.erb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
|
5
|
+
<title></title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin: 0px; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;">
|
9
|
+
<div style="width: 100%; height: 70px; margin: 0; padding: 0;">
|
10
|
+
<div style="width: 600px; margin: 0 auto; padding: 15px 0;">
|
11
|
+
Logo
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
<div style="width: 100%; background-color: #fff; margin: 0; padding: 0;">
|
15
|
+
<div style="width: 500px; margin: 0 auto; padding: 40px 0; ">
|
16
|
+
<%%= yield %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<div style="width: 100%; min-height: 80px; margin: 0; padding: 0;">
|
20
|
+
<div style="width: 600px; margin: 0 auto; padding: 0;">
|
21
|
+
<p style="text-align: center;">
|
22
|
+
This is the default generated layout. A privacy declaration could go here.
|
23
|
+
</p>
|
24
|
+
<p style="text-align: center; margin-bottom: 0px;">
|
25
|
+
© MyCompany Pty Ltd
|
26
|
+
</p>
|
27
|
+
<p style="text-align: center; margin-top: 0px; padding-top: 0px;">
|
28
|
+
ABN 123 456 789
|
29
|
+
</p>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</body>
|
33
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= name.titleize %> happened.
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= name.titleize %> happened with <%%= params.as_json %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class <%= name.camelize %> < NotifyUser::BaseNotification
|
2
|
+
|
3
|
+
channel :action_mailer,
|
4
|
+
subject: "<%= Rails.application.class.parent_name.titleize %>: You have a new <%= name.humanize %> notification.",
|
5
|
+
aggregate: {
|
6
|
+
subject: "<%= Rails.application.class.parent_name.titleize %>: You have new <%= name.humanize %> notifications."
|
7
|
+
}
|
8
|
+
|
9
|
+
@@aggregate_per = 10.minutes
|
10
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ActionMailerChannel
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def default_options
|
6
|
+
{
|
7
|
+
subject: "New Notification",
|
8
|
+
aggregate: {
|
9
|
+
subject: "New Notifications"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def deliver(notification, options={})
|
15
|
+
NotifyUser::NotificationMailer.notification_email(notification, default_options.deep_merge(options)).deliver
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver_aggregated(notifications, options={})
|
19
|
+
NotifyUser::NotificationMailer.aggregate_notifications_email(notifications, default_options.deep_merge(options)).deliver
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/notify_user.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "kaminari"
|
2
|
+
|
3
|
+
require "notify_user/engine"
|
4
|
+
|
5
|
+
module NotifyUser
|
6
|
+
|
7
|
+
mattr_accessor :mailer_sender
|
8
|
+
@@mailer_sender = nil
|
9
|
+
|
10
|
+
mattr_accessor :authentication_method
|
11
|
+
@@authentication_method = nil
|
12
|
+
|
13
|
+
mattr_accessor :current_user_method
|
14
|
+
@@current_user_method = nil
|
15
|
+
|
16
|
+
# Used to set up NotifyUser from the initializer.
|
17
|
+
def self.setup
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.send_notification(type)
|
22
|
+
type.camelize.constantize.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Gem.find_files("notify_user/channels/**/*.rb").each { |path| require path }
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe NotifyUser::NotificationsController do
|
5
|
+
|
6
|
+
let(:user) { User.create({email: "user@example.com" })}
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
NotifyUser::NotificationsController.any_instance.stub(:current_user).and_return(user)
|
10
|
+
NotifyUser::NotificationsController.any_instance.stub(:authenticate_user!).and_return(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "delegates authentication to Devise" do
|
14
|
+
subject.should_receive(:authenticate_user!).and_return(true)
|
15
|
+
subject.should_receive(:current_user).any_number_of_times.and_return(user)
|
16
|
+
get :index
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "GET notifications.json" do
|
20
|
+
render_views
|
21
|
+
|
22
|
+
let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Blobby") }
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
notification.save
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a message from a rendered template" do
|
29
|
+
get :index
|
30
|
+
json[:notifications][0][:message].should include "New Post Notification happened with"
|
31
|
+
json[:notifications][0][:message].should include notification.params[:name]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "PUT notifications/mark_read.json" do
|
36
|
+
let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Blobby") }
|
37
|
+
|
38
|
+
before :each do
|
39
|
+
notification.save
|
40
|
+
end
|
41
|
+
|
42
|
+
it "marks notifications as read" do
|
43
|
+
put :mark_read, ids: [notification.id]
|
44
|
+
notification.reload
|
45
|
+
notification.read?.should eq true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns updated notifications" do
|
49
|
+
put :mark_read, ids: [notification.id]
|
50
|
+
json[:notifications][0].should_not be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
4
|
+
gem 'rails', '4.0.2'
|
5
|
+
|
6
|
+
# Use sqlite3 as the database for Active Record
|
7
|
+
gem 'sqlite3'
|
8
|
+
|
9
|
+
# Use SCSS for stylesheets
|
10
|
+
gem 'sass-rails', '~> 4.0.0'
|
11
|
+
|
12
|
+
# Use Uglifier as compressor for JavaScript assets
|
13
|
+
gem 'uglifier', '>= 1.3.0'
|
14
|
+
|
15
|
+
# Use CoffeeScript for .js.coffee assets and views
|
16
|
+
gem 'coffee-rails', '~> 4.0.0'
|
17
|
+
|
18
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
19
|
+
# gem 'therubyracer', platforms: :ruby
|
20
|
+
|
21
|
+
# Use jquery as the JavaScript library
|
22
|
+
gem 'jquery-rails'
|
23
|
+
|
24
|
+
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
25
|
+
gem 'turbolinks'
|
26
|
+
|
27
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
28
|
+
gem 'jbuilder', '~> 1.2'
|
29
|
+
|
30
|
+
group :doc do
|
31
|
+
# bundle exec rake doc:rails generates the API under doc/api.
|
32
|
+
gem 'sdoc', require: false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Use ActiveModel has_secure_password
|
36
|
+
# gem 'bcrypt-ruby', '~> 3.1.2'
|
37
|
+
|
38
|
+
# Use unicorn as the app server
|
39
|
+
# gem 'unicorn'
|
40
|
+
|
41
|
+
# Use Capistrano for deployment
|
42
|
+
# gem 'capistrano', group: :development
|
43
|
+
|
44
|
+
# Use debugger
|
45
|
+
# gem 'debugger', group: [:development, :test]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class NewPostNotification < NotifyUser::BaseNotification
|
2
|
+
|
3
|
+
channel :action_mailer,
|
4
|
+
subject: "Rails402: You have a new Newpostnotification notification.",
|
5
|
+
aggregate: {
|
6
|
+
subject: "Rails402: You have new Newpostnotification notifications."
|
7
|
+
}
|
8
|
+
|
9
|
+
@@aggregate_per = 10.minutes
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Rails402</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
|
5
|
+
<title></title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin: 0px; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;">
|
9
|
+
<div style="width: 100%; height: 70px; margin: 0; padding: 0;">
|
10
|
+
<div style="width: 600px; margin: 0 auto; padding: 15px 0;">
|
11
|
+
Logo
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
<div style="width: 100%; background-color: #fff; margin: 0; padding: 0;">
|
15
|
+
<div style="width: 500px; margin: 0 auto; padding: 40px 0; ">
|
16
|
+
<%= yield %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<div style="width: 100%; min-height: 80px; margin: 0; padding: 0;">
|
20
|
+
<div style="width: 600px; margin: 0 auto; padding: 0;">
|
21
|
+
<p style="text-align: center;">
|
22
|
+
This is the default generated layout. A privacy declaration could go here.
|
23
|
+
</p>
|
24
|
+
<p style="text-align: center; margin-bottom: 0px;">
|
25
|
+
© MyCompany Pty Ltd
|
26
|
+
</p>
|
27
|
+
<p style="text-align: center; margin-top: 0px; padding-top: 0px;">
|
28
|
+
ABN 123 456 789
|
29
|
+
</p>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</body>
|
33
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
New Post Notification happened.
|
@@ -0,0 +1 @@
|
|
1
|
+
New Post Notification happened with <%= params.as_json %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(:default, Rails.env)
|
8
|
+
|
9
|
+
module Rails402
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
16
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
17
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
18
|
+
|
19
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
20
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
21
|
+
# config.i18n.default_locale = :de
|
22
|
+
end
|
23
|
+
end
|