activity_notification 0.0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/Gemfile +6 -3
  4. data/Gemfile.lock +74 -58
  5. data/README.md +53 -26
  6. data/activity_notification.gemspec +2 -0
  7. data/app/controllers/activity_notification/notifications_controller.rb +4 -4
  8. data/app/mailers/activity_notification/mailer.rb +9 -3
  9. data/app/views/activity_notification/mailer/default/default.html.erb +9 -4
  10. data/app/views/activity_notification/mailer/default/default.text.erb +10 -0
  11. data/app/views/activity_notification/notifications/default/_default.html.erb +173 -34
  12. data/app/views/activity_notification/notifications/default/_index.html.erb +119 -11
  13. data/app/views/activity_notification/notifications/default/destroy.js.erb +2 -2
  14. data/app/views/activity_notification/notifications/default/index.html.erb +25 -14
  15. data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
  16. data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
  17. data/app/views/activity_notification/notifications/default/show.html.erb +1 -1
  18. data/gemfiles/Gemfile.rails-4.2 +0 -2
  19. data/gemfiles/Gemfile.rails-4.2.lock +3 -3
  20. data/gemfiles/Gemfile.rails-5.0 +1 -3
  21. data/lib/activity_notification.rb +10 -9
  22. data/lib/activity_notification/apis/notification_api.rb +108 -14
  23. data/lib/activity_notification/common.rb +11 -2
  24. data/lib/activity_notification/config.rb +13 -13
  25. data/lib/activity_notification/helpers/view_helpers.rb +26 -4
  26. data/lib/activity_notification/mailers/helpers.rb +8 -4
  27. data/lib/activity_notification/models.rb +4 -0
  28. data/lib/activity_notification/models/concerns/group.rb +32 -0
  29. data/lib/activity_notification/models/concerns/notifiable.rb +60 -32
  30. data/lib/activity_notification/models/concerns/notifier.rb +17 -1
  31. data/lib/activity_notification/models/concerns/target.rb +114 -55
  32. data/lib/activity_notification/models/notification.rb +26 -25
  33. data/lib/activity_notification/rails.rb +1 -0
  34. data/lib/activity_notification/renderable.rb +8 -3
  35. data/lib/activity_notification/roles/acts_as_common.rb +28 -0
  36. data/lib/activity_notification/roles/acts_as_group.rb +38 -0
  37. data/lib/activity_notification/roles/acts_as_notifiable.rb +56 -22
  38. data/lib/activity_notification/roles/acts_as_notifier.rb +25 -2
  39. data/lib/activity_notification/roles/acts_as_target.rb +27 -9
  40. data/lib/activity_notification/version.rb +1 -1
  41. data/lib/generators/templates/activity_notification.rb +1 -1
  42. data/spec/concerns/apis/notification_api_spec.rb +361 -2
  43. data/spec/concerns/common_spec.rb +36 -0
  44. data/spec/concerns/models/group_spec.rb +61 -0
  45. data/spec/concerns/models/notifiable_spec.rb +37 -0
  46. data/spec/concerns/models/notifier_spec.rb +48 -0
  47. data/spec/concerns/models/target_spec.rb +81 -31
  48. data/spec/factories/dummy/dummy_group.rb +4 -0
  49. data/spec/helpers/view_helpers_spec.rb +13 -0
  50. data/spec/mailers/mailer_spec.rb +8 -1
  51. data/spec/models/dummy/dummy_group_spec.rb +6 -0
  52. data/spec/rails_app/app/assets/stylesheets/application.css +15 -0
  53. data/spec/rails_app/app/assets/stylesheets/reset.css +85 -0
  54. data/spec/rails_app/app/assets/stylesheets/style.css +244 -0
  55. data/spec/rails_app/app/controllers/articles_controller.rb +1 -1
  56. data/spec/rails_app/app/models/admin.rb +2 -1
  57. data/spec/rails_app/app/models/article.rb +9 -2
  58. data/spec/rails_app/app/models/comment.rb +8 -2
  59. data/spec/rails_app/app/models/dummy/dummy_group.rb +4 -0
  60. data/spec/rails_app/app/models/user.rb +8 -3
  61. data/spec/rails_app/app/views/articles/_form.html.erb +14 -10
  62. data/spec/rails_app/app/views/articles/edit.html.erb +8 -6
  63. data/spec/rails_app/app/views/articles/index.html.erb +59 -67
  64. data/spec/rails_app/app/views/articles/new.html.erb +7 -5
  65. data/spec/rails_app/app/views/articles/show.html.erb +47 -36
  66. data/spec/rails_app/app/views/layouts/_header.html.erb +36 -9
  67. data/spec/rails_app/app/views/layouts/application.html.erb +8 -6
  68. data/spec/rails_app/config/environments/development.rb +9 -0
  69. data/spec/rails_app/config/initializers/activity_notification.rb +1 -1
  70. data/spec/rails_app/db/schema.rb +14 -20
  71. data/spec/rails_app/db/seeds.rb +5 -5
  72. data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +13 -0
  73. data/spec/roles/acts_as_group_spec.rb +32 -0
  74. data/spec/roles/acts_as_notifiable_spec.rb +1 -1
  75. data/spec/roles/acts_as_notifier_spec.rb +15 -0
  76. data/spec/roles/acts_as_target_spec.rb +1 -1
  77. metadata +52 -2
@@ -2,19 +2,23 @@
2
2
  <% if @article.errors.any? %>
3
3
  <div id="error_explanation">
4
4
  <h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
5
-
6
5
  <ul>
7
- <% @article.errors.full_messages.each do |message| %>
8
- <li><%= message %></li>
9
- <% end %>
6
+ <% @article.errors.full_messages.each do |message| %>
7
+ <li><%= message %></li>
8
+ <% end %>
10
9
  </ul>
11
10
  </div>
12
11
  <% end %>
13
12
 
14
- <%= f.text_field :title %>
15
- <%= f.text_area :body %>
16
-
17
- <div class="actions">
18
- <%= f.submit %>
13
+ <div class="input_wrapper">
14
+ <%= f.text_field :title, placeholder: "title..." %>
15
+ </div>
16
+ <div class="textarea_wrapper">
17
+ <%= f.text_area :body, placeholder: "body..." %>
18
+ </div>
19
+ <div class="submit_button_wrapper">
20
+ <button class="green_button" type="submit">
21
+ <%= submit_message %>
22
+ </button>
19
23
  </div>
20
- <% end %>
24
+ <% end %>
@@ -1,6 +1,8 @@
1
- <h1>Editing Article</h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Show', @article %> |
6
- <%= link_to 'Back', articles_path %>
1
+ <section>
2
+ <h1>Editing Article</h1>
3
+ <%= render partial: 'form', locals: { submit_message: "Update Article" } %>
4
+ <div class="left_button_wrapper">
5
+ <%= link_to 'Show', @article, class: "gray_button" %>
6
+ <%= link_to 'Back', articles_path, class: "gray_button" %>
7
+ </div>
8
+ </section>
@@ -1,67 +1,59 @@
1
- <p id="notice"><%= notice %></p>
2
-
3
- <h1>Listing Users</h1>
4
-
5
- <table>
6
- <thead>
7
- <tr>
8
- <th colspan="3"></th>
9
- </tr>
10
- </thead>
11
-
12
- <tbody>
13
- <% User.all.each do |user| %>
14
- <tr>
15
- <td><%= user.email %></td>
16
- <td><%= user.name %></td>
17
- <td><%= link_to 'Notifications', user_notifications_path(user) %></td>
18
- </tr>
19
- <% end %>
20
- </tbody>
21
- </table>
22
-
23
- <h1>Listing Admins</h1>
24
-
25
- <table>
26
- <thead>
27
- <tr>
28
- <th colspan="3"></th>
29
- </tr>
30
- </thead>
31
-
32
- <tbody>
33
- <% Admin.all.each do |admin| %>
34
- <tr>
35
- <td><%= admin.user.email %></td>
36
- <td><%= admin.user.name %></td>
37
- <td><%= link_to 'Notifications', admin_notifications_path(admin) %></td>
38
- </tr>
39
- <% end %>
40
- </tbody>
41
- </table>
42
-
43
- <h1>Listing Articles</h1>
44
-
45
- <table>
46
- <thead>
47
- <tr>
48
- <th colspan="5"></th>
49
- </tr>
50
- </thead>
51
-
52
- <tbody>
53
- <% @articles.each do |article| %>
54
- <tr>
55
- <td><%= article.user.name %></td>
56
- <td><%= article.title %></td>
57
- <td><%= link_to 'Show', article %></td>
58
- <td><%= link_to 'Edit', edit_article_path(article) if user_signed_in? and current_user == article.user %></td>
59
- <td><%= link_to 'Destroy', article, method: :delete, data: { confirm: 'Are you sure?' } %></td>
60
- </tr>
61
- <% end %>
62
- </tbody>
63
- </table>
64
-
65
- <br>
66
-
67
- <%= link_to 'New Article', new_article_path %>
1
+ <section>
2
+ <h1>Listing Users</h1>
3
+ <% User.all.each do |user| %>
4
+ <div class="list_wrapper">
5
+ <div class="list_image"></div>
6
+ <div class="list_description_wrapper">
7
+ <p class="list_description">
8
+ <span><%= user.name %></span> · <%= user.email %><br>
9
+ <%= link_to 'Notifications', user_notifications_path(user) %>
10
+ </p>
11
+ </div>
12
+ </div>
13
+ <% end %>
14
+ </section>
15
+
16
+ <section>
17
+ <h1>Listing Admins</h1>
18
+ <% Admin.all.each do |admin| %>
19
+ <div class="list_wrapper">
20
+ <div class="list_image"></div>
21
+ <div class="list_description_wrapper">
22
+ <p class="list_description">
23
+ <span><%= admin.user.name %></span> · <%= admin.user.email %><br>
24
+ <%= link_to 'Notifications', admin_notifications_path(admin) %>
25
+ </p>
26
+ </div>
27
+ </div>
28
+ <% end %>
29
+ </section>
30
+
31
+ <section>
32
+ <div class="create_button_wrapper">
33
+ <%= link_to 'New Article', new_article_path, class: "create_button green_button" %>
34
+ </div>
35
+ <h1>Listing Articles</h1>
36
+ <% @articles.each do |article| %>
37
+ <div class="list_wrapper">
38
+ <div class="list_image large"></div>
39
+ <div class="list_description_wrapper">
40
+ <h3 class="list_title">
41
+ <%= link_to article.title, article %>
42
+ </h3>
43
+ <p class="list_description">
44
+ <span><%= article.user.name %></span> · <%= article.created_at.strftime("%b %d %H:%M") %><br>
45
+ <%= article.body.truncate(60) if article.body.present? %><br>
46
+ <%= link_to 'Read', article %>
47
+ </p>
48
+ <div class="list_button_wrapper">
49
+ <% if user_signed_in? and article.author?(current_user) %>
50
+ <%= link_to 'Edit Article', edit_article_path(article), class: "gray_button" %>
51
+ <% end %>
52
+ <% if user_signed_in? and (article.author?(current_user) or current_user.admin?) %>
53
+ <%= link_to 'Destroy Article', article, method: :delete, data: { confirm: 'Are you sure?' }, class: "gray_button" %>
54
+ <% end %>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ <% end %>
59
+ </section>
@@ -1,5 +1,7 @@
1
- <h1>New Article</h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Back', articles_path %>
1
+ <section>
2
+ <h1>New Article</h1>
3
+ <%= render partial: 'form', locals: { submit_message: "Create Article" } %>
4
+ <div class="left_button_wrapper">
5
+ <%= link_to 'Back', articles_path, class: "gray_button" %>
6
+ </div>
7
+ </section>
@@ -1,38 +1,49 @@
1
- <p id="notice"><%= notice %></p>
2
-
3
- <h1><%= @article.title %></h1>
4
- <p><%= @article.user.name %></p>
5
- <p><%= @article.body %></p>
6
- <%= link_to 'Edit', edit_article_path(@article) %> |
7
- <%= link_to 'Destroy', @article, method: :delete, data: { confirm: 'Are you sure?' } %>
8
- <%= link_to 'Back', articles_path %>
9
-
10
- <h2>Listing Comments</h2>
11
-
12
- <table>
13
- <thead>
14
- <tr>
15
- <th colspan="3"></th>
16
- </tr>
17
- </thead>
18
-
19
- <tbody>
20
- <% @article.comments.each do |comment| %>
21
- <tr>
22
- <td><%= comment.user.name %></td>
23
- <td><%= comment.body %></td>
24
- <td><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
25
- </tr>
1
+ <section>
2
+ <h1><%= @article.title %></h1>
3
+ <p><%= @article.body %></p>
4
+ <div class="list_wrapper">
5
+ <div class="list_image"></div>
6
+ <div class="list_description_wrapper">
7
+ <p class="list_description">
8
+ <span><%= @article.user.name %></span> · <%= @article.created_at.strftime("%b %d %H:%M") %><br>
9
+ </p>
10
+ <div class="list_button_wrapper">
11
+ <%= link_to 'Edit Article', edit_article_path(@article), class: "gray_button" %>
12
+ <%= link_to 'Destroy Article', @article, method: :delete, data: { confirm: 'Are you sure?' }, class: "gray_button" %>
13
+ </div>
14
+ </div>
15
+ </div>
16
+ <h2>Listing Comments</h2>
17
+ <% @article.comments.includes(:user).each do |comment| %>
18
+ <div class="list_wrapper">
19
+ <div class="list_image"></div>
20
+ <div class="list_description_wrapper">
21
+ <p class="list_description">
22
+ <span><%= comment.user.name %></span> · <%= comment.created_at.strftime("%b %d %H:%M") %><br>
23
+ <%= comment.body %>
24
+ </p>
25
+ <div class="list_button_wrapper">
26
+ <% if user_signed_in? and (comment.author?(current_user) or current_user.admin?) %>
27
+ <%= link_to 'Destroy Comment', comment, method: :delete, data: { confirm: 'Are you sure?' }, class: "gray_button" %>
28
+ <% end %>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ <% end %>
33
+ <% if user_signed_in? %>
34
+ <%= form_for(@comment) do |f| %>
35
+ <%= f.hidden_field :article_id, value: @article.id %>
36
+ <div class="textarea_wrapper">
37
+ <%= f.text_area :body, placeholder: "Write a comment..." %>
38
+ </div>
39
+ <div class="submit_button_wrapper">
40
+ <button class="green_button" type="submit">
41
+ Create Comment
42
+ </button>
43
+ </div>
26
44
  <% end %>
27
- </tbody>
28
- </table>
29
-
30
- <h2>New Comment</h2>
31
- <%= form_for(@comment) do |f| %>
32
- <%= f.hidden_field :article_id, value: @article.id %>
33
- <%= f.text_area :body %>
34
-
35
- <div class="actions">
36
- <%= f.submit %>
45
+ <% end %>
46
+ <div class="left_button_wrapper">
47
+ <%= link_to 'Back', articles_path, class: "gray_button" %>
37
48
  </div>
38
- <% end %>
49
+ </section>
@@ -1,10 +1,37 @@
1
- <%= link_to 'Root', root_path %>
2
- <% if user_signed_in? %>
3
- <%= "Login as #{current_user.name}" %>
4
- <%= link_to 'Logout', destroy_user_session_path, method: :delete %>
5
- <%#= render_notifications_of current_user, fallback: :default, index_content: :simple %>
6
- <%= render_notifications_of current_user, fallback: :default, index_content: :with_attributes %>
7
- <%#= render_notifications_of current_user, fallback: :default, index_content: :none %>
8
- <% else %>
9
- <%= link_to 'Login', new_user_session_path %>
1
+ <% if notice.present? %>
2
+ <div class="notice_wrapper">
3
+ <p class="notice">
4
+ <%= notice %>
5
+ </p>
6
+ </div>
10
7
  <% end %>
8
+
9
+ <header>
10
+ <div class="header_area">
11
+ <div class="header_root_wrapper">
12
+ <%= link_to 'ActivityNotification', root_path %>
13
+ </div>
14
+ <div class="header_menu_wrapper">
15
+ <p>
16
+ <% if user_signed_in? %>
17
+ <%= current_user.name %>
18
+ <%= "(admin)" if current_user.admin? %>
19
+ <%= link_to 'Logout', destroy_user_session_path, method: :delete %>
20
+ <% else %>
21
+ <%= link_to 'Login', new_user_session_path %>
22
+ <% end %>
23
+ </p>
24
+ </div>
25
+ <div class="header_notification_wrapper">
26
+ <% if user_signed_in? %>
27
+ <%= render_notifications_of current_user, fallback: :default, index_content: :with_attributes %>
28
+ <% end %>
29
+ </div>
30
+ <div class="header_menu_wrapper">
31
+ <p>
32
+ <%= link_to 'Preview email', "/rails/mailers" %>
33
+ <%= " · " unless user_signed_in? %>
34
+ </p>
35
+ </div>
36
+ </div>
37
+ </header>
@@ -1,13 +1,15 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Dummy</title>
5
- <%#= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track': true %>
4
+ <title>ActivityNotification</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all' %>
6
+ <%= javascript_include_tag 'application' %>
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
- <%= render 'layouts/header' %>
11
- <%= yield %>
10
+ <%= render 'layouts/header' %>
11
+ <article>
12
+ <%= yield %>
13
+ </article>
12
14
  </body>
13
- </html>
15
+ </html>
@@ -41,4 +41,13 @@ Rails.application.configure do
41
41
 
42
42
  # For devise and notification email
43
43
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
44
+
45
+ # For notification email preview
46
+ config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
47
+
48
+ # Configration for bullet
49
+ config.after_initialize do
50
+ Bullet.enable = true
51
+ Bullet.alert = true
52
+ end
44
53
  end
@@ -23,6 +23,6 @@ ActivityNotification.configure do |config|
23
23
  # config.parent_mailer = 'ActionMailer::Base'
24
24
 
25
25
  # Configure default limit number of opened notifications you can get from opened* scope
26
- config.opened_limit = 10
26
+ config.opened_index_limit = 10
27
27
 
28
28
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -17,54 +16,50 @@ ActiveRecord::Schema.define(version: 20160715050433) do
17
16
  t.integer "user_id"
18
17
  t.datetime "created_at"
19
18
  t.datetime "updated_at"
19
+ t.index ["user_id"], name: "index_admins_on_user_id"
20
20
  end
21
21
 
22
- add_index "admins", ["user_id"], name: "index_admins_on_user_id"
23
-
24
22
  create_table "articles", force: :cascade do |t|
25
23
  t.integer "user_id"
26
24
  t.string "title"
27
25
  t.string "body"
28
26
  t.datetime "created_at"
29
27
  t.datetime "updated_at"
28
+ t.index ["user_id"], name: "index_articles_on_user_id"
30
29
  end
31
30
 
32
- add_index "articles", ["user_id"], name: "index_articles_on_user_id"
33
-
34
31
  create_table "comments", force: :cascade do |t|
35
32
  t.integer "user_id"
36
33
  t.integer "article_id"
37
34
  t.string "body"
38
35
  t.datetime "created_at"
39
36
  t.datetime "updated_at"
37
+ t.index ["article_id"], name: "index_comments_on_article_id"
38
+ t.index ["user_id"], name: "index_comments_on_user_id"
40
39
  end
41
40
 
42
- add_index "comments", ["article_id"], name: "index_comments_on_article_id"
43
- add_index "comments", ["user_id"], name: "index_comments_on_user_id"
44
-
45
41
  create_table "notifications", force: :cascade do |t|
46
- t.integer "target_id", null: false
47
42
  t.string "target_type", null: false
48
- t.integer "notifiable_id", null: false
43
+ t.integer "target_id", null: false
49
44
  t.string "notifiable_type", null: false
45
+ t.integer "notifiable_id", null: false
50
46
  t.string "key", null: false
51
- t.integer "group_id"
52
47
  t.string "group_type"
48
+ t.integer "group_id"
53
49
  t.integer "group_owner_id"
54
- t.integer "notifier_id"
55
50
  t.string "notifier_type"
51
+ t.integer "notifier_id"
56
52
  t.text "parameters"
57
53
  t.datetime "opened_at"
58
54
  t.datetime "created_at"
59
55
  t.datetime "updated_at"
56
+ t.index ["group_owner_id"], name: "index_notifications_on_group_owner_id"
57
+ t.index ["group_type", "group_id"], name: "index_notifications_on_group_type_and_group_id"
58
+ t.index ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable_type_and_notifiable_id"
59
+ t.index ["notifier_type", "notifier_id"], name: "index_notifications_on_notifier_type_and_notifier_id"
60
+ t.index ["target_type", "target_id"], name: "index_notifications_on_target_type_and_target_id"
60
61
  end
61
62
 
62
- add_index "notifications", ["group_owner_id"], name: "index_notifications_on_group_owner_id"
63
- add_index "notifications", ["group_type", "group_id"], name: "index_notifications_on_group_type_and_group_id"
64
- add_index "notifications", ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable_type_and_notifiable_id"
65
- add_index "notifications", ["notifier_type", "notifier_id"], name: "index_notifications_on_notifier_type_and_notifier_id"
66
- add_index "notifications", ["target_type", "target_id"], name: "index_notifications_on_target_type_and_target_id"
67
-
68
63
  create_table "users", force: :cascade do |t|
69
64
  t.string "email", default: "", null: false
70
65
  t.string "encrypted_password", default: "", null: false
@@ -74,8 +69,7 @@ ActiveRecord::Schema.define(version: 20160715050433) do
74
69
  t.string "name"
75
70
  t.datetime "created_at"
76
71
  t.datetime "updated_at"
72
+ t.index ["email"], name: "index_users_on_email"
77
73
  end
78
74
 
79
- add_index "users", ["email"], name: "index_users_on_email"
80
-
81
75
  end