notify_on 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +29 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/notify_on_manifest.js +2 -0
  6. data/app/assets/javascripts/notify_on/application.js +13 -0
  7. data/app/assets/stylesheets/notify_on/application.css +15 -0
  8. data/app/controllers/notify_on/application_controller.rb +5 -0
  9. data/app/helpers/notify_on/application_helper.rb +4 -0
  10. data/app/helpers/notify_on/mailer_helper.rb +9 -0
  11. data/app/jobs/notify_on/application_job.rb +4 -0
  12. data/app/mailers/notify_on/application_mailer.rb +6 -0
  13. data/app/mailers/notify_on/notification_mailer.rb +26 -0
  14. data/app/models/concerns/notify_on/email_support.rb +97 -0
  15. data/app/models/concerns/notify_on/pusher_support.rb +66 -0
  16. data/app/models/concerns/notify_on/string_interpolation.rb +39 -0
  17. data/app/models/notify_on/application_record.rb +5 -0
  18. data/app/models/notify_on/notification.rb +86 -0
  19. data/app/views/layouts/notify_on/application.html.erb +17 -0
  20. data/app/views/notifications/notify.html.erb +9 -0
  21. data/config/database.travis.yml +4 -0
  22. data/config/routes.rb +2 -0
  23. data/lib/generators/notify_on/install_generator.rb +29 -0
  24. data/lib/generators/templates/notifications.yml +19 -0
  25. data/lib/generators/templates/notify_on.rb +64 -0
  26. data/lib/notify_on.rb +29 -0
  27. data/lib/notify_on/bulk_config.rb +36 -0
  28. data/lib/notify_on/configuration.rb +22 -0
  29. data/lib/notify_on/creator.rb +85 -0
  30. data/lib/notify_on/engine.rb +19 -0
  31. data/lib/notify_on/notify_on.rb +36 -0
  32. data/lib/notify_on/receives_notifications.rb +11 -0
  33. data/lib/notify_on/utilities.rb +13 -0
  34. data/lib/notify_on/version.rb +3 -0
  35. data/lib/tasks/notify_on_tasks.rake +4 -0
  36. data/spec/dummy/Rakefile +6 -0
  37. data/spec/dummy/app/assets/config/manifest.js +5 -0
  38. data/spec/dummy/app/assets/javascripts/application.js +7 -0
  39. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  40. data/spec/dummy/app/assets/stylesheets/application.scss +28 -0
  41. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  42. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  44. data/spec/dummy/app/controllers/messages_controller.rb +31 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +8 -0
  46. data/spec/dummy/app/jobs/application_job.rb +2 -0
  47. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  48. data/spec/dummy/app/mailers/notification_mailer.rb +15 -0
  49. data/spec/dummy/app/models/application_record.rb +3 -0
  50. data/spec/dummy/app/models/comment.rb +10 -0
  51. data/spec/dummy/app/models/message.rb +45 -0
  52. data/spec/dummy/app/models/post.rb +11 -0
  53. data/spec/dummy/app/models/user.rb +21 -0
  54. data/spec/dummy/app/views/application/_header.html.erb +44 -0
  55. data/spec/dummy/app/views/application/home.html.erb +1 -0
  56. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  57. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  58. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  59. data/spec/dummy/app/views/messages/_message.html.erb +6 -0
  60. data/spec/dummy/app/views/messages/index.html.erb +33 -0
  61. data/spec/dummy/app/views/messages/new.html.erb +5 -0
  62. data/spec/dummy/app/views/messages/show.html.erb +7 -0
  63. data/spec/dummy/app/views/notifications/new_message.html.erb +9 -0
  64. data/spec/dummy/bin/bundle +3 -0
  65. data/spec/dummy/bin/rails +4 -0
  66. data/spec/dummy/bin/rake +4 -0
  67. data/spec/dummy/bin/setup +34 -0
  68. data/spec/dummy/bin/update +29 -0
  69. data/spec/dummy/config.ru +5 -0
  70. data/spec/dummy/config/application.rb +35 -0
  71. data/spec/dummy/config/boot.rb +5 -0
  72. data/spec/dummy/config/cable.yml +9 -0
  73. data/spec/dummy/config/database.yml +12 -0
  74. data/spec/dummy/config/environment.rb +5 -0
  75. data/spec/dummy/config/environments/development.rb +58 -0
  76. data/spec/dummy/config/environments/production.rb +86 -0
  77. data/spec/dummy/config/environments/test.rb +42 -0
  78. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  79. data/spec/dummy/config/initializers/assets.rb +11 -0
  80. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  82. data/spec/dummy/config/initializers/devise.rb +274 -0
  83. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/spec/dummy/config/initializers/inflections.rb +16 -0
  85. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  86. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  87. data/spec/dummy/config/initializers/notify_on.rb +64 -0
  88. data/spec/dummy/config/initializers/session_store.rb +3 -0
  89. data/spec/dummy/config/initializers/simple_form.rb +165 -0
  90. data/spec/dummy/config/initializers/simple_form_bootstrap.rb +149 -0
  91. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  92. data/spec/dummy/config/locales/devise.en.yml +62 -0
  93. data/spec/dummy/config/locales/en.yml +23 -0
  94. data/spec/dummy/config/locales/simple_form.en.yml +31 -0
  95. data/spec/dummy/config/notifications.yml +20 -0
  96. data/spec/dummy/config/puma.rb +47 -0
  97. data/spec/dummy/config/routes.rb +14 -0
  98. data/spec/dummy/config/secrets.yml +22 -0
  99. data/spec/dummy/config/spring.rb +6 -0
  100. data/spec/dummy/db/migrate/20160801112429_devise_create_users.rb +42 -0
  101. data/spec/dummy/db/migrate/20160801130804_create_messages.rb +11 -0
  102. data/spec/dummy/db/migrate/20160823102904_create_notify_on_notifications.rb +20 -0
  103. data/spec/dummy/db/migrate/20161021100707_create_comments.rb +11 -0
  104. data/spec/dummy/db/migrate/20161021100842_create_posts.rb +11 -0
  105. data/spec/dummy/db/schema.rb +77 -0
  106. data/spec/dummy/db/seeds.rb +4 -0
  107. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  108. data/spec/dummy/public/404.html +67 -0
  109. data/spec/dummy/public/422.html +67 -0
  110. data/spec/dummy/public/500.html +66 -0
  111. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  112. data/spec/dummy/public/apple-touch-icon.png +0 -0
  113. data/spec/dummy/public/favicon.ico +0 -0
  114. data/spec/dummy/spec/controllers/messages_controller_spec.rb +5 -0
  115. data/spec/dummy/spec/factories/comments.rb +7 -0
  116. data/spec/dummy/spec/factories/messages.rb +7 -0
  117. data/spec/dummy/spec/factories/posts.rb +6 -0
  118. data/spec/dummy/spec/factories/users.rb +6 -0
  119. data/spec/dummy/spec/features/send_message_spec.rb +25 -0
  120. data/spec/dummy/spec/mailers/notify_on/notification_mailer_spec.rb +30 -0
  121. data/spec/dummy/spec/mailers/previews/notification_mailer_preview.rb +4 -0
  122. data/spec/dummy/spec/models/comment_spec.rb +22 -0
  123. data/spec/dummy/spec/models/message_spec.rb +60 -0
  124. data/spec/dummy/spec/models/post_spec.rb +23 -0
  125. data/spec/dummy/spec/models/user_spec.rb +21 -0
  126. data/spec/factories/notify_on_notifications.rb +10 -0
  127. data/spec/lib/notify_on/configuration_spec.rb +53 -0
  128. data/spec/mailers/notify_on/notification_mailer_spec.rb +6 -0
  129. data/spec/mailers/previews/notify_on/notification_mailer_preview.rb +6 -0
  130. data/spec/models/notify_on/notification_spec.rb +335 -0
  131. data/spec/rails_helper.rb +95 -0
  132. data/spec/spec_helper.rb +103 -0
  133. data/spec/support/feature_helpers.rb +19 -0
  134. data/spec/support/general_helpers.rb +19 -0
  135. metadata +543 -0
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,28 @@
1
+ @import 'bootstrap-sprockets';
2
+ @import 'bootstrap';
3
+
4
+ #container {
5
+ padding: 10px 25px;
6
+ }
7
+
8
+ #notifications-menu {
9
+ .dropdown-menu > li > a {
10
+ min-width: 350px;
11
+ white-space: normal;
12
+ }
13
+ img {
14
+ float: left;
15
+ width: 50px;
16
+ }
17
+ .time {
18
+ display: block;
19
+ float: left;
20
+ margin-left: 15px;
21
+ font-size: 80%;
22
+ font-weight: 600;
23
+ }
24
+ .desc {
25
+ display: block;
26
+ margin: 20px 0px 0px 65px;
27
+ }
28
+ }
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery :with => :exception
3
+ before_action :authenticate_user!
4
+
5
+ def home
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ class MessagesController < ApplicationController
2
+
3
+ def index
4
+ @inbox = current_user.messages.includes(:user, :author)
5
+ @sent = current_user.sent_messages.includes(:user, :author)
6
+ end
7
+
8
+ def new
9
+ @message = Message.new
10
+ end
11
+
12
+ def create
13
+ @message = Message.new(message_params.merge(:author => current_user))
14
+ if @message.save
15
+ redirect_to messages_path, :notice => 'Message created successfully!'
16
+ else
17
+ render 'new'
18
+ end
19
+ end
20
+
21
+ def show
22
+ @message = current_user.messages.find_by_id(params[:id])
23
+ end
24
+
25
+ private
26
+
27
+ def message_params
28
+ params.require(:message).permit(:user_id, :content)
29
+ end
30
+
31
+ end
@@ -0,0 +1,8 @@
1
+ module ApplicationHelper
2
+
3
+ def avatar(user)
4
+ email_hash = Digest::MD5.hexdigest(user.email.downcase)
5
+ "https://www.gravatar.com/avatar/#{email_hash}"
6
+ end
7
+
8
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,15 @@
1
+ class NotificationMailer < NotifyOn::NotificationMailer
2
+
3
+ def notify(notification_id, template = 'notify')
4
+ @notification = NotifyOn::Notification.find_by_id(notification_id)
5
+ @recipient = @notification.recipient
6
+ @sender = @notification.sender
7
+ @trigger = @notification.trigger
8
+ mail :to => @recipient.email,
9
+ :from => 'Bob Ross <admin@bobross.com>',
10
+ :subject => @notification.description,
11
+ :template_path => 'notifications',
12
+ :template_name => template
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,10 @@
1
+ class Comment < ApplicationRecord
2
+
3
+ # ---------------------------------------- Associations
4
+
5
+ belongs_to :user
6
+ belongs_to :post
7
+
8
+ has_one :post_author, :through => :post, :source => :author
9
+
10
+ end
@@ -0,0 +1,45 @@
1
+ class Message < ApplicationRecord
2
+
3
+ # ---------------------------------------- Plugins
4
+
5
+ # Test that the basics work with the model config. All other features and
6
+ # variations are tested using the bulk config.
7
+ notify_on :create,
8
+ :to => :user,
9
+ :from => :author,
10
+ :message => '{author.email} sent you a message.',
11
+ :link => 'message_path(:self)',
12
+ :email => true
13
+
14
+ # ---------------------------------------- Attributes
15
+
16
+ attr_accessor :delayed
17
+
18
+ # ---------------------------------------- Associations
19
+
20
+ belongs_to :user
21
+ belongs_to :author, :class_name => User
22
+
23
+ # ---------------------------------------- Validations
24
+
25
+ validates :user, :author, :content, :presence => true
26
+
27
+ # ---------------------------------------- Instance Methods
28
+
29
+ def delayed?
30
+ content.start_with?('[DELAYED]')
31
+ end
32
+
33
+ def skip?
34
+ content.start_with?('[SKIP]')
35
+ end
36
+
37
+ def pdf_filename
38
+ 'myfile.pdf'
39
+ end
40
+
41
+ def pdf_file
42
+ @pdf_file ||= open('http://loremflickr.com/200/200')
43
+ end
44
+
45
+ end
@@ -0,0 +1,11 @@
1
+ class Post < ApplicationRecord
2
+
3
+ # ---------------------------------------- Associations
4
+
5
+ belongs_to :author, :class_name => User
6
+
7
+ # ---------------------------------------- Attributes
8
+
9
+ enum :state => { :draft => 0, :pending => 1, :published => 2 }
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ class User < ApplicationRecord
2
+
3
+ # ---------------------------------------- Plugins
4
+
5
+ devise :database_authenticatable, :registerable,
6
+ :recoverable, :rememberable, :trackable, :validatable
7
+
8
+ receives_notifications
9
+
10
+ # ---------------------------------------- Associations
11
+
12
+ has_many :messages
13
+ has_many :sent_messages, :class_name => 'Message', :foreign_key => :author_id
14
+
15
+ # ---------------------------------------- Instance Methods
16
+
17
+ def to_s
18
+ email
19
+ end
20
+
21
+ end
@@ -0,0 +1,44 @@
1
+ <header class="navbar navbar-default">
2
+ <ul class="nav navbar-nav">
3
+ <li class="nav-item <%= 'active' if request.path == root_path %>">
4
+ <a class="nav-link" href="/">Home</a>
5
+ </li>
6
+ <li class="nav-item">
7
+ <a class="nav-link <%= 'active' if controller_name == 'messages' %>"
8
+ href="<%= messages_path %>">Messages</a>
9
+ </li>
10
+ </ul>
11
+ <div class="links pull-right">
12
+ <ul class="nav navbar-nav">
13
+ <% if user_signed_in? %>
14
+ <li class="nav-item dropdown" id="notifications-menu">
15
+ <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
16
+ <i class="glyphicon glyphicon-bell"></i>
17
+ </a>
18
+ <ul class="dropdown-menu pull-right">
19
+ <% current_user.notifications.each do |n| %>
20
+ <li>
21
+ <a href="<%= n.link %>" class="dropdown-item">
22
+ <img src="<%= avatar(n.recipient) %>" alt="">
23
+ <span class="time">
24
+ <%= time_ago_in_words n.created_at %> ago
25
+ </span>
26
+ <span class="desc"><%= n.description %></span>
27
+ </a>
28
+ </li>
29
+ <% end %>
30
+ </ul>
31
+ </li>
32
+ <% end %>
33
+ <li class="nav-item">
34
+ <% if user_signed_in? %>
35
+ <%= link_to 'Sign Out', destroy_user_session_path,
36
+ :class => 'nav-link', :method => :delete %>
37
+ <% else %>
38
+ <%= link_to 'Sign In', new_user_session_path,
39
+ :class => 'nav-link' %>
40
+ <% end %>
41
+ </li>
42
+ </ul>
43
+ </div>
44
+ </header>
@@ -0,0 +1 @@
1
+ <h1>Home</h1>
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ </head>
10
+
11
+ <body>
12
+
13
+ <%= render 'header' %>
14
+
15
+ <div id="container">
16
+ <%= yield %>
17
+ </div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,6 @@
1
+ <li class="list-group-item">
2
+ <div class="card-header">
3
+ From: <strong><%= message.user.email %></strong>
4
+ </div>
5
+ <div class="card-block"><%= message.content %></div>
6
+ </li>
@@ -0,0 +1,33 @@
1
+ <h1>Messages</h1>
2
+
3
+ <%= link_to 'New Message', new_message_path %>
4
+
5
+ <hr>
6
+
7
+ <h2>Inbox</h2>
8
+ <div class="row">
9
+ <div class="col-sm-4">
10
+ <% if @inbox.present? %>
11
+ <ul class="list-group"><%= render @inbox %></ul>
12
+ <% else %>
13
+ <div class="alert alert-warning">
14
+ No messages yet!
15
+ </div>
16
+ <% end %>
17
+ </div>
18
+ </div>
19
+
20
+ <hr>
21
+
22
+ <h2>Sent</h2>
23
+ <div class="row">
24
+ <div class="col-sm-4">
25
+ <% if @sent.present? %>
26
+ <ul class="list-group"><%= render @sent %></ul>
27
+ <% else %>
28
+ <div class="alert alert-warning">
29
+ No messages yet!
30
+ </div>
31
+ <% end %>
32
+ </div>
33
+ </div>
@@ -0,0 +1,5 @@
1
+ <%= simple_form_for @message do |f| %>
2
+ <%= f.input :user_id, :label => 'To', :collection => User.all - [current_user] %>
3
+ <%= f.input :content %>
4
+ <%= f.submit 'Create Message', :class => 'btn btn-primary' %>
5
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <h1>Message #<%= @message.id %></h1>
2
+
3
+ <div class="row">
4
+ <div class="col-sm-4">
5
+ <ul class="list-group"><%= render @message %></ul>
6
+ </div>
7
+ </div>
@@ -0,0 +1,9 @@
1
+ <p>Hey there, <%= @recipient.to_s %>!</p>
2
+
3
+ <p><%= @notification.sender.to_s %> sent you a message:</p>
4
+
5
+ <blockquote>
6
+ <%= simple_format @notification.trigger.content %>
7
+ </blockquote>
8
+
9
+ <p>Cheers!</p>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # puts "\n== Copying sample files =="
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
24
+ # end
25
+
26
+ puts "\n== Preparing database =="
27
+ system! 'bin/rails db:setup'
28
+
29
+ puts "\n== Removing old logs and tempfiles =="
30
+ system! 'bin/rails log:clear tmp:clear'
31
+
32
+ puts "\n== Restarting application server =="
33
+ system! 'bin/rails restart'
34
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end