commontator 2.0.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +20 -2
  4. data/app/controllers/commontator/comments_controller.rb +19 -11
  5. data/app/controllers/commontator/subscriptions_controller.rb +5 -5
  6. data/app/controllers/commontator/threads_controller.rb +3 -3
  7. data/app/mailers/commontator/subscriptions_mailer.rb +3 -2
  8. data/app/models/commontator/comment.rb +0 -6
  9. data/app/models/commontator/subscription.rb +0 -4
  10. data/app/models/commontator/thread.rb +4 -7
  11. data/app/views/commontator/comments/_actions.html.erb +1 -1
  12. data/app/views/commontator/comments/_votes.html.erb +4 -4
  13. data/app/views/commontator/shared/_thread.html.erb +1 -1
  14. data/app/views/commontator/subscriptions/_link.html.erb +1 -1
  15. data/app/views/commontator/threads/_show.html.erb +1 -1
  16. data/config/initializers/commontator.rb +1 -1
  17. data/config/routes.rb +15 -15
  18. data/db/migrate/0_install.rb +50 -0
  19. data/db/migrate/0_install.rb~ +3 -3
  20. data/lib/commontator/shared_helper.rb +1 -1
  21. data/lib/commontator/version.rb +1 -1
  22. data/lib/commontator/version.rb~ +1 -1
  23. data/spec/app/controllers/commontator/comments_controller_spec.rb +90 -41
  24. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +16 -16
  25. data/spec/app/controllers/commontator/threads_controller_spec.rb +13 -13
  26. data/spec/app/helpers/commontator/application_helper_spec.rb +1 -1
  27. data/spec/app/helpers/commontator/threads_helper_spec.rb +1 -1
  28. data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb +2 -2
  29. data/spec/app/models/commontator/comment_spec.rb +1 -1
  30. data/spec/app/models/commontator/subscription_spec.rb +1 -1
  31. data/spec/app/models/commontator/thread_spec.rb +1 -1
  32. data/spec/dummy/Rakefile +0 -1
  33. data/spec/dummy/config.ru +1 -1
  34. data/spec/dummy/config/application.rb +4 -36
  35. data/spec/dummy/config/boot.rb +4 -9
  36. data/spec/dummy/config/environment.rb +2 -2
  37. data/spec/dummy/config/environments/development.rb +11 -19
  38. data/spec/dummy/config/environments/production.rb +40 -27
  39. data/spec/dummy/config/environments/test.rb +13 -14
  40. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/spec/dummy/config/initializers/inflections.rb +6 -5
  42. data/spec/dummy/config/initializers/secret_token.rb +7 -2
  43. data/spec/dummy/config/initializers/session_store.rb +0 -5
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  45. data/spec/dummy/config/locales/en.yml +20 -2
  46. data/spec/dummy/db/schema.rb +41 -41
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/test.log +0 -8352
  49. data/spec/lib/commontator/acts_as_commontable_spec.rb +1 -1
  50. data/spec/lib/commontator/acts_as_commontable_spec.rb~ +2 -2
  51. data/spec/lib/commontator/acts_as_commontator_spec.rb +1 -1
  52. data/spec/lib/commontator/commontable_config_spec.rb +1 -1
  53. data/spec/lib/commontator/commontator_config_spec.rb +1 -1
  54. data/spec/lib/commontator/controller_includes_spec.rb +3 -3
  55. data/spec/lib/commontator/shared_helper_spec.rb +7 -3
  56. data/spec/lib/commontator_spec.rb +1 -1
  57. data/spec/{minitest_helper.rb → test_helper.rb} +8 -4
  58. metadata +9 -10
  59. data/app/models/commontator/comment_observer.rb +0 -12
  60. data/db/migrate/0_install_commontator.rb +0 -50
  61. data/spec/app/models/commontator/comment_observer_spec.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e80641594c9354508803c783181a053cadf8d5b
4
- data.tar.gz: 656bda25be213ff0f5186c363d02ac8f63667e07
3
+ metadata.gz: 407651f272db411b6547f9e0a48b8dff5b1bfe23
4
+ data.tar.gz: 69bee372a89c33f4bb4c2e696391f4f73376eea1
5
5
  SHA512:
6
- metadata.gz: afe7369d598e62151110282f724582724e261e44814bf57582ad86221c0a8b3d25b8f530a95023526f8529fc4fb284debafd38c24dcf8e8db7d09b5a33af88cb
7
- data.tar.gz: 295d8301ae86ad273f2604dafcf257f88b44593dc74e105dcb32461c14ee856aa56faf4a5cf99c28743c64ac80fcb919592556e835422f25fc8c0fa0a2f8c581
6
+ metadata.gz: 6a09b58656b2ea37d063e42b88d70289d929a5e07b3b6afec7312f10e6082d006907791b479ff991505ff81a6f3914e81b4380c2def1c0ef92686a8f4dbf3c1e
7
+ data.tar.gz: 9f13d4b9d2eec2fcbed8d96136d28682ae85b5c8fc43bd964bcb7b6dc8c6131eb6c9a04b2cd222ac56f8c3eb4acb11c893f922cf1bcb99edec83ca0a68876745
@@ -1,4 +1,4 @@
1
- Copyright 2012 Rice University
1
+ Copyright 2012-13 Rice University
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -10,12 +10,14 @@ There are 4 steps you must follow to install commontator:
10
10
 
11
11
  1. Gem
12
12
 
13
- Add this line to your application's Gemfile:
13
+ Add this line to your application's Gemfile (for Rails 4+):
14
14
 
15
15
  ```ruby
16
- gem 'commontator', '~> 2.0.2'
16
+ gem 'commontator', '~> 4.0.0'
17
17
  ```
18
18
 
19
+ If you are still using rails 3, use Commontator version 2.0.1 instead.
20
+
19
21
  And then execute:
20
22
 
21
23
  ```sh
@@ -113,6 +115,22 @@ Follow the steps below to add commontator to your models and views:
113
115
 
114
116
  That's it! Commontator is now ready for use.
115
117
 
118
+ ## Voting
119
+
120
+ You can allow users to vote on each others' comments by adding the acts_as_votable gem to your gemfile:
121
+
122
+ ```ruby
123
+ gem 'acts_as_votable'
124
+ ```
125
+
126
+ And enabling the relevant option in commontator's initializer:
127
+
128
+ ```ruby
129
+ config.can_vote_on_comments = true
130
+ ```
131
+
132
+ Note that acts_as_votable is currently incompatible with the protected_attributes gem if config.active_record.whitelist_attributes is set to true.
133
+
116
134
  ## Browser Support
117
135
 
118
136
  No incompatibilities are currently known with any of the major browsers.
@@ -1,10 +1,10 @@
1
1
  module Commontator
2
- class CommentsController < ApplicationController
2
+ class CommentsController < Commontator::ApplicationController
3
3
  before_filter :get_thread, :only => [:new, :create]
4
4
  before_filter :get_comment_and_thread, :except => [:new, :create]
5
5
  before_filter :set_commontable_url, :only => :create
6
6
 
7
- # GET /1/comments/new
7
+ # GET /threads/1/comments/new
8
8
  def new
9
9
  @comment = Comment.new
10
10
  @comment.thread = @thread
@@ -19,9 +19,10 @@ module Commontator
19
19
 
20
20
  end
21
21
 
22
- # POST /1/comments
22
+ # POST /threads/1/comments
23
23
  def create
24
- @comment = Comment.new(params[:comment])
24
+ @comment = Comment.new
25
+ @comment.body = params[:comment].nil? ? nil : params[:comment][:body]
25
26
  @comment.thread = @thread
26
27
  @comment.creator = @user
27
28
 
@@ -29,6 +30,12 @@ module Commontator
29
30
 
30
31
  respond_to do |format|
31
32
  if @comment.save
33
+ @thread.subscribe(@user) if @thread.config.auto_subscribe_on_comment
34
+ @thread.add_unread_except_for(@user)
35
+ recipients = @thread.active_subscribers.reject{|s| s == @user}
36
+ SubscriptionsMailer.comment_created(@comment, recipients).deliver \
37
+ unless recipients.empty?
38
+
32
39
  format.html { redirect_to @thread }
33
40
  format.js
34
41
  else
@@ -48,13 +55,14 @@ module Commontator
48
55
  end
49
56
  end
50
57
 
51
- # PUT /comments/1
58
+ # PATCH /comments/1
52
59
  def update
53
60
  raise SecurityTransgression unless @comment.can_be_edited_by?(@user)
61
+ @comment.body = params[:comment].nil? ? nil : params[:comment][:body]
54
62
  @comment.editor = @user
55
63
 
56
64
  respond_to do |format|
57
- if @comment.update_attributes(params[:comment])
65
+ if @comment.save
58
66
  format.html { redirect_to @thread }
59
67
  format.js
60
68
  else
@@ -64,7 +72,7 @@ module Commontator
64
72
  end
65
73
  end
66
74
 
67
- # PUT /comments/1/delete
75
+ # PATCH /comments/1/delete
68
76
  def delete
69
77
  raise SecurityTransgression unless @comment.can_be_deleted_by?(@user)
70
78
 
@@ -77,7 +85,7 @@ module Commontator
77
85
  end
78
86
  end
79
87
 
80
- # PUT /comments/1/undelete
88
+ # PATCH /comments/1/undelete
81
89
  def undelete
82
90
  raise SecurityTransgression unless @comment.can_be_deleted_by?(@user)
83
91
 
@@ -90,7 +98,7 @@ module Commontator
90
98
  end
91
99
  end
92
100
 
93
- # PUT /comments/1/upvote
101
+ # PATCH /comments/1/upvote
94
102
  def upvote
95
103
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
96
104
 
@@ -102,7 +110,7 @@ module Commontator
102
110
  end
103
111
  end
104
112
 
105
- # PUT /comments/1/downvote
113
+ # PATCH /comments/1/downvote
106
114
  def downvote
107
115
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
108
116
 
@@ -114,7 +122,7 @@ module Commontator
114
122
  end
115
123
  end
116
124
 
117
- # PUT /comments/1/unvote
125
+ # PATCH /comments/1/unvote
118
126
  def unvote
119
127
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
120
128
 
@@ -1,9 +1,9 @@
1
1
  module Commontator
2
- class SubscriptionsController < ApplicationController
2
+ class SubscriptionsController < Commontator::ApplicationController
3
3
  before_filter :get_thread
4
4
 
5
- # POST /1/subscribe
6
- def create
5
+ # PATCH /threads/1/subscribe
6
+ def subscribe
7
7
  raise SecurityTransgression unless @thread.can_subscribe?(@user)
8
8
 
9
9
  @thread.errors.add(:subscription, "You are already subscribed to this thread") \
@@ -16,8 +16,8 @@ module Commontator
16
16
 
17
17
  end
18
18
 
19
- # POST /1/unsubscribe
20
- def destroy
19
+ # PATCH /threads/1/unsubscribe
20
+ def unsubscribe
21
21
  raise SecurityTransgression unless @thread.can_subscribe?(@user)
22
22
 
23
23
  @thread.errors.add(:subscription, "You are not subscribed to this thread") \
@@ -1,5 +1,5 @@
1
1
  module Commontator
2
- class ThreadsController < ApplicationController
2
+ class ThreadsController < Commontator::ApplicationController
3
3
  before_filter :get_thread
4
4
  before_filter :set_commontable_url, :only => :show
5
5
 
@@ -13,7 +13,7 @@ module Commontator
13
13
  end
14
14
  end
15
15
 
16
- # PUT /threads/1/close
16
+ # PATCH /threads/1/close
17
17
  def close
18
18
  raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
19
19
 
@@ -26,7 +26,7 @@ module Commontator
26
26
  end
27
27
  end
28
28
 
29
- # PUT /threads/1/reopen
29
+ # PATCH /threads/1/reopen
30
30
  def reopen
31
31
  raise SecurityTransgression unless @thread.can_be_edited_by?(@user)
32
32
 
@@ -6,12 +6,13 @@ module Commontator
6
6
  def comment_created(comment, recipients)
7
7
  setup_variables(comment, recipients)
8
8
 
9
- mail :bcc => @bcc,
9
+ mail :to => 'Undisclosed Recipients',
10
+ :bcc => @bcc,
10
11
  :from => @from,
11
12
  :subject => @subject
12
13
  end
13
14
 
14
- protected
15
+ protected
15
16
 
16
17
  def setup_variables(comment, recipients)
17
18
  @comment = comment
@@ -2,16 +2,12 @@ module Commontator
2
2
  class Comment < ActiveRecord::Base
3
3
  belongs_to :creator, :polymorphic => true
4
4
  belongs_to :editor, :polymorphic => true
5
-
6
5
  belongs_to :thread
7
6
 
8
7
  has_one :commontable, :through => :thread
9
8
 
10
- attr_accessible :body
11
-
12
9
  validates_presence_of :creator, :on => :create
13
10
  validates_presence_of :editor, :on => :update
14
-
15
11
  validates_presence_of :thread
16
12
  validates_presence_of :body
17
13
 
@@ -103,6 +99,4 @@ module Commontator
103
99
  can_be_voted_on? && thread.can_be_read_by?(user) && user != creator
104
100
  end
105
101
  end
106
-
107
- CommentObserver.instance
108
102
  end
@@ -1,13 +1,9 @@
1
1
  module Commontator
2
2
  class Subscription < ActiveRecord::Base
3
3
  belongs_to :subscriber, :polymorphic => true
4
-
5
4
  belongs_to :thread
6
5
 
7
- attr_accessible :subscriber, :thread
8
-
9
6
  validates_presence_of :subscriber, :thread
10
-
11
7
  validates_uniqueness_of :thread_id, :scope => [:subscriber_type, :subscriber_id]
12
8
 
13
9
  def mark_as_read
@@ -1,17 +1,12 @@
1
1
  module Commontator
2
2
  class Thread < ActiveRecord::Base
3
3
  belongs_to :closer, :polymorphic => true
4
-
5
4
  belongs_to :commontable, :polymorphic => true
6
5
 
7
6
  has_many :comments, :dependent => :destroy
8
-
9
7
  has_many :subscriptions, :dependent => :destroy
10
8
 
11
- attr_accessible :is_closed
12
-
13
9
  validates_presence_of :commontable, :unless => :is_closed?
14
-
15
10
  validates_uniqueness_of :commontable_id, :scope => :commontable_type, :allow_nil => true
16
11
 
17
12
  def config
@@ -46,8 +41,10 @@ module Commontator
46
41
 
47
42
  def subscribe(subscriber)
48
43
  return false if is_subscribed?(subscriber) || !subscriber.is_commontator
49
- subscription = Subscription.create(
50
- :subscriber => subscriber, :thread => self)
44
+ subscription = Subscription.new
45
+ subscription.subscriber = subscriber
46
+ subscription.thread = self
47
+ subscription.save
51
48
  end
52
49
 
53
50
  def unsubscribe(subscriber)
@@ -23,7 +23,7 @@
23
23
  :confirm => (!is_deleted ? \
24
24
  "Are you sure you want to delete this " + \
25
25
  "#{comment.thread.config.comment_name}?" : nil),
26
- :method => :put,
26
+ :method => :patch,
27
27
  :id => "comment_#{comment.id.to_s}_#{del_string}_link",
28
28
  :class => "comment_#{del_string}_link",
29
29
  :remote => true %>
@@ -10,7 +10,7 @@
10
10
  <span id="comment_<%= comment.id %>_upvote_span" class="comment_upvote">
11
11
  <% if can_vote && (vote.blank? || !vote.vote_flag) %>
12
12
  <%= form_tag commontator.upvote_comment_path(comment),
13
- :method => :put,
13
+ :method => :patch,
14
14
  :remote => true do %>
15
15
  <%= image_submit_tag "commontator/upvote.png",
16
16
  :onmouseover => "this.src='/assets/commontator/upvote_hover.png'",
@@ -18,7 +18,7 @@
18
18
  <% end %>
19
19
  <% elsif can_vote %>
20
20
  <%= form_tag commontator.unvote_comment_path(comment),
21
- :method => :put,
21
+ :method => :patch,
22
22
  :remote => true do %>
23
23
  <%= image_submit_tag "commontator/upvote_hover.png",
24
24
  :onmouseover => "this.src='/assets/commontator/upvote.png'",
@@ -36,7 +36,7 @@
36
36
  <span id="comment_<%= comment.id %>_downvote_span" class="comment_downvote">
37
37
  <% if can_vote && (vote.blank? || vote.vote_flag) %>
38
38
  <%= form_tag commontator.downvote_comment_path(comment),
39
- :method => :put,
39
+ :method => :patch,
40
40
  :remote => true do %>
41
41
  <%= image_submit_tag "commontator/downvote.png",
42
42
  :onmouseover => "this.src='/assets/commontator/downvote_hover.png'",
@@ -44,7 +44,7 @@
44
44
  <% end %>
45
45
  <% elsif can_vote %>
46
46
  <%= form_tag commontator.unvote_comment_path(comment),
47
- :method => :put,
47
+ :method => :patch,
48
48
  :remote => true do %>
49
49
  <%= image_submit_tag "commontator/downvote_hover.png",
50
50
  :onmouseover => "this.src='/assets/commontator/downvote.png'",
@@ -6,7 +6,7 @@
6
6
  <% subscription = thread.subscription_for(user) %>
7
7
 
8
8
  <% if thread.can_be_read_by?(user) %>
9
- <%= stylesheet_link_tag "commontator/application", :media => "all" %>
9
+ <%= stylesheet_link_tag "commontator/application.css", :media => "all" %>
10
10
 
11
11
  <div id="thread_<%= thread.id %>_div" class="thread" style="display: none;">
12
12
  <% if @commontator_thread_show %>
@@ -10,7 +10,7 @@
10
10
  :confirm => (is_subscribed ? \
11
11
  "Are you sure you want to unsubscribe from this thread?" : \
12
12
  nil),
13
- :method => :put,
13
+ :method => :patch,
14
14
  :id => "thread_#{thread.id.to_s}_#{sub_string}_link",
15
15
  :class => "thread_#{sub_string}_link",
16
16
  :remote => true %>
@@ -28,7 +28,7 @@
28
28
  commontator.polymorphic_path([close_string, thread]),
29
29
  :confirm => (!is_closed ? \
30
30
  'Are you sure you want to close this thread?' : nil),
31
- :method => :put,
31
+ :method => :patch,
32
32
  :id => "thread_#{thread.id.to_s}_#{close_string}_link",
33
33
  :class => "thread_#{close_string}_link",
34
34
  :remote => true %>
@@ -23,7 +23,7 @@ Commontator.configure do |config|
23
23
  config.user_missing_name = 'Anonymous'
24
24
 
25
25
  # Whether the comment creator's name is clickable in the comment view
26
- # If enabled, the link will point to the comment creator's show page
26
+ # If enabled, the link will point to the comment creator's 'show' page
27
27
  # Default: false
28
28
  config.user_name_clickable = false
29
29
 
@@ -1,22 +1,22 @@
1
1
  Commontator::Engine.routes.draw do
2
2
  resources :threads, :only => [:show] do
3
3
  resources :comments, :except => [:index, :destroy], :shallow => true do
4
- put 'delete', :on => :member
5
- put 'undelete', :on => :member
6
-
7
- put 'upvote', :on => :member
8
- put 'downvote', :on => :member
9
- put 'unvote', :on => :member
4
+ member do
5
+ patch 'delete'
6
+ patch 'undelete'
7
+
8
+ patch 'upvote'
9
+ patch 'downvote'
10
+ patch 'unvote'
11
+ end
10
12
  end
11
13
 
12
- put 'close', :on => :member
13
- put 'reopen', :on => :member
14
-
15
- put 'subscribe', :to => 'subscriptions#create',
16
- :as => 'subscribe',
17
- :on => :member
18
- put 'unsubscribe', :to => 'subscriptions#destroy',
19
- :as => 'unsubscribe',
20
- :on => :member
14
+ member do
15
+ patch 'close'
16
+ patch 'reopen'
17
+
18
+ patch 'subscribe', :to => 'subscriptions#subscribe'
19
+ patch 'unsubscribe', :to => 'subscriptions#unsubscribe'
20
+ end
21
21
  end
22
22
  end
@@ -0,0 +1,50 @@
1
+ class Install < ActiveRecord::Migration
2
+ def change
3
+ create_table 'commontator_comments' do |t|
4
+ t.string 'creator_type'
5
+ t.integer 'creator_id'
6
+ t.string 'editor_type'
7
+ t.integer 'editor_id'
8
+ t.integer 'thread_id', :null => false
9
+ t.text 'body', :null => false
10
+ t.datetime 'deleted_at'
11
+
12
+ t.integer 'cached_votes_total', :default => 0
13
+ t.integer 'cached_votes_up', :default => 0
14
+ t.integer 'cached_votes_down', :default => 0
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ add_index :commontator_comments, [:creator_type, :creator_id, :thread_id], :name => 'index_c_c_on_c_type_and_c_id_and_t_id'
20
+ add_index :commontator_comments, :thread_id
21
+
22
+ add_index :commontator_comments, :cached_votes_total
23
+ add_index :commontator_comments, :cached_votes_up
24
+ add_index :commontator_comments, :cached_votes_down
25
+
26
+ create_table 'commontator_subscriptions' do |t|
27
+ t.string 'subscriber_type', :null => false
28
+ t.integer 'subscriber_id', :null => false
29
+ t.integer 'thread_id', :null => false
30
+ t.integer 'unread', :null => false, :default => 0
31
+
32
+ t.timestamps
33
+ end
34
+
35
+ add_index :commontator_subscriptions, [:subscriber_type, :subscriber_id, :thread_id], :unique => true, :name => 'index_c_s_on_s_type_and_s_id_and_t_id'
36
+ add_index :commontator_subscriptions, :thread_id
37
+
38
+ create_table 'commontator_threads' do |t|
39
+ t.string 'commontable_type'
40
+ t.integer 'commontable_id'
41
+ t.datetime 'closed_at'
42
+ t.string 'closer_type'
43
+ t.integer 'closer_id'
44
+
45
+ t.timestamps
46
+ end
47
+
48
+ add_index :commontator_threads, [:commontable_type, :commontable_id], :unique => true, :name => 'index_c_t_on_c_type_and_c_id'
49
+ end
50
+ end