commontator 4.10.3 → 4.10.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -6
- data/app/models/commontator/subscription.rb +4 -2
- data/app/models/commontator/subscription.rb~ +23 -0
- data/app/views/commontator/comments/_votes.html.erb +8 -8
- data/config/locales/{commontator/en.yml → en.yml} +0 -0
- data/lib/commontator/engine.rb +0 -3
- data/lib/commontator/version.rb +1 -1
- data/lib/commontator/version.rb~ +3 -0
- data/spec/controllers/commontator/comments_controller_spec.rb +566 -0
- data/spec/controllers/commontator/comments_controller_spec.rb~ +565 -0
- data/spec/controllers/commontator/subscriptions_controller_spec.rb +102 -0
- data/spec/controllers/commontator/subscriptions_controller_spec.rb~ +101 -0
- data/spec/controllers/commontator/threads_controller_spec.rb +130 -0
- data/spec/controllers/commontator/threads_controller_spec.rb~ +130 -0
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/README.md~ +3 -0
- data/spec/dummy/Rakefile +1 -0
- data/spec/dummy/Rakefile~ +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +1 -0
- data/spec/dummy/app/assets/javascripts/application.js~ +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +1 -0
- data/spec/dummy/app/assets/stylesheets/application.css~ +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +1 -0
- data/spec/dummy/app/controllers/application_controller.rb~ +3 -0
- data/spec/dummy/app/controllers/dummy_models_controller.rb +12 -6
- data/spec/dummy/app/controllers/dummy_models_controller.rb~ +34 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -3
- data/spec/dummy/app/helpers/application_helper.rb~ +15 -0
- data/spec/dummy/app/models/dummy_model.rb +1 -0
- data/spec/dummy/app/models/dummy_model.rb~ +3 -0
- data/spec/dummy/app/models/dummy_user.rb +2 -1
- data/spec/dummy/app/models/dummy_user.rb~ +13 -0
- data/spec/dummy/app/views/dummy_model/show.html.erb +1 -0
- data/spec/dummy/app/views/dummy_model/show.html.erb~ +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb~ +14 -0
- data/spec/dummy/config.ru +1 -0
- data/spec/dummy/config.ru~ +4 -0
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/application.rb~ +26 -0
- data/spec/dummy/config/boot.rb +1 -0
- data/spec/dummy/config/boot.rb~ +5 -0
- data/spec/dummy/config/database.yml +1 -0
- data/spec/dummy/config/database.yml~ +25 -0
- data/spec/dummy/config/environment.rb +1 -0
- data/spec/dummy/config/environment.rb~ +5 -0
- data/spec/dummy/config/environments/development.rb +1 -0
- data/spec/dummy/config/environments/development.rb~ +31 -0
- data/spec/dummy/config/environments/production.rb +1 -0
- data/spec/dummy/config/environments/production.rb~ +82 -0
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/environments/test.rb~ +40 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb~ +7 -0
- data/spec/dummy/config/initializers/commontator.rb +1 -0
- data/spec/dummy/config/initializers/commontator.rb~ +14 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +1 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb~ +4 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb~ +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/initializers/mime_types.rb~ +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/secret_token.rb~ +12 -0
- data/spec/dummy/config/initializers/session_store.rb +1 -0
- data/spec/dummy/config/initializers/session_store.rb~ +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb~ +14 -0
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/config/routes.rb~ +7 -0
- data/spec/dummy/db/migrate/1_create_dummy_models.rb +1 -0
- data/spec/dummy/db/migrate/1_create_dummy_models.rb~ +7 -0
- data/spec/dummy/db/migrate/2_create_dummy_users.rb +1 -0
- data/spec/dummy/db/migrate/2_create_dummy_users.rb~ +7 -0
- data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +1 -0
- data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb~ +27 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +33 -119
- data/spec/dummy/log/test.log +33394 -31595
- data/spec/dummy/public/404.html +1 -0
- data/spec/dummy/public/404.html~ +26 -0
- data/spec/dummy/public/422.html +1 -0
- data/spec/dummy/public/422.html~ +26 -0
- data/spec/dummy/public/500.html +1 -0
- data/spec/dummy/public/500.html~ +25 -0
- data/spec/dummy/script/rails +1 -0
- data/spec/dummy/script/rails~ +6 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{72b63dddbc5c995f79af8e3c94904fd9 → 02d4b791eb831cf2057bf4703a1218d1} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{a77b1a9223d168112e1705c29220116f → 0f196a1a50363b0a076ec6e1ee5417f6} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{afa63eb365bdf4f42584b17ac9176b9d → a3fb9025f90ff05a6fd4afc7ded2692c} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{a473b3873e554893372a53d71f5e9879 → c69ee3cc5796188d873574179290a6ef} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{f721383d531f067d82b071e14aed7a92 → e1f674c11941d62aac1764ef3a7134e4} +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/{d2244ccef8e05bb993f75715af0344cc → e85565206c3e5fdf9dfeb367c85557b1} +0 -0
- data/spec/helpers/commontator/application_helper_spec.rb +10 -0
- data/spec/helpers/commontator/application_helper_spec.rb~ +9 -0
- data/spec/lib/commontator/acts_as_commontable_spec.rb +16 -15
- data/spec/lib/commontator/acts_as_commontable_spec.rb~ +25 -0
- data/spec/lib/commontator/acts_as_commontator_spec.rb +17 -16
- data/spec/lib/commontator/acts_as_commontator_spec.rb~ +52 -0
- data/spec/lib/commontator/commontable_config_spec.rb +9 -8
- data/spec/lib/commontator/commontable_config_spec.rb~ +29 -0
- data/spec/lib/commontator/commontator_config_spec.rb +9 -8
- data/spec/lib/commontator/commontator_config_spec.rb~ +29 -0
- data/spec/lib/commontator/controller_includes_spec.rb +10 -7
- data/spec/lib/commontator/controller_includes_spec.rb~ +18 -0
- data/spec/lib/commontator/shared_helper_spec.rb +14 -9
- data/spec/lib/commontator/shared_helper_spec.rb~ +22 -0
- data/spec/lib/commontator_spec.rb +7 -6
- data/spec/lib/commontator_spec.rb~ +26 -0
- data/spec/mailers/commontator/subscriptions_mailer_spec.rb +30 -0
- data/spec/{app/mailers/commontator/subscriptions_mailer_spec.rb → mailers/commontator/subscriptions_mailer_spec.rb~} +12 -12
- data/spec/models/commontator/comment_spec.rb +82 -0
- data/spec/models/commontator/comment_spec.rb~ +82 -0
- data/spec/{app/models → models}/commontator/subscription_spec.rb +14 -13
- data/spec/models/commontator/subscription_spec.rb~ +38 -0
- data/spec/models/commontator/thread_spec.rb +122 -0
- data/spec/{app/models/commontator/thread_spec.rb → models/commontator/thread_spec.rb~} +52 -50
- data/spec/rails_helper.rb +71 -0
- data/spec/rails_helper.rb~ +74 -0
- data/spec/spec_helper.rb +77 -27
- data/spec/spec_helper.rb~ +86 -0
- metadata +184 -78
- data/spec/app/controllers/commontator/comments_controller_spec.rb +0 -582
- data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +0 -99
- data/spec/app/controllers/commontator/threads_controller_spec.rb +0 -127
- data/spec/app/helpers/commontator/application_helper_spec.rb +0 -9
- data/spec/app/models/commontator/comment_spec.rb +0 -73
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/decb63cac838a5314aa0c22a979f5ac9 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f4de129bb2b1ade35efdef135be03f94c8c9bc5
|
4
|
+
data.tar.gz: e481962df931e8d2907fb4275d54bf8144d69358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5522731e1e6faff67704bdc5fbc77e4c0c717fc37406afbdd1c1d27f9f4132d7678b0207a3ab3f05b6d7a6f938135a4cdceb18573e9691cf1cf4c0a1cfa879c7
|
7
|
+
data.tar.gz: 4d8aaf65ba574ccde30e929f24978045896ef13750dee24fd2617e659547b19a925d19ef3658184ce053b2e4df1d8e46f61d565bdae1dd21bb23d5e7d498d863
|
data/Rakefile
CHANGED
@@ -11,12 +11,13 @@ load 'rails/tasks/engine.rake'
|
|
11
11
|
|
12
12
|
Bundler::GemHelper.install_tasks
|
13
13
|
|
14
|
-
|
14
|
+
begin
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
t.verbose = false
|
19
|
+
task :default => :spec
|
20
|
+
rescue LoadError
|
21
|
+
# no rspec available
|
20
22
|
end
|
21
23
|
|
22
|
-
task :default => :spec
|
@@ -8,8 +8,10 @@ module Commontator
|
|
8
8
|
|
9
9
|
def self.comment_created(comment)
|
10
10
|
recipients = comment.thread.subscribers.reject{|s| s == comment.creator}
|
11
|
-
|
12
|
-
|
11
|
+
return if recipients.empty?
|
12
|
+
|
13
|
+
mail = SubscriptionsMailer.comment_created(comment, recipients)
|
14
|
+
mail.respond_to?(:deliver_later) ? mail.deliver_later : mail.deliver
|
13
15
|
end
|
14
16
|
|
15
17
|
def unread_comments
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Commontator
|
2
|
+
class Subscription < ActiveRecord::Base
|
3
|
+
belongs_to :subscriber, :polymorphic => true
|
4
|
+
belongs_to :thread
|
5
|
+
|
6
|
+
validates_presence_of :subscriber, :thread
|
7
|
+
validates_uniqueness_of :thread_id, :scope => [:subscriber_type, :subscriber_id]
|
8
|
+
|
9
|
+
def self.comment_created(comment)
|
10
|
+
recipients = comment.thread.subscribers.reject{|s| s == comment.creator}
|
11
|
+
return if recipients.empty?
|
12
|
+
|
13
|
+
mail = SubscriptionsMailer.comment_created(comment, recipients)
|
14
|
+
(mail.respond_to?(:deliver_later) ? mail.deliver_later : mail.deliver) \
|
15
|
+
unless recipients.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def unread_comments
|
19
|
+
created_at = Comment.arel_table[:created_at]
|
20
|
+
thread.filtered_comments.where(created_at.gt(updated_at))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -17,16 +17,16 @@
|
|
17
17
|
:method => :put,
|
18
18
|
:remote => true do %>
|
19
19
|
<%= image_submit_tag "commontator/upvote.png",
|
20
|
-
:onmouseover => "this.src='
|
21
|
-
:onmouseout => "this.src='
|
20
|
+
:onmouseover => "this.src='#{image_path("commontator/upvote_hover.png")}'",
|
21
|
+
:onmouseout => "this.src='#{image_path("commontator/upvote.png")}'" %>
|
22
22
|
<% end %>
|
23
23
|
<% elsif can_vote %>
|
24
24
|
<%= form_tag commontator.unvote_comment_path(comment),
|
25
25
|
:method => :put,
|
26
26
|
:remote => true do %>
|
27
27
|
<%= image_submit_tag "commontator/upvote_active.png",
|
28
|
-
:onmouseover => "this.src='
|
29
|
-
:onmouseout => "this.src='
|
28
|
+
:onmouseover => "this.src='#{image_path("commontator/upvote.png")}'",
|
29
|
+
:onmouseout => "this.src='#{image_path("commontator/upvote_active.png")}'"
|
30
30
|
%>
|
31
31
|
<% end %>
|
32
32
|
<% else %>
|
@@ -48,16 +48,16 @@
|
|
48
48
|
:method => :put,
|
49
49
|
:remote => true do %>
|
50
50
|
<%= image_submit_tag "commontator/downvote.png",
|
51
|
-
:onmouseover => "this.src='
|
52
|
-
:onmouseout => "this.src='
|
51
|
+
:onmouseover => "this.src='#{image_path("commontator/downvote_hover.png")}'",
|
52
|
+
:onmouseout => "this.src='#{image_path("commontator/downvote.png")}'" %>
|
53
53
|
<% end %>
|
54
54
|
<% elsif can_vote %>
|
55
55
|
<%= form_tag commontator.unvote_comment_path(comment),
|
56
56
|
:method => :put,
|
57
57
|
:remote => true do %>
|
58
58
|
<%= image_submit_tag "commontator/downvote_active.png",
|
59
|
-
:onmouseover => "this.src='
|
60
|
-
:onmouseout => "this.src='
|
59
|
+
:onmouseover => "this.src='#{image_path("commontator/downvote.png")}'",
|
60
|
+
:onmouseout => "this.src='#{image_path("commontator/downvote_active.png")}'"
|
61
61
|
%>
|
62
62
|
<% end %>
|
63
63
|
<% else %>
|
File without changes
|
data/lib/commontator/engine.rb
CHANGED
data/lib/commontator/version.rb
CHANGED
@@ -0,0 +1,566 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'acts_as_votable'
|
3
|
+
|
4
|
+
module Commontator
|
5
|
+
RSpec.describe CommentsController, type: :controller do
|
6
|
+
routes { Commontator::Engine.routes }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
setup_controller_spec
|
10
|
+
@comment = Comment.new
|
11
|
+
@comment.thread = @thread
|
12
|
+
@comment.creator = @user
|
13
|
+
@comment.body = 'Something'
|
14
|
+
@comment.save!
|
15
|
+
expect(@comment.is_votable?).to eq true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "won't get new unless authorized" do
|
19
|
+
get :new, :thread_id => @thread.id
|
20
|
+
expect(response).to have_http_status(:forbidden)
|
21
|
+
|
22
|
+
sign_in @user
|
23
|
+
get :new, :thread_id => @thread.id
|
24
|
+
expect(response).to have_http_status(:forbidden)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'must get new if authorized' do
|
28
|
+
sign_in @user
|
29
|
+
|
30
|
+
@user.can_read = true
|
31
|
+
get :new, :thread_id => @thread.id
|
32
|
+
expect(response).to redirect_to @thread
|
33
|
+
expect(assigns(:comment).errors).to be_empty
|
34
|
+
|
35
|
+
@user.can_read = false
|
36
|
+
@user.can_edit = true
|
37
|
+
get :new, :thread_id => @thread.id
|
38
|
+
expect(response).to redirect_to @thread
|
39
|
+
expect(assigns(:comment).errors).to be_empty
|
40
|
+
|
41
|
+
@user.can_edit = false
|
42
|
+
@user.is_admin = true
|
43
|
+
get :new, :thread_id => @thread.id
|
44
|
+
expect(response).to redirect_to @thread
|
45
|
+
expect(assigns(:comment).errors).to be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it "won't create unless authorized" do
|
49
|
+
attributes = Hash.new
|
50
|
+
attributes[:body] = 'Something else'
|
51
|
+
|
52
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
53
|
+
expect(response).to have_http_status(:forbidden)
|
54
|
+
|
55
|
+
sign_in @user
|
56
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
57
|
+
expect(response).to have_http_status(:forbidden)
|
58
|
+
|
59
|
+
@user.can_read = true
|
60
|
+
@user.can_edit = true
|
61
|
+
@user.is_admin = true
|
62
|
+
expect(@thread.close).to eq true
|
63
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
64
|
+
expect(response).to have_http_status(:forbidden)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'must create if authorized' do
|
68
|
+
sign_in @user
|
69
|
+
attributes = Hash.new
|
70
|
+
|
71
|
+
attributes[:body] = 'Something else'
|
72
|
+
@user.can_read = true
|
73
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
74
|
+
expect(response).to redirect_to @thread
|
75
|
+
expect(assigns(:comment).errors).to be_empty
|
76
|
+
expect(assigns(:comment).body).to eq 'Something else'
|
77
|
+
expect(assigns(:comment).creator).to eq @user
|
78
|
+
expect(assigns(:comment).editor).to be_nil
|
79
|
+
expect(assigns(:comment).thread).to eq @thread
|
80
|
+
|
81
|
+
attributes[:body] = 'Another thing'
|
82
|
+
@user.can_read = false
|
83
|
+
@user.can_edit = true
|
84
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
85
|
+
expect(response).to redirect_to @thread
|
86
|
+
expect(assigns(:comment).errors).to be_empty
|
87
|
+
expect(assigns(:comment).body).to eq 'Another thing'
|
88
|
+
expect(assigns(:comment).creator).to eq @user
|
89
|
+
expect(assigns(:comment).editor).to be_nil
|
90
|
+
expect(assigns(:comment).thread).to eq @thread
|
91
|
+
|
92
|
+
attributes[:body] = 'And this too'
|
93
|
+
@user.can_edit = false
|
94
|
+
@user.is_admin = true
|
95
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
96
|
+
expect(response).to redirect_to @thread
|
97
|
+
expect(assigns(:comment).errors).to be_empty
|
98
|
+
expect(assigns(:comment).body).to eq 'And this too'
|
99
|
+
expect(assigns(:comment).creator).to eq @user
|
100
|
+
expect(assigns(:comment).editor).to be_nil
|
101
|
+
expect(assigns(:comment).thread).to eq @thread
|
102
|
+
end
|
103
|
+
|
104
|
+
it "won't create if double posting" do
|
105
|
+
sign_in @user
|
106
|
+
@user.can_read = true
|
107
|
+
attributes = Hash.new
|
108
|
+
|
109
|
+
attributes[:body] = 'Something'
|
110
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
111
|
+
assert_redirected_to @thread
|
112
|
+
expect(assigns(:comment).errors).not_to be_empty
|
113
|
+
|
114
|
+
attributes[:body] = 'Something else'
|
115
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
116
|
+
expect(response).to redirect_to @thread
|
117
|
+
expect(assigns(:comment).errors).to be_empty
|
118
|
+
expect(assigns(:comment).body).to eq 'Something else'
|
119
|
+
expect(assigns(:comment).creator).to eq @user
|
120
|
+
expect(assigns(:comment).editor).to be_nil
|
121
|
+
expect(assigns(:comment).thread).to eq @thread
|
122
|
+
|
123
|
+
attributes[:body] = 'Something else'
|
124
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
125
|
+
expect(response).to redirect_to @thread
|
126
|
+
expect(assigns(:comment).errors).not_to be_empty
|
127
|
+
end
|
128
|
+
|
129
|
+
it "won't edit unless authorized" do
|
130
|
+
get :edit, :id => @comment.id
|
131
|
+
expect(response).to have_http_status(:forbidden)
|
132
|
+
|
133
|
+
sign_in @user
|
134
|
+
get :edit, :id => @comment.id
|
135
|
+
expect(response).to have_http_status(:forbidden)
|
136
|
+
|
137
|
+
user2 = DummyUser.create
|
138
|
+
user2.can_read = true
|
139
|
+
user2.can_edit = true
|
140
|
+
user2.is_admin = true
|
141
|
+
sign_in user2
|
142
|
+
get :edit, :id => @comment.id
|
143
|
+
expect(response).to have_http_status(:forbidden)
|
144
|
+
|
145
|
+
@user.can_read = true
|
146
|
+
@user.can_edit = true
|
147
|
+
@user.is_admin = true
|
148
|
+
sign_in @user
|
149
|
+
comment2 = Comment.new
|
150
|
+
comment2.thread = @thread
|
151
|
+
comment2.creator = @user
|
152
|
+
comment2.body = 'Something else'
|
153
|
+
comment2.save!
|
154
|
+
get :edit, :id => @comment.id
|
155
|
+
expect(response).to have_http_status(:forbidden)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'must edit if authorized' do
|
159
|
+
sign_in @user
|
160
|
+
|
161
|
+
@user.can_read = true
|
162
|
+
get :edit, :id => @comment.id
|
163
|
+
expect(response).to redirect_to @thread
|
164
|
+
expect(assigns(:comment).errors).to be_empty
|
165
|
+
|
166
|
+
@user.can_read = false
|
167
|
+
@user.can_edit = true
|
168
|
+
get :edit, :id => @comment.id
|
169
|
+
expect(response).to redirect_to @thread
|
170
|
+
expect(assigns(:comment).errors).to be_empty
|
171
|
+
|
172
|
+
@user.can_edit = false
|
173
|
+
@user.is_admin = true
|
174
|
+
get :edit, :id => @comment.id
|
175
|
+
expect(response).to redirect_to @thread
|
176
|
+
expect(assigns(:comment).errors).to be_empty
|
177
|
+
end
|
178
|
+
|
179
|
+
it "won't update unless authorized" do
|
180
|
+
attributes = Hash.new
|
181
|
+
attributes[:body] = 'Something else'
|
182
|
+
|
183
|
+
put :update, :id => @comment.id, :comment => attributes
|
184
|
+
expect(response).to have_http_status(:forbidden)
|
185
|
+
@comment.reload
|
186
|
+
expect(@comment.body).to eq 'Something'
|
187
|
+
expect(@comment.editor).to be_nil
|
188
|
+
|
189
|
+
sign_in @user
|
190
|
+
put :update, :id => @comment.id, :comment => attributes
|
191
|
+
expect(response).to have_http_status(:forbidden)
|
192
|
+
@comment.reload
|
193
|
+
expect(@comment.body).to eq 'Something'
|
194
|
+
expect(@comment.editor).to be_nil
|
195
|
+
|
196
|
+
user2 = DummyUser.create
|
197
|
+
user2.can_read = true
|
198
|
+
user2.can_edit = true
|
199
|
+
user2.is_admin = true
|
200
|
+
sign_in user2
|
201
|
+
put :update, :id => @comment.id, :comment => attributes
|
202
|
+
expect(response).to have_http_status(:forbidden)
|
203
|
+
@comment.reload
|
204
|
+
expect(@comment.body).to eq 'Something'
|
205
|
+
expect(@comment.editor).to be_nil
|
206
|
+
|
207
|
+
@user.can_read = true
|
208
|
+
@user.can_edit = true
|
209
|
+
@user.is_admin = true
|
210
|
+
sign_in @user
|
211
|
+
comment2 = Comment.new
|
212
|
+
comment2.thread = @thread
|
213
|
+
comment2.creator = @user
|
214
|
+
comment2.body = 'Something else'
|
215
|
+
comment2.save!
|
216
|
+
put :update, :id => @comment.id, :comment => attributes
|
217
|
+
expect(response).to have_http_status(:forbidden)
|
218
|
+
@comment.reload
|
219
|
+
expect(@comment.body).to eq 'Something'
|
220
|
+
expect(@comment.editor).to be_nil
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'must update if authorized' do
|
224
|
+
sign_in @user
|
225
|
+
attributes = Hash.new
|
226
|
+
attributes[:body] = 'Something else'
|
227
|
+
|
228
|
+
@user.can_read = true
|
229
|
+
put :update, :id => @comment.id, :comment => attributes
|
230
|
+
expect(response).to redirect_to @thread
|
231
|
+
expect(assigns(:comment).errors).to be_empty
|
232
|
+
expect(assigns(:comment).editor).to eq @user
|
233
|
+
|
234
|
+
@user.can_read = false
|
235
|
+
@user.can_edit = true
|
236
|
+
put :update, :id => @comment.id, :comment => attributes
|
237
|
+
expect(response).to redirect_to @thread
|
238
|
+
expect(assigns(:comment).errors).to be_empty
|
239
|
+
expect(assigns(:comment).editor).to eq @user
|
240
|
+
|
241
|
+
@user.can_edit = false
|
242
|
+
@user.is_admin = true
|
243
|
+
put :update, :id => @comment.id, :comment => attributes
|
244
|
+
expect(response).to redirect_to @thread
|
245
|
+
expect(assigns(:comment).errors).to be_empty
|
246
|
+
expect(assigns(:comment).editor).to eq @user
|
247
|
+
end
|
248
|
+
|
249
|
+
it "won't delete unless authorized and not deleted" do
|
250
|
+
put :delete, :id => @comment.id
|
251
|
+
expect(response).to have_http_status(:forbidden)
|
252
|
+
@comment.reload
|
253
|
+
expect(@comment.is_deleted?).to eq false
|
254
|
+
|
255
|
+
sign_in @user
|
256
|
+
|
257
|
+
put :delete, :id => @comment.id
|
258
|
+
expect(response).to have_http_status(:forbidden)
|
259
|
+
@comment.reload
|
260
|
+
expect(@comment.is_deleted?).to eq false
|
261
|
+
|
262
|
+
@user.can_read = true
|
263
|
+
expect(@comment.delete_by(@user)).to eq true
|
264
|
+
put :delete, :id => @comment.id
|
265
|
+
expect(response).to redirect_to @thread
|
266
|
+
expect(assigns(:comment).errors).not_to be_empty
|
267
|
+
|
268
|
+
comment2 = Comment.new
|
269
|
+
comment2.thread = @thread
|
270
|
+
comment2.creator = @user
|
271
|
+
comment2.body = 'Something else'
|
272
|
+
comment2.save!
|
273
|
+
expect(@comment.undelete_by(@user)).to eq true
|
274
|
+
put :delete, :id => @comment.id
|
275
|
+
expect(response).to have_http_status(:forbidden)
|
276
|
+
@comment.reload
|
277
|
+
expect(@comment.is_deleted?).to eq false
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'must delete if authorized and not deleted' do
|
281
|
+
sign_in @user
|
282
|
+
|
283
|
+
@user.can_read = true
|
284
|
+
put :delete, :id => @comment.id
|
285
|
+
expect(response).to redirect_to @thread
|
286
|
+
expect(assigns(:comment).errors).to be_empty
|
287
|
+
expect(assigns(:comment).is_deleted?).to eq true
|
288
|
+
expect(assigns(:comment).editor).to eq @user
|
289
|
+
|
290
|
+
user2 = DummyUser.create
|
291
|
+
sign_in user2
|
292
|
+
comment2 = Comment.new
|
293
|
+
comment2.thread = @thread
|
294
|
+
comment2.creator = @user
|
295
|
+
comment2.body = 'Something else'
|
296
|
+
comment2.save!
|
297
|
+
|
298
|
+
expect(assigns(:comment).undelete_by(@user)).to eq true
|
299
|
+
user2.can_edit = true
|
300
|
+
put :delete, :id => @comment.id
|
301
|
+
expect(response).to redirect_to @thread
|
302
|
+
expect(assigns(:comment).errors).to be_empty
|
303
|
+
expect(assigns(:comment).is_deleted?).to eq true
|
304
|
+
expect(assigns(:comment).editor).to eq user2
|
305
|
+
|
306
|
+
expect(assigns(:comment).undelete_by(@user)).to eq true
|
307
|
+
user2.can_edit = false
|
308
|
+
user2.is_admin = true
|
309
|
+
put :delete, :id => @comment.id
|
310
|
+
expect(response).to redirect_to @thread
|
311
|
+
expect(assigns(:comment).errors).to be_empty
|
312
|
+
expect(assigns(:comment).is_deleted?).to eq true
|
313
|
+
expect(assigns(:comment).editor).to eq user2
|
314
|
+
end
|
315
|
+
|
316
|
+
it "won't undelete unless authorized and deleted" do
|
317
|
+
expect(@comment.delete_by(@user)).to eq true
|
318
|
+
put :undelete, :id => @comment.id
|
319
|
+
expect(response).to have_http_status(:forbidden)
|
320
|
+
@comment.reload
|
321
|
+
expect(@comment.is_deleted?).to eq true
|
322
|
+
|
323
|
+
sign_in @user
|
324
|
+
|
325
|
+
put :undelete, :id => @comment.id
|
326
|
+
expect(response).to have_http_status(:forbidden)
|
327
|
+
@comment.reload
|
328
|
+
expect(@comment.is_deleted?).to eq true
|
329
|
+
|
330
|
+
@user.can_read = true
|
331
|
+
expect(@comment.undelete_by(@user)).to eq true
|
332
|
+
put :undelete, :id => @comment.id
|
333
|
+
expect(response).to redirect_to @thread
|
334
|
+
expect(assigns(:comment).errors).not_to be_empty
|
335
|
+
|
336
|
+
user2 = DummyUser.create
|
337
|
+
user2.can_read = true
|
338
|
+
user2.can_edit = true
|
339
|
+
user2.is_admin = true
|
340
|
+
expect(@comment.delete_by(user2)).to eq true
|
341
|
+
put :undelete, :id => @comment.id
|
342
|
+
expect(response).to have_http_status(:forbidden)
|
343
|
+
@comment.reload
|
344
|
+
expect(@comment.is_deleted?).to eq true
|
345
|
+
|
346
|
+
comment2 = Comment.new
|
347
|
+
comment2.thread = @thread
|
348
|
+
comment2.creator = @user
|
349
|
+
comment2.body = 'Something else'
|
350
|
+
comment2.save!
|
351
|
+
expect(@comment.undelete_by(@user)).to eq true
|
352
|
+
expect(@comment.delete_by(@user)).to eq true
|
353
|
+
put :undelete, :id => @comment.id
|
354
|
+
expect(response).to have_http_status(:forbidden)
|
355
|
+
@comment.reload
|
356
|
+
expect(@comment.is_deleted?).to eq true
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'must undelete if authorized and deleted' do
|
360
|
+
sign_in @user
|
361
|
+
|
362
|
+
expect(@comment.delete_by(@user)).to eq true
|
363
|
+
@user.can_read = true
|
364
|
+
put :undelete, :id => @comment.id
|
365
|
+
expect(response).to redirect_to @thread
|
366
|
+
expect(assigns(:comment).errors).to be_empty
|
367
|
+
expect(assigns(:comment).is_deleted?).to eq false
|
368
|
+
|
369
|
+
user2 = DummyUser.create
|
370
|
+
sign_in user2
|
371
|
+
comment2 = Comment.new
|
372
|
+
comment2.thread = @thread
|
373
|
+
comment2.creator = @user
|
374
|
+
comment2.body = 'Something else'
|
375
|
+
comment2.save!
|
376
|
+
|
377
|
+
expect(assigns(:comment).delete_by(@user)).to eq true
|
378
|
+
user2.can_edit = true
|
379
|
+
put :undelete, :id => @comment.id
|
380
|
+
expect(response).to redirect_to @thread
|
381
|
+
expect(assigns(:comment).errors).to be_empty
|
382
|
+
expect(assigns(:comment).is_deleted?).to eq false
|
383
|
+
|
384
|
+
expect(assigns(:comment).delete_by(@user)).to eq true
|
385
|
+
user2.can_edit = false
|
386
|
+
user2.is_admin = true
|
387
|
+
put :undelete, :id => @comment.id
|
388
|
+
expect(response).to redirect_to @thread
|
389
|
+
expect(assigns(:comment).errors).to be_empty
|
390
|
+
expect(assigns(:comment).is_deleted?).to eq false
|
391
|
+
end
|
392
|
+
|
393
|
+
it "won't upvote unless authorized" do
|
394
|
+
put :upvote, :id => @comment.id
|
395
|
+
expect(response).to have_http_status(:forbidden)
|
396
|
+
@comment.reload
|
397
|
+
expect(@comment.get_upvotes).to be_empty
|
398
|
+
expect(@comment.get_downvotes).to be_empty
|
399
|
+
|
400
|
+
sign_in @user
|
401
|
+
@user.can_read = true
|
402
|
+
put :upvote, :id => @comment.id
|
403
|
+
expect(response).to have_http_status(:forbidden)
|
404
|
+
@comment.reload
|
405
|
+
expect(@comment.get_upvotes).to be_empty
|
406
|
+
expect(@comment.get_downvotes).to be_empty
|
407
|
+
|
408
|
+
user2 = DummyUser.create
|
409
|
+
sign_in user2
|
410
|
+
put :upvote, :id => @comment.id
|
411
|
+
expect(response).to have_http_status(:forbidden)
|
412
|
+
@comment.reload
|
413
|
+
expect(@comment.get_upvotes).to be_empty
|
414
|
+
expect(@comment.get_downvotes).to be_empty
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'must upvote if authorized' do
|
418
|
+
user2 = DummyUser.create
|
419
|
+
user2.can_read = true
|
420
|
+
sign_in user2
|
421
|
+
|
422
|
+
put :upvote, :id => @comment.id
|
423
|
+
expect(response).to redirect_to @thread
|
424
|
+
expect(assigns(:comment).get_upvotes.count).to eq 1
|
425
|
+
expect(assigns(:comment).get_downvotes).to be_empty
|
426
|
+
|
427
|
+
put :upvote, :id => @comment.id
|
428
|
+
expect(response).to redirect_to @thread
|
429
|
+
expect(assigns(:comment).get_upvotes.count).to eq 1
|
430
|
+
expect(assigns(:comment).get_downvotes).to be_empty
|
431
|
+
|
432
|
+
expect(@comment.downvote_from(user2)).to eq true
|
433
|
+
|
434
|
+
put :upvote, :id => @comment.id
|
435
|
+
expect(response).to redirect_to @thread
|
436
|
+
expect(assigns(:comment).get_upvotes.count).to eq 1
|
437
|
+
expect(assigns(:comment).get_downvotes).to be_empty
|
438
|
+
end
|
439
|
+
|
440
|
+
it "won't downvote unless authorized" do
|
441
|
+
put :downvote, :id => @comment.id
|
442
|
+
expect(response).to have_http_status(:forbidden)
|
443
|
+
@comment.reload
|
444
|
+
expect(@comment.get_upvotes).to be_empty
|
445
|
+
expect(@comment.get_downvotes).to be_empty
|
446
|
+
|
447
|
+
sign_in @user
|
448
|
+
@user.can_read = true
|
449
|
+
put :downvote, :id => @comment.id
|
450
|
+
expect(response).to have_http_status(:forbidden)
|
451
|
+
@comment.reload
|
452
|
+
expect(@comment.get_upvotes).to be_empty
|
453
|
+
expect(@comment.get_downvotes).to be_empty
|
454
|
+
|
455
|
+
user2 = DummyUser.create
|
456
|
+
sign_in user2
|
457
|
+
put :downvote, :id => @comment.id
|
458
|
+
expect(response).to have_http_status(:forbidden)
|
459
|
+
@comment.reload
|
460
|
+
expect(@comment.get_upvotes).to be_empty
|
461
|
+
expect(@comment.get_downvotes).to be_empty
|
462
|
+
end
|
463
|
+
|
464
|
+
it 'must downvote if authorized' do
|
465
|
+
user2 = DummyUser.create
|
466
|
+
user2.can_read = true
|
467
|
+
sign_in user2
|
468
|
+
|
469
|
+
put :downvote, :id => @comment.id
|
470
|
+
expect(response).to redirect_to @thread
|
471
|
+
expect(@comment.get_upvotes).to be_empty
|
472
|
+
expect(@comment.get_downvotes.count).to eq 1
|
473
|
+
|
474
|
+
put :downvote, :id => @comment.id
|
475
|
+
expect(response).to redirect_to @thread
|
476
|
+
expect(@comment.get_upvotes).to be_empty
|
477
|
+
expect(@comment.get_downvotes.count).to eq 1
|
478
|
+
|
479
|
+
expect(@comment.upvote_from(user2)).to eq true
|
480
|
+
|
481
|
+
put :downvote, :id => @comment.id
|
482
|
+
expect(response).to redirect_to @thread
|
483
|
+
expect(@comment.get_upvotes).to be_empty
|
484
|
+
expect(@comment.get_downvotes.count).to eq 1
|
485
|
+
end
|
486
|
+
|
487
|
+
it "won't unvote unless authorized" do
|
488
|
+
expect(@comment.upvote_from(@user)).to eq true
|
489
|
+
|
490
|
+
put :unvote, :id => @comment.id
|
491
|
+
expect(response).to have_http_status(:forbidden)
|
492
|
+
@comment.reload
|
493
|
+
expect(@comment.get_upvotes.count).to eq 1
|
494
|
+
expect(@comment.get_downvotes).to be_empty
|
495
|
+
|
496
|
+
sign_in @user
|
497
|
+
@user.can_read = true
|
498
|
+
put :unvote, :id => @comment.id
|
499
|
+
expect(response).to have_http_status(:forbidden)
|
500
|
+
@comment.reload
|
501
|
+
expect(@comment.get_upvotes.count).to eq 1
|
502
|
+
expect(@comment.get_downvotes).to be_empty
|
503
|
+
|
504
|
+
user2 = DummyUser.create
|
505
|
+
sign_in user2
|
506
|
+
put :unvote, :id => @comment.id
|
507
|
+
expect(response).to have_http_status(:forbidden)
|
508
|
+
@comment.reload
|
509
|
+
expect(@comment.get_upvotes.count).to eq 1
|
510
|
+
expect(@comment.get_downvotes).to be_empty
|
511
|
+
end
|
512
|
+
|
513
|
+
it 'must unvote if authorized' do
|
514
|
+
user2 = DummyUser.create
|
515
|
+
user2.can_read = true
|
516
|
+
sign_in user2
|
517
|
+
|
518
|
+
expect(@comment.upvote_from(user2)).to eq true
|
519
|
+
put :unvote, :id => @comment.id
|
520
|
+
expect(response).to redirect_to @thread
|
521
|
+
expect(assigns(:comment).get_upvotes).to be_empty
|
522
|
+
expect(assigns(:comment).get_downvotes).to be_empty
|
523
|
+
|
524
|
+
put :unvote, :id => @comment.id
|
525
|
+
expect(response).to redirect_to @thread
|
526
|
+
expect(assigns(:comment).get_upvotes).to be_empty
|
527
|
+
expect(assigns(:comment).get_downvotes).to be_empty
|
528
|
+
|
529
|
+
expect(@comment.downvote_from(user2)).to eq true
|
530
|
+
put :unvote, :id => @comment.id
|
531
|
+
expect(response).to redirect_to @thread
|
532
|
+
expect(assigns(:comment).get_upvotes).to be_empty
|
533
|
+
expect(assigns(:comment).get_downvotes).to be_empty
|
534
|
+
end
|
535
|
+
|
536
|
+
it "won't send mail if recipients empty" do
|
537
|
+
user2 = DummyUser.create
|
538
|
+
user2.can_read = true
|
539
|
+
|
540
|
+
@user.can_read = true
|
541
|
+
sign_in @user
|
542
|
+
|
543
|
+
attributes = { :body => 'Something else' }
|
544
|
+
expect {
|
545
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
546
|
+
}.not_to change{ ActionMailer::Base.deliveries.count }
|
547
|
+
expect(assigns(:comment).errors).to be_empty
|
548
|
+
end
|
549
|
+
|
550
|
+
it 'must send mail if recipients not empty' do
|
551
|
+
user2 = DummyUser.create
|
552
|
+
user2.can_read = true
|
553
|
+
@thread.subscribe(user2)
|
554
|
+
|
555
|
+
@user.can_read = true
|
556
|
+
sign_in @user
|
557
|
+
|
558
|
+
attributes = { :body => 'Something else' }
|
559
|
+
expect {
|
560
|
+
post :create, :thread_id => @thread.id, :comment => attributes
|
561
|
+
}.to change{ ActionMailer::Base.deliveries.count }.by(1)
|
562
|
+
expect(assigns(:comment).errors).to be_empty
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|