commontator 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -5
  3. data/app/controllers/commontator/comments_controller.rb +6 -6
  4. data/app/controllers/commontator/subscriptions_controller.rb +2 -2
  5. data/app/controllers/commontator/threads_controller.rb +2 -2
  6. data/app/views/commontator/comments/_actions.html.erb +1 -1
  7. data/app/views/commontator/comments/_votes.html.erb +4 -4
  8. data/app/views/commontator/shared/_thread.html.erb +1 -1
  9. data/app/views/commontator/subscriptions/_link.html.erb +1 -1
  10. data/app/views/commontator/threads/_show.html.erb +1 -1
  11. data/config/routes.rb +9 -9
  12. data/lib/commontator/version.rb +1 -1
  13. data/spec/app/controllers/commontator/comments_controller_spec.rb +40 -40
  14. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +12 -12
  15. data/spec/app/controllers/commontator/threads_controller_spec.rb +12 -12
  16. data/spec/dummy/db/test.sqlite3 +0 -0
  17. data/spec/dummy/log/test.log +4176 -0
  18. metadata +4 -91
  19. data/app/controllers/commontator/application_controller.rb~ +0 -27
  20. data/app/controllers/commontator/comments_controller.rb~ +0 -144
  21. data/app/controllers/commontator/subscriptions_controller.rb~ +0 -32
  22. data/app/controllers/commontator/threads_controller.rb~ +0 -42
  23. data/app/mailers/commontator/subscriptions_mailer.rb~ +0 -50
  24. data/app/models/commontator/comment.rb~ +0 -104
  25. data/app/models/commontator/subscription.rb~ +0 -18
  26. data/app/models/commontator/thread.rb~ +0 -124
  27. data/app/models/commontator/tree.rb~ +0 -123
  28. data/app/views/commontator/comments/_actions.html.erb~ +0 -30
  29. data/app/views/commontator/comments/_body.html.erb~ +0 -8
  30. data/app/views/commontator/comments/_form.html.erb~ +0 -38
  31. data/app/views/commontator/comments/_show.html.erb~ +0 -44
  32. data/app/views/commontator/comments/_votes.html.erb~ +0 -57
  33. data/app/views/commontator/comments/delete.js.erb~ +0 -17
  34. data/app/views/commontator/shared/_thread.html.erb~ +0 -20
  35. data/app/views/commontator/subscriptions/_link.html.erb~ +0 -16
  36. data/app/views/commontator/threads/_show.html.erb~ +0 -62
  37. data/config/initializers/commontator.rb~ +0 -171
  38. data/config/routes.rb~ +0 -22
  39. data/db/migrate/0_install.rb~ +0 -50
  40. data/lib/commontator.rb~ +0 -61
  41. data/lib/commontator/acts_as_commontable.rb~ +0 -45
  42. data/lib/commontator/acts_as_commontator.rb~ +0 -31
  43. data/lib/commontator/controller_includes.rb~ +0 -22
  44. data/lib/commontator/security_transgression.rb~ +0 -3
  45. data/lib/commontator/shared_helper.rb~ +0 -42
  46. data/lib/commontator/version.rb~ +0 -3
  47. data/lib/tasks/commontator_tasks.rake~ +0 -42
  48. data/spec/app/controllers/commontator/comments_controller_spec.rb~ +0 -563
  49. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb~ +0 -99
  50. data/spec/app/controllers/commontator/threads_controller_spec.rb~ +0 -121
  51. data/spec/app/helpers/commontator/application_helper_spec.rb~ +0 -9
  52. data/spec/app/helpers/commontator/threads_helper_spec.rb~ +0 -17
  53. data/spec/app/mailers/commontator/subscriptions_mailer_spec.rb~ +0 -30
  54. data/spec/app/models/commontator/comment_observer_spec.rb~ +0 -27
  55. data/spec/app/models/commontator/comment_spec.rb~ +0 -61
  56. data/spec/app/models/commontator/subscription_spec.rb~ +0 -28
  57. data/spec/app/models/commontator/thread_spec.rb~ +0 -130
  58. data/spec/dummy/README.md~ +0 -3
  59. data/spec/dummy/Rakefile~ +0 -7
  60. data/spec/dummy/config.ru~ +0 -4
  61. data/spec/dummy/config/application.rb~ +0 -23
  62. data/spec/dummy/config/environment.rb~ +0 -5
  63. data/spec/dummy/config/environments/development.rb~ +0 -31
  64. data/spec/dummy/config/environments/production.rb~ +0 -67
  65. data/spec/dummy/config/environments/test.rb~ +0 -31
  66. data/spec/dummy/config/initializers/secret_token.rb~ +0 -12
  67. data/spec/lib/commontator/acts_as_commontable_spec.rb~ +0 -26
  68. data/spec/lib/commontator/acts_as_commontator_spec.rb~ +0 -25
  69. data/spec/lib/commontator/commontable_config_spec.rb~ +0 -26
  70. data/spec/lib/commontator/commontator_config_spec.rb~ +0 -26
  71. data/spec/lib/commontator/controller_includes_spec.rb~ +0 -15
  72. data/spec/lib/commontator/shared_helper_spec.rb~ +0 -16
  73. data/spec/lib/commontator_spec.rb~ +0 -23
  74. data/spec/minitest_helper.rb~ +0 -35
  75. data/spec/spec_helper.rb~ +0 -36
  76. data/spec/test_helper.rb~ +0 -37
data/config/routes.rb~ DELETED
@@ -1,22 +0,0 @@
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
@@ -1,50 +0,0 @@
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
data/lib/commontator.rb~ DELETED
@@ -1,61 +0,0 @@
1
- require 'commontator/engine'
2
- require 'commontator/controller_includes'
3
-
4
- module Commontator
5
- # Attributes
6
-
7
- # Can be set in initializer only
8
- ENGINE_ATTRIBUTES = [
9
- :current_user_method,
10
- :javascript_proc
11
- ]
12
-
13
- # Can be set in initializer or passed as an option to acts_as_commontator
14
- COMMONTATOR_ATTRIBUTES = [
15
- :user_missing_name,
16
- :user_name_clickable,
17
- :user_email_method,
18
- :user_name_method,
19
- :user_admin_proc,
20
- :subscription_email_enable_proc
21
- ]
22
-
23
- # Can be set in initializer or passed as an option to acts_as_commontable
24
- COMMONTABLE_ATTRIBUTES = [
25
- :comment_name,
26
- :comment_create_verb_present,
27
- :comment_create_verb_past,
28
- :comment_edit_verb_past,
29
- :commontable_name,
30
- :timestamp_format,
31
- :admin_can_edit_comments,
32
- :auto_subscribe_on_comment,
33
- :can_edit_own_comments,
34
- :can_edit_old_comments,
35
- :can_delete_own_comments,
36
- :can_delete_old_comments,
37
- :can_subscribe_to_thread,
38
- :can_vote_on_comments,
39
- :comments_ordered_by_votes,
40
- :closed_threads_are_readable,
41
- :deleted_comments_are_visible,
42
- :commontable_id_method,
43
- :can_edit_thread_proc,
44
- :can_read_thread_proc,
45
- :commontable_url_proc,
46
- :subscription_email_from_proc,
47
- :subscription_email_subject_proc
48
- ]
49
-
50
- (ENGINE_ATTRIBUTES + COMMONTATOR_ATTRIBUTES + \
51
- COMMONTABLE_ATTRIBUTES).each do |attribute|
52
- mattr_accessor attribute
53
- end
54
-
55
- def self.configure
56
- yield self
57
- end
58
- end
59
-
60
- require 'commontator/acts_as_commontator'
61
- require 'commontator/acts_as_commontable'
@@ -1,45 +0,0 @@
1
- require 'commontator/commontable_config'
2
-
3
- module Commontator
4
- module ActsAsCommontable
5
- def self.included(base)
6
- base.class_attribute :is_commontable
7
- base.is_commontable = false
8
- base.extend(ClassMethods)
9
- end
10
-
11
- module ClassMethods
12
- def acts_as_commontable(options = {})
13
- class_eval do
14
- cattr_accessor :commontable_config
15
- self.commontable_config = Commontator::CommontableConfig.new(options)
16
- self.is_commontable = true
17
-
18
- has_one :thread, :as => :commontable, :class_name => 'Commontator::Thread'
19
- has_many :comments, :class_name => 'Commontator::Comment', :through => :thread
20
-
21
- has_many :subscriptions, :class_name => 'Commontator::Subscription', :through => :thread
22
- has_many :subscribers, :through => :subscriptions
23
-
24
- validates_presence_of :thread
25
-
26
- alias_method :thread_raw, :thread
27
-
28
- def thread
29
- raw = thread_raw
30
- return raw unless raw.nil?
31
- return Commontator::Thread.find_or_create_by_commontable_type_and_commontable_id(self.class.name, id) \
32
- unless id.nil?
33
- self.thread = Commontator::Thread.new
34
- self.thread.commontable = self
35
- self.thread
36
- end
37
- end
38
- end
39
-
40
- alias_method :acts_as_commentable, :acts_as_commontable
41
- end
42
- end
43
- end
44
-
45
- ActiveRecord::Base.send :include, Commontator::ActsAsCommontable
@@ -1,31 +0,0 @@
1
- require 'commontator/commontator_config'
2
-
3
- module Commontator
4
- module ActsAsCommontator
5
- def self.included(base)
6
- base.class_attribute :is_commontator
7
- base.is_commontator = false
8
- base.extend(ClassMethods)
9
- end
10
-
11
- module ClassMethods
12
- def acts_as_commontator(options = {})
13
- class_eval do
14
- has_many :comments, :as => :commontator, :class_name => 'Commontator::Comment'
15
-
16
- has_many :subscriptions, :as => :subscriber, :class_name => 'Commontator::Subscription', :dependent => :destroy
17
-
18
- cattr_accessor :commontator_config
19
- self.commontator_config = Commontator::CommontatorConfig.new(options)
20
- self.is_commontator = true
21
- end
22
- end
23
-
24
- alias_method :acts_as_commonter, :acts_as_commontator
25
- alias_method :acts_as_commentator, :acts_as_commontator
26
- alias_method :acts_as_commenter, :acts_as_commontator
27
- end
28
- end
29
- end
30
-
31
- ActiveRecord::Base.send :include, Commontator::ActsAsCommontator
@@ -1,22 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- module Commontator
2
- class SecurityTransgression < StandardError; end
3
- end
@@ -1,42 +0,0 @@
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 +0,0 @@
1
- module Commontator
2
- VERSION = "4.0.0"
3
- end
@@ -1,42 +0,0 @@
1
- COMMONTATOR_COPY_TASKS = ['assets/images', 'assets/stylesheets', 'views', 'mailers', 'helpers', 'controllers', 'models']
2
-
3
- namespace :commontator do
4
- namespace :install do
5
- desc "Copy initializers from commontator to application"
6
- task :initializers do
7
- Dir.glob(File.expand_path('../../../config/initializers/*.rb', __FILE__)) do |file|
8
- if File.exists?(File.expand_path(File.basename(file), 'config/initializers'))
9
- print "NOTE: Initializer #{File.basename(file)} from commontator has been skipped. Initializer with the same name already exists.\n"
10
- else
11
- cp file, 'config/initializers', :verbose => false
12
- print "Copied initializer #{File.basename(file)} from commontator\n"
13
- end
14
- end
15
- end
16
- end
17
-
18
- namespace :copy do
19
- COMMONTATOR_COPY_TASKS.each do |path|
20
- name = File.basename(path)
21
- desc "Copy #{name} from commontator to application"
22
- task name.to_sym do
23
- cp_r File.expand_path("../../../app/#{path}/commontator", __FILE__), "app/#{path}", :verbose => false
24
- print "Copied #{name} from commontator\n"
25
- end
26
- end
27
- end
28
-
29
- desc "Copy initializers and migrations from commontator to application"
30
- task :install do
31
- Rake::Task["commontator:install:initializers"].invoke
32
- Rake::Task["commontator:install:migrations"].invoke
33
- end
34
-
35
- desc "Copy assets, views, mailers, helpers, controllers and models from commontator to application"
36
- task :copy do
37
- COMMONTATOR_COPY_TASKS.each do |path|
38
- Rake::Task["commontator:copy:#{File.basename(path)}"].invoke
39
- end
40
- end
41
- end
42
-
@@ -1,563 +0,0 @@
1
- require 'test_helper'
2
- require 'acts_as_votable'
3
-
4
- module Commontator
5
- describe CommentsController do
6
- before do
7
- setup_controller_spec
8
- @comment = Comment.new
9
- @comment.thread = @thread
10
- @comment.creator = @user
11
- @comment.body = 'Something'
12
- @comment.save!
13
- @comment.is_votable?.must_equal true
14
- end
15
-
16
- it 'wont get new unless authorized' do
17
- get :new, :thread_id => @thread.id, :use_route => :commontator
18
- assert_response 403
19
-
20
- sign_in @user
21
- get :new, :thread_id => @thread.id, :use_route => :commontator
22
- assert_response 403
23
- end
24
-
25
- it 'must get new if authorized' do
26
- sign_in @user
27
-
28
- @user.can_read = true
29
- get :new, :thread_id => @thread.id, :use_route => :commontator
30
- assert_redirected_to @thread
31
- assigns(:comment).errors.must_be_empty
32
-
33
- @user.can_read = false
34
- @user.can_edit = true
35
- get :new, :thread_id => @thread.id, :use_route => :commontator
36
- assert_redirected_to @thread
37
- assigns(:comment).errors.must_be_empty
38
-
39
- @user.can_edit = false
40
- @user.is_admin = true
41
- get :new, :thread_id => @thread.id, :use_route => :commontator
42
- assert_redirected_to @thread
43
- assigns(:comment).errors.must_be_empty
44
- end
45
-
46
- it 'wont create unless authorized' do
47
- attributes = Hash.new
48
- attributes[:body] = 'Something else'
49
-
50
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
51
- assert_response 403
52
-
53
- sign_in @user
54
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
55
- assert_response 403
56
-
57
- @user.can_read = true
58
- @user.can_edit = true
59
- @user.is_admin = true
60
- @thread.close.must_equal true
61
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
62
- assert_response 403
63
- end
64
-
65
- it 'must create if authorized' do
66
- sign_in @user
67
- attributes = Hash.new
68
-
69
- attributes[:body] = 'Something else'
70
- @user.can_read = true
71
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
72
- assert_redirected_to @thread
73
- assigns(:comment).errors.must_be_empty
74
- assigns(:comment).body.must_equal 'Something else'
75
- assigns(:comment).creator.must_equal @user
76
- assigns(:comment).editor.must_be_nil
77
- assigns(:comment).thread.must_equal @thread
78
-
79
- attributes[:body] = 'Another thing'
80
- @user.can_read = false
81
- @user.can_edit = true
82
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
83
- assert_redirected_to @thread
84
- assigns(:comment).errors.must_be_empty
85
- assigns(:comment).body.must_equal 'Another thing'
86
- assigns(:comment).creator.must_equal @user
87
- assigns(:comment).editor.must_be_nil
88
- assigns(:comment).thread.must_equal @thread
89
-
90
- attributes[:body] = 'And this too'
91
- @user.can_edit = false
92
- @user.is_admin = true
93
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
94
- assert_redirected_to @thread
95
- assigns(:comment).errors.must_be_empty
96
- assigns(:comment).body.must_equal 'And this too'
97
- assigns(:comment).creator.must_equal @user
98
- assigns(:comment).editor.must_be_nil
99
- assigns(:comment).thread.must_equal @thread
100
- end
101
-
102
- it 'wont create if double posting' do
103
- sign_in @user
104
- @user.can_read = true
105
- attributes = Hash.new
106
-
107
- attributes[:body] = 'Something'
108
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
109
- assert_redirected_to @thread
110
- assigns(:comment).errors.wont_be_empty
111
-
112
- attributes[:body] = 'Something else'
113
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
114
- assert_redirected_to @thread
115
- assigns(:comment).errors.must_be_empty
116
- assigns(:comment).body.must_equal 'Something else'
117
- assigns(:comment).creator.must_equal @user
118
- assigns(:comment).editor.must_be_nil
119
- assigns(:comment).thread.must_equal @thread
120
-
121
- attributes[:body] = 'Something else'
122
- post :create, :thread_id => @thread.id, :comment => attributes, :use_route => :commontator
123
- assert_redirected_to @thread
124
- assigns(:comment).errors.wont_be_empty
125
- end
126
-
127
- it 'wont edit unless authorized' do
128
- get :edit, :id => @comment.id, :use_route => :commontator
129
- assert_response 403
130
-
131
- sign_in @user
132
- get :edit, :id => @comment.id, :use_route => :commontator
133
- assert_response 403
134
-
135
- user2 = DummyUser.create
136
- user2.can_read = true
137
- user2.can_edit = true
138
- user2.is_admin = true
139
- sign_in user2
140
- get :edit, :id => @comment.id, :use_route => :commontator
141
- assert_response 403
142
-
143
- @user.can_read = true
144
- @user.can_edit = true
145
- @user.is_admin = true
146
- sign_in @user
147
- comment2 = Comment.new
148
- comment2.thread = @thread
149
- comment2.creator = @user
150
- comment2.body = 'Something else'
151
- comment2.save!
152
- get :edit, :id => @comment.id, :use_route => :commontator
153
- assert_response 403
154
- end
155
-
156
- it 'must edit if authorized' do
157
- sign_in @user
158
-
159
- @user.can_read = true
160
- get :edit, :id => @comment.id, :use_route => :commontator
161
- assert_redirected_to @thread
162
- assigns(:comment).errors.must_be_empty
163
-
164
- @user.can_read = false
165
- @user.can_edit = true
166
- get :edit, :id => @comment.id, :use_route => :commontator
167
- assert_redirected_to @thread
168
- assigns(:comment).errors.must_be_empty
169
-
170
- @user.can_edit = false
171
- @user.is_admin = true
172
- get :edit, :id => @comment.id, :use_route => :commontator
173
- assert_redirected_to @thread
174
- assigns(:comment).errors.must_be_empty
175
- end
176
-
177
- it 'wont update unless authorized' do
178
- attributes = Hash.new
179
- attributes[:body] = 'Something else'
180
-
181
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
182
- assert_response 403
183
- assigns(:comment).body.must_equal 'Something'
184
- assigns(:comment).editor.must_be_nil
185
-
186
- sign_in @user
187
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
188
- assert_response 403
189
- assigns(:comment).body.must_equal 'Something'
190
- assigns(:comment).editor.must_be_nil
191
-
192
- user2 = DummyUser.create
193
- user2.can_read = true
194
- user2.can_edit = true
195
- user2.is_admin = true
196
- sign_in user2
197
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
198
- assert_response 403
199
- assigns(:comment).body.must_equal 'Something'
200
- assigns(:comment).editor.must_be_nil
201
-
202
- @user.can_read = true
203
- @user.can_edit = true
204
- @user.is_admin = true
205
- sign_in @user
206
- comment2 = Comment.new
207
- comment2.thread = @thread
208
- comment2.creator = @user
209
- comment2.body = 'Something else'
210
- comment2.save!
211
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
212
- assert_response 403
213
- assigns(:comment).body.must_equal 'Something'
214
- assigns(:comment).editor.must_be_nil
215
- end
216
-
217
- it 'must update if authorized' do
218
- sign_in @user
219
- attributes = Hash.new
220
- attributes[:body] = 'Something else'
221
-
222
- @user.can_read = true
223
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
224
- assert_redirected_to @thread
225
- assigns(:comment).errors.must_be_empty
226
- assigns(:comment).editor.must_equal @user
227
-
228
- @user.can_read = false
229
- @user.can_edit = true
230
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
231
- assert_redirected_to @thread
232
- assigns(:comment).errors.must_be_empty
233
- assigns(:comment).editor.must_equal @user
234
-
235
- @user.can_edit = false
236
- @user.is_admin = true
237
- put :update, :id => @comment.id, :comment => attributes, :use_route => :commontator
238
- assert_redirected_to @thread
239
- assigns(:comment).errors.must_be_empty
240
- assigns(:comment).editor.must_equal @user
241
- end
242
-
243
- it 'wont delete unless authorized and not deleted' do
244
- put :delete, :id => @comment.id, :use_route => :commontator
245
- assert_response 403
246
- assigns(:comment).is_deleted?.must_equal false
247
-
248
- sign_in @user
249
-
250
- put :delete, :id => @comment.id, :use_route => :commontator
251
- assert_response 403
252
- assigns(:comment).is_deleted?.must_equal false
253
-
254
- @user.can_read = true
255
- @comment.delete_by(@user).must_equal true
256
- put :delete, :id => @comment.id, :use_route => :commontator
257
- assert_redirected_to @thread
258
- assigns(:comment).errors.wont_be_empty
259
-
260
- comment2 = Comment.new
261
- comment2.thread = @thread
262
- comment2.creator = @user
263
- comment2.body = 'Something else'
264
- comment2.save!
265
- @comment.undelete_by(@user).must_equal true
266
- put :delete, :id => @comment.id, :use_route => :commontator
267
- assert_response 403
268
- assigns(:comment).is_deleted?.must_equal false
269
- end
270
-
271
- it 'must delete if authorized and not deleted' do
272
- sign_in @user
273
-
274
- @user.can_read = true
275
- put :delete, :id => @comment.id, :use_route => :commontator
276
- assert_redirected_to @thread
277
- assigns(:comment).errors.must_be_empty
278
- assigns(:comment).is_deleted?.must_equal true
279
- assigns(:comment).editor.must_equal @user
280
-
281
- user2 = DummyUser.create
282
- sign_in user2
283
- comment2 = Comment.new
284
- comment2.thread = @thread
285
- comment2.creator = @user
286
- comment2.body = 'Something else'
287
- comment2.save!
288
-
289
- assigns(:comment).undelete_by(@user).must_equal true
290
- user2.can_edit = true
291
- put :delete, :id => @comment.id, :use_route => :commontator
292
- assert_redirected_to @thread
293
- assigns(:comment).errors.must_be_empty
294
- assigns(:comment).is_deleted?.must_equal true
295
- assigns(:comment).editor.must_equal user2
296
-
297
- assigns(:comment).undelete_by(@user).must_equal true
298
- user2.can_edit = false
299
- user2.is_admin = true
300
- put :delete, :id => @comment.id, :use_route => :commontator
301
- assert_redirected_to @thread
302
- assigns(:comment).errors.must_be_empty
303
- assigns(:comment).is_deleted?.must_equal true
304
- assigns(:comment).editor.must_equal user2
305
- end
306
-
307
- it 'wont undelete unless authorized and deleted' do
308
- @comment.delete_by(@user).must_equal true
309
- put :undelete, :id => @comment.id, :use_route => :commontator
310
- assert_response 403
311
- assigns(:comment).is_deleted?.must_equal true
312
-
313
- sign_in @user
314
-
315
- put :undelete, :id => @comment.id, :use_route => :commontator
316
- assert_response 403
317
- assigns(:comment).is_deleted?.must_equal true
318
-
319
- @user.can_read = true
320
- @comment.undelete_by(@user).must_equal true
321
- put :undelete, :id => @comment.id, :use_route => :commontator
322
- assert_redirected_to @thread
323
- assigns(:comment).errors.wont_be_empty
324
-
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
330
- put :undelete, :id => @comment.id, :use_route => :commontator
331
- assert_response 403
332
- assigns(:comment).is_deleted?.must_equal true
333
-
334
- comment2 = Comment.new
335
- comment2.thread = @thread
336
- comment2.creator = @user
337
- comment2.body = 'Something else'
338
- comment2.save!
339
- @comment.undelete_by(@user).must_equal true
340
- @comment.delete_by(@user).must_equal true
341
- put :undelete, :id => @comment.id, :use_route => :commontator
342
- assert_response 403
343
- assigns(:comment).is_deleted?.must_equal true
344
- end
345
-
346
- it 'must undelete if authorized and deleted' do
347
- sign_in @user
348
-
349
- @comment.delete_by(@user).must_equal true
350
- @user.can_read = true
351
- put :undelete, :id => @comment.id, :use_route => :commontator
352
- assert_redirected_to @thread
353
- assigns(:comment).errors.must_be_empty
354
- assigns(:comment).is_deleted?.must_equal false
355
-
356
- user2 = DummyUser.create
357
- sign_in user2
358
- comment2 = Comment.new
359
- comment2.thread = @thread
360
- comment2.creator = @user
361
- comment2.body = 'Something else'
362
- comment2.save!
363
-
364
- assigns(:comment).delete_by(@user).must_equal true
365
- user2.can_edit = true
366
- put :undelete, :id => @comment.id, :use_route => :commontator
367
- assert_redirected_to @thread
368
- assigns(:comment).errors.must_be_empty
369
- assigns(:comment).is_deleted?.must_equal false
370
-
371
- assigns(:comment).delete_by(@user).must_equal true
372
- user2.can_edit = false
373
- user2.is_admin = true
374
- put :undelete, :id => @comment.id, :use_route => :commontator
375
- assert_redirected_to @thread
376
- assigns(:comment).errors.must_be_empty
377
- assigns(:comment).is_deleted?.must_equal false
378
- end
379
-
380
- it 'wont upvote if not authorized' do
381
- put :upvote, :id => @comment.id, :use_route => :commontator
382
- assert_response 403
383
- assigns(:comment).upvotes.must_be_empty
384
- assigns(:comment).downvotes.must_be_empty
385
-
386
- sign_in @user
387
- @user.can_read = true
388
- put :upvote, :id => @comment.id, :use_route => :commontator
389
- assert_response 403
390
- assigns(:comment).upvotes.must_be_empty
391
- assigns(:comment).downvotes.must_be_empty
392
-
393
- user2 = DummyUser.create
394
- sign_in user2
395
- put :upvote, :id => @comment.id, :use_route => :commontator
396
- assert_response 403
397
- assigns(:comment).upvotes.must_be_empty
398
- assigns(:comment).downvotes.must_be_empty
399
- end
400
-
401
- it 'must upvote if authorized' do
402
- user2 = DummyUser.create
403
- user2.can_read = true
404
- sign_in user2
405
-
406
- put :upvote, :id => @comment.id, :use_route => :commontator
407
- assert_redirected_to @thread
408
- assigns(:comment).upvotes.count.must_equal 1
409
- assigns(:comment).downvotes.must_be_empty
410
-
411
- put :upvote, :id => @comment.id, :use_route => :commontator
412
- assert_redirected_to @thread
413
- assigns(:comment).upvotes.count.must_equal 1
414
- assigns(:comment).downvotes.must_be_empty
415
-
416
- @comment.downvote_from(user2).must_equal true
417
-
418
- put :upvote, :id => @comment.id, :use_route => :commontator
419
- assert_redirected_to @thread
420
- assigns(:comment).upvotes.count.must_equal 1
421
- assigns(:comment).downvotes.must_be_empty
422
- end
423
-
424
- it 'wont downvote if not authorized' do
425
- put :downvote, :id => @comment.id, :use_route => :commontator
426
- assert_response 403
427
- assigns(:comment).upvotes.must_be_empty
428
- assigns(:comment).downvotes.must_be_empty
429
-
430
- sign_in @user
431
- @user.can_read = true
432
- put :downvote, :id => @comment.id, :use_route => :commontator
433
- assert_response 403
434
- assigns(:comment).upvotes.must_be_empty
435
- assigns(:comment).downvotes.must_be_empty
436
-
437
- user2 = DummyUser.create
438
- sign_in user2
439
- put :downvote, :id => @comment.id, :use_route => :commontator
440
- assert_response 403
441
- assigns(:comment).upvotes.must_be_empty
442
- assigns(:comment).downvotes.must_be_empty
443
- end
444
-
445
- it 'must downvote if authorized' do
446
- user2 = DummyUser.create
447
- user2.can_read = true
448
- sign_in user2
449
-
450
- put :downvote, :id => @comment.id, :use_route => :commontator
451
- assert_redirected_to @thread
452
- assigns(:comment).upvotes.must_be_empty
453
- assigns(:comment).downvotes.count.must_equal 1
454
-
455
- put :downvote, :id => @comment.id, :use_route => :commontator
456
- assert_redirected_to @thread
457
- assigns(:comment).upvotes.must_be_empty
458
- assigns(:comment).downvotes.count.must_equal 1
459
-
460
- @comment.upvote_from(user2).must_equal true
461
-
462
- put :downvote, :id => @comment.id, :use_route => :commontator
463
- assert_redirected_to @thread
464
- assigns(:comment).upvotes.must_be_empty
465
- assigns(:comment).downvotes.count.must_equal 1
466
- end
467
-
468
- it 'wont unvote if not authorized' do
469
- @comment.upvote_from(@user).must_equal true
470
-
471
- put :unvote, :id => @comment.id, :use_route => :commontator
472
- assert_response 403
473
- assigns(:comment).upvotes.count.must_equal 1
474
- assigns(:comment).downvotes.must_be_empty
475
-
476
- sign_in @user
477
- @user.can_read = true
478
- put :unvote, :id => @comment.id, :use_route => :commontator
479
- assert_response 403
480
- assigns(:comment).upvotes.count.must_equal 1
481
- assigns(:comment).downvotes.must_be_empty
482
-
483
- user2 = DummyUser.create
484
- sign_in user2
485
- put :unvote, :id => @comment.id, :use_route => :commontator
486
- assert_response 403
487
- assigns(:comment).upvotes.count.must_equal 1
488
- assigns(:comment).downvotes.must_be_empty
489
- end
490
-
491
- it 'must unvote if authorized' do
492
- user2 = DummyUser.create
493
- user2.can_read = true
494
- sign_in user2
495
-
496
- @comment.upvote_from(user2).must_equal true
497
- put :unvote, :id => @comment.id, :use_route => :commontator
498
- assert_redirected_to @thread
499
- assigns(:comment).upvotes.must_be_empty
500
- assigns(:comment).downvotes.must_be_empty
501
-
502
- put :unvote, :id => @comment.id, :use_route => :commontator
503
- assert_redirected_to @thread
504
- assigns(:comment).upvotes.must_be_empty
505
- assigns(:comment).downvotes.must_be_empty
506
-
507
- @comment.downvote_from(user2).must_equal true
508
- put :unvote, :id => @comment.id, :use_route => :commontator
509
- assert_redirected_to @thread
510
- assigns(:comment).upvotes.must_be_empty
511
- assigns(:comment).downvotes.must_be_empty
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
562
- end
563
- end