decidim-dev 0.28.2 → 0.29.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/packs/stylesheets/decidim/dev/_accessibility.scss +1 -1
  3. data/app/packs/stylesheets/decidim/dev/_bullet.scss +4 -0
  4. data/app/packs/stylesheets/decidim/dev/_rack_profiler.scss +4 -0
  5. data/app/packs/stylesheets/decidim/dev.scss +2 -0
  6. data/config/rubocop/disabled.yml +60 -0
  7. data/config/rubocop/performance.yml +154 -0
  8. data/config/rubocop/rspec.yml +7 -2
  9. data/config/rubocop/ruby.yml +5 -5
  10. data/decidim-dev.gemspec +11 -6
  11. data/lib/decidim/dev/assets/assemblies.json +1 -34
  12. data/lib/decidim/dev/assets/assemblies_with_null.json +1 -2
  13. data/lib/decidim/dev/assets/participatory_processes.json +1 -34
  14. data/lib/decidim/dev/assets/participatory_processes_with_null.json +0 -1
  15. data/lib/decidim/dev/assets/participatory_text.md +0 -2
  16. data/lib/decidim/dev/component.rb +2 -2
  17. data/lib/decidim/dev/dummy_translator.rb +1 -1
  18. data/lib/decidim/dev/engine.rb +11 -0
  19. data/lib/decidim/dev/test/map_server.rb +125 -0
  20. data/lib/decidim/dev/test/rspec_support/autocomplete_select.rb +2 -2
  21. data/lib/decidim/dev/test/rspec_support/bullet.rb +4 -0
  22. data/lib/decidim/dev/test/rspec_support/capybara.rb +18 -7
  23. data/lib/decidim/dev/test/rspec_support/cell_matchers.rb +1 -1
  24. data/lib/decidim/dev/test/rspec_support/component_context.rb +1 -1
  25. data/lib/decidim/dev/test/rspec_support/data_consent.rb +6 -6
  26. data/lib/decidim/dev/test/rspec_support/datepicker_date_fill.rb +25 -0
  27. data/lib/decidim/dev/test/rspec_support/datepicker_time_fill.rb +23 -0
  28. data/lib/decidim/dev/test/rspec_support/dynamic_attach.rb +2 -2
  29. data/lib/decidim/dev/test/rspec_support/geocoder.rb +8 -72
  30. data/lib/decidim/dev/test/rspec_support/helpers.rb +4 -4
  31. data/lib/decidim/dev/test/rspec_support/tom_select.rb +1 -1
  32. data/lib/decidim/dev/test/rspec_support/translation_helpers.rb +5 -5
  33. data/lib/decidim/dev/test/rspec_support/webmock.rb +7 -1
  34. data/lib/decidim/dev/test/rspec_support/wicked_pdf_assets_mock.rb +2 -2
  35. data/lib/decidim/dev/test/spec_helper.rb +2 -1
  36. data/lib/decidim/dev/version.rb +1 -1
  37. data/lib/decidim/dev.rb +0 -9
  38. data/lib/decidim-dev.rb +2 -0
  39. data/lib/tasks/lighthouse_report.rake +1 -1
  40. data/rubocop-decidim.yml +6 -0
  41. metadata +97 -21
  42. /data/app/views/decidim/dummy_resource/{_linked_dummys.html.erb → _linked_dummies.html.erb} +0 -0
  43. /data/{app/controllers/concerns → lib}/decidim/dev/needs_development_tools.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc9d821614ad42d1eb20f682ab82321b933753c5b4d951fea170751b8f6a5bcf
4
- data.tar.gz: e256ccb91d7c4ffc96a7722dcd4cb047bfd76724a1199d86ed04527fe0c8829b
3
+ metadata.gz: e2fcbfc76decf8d8809bad2ff00344de88b9ccf71750415f1cdfc498e1c9921a
4
+ data.tar.gz: eb37bd7b9db59ef9fbf4551c7303ff82943cdeb496d7bb8acb0c739fea947ea6
5
5
  SHA512:
6
- metadata.gz: ccaee176486a56c7b99979f06c2debc99e93b44ada6f251db4a6e57684a065858e46eb32884ff9c9696f225f5d243fd5fdfe8cf8eff2ab8ce84df59277a39e3a
7
- data.tar.gz: b74b0ee53ae4c5b2db19932c575793fecf546458c51bc0bd62dc3692646c621e04786de35f0a540a166c7ad9ca91869e8c160b58c82ad3d67fe6bc3d4d21fdea
6
+ metadata.gz: 50596057f7f981b5e9630b1db72ad64352a32042f1bdd87158af74b0c57fd6214df68cb543db22413540d980e17dafc7625dd450440a6e5f58af808f39f0743d
7
+ data.tar.gz: 3c7084087adc7166f12d04ce5a2738cc63219cafa6a0793191d71d75419966a5f2e7ad613175635f06b524a3b3196e99a2a17daf44c48570afb66e1f372584f5
@@ -2,7 +2,7 @@
2
2
  position: fixed;
3
3
  display: flex;
4
4
  z-index: 9999;
5
- top: 60px;
5
+ bottom: 0;
6
6
  left: 0;
7
7
  background: #fff;
8
8
  border: 1px solid #888;
@@ -0,0 +1,4 @@
1
+ details#bullet-footer {
2
+ z-index: 77777 !important;
3
+ bottom: 48px !important;
4
+ }
@@ -0,0 +1,4 @@
1
+ .profiler-results.profiler-bottom {
2
+ bottom: 26px !important;
3
+ z-index: 88888 !important;
4
+ }
@@ -1,2 +1,4 @@
1
1
  @import "stylesheets/decidim/dev/accessibility";
2
+ @import "stylesheets/decidim/dev/bullet";
3
+ @import "stylesheets/decidim/dev/rack_profiler";
2
4
  @import "stylesheets/decidim/dev/map";
@@ -9,3 +9,63 @@ Naming/MemoizedInstanceVariableName:
9
9
 
10
10
  RSpec/VerifiedDoubleReference:
11
11
  Enabled: false
12
+
13
+ FactoryBot/ConsistentParenthesesStyle:
14
+ Enabled: false
15
+
16
+ FactoryBot/ExcessiveCreateList:
17
+ Enabled: false
18
+
19
+ RSpec/ExampleWording:
20
+ Enabled: false
21
+
22
+ Rails/PluckInWhere:
23
+ Enabled: false
24
+
25
+ RSpec/ReceiveMessages:
26
+ Enabled: false
27
+
28
+ RSpecRails/NegationBeValid:
29
+ Enabled: false
30
+
31
+ RSpec/MetadataStyle:
32
+ Enabled: false
33
+
34
+ FactoryBot/FactoryAssociationWithStrategy:
35
+ Enabled: false
36
+
37
+ RSpec/RemoveConst:
38
+ Enabled: false
39
+
40
+ FactoryBot/AssociationStyle:
41
+ Enabled: false
42
+
43
+ Rubycw/Rubycw:
44
+ Enabled: false
45
+
46
+ Lint/SymbolConversion:
47
+ Enabled: false
48
+
49
+ Style/RedundantParentheses:
50
+ Enabled: false
51
+
52
+ Style/MapIntoArray:
53
+ Enabled: false
54
+
55
+ Style/SuperWithArgsParentheses:
56
+ Enabled: false
57
+
58
+ Style/ArgumentsForwarding:
59
+ Enabled: false
60
+
61
+ Style/SuperArguments:
62
+ Enabled: false
63
+
64
+ Lint/SelfAssignment:
65
+ Enabled: false
66
+
67
+ Style/SendWithLiteralMethodName:
68
+ Enabled: false
69
+
70
+ Rails/WhereRange:
71
+ Enabled: false
@@ -0,0 +1,154 @@
1
+ require: rubocop-performance
2
+
3
+ Performance:
4
+ Enabled: false
5
+
6
+ Performance/AncestorsInclude:
7
+ Enabled: false
8
+
9
+ Performance/ArraySemiInfiniteRangeSlice:
10
+ Enabled: false
11
+
12
+ Performance/BigDecimalWithNumericArgument:
13
+ Enabled: false
14
+
15
+ Performance/BindCall:
16
+ Enabled: false
17
+
18
+ Performance/BlockGivenWithExplicitBlock:
19
+ Enabled: false
20
+
21
+ Performance/Caller:
22
+ Enabled: false
23
+
24
+ Performance/CaseWhenSplat:
25
+ Enabled: false
26
+
27
+ Performance/Casecmp:
28
+ Enabled: false
29
+
30
+ Performance/ChainArrayAllocation:
31
+ Enabled: false
32
+
33
+ Performance/CollectionLiteralInLoop:
34
+ Enabled: false
35
+
36
+ Performance/CompareWithBlock:
37
+ Enabled: false
38
+
39
+ Performance/ConcurrentMonotonicTime:
40
+ Enabled: false
41
+
42
+ Performance/ConstantRegexp:
43
+ Enabled: false
44
+
45
+ Performance/Count:
46
+ Enabled: false
47
+
48
+ Performance/DeletePrefix:
49
+ Enabled: false
50
+
51
+ Performance/DeleteSuffix:
52
+ Enabled: false
53
+
54
+ Performance/Detect:
55
+ Enabled: false
56
+
57
+ Performance/DoubleStartEndWith:
58
+ Enabled: false
59
+
60
+ Performance/EndWith:
61
+ Enabled: false
62
+
63
+ Performance/FixedSize:
64
+ Enabled: false
65
+
66
+ Performance/FlatMap:
67
+ Enabled: false
68
+
69
+ Performance/InefficientHashSearch:
70
+ Enabled: false
71
+
72
+ Performance/IoReadlines:
73
+ Enabled: false
74
+
75
+ Performance/MapCompact:
76
+ Enabled: false
77
+
78
+ Performance/MapMethodChain:
79
+ Enabled: false
80
+
81
+ Performance/MethodObjectAsBlock:
82
+ Enabled: false
83
+
84
+ Performance/OpenStruct:
85
+ Enabled: false
86
+
87
+ Performance/RangeInclude:
88
+ Enabled: false
89
+
90
+ Performance/RedundantBlockCall:
91
+ Enabled: false
92
+
93
+ Performance/RedundantEqualityComparisonBlock:
94
+ Enabled: false
95
+
96
+ Performance/RedundantMatch:
97
+ Enabled: false
98
+
99
+ Performance/RedundantMerge:
100
+ Enabled: false
101
+
102
+ Performance/RedundantSortBlock:
103
+ Enabled: false
104
+
105
+ Performance/RedundantSplitRegexpArgument:
106
+ Enabled: false
107
+
108
+ Performance/RedundantStringChars:
109
+ Enabled: false
110
+
111
+ Performance/RegexpMatch:
112
+ Enabled: false
113
+
114
+ Performance/ReverseEach:
115
+ Enabled: false
116
+
117
+ Performance/ReverseFirst:
118
+ Enabled: false
119
+
120
+ Performance/SelectMap:
121
+ Enabled: false
122
+
123
+ Performance/Size:
124
+ Enabled: false
125
+
126
+ Performance/SortReverse:
127
+ Enabled: false
128
+
129
+ Performance/Squeeze:
130
+ Enabled: false
131
+
132
+ Performance/StartWith:
133
+ Enabled: false
134
+
135
+ Performance/StringIdentifierArgument:
136
+ Enabled: false
137
+
138
+ Performance/StringInclude:
139
+ Enabled: false
140
+
141
+ Performance/StringReplacement:
142
+ Enabled: false
143
+
144
+ Performance/Sum:
145
+ Enabled: false
146
+
147
+ Performance/TimesMap:
148
+ Enabled: false
149
+
150
+ Performance/UnfreezeString:
151
+ Enabled: false
152
+
153
+ Performance/UriDefaultParser:
154
+ Enabled: false
@@ -1,11 +1,13 @@
1
- require: rubocop-rspec
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rspec_rails
2
4
 
3
5
  # RSpec:
4
6
  # Patterns:
5
7
  # - "(?:^|/)spec/"
6
8
  # - "(?:^|/)test/"
7
9
 
8
- RSpec/FilePath:
10
+ RSpec/SpecFilePathFormat:
9
11
  CustomTransform:
10
12
  OAuthApplicationPresenter: oauth_application_presenter
11
13
 
@@ -71,3 +73,6 @@ RSpec/LeakyConstantDeclaration:
71
73
 
72
74
  RSpec/DescribedClass:
73
75
  Enabled: false
76
+
77
+ RSpec/IndexedLet:
78
+ Enabled: false
@@ -37,7 +37,7 @@ AllCops:
37
37
  StyleGuideCopsOnly: false
38
38
  # All cops except the ones in disabled.yml are enabled by default. Change
39
39
  # this behavior by overriding DisabledByDefault. When DisabledByDefault is
40
- # true, all cops in the default configuration are disabled, and and only cops
40
+ # true, all cops in the default configuration are disabled, and only cops
41
41
  # in user configuration are enabled. This makes cops opt-in instead of
42
42
  # opt-out. Note that when DisabledByDefault is true, cops in user
43
43
  # configuration will be enabled even if they do not set the Enabled parameter.
@@ -66,7 +66,7 @@ AllCops:
66
66
  # If a value is specified for TargetRubyVersion then it is used.
67
67
  # Else if .ruby-version exists and it contains an MRI version it is used.
68
68
  # Otherwise we fallback to the oldest officially supported Ruby version (2.0).
69
- TargetRubyVersion: 3.1
69
+ TargetRubyVersion: 3.2
70
70
 
71
71
  # Indent private/protected/public as deep as method definitions
72
72
  Layout/AccessModifierIndentation:
@@ -530,7 +530,7 @@ Style/GuardClause:
530
530
  MinBodyLength: 6
531
531
 
532
532
  Style/HashSyntax:
533
- EnforcedStyle: ruby19
533
+ EnforcedStyle: no_mixed_keys
534
534
  SupportedStyles:
535
535
  # checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys
536
536
  - ruby19
@@ -803,11 +803,11 @@ Naming/PredicateName:
803
803
  ForbiddenPrefixes:
804
804
  - is_
805
805
  - have_
806
- # Predicate names which, despite having a blacklisted prefix, or no ?,
806
+ # Predicate names which, despite having a denylisted prefix, or no ?,
807
807
  # should still be accepted
808
808
  AllowedMethods:
809
809
  - is_a?
810
- # Exclude Rspec specs because there is a strong convetion to write spec
810
+ # Exclude Rspec specs because there is a strong convention to write spec
811
811
  # helpers in the form of `have_something` or `be_something`.
812
812
  Exclude:
813
813
  - "**/spec/**/*"
data/decidim-dev.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  "homepage_uri" => "https://decidim.org",
20
20
  "source_code_uri" => "https://github.com/decidim/decidim"
21
21
  }
22
- s.required_ruby_version = "~> 3.1.0"
22
+ s.required_ruby_version = "~> 3.2.0"
23
23
 
24
24
  s.name = "decidim-dev"
25
25
  s.summary = "Decidim dev tools"
@@ -37,11 +37,11 @@ Gem::Specification.new do |s|
37
37
  s.add_dependency "factory_bot_rails", "~> 6.2"
38
38
  s.add_dependency "faker", "~> 3.2"
39
39
 
40
- s.add_dependency "bullet", "~> 7.0"
40
+ s.add_dependency "bullet", "~> 7.1.6"
41
41
  s.add_dependency "byebug", "~> 11.0"
42
42
  s.add_dependency "erb_lint", "~> 0.4.0"
43
43
  s.add_dependency "i18n-tasks", "~> 1.0"
44
- s.add_dependency "nokogiri", "~> 1.14", ">= 1.14.3"
44
+ s.add_dependency "nokogiri", "~> 1.16", ">= 1.16.2"
45
45
  s.add_dependency "parallel_tests", "~> 4.2"
46
46
  s.add_dependency "puma", "~> 6.2", ">= 6.3.1"
47
47
  s.add_dependency "rails-controller-testing", "~> 1.0"
@@ -51,10 +51,15 @@ Gem::Specification.new do |s|
51
51
  s.add_dependency "rspec_junit_formatter", "~> 0.6.0"
52
52
  s.add_dependency "rspec-rails", "~> 6.0"
53
53
  s.add_dependency "rspec-retry", "~> 0.6.2"
54
- s.add_dependency "rubocop", "~> 1.50.0"
54
+ s.add_dependency "rubocop", "~> 1.65.0"
55
+ s.add_dependency "rubocop-capybara", "~> 2.21"
56
+ s.add_dependency "rubocop-factory_bot", "~> 2.26"
55
57
  s.add_dependency "rubocop-faker", "~> 1.1"
56
- s.add_dependency "rubocop-rails", "~> 2.19"
57
- s.add_dependency "rubocop-rspec", "~> 2.20"
58
+ s.add_dependency "rubocop-performance", "~> 1.21"
59
+ s.add_dependency "rubocop-rails", "~> 2.25"
60
+ s.add_dependency "rubocop-rspec", "~> 3.0"
61
+ s.add_dependency "rubocop-rspec_rails", "~> 2.30"
62
+ s.add_dependency "rubocop-rubycw", "~> 0.1"
58
63
  s.add_dependency "selenium-webdriver", "~> 4.9"
59
64
  s.add_dependency "simplecov", "~> 0.22.0"
60
65
  s.add_dependency "simplecov-cobertura", "~> 2.1.0"
@@ -58,7 +58,6 @@
58
58
  "en": "Vel qui.",
59
59
  "es": "Et molestiae."
60
60
  },
61
- "show_statistics": false,
62
61
  "scopes_enabled": true,
63
62
  "private_space": false,
64
63
  "reference": "PhD-ASSE-2020-01-1",
@@ -352,38 +351,6 @@
352
351
  "intro_en": "<p>Praesentium iste sit dicta.</p>",
353
352
  "intro_ca": "<p>Odit aperiam ea reiciendis.</p>",
354
353
  "intro_es": "<p>Repudiandae magni quo sit.</p>",
355
- "categories_label": {
356
- "ca": "rerum",
357
- "en": "dolores",
358
- "es": "voluptatem"
359
- },
360
- "categories_label_en": "dolores",
361
- "categories_label_ca": "rerum",
362
- "categories_label_es": "voluptatem",
363
- "subcategories_label": {
364
- "ca": "totam",
365
- "en": "qui",
366
- "es": "iure"
367
- },
368
- "subcategories_label_en": "qui",
369
- "subcategories_label_ca": "totam",
370
- "subcategories_label_es": "iure",
371
- "heading_parent_level_results": {
372
- "ca": "pariatur",
373
- "en": "voluptatem",
374
- "es": "molestias"
375
- },
376
- "heading_parent_level_results_en": "voluptatem",
377
- "heading_parent_level_results_ca": "pariatur",
378
- "heading_parent_level_results_es": "molestias",
379
- "heading_leaf_level_results": {
380
- "ca": "enim",
381
- "en": "nam",
382
- "es": "et"
383
- },
384
- "heading_leaf_level_results_en": "nam",
385
- "heading_leaf_level_results_ca": "enim",
386
- "heading_leaf_level_results_es": "et",
387
354
  "display_progress_enabled": true
388
355
  },
389
356
  "weight": 0,
@@ -541,7 +508,7 @@
541
508
  "proposal_length": 500,
542
509
  "proposal_edit_before_minutes": 5,
543
510
  "threshold_per_proposal": 0,
544
- "can_accumulate_supports_beyond_threshold": false,
511
+ "can_accumulate_votes_beyond_threshold": false,
545
512
  "proposal_answering_enabled": true,
546
513
  "official_proposals_enabled": true,
547
514
  "comments_enabled": true,
@@ -48,7 +48,7 @@
48
48
  "es": "Incidunt provident doloremque."
49
49
  },
50
50
  "decidim_scope_id": null,
51
- "paticipatory_scope": {
51
+ "participatory_scope": {
52
52
  "ca": "Assumenda.",
53
53
  "en": "Quidem.",
54
54
  "es": "Aspernatur."
@@ -58,7 +58,6 @@
58
58
  "en": "Vel qui.",
59
59
  "es": "Et molestiae."
60
60
  },
61
- "show_statistics": false,
62
61
  "scopes_enabled": true,
63
62
  "private_space": false,
64
63
  "reference": "PhD-ASSE-2020-01-1",
@@ -91,7 +91,6 @@
91
91
  "private_space": false,
92
92
  "promoted": true,
93
93
  "scopes_enabled": true,
94
- "show_statistics": true,
95
94
  "participatory_process_steps": [
96
95
  {
97
96
  "id": 1,
@@ -340,38 +339,6 @@
340
339
  "intro_en": "<p>Voluptatem praesentium maxime vitae.</p>",
341
340
  "intro_ca": "<p>Sapiente animi quo at.</p>",
342
341
  "intro_es": "<p>Illum veritatis porro nulla.</p>",
343
- "categories_label": {
344
- "ca": "alias",
345
- "en": "aut",
346
- "es": "omnis"
347
- },
348
- "categories_label_en": "aut",
349
- "categories_label_ca": "alias",
350
- "categories_label_es": "omnis",
351
- "subcategories_label": {
352
- "ca": "rerum",
353
- "en": "reprehenderit",
354
- "es": "nostrum"
355
- },
356
- "subcategories_label_en": "reprehenderit",
357
- "subcategories_label_ca": "rerum",
358
- "subcategories_label_es": "nostrum",
359
- "heading_parent_level_results": {
360
- "ca": "et",
361
- "en": "explicabo",
362
- "es": "officiis"
363
- },
364
- "heading_parent_level_results_en": "explicabo",
365
- "heading_parent_level_results_ca": "et",
366
- "heading_parent_level_results_es": "officiis",
367
- "heading_leaf_level_results": {
368
- "ca": "consectetur",
369
- "en": "illum",
370
- "es": "sunt"
371
- },
372
- "heading_leaf_level_results_en": "illum",
373
- "heading_leaf_level_results_ca": "consectetur",
374
- "heading_leaf_level_results_es": "sunt",
375
342
  "display_progress_enabled": true
376
343
  },
377
344
  "weight": 0,
@@ -431,4 +398,4 @@
431
398
  }
432
399
  ]
433
400
  }
434
- ]
401
+ ]
@@ -91,7 +91,6 @@
91
91
  "private_space": false,
92
92
  "promoted": true,
93
93
  "scopes_enabled": true,
94
- "show_statistics": true,
95
94
  "participatory_process_steps": null,
96
95
  "participatory_process_categories": null,
97
96
  "attachments": {
@@ -1,5 +1,3 @@
1
- <!-- markdown-lint-disable-file single-h1 -->
2
-
3
1
  # The great title for a new law
4
2
 
5
3
  ## A co-creation process to create creative creations
@@ -40,7 +40,7 @@ Decidim.register_component(:dummy) do |component|
40
40
  component.register_resource(:dummy_resource) do |resource|
41
41
  resource.name = :dummy
42
42
  resource.model_class_name = "Decidim::Dev::DummyResource"
43
- resource.template = "decidim/dummy_resource/linked_dummys"
43
+ resource.template = "decidim/dummy_resource/linked_dummies"
44
44
  resource.actions = %w(foo)
45
45
  resource.searchable = true
46
46
  end
@@ -53,7 +53,7 @@ Decidim.register_component(:dummy) do |component|
53
53
  component.register_resource(:coauthorable_dummy_resource) do |resource|
54
54
  resource.name = :coauthorable_dummy
55
55
  resource.model_class_name = "Decidim::Dev::CoauthorableDummyResource"
56
- resource.template = "decidim/coauthorabledummy_resource/linked_dummys"
56
+ resource.template = "decidim/coauthorabledummy_resource/linked_dummies"
57
57
  resource.actions = %w(foo-coauthorable)
58
58
  resource.searchable = false
59
59
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Dev
5
- # This Dummy translator recieves the field value
5
+ # This Dummy translator receives the field value
6
6
  # and the locale of the field which has to be
7
7
  # translated. It returns the appended value for both.
8
8
  # This is for testing only.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "decidim/dev/needs_development_tools"
4
+
3
5
  module Decidim
4
6
  module Dev
5
7
  # Decidim's development Rails Engine.
@@ -27,6 +29,15 @@ module Decidim
27
29
  Decidim.register_assets_path File.expand_path("app/packs", root)
28
30
  end
29
31
 
32
+ initializer "decidim_dev.middleware.test_map_server" do |app|
33
+ next unless Rails.env.test?
34
+
35
+ require "decidim/dev/test/map_server"
36
+
37
+ # Add the test map server as the first middleware in the stack
38
+ app.config.middleware.insert_before 0, Decidim::Dev::Test::MapServer
39
+ end
40
+
30
41
  initializer "decidim_dev.moderation_content" do
31
42
  config.to_prepare do
32
43
  ActiveSupport::Notifications.subscribe("decidim.admin.block_user:after") do |_event_name, data|
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Dev
5
+ module Test
6
+ # The test map server serves all map related requests for the app.
7
+ #
8
+ # Works as a rack middleware that is mounted to the Rails app during
9
+ # tests (at the decidim-dev module's engine).
10
+ class MapServer
11
+ def self.host
12
+ "http://#{hostname}:#{Capybara.server_port}"
13
+ end
14
+
15
+ def self.hostname
16
+ "maps.lvh.me"
17
+ end
18
+
19
+ def self.url(endpoint)
20
+ case endpoint
21
+ when :tiles
22
+ "#{host}/maptiles/{z}/{x}/{y}.png"
23
+ when :static
24
+ "#{host}/static"
25
+ when :autocomplete
26
+ "#{host}/photon_api"
27
+ end
28
+ end
29
+
30
+ def initialize(app)
31
+ @app = app
32
+ end
33
+
34
+ def call(env)
35
+ request = Rack::Request.new(env)
36
+ return @app.call(env) unless request.host == self.class.hostname
37
+
38
+ if (match = request.path.match(%r{^/maptiles/([0-9]+)/([0-9]+)/([0-9]+).png$}))
39
+ return serve_maptiles(request, { z: match[1], x: match[2], y: match[3] })
40
+ elsif request.path == "/static"
41
+ return serve_static(request)
42
+ elsif request.path == "/photon_api"
43
+ return serve_autocomplete(request)
44
+ end
45
+
46
+ not_found
47
+ end
48
+
49
+ private
50
+
51
+ def tile_image_content
52
+ @tile_image_content ||= File.read(Decidim::Dev.asset("icon.png"))
53
+ end
54
+
55
+ def serve_maptiles(_request, _properties)
56
+ [200, { "Content-Type" => "image/png" }, [tile_image_content]]
57
+ end
58
+
59
+ def serve_static(_request)
60
+ [200, { "Content-Type" => "image/png" }, [tile_image_content]]
61
+ end
62
+
63
+ def serve_autocomplete(_request)
64
+ photon_response = {
65
+ features: [
66
+ {
67
+ properties: {
68
+ name: "Park",
69
+ street: "Street1",
70
+ housenumber: "1",
71
+ postcode: "123456",
72
+ city: "City1",
73
+ state: "State1",
74
+ country: "Country1"
75
+ },
76
+ geometry: {
77
+ coordinates: [2.234, 1.123]
78
+ }
79
+ },
80
+ {
81
+ properties: {
82
+ street: "Street2",
83
+ postcode: "654321",
84
+ city: "City2",
85
+ country: "Country2"
86
+ },
87
+ geometry: {
88
+ coordinates: [4.456, 3.345]
89
+ }
90
+ },
91
+ {
92
+ properties: {
93
+ street: "Street3",
94
+ housenumber: "3",
95
+ postcode: "142536",
96
+ city: "City3",
97
+ country: "Country3"
98
+ },
99
+ geometry: {
100
+ coordinates: [6.678, 5.567]
101
+ }
102
+ }
103
+ ]
104
+ }.tap do |response|
105
+ Decidim::Map::Provider::Autocomplete::Test.stubs.length.positive? &&
106
+ response[:features] = Decidim::Map::Provider::Autocomplete::Test.stubs
107
+ end
108
+
109
+ [
110
+ 200,
111
+ {
112
+ "Content-Type" => "application/json",
113
+ "Access-Control-Allow-Origin" => "*"
114
+ },
115
+ [photon_response.to_json.to_s]
116
+ ]
117
+ end
118
+
119
+ def not_found
120
+ [404, { "Content-Type" => "text/plain" }, ["Not found."]]
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end