decidim-dev 0.26.2 → 0.27.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/app/commands/decidim/dummy_resources/create_dummy_resource.rb +1 -1
  3. data/app/controllers/concerns/decidim/dev/needs_development_tools.rb +1 -1
  4. data/config/locales/am-ET.yml +1 -0
  5. data/config/locales/ar.yml +1 -0
  6. data/config/locales/bg.yml +1 -0
  7. data/config/locales/ca.yml +1 -0
  8. data/config/locales/cs.yml +1 -0
  9. data/config/locales/da.yml +1 -0
  10. data/config/locales/de.yml +1 -0
  11. data/config/locales/el.yml +1 -0
  12. data/config/locales/eo.yml +1 -0
  13. data/config/locales/es-MX.yml +1 -0
  14. data/config/locales/es-PY.yml +1 -0
  15. data/config/locales/es.yml +1 -0
  16. data/config/locales/et.yml +1 -0
  17. data/config/locales/eu.yml +1 -0
  18. data/config/locales/fi-plain.yml +1 -0
  19. data/config/locales/fi.yml +1 -0
  20. data/config/locales/fr-CA.yml +1 -0
  21. data/config/locales/fr.yml +1 -0
  22. data/config/locales/ga-IE.yml +1 -0
  23. data/config/locales/gl.yml +1 -0
  24. data/config/locales/hr.yml +1 -0
  25. data/config/locales/hu.yml +1 -0
  26. data/config/locales/id-ID.yml +1 -0
  27. data/config/locales/is-IS.yml +2 -1
  28. data/config/locales/it.yml +1 -0
  29. data/config/locales/ja.yml +1 -0
  30. data/config/locales/ko.yml +1 -0
  31. data/config/locales/lb.yml +1 -0
  32. data/config/locales/lt.yml +1 -0
  33. data/config/locales/lv.yml +1 -0
  34. data/config/locales/mt.yml +1 -0
  35. data/config/locales/nl.yml +1 -0
  36. data/config/locales/no.yml +1 -0
  37. data/config/locales/om-ET.yml +1 -0
  38. data/config/locales/pl.yml +1 -0
  39. data/config/locales/pt-BR.yml +2 -1
  40. data/config/locales/pt.yml +1 -0
  41. data/config/locales/ro-RO.yml +1 -0
  42. data/config/locales/ru.yml +1 -0
  43. data/config/locales/si-LK.yml +1 -0
  44. data/config/locales/sk.yml +1 -0
  45. data/config/locales/sl.yml +1 -0
  46. data/config/locales/so-SO.yml +1 -0
  47. data/config/locales/sr-CS.yml +1 -0
  48. data/config/locales/sv.yml +1 -0
  49. data/config/locales/sw-KE.yml +1 -0
  50. data/config/locales/ti-ER.yml +1 -0
  51. data/config/locales/tr-TR.yml +1 -0
  52. data/config/locales/uk.yml +1 -0
  53. data/config/locales/val-ES.yml +1 -0
  54. data/config/locales/vi.yml +1 -0
  55. data/config/locales/zh-CN.yml +1 -0
  56. data/config/locales/zh-TW.yml +1 -0
  57. data/lib/decidim/dev/assets/geocoder_result_here.json +46 -67
  58. data/lib/decidim/dev/assets/logo.png +0 -0
  59. data/lib/decidim/dev/common_rake.rb +1 -0
  60. data/lib/decidim/dev/railtie.rb +1 -1
  61. data/lib/decidim/dev/test/base_spec_helper.rb +2 -1
  62. data/lib/decidim/dev/test/rspec_support/attachment_helpers.rb +30 -0
  63. data/lib/decidim/dev/test/rspec_support/autocomplete_select.rb +23 -0
  64. data/lib/decidim/dev/test/rspec_support/capybara.rb +43 -5
  65. data/lib/decidim/dev/test/rspec_support/comments.rb +1 -1
  66. data/lib/decidim/dev/test/rspec_support/component.rb +5 -5
  67. data/lib/decidim/dev/test/rspec_support/controller_example_group.rb +27 -0
  68. data/lib/decidim/dev/test/rspec_support/cookies.rb +41 -0
  69. data/lib/decidim/dev/test/rspec_support/dynamic_attach.rb +31 -0
  70. data/lib/decidim/dev/test/rspec_support/frontend.rb +1 -1
  71. data/lib/decidim/dev/test/rspec_support/geocoder.rb +6 -2
  72. data/lib/decidim/dev/test/rspec_support/html_matchers.rb +11 -0
  73. data/lib/decidim/dev/test/rspec_support/imports_controller_shared_examples.rb +3 -8
  74. data/lib/decidim/dev/test/rspec_support/network_conditions_helpers.rb +18 -0
  75. data/lib/decidim/dev/test/rspec_support/rake_tasks.rb +0 -2
  76. data/lib/decidim/dev/test/rspec_support/screenshot_helper.rb +41 -0
  77. data/lib/decidim/dev/test/rspec_support/warden.rb +5 -0
  78. data/lib/decidim/dev/test/rspec_support/wicked_pdf_assets_mock.rb +4 -0
  79. data/lib/decidim/dev/test/spec_helper.rb +2 -4
  80. data/lib/decidim/dev/test/w3c_rspec_validators_overrides.rb +0 -2
  81. data/lib/decidim/dev/version.rb +1 -1
  82. data/lib/decidim-dev.rb +1 -1
  83. data/lib/tasks/generators.rake +6 -2
  84. data/lib/tasks/lighthouse_report.rake +29 -0
  85. data/lib/tasks/locale_checker.rake +1 -1
  86. metadata +48 -41
  87. data/lib/decidim/dev/test/rspec_support/react_select.rb +0 -29
@@ -89,7 +89,7 @@ module Decidim
89
89
  include Followable
90
90
  include Traceable
91
91
  include Publicable
92
- include Decidim::DataPortability
92
+ include Decidim::DownloadYourData
93
93
  include Searchable
94
94
  include Paddable
95
95
  include Amendable
@@ -236,8 +236,8 @@ Decidim.register_component(:dummy) do |component|
236
236
  settings.attribute :comments_enabled, type: :boolean, default: true
237
237
  settings.attribute :comments_max_length, type: :integer, required: false
238
238
  settings.attribute :resources_permissions_enabled, type: :boolean, default: true
239
- settings.attribute :dummy_global_attribute_1, type: :boolean
240
- settings.attribute :dummy_global_attribute_2, type: :boolean, readonly: ->(_context) { false }
239
+ settings.attribute :dummy_global_attribute1, type: :boolean
240
+ settings.attribute :dummy_global_attribute2, type: :boolean, readonly: ->(_context) { false }
241
241
  settings.attribute :readonly_attribute, type: :boolean, default: true, readonly: ->(_context) { true }
242
242
  settings.attribute :enable_pads_creation, type: :boolean, default: false
243
243
  settings.attribute :amendments_enabled, type: :boolean, default: false
@@ -246,8 +246,8 @@ Decidim.register_component(:dummy) do |component|
246
246
 
247
247
  component.settings(:step) do |settings|
248
248
  settings.attribute :comments_blocked, type: :boolean, default: false
249
- settings.attribute :dummy_step_attribute_1, type: :boolean
250
- settings.attribute :dummy_step_attribute_2, type: :boolean, readonly: ->(_context) { false }
249
+ settings.attribute :dummy_step_attribute1, type: :boolean
250
+ settings.attribute :dummy_step_attribute2, type: :boolean, readonly: ->(_context) { false }
251
251
  settings.attribute :dummy_step_translatable_text, type: :text, translated: true, editor: true, required: true
252
252
  settings.attribute :readonly_step_attribute, type: :boolean, default: true, readonly: ->(_context) { true }
253
253
  settings.attribute :amendment_creation_enabled, type: :boolean, default: true
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ControllerExampleGroup
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def routes
9
+ before do
10
+ routes = yield
11
+ @orig_default_url_options = routes.default_url_options.dup
12
+ routes.default_url_options[:script_name] = ""
13
+
14
+ self.routes = routes
15
+ end
16
+
17
+ after do
18
+ routes.default_url_options = @orig_default_url_options
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ RSpec.configure do |config|
26
+ config.include Decidim::ControllerExampleGroup, type: :controller
27
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capybara
4
+ module Cookies
5
+ # Update cookie consent
6
+ def select_cookies(cookies = "all", options = {})
7
+ visit decidim.root_path if options[:visit_root]
8
+
9
+ dialog_present = begin
10
+ find("#cc-dialog-wrapper")
11
+ rescue Capybara::ElementNotFound => _e
12
+ false
13
+ end
14
+
15
+ if dialog_present
16
+ click_button "Settings"
17
+ else
18
+ within ".footer" do
19
+ click_link "Cookie settings"
20
+ end
21
+ end
22
+
23
+ if [true, "all"].include?(cookies)
24
+ click_button "Accept all"
25
+ elsif cookies.is_a?(Array)
26
+ cookies.each do |cookie|
27
+ within "[data-id='#{cookie}']" do
28
+ find(".switch-paddle").click
29
+ end
30
+ end
31
+ click_button "Save settings"
32
+ elsif [false, "essential"].include?(cookies)
33
+ click_button "Accept only essential"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ RSpec.configure do |config|
40
+ config.include Capybara::Cookies, type: :system
41
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adapted from https://github.com/JedWatson/react-select/issues/832#issuecomment-276441836
4
+
5
+ module Capybara
6
+ module UploadModal
7
+ # Replaces attach_file.
8
+ # Beware that modal does not open within form!
9
+ def dynamically_attach_file(name, file_location, options = {})
10
+ find("##{name}_button").click
11
+ filename = options[:filename] || file_location.to_s.split("/").last
12
+
13
+ yield if block_given?
14
+
15
+ within ".upload-modal" do
16
+ find(".remove-upload-item").click if options[:remove_before]
17
+ input_element = find("input[type='file']", visible: :all)
18
+ input_element.attach_file(file_location)
19
+ within "[data-filename='#{filename}']" do
20
+ expect(page).to have_css("div.progress-bar.filled", wait: 5)
21
+ end
22
+ all("input.attachment-title").last.set(options[:title]) if options.has_key?(:title)
23
+ click_button "Save" unless options[:keep_modal_open]
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ RSpec.configure do |config|
30
+ config.include Capybara::UploadModal, type: :system
31
+ end
@@ -4,7 +4,7 @@ module FrontendHelpers
4
4
  # Thanks to:
5
5
  # https://medium.com/@coorasse/catch-javascript-errors-in-your-system-tests-89c2fe6773b1
6
6
  def expect_no_js_errors
7
- errors = page.driver.browser.manage.logs.get(:browser)
7
+ errors = page.driver.browser.logs.get(:browser)
8
8
  return if errors.blank?
9
9
 
10
10
  aggregate_failures "javascript errors" do
@@ -17,8 +17,9 @@ module GeocoderHelpers
17
17
  # Waits for the front-end geocoding request to finish in order to ensure there
18
18
  # are no pending requests when proceeding.
19
19
  def fill_in_geocoding(attribute, options = {})
20
- fill_in attribute, options
21
- expect(page).to have_selector(".tribute-container ul#results", count: 1)
20
+ fill_in attribute, **options
21
+ expect(page).to have_selector(".autoComplete_wrapper ul#autoComplete_list_1", count: 1)
22
+ find("li#autoComplete_result_0").click
22
23
  end
23
24
 
24
25
  module_function
@@ -38,6 +39,7 @@ module Decidim::Map::Provider
38
39
  module Geocoding
39
40
  class Test < ::Decidim::Map::Geocoding; end
40
41
  end
42
+
41
43
  module Autocomplete
42
44
  class Test < ::Decidim::Map::Autocomplete
43
45
  def self.stubs
@@ -66,9 +68,11 @@ module Decidim::Map::Provider
66
68
  end
67
69
  end
68
70
  end
71
+
69
72
  module DynamicMap
70
73
  class Test < ::Decidim::Map::DynamicMap; end
71
74
  end
75
+
72
76
  module StaticMap
73
77
  class Test < ::Decidim::Map::StaticMap; end
74
78
  end
@@ -2,6 +2,16 @@
2
2
 
3
3
  require "rspec-html-matchers"
4
4
 
5
+ module EscapeHtmlHelpers
6
+ def escaped_html(string)
7
+ CGI.escapeHTML(string)
8
+ end
9
+
10
+ def have_escaped_html(string)
11
+ include(escaped_html(string))
12
+ end
13
+ end
14
+
5
15
  RSpec::Matchers.define(:have_equivalent_markup_to) do |expected|
6
16
  cleaner = ->(str) { str.gsub(/>[[:space:]]*/, ">").gsub(/[[:space:]]*</, "<").strip }
7
17
 
@@ -14,4 +24,5 @@ end
14
24
 
15
25
  RSpec.configure do |config|
16
26
  config.include RSpecHtmlMatchers
27
+ config.include EscapeHtmlHelpers
17
28
  end
@@ -19,14 +19,9 @@ shared_examples "admin imports controller" do
19
19
  end
20
20
 
21
21
  describe "POST create" do
22
- let(:file) do
23
- # The file does not really matter for the dummies creator because it
24
- # will always create a record for each data row regardless of the data.
25
- Rack::Test::UploadedFile.new(
26
- Decidim::Dev.test_file("import_proposals.csv", "text/csv"),
27
- "text/csv"
28
- )
29
- end
22
+ # The file does not really matter for the dummies creator because it
23
+ # will always create a record for each data row regardless of the data.
24
+ let(:file) { upload_test_file(Decidim::Dev.test_file("import_proposals.csv", "text/csv")) }
30
25
  let(:params) do
31
26
  default_params.merge(extra_params).merge(file: file)
32
27
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NetworkConditionsHelpers
4
+ def with_browser_in_offline_mode
5
+ page.driver.browser.network_conditions = { offline: true }
6
+
7
+ # Wait for the browser to be offline
8
+ sleep 1
9
+
10
+ yield
11
+
12
+ page.driver.browser.network_conditions = { offline: false }
13
+ end
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.include NetworkConditionsHelpers, type: :system
18
+ end
@@ -32,7 +32,6 @@ module RakeTaskOutputHelpers
32
32
  included do
33
33
  let!(:original_stdout) { $stdout }
34
34
 
35
- # rubocop:disable RSpec/ExpectOutput
36
35
  before do
37
36
  $stdout = StringIO.new
38
37
  end
@@ -40,7 +39,6 @@ module RakeTaskOutputHelpers
40
39
  after do
41
40
  $stdout = original_stdout
42
41
  end
43
- # rubocop:enable RSpec/ExpectOutput
44
42
  end
45
43
 
46
44
  def check_no_errors_have_been_printed
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/system_testing/test_helpers/screenshot_helper"
4
+
5
+ module ActionDispatch
6
+ module SystemTesting
7
+ module TestHelpers
8
+ module ScreenshotHelper
9
+ private
10
+
11
+ # Customize the screenshot helper to fix the file paths for examples that have
12
+ # unallowed characters in them. Otherwise the artefacts creation and upload
13
+ # fails at GitHub actions. See the list of unallowed characters from:
14
+ # https://github.com/actions/toolkit/blob/main/packages/artifact/docs/additional-information.md#non-supported-characters
15
+ def image_name
16
+ # By default, this only cleans up the forward and backward slash characters.
17
+ sanitized_method_name = method_name.tr("/\\()\":<>|*?", "-----------")
18
+ name = "#{unique}_#{sanitized_method_name}"
19
+ name[0...225]
20
+ end
21
+
22
+ # Add the file URI scheme so terminal emulators can open one click
23
+ def display_image
24
+ message = +"[Screenshot Image]: file://#{image_path}\n"
25
+ message << +"[Screenshot HTML]: file://#{html_path}\n" if save_html?
26
+
27
+ case output_type
28
+ when "artifact"
29
+ message << "\e]1338;url=artifact://#{absolute_image_path}\a\n"
30
+ when "inline"
31
+ name = inline_base64(File.basename(absolute_image_path))
32
+ image = inline_base64(File.read(absolute_image_path))
33
+ message << "\e]1337;File=name=#{name};height=400px;inline=1:#{image}\a\n"
34
+ end
35
+
36
+ message
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -18,6 +18,7 @@ end
18
18
 
19
19
  RSpec.configure do |config|
20
20
  config.include Decidim::WardenTestHelpers, type: :system
21
+ config.include Decidim::WardenTestHelpers, type: :request
21
22
  config.include Devise::Test::ControllerHelpers, type: :controller
22
23
 
23
24
  config.before :each, type: :cell do
@@ -30,4 +31,8 @@ RSpec.configure do |config|
30
31
  config.after :each, type: :system do
31
32
  Warden.test_reset!
32
33
  end
34
+
35
+ config.after :each, type: :request do
36
+ Warden.test_reset!
37
+ end
33
38
  end
@@ -8,6 +8,10 @@ class WickedPdf
8
8
  def wicked_pdf_stylesheet_pack_tag(*sources)
9
9
  stylesheet_pack_tag(*sources)
10
10
  end
11
+
12
+ # Disables the images in the PDFs as those requests would be jamming under
13
+ # the test environment
14
+ def wicked_pdf_image_tag(img, options = {}); end
11
15
  end
12
16
  end
13
17
  end
@@ -4,7 +4,6 @@ require "rails-controller-testing"
4
4
  require "rspec/rails"
5
5
  require "rspec/cells"
6
6
  require "byebug"
7
- require "rectify/rspec"
8
7
  require "wisper/rspec/stub_wisper_publisher"
9
8
  require "db-query-matchers"
10
9
  require "action_view/helpers/sanitize_helper"
@@ -14,13 +13,13 @@ require "decidim/dev/test/w3c_rspec_validators_overrides"
14
13
 
15
14
  # Requires supporting files with custom matchers and macros, etc,
16
15
  # in ./rspec_support/ and its subdirectories.
17
- Dir["#{__dir__}/rspec_support/**/*.rb"].sort.each { |f| require f }
16
+ Dir["#{__dir__}/rspec_support/**/*.rb"].each { |f| require f }
18
17
 
19
18
  require_relative "factories"
20
19
 
21
20
  RSpec.configure do |config|
22
21
  config.color = true
23
- config.fail_fast = ENV["FAIL_FAST"] == "true"
22
+ config.fail_fast = ENV.fetch("FAIL_FAST", nil) == "true"
24
23
  config.infer_spec_type_from_file_location!
25
24
  config.mock_with :rspec
26
25
  config.order = :random
@@ -32,7 +31,6 @@ RSpec.configure do |config|
32
31
  # instead of true.
33
32
  config.use_transactional_fixtures = true
34
33
 
35
- config.include Rectify::RSpec::Helpers
36
34
  config.include ActionView::Helpers::SanitizeHelper
37
35
  config.include ERB::Util
38
36
  end
@@ -36,12 +36,10 @@ end
36
36
  # This allows us to dynamically load the validator URL from the ENV.
37
37
  module W3cRspecValidators
38
38
  class Config
39
- # rubocop:disable Naming/MemoizedInstanceVariableName
40
39
  def self.get
41
40
  @config ||= {
42
41
  w3c_service_uri: ENV.fetch("VALIDATOR_HTML_URI", "https://validator.w3.org/nu/")
43
42
  }.stringify_keys
44
43
  end
45
- # rubocop:enable Naming/MemoizedInstanceVariableName
46
44
  end
47
45
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-dev version.
5
5
  module Dev
6
6
  def self.version
7
- "0.26.2"
7
+ "0.27.0.rc1"
8
8
  end
9
9
  end
10
10
  end
data/lib/decidim-dev.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "decidim/dev/engine" if Rails.env.development? || ENV["DECIDIM_DEV_ENGINE"]
3
+ require "decidim/dev/engine" if Rails.env.development? || ENV.fetch("DECIDIM_DEV_ENGINE", nil)
@@ -32,7 +32,9 @@ namespace :decidim do
32
32
  "--skip_spring",
33
33
  "--demo",
34
34
  "--force_ssl",
35
- "false"
35
+ "false",
36
+ "--locales",
37
+ "en,ca,es"
36
38
  )
37
39
  end
38
40
 
@@ -48,7 +50,9 @@ namespace :decidim do
48
50
  "--recreate_db",
49
51
  "--seed_db",
50
52
  "--demo",
51
- "--profiling"
53
+ "--profiling",
54
+ "--locales",
55
+ "en,ca,es"
52
56
  )
53
57
  end
54
58
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :decidim do
4
+ namespace :lighthouse do
5
+ desc "Prepares seeds for Lighthouse report"
6
+ task prepare_urls: :environment do
7
+ # Lighhouse report is executed in CI and should check:
8
+ # - homepage
9
+ # - a participatory process page
10
+ # - a meeting page
11
+ # - a proposal page
12
+ #
13
+ # Because seeds make urls dynamic, this task updates the lighthouse configuration
14
+ # to add dynamically the urls to check.
15
+
16
+ host = "http://localhost:3000"
17
+ urls = ["/"]
18
+ urls << ::Decidim::ResourceLocatorPresenter.new(Decidim::ParticipatoryProcess.published.first).path
19
+ urls << ::Decidim::ResourceLocatorPresenter.new(Decidim::Meetings::Meeting.published.first).path
20
+ urls << ::Decidim::ResourceLocatorPresenter.new(Decidim::Proposals::Proposal.published.first).path
21
+
22
+ # Update lighthouse configuration with the urls
23
+ lighthouse_rc_path = Rails.root.join("../.lighthouserc.json")
24
+ lighthouserc = JSON.parse(File.read(lighthouse_rc_path))
25
+ lighthouserc["ci"]["collect"]["url"] = urls.map { |url| "#{host}#{url}" }
26
+ File.write(lighthouse_rc_path, lighthouserc.to_json)
27
+ end
28
+ end
29
+ end
@@ -5,7 +5,7 @@ namespace :decidim do
5
5
  task check_locales: :environment do
6
6
  FileUtils.remove_dir("tmp/decidim_repo", true)
7
7
 
8
- branch = ENV["TARGET_BRANCH"] || "develop"
8
+ branch = ENV.fetch("TARGET_BRANCH", nil) || "develop"
9
9
  status = system("git clone --depth=1 --single-branch --branch #{branch} https://github.com/decidim/decidim tmp/decidim_repo")
10
10
  return unless status
11
11