commontator 4.10.3 → 4.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -6
  3. data/app/models/commontator/subscription.rb +4 -2
  4. data/app/models/commontator/subscription.rb~ +23 -0
  5. data/app/views/commontator/comments/_votes.html.erb +8 -8
  6. data/config/locales/{commontator/en.yml → en.yml} +0 -0
  7. data/lib/commontator/engine.rb +0 -3
  8. data/lib/commontator/version.rb +1 -1
  9. data/lib/commontator/version.rb~ +3 -0
  10. data/spec/controllers/commontator/comments_controller_spec.rb +566 -0
  11. data/spec/controllers/commontator/comments_controller_spec.rb~ +565 -0
  12. data/spec/controllers/commontator/subscriptions_controller_spec.rb +102 -0
  13. data/spec/controllers/commontator/subscriptions_controller_spec.rb~ +101 -0
  14. data/spec/controllers/commontator/threads_controller_spec.rb +130 -0
  15. data/spec/controllers/commontator/threads_controller_spec.rb~ +130 -0
  16. data/spec/dummy/README.md +1 -0
  17. data/spec/dummy/README.md~ +3 -0
  18. data/spec/dummy/Rakefile +1 -0
  19. data/spec/dummy/Rakefile~ +6 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +1 -0
  21. data/spec/dummy/app/assets/javascripts/application.js~ +15 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +1 -0
  23. data/spec/dummy/app/assets/stylesheets/application.css~ +13 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +1 -0
  25. data/spec/dummy/app/controllers/application_controller.rb~ +3 -0
  26. data/spec/dummy/app/controllers/dummy_models_controller.rb +12 -6
  27. data/spec/dummy/app/controllers/dummy_models_controller.rb~ +34 -0
  28. data/spec/dummy/app/helpers/application_helper.rb +4 -3
  29. data/spec/dummy/app/helpers/application_helper.rb~ +15 -0
  30. data/spec/dummy/app/models/dummy_model.rb +1 -0
  31. data/spec/dummy/app/models/dummy_model.rb~ +3 -0
  32. data/spec/dummy/app/models/dummy_user.rb +2 -1
  33. data/spec/dummy/app/models/dummy_user.rb~ +13 -0
  34. data/spec/dummy/app/views/dummy_model/show.html.erb +1 -0
  35. data/spec/dummy/app/views/dummy_model/show.html.erb~ +1 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +1 -0
  37. data/spec/dummy/app/views/layouts/application.html.erb~ +14 -0
  38. data/spec/dummy/config.ru +1 -0
  39. data/spec/dummy/config.ru~ +4 -0
  40. data/spec/dummy/config/application.rb +1 -0
  41. data/spec/dummy/config/application.rb~ +26 -0
  42. data/spec/dummy/config/boot.rb +1 -0
  43. data/spec/dummy/config/boot.rb~ +5 -0
  44. data/spec/dummy/config/database.yml +1 -0
  45. data/spec/dummy/config/database.yml~ +25 -0
  46. data/spec/dummy/config/environment.rb +1 -0
  47. data/spec/dummy/config/environment.rb~ +5 -0
  48. data/spec/dummy/config/environments/development.rb +1 -0
  49. data/spec/dummy/config/environments/development.rb~ +31 -0
  50. data/spec/dummy/config/environments/production.rb +1 -0
  51. data/spec/dummy/config/environments/production.rb~ +82 -0
  52. data/spec/dummy/config/environments/test.rb +1 -0
  53. data/spec/dummy/config/environments/test.rb~ +40 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb~ +7 -0
  56. data/spec/dummy/config/initializers/commontator.rb +1 -0
  57. data/spec/dummy/config/initializers/commontator.rb~ +14 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +1 -0
  59. data/spec/dummy/config/initializers/filter_parameter_logging.rb~ +4 -0
  60. data/spec/dummy/config/initializers/inflections.rb +1 -0
  61. data/spec/dummy/config/initializers/inflections.rb~ +16 -0
  62. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  63. data/spec/dummy/config/initializers/mime_types.rb~ +5 -0
  64. data/spec/dummy/config/initializers/secret_token.rb +1 -0
  65. data/spec/dummy/config/initializers/secret_token.rb~ +12 -0
  66. data/spec/dummy/config/initializers/session_store.rb +1 -0
  67. data/spec/dummy/config/initializers/session_store.rb~ +3 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -0
  69. data/spec/dummy/config/initializers/wrap_parameters.rb~ +14 -0
  70. data/spec/dummy/config/routes.rb +2 -1
  71. data/spec/dummy/config/routes.rb~ +7 -0
  72. data/spec/dummy/db/migrate/1_create_dummy_models.rb +1 -0
  73. data/spec/dummy/db/migrate/1_create_dummy_models.rb~ +7 -0
  74. data/spec/dummy/db/migrate/2_create_dummy_users.rb +1 -0
  75. data/spec/dummy/db/migrate/2_create_dummy_users.rb~ +7 -0
  76. data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +1 -0
  77. data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb~ +27 -0
  78. data/spec/dummy/db/test.sqlite3 +0 -0
  79. data/spec/dummy/log/development.log +33 -119
  80. data/spec/dummy/log/test.log +33394 -31595
  81. data/spec/dummy/public/404.html +1 -0
  82. data/spec/dummy/public/404.html~ +26 -0
  83. data/spec/dummy/public/422.html +1 -0
  84. data/spec/dummy/public/422.html~ +26 -0
  85. data/spec/dummy/public/500.html +1 -0
  86. data/spec/dummy/public/500.html~ +25 -0
  87. data/spec/dummy/script/rails +1 -0
  88. data/spec/dummy/script/rails~ +6 -0
  89. data/spec/dummy/tmp/cache/assets/test/sprockets/{72b63dddbc5c995f79af8e3c94904fd9 → 02d4b791eb831cf2057bf4703a1218d1} +0 -0
  90. data/spec/dummy/tmp/cache/assets/test/sprockets/{a77b1a9223d168112e1705c29220116f → 0f196a1a50363b0a076ec6e1ee5417f6} +0 -0
  91. data/spec/dummy/tmp/cache/assets/test/sprockets/{afa63eb365bdf4f42584b17ac9176b9d → a3fb9025f90ff05a6fd4afc7ded2692c} +0 -0
  92. data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
  93. data/spec/dummy/tmp/cache/assets/test/sprockets/{a473b3873e554893372a53d71f5e9879 → c69ee3cc5796188d873574179290a6ef} +0 -0
  94. data/spec/dummy/tmp/cache/assets/test/sprockets/{f721383d531f067d82b071e14aed7a92 → e1f674c11941d62aac1764ef3a7134e4} +0 -0
  95. data/spec/dummy/tmp/cache/assets/test/sprockets/{d2244ccef8e05bb993f75715af0344cc → e85565206c3e5fdf9dfeb367c85557b1} +0 -0
  96. data/spec/helpers/commontator/application_helper_spec.rb +10 -0
  97. data/spec/helpers/commontator/application_helper_spec.rb~ +9 -0
  98. data/spec/lib/commontator/acts_as_commontable_spec.rb +16 -15
  99. data/spec/lib/commontator/acts_as_commontable_spec.rb~ +25 -0
  100. data/spec/lib/commontator/acts_as_commontator_spec.rb +17 -16
  101. data/spec/lib/commontator/acts_as_commontator_spec.rb~ +52 -0
  102. data/spec/lib/commontator/commontable_config_spec.rb +9 -8
  103. data/spec/lib/commontator/commontable_config_spec.rb~ +29 -0
  104. data/spec/lib/commontator/commontator_config_spec.rb +9 -8
  105. data/spec/lib/commontator/commontator_config_spec.rb~ +29 -0
  106. data/spec/lib/commontator/controller_includes_spec.rb +10 -7
  107. data/spec/lib/commontator/controller_includes_spec.rb~ +18 -0
  108. data/spec/lib/commontator/shared_helper_spec.rb +14 -9
  109. data/spec/lib/commontator/shared_helper_spec.rb~ +22 -0
  110. data/spec/lib/commontator_spec.rb +7 -6
  111. data/spec/lib/commontator_spec.rb~ +26 -0
  112. data/spec/mailers/commontator/subscriptions_mailer_spec.rb +30 -0
  113. data/spec/{app/mailers/commontator/subscriptions_mailer_spec.rb → mailers/commontator/subscriptions_mailer_spec.rb~} +12 -12
  114. data/spec/models/commontator/comment_spec.rb +82 -0
  115. data/spec/models/commontator/comment_spec.rb~ +82 -0
  116. data/spec/{app/models → models}/commontator/subscription_spec.rb +14 -13
  117. data/spec/models/commontator/subscription_spec.rb~ +38 -0
  118. data/spec/models/commontator/thread_spec.rb +122 -0
  119. data/spec/{app/models/commontator/thread_spec.rb → models/commontator/thread_spec.rb~} +52 -50
  120. data/spec/rails_helper.rb +71 -0
  121. data/spec/rails_helper.rb~ +74 -0
  122. data/spec/spec_helper.rb +77 -27
  123. data/spec/spec_helper.rb~ +86 -0
  124. metadata +184 -78
  125. data/spec/app/controllers/commontator/comments_controller_spec.rb +0 -582
  126. data/spec/app/controllers/commontator/subscriptions_controller_spec.rb +0 -99
  127. data/spec/app/controllers/commontator/threads_controller_spec.rb +0 -127
  128. data/spec/app/helpers/commontator/application_helper_spec.rb +0 -9
  129. data/spec/app/models/commontator/comment_spec.rb +0 -73
  130. data/spec/dummy/db/development.sqlite3 +0 -0
  131. data/spec/dummy/tmp/cache/assets/test/sprockets/decb63cac838a5314aa0c22a979f5ac9 +0 -0
@@ -0,0 +1,102 @@
1
+ require 'rails_helper'
2
+
3
+ module Commontator
4
+ RSpec.describe SubscriptionsController, type: :controller do
5
+ routes { Commontator::Engine.routes }
6
+
7
+ before(:each) do
8
+ setup_controller_spec
9
+ end
10
+
11
+ it "won't subscribe unless authorized" do
12
+ put :subscribe, :id => @thread.id
13
+ expect(response).to have_http_status(:forbidden)
14
+ expect(@thread.subscription_for(nil)).to be_nil
15
+ expect(@thread.subscription_for(@user)).to be_nil
16
+
17
+ sign_in @user
18
+ put :subscribe, :id => @thread.id
19
+ expect(response).to have_http_status(:forbidden)
20
+ expect(@thread.subscription_for(@user)).to be_nil
21
+
22
+ @thread.subscribe(@user)
23
+ @user.can_read = true
24
+ put :subscribe, :id => @thread.id
25
+ expect(response).to redirect_to(@thread)
26
+ expect(assigns(:thread).errors).not_to be_empty
27
+ end
28
+
29
+ it 'must subscribe if authorized' do
30
+ sign_in @user
31
+
32
+ @user.can_read = true
33
+ put :subscribe, :id => @thread.id
34
+ expect(response).to redirect_to(@thread)
35
+ expect(assigns(:thread).errors).to be_empty
36
+ expect(@thread.subscription_for(@user)).not_to be_nil
37
+
38
+ @thread.unsubscribe(@user)
39
+ @user.can_read = false
40
+ @user.can_edit = true
41
+ put :subscribe, :id => @thread.id
42
+ expect(response).to redirect_to(@thread)
43
+ expect(assigns(:thread).errors).to be_empty
44
+ expect(@thread.subscription_for(@user)).not_to be_nil
45
+
46
+ @thread.unsubscribe(@user)
47
+ @user.can_edit = false
48
+ @user.is_admin = true
49
+ put :subscribe, :id => @thread.id
50
+ expect(response).to redirect_to(@thread)
51
+ expect(assigns(:thread).errors).to be_empty
52
+ expect(@thread.subscription_for(@user)).not_to be_nil
53
+ end
54
+
55
+ it "won't unsubscribe unless authorized" do
56
+ @thread.subscribe(@user)
57
+ put :unsubscribe, :id => @thread.id
58
+ expect(response).to have_http_status(:forbidden)
59
+ expect(@thread.subscription_for(nil)).to be_nil
60
+ expect(@thread.subscription_for(@user)).not_to be_nil
61
+
62
+ sign_in @user
63
+ put :unsubscribe, :id => @thread.id
64
+ expect(response).to have_http_status(:forbidden)
65
+ expect(@thread.subscription_for(@user)).not_to be_nil
66
+
67
+ @thread.unsubscribe(@user)
68
+ @user.can_read = true
69
+ put :unsubscribe, :id => @thread.id
70
+ expect(response).to redirect_to(@thread)
71
+ expect(assigns(:thread).errors).not_to be_empty
72
+ end
73
+
74
+ it 'must unsubscribe if authorized' do
75
+ sign_in @user
76
+
77
+ @thread.subscribe(@user)
78
+ @user.can_read = true
79
+ put :unsubscribe, :id => @thread.id
80
+ expect(response).to redirect_to(@thread)
81
+ expect(assigns(:thread).errors).to be_empty
82
+ expect(@thread.subscription_for(@user)).to be_nil
83
+
84
+ @thread.subscribe(@user)
85
+ @user.can_read = false
86
+ @user.can_edit = true
87
+ put :unsubscribe, :id => @thread.id
88
+ expect(response).to redirect_to(@thread)
89
+ expect(assigns(:thread).errors).to be_empty
90
+ expect(@thread.subscription_for(@user)).to be_nil
91
+
92
+ @thread.subscribe(@user)
93
+ @user.can_edit = false
94
+ @user.is_admin = true
95
+ put :unsubscribe, :id => @thread.id
96
+ expect(response).to redirect_to(@thread)
97
+ expect(assigns(:thread).errors).to be_empty
98
+ expect(@thread.subscription_for(@user)).to be_nil
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,101 @@
1
+ require 'rails_helper'
2
+
3
+ module Commontator
4
+ RSpec.describe SubscriptionsController, type: :controller do
5
+ routes { Commontator::Engine.routes }
6
+
7
+ before(:each) do
8
+ setup_controller_spec
9
+ end
10
+
11
+ it "won't subscribe unless authorized" do
12
+ put :subscribe, :id => @thread.id
13
+ expect(response).to have_http_status(:forbidden)
14
+ expect(@thread.subscription_for(nil)).to be_nil
15
+ expect(@thread.subscription_for(@user)).to be_nil
16
+
17
+ sign_in @user
18
+ put :subscribe, :id => @thread.id
19
+ expect(response).to have_http_status(:forbidden)
20
+ expect(@thread.subscription_for(@user)).to be_nil
21
+
22
+ @thread.subscribe(@user)
23
+ @user.can_read = true
24
+ put :subscribe, :id => @thread.id
25
+ expect(response).to redirect_to(@thread)
26
+ expect(assigns(:thread).errors).not_to be_empty
27
+ end
28
+
29
+ it 'must subscribe if authorized' do
30
+ sign_in @user
31
+
32
+ @user.can_read = true
33
+ put :subscribe, :id => @thread.id
34
+ expect(response).to redirect_to(@thread)
35
+ expect(assigns(:thread).errors).to be_empty
36
+ expect(@thread.subscription_for(@user)).not_to be_nil
37
+
38
+ @thread.unsubscribe(@user)
39
+ @user.can_read = false
40
+ @user.can_edit = true
41
+ put :subscribe, :id => @thread.id
42
+ expect(response).to redirect_to(@thread)
43
+ expect(assigns(:thread).errors).to be_empty
44
+ expect(@thread.subscription_for(@user)).not_to be_nil
45
+
46
+ @thread.unsubscribe(@user)
47
+ @user.can_edit = false
48
+ @user.is_admin = true
49
+ put :subscribe, :id => @thread.id
50
+ expect(response).to redirect_to(@thread)
51
+ expect(assigns(:thread).errors).to be_empty
52
+ expect(@thread.subscription_for(@user)).not_to be_nil
53
+ end
54
+
55
+ it "won't unsubscribe unless authorized" do
56
+ @thread.subscribe(@user)
57
+ put :unsubscribe, :id => @thread.id
58
+ expect(response).to have_http_status(:forbidden)
59
+ expect(@thread.subscription_for(nil)).to be_nil
60
+ expect(@thread.subscription_for(@user)).not_to be_nil
61
+
62
+ sign_in @user
63
+ put :unsubscribe, :id => @thread.id
64
+ expect(response).to have_http_status(:forbidden)
65
+ expect(@thread.subscription_for(@user)).not_to be_nil
66
+
67
+ @thread.unsubscribe(@user)
68
+ @user.can_read = true
69
+ put :unsubscribe, :id => @thread.id
70
+ expect(response).to redirect_to(@thread)
71
+ expect(assigns(:thread).errors).not_to be_empty
72
+ end
73
+
74
+ it 'must unsubscribe if authorized' do
75
+ sign_in @user
76
+
77
+ @thread.subscribe(@user)
78
+ @user.can_read = true
79
+ put :unsubscribe, :id => @thread.id
80
+ expect(response).to redirect_to(@thread)
81
+ expect(assigns(:thread).errors).to be_empty
82
+ expect(@thread.subscription_for(@user)).to be_nil
83
+
84
+ @thread.subscribe(@user)
85
+ @user.can_read = false
86
+ @user.can_edit = true
87
+ put :unsubscribe, :id => @thread.id
88
+ expect(response).to redirect_to(@thread)
89
+ expect(assigns(:thread).errors).to be_empty
90
+ expect(@thread.subscription_for(@user)).to be_nil
91
+
92
+ @thread.subscribe(@user)
93
+ @user.can_edit = false
94
+ @user.is_admin = true
95
+ put :unsubscribe, :id => @thread.id
96
+ expect(response).to redirect_to(@thread)
97
+ expect(assigns(:thread).errors).to be_empty
98
+ expect(@thread.subscription_for(@user)).to be_nil
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,130 @@
1
+ require 'rails_helper'
2
+
3
+ module Commontator
4
+ RSpec.describe ThreadsController, type: :controller do
5
+ routes { Commontator::Engine.routes }
6
+
7
+ before(:each) do
8
+ setup_controller_spec
9
+ end
10
+
11
+ it "won't show unless authorized" do
12
+ get :show, :id => @thread.id
13
+ expect(response).to have_http_status(:forbidden)
14
+
15
+ sign_in @user
16
+ get :show, :id => @thread.id
17
+ expect(response).to have_http_status(:forbidden)
18
+ end
19
+
20
+ it 'must show if authorized' do
21
+ commontable_path = Rails.application.routes.url_helpers.dummy_model_path(@commontable)
22
+ sign_in @user
23
+
24
+ @user.can_read = true
25
+ get :show, :id => @thread.id
26
+ expect(response).to redirect_to(commontable_path)
27
+
28
+ @user.can_read = false
29
+ @user.can_edit = true
30
+ get :show, :id => @thread.id
31
+ expect(response).to redirect_to(commontable_path)
32
+
33
+ @user.can_edit = false
34
+ @user.is_admin = true
35
+ get :show, :id => @thread.id
36
+ expect(response).to redirect_to(commontable_path)
37
+ end
38
+
39
+ it "won't close unless authorized and open" do
40
+ put :close, :id => @thread.id
41
+ expect(response).to have_http_status(:forbidden)
42
+ @thread.reload
43
+ expect(@thread.is_closed?).to eq false
44
+
45
+ sign_in @user
46
+ put :close, :id => @thread.id
47
+ expect(response).to have_http_status(:forbidden)
48
+ @thread.reload
49
+ expect(@thread.is_closed?).to eq false
50
+
51
+ @user.can_read = true
52
+ put :close, :id => @thread.id
53
+ expect(response).to have_http_status(:forbidden)
54
+ @thread.reload
55
+ expect(@thread.is_closed?).to eq false
56
+
57
+ @user.can_edit = true
58
+ expect(@thread.close).to eq true
59
+ put :close, :id => @thread.id
60
+ expect(response).to redirect_to(@thread)
61
+ expect(assigns(:thread).errors).not_to be_empty
62
+ end
63
+
64
+ it 'must close if authorized and open' do
65
+ sign_in @user
66
+
67
+ @user.can_edit = true
68
+ put :close, :id => @thread.id
69
+ expect(response).to redirect_to(@thread)
70
+ expect(assigns(:thread).errors).to be_empty
71
+ expect(assigns(:thread).is_closed?).to eq true
72
+ expect(assigns(:thread).closer).to eq @user
73
+
74
+ expect(assigns(:thread).reopen).to eq true
75
+ @user.can_edit = false
76
+ @user.is_admin = true
77
+ put :close, :id => @thread.id
78
+ expect(response).to redirect_to(@thread)
79
+ expect(assigns(:thread).errors).to be_empty
80
+ expect(assigns(:thread).is_closed?).to eq true
81
+ expect(assigns(:thread).closer).to eq @user
82
+ end
83
+
84
+ it "won't reopen unless authorized and closed" do
85
+ expect(@thread.close).to eq true
86
+ put :reopen, :id => @thread.id
87
+ expect(response).to have_http_status(:forbidden)
88
+ @thread.reload
89
+ expect(@thread.is_closed?).to eq true
90
+
91
+ sign_in @user
92
+ put :reopen, :id => @thread.id
93
+ expect(response).to have_http_status(:forbidden)
94
+ @thread.reload
95
+ expect(@thread.is_closed?).to eq true
96
+
97
+ @user.can_read = true
98
+ put :reopen, :id => @thread.id
99
+ expect(response).to have_http_status(:forbidden)
100
+ @thread.reload
101
+ expect(@thread.is_closed?).to eq true
102
+
103
+ expect(@thread.reopen).to eq true
104
+ @user.can_edit = true
105
+ put :reopen, :id => @thread.id
106
+ expect(response).to redirect_to(@thread)
107
+ expect(assigns(:thread).errors).not_to be_empty
108
+ end
109
+
110
+ it 'must reopen if authorized and closed' do
111
+ sign_in @user
112
+
113
+ expect(@thread.close).to eq true
114
+ @user.can_edit = true
115
+ put :reopen, :id => @thread.id
116
+ expect(response).to redirect_to(@thread)
117
+ expect(assigns(:thread).errors).to be_empty
118
+ expect(assigns(:thread).is_closed?).to eq false
119
+
120
+ expect(assigns(:thread).close).to eq true
121
+ @user.can_edit = false
122
+ @user.is_admin = true
123
+ put :reopen, :id => @thread.id
124
+ expect(response).to redirect_to(@thread)
125
+ expect(assigns(:thread).errors).to be_empty
126
+ expect(assigns(:thread).is_closed?).to eq false
127
+ end
128
+ end
129
+ end
130
+
@@ -0,0 +1,130 @@
1
+ require 'rails_helper'
2
+
3
+ module Commontator
4
+ RSpec.describe ThreadsController, type: :controller do
5
+ routes { Commontator::Engine.routes }
6
+
7
+ before(:each) do
8
+ setup_controller_spec
9
+ end
10
+
11
+ it "won't show unless authorized" do
12
+ get :show, :id => @thread.id
13
+ expect(response).to have_http_status(:forbidden)
14
+
15
+ sign_in @user
16
+ get :show, :id => @thread.id
17
+ expect(response).to have_http_status(:forbidden)
18
+ end
19
+
20
+ it 'must show if authorized' do
21
+ commontable_path = Rails.application.routes.url_helpers.dummy_model_path(@commontable)
22
+ sign_in @user
23
+
24
+ @user.can_read = true
25
+ get :show, :id => @thread.id
26
+ expect(response).to redirect_to(commontable_path)
27
+
28
+ @user.can_read = false
29
+ @user.can_edit = true
30
+ get :show, :id => @thread.id
31
+ expect(response).to redirect_to(commontable_path)
32
+
33
+ @user.can_edit = false
34
+ @user.is_admin = true
35
+ get :show, :id => @thread.id
36
+ expect(response).to redirect_to(commontable_path)
37
+ end
38
+
39
+ it "won't close unless authorized and open" do
40
+ put :close, :id => @thread.id
41
+ expect(response).to have_http_status(:forbidden)
42
+ @thread.reload
43
+ expect(@thread.is_closed?).to eq false
44
+
45
+ sign_in @user
46
+ put :close, :id => @thread.id
47
+ expect(response).to have_http_status(:forbidden)
48
+ @thread.reload
49
+ expect(@thread.is_closed?).to eq false
50
+
51
+ @user.can_read = true
52
+ put :close, :id => @thread.id
53
+ expect(response).to have_http_status(:forbidden)
54
+ @thread.reload
55
+ expect(@thread.is_closed?).to eq false
56
+
57
+ @user.can_edit = true
58
+ expect(@thread.close).to eq true
59
+ put :close, :id => @thread.id
60
+ expect(response).to redirect_to(@thread)
61
+ expect(assigns(:thread).errors).not_to be_empty
62
+ end
63
+
64
+ it 'must close if authorized and open' do
65
+ sign_in @user
66
+
67
+ @user.can_edit = true
68
+ put :close, :id => @thread.id
69
+ expect(response).to redirect_to(@thread)
70
+ expect(assigns(:thread).errors).to be_empty
71
+ expect(assigns(:thread).is_closed?).to eq true
72
+ expect(assigns(:thread).closer).to eq @user
73
+
74
+ expect(assigns(:thread).reopen).to eq true
75
+ @user.can_edit = false
76
+ @user.is_admin = true
77
+ put :close, :id => @thread.id
78
+ expect(response).to redirect_to(@thread)
79
+ expect(assigns(:thread).errors).to be_empty
80
+ expect(assigns(:thread).is_closed?).to eq true
81
+ expect(assigns(:thread).closer).to eq @user
82
+ end
83
+
84
+ it "won't reopen unless authorized and closed" do
85
+ @thread.close.must_equal true
86
+ put :reopen, :id => @thread.id
87
+ expect(response).to have_http_status(:forbidden)
88
+ @thread.reload
89
+ expect(@thread.is_closed?).to eq true
90
+
91
+ sign_in @user
92
+ put :reopen, :id => @thread.id
93
+ expect(response).to have_http_status(:forbidden)
94
+ @thread.reload
95
+ expect(@thread.is_closed?).to eq true
96
+
97
+ @user.can_read = true
98
+ put :reopen, :id => @thread.id
99
+ expect(response).to have_http_status(:forbidden)
100
+ @thread.reload
101
+ expect(@thread.is_closed?).to eq true
102
+
103
+ expect(@thread.reopen).to eq true
104
+ @user.can_edit = true
105
+ put :reopen, :id => @thread.id
106
+ expect(response).to redirect_to(@thread)
107
+ expect(assigns(:thread).errors).not_to be_empty
108
+ end
109
+
110
+ it 'must reopen if authorized and closed' do
111
+ sign_in @user
112
+
113
+ expect(@thread.close).to eq true
114
+ @user.can_edit = true
115
+ put :reopen, :id => @thread.id
116
+ expect(response).to redirect_to(@thread)
117
+ expect(assigns(:thread).errors).to be_empty
118
+ expect(assigns(:thread).is_closed?).to eq false
119
+
120
+ expect(assigns(:thread).close).to eq true
121
+ @user.can_edit = false
122
+ @user.is_admin = true
123
+ put :reopen, :id => @thread.id
124
+ expect(response).to redirect_to(@thread)
125
+ expect(assigns(:thread).errors).to be_empty
126
+ expect(assigns(:thread).is_closed?).to eq false
127
+ end
128
+ end
129
+ end
130
+