commontator 5.1.0 → 6.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +83 -63
  4. data/app/assets/javascripts/commontator/mentions.js +2 -2
  5. data/app/assets/stylesheets/commontator/application.scss +101 -0
  6. data/app/assets/stylesheets/commontator/comments.scss +103 -0
  7. data/app/controllers/commontator/application_controller.rb +21 -21
  8. data/app/controllers/commontator/comments_controller.rb +123 -114
  9. data/app/controllers/commontator/security_transgression.rb +2 -0
  10. data/app/controllers/commontator/subscriptions_controller.rb +20 -22
  11. data/app/controllers/commontator/threads_controller.rb +50 -50
  12. data/app/helpers/commontator/application_helper.rb +3 -5
  13. data/app/helpers/commontator/link_renderer.rb +25 -0
  14. data/app/mailers/commontator/subscriptions_mailer.rb +35 -35
  15. data/app/models/commontator/comment.rb +208 -91
  16. data/app/models/commontator/json_array_coder.rb +10 -0
  17. data/app/models/commontator/subscription.rb +13 -16
  18. data/app/models/commontator/thread.rb +139 -133
  19. data/app/views/commontator/comments/_actions.html.erb +9 -10
  20. data/app/views/commontator/comments/_body.html.erb +11 -6
  21. data/app/views/commontator/comments/_form.html.erb +31 -20
  22. data/app/views/commontator/comments/_list.html.erb +6 -5
  23. data/app/views/commontator/comments/_reply.html.erb +15 -0
  24. data/app/views/commontator/comments/_show.html.erb +31 -25
  25. data/app/views/commontator/comments/_votes.html.erb +12 -11
  26. data/app/views/commontator/comments/cancel.js.erb +6 -14
  27. data/app/views/commontator/comments/create.js.erb +20 -14
  28. data/app/views/commontator/comments/delete.js.erb +14 -14
  29. data/app/views/commontator/comments/edit.js.erb +6 -4
  30. data/app/views/commontator/comments/new.js.erb +11 -7
  31. data/app/views/commontator/comments/update.js.erb +6 -4
  32. data/app/views/commontator/comments/vote.js.erb +3 -4
  33. data/app/views/commontator/shared/_thread.html.erb +23 -11
  34. data/app/views/commontator/subscriptions/_link.html.erb +7 -8
  35. data/app/views/commontator/subscriptions/subscribe.js.erb +3 -4
  36. data/app/views/commontator/subscriptions_mailer/comment_created.html.erb +9 -8
  37. data/app/views/commontator/threads/_hide_show_links.js.erb +10 -9
  38. data/app/views/commontator/threads/_reply.html.erb +17 -16
  39. data/app/views/commontator/threads/_show.html.erb +75 -76
  40. data/app/views/commontator/threads/_show.js.erb +12 -16
  41. data/app/views/commontator/threads/show.js.erb +9 -6
  42. data/config/initializers/commontator.rb +81 -67
  43. data/config/locales/de.yml +28 -48
  44. data/config/locales/en.yml +38 -27
  45. data/config/locales/pt-BR.yml +31 -29
  46. data/config/locales/ru.yml +34 -29
  47. data/config/locales/zh.yml +65 -48
  48. data/db/migrate/0_install_commontator.rb +27 -32
  49. data/db/migrate/1_add_replying_to_comments.rb +9 -0
  50. data/lib/commontator.rb +9 -140
  51. data/lib/commontator/acts_as_commontable.rb +24 -33
  52. data/lib/commontator/acts_as_commontator.rb +28 -25
  53. data/lib/commontator/build_thread.rb +10 -0
  54. data/lib/commontator/commontable_config.rb +10 -10
  55. data/lib/commontator/commontator_config.rb +10 -10
  56. data/lib/{commontator.rb~ → commontator/config.rb} +57 -57
  57. data/lib/commontator/controllers.rb +35 -29
  58. data/lib/commontator/engine.rb +6 -4
  59. data/lib/commontator/shared_helper.rb +58 -21
  60. data/lib/commontator/version.rb +1 -3
  61. data/lib/tasks/commontator_tasks.rake +2 -2
  62. data/vendor/assets/stylesheets/mentionsInput/jquery.mentionsInput.css +0 -1
  63. metadata +50 -496
  64. data/Rakefile +0 -22
  65. data/app/assets/javascripts/commontator/application.js~ +0 -3
  66. data/app/assets/javascripts/commontator/mentions.js~ +0 -31
  67. data/app/assets/stylesheets/commontator/application.css +0 -5
  68. data/app/assets/stylesheets/commontator/application.css~ +0 -14
  69. data/app/assets/stylesheets/commontator/comments.css +0 -121
  70. data/app/assets/stylesheets/commontator/threads.css +0 -71
  71. data/app/assets/stylesheets/commontator/threads.css~ +0 -71
  72. data/app/controllers/commontator/comments_controller.rb~ +0 -160
  73. data/app/controllers/commontator/threads_controller.rb~ +0 -75
  74. data/app/mailers/commontator/subscriptions_mailer.rb~ +0 -65
  75. data/app/models/commontator/comment.rb~ +0 -124
  76. data/app/models/commontator/subscription.rb~ +0 -23
  77. data/app/views/commontator/shared/_thread.html.erb~ +0 -21
  78. data/app/views/commontator/subscriptions_mailer/comment_created.html.erb~ +0 -10
  79. data/app/views/commontator/threads/_hide_show.js.erb~ +0 -21
  80. data/app/views/commontator/threads/_hide_show_links.js.erb~ +0 -17
  81. data/app/views/commontator/threads/_show.html.erb~ +0 -118
  82. data/app/views/commontator/threads/_show.js.erb~ +0 -18
  83. data/config/initializers/commontator.rb~ +0 -290
  84. data/config/locales/en.yml~ +0 -101
  85. data/config/locales/ru.yml~ +0 -79
  86. data/config/locales/zh.yml~ +0 -79
  87. data/config/routes.rb~ +0 -25
  88. data/db/migrate/0_install_commontator.rb~ +0 -52
  89. data/db/migrate/1_add_parent_comment_id_to_commontator_comments.rb~ +0 -9
  90. data/lib/commontator/link_renderer.rb +0 -28
  91. data/lib/commontator/security_transgression.rb +0 -4
  92. data/lib/commontator/shared_helper.rb~ +0 -26
  93. data/lib/commontator/version.rb~ +0 -3
  94. data/spec/controllers/commontator/comments_controller_spec.rb +0 -613
  95. data/spec/controllers/commontator/comments_controller_spec.rb~ +0 -612
  96. data/spec/controllers/commontator/subscriptions_controller_spec.rb +0 -101
  97. data/spec/controllers/commontator/subscriptions_controller_spec.rb~ +0 -101
  98. data/spec/controllers/commontator/threads_controller_spec.rb +0 -219
  99. data/spec/controllers/commontator/threads_controller_spec.rb~ +0 -218
  100. data/spec/dummy/README.md +0 -4
  101. data/spec/dummy/README.md~ +0 -3
  102. data/spec/dummy/Rakefile +0 -7
  103. data/spec/dummy/Rakefile~ +0 -6
  104. data/spec/dummy/app/assets/javascripts/application.js +0 -17
  105. data/spec/dummy/app/assets/javascripts/application.js~ +0 -16
  106. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  107. data/spec/dummy/app/assets/stylesheets/application.css~ +0 -14
  108. data/spec/dummy/app/controllers/application_controller.rb +0 -6
  109. data/spec/dummy/app/controllers/application_controller.rb~ +0 -4
  110. data/spec/dummy/app/controllers/dummy_models_controller.rb +0 -23
  111. data/spec/dummy/app/controllers/dummy_models_controller.rb~ +0 -23
  112. data/spec/dummy/app/helpers/application_helper.rb +0 -16
  113. data/spec/dummy/app/helpers/application_helper.rb~ +0 -15
  114. data/spec/dummy/app/models/dummy_dependent_model.rb +0 -4
  115. data/spec/dummy/app/models/dummy_model.rb +0 -4
  116. data/spec/dummy/app/models/dummy_model.rb~ +0 -3
  117. data/spec/dummy/app/models/dummy_user.rb +0 -14
  118. data/spec/dummy/app/models/dummy_user.rb~ +0 -13
  119. data/spec/dummy/app/views/dummy_models/index.html.erb~ +0 -6
  120. data/spec/dummy/app/views/dummy_models/show.html.erb +0 -2
  121. data/spec/dummy/app/views/dummy_models/show.html.erb~ +0 -2
  122. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  123. data/spec/dummy/app/views/layouts/application.html.erb~ +0 -14
  124. data/spec/dummy/config.ru +0 -5
  125. data/spec/dummy/config.ru~ +0 -4
  126. data/spec/dummy/config/application.rb +0 -27
  127. data/spec/dummy/config/application.rb~ +0 -26
  128. data/spec/dummy/config/boot.rb +0 -6
  129. data/spec/dummy/config/boot.rb~ +0 -5
  130. data/spec/dummy/config/database.yml +0 -26
  131. data/spec/dummy/config/database.yml~ +0 -25
  132. data/spec/dummy/config/environment.rb +0 -8
  133. data/spec/dummy/config/environment.rb~ +0 -8
  134. data/spec/dummy/config/environments/development.rb +0 -31
  135. data/spec/dummy/config/environments/development.rb~ +0 -31
  136. data/spec/dummy/config/environments/production.rb +0 -82
  137. data/spec/dummy/config/environments/production.rb~ +0 -82
  138. data/spec/dummy/config/environments/test.rb +0 -40
  139. data/spec/dummy/config/environments/test.rb~ +0 -40
  140. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
  141. data/spec/dummy/config/initializers/backtrace_silencers.rb~ +0 -7
  142. data/spec/dummy/config/initializers/commontator.rb +0 -20
  143. data/spec/dummy/config/initializers/commontator.rb~ +0 -21
  144. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -5
  145. data/spec/dummy/config/initializers/filter_parameter_logging.rb~ +0 -4
  146. data/spec/dummy/config/initializers/inflections.rb +0 -17
  147. data/spec/dummy/config/initializers/inflections.rb~ +0 -16
  148. data/spec/dummy/config/initializers/mime_types.rb +0 -6
  149. data/spec/dummy/config/initializers/mime_types.rb~ +0 -5
  150. data/spec/dummy/config/initializers/secret_token.rb +0 -13
  151. data/spec/dummy/config/initializers/secret_token.rb~ +0 -12
  152. data/spec/dummy/config/initializers/session_store.rb +0 -4
  153. data/spec/dummy/config/initializers/session_store.rb~ +0 -3
  154. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -15
  155. data/spec/dummy/config/initializers/wrap_parameters.rb~ +0 -14
  156. data/spec/dummy/config/routes.rb +0 -9
  157. data/spec/dummy/config/routes.rb~ +0 -10
  158. data/spec/dummy/db/development.sqlite3 +0 -0
  159. data/spec/dummy/db/migrate/1_create_dummy_models.rb +0 -7
  160. data/spec/dummy/db/migrate/1_create_dummy_models.rb~ +0 -7
  161. data/spec/dummy/db/migrate/2_create_dummy_users.rb +0 -7
  162. data/spec/dummy/db/migrate/2_create_dummy_users.rb~ +0 -7
  163. data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb +0 -22
  164. data/spec/dummy/db/migrate/3_acts_as_votable_migration.rb~ +0 -27
  165. data/spec/dummy/db/migrate/4_create_dummy_dependent_models.rb +0 -7
  166. data/spec/dummy/db/schema.rb +0 -85
  167. data/spec/dummy/db/test.sqlite3 +0 -0
  168. data/spec/dummy/lib/controllers.rb~ +0 -10
  169. data/spec/dummy/lib/dummy_controllers.rb +0 -10
  170. data/spec/dummy/log/development.log +0 -6693
  171. data/spec/dummy/log/test.log +0 -125970
  172. data/spec/dummy/public/404.html +0 -27
  173. data/spec/dummy/public/404.html~ +0 -26
  174. data/spec/dummy/public/422.html +0 -27
  175. data/spec/dummy/public/422.html~ +0 -26
  176. data/spec/dummy/public/500.html +0 -26
  177. data/spec/dummy/public/500.html~ +0 -25
  178. data/spec/dummy/public/favicon.ico +0 -0
  179. data/spec/dummy/script/rails +0 -7
  180. data/spec/dummy/script/rails~ +0 -6
  181. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/-RolHYhJdGiLoPkoWZXQdI9AIWUjMMCa2yFJezCE_Bo.cache +0 -2
  182. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/-STzK7UuGeY3gSvnmTELWLvtRMKpmSAQCEw4ao3b1r8.cache +0 -1
  183. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/3NH8nN7uktAXgA3NqaqXTXDVic3BxBvqCxoLpGGbib4.cache +0 -0
  184. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/4_iT7KM6P2IT75Rssrk9p4crTBwM8DQWR41gmsxczL0.cache +0 -0
  185. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/58TLCXvf5bFFYY-mIUXrQNOVWlGsq7qPAoSX2OIIB8Y.cache +0 -0
  186. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6OQdyrATvNatvWu8Mp1qbuvRx-HLmzCZ5XBGYca-rZU.cache +0 -0
  187. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6UKCUV-ZLaWCoPMfMB6a2W0RCFPQzPJ6Mz-y67sH7zk.cache +0 -2
  188. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6wKNjFdNd4OHjIpLC0nq1kBWcbYg1aEYrp7ZhWoJlvY.cache +0 -1
  189. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/7Xxb5iYP5elo40JRlhNQB1gLbv3ueELK2rTinYt5xdc.cache +0 -1
  190. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/7twIKlS6VYCyLlwhsQg2vu4wLSUJsT2REHR4DjZf1oE.cache +0 -2
  191. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/87m-4EcbQnkbo2HYkQp4V9I2U3AYQO1mPeReieduolA.cache +0 -1
  192. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/8B331vt8qC4iXTcVzkx3j-ET8i1oaQskj5LyqGq8mPQ.cache +0 -0
  193. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/8KWvIOgvo7BVJYtdTpFuiSQQFFwZhLWYtwacZv52y48.cache +0 -0
  194. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/9yQa5M2ObK2-qDu231zMoarjVbhKUUg-ND3r2iXqB_Q.cache +0 -0
  195. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/A-ffuUI2juZT6qFpTUwUR1P8OPWcyFFN26WSUZe60Ko.cache +0 -1
  196. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/BbO4diS6uacx69Hn_bCabYlXEbWWdjHShRlfzlWSOMI.cache +0 -0
  197. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/CXhqxaQQAQ8b0Y8y0jTQyiqsZ6Oe4fZn0YiacpJ9IoI.cache +0 -1
  198. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/E1zaNOh68xzPxdtdOwRtOaMCoKivN2dxVwCP65WEi5I.cache +0 -2
  199. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/EmPkV3H8p2Snv9WyPjWran_kOMQ0MqQ1a9CVdGDd8l4.cache +0 -1
  200. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Hc12Nxe7cw2e0u2pzNsAe8D3ncQpcqLuI2NVL7aAXgw.cache +0 -1
  201. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/HdWuQr9W2mZvggsAxVjDgLYUNfg3rbI-T8KhaDIsvQk.cache +0 -0
  202. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/I7lsrHTKpbfLWqIqdDIx2RN_12yFL2PyLRyYsMxg1IU.cache +0 -1
  203. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/JOCzfBjMjX3D5BUUGh5lJ7fjzMuJrHLxAginRA2_hZQ.cache +0 -0
  204. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/JusxTSXt06IqBm9jeCMM2nTmM3Wvbl3i3L1IwEvW5YA.cache +0 -2
  205. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/KAY1_IaTONtGr0KK8ihOdoA-RDXybqBMNSZLIDRHx68.cache +0 -1
  206. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/KBHIDNfa4ryw9LAkYqK8GgPWne7HkX6mNYgrJajGm94.cache +0 -1
  207. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/L_lv02y00MmIFiFhg5c9zhl7CDHLSahehzLyi_mRZeY.cache +0 -0
  208. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MOT2X4iikR8v89A4N1bxDTeS1-xV8c9036TNFXmwXCM.cache +0 -1
  209. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MiX2Z4Vbha1riozZWw1U3_PGttRiZ1iQ_o4wSZJnKCs.cache +0 -3
  210. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MntKfwol0ud4LuvrX3MVPthTlfNlJZRYbQXpQBxhRrs.cache +0 -1
  211. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MrqmgPGNYJV1capJKIKJOVEQ4NiO-Z_2YhpjNteJ8B8.cache +0 -2
  212. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/NVMnAwylzGp5bjl_o9dwMAQxVAPDzc4ygddNQSD1fiw.cache +0 -0
  213. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/O2sKqGxNuCYhjzuEZVC9hX_FeemOfRn_1-CCuHBQYyg.cache +0 -1
  214. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Qy3TykLFmAt5jhSluMTaZaefcA5c_vfBRhQ7tin-gsk.cache +0 -0
  215. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/R3DpUgZ_hja1dQTIzumiP9AD_r8mlOaqv0U9QqnGQqo.cache +0 -0
  216. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/RF07mgb06A30OcDWtCaDlM5tEc1yp0uAsk986Gqs5w8.cache +0 -1
  217. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/S-6Iq5YOEpVnd_vQ0RSSfrmyIwB1dk0op35alFgJ9xA.cache +0 -2
  218. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/TKV8dUTo88gdFY-z2I7Xa5vDC1Z3LY6Paa18385MJsI.cache +0 -1
  219. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/UI4zPmWfZA2d_5ZZIXqK9KmkjOKSDg6JoM7qcOIxm0Q.cache +0 -1
  220. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/UP29vrIQbCkfghZGSCFxpW5gjlsgCxlVrncjjopvRqM.cache +0 -2
  221. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/UoU16f4V7haEXM5GY5j4QFuNMP7PJZaAMEvVNNtNLBA.cache +0 -1
  222. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/VqPqYNG07yqcjbd7FA05Mu-jr5hzsZPaHFf8X0FFbXk.cache +0 -2
  223. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/WkN1QFvcuzXSsyNmfaK02ojXPk-8zmdEegzNPfdAEL4.cache +0 -0
  224. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/WkQX7Wiz41OKx2aGF7uffOmS04hIVZeGCondBAvwum8.cache +0 -2
  225. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/XMeYF1vwAg53eVjXVkw_IKQH2W3-9tWvtuCdqUCbPBM.cache +0 -2
  226. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/XX0Z7OM0xZKfQaAvHARpyeQNZCstNyu9MlsnwThSkg8.cache +0 -1
  227. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Y-pGNFTA6bAKxSvqZvmMVs3b4Els1aByxZVFxtJR71c.cache +0 -1
  228. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Y3p3m5V5NOm7yq56apKmF5KZUUsTfnhT_SG3fqbEJgo.cache +0 -1
  229. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/YLZuRWklL6q-csC-7A7CiOTTTYEQcA9PCdWEOm9MpNU.cache +0 -1
  230. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Yo7V5YXukEBm6z37l-TIRCJx3HZExEUBu3MUMhAzkMU.cache +0 -1
  231. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/bK6QttR8pGmMAMJO0avCBLwH0za8_bAC-yWqkU3Yj24.cache +0 -1
  232. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/cLncjrqpQXzsVBp7K0W7iG1STLrnzfGpbJXxNE7aIUk.cache +0 -2
  233. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/dBcAd64EZFdhHZNXKGXPIR7EtPGf03bzqkci2W12T8g.cache +0 -2
  234. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/d_bbPiareJHKkzFZFCl3pcwfQOFzsB1KHn4A2xxhR20.cache +0 -1
  235. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/eaHZBuJRcawVlkGZVyyRr5_4xYKVOXbCqnTcmaNXzL0.cache +0 -0
  236. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/gWnmfJty3jBn53qsJfOXKrWv4e8i3Dp80wVel-f1L1E.cache +0 -1
  237. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/gumo32Bd3W_q7MYEt9JIZEiQdHF93tLSsGfmXIm2MqU.cache +0 -1
  238. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/jKTlG9KP0iaCGHwg8kQ1amz9SHJ1OAWeCRRn9wc5w7c.cache +0 -1
  239. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/kPJfTiWbmX-q6i2rjM9MAMdEf2silSihU0_lxlTGVA8.cache +0 -1
  240. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/lrt1SWPj4qWUZUMH9xg3n9KLYUqJZxRn-XI-NTU6oTI.cache +0 -1
  241. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/mcCP5u08nlCL6TgWdzzrem9uE2rbsbG3KyIXxvWvlJE.cache +0 -3
  242. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/pC4exGjkQLXXPE0O9hjX_2AJ4DASTFeB6RGjXagxEac.cache +0 -0
  243. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/pIRh_Lq-ZhYC_XdRcqIsCtUkTnwVET0Wrrpw1EltHd8.cache +0 -2
  244. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/qfXc71sDbi1cE9f327D6ABPURPU6lLguGiJqH2fqM0w.cache +0 -1
  245. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rBcrkzXcMaiCjwvWl8tO0eARzKZS69I3i-lfsTAFzcc.cache +0 -1
  246. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/sfl8l1_1AGn-4llkmb91Q0wHJ-A-x5gAGkIUWe1zLqo.cache +0 -1
  247. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/tFQc0MOeWpJ7t7cNP2GOzo7o9Z6YBgLEpdS0tGLvUSw.cache +0 -0
  248. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/tb9v5OemP-ADEwYnETLLi1r088kZm_TMb9ZVeTV5JxI.cache +0 -1
  249. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/uKmWfbgaNZ8FTsVK1VNuUv15rmtTHzSdJ7TQRGr0Rck.cache +0 -2
  250. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/ul0QEoovfr_12YOpyWx8BJs8fvz5Ay3AZG8-lsLr-a4.cache +0 -1
  251. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/vY6eUgBIXKHqfU2ZroS-GugKPg5_fo2QBs-vS5gBN2o.cache +0 -0
  252. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/vrRc4DPAbHIJHJqsXfBYdyKUPFv8f8YYKJUrk-1zdVw.cache +0 -0
  253. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/wTET4PQq7wlxzrgvNivPJad-CACkoQS4BNxAP0FQaR4.cache +0 -0
  254. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/wcvE87iLx7cDjMDs_Yu1jKYvep-VyLEyj1eXL79KLp4.cache +0 -0
  255. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xQeZ92qbm2t9FaRck5xUakvNP-MJ2cs0RroN-fm0Tf8.cache +0 -1
  256. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xQz9WPf67Mu5uV4rNuOfU-y6_KWSlWcnTWrTvQPonKM.cache +0 -0
  257. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xhYTRUOS8cIvyRp2Jn6FKnXlGOSsIM2z3HAGOJoJs7w.cache +0 -1
  258. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/yLxMFI0ARh2OKSOQLF2xEfM7sbst2vUbOBXoOuI6iTE.cache +0 -1
  259. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/ynnYZxuxqerlFUytw54dl_CwP94g0U4HmGjyILWnhfQ.cache +0 -1
  260. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/zCivVPbSRpKF_X-P5OJeld32YhymG-bkjQwzqe2o6zg.cache +0 -2
  261. data/spec/dummy/tmp/cache/assets/test/sprockets/02d4b791eb831cf2057bf4703a1218d1 +0 -0
  262. data/spec/dummy/tmp/cache/assets/test/sprockets/0f196a1a50363b0a076ec6e1ee5417f6 +0 -0
  263. data/spec/dummy/tmp/cache/assets/test/sprockets/a3fb9025f90ff05a6fd4afc7ded2692c +0 -0
  264. data/spec/dummy/tmp/cache/assets/test/sprockets/a41c8be5379abec3c0d0d98e2f0d5609 +0 -0
  265. data/spec/dummy/tmp/cache/assets/test/sprockets/c69ee3cc5796188d873574179290a6ef +0 -0
  266. data/spec/dummy/tmp/cache/assets/test/sprockets/e1f674c11941d62aac1764ef3a7134e4 +0 -0
  267. data/spec/dummy/tmp/cache/assets/test/sprockets/e85565206c3e5fdf9dfeb367c85557b1 +0 -0
  268. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/-gXoYfEJ-e9QQUbNRpNa-pwMCnTc7Eqvkq6Bosde6W8.cache +0 -0
  269. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/6iNAIrMKxHltOChiHQQf9VNsLQuj2rVKz6oqWnK7aSM.cache +0 -1
  270. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/E1zaNOh68xzPxdtdOwRtOaMCoKivN2dxVwCP65WEi5I.cache +0 -2
  271. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/HsNbq1o4RbrEWNL4zXVqFfUVnXXLK_y0F0BvddDre6g.cache +0 -0
  272. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/JusxTSXt06IqBm9jeCMM2nTmM3Wvbl3i3L1IwEvW5YA.cache +0 -2
  273. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/L5DjABL_iOtoxSOLn3X7_YlxECU5EhnrVIKxJFAysgc.cache +0 -1
  274. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/PNc9TJUmRdGTSwgZvGlxKaIiJIkyoWtTPiGGWBqpHAE.cache +0 -0
  275. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/QkgTHa6nNs7XP6RPoV3yBbWWV-uo1u2-qxLuvLCFe_0.cache +0 -0
  276. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/S-6Iq5YOEpVnd_vQ0RSSfrmyIwB1dk0op35alFgJ9xA.cache +0 -2
  277. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/Vuc93A9yywiFxc9CAdxrzdsAQw4jxiCa6JRzRjNxOYs.cache +0 -1
  278. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/YAPBll4U0cgs6cz-WyMRKoakK_gVOOcl9n0CvGyxPjY.cache +0 -1
  279. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/bDNeZfPBQaef5z0YajZc4jFE54nNy9gc06mPNKvvPFk.cache +0 -1
  280. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/c5Wa2loowFYFRBaMoTn1IWYXo4BGMbEy7NIi0vbvfRU.cache +0 -1
  281. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/dkn8MYu2ve_AJW6u0jjTlKrj1KBRqorOHQR0Obx2elU.cache +0 -0
  282. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/fZuAzt_-48u9C7ZXmsPgTraGDYtNC9B9zN-9-EnxJG4.cache +0 -1
  283. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/gumo32Bd3W_q7MYEt9JIZEiQdHF93tLSsGfmXIm2MqU.cache +0 -1
  284. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/ige85jXyj8X7XYr7HpA0gSTThqfPUm71HjhSJXtTbUY.cache +0 -1
  285. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/kuYeE5bV6FdXmfB_o-xhflhSDWoQhYYaaupAXODZ9dQ.cache +0 -1
  286. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/qhZbbNIRUaAOtGano94zLHjeBKUhKr4qbh2tTCi0Bnk.cache +0 -2
  287. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/wJJbzdHJHP6tchng3HhfTwmjc5LursgX8yZkAjpO5UA.cache +0 -0
  288. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/xNL1WW-qU3EvV2iTSW6F4hAFRBsCYmFKJhLjgCZkOV8.cache +0 -2
  289. data/spec/dummy/tmp/cache/assets/test/sprockets/v3.0/ytHkF2DwUE6oaiLyrK6tL-0INpeNhjN6ctD7J0LNY6I.cache +0 -2
  290. data/spec/helpers/commontator/application_helper_spec.rb +0 -10
  291. data/spec/helpers/commontator/application_helper_spec.rb~ +0 -9
  292. data/spec/lib/commontator/acts_as_commontable_spec.rb +0 -25
  293. data/spec/lib/commontator/acts_as_commontable_spec.rb~ +0 -25
  294. data/spec/lib/commontator/acts_as_commontator_spec.rb +0 -26
  295. data/spec/lib/commontator/acts_as_commontator_spec.rb~ +0 -52
  296. data/spec/lib/commontator/commontable_config_spec.rb +0 -28
  297. data/spec/lib/commontator/commontable_config_spec.rb~ +0 -29
  298. data/spec/lib/commontator/commontator_config_spec.rb +0 -28
  299. data/spec/lib/commontator/commontator_config_spec.rb~ +0 -29
  300. data/spec/lib/commontator/controller_includes_spec.rb~ +0 -18
  301. data/spec/lib/commontator/controllers_spec.rb +0 -18
  302. data/spec/lib/commontator/controllers_spec.rb~ +0 -18
  303. data/spec/lib/commontator/shared_helper_spec.rb +0 -21
  304. data/spec/lib/commontator/shared_helper_spec.rb~ +0 -22
  305. data/spec/lib/commontator_spec.rb +0 -25
  306. data/spec/lib/commontator_spec.rb~ +0 -26
  307. data/spec/mailers/commontator/subscriptions_mailer_spec.rb +0 -49
  308. data/spec/mailers/commontator/subscriptions_mailer_spec.rb~ +0 -30
  309. data/spec/models/commontator/comment_spec.rb +0 -82
  310. data/spec/models/commontator/comment_spec.rb~ +0 -82
  311. data/spec/models/commontator/subscription_spec.rb +0 -38
  312. data/spec/models/commontator/subscription_spec.rb~ +0 -38
  313. data/spec/models/commontator/thread_spec.rb +0 -159
  314. data/spec/models/commontator/thread_spec.rb~ +0 -122
  315. data/spec/rails_helper.rb +0 -72
  316. data/spec/rails_helper.rb~ +0 -74
  317. data/spec/spec_helper.rb +0 -94
  318. data/spec/spec_helper.rb~ +0 -93
  319. data/vendor/assets/javascripts/mentionsInput/index.js~ +0 -3
@@ -1,7 +1,5 @@
1
- module Commontator
2
- module ApplicationHelper
3
- def javascript_proc
4
- Commontator.javascript_proc.call(self).html_safe
5
- end
1
+ module Commontator::ApplicationHelper
2
+ def javascript_proc
3
+ Commontator.javascript_proc.call(self).html_safe
6
4
  end
7
5
  end
@@ -0,0 +1,25 @@
1
+ require 'will_paginate'
2
+
3
+ class Commontator::LinkRenderer < WillPaginate::ActionView::LinkRenderer
4
+ protected
5
+
6
+ def url(page)
7
+ @base_url_params ||= begin
8
+ url_params = merge_get_params(default_url_params)
9
+ merge_optional_params(url_params)
10
+ end
11
+
12
+ url_params = @base_url_params.dup
13
+ add_current_page_param(url_params, page)
14
+
15
+ routes_proxy = @options[:routes_proxy] || @template
16
+ routes_proxy.url_for(url_params)
17
+ end
18
+
19
+ private
20
+
21
+ def link(text, target, attributes = {})
22
+ attributes = attributes.merge('data-remote' => true) if @options[:remote]
23
+ super
24
+ end
25
+ end
@@ -1,49 +1,49 @@
1
- module Commontator
2
- class SubscriptionsMailer < ActionMailer::Base
3
- def comment_created(comment, recipients)
4
- setup_variables(comment, recipients)
1
+ class Commontator::SubscriptionsMailer < ActionMailer::Base
2
+ helper Commontator::SharedHelper
5
3
 
6
- mail(@mail_params).tap do |message|
7
- message.mailgun_recipient_variables = @mailgun_recipient_variables if @using_mailgun
8
- end
4
+ def comment_created(comment, recipients)
5
+ setup_variables(comment, recipients)
6
+
7
+ mail(@mail_params).tap do |message|
8
+ message.mailgun_recipient_variables = @mailgun_recipient_variables if @using_mailgun
9
9
  end
10
+ end
10
11
 
11
- protected
12
+ protected
12
13
 
13
- def setup_variables(comment, recipients)
14
- @comment = comment
15
- @thread = @comment.thread
16
- @creator = @comment.creator
14
+ def setup_variables(comment, recipients)
15
+ @comment = comment
16
+ @thread = @comment.thread
17
+ @creator = @comment.creator
17
18
 
18
- @mail_params = { from: @thread.config.email_from_proc.call(@thread) }
19
+ @mail_params = { from: @thread.config.email_from_proc.call(@thread) }
19
20
 
20
- @recipient_emails = recipients.map do |recipient|
21
- Commontator.commontator_email(recipient, self)
22
- end
21
+ @recipient_emails = recipients.map do |recipient|
22
+ Commontator.commontator_email(recipient, self)
23
+ end
23
24
 
24
- @using_mailgun = Rails.application.config.action_mailer.delivery_method == :mailgun
25
+ @using_mailgun = Rails.application.config.action_mailer.delivery_method == :mailgun
25
26
 
26
- if @using_mailgun
27
- @recipients_header = :to
28
- @mailgun_recipient_variables = {}.tap do |mailgun_recipient_variables|
29
- @recipient_emails.each { |email| mailgun_recipient_variables[email] = {} }
30
- end
31
- else
32
- @recipients_header = :bcc
27
+ if @using_mailgun
28
+ @recipients_header = :to
29
+ @mailgun_recipient_variables = {}.tap do |mailgun_recipient_variables|
30
+ @recipient_emails.each { |email| mailgun_recipient_variables[email] = {} }
33
31
  end
32
+ else
33
+ @recipients_header = :bcc
34
+ end
34
35
 
35
- @mail_params[@recipients_header] = @recipient_emails
36
+ @mail_params[@recipients_header] = @recipient_emails
36
37
 
37
- @creator_name = Commontator.commontator_name(@creator)
38
- @commontable_name = Commontator.commontable_name(@thread)
39
- @comment_url = Commontator.comment_url(@comment, main_app)
38
+ @creator_name = Commontator.commontator_name(@creator)
39
+ @commontable_name = Commontator.commontable_name(@thread)
40
+ @comment_url = Commontator.comment_url(@comment, main_app)
40
41
 
41
- @mail_params[:subject] = t(
42
- 'commontator.email.comment_created.subject',
43
- creator_name: @creator_name,
44
- commontable_name: @commontable_name,
45
- comment_url: @comment_url
46
- )
47
- end
42
+ @mail_params[:subject] = t(
43
+ 'commontator.email.comment_created.subject',
44
+ creator_name: @creator_name,
45
+ commontable_name: @commontable_name,
46
+ comment_url: @comment_url
47
+ )
48
48
  end
49
49
  end
@@ -1,116 +1,233 @@
1
- module Commontator
2
- class Comment < ActiveRecord::Base
3
- belongs_to :creator, polymorphic: true
4
- belongs_to :editor, polymorphic: true, optional: true
5
- belongs_to :thread
1
+ class Commontator::Comment < ActiveRecord::Base
2
+ belongs_to :creator, polymorphic: true
3
+ belongs_to :editor, polymorphic: true, optional: true
4
+ belongs_to :thread, inverse_of: :comments
5
+ belongs_to :parent, optional: true, class_name: name, inverse_of: :children
6
+
7
+ has_many :children, class_name: name, inverse_of: :parent
8
+
9
+ serialize :ancestor_ids, Commontator::JsonArrayCoder
10
+ serialize :descendant_ids, Commontator::JsonArrayCoder
11
+
12
+ validates :editor, presence: true, on: :update
13
+ validates :body, presence: true, uniqueness: {
14
+ scope: [ :creator_type, :creator_id, :thread_id, :deleted_at ],
15
+ message: I18n.t('commontator.comment.errors.double_posted')
16
+ }
17
+ validate :parent_is_not_self, :parent_belongs_to_the_same_thread, if: :parent
18
+
19
+ before_save :set_ancestor_ids_and_ancestor_descendant_ids
20
+ before_destroy :remove_ancestor_descendant_ids
21
+
22
+ cattr_accessor :will_paginate
23
+ self.will_paginate = begin
24
+ require 'will_paginate'
25
+
26
+ true
27
+ rescue LoadError
28
+ false
29
+ end
6
30
 
7
- validates_presence_of :creator, on: :create
8
- validates_presence_of :editor, on: :update
9
- validates_presence_of :thread
10
- validates_presence_of :body
31
+ cattr_accessor :is_votable
32
+ self.is_votable = begin
33
+ require 'acts_as_votable'
34
+ acts_as_votable
11
35
 
12
- validates_uniqueness_of :body,
13
- scope: [:creator_type, :creator_id, :thread_id, :deleted_at],
14
- message: I18n.t('commontator.comment.errors.double_posted')
36
+ true
37
+ rescue LoadError
38
+ false
39
+ end
15
40
 
16
- protected
41
+ def self.will_paginate?
42
+ will_paginate
43
+ end
17
44
 
18
- cattr_accessor :acts_as_votable_initialized
45
+ def self.is_votable?
46
+ is_votable
47
+ end
19
48
 
20
- public
49
+ def is_modified?
50
+ !editor.nil?
51
+ end
21
52
 
22
- def is_modified?
23
- !editor.nil?
24
- end
53
+ def is_latest?
54
+ thread.comments.last == self
55
+ end
25
56
 
26
- def is_latest?
27
- thread.comments.last == self
28
- end
57
+ def get_vote_by(user)
58
+ return nil unless self.class.is_votable? && !user.nil? && user.is_commontator
29
59
 
30
- def is_votable?
31
- return true if acts_as_votable_initialized
32
- return false unless self.class.respond_to?(:acts_as_votable)
33
- self.class.acts_as_votable
34
- self.class.acts_as_votable_initialized = true
35
- end
60
+ votes_for.find_by(voter_type: user.class.name, voter_id: user.id)
61
+ end
36
62
 
37
- def get_vote_by(user)
38
- return nil unless is_votable? && !user.nil? && user.is_commontator
39
- votes_for.where(voter_type: user.class.name, voter_id: user.id).first
40
- end
63
+ def update_cached_votes(vote_scope = nil)
64
+ self.update_column(:cached_votes_up, count_votes_up(true))
65
+ self.update_column(:cached_votes_down, count_votes_down(true))
66
+ end
41
67
 
42
- def update_cached_votes(vote_scope = nil)
43
- self.update_column(:cached_votes_up, count_votes_up(true))
44
- self.update_column(:cached_votes_down, count_votes_down(true))
45
- end
68
+ def is_deleted?
69
+ !deleted_at.nil?
70
+ end
46
71
 
47
- def is_deleted?
48
- !deleted_at.blank?
49
- end
72
+ def delete_by(user)
73
+ return false if is_deleted?
50
74
 
51
- def delete_by(user)
52
- return false if is_deleted?
53
- self.deleted_at = Time.now
54
- self.editor = user
55
- self.save
56
- end
75
+ self.deleted_at = Time.now
76
+ self.editor = user
77
+ self.save
78
+ end
57
79
 
58
- def undelete_by(user)
59
- return false unless is_deleted?
60
- self.deleted_at = nil
61
- self.editor = user
62
- self.save
63
- end
80
+ def undelete_by(user)
81
+ return false unless is_deleted?
64
82
 
65
- def created_timestamp
66
- I18n.t 'commontator.comment.status.created_at',
67
- created_at: I18n.l(created_at, format: :commontator)
68
- end
83
+ self.deleted_at = nil
84
+ self.editor = user
85
+ self.save
86
+ end
69
87
 
70
- def updated_timestamp
71
- I18n.t 'commontator.comment.status.updated_at',
72
- editor_name: Commontator.commontator_name(editor || creator),
73
- updated_at: I18n.l(updated_at, format: :commontator)
74
- end
88
+ def created_timestamp
89
+ I18n.t 'commontator.comment.status.created_at',
90
+ created_at: I18n.l(created_at, format: :commontator)
91
+ end
75
92
 
76
- ##################
77
- # Access Control #
78
- ##################
93
+ def updated_timestamp
94
+ I18n.t 'commontator.comment.status.updated_at',
95
+ editor_name: Commontator.commontator_name(editor || creator),
96
+ updated_at: I18n.l(updated_at, format: :commontator)
97
+ end
79
98
 
80
- def can_be_created_by?(user)
81
- user == creator && !user.nil? && user.is_commontator &&\
82
- !thread.is_closed? && thread.can_be_read_by?(user)
83
- end
99
+ ##################
100
+ # Access Control #
101
+ ##################
84
102
 
85
- def can_be_edited_by?(user)
86
- return true if thread.can_be_edited_by?(user) &&\
87
- thread.config.moderator_permissions.to_sym == :e
88
- comment_edit = thread.config.comment_editing.to_sym
89
- !thread.is_closed? && !is_deleted? && user == creator &&\
90
- comment_edit != :n && (is_latest? || comment_edit == :a) &&\
91
- thread.can_be_read_by?(user)
92
- end
103
+ def can_be_created_by?(user)
104
+ user == creator && !user.nil? && user.is_commontator &&
105
+ !thread.is_closed? && thread.can_be_read_by?(user)
106
+ end
93
107
 
94
- def can_be_deleted_by?(user)
95
- mod_perm = thread.config.moderator_permissions.to_sym
96
- return true if thread.can_be_edited_by?(user) &&\
97
- (mod_perm == :e ||\
98
- mod_perm == :d)
99
- comment_del = thread.config.comment_deletion.to_sym
100
- !thread.is_closed? && (!is_deleted? || editor == user) &&\
101
- user == creator && comment_del != :n &&\
102
- (is_latest? || comment_del == :a) &&\
103
- thread.can_be_read_by?(user)
104
- end
108
+ def can_be_edited_by?(user)
109
+ return true if thread.can_be_edited_by?(user) &&
110
+ thread.config.moderator_permissions.to_sym == :e
111
+
112
+ comment_edit = thread.config.comment_editing.to_sym
113
+ !thread.is_closed? && !is_deleted? && user == creator && (editor.nil? || user == editor) &&
114
+ comment_edit != :n && (is_latest? || comment_edit == :a) && thread.can_be_read_by?(user)
115
+ end
116
+
117
+ def can_be_deleted_by?(user)
118
+ mod_perm = thread.config.moderator_permissions.to_sym
119
+ return true if thread.can_be_edited_by?(user) && (mod_perm == :e || mod_perm == :d)
120
+
121
+ comment_del = thread.config.comment_deletion.to_sym
122
+ !thread.is_closed? && user == creator && (!is_deleted? || editor == user) &&
123
+ comment_del != :n && (is_latest? || comment_del == :a) && thread.can_be_read_by?(user)
124
+ end
125
+
126
+ def can_be_voted_on?
127
+ !thread.is_closed? && !is_deleted? &&
128
+ thread.config.comment_voting.to_sym != :n && self.class.is_votable?
129
+ end
130
+
131
+ def can_be_voted_on_by?(user)
132
+ !user.nil? && user.is_commontator && user != creator &&
133
+ thread.can_be_read_by?(user) && can_be_voted_on?
134
+ end
135
+
136
+ protected
137
+
138
+ def parent_is_not_self
139
+ return if parent != self
140
+ errors.add :parent, 'must be a different comment'
141
+ throw :abort
142
+ end
143
+
144
+ def parent_belongs_to_the_same_thread
145
+ return if parent.thread_id == thread_id
146
+ errors.add :parent, 'must belong to the same thread'
147
+ throw :abort
148
+ end
149
+
150
+ def remove_ancestor_descendant_ids
151
+ return if ancestor_ids.empty?
152
+
153
+ # Remove id and descendant_ids from ancestors
154
+ self.class.where(id: ancestor_ids).order(:id).update_all("descendant_ids = #{
155
+ ([ id ] + descendant_ids).reduce(self.class.arel_table[:descendant_ids]) do |memo, descendant_id|
156
+ Arel::Nodes::NamedFunction.new('REPLACE', [
157
+ Arel::Nodes::NamedFunction.new('REPLACE', [
158
+ Arel::Nodes::NamedFunction.new('REPLACE', [
159
+ Arel::Nodes::NamedFunction.new('REPLACE', [
160
+ memo, Arel::Nodes.build_quoted("[#{descendant_id}]"), Arel::Nodes.build_quoted('[]')
161
+ ]), Arel::Nodes.build_quoted("[#{descendant_id},"), Arel::Nodes.build_quoted('[')
162
+ ]), Arel::Nodes.build_quoted(",#{descendant_id},"), Arel::Nodes.build_quoted(',')
163
+ ]), Arel::Nodes.build_quoted(",#{descendant_id}]"), Arel::Nodes.build_quoted(']')
164
+ ])
165
+ end.to_sql
166
+ }")
167
+
168
+ association(:parent).reset
169
+ end
105
170
 
106
- def can_be_voted_on?
107
- !thread.is_closed? && !is_deleted? &&\
108
- thread.config.comment_voting.to_sym != :n && is_votable?
171
+ def set_ancestor_ids_and_ancestor_descendant_ids
172
+ return if ancestor_ids.first == parent_id
173
+
174
+ pa = parent
175
+
176
+ remove_ancestor_descendant_ids
177
+
178
+ # Remove ancestor_ids from descendants
179
+ unless ancestor_ids.empty? || descendant_ids.empty?
180
+ self.class.where(id: descendant_ids).order(:id).update_all("ancestor_ids = #{
181
+ ancestor_ids.reduce(self.class.arel_table[:ancestor_ids]) do |memo, ancestor_id|
182
+ Arel::Nodes::NamedFunction.new('REPLACE', [
183
+ Arel::Nodes::NamedFunction.new('REPLACE', [
184
+ Arel::Nodes::NamedFunction.new('REPLACE', [
185
+ Arel::Nodes::NamedFunction.new('REPLACE', [
186
+ memo, Arel::Nodes.build_quoted("[#{ancestor_id}]"), Arel::Nodes.build_quoted('[]')
187
+ ]), Arel::Nodes.build_quoted("[#{ancestor_id},"), Arel::Nodes.build_quoted('[')
188
+ ]), Arel::Nodes.build_quoted(",#{ancestor_id},"), Arel::Nodes.build_quoted(',')
189
+ ]), Arel::Nodes.build_quoted(",#{ancestor_id}]"), Arel::Nodes.build_quoted(']')
190
+ ])
191
+ end.to_sql
192
+ }")
193
+
194
+ children.reset
109
195
  end
110
196
 
111
- def can_be_voted_on_by?(user)
112
- !user.nil? && user.is_commontator && user != creator &&\
113
- thread.can_be_read_by?(user) && can_be_voted_on?
197
+ if pa.nil?
198
+ self.ancestor_ids = []
199
+ else
200
+ self.ancestor_ids = [ pa.id ] + pa.ancestor_ids
201
+
202
+ # Add id and descendant_ids to ancestors
203
+ descendant_ids_str = ([ id ] + descendant_ids).to_json[1..-2]
204
+ self.class.where(id: ancestor_ids).order(:id).update_all("descendant_ids = #{
205
+ Arel::Nodes::NamedFunction.new('REPLACE', [
206
+ Arel::Nodes::NamedFunction.new('REPLACE', [
207
+ Arel::Nodes::NamedFunction.new('COALESCE', [
208
+ self.class.arel_table[:descendant_ids], Arel::Nodes.build_quoted('[]')
209
+ ]), Arel::Nodes.build_quoted(']'), Arel::Nodes.build_quoted(",#{descendant_ids_str}]")
210
+ ]), Arel::Nodes.build_quoted('[,'), Arel::Nodes.build_quoted('[')
211
+ ]).to_sql
212
+ }")
213
+
214
+ association(:parent).reset
215
+
216
+ # Add ancestor_ids to descendants
217
+ unless descendant_ids.empty?
218
+ ancestor_ids_str = ancestor_ids.to_json[1..-2]
219
+ self.class.where(id: descendant_ids).order(:id).update_all("ancestor_ids = #{
220
+ Arel::Nodes::NamedFunction.new('REPLACE', [
221
+ Arel::Nodes::NamedFunction.new('REPLACE', [
222
+ Arel::Nodes::NamedFunction.new('COALESCE', [
223
+ self.class.arel_table[:ancestor_ids], Arel::Nodes.build_quoted('[]')
224
+ ]), Arel::Nodes.build_quoted(']'), Arel::Nodes.build_quoted(",#{ancestor_ids_str}]")
225
+ ]), Arel::Nodes.build_quoted('[,'), Arel::Nodes.build_quoted('[')
226
+ ]).to_sql
227
+ }")
228
+
229
+ children.reset
230
+ end
114
231
  end
115
232
  end
116
233
  end
@@ -0,0 +1,10 @@
1
+ module Commontator::JsonArrayCoder
2
+ def self.load(data)
3
+ obj = JSON.load(data)
4
+ obj.is_a?(Array) ? obj : []
5
+ end
6
+
7
+ def self.dump(obj)
8
+ obj.is_a?(Array) ? JSON.dump(obj) : '[]'
9
+ end
10
+ end