commontator 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -1
  3. data/app/controllers/commontator/application_controller.rb~ +27 -0
  4. data/app/controllers/commontator/comments_controller.rb~ +20 -12
  5. data/app/controllers/commontator/subscriptions_controller.rb~ +32 -0
  6. data/app/controllers/commontator/threads_controller.rb~ +42 -0
  7. data/app/mailers/commontator/subscriptions_mailer.rb~ +50 -0
  8. data/app/models/commontator/comment.rb~ +2 -6
  9. data/app/models/commontator/subscription.rb~ +2 -5
  10. data/app/models/commontator/thread.rb~ +5 -7
  11. data/app/views/commontator/comments/_actions.html.erb~ +30 -0
  12. data/app/views/commontator/comments/_votes.html.erb~ +1 -1
  13. data/app/views/commontator/shared/_thread.html.erb~ +20 -0
  14. data/app/views/commontator/subscriptions/_link.html.erb~ +16 -0
  15. data/app/views/commontator/threads/_show.html.erb~ +62 -0
  16. data/config/initializers/commontator.rb~ +1 -1
  17. data/config/routes.rb~ +22 -0
  18. data/db/migrate/0_install.rb~ +1 -1
  19. data/db/migrate/{0_install.rb → 0_install_commontator.rb} +1 -1
  20. data/lib/commontator/controller_includes.rb~ +22 -0
  21. data/lib/commontator/shared_helper.rb~ +42 -0
  22. data/lib/commontator/version.rb +1 -1
  23. data/lib/commontator/version.rb~ +1 -1
  24. data/spec/app/controllers/commontator/comments_controller_spec.rb~ +55 -2
  25. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb~ +16 -16
  26. data/spec/app/controllers/commontator/threads_controller_spec.rb~ +1 -1
  27. data/spec/app/helpers/commontator/application_helper_spec.rb~ +2 -0
  28. data/spec/app/helpers/commontator/threads_helper_spec.rb~ +1 -1
  29. data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb~ +1 -1
  30. data/spec/app/models/commontator/comment_spec.rb~ +1 -1
  31. data/spec/app/models/commontator/subscription_spec.rb~ +1 -1
  32. data/spec/app/models/commontator/thread_spec.rb~ +1 -1
  33. data/spec/dummy/Rakefile~ +1 -1
  34. data/spec/dummy/config.ru~ +4 -0
  35. data/spec/dummy/config/application.rb~ +23 -0
  36. data/spec/dummy/config/environment.rb~ +5 -0
  37. data/spec/dummy/config/environments/development.rb~ +31 -0
  38. data/spec/dummy/config/environments/production.rb~ +67 -0
  39. data/spec/dummy/config/environments/test.rb~ +31 -0
  40. data/spec/dummy/config/initializers/secret_token.rb~ +12 -0
  41. data/spec/dummy/db/development.sqlite3 +0 -0
  42. data/spec/dummy/db/test.sqlite3 +0 -0
  43. data/spec/dummy/log/development.log +1250 -0
  44. data/spec/dummy/log/test.log +170101 -0
  45. data/spec/dummy/tmp/cache/assets/test/sprockets/02d4b791eb831cf2057bf4703a1218d1 +0 -0
  46. data/spec/dummy/tmp/cache/assets/test/sprockets/0f196a1a50363b0a076ec6e1ee5417f6 +0 -0
  47. data/spec/dummy/tmp/cache/assets/test/sprockets/a3fb9025f90ff05a6fd4afc7ded2692c +0 -0
  48. data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
  49. data/spec/dummy/tmp/cache/assets/test/sprockets/c69ee3cc5796188d873574179290a6ef +0 -0
  50. data/spec/dummy/tmp/cache/assets/test/sprockets/e1f674c11941d62aac1764ef3a7134e4 +0 -0
  51. data/spec/dummy/tmp/cache/assets/test/sprockets/e85565206c3e5fdf9dfeb367c85557b1 +0 -0
  52. data/spec/lib/commontator/acts_as_commontable_spec.rb~ +2 -2
  53. data/spec/lib/commontator/acts_as_commontator_spec.rb~ +1 -1
  54. data/spec/lib/commontator/commontable_config_spec.rb~ +1 -1
  55. data/spec/lib/commontator/commontator_config_spec.rb~ +1 -1
  56. data/spec/lib/commontator/controller_includes_spec.rb~ +3 -3
  57. data/spec/lib/commontator/shared_helper_spec.rb~ +7 -3
  58. data/spec/lib/commontator_spec.rb~ +1 -1
  59. data/spec/test_helper.rb~ +37 -0
  60. metadata +61 -31
@@ -0,0 +1,62 @@
1
+ <% # Clients of this partial must supply the following variables:
2
+ # thread
3
+ # user
4
+ %>
5
+
6
+ <% can_subscribe = thread.can_subscribe?(user) %>
7
+ <% can_edit = thread.can_be_edited_by?(user) %>
8
+
9
+ <span id="thread_<%= thread.id.to_s %>_header_span" class="thread_header">
10
+ <%= thread.config.comment_name.capitalize.pluralize + (thread.is_closed? ? ' (closed)' : '') %>
11
+ </span>
12
+
13
+ <span id="thread_<%= thread.id.to_s %>_actions_span" class="thread_actions">
14
+ <% if can_subscribe %>
15
+ <span id="thread_<%= thread.id.to_s %>_subscription_span" class="thread_subscription">
16
+ <%= render :partial => 'commontator/subscriptions/link',
17
+ :locals => {:thread => thread,
18
+ :user => user} %>
19
+ </span>
20
+ <% end %>
21
+
22
+ &nbsp;
23
+
24
+ <% if can_edit %>
25
+ <% is_closed = thread.is_closed? %>
26
+ <% close_string = is_closed ? "reopen" : "close" %>
27
+ <%= link_to close_string.capitalize,
28
+ commontator.polymorphic_path([close_string, thread]),
29
+ :confirm => (!is_closed ? \
30
+ 'Are you sure you want to close this thread?' : nil),
31
+ :method => :put,
32
+ :id => "thread_#{thread.id.to_s}_#{close_string}_link",
33
+ :class => "thread_#{close_string}_link",
34
+ :remote => true %>
35
+ <% end %>
36
+ </span>
37
+
38
+ <div id="thread_<%= thread.id.to_s %>_comment_list_div" class="thread_comment_list">
39
+ <% thread.ordered_comments.each do |comment| %>
40
+ <% next unless comment.can_be_read_by?(user) %>
41
+ <%= render :partial => 'commontator/comments/show',
42
+ :locals => {:comment => comment,
43
+ :user => user} %>
44
+ <% end %>
45
+ </div>
46
+
47
+ <br/>
48
+
49
+ <% if thread.is_closed? %>
50
+
51
+ <p><%= thread.config.comment_name.capitalize.pluralize %> cannot be <%= thread.config.comment_create_verb_past %> at this time.</p>
52
+
53
+ <% else %>
54
+
55
+ <div id="thread_<%= thread.id %>_new_comment_div" class="thread_new_comment"></div>
56
+
57
+ <span id="thread_<%= thread.id %>_new_comment_link_span" class="thread_new_comment_link">
58
+ <%= link_to thread.config.comment_create_verb_present.capitalize + ' ' + thread.config.comment_name,
59
+ commontator.new_thread_comment_path(thread), :remote => true %>
60
+ </span>
61
+
62
+ <% end %>
@@ -62,7 +62,7 @@ Commontator.configure do |config|
62
62
  config.comment_create_verb_past = 'posted'
63
63
 
64
64
  # Verb used when editing comments (present)
65
- # Default: 'edit'
65
+ # Default: 'modify'
66
66
  config.comment_edit_verb_present = 'modify'
67
67
 
68
68
  # Verb used when editing comments (past)
data/config/routes.rb~ ADDED
@@ -0,0 +1,22 @@
1
+ Commontator::Engine.routes.draw do
2
+ resources :threads, :only => [:show] do
3
+ resources :comments, :except => [:index, :destroy], :shallow => true do
4
+ patch 'delete', :on => :member
5
+ patch 'undelete', :on => :member
6
+
7
+ patch 'upvote', :on => :member
8
+ patch 'downvote', :on => :member
9
+ patch 'unvote', :on => :member
10
+ end
11
+
12
+ patch 'close', :on => :member
13
+ patch 'reopen', :on => :member
14
+
15
+ patch 'subscribe', :to => 'subscriptions#subscribe',
16
+ :as => 'subscribe',
17
+ :on => :member
18
+ patch 'unsubscribe', :to => 'subscriptions#destroy',
19
+ :as => 'unsubscribe',
20
+ :on => :member
21
+ end
22
+ end
@@ -6,7 +6,7 @@ class Install < ActiveRecord::Migration
6
6
  t.string "editor_type"
7
7
  t.integer "editor_id"
8
8
  t.integer "thread_id", :null => false
9
- t.text "body", :null => false, :default => ''
9
+ t.text "body", :null => false
10
10
  t.datetime "deleted_at"
11
11
 
12
12
  t.integer "cached_votes_total", :default => 0
@@ -1,4 +1,4 @@
1
- class Install < ActiveRecord::Migration
1
+ class InstallCommontator < ActiveRecord::Migration
2
2
  def change
3
3
  create_table "commontator_comments" do |t|
4
4
  t.string "creator_type"
@@ -0,0 +1,22 @@
1
+ require 'commontator/shared_helper'
2
+ require 'commontator/security_transgression'
3
+
4
+ module Commontator
5
+ module ControllerIncludes
6
+ def self.included(base)
7
+ base.helper Commontator::SharedHelper
8
+ end
9
+
10
+ def commontator_thread_show(commontable)
11
+ user = send Commontator.current_user_method
12
+ raise SecurityTransgression unless (user.nil? || user.is_commontator)
13
+
14
+ thread = commontable.thread
15
+ raise SecurityTransgression unless thread.can_be_read_by?(user)
16
+ thread.mark_as_read_for(user)
17
+ @commontator_thread_show = true
18
+ end
19
+ end
20
+ end
21
+
22
+ ActionController::Base.send :include, Commontator::ControllerIncludes
@@ -0,0 +1,42 @@
1
+ module Commontator
2
+ module SharedHelper
3
+ def commontator_thread(commontable)
4
+ user = send Commontator.current_user_method
5
+
6
+ render(:partial => 'commontator/shared/thread',
7
+ :locals => {:thread => commontable.thread,
8
+ :user => user}).html_safe
9
+ end
10
+
11
+ def commontator_name(user)
12
+ return Commontator.user_missing_name if user.nil?
13
+ config = user.commontator_config
14
+ config.user_name_method.blank? ? config.user_missing_name : \
15
+ user.send(config.user_name_method)
16
+ end
17
+
18
+ def commontator_email(user)
19
+ return '' if user.nil?
20
+ config = user.commontator_config
21
+ config.user_email_method.blank? ? '' : user.send(config.user_email_method)
22
+ end
23
+
24
+ def commontator_gravatar_url(user, options = {})
25
+ options[:secure] ||= request.ssl?
26
+ options[:size] ||= 50
27
+
28
+ hash = Digest::MD5.hexdigest(commontator_email(user))
29
+ base = options[:secure] ? "s://secure" : "://www"
30
+
31
+ "http#{base}.gravatar.com/avatar/#{hash}?s=#{options[:size]}"
32
+ end
33
+
34
+ def commontator_gravatar_image(user, options = {})
35
+ name = commontator_name(user)
36
+ image_tag(commontator_gravatar_url(user, options),
37
+ { :alt => name,
38
+ :title => name,
39
+ :border => 1 })
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Commontator
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Commontator
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'minitest_helper'
1
+ require 'test_helper'
2
2
  require 'acts_as_votable'
3
3
 
4
4
  module Commontator
@@ -322,7 +322,11 @@ module Commontator
322
322
  assert_redirected_to @thread
323
323
  assigns(:comment).errors.wont_be_empty
324
324
 
325
- @comment.delete_by(@user).must_equal true
325
+ user2 = DummyUser.create
326
+ user2.can_read = true
327
+ user2.can_edit = true
328
+ user2.is_admin = true
329
+ @comment.delete_by(user2).must_equal true
326
330
  put :undelete, :id => @comment.id, :use_route => :commontator
327
331
  assert_response 403
328
332
  assigns(:comment).is_deleted?.must_equal true
@@ -506,5 +510,54 @@ module Commontator
506
510
  assigns(:comment).upvotes.must_be_empty
507
511
  assigns(:comment).downvotes.must_be_empty
508
512
  end
513
+
514
+ it 'wont send mail if recipients empty' do
515
+ if defined?(CommentsController::SubscriptionsMailer)
516
+ CommentsController::SubscriptionsMailer.__send__(:initialize)
517
+ else
518
+ CommentsController::SubscriptionsMailer = MiniTest::Mock.new
519
+ end
520
+
521
+ user2 = DummyUser.create
522
+ user2.can_read = true
523
+
524
+ email = MiniTest::Mock.new.expect(:deliver, nil)
525
+ CommentsController::SubscriptionsMailer.expect(:comment_created, email, [Comment, [user2]])
526
+
527
+ @user.can_read = true
528
+ sign_in @user
529
+
530
+ attributes = {:body => 'Something else'}
531
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
532
+ assigns(:comment).errors.must_be_empty
533
+
534
+ proc { CommentsController::SubscriptionsMailer.verify }.must_raise(MockExpectationError)
535
+ proc { email.verify }.must_raise(MockExpectationError)
536
+ end
537
+
538
+ it 'must send mail if recipients not empty' do
539
+ if defined?(CommentsController::SubscriptionsMailer)
540
+ CommentsController::SubscriptionsMailer.__send__(:initialize)
541
+ else
542
+ CommentsController::SubscriptionsMailer = MiniTest::Mock.new
543
+ end
544
+
545
+ user2 = DummyUser.create
546
+ user2.can_read = true
547
+ @thread.subscribe(user2)
548
+
549
+ email = MiniTest::Mock.new.expect(:deliver, nil)
550
+ CommentsController::SubscriptionsMailer.expect(:comment_created, email, [Comment, [user2]])
551
+
552
+ @user.can_read = true
553
+ sign_in @user
554
+
555
+ attributes = {:body => 'Something else'}
556
+ post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
557
+ assigns(:comment).errors.must_be_empty
558
+
559
+ CommentsController::SubscriptionsMailer.verify
560
+ email.verify
561
+ end
509
562
  end
510
563
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'test_helper'
2
2
 
3
3
  module Commontator
4
4
  describe SubscriptionsController do
@@ -6,29 +6,29 @@ module Commontator
6
6
  setup_controller_spec
7
7
  end
8
8
 
9
- it 'wont create unless authorized' do
10
- post :create, :thread_id => @thread.id, :use_route => :commontator
9
+ it 'wont subscribe unless authorized' do
10
+ post :subscribe, :thread_id => @thread.id, :use_route => :commontator
11
11
  assert_response 403
12
12
  @thread.subscription_for(nil).must_be_nil
13
13
  @thread.subscription_for(@user).must_be_nil
14
14
 
15
15
  sign_in @user
16
- post :create, :thread_id => @thread.id, :use_route => :commontator
16
+ patch :subscribe, :thread_id => @thread.id, :use_route => :commontator
17
17
  assert_response 403
18
18
  @thread.subscription_for(@user).must_be_nil
19
19
 
20
20
  @thread.subscribe(@user)
21
21
  @user.can_read = true
22
- post :create, :thread_id => @thread.id, :use_route => :commontator
22
+ patch :subscribe, :thread_id => @thread.id, :use_route => :commontator
23
23
  assert_redirected_to @thread
24
24
  assigns(:thread).errors.wont_be_empty
25
25
  end
26
26
 
27
- it 'must create if authorized' do
27
+ it 'must subscribe if authorized' do
28
28
  sign_in @user
29
29
 
30
30
  @user.can_read = true
31
- post :create, :thread_id => @thread.id, :use_route => :commontator
31
+ patch :subscribe, :thread_id => @thread.id, :use_route => :commontator
32
32
  assert_redirected_to @thread
33
33
  assigns(:thread).errors.must_be_empty
34
34
  @thread.subscription_for(@user).wont_be_nil
@@ -36,7 +36,7 @@ module Commontator
36
36
  @thread.unsubscribe(@user)
37
37
  @user.can_read = false
38
38
  @user.can_edit = true
39
- post :create, :thread_id => @thread.id, :use_route => :commontator
39
+ patch :subscribe, :thread_id => @thread.id, :use_route => :commontator
40
40
  assert_redirected_to @thread
41
41
  assigns(:thread).errors.must_be_empty
42
42
  @thread.subscription_for(@user).wont_be_nil
@@ -44,27 +44,27 @@ module Commontator
44
44
  @thread.unsubscribe(@user)
45
45
  @user.can_edit = false
46
46
  @user.is_admin = true
47
- post :create, :thread_id => @thread.id, :use_route => :commontator
47
+ patch :subscribe, :thread_id => @thread.id, :use_route => :commontator
48
48
  assert_redirected_to @thread
49
49
  assigns(:thread).errors.must_be_empty
50
50
  @thread.subscription_for(@user).wont_be_nil
51
51
  end
52
52
 
53
- it 'wont destroy unless authorized' do
53
+ it 'wont unsubscribe unless authorized' do
54
54
  @thread.subscribe(@user)
55
- delete :destroy, :thread_id => @thread.id, :use_route => :commontator
55
+ patch :unsubscribe, :thread_id => @thread.id, :use_route => :commontator
56
56
  assert_response 403
57
57
  @thread.subscription_for(nil).must_be_nil
58
58
  @thread.subscription_for(@user).wont_be_nil
59
59
 
60
60
  sign_in @user
61
- delete :destroy, :thread_id => @thread.id, :use_route => :commontator
61
+ patch :unsubscribe, :thread_id => @thread.id, :use_route => :commontator
62
62
  assert_response 403
63
63
  @thread.subscription_for(@user).wont_be_nil
64
64
 
65
65
  @thread.unsubscribe(@user)
66
66
  @user.can_read = true
67
- delete :destroy, :thread_id => @thread.id, :use_route => :commontator
67
+ patch :unsubscribe, :thread_id => @thread.id, :use_route => :commontator
68
68
  assert_redirected_to @thread
69
69
  assigns(:thread).errors.wont_be_empty
70
70
  end
@@ -74,7 +74,7 @@ module Commontator
74
74
 
75
75
  @thread.subscribe(@user)
76
76
  @user.can_read = true
77
- delete :destroy, :thread_id => @thread.id, :use_route => :commontator
77
+ patch :unsubscribe, :thread_id => @thread.id, :use_route => :commontator
78
78
  assert_redirected_to @thread
79
79
  assigns(:thread).errors.must_be_empty
80
80
  @thread.subscription_for(@user).must_be_nil
@@ -82,7 +82,7 @@ module Commontator
82
82
  @thread.subscribe(@user)
83
83
  @user.can_read = false
84
84
  @user.can_edit = true
85
- delete :destroy, :thread_id => @thread.id, :use_route => :commontator
85
+ patch :unsubscribe, :thread_id => @thread.id, :use_route => :commontator
86
86
  assert_redirected_to @thread
87
87
  assigns(:thread).errors.must_be_empty
88
88
  @thread.subscription_for(@user).must_be_nil
@@ -90,7 +90,7 @@ module Commontator
90
90
  @thread.subscribe(@user)
91
91
  @user.can_edit = false
92
92
  @user.is_admin = true
93
- delete :destroy, :thread_id => @thread.id, :use_route => :commontator
93
+ patch :unsubscribe, :thread_id => @thread.id, :use_route => :commontator
94
94
  assert_redirected_to @thread
95
95
  assigns(:thread).errors.must_be_empty
96
96
  @thread.subscription_for(@user).must_be_nil
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'test_helper'
2
2
 
3
3
  module Commontator
4
4
  describe ThreadsController do
@@ -1,3 +1,5 @@
1
+ require 'minitest_helper'
2
+
1
3
  module Commontator
2
4
  describe ApplicationHelper do
3
5
  it 'must print javascript proc' do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'minitest_helper'
2
2
 
3
3
  module Commontator
4
4
  describe ThreadsHelper do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'test_helper'
2
2
 
3
3
  module Commontator
4
4
  describe SubscriptionsMailer do
@@ -54,7 +54,7 @@ module Commontator
54
54
  @comment.editor = @user
55
55
  @comment.save!
56
56
 
57
- @comment.timestamp.must_equal "#{@thread.config.comment_create_verb_past.capitalize} on #{@comment.created_at.strftime(@thread.config.timestamp_format)}" +
57
+ @comment.timestamp.must_equal "#{@thread.config.comment_create_verb_past.capitalize} on #{@comment.created_at.strftime(@thread.config.timestamp_format)}" + \
58
58
  " | Last #{@thread.config.comment_edit_verb_past} on #{@comment.updated_at.strftime(@thread.config.timestamp_format)}"
59
59
  end
60
60
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'minitest_helper'
2
2
 
3
3
  module Commontator
4
4
  describe Subscription do
@@ -9,7 +9,7 @@ module Commontator
9
9
  it 'must have a config' do
10
10
  @thread.config.must_be_instance_of CommontableConfig
11
11
  @thread.commontable = nil
12
- @thread.config.must_be_nil
12
+ @thread.config.must_equal Commontator
13
13
  end
14
14
 
15
15
  it 'must order all comments' do
data/spec/dummy/Rakefile~ CHANGED
@@ -4,4 +4,4 @@
4
4
 
5
5
  require File.expand_path('../config/application', __FILE__)
6
6
 
7
- #Dummy::Application.load_tasks
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application