commontator 0.1.46
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +40 -0
- data/app/assets/images/commontator/downvote.png +0 -0
- data/app/assets/images/commontator/downvote_hover.png +0 -0
- data/app/assets/images/commontator/upvote.png +0 -0
- data/app/assets/images/commontator/upvote_hover.png +0 -0
- data/app/assets/stylesheets/commontator/application.css +13 -0
- data/app/assets/stylesheets/commontator/application.css~ +88 -0
- data/app/assets/stylesheets/commontator/comments.css +86 -0
- data/app/assets/stylesheets/commontator/comments.css~ +90 -0
- data/app/assets/stylesheets/commontator/threads.css +13 -0
- data/app/assets/stylesheets/commontator/threads.css~ +13 -0
- data/app/controllers/commontator/application_controller.rb +18 -0
- data/app/controllers/commontator/application_controller.rb~ +16 -0
- data/app/controllers/commontator/comments_controller.rb +143 -0
- data/app/controllers/commontator/comments_controller.rb~ +143 -0
- data/app/controllers/commontator/subscriptions_controller.rb +42 -0
- data/app/controllers/commontator/subscriptions_controller.rb~ +40 -0
- data/app/controllers/commontator/threads_controller.rb +42 -0
- data/app/controllers/commontator/threads_controller.rb~ +43 -0
- data/app/helpers/commontator/application_helper.rb +11 -0
- data/app/helpers/commontator/application_helper.rb~ +11 -0
- data/app/helpers/commontator/comments_helper.rb +47 -0
- data/app/helpers/commontator/comments_helper.rb~ +58 -0
- data/app/helpers/commontator/commontable_helper.rb~ +9 -0
- data/app/helpers/commontator/commontator_helper.rb +8 -0
- data/app/helpers/commontator/commontator_helper.rb~ +8 -0
- data/app/helpers/commontator/subscriptions_helper.rb +8 -0
- data/app/helpers/commontator/subscriptions_helper.rb~ +8 -0
- data/app/helpers/commontator/threads_helper.rb +21 -0
- data/app/helpers/commontator/threads_helper.rb~ +32 -0
- data/app/mailers/commontator/subscription_mailer.rb~ +38 -0
- data/app/mailers/commontator/subscriptions_mailer.rb +51 -0
- data/app/mailers/commontator/subscriptions_mailer.rb~ +51 -0
- data/app/models/commontator/comment.rb +84 -0
- data/app/models/commontator/comment.rb~ +84 -0
- data/app/models/commontator/subscription.rb +21 -0
- data/app/models/commontator/subscription.rb~ +21 -0
- data/app/models/commontator/thread.rb +138 -0
- data/app/models/commontator/thread.rb~ +141 -0
- data/app/views/commontator/comments/_actions.html.erb +32 -0
- data/app/views/commontator/comments/_actions.html.erb~ +33 -0
- data/app/views/commontator/comments/_body.html.erb +7 -0
- data/app/views/commontator/comments/_body.html.erb~ +8 -0
- data/app/views/commontator/comments/_form.html.erb +20 -0
- data/app/views/commontator/comments/_form.html.erb~ +21 -0
- data/app/views/commontator/comments/_show.html.erb +41 -0
- data/app/views/commontator/comments/_show.html.erb~ +45 -0
- data/app/views/commontator/comments/_votes.html.erb +60 -0
- data/app/views/commontator/comments/_votes.html.erb~ +62 -0
- data/app/views/commontator/comments/create.js.erb +15 -0
- data/app/views/commontator/comments/create.js.erb~ +15 -0
- data/app/views/commontator/comments/delete.js.erb +15 -0
- data/app/views/commontator/comments/delete.js.erb~ +15 -0
- data/app/views/commontator/comments/destroy.js.erb~ +1 -0
- data/app/views/commontator/comments/edit.html.erb +6 -0
- data/app/views/commontator/comments/edit.html.erb~ +6 -0
- data/app/views/commontator/comments/edit.js.erb +5 -0
- data/app/views/commontator/comments/edit.js.erb~ +5 -0
- data/app/views/commontator/comments/new.html.erb +8 -0
- data/app/views/commontator/comments/new.html.erb~ +8 -0
- data/app/views/commontator/comments/new.js.erb +12 -0
- data/app/views/commontator/comments/new.js.erb~ +12 -0
- data/app/views/commontator/comments/update.js.erb +7 -0
- data/app/views/commontator/comments/update.js.erb~ +7 -0
- data/app/views/commontator/comments/vote.js.erb +5 -0
- data/app/views/commontator/comments/vote.js.erb~ +5 -0
- data/app/views/commontator/commontator/_thread.html.erb +14 -0
- data/app/views/commontator/commontator/_thread.html.erb~ +15 -0
- data/app/views/commontator/subscriptions/_subscription_link.html.erb +12 -0
- data/app/views/commontator/subscriptions/_subscription_link.html.erb~ +12 -0
- data/app/views/commontator/subscriptions/create.js.erb +5 -0
- data/app/views/commontator/subscriptions/create.js.erb~ +3 -0
- data/app/views/commontator/subscriptions/destroy.js.erb +5 -0
- data/app/views/commontator/subscriptions/destroy.js.erb~ +3 -0
- data/app/views/commontator/subscriptions/index.html.erb +16 -0
- data/app/views/commontator/subscriptions/index.html.erb~ +16 -0
- data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb +14 -0
- data/app/views/commontator/subscriptions_mailer/comment_created_email.html.erb~ +14 -0
- data/app/views/commontator/threads/_show.html.erb +26 -0
- data/app/views/commontator/threads/_show.html.erb~ +26 -0
- data/app/views/commontator/threads/show.html.erb +3 -0
- data/app/views/commontator/threads/show.js.erb +6 -0
- data/app/views/layouts/commontator/application.html.erb +14 -0
- data/config/initializers/commontator.rb +7 -0
- data/config/routes.rb +24 -0
- data/config/routes.rb~ +22 -0
- data/db/migrate/0_install_commontator.rb +40 -0
- data/db/migrate/0_install_commontator.rb~ +40 -0
- data/lib/commontator.rb +66 -0
- data/lib/commontator.rb~ +66 -0
- data/lib/commontator/acts_as_commontable.rb +39 -0
- data/lib/commontator/acts_as_commontable.rb~ +42 -0
- data/lib/commontator/acts_as_commontator.rb +28 -0
- data/lib/commontator/acts_as_commontator.rb~ +37 -0
- data/lib/commontator/commontable_config.rb +13 -0
- data/lib/commontator/commontator_config.rb +13 -0
- data/lib/commontator/engine.rb +5 -0
- data/lib/commontator/routes.rb~ +37 -0
- data/lib/commontator/version.rb +3 -0
- data/lib/commontator/version.rb~ +3 -0
- data/test/commontator_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +16 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +204 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/comment_thread_subscriptions_controller_test.rb~ +125 -0
- data/test/functional/comments_controller_test.rb +181 -0
- data/test/functional/comments_controller_test.rb~ +184 -0
- data/test/functional/subscriptions_controller_test.rb +122 -0
- data/test/functional/subscriptions_controller_test.rb~ +122 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/comment_test.rb +35 -0
- data/test/unit/comment_test.rb~ +38 -0
- data/test/unit/comment_thread_subscription_test.rb~ +18 -0
- data/test/unit/comment_thread_test.rb~ +60 -0
- data/test/unit/helpers/comment_thread_subscriptions_helper_test.rb~ +7 -0
- data/test/unit/helpers/comments_helper_test.rb +4 -0
- data/test/unit/helpers/comments_helper_test.rb~ +7 -0
- data/test/unit/helpers/subscriptions_helper_test.rb +4 -0
- data/test/unit/helpers/subscriptions_helper_test.rb~ +4 -0
- data/test/unit/subscription_test.rb +15 -0
- data/test/unit/subscription_test.rb~ +15 -0
- data/test/unit/thread_test.rb +57 -0
- data/test/unit/thread_test.rb~ +57 -0
- metadata +301 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SubscriptionsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@question = FactoryGirl.create(:simple_question)
|
7
|
+
@user = FactoryGirl.create(:user)
|
8
|
+
FactoryGirl.create(:project_question, :question => @question, :project => Project.default_for_user!(@user))
|
9
|
+
@published_question = make_simple_question(:method => :create, :published => true)
|
10
|
+
@user2 = FactoryGirl.create(:user)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should not get index not logged in" do
|
14
|
+
get :index
|
15
|
+
assert_redirected_to login_path
|
16
|
+
end
|
17
|
+
|
18
|
+
test "should get index" do
|
19
|
+
user_login
|
20
|
+
get :index
|
21
|
+
assert_response :success
|
22
|
+
end
|
23
|
+
|
24
|
+
test "should not create subscription not logged in" do
|
25
|
+
assert_difference('Subscription.count', 0) do
|
26
|
+
get :create, :question_id => @question.to_param
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_redirected_to login_path
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should not create subscription not authorized" do
|
33
|
+
user_login
|
34
|
+
assert_difference('Subscription.count', 0) do
|
35
|
+
get :create, :question_id => @question.to_param
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_response(403)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should not create subscription already subscribed" do
|
42
|
+
sign_in @user
|
43
|
+
FactoryGirl.create(:subscription,
|
44
|
+
:user => @user, :thread => @question.thread)
|
45
|
+
assert_difference('Subscription.count', 0) do
|
46
|
+
get :create, :question_id => @question.to_param
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "should create subscription" do
|
53
|
+
sign_in @user
|
54
|
+
assert_difference('Subscription.count') do
|
55
|
+
get :create, :question_id => @question.to_param
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
59
|
+
end
|
60
|
+
|
61
|
+
test "should create subscription published question" do
|
62
|
+
user_login
|
63
|
+
assert_difference('Subscription.count') do
|
64
|
+
get :create, :question_id => @published_question.to_param
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_redirected_to question_comments_path(@published_question.to_param)
|
68
|
+
end
|
69
|
+
|
70
|
+
test "should not destroy comment_thread_subscription not logged in" do
|
71
|
+
FactoryGirl.create(:comment_thread_subscription,
|
72
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
73
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
74
|
+
get :destroy, :question_id => @question.to_param
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_redirected_to login_path
|
78
|
+
end
|
79
|
+
|
80
|
+
test "should not destroy comment_thread_subscription not authorized" do
|
81
|
+
user_login
|
82
|
+
FactoryGirl.create(:comment_thread_subscription,
|
83
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
84
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
85
|
+
get :destroy, :question_id => @question.to_param
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_response(403)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "should not destroy comment_thread_subscription no subscription" do
|
92
|
+
sign_in @user
|
93
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
94
|
+
get :destroy, :question_id => @question.to_param
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
98
|
+
end
|
99
|
+
|
100
|
+
test "should destroy comment_thread_subscription" do
|
101
|
+
sign_in @user
|
102
|
+
FactoryGirl.create(:comment_thread_subscription,
|
103
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
104
|
+
assert_difference('CommentThreadSubscription.count', -1) do
|
105
|
+
get :destroy, :question_id => @question.to_param
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
109
|
+
end
|
110
|
+
|
111
|
+
test "should destroy comment_thread_subscription published question" do
|
112
|
+
sign_in @user2
|
113
|
+
FactoryGirl.create(:comment_thread_subscription,
|
114
|
+
:user => @user2, :comment_thread => @published_question.comment_thread)
|
115
|
+
assert_difference('CommentThreadSubscription.count', -1) do
|
116
|
+
get :destroy, :question_id => @published_question.to_param
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_redirected_to question_comments_path(@published_question.to_param)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CommentThreadSubscriptionsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@question = FactoryGirl.create(:simple_question)
|
7
|
+
@user = FactoryGirl.create(:user)
|
8
|
+
FactoryGirl.create(:project_question, :question => @question, :project => Project.default_for_user!(@user))
|
9
|
+
@published_question = make_simple_question(:method => :create, :published => true)
|
10
|
+
@user2 = FactoryGirl.create(:user)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should not get index not logged in" do
|
14
|
+
get :index
|
15
|
+
assert_redirected_to login_path
|
16
|
+
end
|
17
|
+
|
18
|
+
test "should get index" do
|
19
|
+
user_login
|
20
|
+
get :index
|
21
|
+
assert_response :success
|
22
|
+
end
|
23
|
+
|
24
|
+
test "should not create comment_thread_subscription not logged in" do
|
25
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
26
|
+
get :create, :question_id => @question.to_param
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_redirected_to login_path
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should not create comment_thread_subscription not authorized" do
|
33
|
+
user_login
|
34
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
35
|
+
get :create, :question_id => @question.to_param
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_response(403)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should not create comment_thread_subscription already subscribed" do
|
42
|
+
sign_in @user
|
43
|
+
FactoryGirl.create(:comment_thread_subscription,
|
44
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
45
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
46
|
+
get :create, :question_id => @question.to_param
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "should create comment_thread_subscription" do
|
53
|
+
sign_in @user
|
54
|
+
assert_difference('CommentThreadSubscription.count') do
|
55
|
+
get :create, :question_id => @question.to_param
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
59
|
+
end
|
60
|
+
|
61
|
+
test "should create comment_thread_subscription published question" do
|
62
|
+
user_login
|
63
|
+
assert_difference('CommentThreadSubscription.count') do
|
64
|
+
get :create, :question_id => @published_question.to_param
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_redirected_to question_comments_path(@published_question.to_param)
|
68
|
+
end
|
69
|
+
|
70
|
+
test "should not destroy comment_thread_subscription not logged in" do
|
71
|
+
FactoryGirl.create(:comment_thread_subscription,
|
72
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
73
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
74
|
+
get :destroy, :question_id => @question.to_param
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_redirected_to login_path
|
78
|
+
end
|
79
|
+
|
80
|
+
test "should not destroy comment_thread_subscription not authorized" do
|
81
|
+
user_login
|
82
|
+
FactoryGirl.create(:comment_thread_subscription,
|
83
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
84
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
85
|
+
get :destroy, :question_id => @question.to_param
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_response(403)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "should not destroy comment_thread_subscription no subscription" do
|
92
|
+
sign_in @user
|
93
|
+
assert_difference('CommentThreadSubscription.count', 0) do
|
94
|
+
get :destroy, :question_id => @question.to_param
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
98
|
+
end
|
99
|
+
|
100
|
+
test "should destroy comment_thread_subscription" do
|
101
|
+
sign_in @user
|
102
|
+
FactoryGirl.create(:comment_thread_subscription,
|
103
|
+
:user => @user, :comment_thread => @question.comment_thread)
|
104
|
+
assert_difference('CommentThreadSubscription.count', -1) do
|
105
|
+
get :destroy, :question_id => @question.to_param
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_redirected_to question_comments_path(@question.to_param)
|
109
|
+
end
|
110
|
+
|
111
|
+
test "should destroy comment_thread_subscription published question" do
|
112
|
+
sign_in @user2
|
113
|
+
FactoryGirl.create(:comment_thread_subscription,
|
114
|
+
:user => @user2, :comment_thread => @published_question.comment_thread)
|
115
|
+
assert_difference('CommentThreadSubscription.count', -1) do
|
116
|
+
get :destroy, :question_id => @published_question.to_param
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_redirected_to question_comments_path(@published_question.to_param)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CommentTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "cannot mass-assign comment_thread, creator" do
|
6
|
+
ct = FactoryGirl.create(:comment_thread)
|
7
|
+
u = FactoryGirl.create(:user)
|
8
|
+
c = Comment.new(:comment_thread => ct, :creator => u)
|
9
|
+
assert c.comment_thread != ct
|
10
|
+
assert c.creator != u
|
11
|
+
end
|
12
|
+
|
13
|
+
test "is_modified" do
|
14
|
+
c = FactoryGirl.create(:comment)
|
15
|
+
assert !c.is_modified?
|
16
|
+
c.message = 'Another message'
|
17
|
+
c.save!
|
18
|
+
assert c.is_modified?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "must have comment_thread and creator" do
|
22
|
+
ct = FactoryGirl.create(:comment_thread)
|
23
|
+
u = FactoryGirl.create(:user)
|
24
|
+
c = Comment.new(:message => "Some message")
|
25
|
+
assert !c.save
|
26
|
+
c.comment_thread = ct
|
27
|
+
assert !c.save
|
28
|
+
c.comment_thread = nil
|
29
|
+
c.creator = u
|
30
|
+
assert !c.save
|
31
|
+
c.comment_thread = ct
|
32
|
+
c.save!
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright 2011-2012 Rice University. Licensed under the Affero General Public
|
2
|
+
# License version 3 or later. See the COPYRIGHT file for details.
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class CommentTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
test "cannot mass-assign comment_thread, creator" do
|
9
|
+
ct = FactoryGirl.create(:comment_thread)
|
10
|
+
u = FactoryGirl.create(:user)
|
11
|
+
c = Comment.new(:comment_thread => ct, :creator => u)
|
12
|
+
assert c.comment_thread != ct
|
13
|
+
assert c.creator != u
|
14
|
+
end
|
15
|
+
|
16
|
+
test "is_modified" do
|
17
|
+
c = FactoryGirl.create(:comment)
|
18
|
+
assert !c.is_modified?
|
19
|
+
c.message = 'Another message'
|
20
|
+
c.save!
|
21
|
+
assert c.is_modified?
|
22
|
+
end
|
23
|
+
|
24
|
+
test "must have comment_thread and creator" do
|
25
|
+
ct = FactoryGirl.create(:comment_thread)
|
26
|
+
u = FactoryGirl.create(:user)
|
27
|
+
c = Comment.new(:message => "Some message")
|
28
|
+
assert !c.save
|
29
|
+
c.comment_thread = ct
|
30
|
+
assert !c.save
|
31
|
+
c.comment_thread = nil
|
32
|
+
c.creator = u
|
33
|
+
assert !c.save
|
34
|
+
c.comment_thread = ct
|
35
|
+
c.save!
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright 2011-2012 Rice University. Licensed under the Affero General Public
|
2
|
+
# License version 3 or later. See the COPYRIGHT file for details.
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class CommentThreadSubscriptionTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
test 'one comment_thread_subscription per user per thread' do
|
9
|
+
u = FactoryGirl.create(:user)
|
10
|
+
ct = FactoryGirl.create(:comment_thread)
|
11
|
+
cts0 = CommentThreadSubscription.create(:user => u, :comment_thread => ct)
|
12
|
+
cts1 = CommentThreadSubscription.new(:user => u, :comment_thread => ct)
|
13
|
+
assert !cts1.save
|
14
|
+
cts0.destroy
|
15
|
+
cts1.save!
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Copyright 2011-2012 Rice University. Licensed under the Affero General Public
|
2
|
+
# License version 3 or later. See the COPYRIGHT file for details.
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class CommentThreadTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
test 'cannot mass-assign commentable, comments and comment_thread_subscriptions' do
|
9
|
+
sq = FactoryGirl.create(:simple_question)
|
10
|
+
c = [FactoryGirl.create(:comment)]
|
11
|
+
cts = [FactoryGirl.create(:comment_thread_subscription)]
|
12
|
+
ct = CommentThread.new(:commentable => sq,
|
13
|
+
:comments => c,
|
14
|
+
:comment_thread_subscriptions => cts)
|
15
|
+
assert ct.commentable != sq
|
16
|
+
assert ct.comments != c
|
17
|
+
assert ct.comment_thread_subscriptions != cts
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'clear' do
|
21
|
+
u = FactoryGirl.create(:user)
|
22
|
+
q = FactoryGirl.create(:simple_question)
|
23
|
+
ct = q.comment_thread
|
24
|
+
c = Comment.new
|
25
|
+
c.comment_thread = ct
|
26
|
+
c.creator = u
|
27
|
+
c.save!
|
28
|
+
|
29
|
+
assert !q.comment_thread.comments.empty?
|
30
|
+
assert_equal q.comment_thread, ct
|
31
|
+
|
32
|
+
ct.clear!
|
33
|
+
q.reload
|
34
|
+
|
35
|
+
assert q.comment_thread.comments.empty?
|
36
|
+
assert q.comment_thread != ct
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'subscribe' do
|
40
|
+
u = FactoryGirl.create(:user)
|
41
|
+
ct = FactoryGirl.create(:comment_thread)
|
42
|
+
|
43
|
+
assert !ct.subscription_for(u)
|
44
|
+
assert ct.subscribe!(u)
|
45
|
+
assert ct.subscription_for(u)
|
46
|
+
assert ct.subscribe!(u)
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'unsubscribe' do
|
50
|
+
u = FactoryGirl.create(:user)
|
51
|
+
ct = FactoryGirl.create(:comment_thread)
|
52
|
+
|
53
|
+
assert !ct.unsubscribe!(u)
|
54
|
+
assert ct.subscribe!(u)
|
55
|
+
assert ct.subscription_for(u)
|
56
|
+
assert ct.unsubscribe!(u)
|
57
|
+
assert !ct.subscription_for(u)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|