decidim 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim might be problematic. Click here for more details.

Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.json +2 -5
  3. data/.mention-bot +2 -1
  4. data/.yardopts +8 -0
  5. data/Gemfile.lock +64 -62
  6. data/README.md +11 -9
  7. data/decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6 +3 -3
  8. data/decidim-admin/app/assets/stylesheets/decidim/admin/_email_preview.scss +5 -0
  9. data/decidim-admin/app/assets/stylesheets/decidim/admin/application.scss +1 -0
  10. data/decidim-admin/app/commands/decidim/admin/create_newsletter.rb +30 -0
  11. data/decidim-admin/app/commands/decidim/admin/deliver_newsletter.rb +29 -0
  12. data/decidim-admin/app/commands/decidim/admin/destroy_participatory_process_step.rb +9 -0
  13. data/decidim-admin/app/commands/decidim/admin/update_newsletter.rb +33 -0
  14. data/decidim-admin/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
  15. data/decidim-admin/app/controllers/decidim/admin/features_controller.rb +2 -2
  16. data/decidim-admin/app/controllers/decidim/admin/newsletters_controller.rb +115 -0
  17. data/decidim-admin/app/controllers/decidim/admin/participatory_processes_controller.rb +4 -4
  18. data/decidim-admin/app/forms/decidim/admin/newsletter_form.rb +15 -0
  19. data/decidim-admin/app/jobs/decidim/admin/newsletter_delivery_job.rb +18 -0
  20. data/decidim-admin/app/jobs/decidim/admin/newsletter_job.rb +32 -0
  21. data/decidim-admin/app/models/decidim/admin/abilities/admin_user.rb +4 -0
  22. data/decidim-admin/app/models/decidim/admin/abilities/base.rb +4 -0
  23. data/decidim-admin/app/models/decidim/admin/abilities/collaborator_user.rb +19 -0
  24. data/decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb +1 -1
  25. data/decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb +1 -1
  26. data/decidim-admin/app/views/decidim/admin/newsletters/_form.html.erb +5 -0
  27. data/decidim-admin/app/views/decidim/admin/newsletters/edit.html.erb +11 -0
  28. data/decidim-admin/app/views/decidim/admin/newsletters/index.html.erb +47 -0
  29. data/decidim-admin/app/views/decidim/admin/newsletters/new.html.erb +11 -0
  30. data/decidim-admin/app/views/decidim/admin/newsletters/show.html.erb +14 -0
  31. data/decidim-admin/app/views/decidim/admin/participatory_process_steps/_form.html.erb +1 -1
  32. data/decidim-admin/app/views/decidim/admin/participatory_processes/_form.html.erb +1 -1
  33. data/decidim-admin/app/views/decidim/admin/static_pages/_form.html.erb +1 -1
  34. data/decidim-admin/app/views/layouts/decidim/admin/_sidebar.html.erb +1 -0
  35. data/decidim-admin/config/locales/ca.yml +40 -0
  36. data/decidim-admin/config/locales/en.yml +40 -0
  37. data/decidim-admin/config/locales/es.yml +40 -0
  38. data/decidim-admin/config/routes.rb +7 -0
  39. data/decidim-admin/decidim-admin.gemspec +0 -1
  40. data/decidim-admin/lib/decidim/admin/engine.rb +1 -0
  41. data/decidim-admin/lib/decidim/admin/features/base_controller.rb +5 -1
  42. data/decidim-admin/spec/commands/create_newsletter_spec.rb +62 -0
  43. data/decidim-admin/spec/commands/deliver_newsletter_spec.rb +45 -0
  44. data/decidim-admin/spec/commands/destroy_participatory_process_step_spec.rb +12 -0
  45. data/decidim-admin/spec/commands/update_newsletter_spec.rb +64 -0
  46. data/decidim-admin/spec/features/admin_manages_newsletters_spec.rb +147 -0
  47. data/decidim-admin/spec/features/admin_manages_participatory_processes_spec.rb +1 -5
  48. data/decidim-admin/spec/features/static_pages_spec.rb +16 -0
  49. data/decidim-admin/spec/forms/newsletter_form_spec.rb +47 -0
  50. data/decidim-admin/spec/jobs/newsletter_delivery_job_spec.rb +25 -0
  51. data/decidim-admin/spec/jobs/newsletter_job_spec.rb +29 -0
  52. data/decidim-admin/spec/models/abilities/collaborator_user_spec.rb +66 -0
  53. data/decidim-admin/spec/organization_dashboard_constraint_spec.rb +55 -0
  54. data/decidim-admin/spec/queries/manageable_participatory_processes_for_user_spec.rb +8 -0
  55. data/decidim-admin/spec/shared/manage_processes_examples.rb +1 -5
  56. data/decidim-api/lib/decidim/api.rb +2 -7
  57. data/decidim-api/lib/decidim/api/{types/mutation.rb → mutation_type.rb} +0 -0
  58. data/decidim-api/lib/decidim/api/{types/query.rb → query_type.rb} +0 -0
  59. data/decidim-budgets/app/assets/javascripts/decidim/budgets/projects.js.es6 +4 -4
  60. data/decidim-budgets/app/commands/decidim/budgets/add_line_item.rb +4 -2
  61. data/decidim-budgets/app/commands/decidim/budgets/checkout.rb +7 -3
  62. data/decidim-budgets/app/models/decidim/budgets/order.rb +16 -1
  63. data/decidim-budgets/app/models/decidim/budgets/project.rb +16 -0
  64. data/decidim-budgets/app/views/decidim/budgets/line_items/update_budget.js.erb +7 -7
  65. data/decidim-budgets/app/views/decidim/budgets/projects/_budget_confirm.html.erb +27 -25
  66. data/decidim-budgets/app/views/decidim/budgets/projects/_budget_summary.html.erb +4 -13
  67. data/decidim-budgets/app/views/decidim/budgets/projects/_order_progress.html.erb +23 -21
  68. data/decidim-budgets/app/views/decidim/budgets/projects/_order_selected_projects.html.erb +25 -23
  69. data/decidim-budgets/app/views/decidim/budgets/projects/_order_total_budget.html.erb +3 -1
  70. data/decidim-budgets/app/views/decidim/budgets/projects/_project.html.erb +32 -30
  71. data/decidim-budgets/app/views/decidim/budgets/projects/_projects.html.erb +1 -3
  72. data/decidim-budgets/app/views/decidim/budgets/projects/index.html.erb +0 -4
  73. data/decidim-budgets/app/views/decidim/budgets/projects/show.html.erb +5 -6
  74. data/decidim-budgets/config/i18n-tasks.yml +1 -0
  75. data/decidim-budgets/config/locales/ca.yml +7 -2
  76. data/decidim-budgets/config/locales/en.yml +17 -6
  77. data/decidim-budgets/config/locales/es.yml +7 -2
  78. data/decidim-budgets/lib/decidim/budgets/feature.rb +2 -2
  79. data/decidim-budgets/spec/commands/add_line_item_spec.rb +16 -3
  80. data/decidim-budgets/spec/commands/cancel_order_spec.rb +7 -1
  81. data/decidim-budgets/spec/commands/checkout_spec.rb +9 -2
  82. data/decidim-budgets/spec/commands/remove_line_item_spec.rb +16 -5
  83. data/decidim-budgets/spec/features/orders_spec.rb +8 -2
  84. data/decidim-budgets/spec/models/order_spec.rb +31 -2
  85. data/decidim-budgets/spec/shared/admin_shared_context.rb +1 -1
  86. data/decidim-comments/README.md +1 -1
  87. data/decidim-comments/app/assets/javascripts/decidim/comments/bundle.js +0 -0
  88. data/decidim-comments/app/frontend/comments/add_comment_form.component.jsx +156 -93
  89. data/decidim-comments/app/frontend/comments/add_comment_form.component.test.jsx +36 -23
  90. data/decidim-comments/app/frontend/comments/add_comment_form.mutation.graphql +5 -3
  91. data/decidim-comments/app/frontend/comments/add_comment_form_commentable.fragment.graphql +4 -0
  92. data/decidim-comments/app/frontend/comments/add_comment_form_session.fragment.graphql +6 -0
  93. data/decidim-comments/app/frontend/comments/comment.component.jsx +11 -13
  94. data/decidim-comments/app/frontend/comments/comment.component.test.jsx +22 -21
  95. data/decidim-comments/app/frontend/comments/comment.fragment.graphql +4 -4
  96. data/decidim-comments/app/frontend/comments/comment_data.fragment.graphql +4 -3
  97. data/decidim-comments/app/frontend/comments/comment_order_selector.component.jsx +1 -1
  98. data/decidim-comments/app/frontend/comments/comment_thread.component.jsx +3 -3
  99. data/decidim-comments/app/frontend/comments/comment_thread.component.test.jsx +3 -3
  100. data/decidim-comments/app/frontend/comments/comment_thread.fragment.graphql +1 -1
  101. data/decidim-comments/app/frontend/comments/comments.component.jsx +47 -39
  102. data/decidim-comments/app/frontend/comments/comments.component.test.jsx +51 -38
  103. data/decidim-comments/app/frontend/comments/comments.query.graphql +10 -4
  104. data/decidim-comments/app/frontend/comments/down_vote_button.component.jsx +6 -3
  105. data/decidim-comments/app/frontend/comments/up_vote_button.component.jsx +7 -4
  106. data/decidim-comments/app/frontend/support/generate_comments_data.js +4 -4
  107. data/decidim-comments/app/models/decidim/comments/comment.rb +7 -9
  108. data/decidim-comments/app/queries/decidim/comments/{comments_with_replies.rb → sorted_comments.rb} +3 -8
  109. data/decidim-comments/app/types/decidim/comments/commentable_interface.rb +44 -0
  110. data/decidim-comments/app/types/decidim/comments/commentable_mutation_type.rb +29 -0
  111. data/decidim-comments/app/types/decidim/comments/commentable_type.rb +14 -0
  112. data/decidim-comments/config/locales/ca.yml +3 -1
  113. data/decidim-comments/config/locales/en.yml +5 -2
  114. data/decidim-comments/config/locales/es.yml +3 -1
  115. data/decidim-comments/lib/decidim/comments.rb +4 -0
  116. data/decidim-comments/{app/types/decidim/comments → lib/decidim/comments/api}/add_comment_type.rb +0 -0
  117. data/decidim-comments/{app/types/decidim/comments → lib/decidim/comments/api}/comment_mutation_type.rb +0 -0
  118. data/decidim-comments/{app/types/decidim/comments → lib/decidim/comments/api}/comment_type.rb +11 -17
  119. data/decidim-comments/lib/decidim/comments/commentable.rb +45 -0
  120. data/decidim-comments/lib/decidim/comments/comments_helper.rb +15 -10
  121. data/decidim-comments/lib/decidim/comments/mutation_extensions.rb +8 -16
  122. data/decidim-comments/lib/decidim/comments/query_extensions.rb +5 -8
  123. data/decidim-comments/lib/decidim/comments/test/factories.rb +3 -3
  124. data/decidim-comments/spec/commands/vote_comment_spec.rb +3 -1
  125. data/decidim-comments/spec/features/comments_spec.rb +28 -14
  126. data/decidim-comments/spec/features/notifications_spec.rb +1 -1
  127. data/decidim-comments/spec/helpers/comments_helper_spec.rb +4 -27
  128. data/decidim-comments/spec/models/comment_spec.rb +7 -11
  129. data/decidim-comments/spec/models/comment_vote_spec.rb +3 -1
  130. data/decidim-comments/spec/models/seed_spec.rb +3 -4
  131. data/decidim-comments/spec/queries/{comments_with_replies_spec.rb → sorted_comments_spec.rb} +12 -29
  132. data/decidim-comments/spec/types/comment_type_spec.rb +23 -17
  133. data/decidim-comments/spec/types/commentable_mutation_type_spec.rb +34 -0
  134. data/decidim-comments/spec/types/commentable_type_spec.rb +48 -0
  135. data/decidim-comments/spec/types/mutation_type_spec.rb +5 -22
  136. data/decidim-comments/spec/types/query_type_spec.rb +0 -24
  137. data/decidim-dev/config/i18n-tasks.yml +4 -0
  138. data/decidim-dev/decidim-dev.gemspec +1 -1
  139. data/decidim-dev/lib/decidim/dev/test/rspec_support/action_mailer.rb +10 -4
  140. data/decidim-dev/lib/decidim/dev/test/rspec_support/feature.rb +6 -5
  141. data/decidim-dev/lib/decidim/dev/test/rspec_support/i18n.rb +0 -1
  142. data/decidim-meetings/app/assets/javascripts/decidim/meetings/map.js.es6.erb +8 -3
  143. data/decidim-meetings/app/assets/stylesheets/decidim/meetings/map.css +3 -1
  144. data/decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb +2 -2
  145. data/decidim-meetings/app/forms/decidim/meetings/admin/close_meeting_form.rb +2 -1
  146. data/decidim-meetings/app/helpers/decidim/meetings/map_helper.rb +1 -0
  147. data/decidim-meetings/app/services/decidim/meetings/meeting_search.rb +7 -3
  148. data/decidim-meetings/app/views/decidim/meetings/meetings/_datetime.html.erb +1 -1
  149. data/decidim-meetings/app/views/decidim/meetings/meetings/_filters.html.erb +5 -5
  150. data/decidim-meetings/app/views/decidim/meetings/meetings/_linked_meetings.html.erb +1 -1
  151. data/decidim-meetings/app/views/decidim/meetings/meetings/index.html.erb +1 -5
  152. data/decidim-meetings/app/views/decidim/meetings/meetings/show.html.erb +16 -9
  153. data/decidim-meetings/config/locales/ca.yml +2 -3
  154. data/decidim-meetings/config/locales/en.yml +2 -3
  155. data/decidim-meetings/config/locales/es.yml +2 -3
  156. data/decidim-meetings/spec/features/explore_meetings_spec.rb +75 -24
  157. data/decidim-meetings/spec/forms/close_meeting_form_spec.rb +1 -1
  158. data/decidim-meetings/spec/services/meeting_search_spec.rb +15 -12
  159. data/decidim-meetings/vendor/assets/javascripts/leaflet.markercluster.js +7 -0
  160. data/decidim-meetings/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
  161. data/decidim-meetings/vendor/assets/stylesheets/MarkerCluster.css +14 -0
  162. data/decidim-pages/app/models/decidim/pages/page.rb +22 -0
  163. data/decidim-pages/app/views/decidim/pages/application/show.html.erb +2 -6
  164. data/decidim-pages/config/locales/ca.yml +2 -2
  165. data/decidim-pages/config/locales/en.yml +2 -2
  166. data/decidim-pages/config/locales/es.yml +2 -2
  167. data/decidim-pages/lib/decidim/pages/feature.rb +2 -2
  168. data/decidim-pages/spec/features/page_show_spec.rb +0 -33
  169. data/decidim-proposals/app/controllers/decidim/proposals/admin/proposal_answers_controller.rb +2 -0
  170. data/decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb +2 -0
  171. data/decidim-proposals/app/models/decidim/proposals/abilities/admin_user.rb +45 -0
  172. data/decidim-proposals/app/models/decidim/proposals/abilities/process_admin_user.rb +57 -0
  173. data/decidim-proposals/app/models/decidim/proposals/proposal.rb +21 -0
  174. data/decidim-proposals/app/views/decidim/proposals/admin/proposals/_form.html.erb +1 -1
  175. data/decidim-proposals/app/views/decidim/proposals/admin/proposals/index.html.erb +16 -10
  176. data/decidim-proposals/app/views/decidim/proposals/proposal_votes/update_buttons_and_counters.js.erb +4 -4
  177. data/decidim-proposals/app/views/decidim/proposals/proposals/_filters.html.erb +7 -3
  178. data/decidim-proposals/app/views/decidim/proposals/proposals/_proposal.html.erb +2 -6
  179. data/decidim-proposals/app/views/decidim/proposals/proposals/_remaining_votes_count.html.erb +3 -1
  180. data/decidim-proposals/app/views/decidim/proposals/proposals/_tags.html.erb +1 -1
  181. data/decidim-proposals/app/views/decidim/proposals/proposals/_vote_button.html.erb +23 -21
  182. data/decidim-proposals/app/views/decidim/proposals/proposals/_votes_count.html.erb +9 -6
  183. data/decidim-proposals/app/views/decidim/proposals/proposals/_votes_limit.html.erb +1 -3
  184. data/decidim-proposals/app/views/decidim/proposals/proposals/index.html.erb +0 -4
  185. data/decidim-proposals/app/views/decidim/proposals/proposals/new.html.erb +1 -1
  186. data/decidim-proposals/app/views/decidim/proposals/proposals/show.html.erb +2 -6
  187. data/decidim-proposals/config/locales/ca.yml +8 -1
  188. data/decidim-proposals/config/locales/en.yml +8 -1
  189. data/decidim-proposals/config/locales/es.yml +8 -1
  190. data/decidim-proposals/lib/decidim/proposals/admin_engine.rb +7 -0
  191. data/decidim-proposals/lib/decidim/proposals/feature.rb +6 -2
  192. data/decidim-proposals/spec/features/proposals_spec.rb +226 -40
  193. data/decidim-proposals/spec/models/decidim/proposals/abilities/admin_user_spec.rb +62 -0
  194. data/decidim-proposals/spec/models/decidim/proposals/abilities/process_admin_user_spec.rb +63 -0
  195. data/decidim-proposals/spec/shared/manage_proposals_examples.rb +161 -50
  196. data/decidim-results/app/models/decidim/results/result.rb +21 -0
  197. data/decidim-results/app/views/decidim/results/results/index.html.erb +0 -4
  198. data/decidim-results/app/views/decidim/results/results/show.html.erb +2 -8
  199. data/decidim-results/config/i18n-tasks.yml +1 -0
  200. data/decidim-results/config/locales/ca.yml +5 -2
  201. data/decidim-results/config/locales/en.yml +5 -2
  202. data/decidim-results/config/locales/es.yml +5 -2
  203. data/decidim-results/lib/decidim/results/feature.rb +2 -2
  204. data/decidim-results/spec/services/result_stats_calculator_spec.rb +2 -2
  205. data/decidim-results/spec/shared/admin_shared_context.rb +1 -1
  206. data/decidim-system/config/i18n-tasks.yml +1 -1
  207. data/package.json +50 -51
  208. data/yarn.lock +198 -151
  209. metadata +69 -36
  210. data/decidim-admin/spec/features/admin_access_control.rb +0 -52
  211. data/decidim-api/lib/decidim/api/types/author_interface.rb +0 -13
  212. data/decidim-api/lib/decidim/api/types/localized_string.rb +0 -13
  213. data/decidim-api/lib/decidim/api/types/translated_field.rb +0 -44
  214. data/decidim-api/spec/types/localized_string_type_spec.rb +0 -31
  215. data/decidim-api/spec/types/translated_field_type_spec.rb +0 -69
  216. data/decidim-comments/app/frontend/comments/add_comment_form.fragment.graphql +0 -6
@@ -11,17 +11,14 @@ module Decidim
11
11
  # Returns nothing.
12
12
  def self.extend!(type)
13
13
  type.define do
14
- field :comments do
15
- description "Lists all commentable's comments."
16
- type !types[CommentType]
14
+ field :commentable do
15
+ type !CommentableType
17
16
 
18
- argument :commentableId, !types.String, "The commentable's ID"
19
- argument :commentableType, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
20
- argument :orderBy, types.String, "Order the comments"
17
+ argument :id, !types.String, "The commentable's ID"
18
+ argument :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
21
19
 
22
20
  resolve lambda { |_obj, args, _ctx|
23
- commentable = args[:commentableType].constantize.find(args[:commentableId])
24
- CommentsWithReplies.for(commentable, order_by: args[:orderBy])
21
+ args[:type].constantize.find(args[:id])
25
22
  }
26
23
  end
27
24
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  FactoryGirl.define do
3
- factory :comment, class: Decidim::Comments::Comment do
3
+ factory :comment, class: "Decidim::Comments::Comment" do
4
4
  author { build(:user, organization: commentable.organization) }
5
- commentable { build(:participatory_process) }
5
+ commentable { build(:dummy_resource) }
6
6
  body { Faker::Lorem.paragraph }
7
7
  end
8
8
 
9
- factory :comment_vote, class: Decidim::Comments::CommentVote do
9
+ factory :comment_vote, class: "Decidim::Comments::CommentVote" do
10
10
  comment { build(:comment) }
11
11
  author { build(:user, organization: comment.organization) }
12
12
  weight { [-1, 1].sample }
@@ -7,8 +7,10 @@ module Decidim
7
7
  describe "call" do
8
8
  let(:organization) { create :organization }
9
9
  let(:participatory_process) { create(:participatory_process, organization: organization) }
10
+ let(:feature) { create(:feature, participatory_process: participatory_process) }
11
+ let(:commentable) { create(:dummy_resource, feature: feature) }
10
12
  let(:author) { create(:user, organization: organization) }
11
- let(:comment) { create(:comment, commentable: participatory_process) }
13
+ let(:comment) { create(:comment, commentable: commentable) }
12
14
  let(:command) { described_class.new(comment, author) }
13
15
 
14
16
  describe "when the vote is not created" do
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe "Comments", type: :feature do
5
5
  let!(:organization) { create(:organization) }
6
- let!(:feature) { create(:feature, organization: organization) }
6
+ let!(:feature) { create(:feature, manifest_name: :dummy, organization: organization) }
7
7
  let!(:user) { create(:user, :confirmed, organization: organization) }
8
8
  let!(:commentable) { create(:dummy_resource, feature: feature) }
9
9
  let!(:comments) {
@@ -11,17 +11,22 @@ describe "Comments", type: :feature do
11
11
  create(:comment, commentable: commentable)
12
12
  end
13
13
  }
14
+ let(:authenticated) { false }
14
15
 
15
- def visit_commentable_path(options = {})
16
- visit decidim_dummy.dummy_resource_path(commentable, feature_id: commentable.feature, participatory_process_id: commentable.feature.participatory_process, arguable: options[:arguable], votable: options[:votable])
16
+ def visit_commentable_path
17
+ if authenticated
18
+ login_as user, scope: :user
19
+ end
20
+ visit decidim_dummy.dummy_resource_path(commentable, feature_id: commentable.feature, participatory_process_id: commentable.feature.participatory_process)
17
21
  end
18
22
 
19
23
  before do
20
24
  switch_to_host(organization.host)
21
- visit_commentable_path
22
25
  end
23
26
 
24
27
  it "user should see a list of comments" do
28
+ visit_commentable_path
29
+
25
30
  expect(page).to have_selector("#comments")
26
31
  expect(page).to have_selector("article.comment", count: comments.length)
27
32
 
@@ -51,25 +56,27 @@ describe "Comments", type: :feature do
51
56
 
52
57
  context "when not authenticated" do
53
58
  it "user should not see the form to add comments" do
59
+ visit_commentable_path
54
60
  expect(page).not_to have_selector(".add-comment form")
55
61
  end
56
62
  end
57
63
 
58
64
  context "when authenticated" do
59
- before do
60
- login_as user, scope: :user
65
+ let(:authenticated) { true }
66
+
67
+ it "user sees the form to add comments" do
61
68
  visit_commentable_path
62
- end
63
69
 
64
- it "user should not see the form to add comments" do
65
70
  expect(page).to have_selector(".add-comment form")
66
71
  end
67
72
 
68
73
  it "user can add a new comment" do
74
+ visit_commentable_path
75
+
69
76
  expect(page).to have_selector(".add-comment form")
70
77
 
71
78
  within ".add-comment form" do
72
- fill_in "add-comment-#{commentable.class.name}-#{commentable.id}", with: "This is a new comment"
79
+ fill_in "add-comment-#{commentable.commentable_type}-#{commentable.id}", with: "This is a new comment"
73
80
  click_button "Send"
74
81
  end
75
82
 
@@ -84,14 +91,15 @@ describe "Comments", type: :feature do
84
91
 
85
92
  before do
86
93
  create(:user_group_membership, user: user, user_group: user_group)
87
- visit_commentable_path
88
94
  end
89
95
 
90
96
  it "user can add a new comment as a user group" do
97
+ visit_commentable_path
98
+
91
99
  expect(page).to have_selector(".add-comment form")
92
100
 
93
101
  within ".add-comment form" do
94
- fill_in "add-comment-#{commentable.class.name}-#{commentable.id}", with: "This is a new comment"
102
+ fill_in "add-comment-#{commentable.commentable_type}-#{commentable.id}", with: "This is a new comment"
95
103
  select user_group.name, from: "Comment as"
96
104
  click_button "Send"
97
105
  end
@@ -121,16 +129,18 @@ describe "Comments", type: :feature do
121
129
 
122
130
  context "when arguable option is enabled" do
123
131
  before do
124
- visit_commentable_path arguable: true
132
+ expect_any_instance_of(Decidim::DummyResource).to receive(:comments_have_alignment?).and_return(true)
125
133
  end
126
134
 
127
135
  it "user can comment in favor" do
136
+ visit_commentable_path
137
+
128
138
  expect(page).to have_selector(".add-comment form")
129
139
 
130
140
  page.find('.opinion-toggle--ok').click
131
141
 
132
142
  within ".add-comment form" do
133
- fill_in "add-comment-#{commentable.class.name}-#{commentable.id}", with: "I am in favor about this!"
143
+ fill_in "add-comment-#{commentable.commentable_type}-#{commentable.id}", with: "I am in favor about this!"
134
144
  click_button "Send"
135
145
  end
136
146
 
@@ -142,10 +152,12 @@ describe "Comments", type: :feature do
142
152
 
143
153
  context "when votable option is enabled" do
144
154
  before do
145
- visit_commentable_path votable: true
155
+ expect_any_instance_of(Decidim::DummyResource).to receive(:comments_have_votes?).and_return(true)
146
156
  end
147
157
 
148
158
  it "user can upvote a comment" do
159
+ visit_commentable_path
160
+
149
161
  within "#comment_#{comments[0].id}" do
150
162
  expect(page).to have_selector('.comment__votes--up', text: /0/)
151
163
  page.find('.comment__votes--up').click
@@ -154,6 +166,8 @@ describe "Comments", type: :feature do
154
166
  end
155
167
 
156
168
  it "user can downvote a comment" do
169
+ visit_commentable_path
170
+
157
171
  within "#comment_#{comments[0].id}" do
158
172
  expect(page).to have_selector('.comment__votes--down', text: /0/)
159
173
  page.find('.comment__votes--down').click
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  describe "Comment notifications", type: :feature do
5
5
  let!(:organization) { create(:organization) }
6
- let!(:feature) { create(:feature, organization: organization) }
6
+ let!(:feature) { create(:feature, manifest_name: :dummy, organization: organization) }
7
7
  let!(:user) { create(:user, :confirmed, organization: organization) }
8
8
  let!(:commentable) { create(:dummy_resource, feature: feature) }
9
9
  let!(:comments) {
@@ -4,43 +4,20 @@ require "spec_helper"
4
4
  module Decidim
5
5
  module Comments
6
6
  describe CommentsHelper do
7
- class DummyCommentable
8
- def id
9
- 1
10
- end
11
- end
7
+ let(:dummy_resource) { create(:dummy_resource) }
12
8
 
13
- let(:commentable) { DummyCommentable.new }
14
-
15
9
  describe "comments_for" do
16
10
  it "should render the react component `Comments` with the correct data" do
17
11
  expect(helper)
18
12
  .to receive(:react_comments_component)
19
- .with("comments-for-DummyCommentable-1", {
20
- commentableType: "Decidim::Comments::DummyCommentable",
21
- commentableId: "1",
22
- options: {},
23
- locale: I18n.locale
24
- })
25
- .and_call_original
26
-
27
- helper.comments_for(commentable)
28
- end
29
-
30
- it "should accept an optional hash of options" do
31
- expect(helper)
32
- .to receive(:react_comments_component)
33
- .with("comments-for-DummyCommentable-1", {
34
- commentableType: "Decidim::Comments::DummyCommentable",
13
+ .with("comments-for-DummyResource-1", {
14
+ commentableType: "Decidim::DummyResource",
35
15
  commentableId: "1",
36
- options: {
37
- arguable: true
38
- },
39
16
  locale: I18n.locale
40
17
  })
41
18
  .and_call_original
42
19
 
43
- helper.comments_for(commentable, arguable: true)
20
+ helper.comments_for(dummy_resource)
44
21
  end
45
22
  end
46
23
  end
@@ -4,7 +4,7 @@ require "spec_helper"
4
4
  module Decidim
5
5
  module Comments
6
6
  describe Comment do
7
- let!(:commentable) { create(:participatory_process) }
7
+ let!(:commentable) { create(:dummy_resource) }
8
8
  let!(:comment) { create(:comment, commentable: commentable) }
9
9
  let!(:replies) { 3.times.map { create(:comment, commentable: comment) } }
10
10
  let!(:up_vote) { create(:comment_vote, :up_vote, comment: comment) }
@@ -22,10 +22,6 @@ module Decidim
22
22
  expect(subject.commentable).to eq(commentable)
23
23
  end
24
24
 
25
- it "has a replies association" do
26
- expect(subject.replies).to match_array(replies)
27
- end
28
-
29
25
  it "has a up_votes association returning comment votes with weight 1" do
30
26
  expect(subject.up_votes.count).to eq(1)
31
27
  end
@@ -34,27 +30,27 @@ module Decidim
34
30
  expect(subject.down_votes.count).to eq(1)
35
31
  end
36
32
 
37
- it "is not valid if its parent is a comment and cannot have replies" do
38
- expect(subject).to receive(:can_have_replies?).and_return false
33
+ it "is not valid if its parent is a comment and cannot accept new comments" do
34
+ expect(subject).to receive(:accepts_new_comments?).and_return false
39
35
  expect(replies[0]).not_to be_valid
40
36
  end
41
37
 
42
38
  it "should compute its depth before saving the model" do
43
39
  expect(subject.depth).to eq(0)
44
- comment.replies.each do |reply|
40
+ comment.comments.each do |reply|
45
41
  expect(reply.depth).to eq(1)
46
42
  end
47
43
  end
48
44
 
49
- describe "#can_have_replies?" do
45
+ describe "#accepts_new_comments?" do
50
46
  it "should return true if the comment's depth is below MAX_DEPTH" do
51
47
  subject.depth = Comment::MAX_DEPTH - 1
52
- expect(subject.can_have_replies?).to be_truthy
48
+ expect(subject.accepts_new_comments?).to be_truthy
53
49
  end
54
50
 
55
51
  it "should return false if the comment's depth is equal or greater than MAX_DEPTH" do
56
52
  subject.depth = Comment::MAX_DEPTH
57
- expect(subject.can_have_replies?).to be_falsy
53
+ expect(subject.accepts_new_comments?).to be_falsy
58
54
  end
59
55
  end
60
56
 
@@ -6,8 +6,10 @@ module Decidim
6
6
  describe CommentVote do
7
7
  let!(:organization) { create(:organization) }
8
8
  let!(:participatory_process) { create(:participatory_process, organization: organization) }
9
+ let!(:feature) { create(:feature, participatory_process: participatory_process) }
10
+ let!(:commentable) { create(:dummy_resource, feature: feature) }
9
11
  let!(:author) { create(:user, organization: organization) }
10
- let!(:comment) { create(:comment, commentable: participatory_process, author: author)}
12
+ let!(:comment) { create(:comment, commentable: commentable, author: author)}
11
13
  let!(:comment_vote) { create(:comment_vote, comment: comment, author: author) }
12
14
 
13
15
  it "is valid" do
@@ -4,14 +4,13 @@ require "spec_helper"
4
4
  module Decidim
5
5
  module Comments
6
6
  describe Seed do
7
- let!(:organization) { create(:organization) }
8
7
  let(:subject) { Decidim::Comments::Seed }
9
8
 
10
9
  describe "#comments_for(resource)" do
11
10
  it 'creates comments for a page if one is given' do
12
- user = create(:user, organization: organization)
13
- subject.comments_for(user)
14
- expect(Decidim::Comments::CommentsWithReplies.for(user).length).to be_between(1, 5).inclusive
11
+ dummy_resource = create(:dummy_resource)
12
+ subject.comments_for(dummy_resource)
13
+ expect(Decidim::Comments::SortedComments.for(dummy_resource).length).to be_between(1, 5).inclusive
15
14
  end
16
15
  end
17
16
  end
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
  require "spec_helper"
3
3
 
4
- describe Decidim::Comments::CommentsWithReplies do
4
+ describe Decidim::Comments::SortedComments do
5
5
  let!(:organization) { create(:organization) }
6
+ let!(:participatory_process) { create(:participatory_process, organization: organization) }
7
+ let!(:feature) { create(:feature, participatory_process: participatory_process) }
6
8
  let!(:author) { create(:user, organization: organization) }
7
- let!(:commentable) { create(:participatory_process, organization: organization) }
9
+ let!(:commentable) { create(:dummy_resource, feature: feature) }
8
10
  let!(:comment) { create(:comment, commentable: commentable, author: author) }
9
11
  let!(:order_by) {}
10
12
 
11
13
  subject { described_class.new(commentable, order_by: order_by) }
12
-
14
+
13
15
  it "returns the commentable's comments" do
14
16
  expect(subject.query).to eq [comment]
15
17
  end
@@ -17,25 +19,6 @@ describe Decidim::Comments::CommentsWithReplies do
17
19
  it "eager loads comment's author, up_votes and down_votes" do
18
20
  comment = subject.query[0]
19
21
  expect {
20
- expect(comment.author.name).to be_present
21
- expect(comment.up_votes.size).to eq(0)
22
- expect(comment.down_votes.size).to eq(0)
23
- }.not_to make_database_queries
24
- end
25
-
26
- it "eager loads a comment tree based on the MAX_DEPTH" do
27
- reply = comment
28
-
29
- Decidim::Comments::Comment::MAX_DEPTH.times do
30
- reply = create(:comment, commentable: reply)
31
- end
32
-
33
- comment = subject.query[0]
34
-
35
- expect {
36
- Decidim::Comments::Comment::MAX_DEPTH.times do
37
- comment = comment.replies[0]
38
- end
39
22
  expect(comment.author.name).to be_present
40
23
  expect(comment.up_votes.size).to eq(0)
41
24
  expect(comment.down_votes.size).to eq(0)
@@ -45,9 +28,9 @@ describe Decidim::Comments::CommentsWithReplies do
45
28
  it "return the comments ordered by created_at asc by default" do
46
29
  previous_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.ago, updated_at: 1.week.ago)
47
30
  future_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.from_now, updated_at: 1.week.from_now)
48
- expect(subject.query).to eq [previous_comment, comment, future_comment]
31
+ expect(subject.query).to eq [previous_comment, comment, future_comment]
49
32
  end
50
-
33
+
51
34
  context "When order_by is not default" do
52
35
  context "When order by recent" do
53
36
  let!(:order_by) {"recent"}
@@ -55,19 +38,19 @@ describe Decidim::Comments::CommentsWithReplies do
55
38
  it "return the comments ordered by recent" do
56
39
  previous_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.ago, updated_at: 1.week.ago)
57
40
  future_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.from_now, updated_at: 1.week.from_now)
58
- expect(subject.query).to eq [previous_comment, comment, future_comment].reverse
41
+ expect(subject.query).to eq [previous_comment, comment, future_comment].reverse
59
42
  end
60
43
  end
61
-
44
+
62
45
  context "When order by best_rated" do
63
46
  let!(:order_by) {"best_rated"}
64
47
 
65
48
  it "return the comments ordered by best_rated" do
66
49
  most_voted_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.ago, updated_at: 1.week.ago)
67
- less_voted_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.from_now, updated_at: 1.week.from_now)
50
+ less_voted_comment = create(:comment, commentable: commentable, author: author, created_at: 1.week.from_now, updated_at: 1.week.from_now)
68
51
  create(:comment_vote, comment: most_voted_comment, author: author, weight: 1)
69
52
  create(:comment_vote, comment: less_voted_comment, author: author, weight: -1)
70
- expect(subject.query).to eq [most_voted_comment, comment, less_voted_comment]
53
+ expect(subject.query).to eq [most_voted_comment, comment, less_voted_comment]
71
54
  end
72
55
  end
73
56
 
@@ -76,7 +59,7 @@ describe Decidim::Comments::CommentsWithReplies do
76
59
 
77
60
  it "return the comments ordered by most_discussed" do
78
61
  most_commented = create(:comment, commentable: commentable, author: author, created_at: 1.week.ago, updated_at: 1.week.ago)
79
- less_commented = create(:comment, commentable: commentable, author: author, created_at: 1.week.from_now, updated_at: 1.week.from_now)
62
+ less_commented = create(:comment, commentable: commentable, author: author, created_at: 1.week.from_now, updated_at: 1.week.from_now)
80
63
  create(:comment, commentable: comment)
81
64
  create_list(:comment, 3, commentable: most_commented)
82
65
  expect(subject.query).to eq [most_commented, comment, less_commented]
@@ -17,43 +17,49 @@ module Decidim
17
17
  end
18
18
  end
19
19
 
20
- describe "hasReplies" do
21
- let (:query) { "{ hasReplies }" }
20
+ describe "hasComments" do
21
+ let (:query) { "{ hasComments }" }
22
22
 
23
- it "returns false if the comment has not replies" do
24
- expect(response).to include("hasReplies" => false)
23
+ it "returns false if the comment has not comments" do
24
+ expect(response).to include("hasComments" => false)
25
25
  end
26
26
 
27
- it "returns true if the comment has replies" do
27
+ it "returns true if the comment has comments" do
28
28
  FactoryGirl.create(:comment, commentable: model)
29
- expect(response).to include("hasReplies" => true)
29
+ expect(response).to include("hasComments" => true)
30
+ end
31
+
32
+ it "returns false if the comment depth is equal to MAX_DEPTH" do
33
+ FactoryGirl.create(:comment, commentable: model)
34
+ model.update_attribute(:depth, Comment::MAX_DEPTH)
35
+ expect(response).to include("hasComments" => false)
30
36
  end
31
37
  end
32
38
 
33
- describe "canHaveReplies" do
34
- let (:query) { "{ canHaveReplies }" }
39
+ describe "acceptsNewComments" do
40
+ let (:query) { "{ acceptsNewComments }" }
35
41
 
36
- it "returns the return value of can_have_replies? method" do
37
- expect(response).to include("canHaveReplies" => model.can_have_replies?)
42
+ it "returns the return value of accepts_new_comments? method" do
43
+ expect(response).to include("acceptsNewComments" => model.accepts_new_comments?)
38
44
  end
39
45
  end
40
46
 
41
- describe "replies" do
47
+ describe "comments" do
42
48
  let!(:random_comment) { FactoryGirl.create(:comment) }
43
49
  let!(:replies) { 3.times.map { |n| FactoryGirl.create(:comment, commentable: model, created_at: Time.now - n.days) } }
44
50
 
45
51
 
46
- let(:query) { "{ replies { id } }" }
52
+ let(:query) { "{ comments { id } }" }
47
53
 
48
- it "return comment's replies comments data" do
54
+ it "return comment's comments comments data" do
49
55
  replies.each do |reply|
50
- expect(response["replies"]).to include("id" => reply.id.to_s)
56
+ expect(response["comments"]).to include("id" => reply.id.to_s)
51
57
  end
52
- expect(response["replies"]).not_to include("id" => random_comment.id.to_s)
58
+ expect(response["comments"]).not_to include("id" => random_comment.id.to_s)
53
59
  end
54
60
 
55
- it "return comment's replies ordered by date" do
56
- response_ids = response["replies"].map{|reply| reply["id"].to_i }
61
+ it "return comment's comments ordered by date" do
62
+ response_ids = response["comments"].map{|reply| reply["id"].to_i }
57
63
  replies_ids = replies.sort_by(&:created_at).map(&:id)
58
64
  expect(response_ids).to eq(replies_ids)
59
65
  end