proclaim 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +5 -38
  3. data/app/assets/config/proclaim_manifest.js +2 -0
  4. data/app/assets/images/{ajax_loader.gif → proclaim/ajax_loader.gif} +0 -0
  5. data/app/assets/javascripts/proclaim.js +7 -7
  6. data/app/assets/javascripts/proclaim/{comments_handler.js.coffee → comments_handler.coffee} +16 -10
  7. data/app/assets/javascripts/proclaim/editor.coffee +55 -0
  8. data/app/assets/stylesheets/{proclaim.css.scss → proclaim.scss} +7 -8
  9. data/app/assets/stylesheets/proclaim/{comments.css.scss → comments.scss} +0 -0
  10. data/app/assets/stylesheets/proclaim/{posts.css.scss → posts.scss} +60 -25
  11. data/app/assets/stylesheets/proclaim/{subscriptions.css.scss → subscriptions.scss} +0 -0
  12. data/app/controllers/proclaim/application_controller.rb +60 -56
  13. data/app/controllers/proclaim/comments_controller.rb +13 -42
  14. data/app/controllers/proclaim/posts_controller.rb +25 -57
  15. data/app/controllers/proclaim/subscriptions_controller.rb +3 -3
  16. data/app/jobs/proclaim/application_job.rb +4 -0
  17. data/app/mailers/proclaim/application_mailer.rb +5 -0
  18. data/app/mailers/proclaim/subscription_mailer.rb +19 -17
  19. data/app/models/proclaim/application_record.rb +5 -0
  20. data/app/models/proclaim/comment.rb +6 -1
  21. data/app/models/proclaim/post.rb +20 -28
  22. data/app/models/proclaim/subscription.rb +33 -11
  23. data/app/views/layouts/proclaim/subscription_mailer.html.erb +15 -36
  24. data/app/views/proclaim/comments/_comment.html.erb +7 -7
  25. data/app/views/proclaim/comments/_form.html.erb +7 -5
  26. data/app/views/proclaim/posts/_form.html.erb +34 -21
  27. data/app/views/proclaim/posts/show.html.erb +16 -3
  28. data/app/views/proclaim/subscription_mailer/welcome_email.html.erb +2 -6
  29. data/config/initializers/friendly_id.rb +20 -1
  30. data/config/routes.rb +1 -5
  31. data/db/migrate/20141108222616_create_proclaim_posts.rb +8 -1
  32. data/db/migrate/20141114235359_create_proclaim_comments.rb +1 -1
  33. data/db/migrate/20141115022230_create_proclaim_comment_hierarchies.rb +1 -1
  34. data/db/migrate/20141210234057_create_proclaim_subscriptions.rb +5 -4
  35. data/db/migrate/20150213015321_create_friendly_id_slugs.rb +1 -1
  36. data/lib/generators/proclaim/install_generator.rb +1 -1
  37. data/lib/generators/proclaim/templates/initialize_proclaim.rb +31 -29
  38. data/lib/generators/proclaim/views_generator.rb +1 -1
  39. data/lib/proclaim.rb +15 -15
  40. data/lib/proclaim/engine.rb +21 -19
  41. data/lib/proclaim/version.rb +1 -1
  42. data/vendor/assets/fonts/KaTeX_AMS-Regular.ttf +0 -0
  43. data/vendor/assets/fonts/KaTeX_AMS-Regular.woff +0 -0
  44. data/vendor/assets/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  45. data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  46. data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  47. data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  48. data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  49. data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  50. data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  51. data/vendor/assets/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  52. data/vendor/assets/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  53. data/vendor/assets/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  54. data/vendor/assets/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  55. data/vendor/assets/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  56. data/vendor/assets/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  57. data/vendor/assets/fonts/KaTeX_Main-Bold.ttf +0 -0
  58. data/vendor/assets/fonts/KaTeX_Main-Bold.woff +0 -0
  59. data/vendor/assets/fonts/KaTeX_Main-Bold.woff2 +0 -0
  60. data/vendor/assets/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  61. data/vendor/assets/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  62. data/vendor/assets/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  63. data/vendor/assets/fonts/KaTeX_Main-Italic.ttf +0 -0
  64. data/vendor/assets/fonts/KaTeX_Main-Italic.woff +0 -0
  65. data/vendor/assets/fonts/KaTeX_Main-Italic.woff2 +0 -0
  66. data/vendor/assets/fonts/KaTeX_Main-Regular.ttf +0 -0
  67. data/vendor/assets/fonts/KaTeX_Main-Regular.woff +0 -0
  68. data/vendor/assets/fonts/KaTeX_Main-Regular.woff2 +0 -0
  69. data/vendor/assets/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  70. data/vendor/assets/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  71. data/vendor/assets/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  72. data/vendor/assets/fonts/KaTeX_Math-Italic.ttf +0 -0
  73. data/vendor/assets/fonts/KaTeX_Math-Italic.woff +0 -0
  74. data/vendor/assets/fonts/KaTeX_Math-Italic.woff2 +0 -0
  75. data/vendor/assets/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  76. data/vendor/assets/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  77. data/vendor/assets/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  78. data/vendor/assets/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  79. data/vendor/assets/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  80. data/vendor/assets/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  81. data/vendor/assets/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  82. data/vendor/assets/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  83. data/vendor/assets/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  84. data/vendor/assets/fonts/KaTeX_Script-Regular.ttf +0 -0
  85. data/vendor/assets/fonts/KaTeX_Script-Regular.woff +0 -0
  86. data/vendor/assets/fonts/KaTeX_Script-Regular.woff2 +0 -0
  87. data/vendor/assets/fonts/KaTeX_Size1-Regular.ttf +0 -0
  88. data/vendor/assets/fonts/KaTeX_Size1-Regular.woff +0 -0
  89. data/vendor/assets/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  90. data/vendor/assets/fonts/KaTeX_Size2-Regular.ttf +0 -0
  91. data/vendor/assets/fonts/KaTeX_Size2-Regular.woff +0 -0
  92. data/vendor/assets/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  93. data/vendor/assets/fonts/KaTeX_Size3-Regular.ttf +0 -0
  94. data/vendor/assets/fonts/KaTeX_Size3-Regular.woff +0 -0
  95. data/vendor/assets/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  96. data/vendor/assets/fonts/KaTeX_Size4-Regular.ttf +0 -0
  97. data/vendor/assets/fonts/KaTeX_Size4-Regular.woff +0 -0
  98. data/vendor/assets/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  99. data/vendor/assets/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  100. data/vendor/assets/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  101. data/vendor/assets/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  102. data/vendor/assets/javascripts/contrib/auto-render.js +339 -0
  103. data/vendor/assets/javascripts/contrib/auto-render.min.js +1 -0
  104. data/vendor/assets/javascripts/contrib/auto-render.mjs +215 -0
  105. data/vendor/assets/javascripts/contrib/copy-tex.css +14 -0
  106. data/vendor/assets/javascripts/contrib/copy-tex.js +213 -0
  107. data/vendor/assets/javascripts/contrib/copy-tex.min.css +1 -0
  108. data/vendor/assets/javascripts/contrib/copy-tex.min.js +1 -0
  109. data/vendor/assets/javascripts/contrib/copy-tex.mjs +85 -0
  110. data/vendor/assets/javascripts/contrib/mathtex-script-type.js +137 -0
  111. data/vendor/assets/javascripts/contrib/mathtex-script-type.min.js +1 -0
  112. data/vendor/assets/javascripts/contrib/mathtex-script-type.mjs +24 -0
  113. data/vendor/assets/javascripts/contrib/mhchem.js +3241 -0
  114. data/vendor/assets/javascripts/contrib/mhchem.min.js +1 -0
  115. data/vendor/assets/javascripts/contrib/mhchem.mjs +3109 -0
  116. data/vendor/assets/javascripts/katex.js +16517 -0
  117. data/vendor/assets/javascripts/katex.min.js +1 -0
  118. data/vendor/assets/javascripts/katex.mjs +16122 -0
  119. data/vendor/assets/javascripts/quill.core.js +8522 -0
  120. data/vendor/assets/javascripts/quill.js +11489 -0
  121. data/vendor/assets/javascripts/quill.min.js +8 -0
  122. data/vendor/assets/javascripts/quill.min.js.map +1 -0
  123. data/vendor/assets/stylesheets/katex.css +1011 -0
  124. data/vendor/assets/stylesheets/katex.min.css +1 -0
  125. data/vendor/assets/stylesheets/quill.bubble.css +952 -0
  126. data/vendor/assets/stylesheets/quill.core.css +397 -0
  127. data/vendor/assets/stylesheets/quill.snow.css +945 -0
  128. metadata +169 -278
  129. data/CHANGELOG +0 -77
  130. data/Gemfile +0 -14
  131. data/VERSION +0 -1
  132. data/app/assets/javascripts/proclaim/editor.js.coffee +0 -52
  133. data/app/assets/javascripts/proclaim/images.js.coffee +0 -3
  134. data/app/assets/javascripts/proclaim/subscriptions.js.coffee +0 -3
  135. data/app/assets/stylesheets/proclaim/images.scss +0 -3
  136. data/app/controllers/proclaim/images_controller.rb +0 -67
  137. data/app/helpers/proclaim/comments_helper.rb +0 -4
  138. data/app/helpers/proclaim/images_helper.rb +0 -4
  139. data/app/helpers/proclaim/subscriptions_helper.rb +0 -4
  140. data/app/models/proclaim/image.rb +0 -19
  141. data/app/policies/proclaim/image_policy.rb +0 -29
  142. data/app/uploaders/proclaim/image_uploader.rb +0 -82
  143. data/db/migrate/20141222224905_create_proclaim_images.rb +0 -12
  144. data/db/migrate/20150123115226_add_name_to_subscriptions.rb +0 -7
  145. data/db/migrate/20150213015850_add_slug_to_posts.rb +0 -20
  146. data/proclaim.gemspec +0 -51
  147. data/test/controllers/proclaim/comments_controller_test.rb +0 -228
  148. data/test/controllers/proclaim/images_controller_test.rb +0 -166
  149. data/test/controllers/proclaim/posts_controller_test.rb +0 -465
  150. data/test/controllers/proclaim/subscriptions_controller_test.rb +0 -154
  151. data/test/dummy/README.rdoc +0 -28
  152. data/test/dummy/Rakefile +0 -6
  153. data/test/dummy/app/assets/javascripts/application.js +0 -14
  154. data/test/dummy/app/assets/stylesheets/application.css +0 -16
  155. data/test/dummy/app/controllers/application_controller.rb +0 -15
  156. data/test/dummy/app/helpers/application_helper.rb +0 -28
  157. data/test/dummy/app/models/user.rb +0 -7
  158. data/test/dummy/app/views/layouts/application.html.erb +0 -16
  159. data/test/dummy/bin/bundle +0 -3
  160. data/test/dummy/bin/rails +0 -4
  161. data/test/dummy/bin/rake +0 -4
  162. data/test/dummy/config.ru +0 -4
  163. data/test/dummy/config/application.rb +0 -24
  164. data/test/dummy/config/boot.rb +0 -5
  165. data/test/dummy/config/database.yml +0 -25
  166. data/test/dummy/config/environment.rb +0 -5
  167. data/test/dummy/config/environments/development.rb +0 -45
  168. data/test/dummy/config/environments/production.rb +0 -80
  169. data/test/dummy/config/environments/test.rb +0 -49
  170. data/test/dummy/config/initializers/assets.rb +0 -8
  171. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  172. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  173. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  174. data/test/dummy/config/initializers/inflections.rb +0 -16
  175. data/test/dummy/config/initializers/mime_types.rb +0 -4
  176. data/test/dummy/config/initializers/session_store.rb +0 -3
  177. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  178. data/test/dummy/config/locales/en.yml +0 -23
  179. data/test/dummy/config/routes.rb +0 -5
  180. data/test/dummy/config/secrets.yml +0 -22
  181. data/test/dummy/db/migrate/20141117214323_create_users.rb +0 -10
  182. data/test/dummy/db/schema.rb +0 -91
  183. data/test/dummy/public/404.html +0 -67
  184. data/test/dummy/public/422.html +0 -67
  185. data/test/dummy/public/500.html +0 -66
  186. data/test/dummy/public/favicon.ico +0 -0
  187. data/test/factories/proclaim/comment.rb +0 -11
  188. data/test/factories/proclaim/image.rb +0 -6
  189. data/test/factories/proclaim/post.rb +0 -14
  190. data/test/factories/proclaim/subscription.rb +0 -14
  191. data/test/factories/user.rb +0 -6
  192. data/test/helpers/proclaim/comments_helper_test.rb +0 -6
  193. data/test/helpers/proclaim/posts_helper_test.rb +0 -6
  194. data/test/helpers/proclaim/subscriptions_helper_test.rb +0 -6
  195. data/test/integration/with_javascript/comment_test.rb +0 -391
  196. data/test/integration/with_javascript/post_form_test.rb +0 -225
  197. data/test/integration/with_javascript/post_show_test.rb +0 -47
  198. data/test/integration/with_javascript/post_subscription_test.rb +0 -302
  199. data/test/integration/without_javascript/blog_subscription_test.rb +0 -114
  200. data/test/integration/without_javascript/manage_subscriptions_test.rb +0 -37
  201. data/test/integration/without_javascript/post_test.rb +0 -234
  202. data/test/integration/without_javascript/subscription_email_test.rb +0 -95
  203. data/test/integration/without_javascript/unsubscribe_test.rb +0 -32
  204. data/test/mailers/previews/proclaim/subscription_mailer_preview.rb +0 -22
  205. data/test/mailers/proclaim/subscription_mailer_test.rb +0 -91
  206. data/test/models/proclaim/comment_test.rb +0 -41
  207. data/test/models/proclaim/image_test.rb +0 -70
  208. data/test/models/proclaim/post_test.rb +0 -193
  209. data/test/models/proclaim/subscription_test.rb +0 -77
  210. data/test/policies/application_policy_test.rb +0 -87
  211. data/test/policies/proclaim/comment_policy_test.rb +0 -71
  212. data/test/policies/proclaim/image_policy_test.rb +0 -83
  213. data/test/policies/proclaim/post_policy_test.rb +0 -98
  214. data/test/policies/proclaim/subscription_policy_test.rb +0 -103
  215. data/test/proclaim_test.rb +0 -7
  216. data/test/support/images/test.jpg +0 -0
  217. data/test/support/pages/posts/edit_page.rb +0 -5
  218. data/test/support/pages/posts/show_page.rb +0 -47
  219. data/test/support/wait_for_ajax.rb +0 -11
  220. data/test/test_helper.rb +0 -71
  221. data/test/unit/proclaim/new_comment_callback_test.rb +0 -62
  222. data/test/unit/proclaim/new_subscription_callback_test.rb +0 -62
  223. data/test/unit/proclaim/post_published_callback_test.rb +0 -74
  224. data/vendor/assets/images/link.png +0 -0
  225. data/vendor/assets/images/remove.png +0 -0
  226. data/vendor/assets/images/resize-bigger.png +0 -0
  227. data/vendor/assets/images/resize-smaller.png +0 -0
  228. data/vendor/assets/images/unlink.png +0 -0
  229. data/vendor/assets/javascripts/addons/medium-editor-insert-embeds.js +0 -197
  230. data/vendor/assets/javascripts/addons/medium-editor-insert-images.js +0 -572
  231. data/vendor/assets/javascripts/addons/medium-editor-insert-maps.js +0 -50
  232. data/vendor/assets/javascripts/addons/medium-editor-insert-plugin.js +0 -496
  233. data/vendor/assets/javascripts/addons/medium-editor-insert-tables.js +0 -132
  234. data/vendor/assets/javascripts/medium-editor-insert-plugin.all.js +0 -1415
  235. data/vendor/assets/stylesheets/medium-editor-insert-plugin-frontend.css.scss +0 -55
  236. data/vendor/assets/stylesheets/medium-editor-insert-plugin.css.scss +0 -277
@@ -1,228 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Proclaim
4
- class CommentsControllerTest < ActionController::TestCase
5
- setup do
6
- @routes = Engine.routes
7
-
8
- @controller.stubs(:current_user).returns(nil)
9
- @controller.stubs(:authenticate_user).returns(false)
10
- end
11
-
12
- test "should create root comment if logged in" do
13
- user = FactoryGirl.create(:user)
14
- sign_in user
15
-
16
- # Users should be able to make comments on unpublished posts
17
- newComment = FactoryGirl.build(:comment)
18
- assert_create_comment newComment
19
-
20
- # Users should also be able to make comments on published posts
21
- newComment = FactoryGirl.build(:published_comment)
22
- assert_create_comment newComment
23
- end
24
-
25
- test "should create reply if logged in" do
26
- user = FactoryGirl.create(:user)
27
- sign_in user
28
-
29
- # Users should be able to make replies to comments on unpublished posts
30
- parent = FactoryGirl.create(:comment)
31
- reply = FactoryGirl.build(:comment,
32
- post: parent.post,
33
- parent: parent)
34
- assert_create_comment reply, 1, 1, parent
35
-
36
- # Users should be able to make replies to comments on published posts
37
- parent = FactoryGirl.create(:published_comment)
38
- reply = FactoryGirl.build(:published_comment,
39
- post: parent.post,
40
- parent: parent)
41
- assert_create_comment reply, 1, 1, parent
42
- end
43
-
44
- test "should create root comment if not logged in" do
45
- # Guests should not be able to make comments on unpublished comments
46
- newComment = FactoryGirl.build(:comment)
47
- refute_create_comment newComment
48
-
49
- # Guests should be able to make comments on published comments
50
- newComment = FactoryGirl.build(:published_comment)
51
- assert_create_comment newComment
52
- end
53
-
54
- test "should create reply if not logged in" do
55
- # Guests should not be able to make replies to comments on unpublished posts
56
- parent = FactoryGirl.create(:comment)
57
- reply = FactoryGirl.build(:comment,
58
- post: parent.post,
59
- parent: parent)
60
- refute_create_comment reply, 1, 1, parent
61
-
62
- # Guests should be able to make replies to comments on published posts
63
- parent = FactoryGirl.create(:published_comment)
64
- reply = FactoryGirl.build(:published_comment,
65
- post: parent.post,
66
- parent: parent)
67
- assert_create_comment reply, 1, 1, parent
68
- end
69
-
70
- test "should not create root comment if spammy" do
71
- newComment = FactoryGirl.build(:published_comment)
72
- refute_create_comment newComment, 1, 2
73
- end
74
-
75
- test "should not create reply if spammy" do
76
- parent = FactoryGirl.create(:published_comment)
77
- reply = FactoryGirl.build(:published_comment,
78
- post: parent.post,
79
- parent: parent)
80
- refute_create_comment reply, 3, 4, parent
81
- end
82
-
83
- test "should update root comment if logged in" do
84
- user = FactoryGirl.create(:user)
85
- sign_in user
86
-
87
- newComment = FactoryGirl.create(:comment)
88
- assert_update_comment newComment
89
- end
90
-
91
- test "should not update root comment if not logged in" do
92
- newComment = FactoryGirl.create(:comment)
93
- refute_update_comment newComment
94
- end
95
-
96
- test "should destroy root comment if logged in" do
97
- user = FactoryGirl.create(:user)
98
- sign_in user
99
-
100
- newComment = FactoryGirl.create(:comment)
101
-
102
- assert_difference('Comment.count', -1) do
103
- delete :destroy, format: :json, id: newComment
104
- end
105
- end
106
-
107
- test "should not destroy root comment if not logged in" do
108
- newComment = FactoryGirl.create(:comment)
109
-
110
- assert_no_difference('Comment.count') do
111
- delete :destroy, format: :json, id: newComment
112
- end
113
-
114
- assert_response :unauthorized
115
- end
116
-
117
- private
118
-
119
- def assert_create_comment(comment, antispam_solution = 1,
120
- antispam_answer = 1, parent = nil,
121
- subscription = nil)
122
- subscription_params = nil
123
- if subscription
124
- subscription_params = {
125
- subscribe: true,
126
- email: subscription.email
127
- }
128
- end
129
-
130
- antispam_params = nil
131
- if antispam_solution and antispam_answer
132
- antispam_params = {
133
- solution: antispam_solution,
134
- answer: antispam_answer
135
- }
136
- end
137
-
138
- assert_difference('Comment.count', 1,
139
- "A comment should have been created") do
140
- post :create, format: :json,
141
- comment: {
142
- author: comment.author,
143
- body: comment.body,
144
- post_id: comment.post_id,
145
- parent_id: comment.parent_id
146
- },
147
- subscription: subscription_params,
148
- antispam: antispam_params
149
- end
150
-
151
- if parent
152
- parent.reload # Refresh parent to pull in new associations
153
- assert_equal 1, parent.children.count,
154
- "The parent should have a child!"
155
-
156
- newComment = parent.children.first
157
- assert_equal comment.author, newComment.author
158
- assert_equal comment.body, newComment.body
159
- end
160
-
161
- json = JSON.parse(@response.body)
162
- assert_not_nil json["id"], "The returned JSON should include the ID!"
163
- assert_not_nil json["html"],
164
- "The returned JSON should include the HTML containing the comment!"
165
- end
166
-
167
- def refute_create_comment(comment, antispam_solution = 1,
168
- antispam_answer = 1, parent = nil,
169
- subscription = nil)
170
- subscription_params = nil
171
- if subscription
172
- subscription_params = {
173
- subscribe: true,
174
- email: subscription.email
175
- }
176
- end
177
-
178
- antispam_params = nil
179
- if antispam_solution and antispam_answer
180
- antispam_params = {
181
- solution: antispam_solution,
182
- answer: antispam_answer
183
- }
184
- end
185
-
186
- assert_no_difference('Comment.count',
187
- "A comment should not be created!") do
188
- post :create, format: :json,
189
- comment: {
190
- author: comment.author,
191
- body: comment.body,
192
- post_id: comment.post_id,
193
- parent_id: comment.parent_id
194
- },
195
- subscription: subscription_params,
196
- antispam: antispam_params
197
- end
198
-
199
- if antispam_solution == antispam_answer
200
- assert_response :not_found
201
- else
202
- assert_response :unprocessable_entity
203
- end
204
- end
205
-
206
- def assert_update_comment(comment)
207
- patch :update, format: :json, id: comment, comment: {
208
- author: comment.author,
209
- body: comment.body,
210
- post_id: comment.post_id
211
- }
212
-
213
- json = JSON.parse(@response.body)
214
- assert_not_nil json["id"]
215
- assert_not_nil json["html"]
216
- end
217
-
218
- def refute_update_comment(comment)
219
- patch :update, format: :json, id: comment, comment: {
220
- author: comment.author,
221
- body: comment.body,
222
- post_id: comment.post_id
223
- }
224
-
225
- assert_response :unauthorized
226
- end
227
- end
228
- end
@@ -1,166 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Proclaim
4
- class ImagesControllerTest < ActionController::TestCase
5
- setup do
6
- @routes = Engine.routes
7
-
8
- @controller.stubs(:current_user).returns(nil)
9
- @controller.stubs(:authenticate_user).returns(false)
10
- end
11
-
12
- teardown do
13
- image = FactoryGirl.build(:image, image: nil)
14
- FileUtils.rm_rf(File.join(Rails.public_path, image.image.cache_dir))
15
- FileUtils.rm_rf(File.join(Rails.public_path, image.image.store_dir))
16
- end
17
-
18
- test "should create image if logged in" do
19
- user = FactoryGirl.create(:user)
20
- sign_in user
21
-
22
- image = FactoryGirl.build(:image, image: nil)
23
-
24
- assert_difference('Image.count') do
25
- post :create, format: :json, image: {
26
- post_id: image.post_id,
27
- image: Rack::Test::UploadedFile.new(File.join(Rails.root, '../', 'support', 'images', 'test.jpg'))
28
- }
29
- end
30
-
31
- # Response should be the URL to the newly stored image
32
- assert_match image.image.store_dir, @response.body
33
- end
34
-
35
- test "should not create image if not logged in" do
36
- image = FactoryGirl.build(:image, image: nil)
37
-
38
- assert_no_difference('Image.count') do
39
- post :create, format: :json, image: {
40
- post_id: image.post_id,
41
- image: Rack::Test::UploadedFile.new(File.join(Rails.root, '../', 'support', 'images', 'test.jpg'))
42
- }
43
- end
44
-
45
- assert_response :unauthorized
46
- end
47
-
48
- test "should not create image without a post" do
49
- user = FactoryGirl.create(:user)
50
- sign_in user
51
-
52
- image = FactoryGirl.build(:image, post: nil, image: nil)
53
-
54
- assert_no_difference('Image.count') do
55
- post :create, format: :json, image: {
56
- image: Rack::Test::UploadedFile.new(File.join(Rails.root, '../', 'support', 'images', 'test.jpg'))
57
- }
58
- end
59
-
60
- assert_response :unprocessable_entity
61
- end
62
-
63
- test "should not create image without actual image" do
64
- user = FactoryGirl.create(:user)
65
- sign_in user
66
-
67
- image = FactoryGirl.build(:image, image: nil)
68
-
69
- assert_no_difference('Image.count') do
70
- post :create, format: :json, image: {
71
- post_id: image.post_id
72
- }
73
- end
74
-
75
- assert_response :unprocessable_entity
76
- end
77
-
78
- test "should cache image if logged in" do
79
- user = FactoryGirl.create(:user)
80
- sign_in user
81
-
82
- image = FactoryGirl.build(:image, image: nil)
83
-
84
- # This is only caching! No new image should be inserted into the database
85
- assert_no_difference('Image.count', "Caching shouldn't create new images!") do
86
- post :cache, format: :json, file: Rack::Test::UploadedFile.new(test_image_file_path)
87
- end
88
-
89
- # Response should be the URL to the newly cached image
90
- assert_match image.image.cache_dir, @response.body
91
- end
92
-
93
- test "should not cache image if not logged in" do
94
- assert_no_difference('Image.count') do
95
- post :cache, format: :json, file: Rack::Test::UploadedFile.new(test_image_file_path)
96
- end
97
-
98
- assert_response :unauthorized
99
- end
100
-
101
- test "should discard image if logged in" do
102
- user = FactoryGirl.create(:user)
103
- sign_in user
104
-
105
- image = FactoryGirl.build(:image)
106
-
107
- # This is only discarding from the cache! No images should be removed
108
- # from the database.
109
- assert_no_difference('Image.count', "Discarding shouldn't remove images!") do
110
- post :discard, format: :json, file: image.image.url
111
- end
112
-
113
- assert_response :success
114
- end
115
-
116
- test "should not discard image if not logged in" do
117
- image = FactoryGirl.build(:image)
118
-
119
- assert_no_difference('Image.count') do
120
- post :discard, format: :json, file: image.image.url
121
- end
122
-
123
- assert_response :unauthorized
124
- end
125
-
126
- test "discard should not destroy image if logged in but return ID" do
127
- user = FactoryGirl.create(:user)
128
- sign_in user
129
-
130
- image = FactoryGirl.create(:image)
131
-
132
- assert_no_difference('Image.count', -1) do
133
- post :discard, format: :json, file: image.image.url
134
- end
135
-
136
- assert_response :success
137
- assert_not_nil @response.body
138
- json = JSON.parse(@response.body)
139
-
140
- assert_equal image.id.to_s, json["id"]
141
- end
142
-
143
- test "should destroy image if logged in" do
144
- user = FactoryGirl.create(:user)
145
- sign_in user
146
-
147
- image = FactoryGirl.create(:image)
148
-
149
- assert_difference('Image.count', -1) do
150
- delete :destroy, format: :json, id: image.id
151
- end
152
-
153
- assert_response :success
154
- end
155
-
156
- test "should not destroy image if not logged in" do
157
- image = FactoryGirl.create(:image)
158
-
159
- assert_no_difference('Image.count') do
160
- delete :destroy, format: :json, id: image.id
161
- end
162
-
163
- assert_response :unauthorized
164
- end
165
- end
166
- end
@@ -1,465 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Proclaim
4
- class PostsControllerTest < ActionController::TestCase
5
- setup do
6
- @routes = Engine.routes
7
-
8
- @controller.stubs(:current_user).returns(nil)
9
- @controller.stubs(:authenticate_user).returns(false)
10
- end
11
-
12
- teardown do
13
- image = Image.new
14
- FileUtils.rm_rf(File.join(Rails.public_path, image.image.cache_dir))
15
- FileUtils.rm_rf(File.join(Rails.public_path, image.image.store_dir))
16
- end
17
-
18
- test "should get index if logged in" do
19
- user = FactoryGirl.create(:user)
20
- sign_in user
21
-
22
- post1 = FactoryGirl.create(:post)
23
- post2 = FactoryGirl.create(:published_post)
24
-
25
- get :index
26
- assert_response :success
27
- assert_not_nil assigns(:posts)
28
- assert_includes assigns(:posts), post1
29
- assert_includes assigns(:posts), post2
30
- end
31
-
32
- test "should get index even if not logged in" do
33
- post1 = FactoryGirl.create(:post)
34
- post2 = FactoryGirl.create(:published_post)
35
-
36
- get :index
37
- assert_response :success
38
- assert_not_nil assigns(:posts)
39
- assert_not_includes assigns(:posts), post1
40
- assert_includes assigns(:posts), post2
41
- end
42
-
43
- test "posts should be ordered by publication date" do
44
- post1 = FactoryGirl.create(:published_post)
45
- post2 = FactoryGirl.create(:published_post)
46
-
47
- get :index
48
- assert_response :success
49
- assert_not_nil assigns(:posts)
50
- assert_equal 2, assigns(:posts).count
51
- assert_equal post2, assigns(:posts).first
52
- assert_equal post1, assigns(:posts).last
53
- end
54
-
55
- test "drafts should be ordered by updated date" do
56
- user = FactoryGirl.create(:user)
57
- sign_in user
58
-
59
- post1 = FactoryGirl.create(:post)
60
- post2 = FactoryGirl.create(:post)
61
- post3 = FactoryGirl.create(:post)
62
-
63
- # Update post1 so its updated_at is newest
64
- post2.body = "Updated Body"
65
- post2.save
66
-
67
- get :index
68
- assert_response :success
69
- assert_not_nil assigns(:posts)
70
- assert_equal 3, assigns(:posts).count
71
- assert_equal post2, assigns(:posts).first
72
- assert_equal post3, assigns(:posts).second
73
- assert_equal post1, assigns(:posts).last
74
- end
75
-
76
- test "should get new if logged in" do
77
- user = FactoryGirl.create(:user)
78
- sign_in user
79
-
80
- get :new
81
- assert_response :success
82
- end
83
-
84
- test "should not get new if not logged in" do
85
- get :new
86
- assert_response :redirect
87
- assert_match /not authorized/, flash[:error]
88
- end
89
-
90
- test "should create post if logged in" do
91
- user = FactoryGirl.create(:user)
92
- sign_in user
93
-
94
- newPost = FactoryGirl.build(:post)
95
-
96
- assert_difference('Post.count') do
97
- post :create, post: {
98
- author_id: newPost.author_id,
99
- body: newPost.body,
100
- title: newPost.title
101
- }
102
- end
103
-
104
- assert_redirected_to post_path(assigns(:post))
105
- assert_match /successfully created/, flash[:notice]
106
- refute assigns(:post).published?
107
- end
108
-
109
- test "should create published post if logged in" do
110
- user = FactoryGirl.create(:user)
111
- sign_in user
112
-
113
- newPost = FactoryGirl.build(:post)
114
-
115
- assert_difference('Post.count') do
116
- post :create, post: {
117
- author_id: newPost.author_id,
118
- body: newPost.body,
119
- title: newPost.title
120
- }, publish: "true"
121
- end
122
-
123
- assert_redirected_to post_path(assigns(:post))
124
- assert_match /successfully created/, flash[:notice]
125
- assert assigns(:post).published?
126
- end
127
-
128
- test "should not create post without title" do
129
- user = FactoryGirl.create(:user)
130
- sign_in user
131
-
132
- newPost = FactoryGirl.build(:post)
133
-
134
- assert_no_difference('Post.count') do
135
- post :create, post: {
136
- author_id: newPost.author_id,
137
- body: newPost.body
138
- # Leave off title
139
- }
140
- end
141
-
142
- assert assigns(:post).errors.any?,
143
- "Expected an error due to lack of post title"
144
- assert_template :new, "Expected new view to be rendered again"
145
- end
146
-
147
- test "should not create post without body" do
148
- user = FactoryGirl.create(:user)
149
- sign_in user
150
-
151
- newPost = FactoryGirl.build(:post)
152
-
153
- assert_no_difference('Post.count') do
154
- post :create, post: {
155
- author_id: newPost.author_id,
156
- title: newPost.title
157
- # Leave off body
158
- }
159
- end
160
-
161
- assert assigns(:post).errors.any?,
162
- "Expected an error due to lack of post body"
163
- assert_template :new, "Expected new view to be rendered again"
164
- end
165
-
166
- test "should upload images when creating post" do
167
- user = FactoryGirl.create(:user)
168
- sign_in user
169
-
170
- newPost = FactoryGirl.build(:post)
171
- image = FactoryGirl.build(:image, post: newPost)
172
-
173
- newPost.body = "<img src=\"#{image.image.url}\"></img>"
174
-
175
- post :create, post: {
176
- author_id: newPost.author_id,
177
- body: newPost.body,
178
- title: newPost.title
179
- }
180
-
181
- post = Post.first # This works since there's only one
182
- assert_equal 1, post.images.count, "The post should have an image"
183
-
184
- image = post.images.first
185
-
186
- save_path = File.join(Rails.public_path, image.image.store_dir)
187
- saved_file_path = File.join(save_path, image.image_identifier)
188
- assert File.exist?(saved_file_path), "File should be saved: #{saved_file_path}"
189
-
190
- document = Nokogiri::HTML.fragment(post.body)
191
- image_tags = document.css("img")
192
- assert_equal 1, image_tags.count, "Post body should have one image tag"
193
-
194
- # Note that, now that the image is saved, this URL is different than
195
- # the one submitted to :create
196
- assert_equal image.image.url, image_tags.first.attributes["src"].value
197
- end
198
-
199
- test "should not create post if not logged in" do
200
- newPost = FactoryGirl.build(:post)
201
-
202
- assert_no_difference('Post.count') do
203
- post :create, post: {
204
- author_id: newPost.author_id,
205
- body: newPost.body,
206
- title: newPost.title
207
- }
208
- end
209
-
210
- assert_response :redirect
211
- assert_match /not authorized/, flash[:error]
212
- end
213
-
214
- test "should show draft post if logged in" do
215
- user = FactoryGirl.create(:user)
216
- sign_in user
217
-
218
- # Should show draft post
219
- newPost = FactoryGirl.create(:post)
220
-
221
- get :show, id: newPost
222
- assert_response :success
223
- assert_equal newPost, assigns(:post)
224
- end
225
-
226
- test "should show published post if logged in" do
227
- user = FactoryGirl.create(:user)
228
- sign_in user
229
-
230
- # Should show published post
231
- newPost = FactoryGirl.create(:published_post)
232
-
233
- get :show, id: newPost
234
- assert_response :success
235
- assert_equal newPost, assigns(:post)
236
- end
237
-
238
- test "should not show draft post if not logged in" do
239
- # Should not show draft post
240
- newPost = FactoryGirl.create(:post)
241
-
242
- # Controller should hide the "permission denied" in a "not-found"
243
- assert_raises ActiveRecord::RecordNotFound do
244
- get :show, id: newPost
245
- end
246
- end
247
-
248
- test "should show published post if not logged in" do
249
- # Should show published post
250
- newPost = FactoryGirl.create(:published_post)
251
-
252
- get :show, id: newPost
253
- assert_response :success
254
- assert_equal newPost, assigns(:post)
255
- end
256
-
257
- test "should show post via id" do
258
- post = FactoryGirl.create(:published_post, title: "New Post")
259
-
260
- # Test with ID
261
- get :show, id: post.id
262
- assert_response :redirect,
263
- "Visiting a post by ID should redirect to slug"
264
- assert_equal post, assigns(:post)
265
- end
266
-
267
- test "should show post via slug" do
268
- post = FactoryGirl.create(:published_post, title: "New Post")
269
-
270
- # Test with slug
271
- get :show, id: post.friendly_id
272
- assert_response :success
273
- assert_equal post, assigns(:post)
274
- end
275
-
276
- test "should not show draft post via old slugs" do
277
- user = FactoryGirl.create(:user)
278
- sign_in user
279
-
280
- post = FactoryGirl.create(:post, title: "New Post")
281
- old_slug = post.friendly_id
282
-
283
- # Now change slug
284
- post.title = "New Post Modified"
285
- post.save
286
-
287
- # Verify that old slug doesn't work
288
- assert_raises ActiveRecord::RecordNotFound,
289
- "Draft posts should not maintain slug history" do
290
- get :show, id: old_slug
291
- end
292
- end
293
-
294
- test "should show published post via old slugs" do
295
- post = FactoryGirl.create(:published_post, title: "New Post")
296
- old_slug = post.friendly_id
297
-
298
- # Now change slug
299
- post.title = "New Post Modified"
300
- post.save
301
-
302
- # Verify that old slug still works
303
- get :show, id: old_slug
304
- assert_response :redirect, "This should redirect to the current slug"
305
- assert_equal assigns(:post), post
306
- end
307
-
308
- test "should get edit if logged in" do
309
- user = FactoryGirl.create(:user)
310
- sign_in user
311
-
312
- newPost = FactoryGirl.create(:post)
313
-
314
- get :edit, id: newPost
315
- assert_response :success
316
- assert_equal assigns(:post), newPost
317
- end
318
-
319
- test "should not get edit if not logged in" do
320
- newPost = FactoryGirl.create(:post)
321
-
322
- get :edit, id: newPost
323
- assert_response :redirect
324
- assert_match /not authorized/, flash[:error]
325
- end
326
-
327
- test "should update post if logged in" do
328
- user = FactoryGirl.create(:user)
329
- sign_in user
330
-
331
- newPost = FactoryGirl.create(:post)
332
-
333
- patch :update, id: newPost, post: {
334
- author_id: newPost.author_id,
335
- body: newPost.body,
336
- title: newPost.title
337
- }
338
-
339
- assert_redirected_to post_path(assigns(:post))
340
- assert_match /successfully updated/, flash[:notice]
341
- refute assigns(:post).published?
342
- end
343
-
344
- test "should publish post if logged in" do
345
- user = FactoryGirl.create(:user)
346
- sign_in user
347
-
348
- newPost = FactoryGirl.create(:post)
349
-
350
- patch :update, id: newPost, post: {
351
- author_id: newPost.author_id,
352
- body: newPost.body,
353
- title: newPost.title
354
- }, publish: "true"
355
-
356
- assert_redirected_to post_path(assigns(:post))
357
- assert_match /successfully updated/, flash[:notice]
358
- assert assigns(:post).published?, "Post should now be published!"
359
- end
360
-
361
- test "should upload images when updating a post" do
362
- user = FactoryGirl.create(:user)
363
- sign_in user
364
-
365
- newPost = FactoryGirl.create(:post)
366
- image = FactoryGirl.build(:image, post: newPost)
367
-
368
- newPost.body = "<img src=\"#{image.image.url}\">"
369
-
370
- patch :update, id: newPost, post: {
371
- author_id: newPost.author_id,
372
- body: newPost.body,
373
- title: newPost.title
374
- }
375
-
376
- post = Post.first # This works since there's only one
377
- assert_equal 1, post.images.count, "The post should have an image"
378
-
379
- image = post.images.first
380
-
381
- save_path = File.join(Rails.public_path, image.image.store_dir)
382
- saved_file_path = File.join(save_path, image.image_identifier)
383
- assert File.exist?(saved_file_path), "File should be saved: #{saved_file_path}"
384
-
385
- document = Nokogiri::HTML.fragment(post.body)
386
- image_tags = document.css("img")
387
- assert_equal 1, image_tags.count,
388
- "Post body should contain one image tag"
389
-
390
- # Note that, now that the image is saved, this URL is different than
391
- # the one submitted to :create
392
- assert_equal image.image.url, image_tags.first.attributes["src"].value
393
- end
394
-
395
- test "should not update post if not logged in" do
396
- newPost = FactoryGirl.create(:post)
397
-
398
- patch :update, id: newPost, post: {
399
- author_id: newPost.author_id,
400
- body: newPost.body,
401
- title: newPost.title
402
- }
403
-
404
- assert_response :redirect
405
- assert_match /not authorized/, flash[:error]
406
- end
407
-
408
- test "should not update post without title" do
409
- user = FactoryGirl.create(:user)
410
- sign_in user
411
-
412
- newPost = FactoryGirl.create(:post)
413
-
414
- patch :update, id: newPost, post: {
415
- author_id: newPost.author_id,
416
- title: "" # Remove title
417
- }
418
-
419
- assert assigns(:post).errors.any?,
420
- "Expected an error due to lack of post title"
421
- assert_template :edit, "Expected edit view to be rendered again"
422
- end
423
-
424
- test "should not update post without body" do
425
- user = FactoryGirl.create(:user)
426
- sign_in user
427
-
428
- newPost = FactoryGirl.create(:post)
429
-
430
- patch :update, id: newPost, post: {
431
- author_id: newPost.author_id,
432
- body: "" # Remove body
433
- }
434
-
435
- assert assigns(:post).errors.any?,
436
- "Expected an error due to lack of post body"
437
- assert_template :edit, "Expected edit view to be rendered again"
438
- end
439
-
440
- test "should destroy post if logged in" do
441
- user = FactoryGirl.create(:user)
442
- sign_in user
443
-
444
- newPost = FactoryGirl.create(:post)
445
-
446
- assert_difference('Post.count', -1) do
447
- delete :destroy, id: newPost
448
- end
449
-
450
- assert_redirected_to posts_path
451
- assert_match /successfully destroyed/, flash[:notice]
452
- end
453
-
454
- test "should not destroy post if not logged in" do
455
- newPost = FactoryGirl.create(:post)
456
-
457
- assert_no_difference('Post.count') do
458
- delete :destroy, id: newPost
459
- end
460
-
461
- assert_response :redirect
462
- assert_match /not authorized/, flash[:error]
463
- end
464
- end
465
- end