notify_user 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +12 -0
  4. data/app/assets/javascripts/notify_user/application.js +15 -0
  5. data/app/assets/stylesheets/notify_user/application.css +13 -0
  6. data/app/controllers/notify_user/notifications_controller.rb +33 -0
  7. data/app/helpers/notify_user/application_helper.rb +4 -0
  8. data/app/mailers/notify_user/notification_mailer.rb +28 -0
  9. data/app/models/notify_user/base_notification.rb +187 -0
  10. data/app/serializers/notify_user/notification_serializer.rb +15 -0
  11. data/app/views/layouts/notify_user/application.html.erb +14 -0
  12. data/app/views/notify_user/action_mailer/aggregate_notification.html.erb +5 -0
  13. data/app/views/notify_user/action_mailer/notification.html.erb +1 -0
  14. data/config/routes.rb +6 -0
  15. data/lib/generators/notify_user/install/USAGE +8 -0
  16. data/lib/generators/notify_user/install/install_generator.rb +28 -0
  17. data/lib/generators/notify_user/install/templates/initializer.rb +12 -0
  18. data/lib/generators/notify_user/install/templates/migration.rb +13 -0
  19. data/lib/generators/notify_user/notification/USAGE +8 -0
  20. data/lib/generators/notify_user/notification/notification_generator.rb +16 -0
  21. data/lib/generators/notify_user/notification/templates/email_layout_template.html.erb.erb +33 -0
  22. data/lib/generators/notify_user/notification/templates/email_template.html.erb.erb +1 -0
  23. data/lib/generators/notify_user/notification/templates/mobile_sdk_template.html.erb.erb +1 -0
  24. data/lib/generators/notify_user/notification/templates/notification.rb.erb +10 -0
  25. data/lib/notify_user/channels/action_mailer/action_mailer_channel.rb +24 -0
  26. data/lib/notify_user/engine.rb +11 -0
  27. data/lib/notify_user/version.rb +3 -0
  28. data/lib/notify_user.rb +26 -0
  29. data/spec/controllers/notify_user/notifications_controller_spec.rb +54 -0
  30. data/spec/dummy/rails-4.0.2/Gemfile +45 -0
  31. data/spec/dummy/rails-4.0.2/README.rdoc +28 -0
  32. data/spec/dummy/rails-4.0.2/Rakefile +6 -0
  33. data/spec/dummy/rails-4.0.2/app/assets/javascripts/application.js +16 -0
  34. data/spec/dummy/rails-4.0.2/app/assets/stylesheets/application.css +13 -0
  35. data/spec/dummy/rails-4.0.2/app/controllers/application_controller.rb +5 -0
  36. data/spec/dummy/rails-4.0.2/app/helpers/application_helper.rb +2 -0
  37. data/spec/dummy/rails-4.0.2/app/models/user.rb +2 -0
  38. data/spec/dummy/rails-4.0.2/app/notifications/new_post_notification.rb +10 -0
  39. data/spec/dummy/rails-4.0.2/app/views/layouts/application.html.erb +14 -0
  40. data/spec/dummy/rails-4.0.2/app/views/notify_user/layouts/action_mailer.html.erb +33 -0
  41. data/spec/dummy/rails-4.0.2/app/views/notify_user/new_post_notification/action_mailer/notification.html.erb +1 -0
  42. data/spec/dummy/rails-4.0.2/app/views/notify_user/new_post_notification/mobile_sdk/notification.html.erb +1 -0
  43. data/spec/dummy/rails-4.0.2/bin/bundle +3 -0
  44. data/spec/dummy/rails-4.0.2/bin/rails +4 -0
  45. data/spec/dummy/rails-4.0.2/bin/rake +4 -0
  46. data/spec/dummy/rails-4.0.2/config/application.rb +23 -0
  47. data/spec/dummy/rails-4.0.2/config/boot.rb +4 -0
  48. data/spec/dummy/rails-4.0.2/config/database.yml +25 -0
  49. data/spec/dummy/rails-4.0.2/config/environment.rb +5 -0
  50. data/spec/dummy/rails-4.0.2/config/environments/development.rb +29 -0
  51. data/spec/dummy/rails-4.0.2/config/environments/production.rb +80 -0
  52. data/spec/dummy/rails-4.0.2/config/environments/test.rb +36 -0
  53. data/spec/dummy/rails-4.0.2/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/dummy/rails-4.0.2/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/spec/dummy/rails-4.0.2/config/initializers/inflections.rb +16 -0
  56. data/spec/dummy/rails-4.0.2/config/initializers/mime_types.rb +5 -0
  57. data/spec/dummy/rails-4.0.2/config/initializers/notify_user.rb +12 -0
  58. data/spec/dummy/rails-4.0.2/config/initializers/secret_token.rb +12 -0
  59. data/spec/dummy/rails-4.0.2/config/initializers/session_store.rb +3 -0
  60. data/spec/dummy/rails-4.0.2/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/dummy/rails-4.0.2/config/locales/en.yml +23 -0
  62. data/spec/dummy/rails-4.0.2/config/routes.rb +56 -0
  63. data/spec/dummy/rails-4.0.2/config.ru +4 -0
  64. data/spec/dummy/rails-4.0.2/db/migrate/20140105070446_create_users.rb +9 -0
  65. data/spec/dummy/rails-4.0.2/db/migrate/20140105070448_create_notify_user_notifications.rb +13 -0
  66. data/spec/dummy/rails-4.0.2/db/schema.rb +32 -0
  67. data/spec/dummy/rails-4.0.2/db/seeds.rb +7 -0
  68. data/spec/dummy/rails-4.0.2/db/test.sqlite3 +0 -0
  69. data/spec/dummy/rails-4.0.2/log/test.log +1701 -0
  70. data/spec/dummy/rails-4.0.2/public/404.html +58 -0
  71. data/spec/dummy/rails-4.0.2/public/422.html +58 -0
  72. data/spec/dummy/rails-4.0.2/public/500.html +57 -0
  73. data/spec/dummy/rails-4.0.2/public/favicon.ico +0 -0
  74. data/spec/dummy/rails-4.0.2/public/robots.txt +5 -0
  75. data/spec/dummy/rails-4.0.2/test/fixtures/users.yml +7 -0
  76. data/spec/dummy/rails-4.0.2/test/models/user_test.rb +7 -0
  77. data/spec/dummy/rails-4.0.2/test/test_helper.rb +15 -0
  78. data/spec/factories/notify_user_notifications.rb +10 -0
  79. data/spec/fixtures/notify_user/notification_mailer/notification_email +3 -0
  80. data/spec/mailers/notify_user/notification_mailer_spec.rb +31 -0
  81. data/spec/models/notify_user/notification_spec.rb +71 -0
  82. data/spec/serializers/notify_user/notification_serializer_spec.rb +10 -0
  83. data/spec/setup_spec.rb +17 -0
  84. data/spec/spec_helper.rb +46 -0
  85. data/spec/support/rails_template.rb +8 -0
  86. metadata +289 -0
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Create a notification, from which you can customise copy and aggregation settings.
3
+
4
+ Example:
5
+ rails generate notify_user:notification PostLiked
6
+
7
+ This will create:
8
+ app/notifications/post_liked.rb
@@ -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
@@ -0,0 +1,11 @@
1
+ module NotifyUser
2
+ class Engine < ::Rails::Engine
3
+
4
+ config.generators do |g|
5
+ g.test_framework :rspec, :fixture => false
6
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
7
+ g.assets false
8
+ g.helper false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module NotifyUser
2
+ VERSION = "0.0.1"
3
+ end
@@ -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,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails402::Application.load_tasks
@@ -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,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -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 with <%= params.as_json %>
@@ -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', __FILE__)
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,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