commontator 4.11.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -5
  3. data/app/controllers/commontator/application_controller.rb +4 -4
  4. data/app/controllers/commontator/comments_controller.rb +15 -15
  5. data/app/controllers/commontator/subscriptions_controller.rb +1 -1
  6. data/app/controllers/commontator/threads_controller.rb +5 -5
  7. data/app/mailers/commontator/subscriptions_mailer.rb +25 -37
  8. data/app/models/commontator/comment.rb +11 -11
  9. data/app/models/commontator/subscription.rb +2 -2
  10. data/app/models/commontator/thread.rb +9 -9
  11. data/app/views/commontator/comments/_actions.html.erb +8 -8
  12. data/app/views/commontator/comments/_body.html.erb +1 -1
  13. data/app/views/commontator/comments/_form.html.erb +3 -3
  14. data/app/views/commontator/comments/_list.html.erb +3 -3
  15. data/app/views/commontator/comments/_show.html.erb +8 -8
  16. data/app/views/commontator/comments/_votes.html.erb +16 -16
  17. data/app/views/commontator/comments/cancel.js.erb +5 -5
  18. data/app/views/commontator/comments/create.js.erb +9 -9
  19. data/app/views/commontator/comments/delete.js.erb +7 -7
  20. data/app/views/commontator/comments/edit.js.erb +2 -2
  21. data/app/views/commontator/comments/new.js.erb +4 -4
  22. data/app/views/commontator/comments/update.js.erb +1 -1
  23. data/app/views/commontator/comments/vote.js.erb +3 -3
  24. data/app/views/commontator/shared/_thread.html.erb +6 -6
  25. data/app/views/commontator/subscriptions/_link.html.erb +5 -5
  26. data/app/views/commontator/subscriptions/subscribe.js.erb +3 -3
  27. data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +6 -6
  28. data/app/views/commontator/threads/_reply.html.erb +6 -6
  29. data/app/views/commontator/threads/_show.html.erb +33 -33
  30. data/app/views/commontator/threads/_show.js.erb +7 -7
  31. data/app/views/commontator/threads/show.js.erb +6 -6
  32. data/config/initializers/commontator.rb +43 -38
  33. data/config/locales/de.yml +100 -0
  34. data/config/locales/en.yml +26 -27
  35. data/config/locales/pt-BR.yml +78 -0
  36. data/config/locales/ru.yml +25 -26
  37. data/config/locales/zh.yml +26 -27
  38. data/config/routes.rb +4 -4
  39. data/db/migrate/0_install_commontator.rb +17 -17
  40. data/lib/commontator.rb +2 -2
  41. data/lib/commontator/acts_as_commontable.rb +14 -12
  42. data/lib/commontator/acts_as_commontator.rb +5 -5
  43. data/lib/commontator/shared_helper.rb +6 -6
  44. data/lib/commontator/version.rb +1 -1
  45. data/lib/tasks/commontator_tasks.rake +2 -2
  46. data/spec/controllers/commontator/comments_controller_spec.rb +76 -75
  47. data/spec/controllers/commontator/subscriptions_controller_spec.rb +26 -27
  48. data/spec/controllers/commontator/threads_controller_spec.rb +42 -41
  49. data/spec/dummy/app/controllers/dummy_models_controller.rb +1 -1
  50. data/spec/dummy/app/views/layouts/application.html.erb +1 -2
  51. data/spec/dummy/config/application.rb +1 -1
  52. data/spec/dummy/config/environments/development.rb +1 -2
  53. data/spec/dummy/config/environments/production.rb +1 -2
  54. data/spec/dummy/config/environments/test.rb +1 -2
  55. data/spec/dummy/config/initializers/commontator.rb +7 -7
  56. data/spec/dummy/config/routes.rb +2 -3
  57. data/spec/dummy/db/development.sqlite3 +0 -0
  58. data/spec/dummy/db/migrate/1_create_dummy_models.rb +2 -3
  59. data/spec/dummy/db/migrate/2_create_dummy_users.rb +2 -3
  60. data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +4 -10
  61. data/spec/dummy/db/schema.rb +45 -48
  62. data/spec/dummy/db/test.sqlite3 +0 -0
  63. data/spec/dummy/log/development.log +413 -0
  64. data/spec/dummy/log/test.log +33690 -0
  65. data/spec/lib/commontator/commontable_config_spec.rb +4 -5
  66. data/spec/lib/commontator/commontator_config_spec.rb +4 -5
  67. data/spec/lib/commontator_spec.rb +2 -3
  68. data/spec/mailers/commontator/subscriptions_mailer_spec.rb +2 -3
  69. data/spec/models/commontator/comment_spec.rb +10 -10
  70. data/spec/rails_helper.rb +3 -2
  71. metadata +64 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba13938d041038942002c5071726bcc5ed4c440a
4
- data.tar.gz: 30ce7ec6b5a1837ac7330402ccad880de3cc4a00
3
+ metadata.gz: fcd57c56f76291406b85f24de5a0ad2235c350ca
4
+ data.tar.gz: 8af611ffdae4c578f9a784b39f10a1d4a9860503
5
5
  SHA512:
6
- metadata.gz: 86dadff77fd7beffe86f9e396f3913e38ad36a05b9401b5e8bea02c2256feec3221cf784e4a79a54efbabd7762d613e28b63241ec442c32e445981b9ee6b3329
7
- data.tar.gz: f6dc996037639730d9567a4fd1133c4a7a93615fefbad780f45bc122761dcd886161fe3f5e172ee0c5ff7b99545ecff7a964f7c52271c9a2ab6b861a93f4e445
6
+ metadata.gz: 328b21764347f350e0bbef130ab82bf5d26bb5866d8e864261e6080fc9a1052368f505d1a5ff2fbd947c5bc9fe123fe95fd7f6d321e9809ad199f21e7d898681
7
+ data.tar.gz: 9db4ba13a3576b3629239496012bdf92c096aa0f5f6377919a249026da2097ceb9519ac3a55c25990c0539482fc40c0a903ee6d51e3d3a8f47a8e0bd9e9b4db5
data/README.md CHANGED
@@ -132,7 +132,7 @@ That's it! Commontator is now ready for use.
132
132
  When you enable subscriptions, emails are sent automatically by Commontator. If sending emails, remember to add your host URL's to your environment files (test.rb, development.rb and production.rb):
133
133
 
134
134
  ```rb
135
- config.action_mailer.default_url_options = { :host => "www.example.com" }
135
+ config.action_mailer.default_url_options = { host: "www.example.com" }
136
136
  ```
137
137
 
138
138
  Batch sending through Mailgun is also supported and automatically detected.
@@ -172,12 +172,13 @@ Then enable mentions in commontator's initializer:
172
172
  config.mentions_enabled = true
173
173
  ```
174
174
 
175
- Finally configure the user_mentions_proc, which receives the current user
176
- and the search query inputted by that user and should return a relation
177
- containing the users that can be mentioned and match the query string:
175
+ Finally configure the user_mentions_proc, which receives the current user,
176
+ the current thread, and the search query inputted by that user and should
177
+ return a relation containing the users that can be mentioned and match the
178
+ query string:
178
179
 
179
180
  ```rb
180
- config.user_mentions_proc = lambda { |current_user, query| ... }
181
+ config.user_mentions_proc = ->(current_user, thread, query) { ... }
181
182
  ```
182
183
 
183
184
  Please be aware that with mentions enabled, any registered user
@@ -1,9 +1,9 @@
1
1
  module Commontator
2
2
  class ApplicationController < ActionController::Base
3
- before_filter :set_user, :ensure_user
4
-
5
- rescue_from SecurityTransgression, :with => lambda { head(:forbidden) }
6
-
3
+ before_action :set_user, :ensure_user
4
+
5
+ rescue_from SecurityTransgression, with: -> { head(:forbidden) }
6
+
7
7
  protected
8
8
 
9
9
  def security_transgression_unless(check)
@@ -1,7 +1,7 @@
1
1
  module Commontator
2
2
  class CommentsController < Commontator::ApplicationController
3
- before_filter :set_thread, :only => [:new, :create]
4
- before_filter :set_comment_and_thread, :except => [:new, :create]
3
+ before_action :set_thread, only: [:new, :create]
4
+ before_action :set_comment_and_thread, except: [:new, :create]
5
5
 
6
6
  # GET /threads/1/comments/new
7
7
  def new
@@ -16,7 +16,7 @@ module Commontator
16
16
  format.html { redirect_to @thread }
17
17
  format.js
18
18
  end
19
-
19
+
20
20
  end
21
21
 
22
22
  # POST /threads/1/comments
@@ -27,7 +27,7 @@ module Commontator
27
27
  @comment.body = params[:comment].nil? ? nil : params[:comment][:body]
28
28
  security_transgression_unless @comment.can_be_created_by?(@user)
29
29
  subscribe_mentioned if Commontator.mentions_enabled
30
-
30
+
31
31
  respond_to do |format|
32
32
  if !params[:cancel].nil?
33
33
  format.html { redirect_to @thread }
@@ -91,7 +91,7 @@ module Commontator
91
91
  format.js { render :delete }
92
92
  end
93
93
  end
94
-
94
+
95
95
  # PUT /comments/1/undelete
96
96
  def undelete
97
97
  security_transgression_unless @comment.can_be_deleted_by?(@user)
@@ -104,11 +104,11 @@ module Commontator
104
104
  format.js { render :delete }
105
105
  end
106
106
  end
107
-
107
+
108
108
  # PUT /comments/1/upvote
109
109
  def upvote
110
110
  security_transgression_unless @comment.can_be_voted_on_by?(@user)
111
-
111
+
112
112
  @comment.upvote_from @user
113
113
 
114
114
  respond_to do |format|
@@ -116,12 +116,12 @@ module Commontator
116
116
  format.js { render :vote }
117
117
  end
118
118
  end
119
-
119
+
120
120
  # PUT /comments/1/downvote
121
121
  def downvote
122
122
  security_transgression_unless @comment.can_be_voted_on_by?(@user) &&\
123
123
  @comment.thread.config.comment_voting.to_sym == :ld
124
-
124
+
125
125
  @comment.downvote_from @user
126
126
 
127
127
  respond_to do |format|
@@ -129,21 +129,21 @@ module Commontator
129
129
  format.js { render :vote }
130
130
  end
131
131
  end
132
-
132
+
133
133
  # PUT /comments/1/unvote
134
134
  def unvote
135
135
  security_transgression_unless @comment.can_be_voted_on_by?(@user)
136
-
137
- @comment.unvote :voter => @user
136
+
137
+ @comment.unvote voter: @user
138
138
 
139
139
  respond_to do |format|
140
140
  format.html { redirect_to @thread }
141
141
  format.js { render :vote }
142
142
  end
143
143
  end
144
-
144
+
145
145
  protected
146
-
146
+
147
147
  def set_comment_and_thread
148
148
  @comment = Comment.find(params[:id])
149
149
  @thread = @comment.thread
@@ -151,7 +151,7 @@ module Commontator
151
151
  end
152
152
 
153
153
  def subscribe_mentioned
154
- Commontator.commontator_mentions(@user, '').where(id: params[:mentioned_ids]).each do |user|
154
+ Commontator.commontator_mentions(@user, @thread, '').where(id: params[:mentioned_ids]).each do |user|
155
155
  @thread.subscribe(user)
156
156
  end
157
157
  end
@@ -1,6 +1,6 @@
1
1
  module Commontator
2
2
  class SubscriptionsController < Commontator::ApplicationController
3
- before_filter :set_thread
3
+ before_action :set_thread
4
4
 
5
5
  # PUT /threads/1/subscribe
6
6
  def subscribe
@@ -1,7 +1,7 @@
1
1
  module Commontator
2
2
  class ThreadsController < Commontator::ApplicationController
3
- skip_before_filter :ensure_user, :only => :show
4
- before_filter :set_thread
3
+ skip_before_action :ensure_user, only: :show
4
+ before_action :set_thread
5
5
 
6
6
  # GET /threads/1
7
7
  def show
@@ -13,7 +13,7 @@ module Commontator
13
13
  format.js
14
14
  end
15
15
  end
16
-
16
+
17
17
  # PUT /threads/1/close
18
18
  def close
19
19
  security_transgression_unless @thread.can_be_edited_by?(@user)
@@ -28,7 +28,7 @@ module Commontator
28
28
  format.js { render :show }
29
29
  end
30
30
  end
31
-
31
+
32
32
  # PUT /threads/1/reopen
33
33
  def reopen
34
34
  security_transgression_unless @thread.can_be_edited_by?(@user)
@@ -60,7 +60,7 @@ module Commontator
60
60
  protected
61
61
 
62
62
  def serialized_mentions(query)
63
- { mentions: Commontator.commontator_mentions(@user, query).map do |user|
63
+ { mentions: Commontator.commontator_mentions(@user, @thread, query).map do |user|
64
64
  { id: user.id, name: Commontator.commontator_name(user), type: 'user' }
65
65
  end }
66
66
  end
@@ -2,15 +2,10 @@ module Commontator
2
2
  class SubscriptionsMailer < ActionMailer::Base
3
3
  def comment_created(comment, recipients)
4
4
  setup_variables(comment, recipients)
5
- message = mail :to => @to,
6
- :bcc => @bcc,
7
- :from => @from,
8
- :subject => t('commontator.email.comment_created.subject',
9
- :creator_name => @creator_name,
10
- :commontable_name => @commontable_name,
11
- :comment_url => @comment_url)
12
-
13
- message.mailgun_recipient_variables = mailgun_recipient_variables(recipients) if uses_mailgun?
5
+
6
+ mail(@mail_params).tap do |message|
7
+ message.mailgun_recipient_variables = @mailgun_recipient_variables if @using_mailgun
8
+ end
14
9
  end
15
10
 
16
11
  protected
@@ -20,42 +15,35 @@ module Commontator
20
15
  @thread = @comment.thread
21
16
  @creator = @comment.creator
22
17
 
23
- @creator_name = Commontator.commontator_name(@creator)
24
-
25
- @commontable_name = Commontator.commontable_name(@thread)
18
+ @mail_params = { from: @thread.config.email_from_proc.call(@thread) }
26
19
 
27
- @comment_url = Commontator.comment_url(@comment, main_app)
20
+ @recipient_emails = recipients.map do |recipient|
21
+ Commontator.commontator_email(recipient, self)
22
+ end
28
23
 
29
- params = Hash.new
30
- params[:comment] = @comment
31
- params[:thread] = @thread
32
- params[:creator] = @creator
33
- params[:creator_name] = @creator_name
34
- params[:commontable_name] = @commontable_name
35
- params[:comment_url] = @comment_url
24
+ @using_mailgun = Rails.application.config.action_mailer.delivery_method == :mailgun
36
25
 
37
- if uses_mailgun?
38
- @to = recipient_emails(recipients)
26
+ if @using_mailgun
27
+ @recipients_header = :to
28
+ @mailgun_recipient_variables = {}.tap do |mailgun_recipient_variables|
29
+ @recipient_emails.each { |email| mailgun_recipient_variables[email] = {} }
30
+ end
39
31
  else
40
- @to = t('commontator.email.undisclosed_recipients')
41
- @bcc = recipient_emails(recipients)
32
+ @recipients_header = :bcc
42
33
  end
43
34
 
44
- @from = @thread.config.email_from_proc.call(@thread)
45
- end
35
+ @mail_params[@recipients_header] = @recipient_emails
46
36
 
47
- def recipient_emails(recipients)
48
- recipients.collect{ |s| Commontator.commontator_email(s, self) }
49
- end
50
-
51
- def mailgun_recipient_variables(recipients)
52
- recipient_emails(recipients).each_with_object({}) do |user_email, memo|
53
- memo[user_email] = {}
54
- end
55
- end
37
+ @creator_name = Commontator.commontator_name(@creator)
38
+ @commontable_name = Commontator.commontable_name(@thread)
39
+ @comment_url = Commontator.comment_url(@comment, main_app)
56
40
 
57
- def uses_mailgun?
58
- Rails.application.config.action_mailer.delivery_method == :mailgun
41
+ @mail_params[:subject] = t(
42
+ 'commontator.email.comment_created.subject',
43
+ creator_name: @creator_name,
44
+ commontable_name: @commontable_name,
45
+ comment_url: @comment_url
46
+ )
59
47
  end
60
48
  end
61
49
  end
@@ -1,17 +1,17 @@
1
1
  module Commontator
2
2
  class Comment < ActiveRecord::Base
3
- belongs_to :creator, :polymorphic => true
4
- belongs_to :editor, :polymorphic => true
3
+ belongs_to :creator, polymorphic: true
4
+ belongs_to :editor, polymorphic: true, optional: true
5
5
  belongs_to :thread
6
6
 
7
- validates_presence_of :creator, :on => :create
8
- validates_presence_of :editor, :on => :update
7
+ validates_presence_of :creator, on: :create
8
+ validates_presence_of :editor, on: :update
9
9
  validates_presence_of :thread
10
10
  validates_presence_of :body
11
11
 
12
12
  validates_uniqueness_of :body,
13
- :scope => [:creator_type, :creator_id, :thread_id, :deleted_at],
14
- :message => I18n.t('commontator.comment.errors.double_posted')
13
+ scope: [:creator_type, :creator_id, :thread_id, :deleted_at],
14
+ message: I18n.t('commontator.comment.errors.double_posted')
15
15
 
16
16
  protected
17
17
 
@@ -36,7 +36,7 @@ module Commontator
36
36
 
37
37
  def get_vote_by(user)
38
38
  return nil unless is_votable? && !user.nil? && user.is_commontator
39
- votes_for.where(:voter_type => user.class.name, :voter_id => user.id).first
39
+ votes_for.where(voter_type: user.class.name, voter_id: user.id).first
40
40
  end
41
41
 
42
42
  def update_cached_votes(vote_scope = nil)
@@ -64,13 +64,13 @@ module Commontator
64
64
 
65
65
  def created_timestamp
66
66
  I18n.t 'commontator.comment.status.created_at',
67
- :created_at => I18n.l(created_at, :format => :commontator)
67
+ created_at: I18n.l(created_at, format: :commontator)
68
68
  end
69
-
69
+
70
70
  def updated_timestamp
71
71
  I18n.t 'commontator.comment.status.updated_at',
72
- :editor_name => Commontator.commontator_name(editor || creator),
73
- :updated_at => I18n.l(updated_at, :format => :commontator)
72
+ editor_name: Commontator.commontator_name(editor || creator),
73
+ updated_at: I18n.l(updated_at, format: :commontator)
74
74
  end
75
75
 
76
76
  ##################
@@ -1,10 +1,10 @@
1
1
  module Commontator
2
2
  class Subscription < ActiveRecord::Base
3
- belongs_to :subscriber, :polymorphic => true
3
+ belongs_to :subscriber, polymorphic: true
4
4
  belongs_to :thread
5
5
 
6
6
  validates_presence_of :subscriber, :thread
7
- validates_uniqueness_of :thread_id, :scope => [:subscriber_type, :subscriber_id]
7
+ validates_uniqueness_of :thread_id, scope: [:subscriber_type, :subscriber_id]
8
8
 
9
9
  def self.comment_created(comment)
10
10
  recipients = comment.thread.subscribers.reject{|s| s == comment.creator}
@@ -1,15 +1,15 @@
1
1
  module Commontator
2
2
  class Thread < ActiveRecord::Base
3
- belongs_to :closer, :polymorphic => true
4
- belongs_to :commontable, :polymorphic => true
3
+ belongs_to :closer, polymorphic: true, optional: true
4
+ belongs_to :commontable, polymorphic: true, optional: true
5
5
 
6
- has_many :comments, :dependent => :destroy
7
- has_many :subscriptions, :dependent => :destroy
6
+ has_many :comments, dependent: :destroy
7
+ has_many :subscriptions, dependent: :destroy
8
8
 
9
- validates_presence_of :commontable, :unless => :is_closed?
9
+ validates_presence_of :commontable, unless: :is_closed?
10
10
  validates_uniqueness_of :commontable_id,
11
- :scope => :commontable_type,
12
- :allow_nil => true
11
+ scope: :commontable_type,
12
+ allow_nil: true
13
13
 
14
14
  def config
15
15
  @config ||= commontable.try(:commontable_config) || Commontator
@@ -45,7 +45,7 @@ module Commontator
45
45
  def paginated_comments(page = 1, per_page = config.comments_per_page)
46
46
  oc = ordered_comments
47
47
  return oc unless will_paginate?
48
- oc.paginate(:page => page, :per_page => per_page)
48
+ oc.paginate(page: page, per_page: per_page)
49
49
  end
50
50
 
51
51
  def new_comment_page(per_page = config.comments_per_page)
@@ -91,7 +91,7 @@ module Commontator
91
91
 
92
92
  def subscription_for(subscriber)
93
93
  return nil if !subscriber || !subscriber.is_commontator
94
- subscriber.subscriptions.where(:thread_id => self.id).first
94
+ subscriber.subscriptions.where(thread_id: self.id).first
95
95
  end
96
96
 
97
97
  def subscribe(subscriber)
@@ -9,9 +9,9 @@
9
9
  <% if can_edit %>
10
10
  <%= link_to t('commontator.comment.actions.edit'),
11
11
  commontator.edit_comment_path(comment),
12
- :id => "comment_#{comment.id.to_s}_edit_link",
13
- :class => "comment_edit_link",
14
- :remote => true %>
12
+ id: "comment_#{comment.id.to_s}_edit_link",
13
+ class: "comment_edit_link",
14
+ remote: true %>
15
15
  <% end %>
16
16
 
17
17
  &nbsp;
@@ -21,9 +21,9 @@
21
21
  <% del_string = is_deleted ? 'undelete' : 'delete' %>
22
22
  <%= link_to t("commontator.comment.actions.#{del_string}"),
23
23
  commontator.polymorphic_path([del_string, comment]),
24
- :confirm => (!is_deleted ? t('commontator.comment.actions.confirm_delete') : nil),
25
- :method => :put,
26
- :id => "comment_#{comment.id.to_s}_#{del_string}_link",
27
- :class => "comment_#{del_string}_link",
28
- :remote => true %>
24
+ confirm: (!is_deleted ? t('commontator.comment.actions.confirm_delete') : nil),
25
+ method: :put,
26
+ id: "comment_#{comment.id.to_s}_#{del_string}_link",
27
+ class: "comment_#{del_string}_link",
28
+ remote: true %>
29
29
  <% end %>
@@ -4,5 +4,5 @@
4
4
 
5
5
  <%= simple_format comment.is_deleted? ? \
6
6
  t('commontator.comment.status.deleted_by',
7
- :deleter_name => Commontator.commontator_name(comment.editor)) : \
7
+ deleter_name: Commontator.commontator_name(comment.editor)) : \
8
8
  comment.body %>
@@ -22,18 +22,18 @@
22
22
  <% end %>
23
23
 
24
24
  <%= form_for([commontator, thread, comment],
25
- :remote => !no_remote) do |f| %>
25
+ remote: !no_remote) do |f| %>
26
26
 
27
27
  <%= hidden_field_tag :per_page, per_page %>
28
28
 
29
29
  <div class="comment_form_field">
30
- <%= f.text_area :body, :rows => '7' %>
30
+ <%= f.text_area :body, rows: '7' %>
31
31
  <%= javascript_tag('Commontator.initMentions()') if Commontator.mentions_enabled %>
32
32
  </div>
33
33
 
34
34
  <div class="comment_form_actions">
35
35
  <%= f.submit t("commontator.comment.actions.#{comment.id.blank? ? 'create' : 'update'}") %>
36
- <%= f.submit t('commontator.comment.actions.cancel'), :name => 'cancel' %>
36
+ <%= f.submit t('commontator.comment.actions.cancel'), name: 'cancel' %>
37
37
  </div>
38
38
 
39
39
  <% end %>