diff --git a/.gitignore b/.gitignore index 5cedbfc..d523635 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,12 @@ # Ignore Tailwind configuration tailwind.config.js +# Ignore rspec failures +.rspec-failures + +# Ignore public/sw.js* +public/sw.js* + Capfile /config/deploy/* /config/deploy.rb diff --git a/README.md b/README.md index 5484860..6235bd0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # decidim_ub +[![[CI] Lint](https://github.com/Platoniq/decidim-ub/actions/workflows/lint.yml/badge.svg)](https://github.com/Platoniq/decidim-ub/actions/workflows/lint.yml) +[![[CI] Test](https://github.com/Platoniq/decidim-ub/actions/workflows/test.yml/badge.svg)](https://github.com/Platoniq/decidim-ub/actions/workflows/test.yml) + Free Open-Source participatory democracy, citizen participation and open government for cities and organizations This is the open-source repository for decidim_ub, based on [Decidim](https://github.com/decidim/decidim). diff --git a/app/packs/images/platoniq-logo.png b/app/packs/images/platoniq-logo.png new file mode 100644 index 0000000..76032c5 Binary files /dev/null and b/app/packs/images/platoniq-logo.png differ diff --git a/app/views/layouts/decidim/footer/_mini.html.erb b/app/views/layouts/decidim/footer/_mini.html.erb new file mode 100644 index 0000000..50b923e --- /dev/null +++ b/app/views/layouts/decidim/footer/_mini.html.erb @@ -0,0 +1,26 @@ + diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml new file mode 100644 index 0000000..621c5a1 --- /dev/null +++ b/config/i18n-tasks.yml @@ -0,0 +1,13 @@ +--- + +base_locale: en +locales: [en] + +data: + read: + - 'config/locales/*.%{locale}.yml' + +ignore_missing: + - layouts.decidim.footer.cc_by_license + - layouts.decidim.footer.decidim_logo + - layouts.decidim.footer.made_with_open_source diff --git a/config/locales/en.yml b/config/locales/en.yml index 5463f43..ea8ea7b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,3 +1,32 @@ ---- +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + en: - hello: Hello world diff --git a/config/locales/platoniq.en.yml b/config/locales/platoniq.en.yml new file mode 100644 index 0000000..c426b46 --- /dev/null +++ b/config/locales/platoniq.en.yml @@ -0,0 +1,6 @@ +--- +en: + platoniq: + footer: + logo: Platoniq Foundation - Creativity and Democracy + text: Made with ♥ by diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 0000000..0e6d87b --- /dev/null +++ b/spec/factories.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require "decidim/core/test/factories" diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb new file mode 100644 index 0000000..4a05e6d --- /dev/null +++ b/spec/i18n_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require "i18n/tasks" + +describe "I18n sanity" do + let(:locales) do + ENV["ENFORCED_LOCALES"].presence || "en" + end + + let(:i18n) { I18n::Tasks::BaseTask.new(locales: locales.split(",")) } + let(:missing_keys) { i18n.missing_keys } + let(:unused_keys) { i18n.unused_keys } + let(:non_normalized_paths) { i18n.non_normalized_paths } + + it "does not have missing keys" do + expect(missing_keys).to be_empty, "#{missing_keys.inspect} are missing" + end + + it "does not have unused keys" do + expect(unused_keys).to be_empty, "#{unused_keys.inspect} are unused" + end + + unless ENV["SKIP_NORMALIZATION"] + it "is normalized" do + error_message = "The following files need to be normalized:\n" \ + "#{non_normalized_paths.map { |path| " #{path}" }.join("\n")}\n" \ + "Please run `bundle exec i18n-tasks normalize --locales #{locales}` to fix them" + + expect(non_normalized_paths).to be_empty, error_message + end + end +end diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb new file mode 100644 index 0000000..57d1d76 --- /dev/null +++ b/spec/lib/overrides_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "rails_helper" + +# We make sure that the checksum of the file overridden is the same +# as the expected. If this test fails, it means that the overridden +# file should be updated to match any change/bug fix introduced in the core +checksums = [ + { + package: "decidim-core", + files: { + # views + "/app/views/layouts/decidim/footer/_mini.html.erb" => "ccead2f5f20557ea4db1501de943f82b" + } + } +] + +describe "Overridden files", type: :view do + checksums.each do |item| + spec = Gem::Specification.find_by_name(item[:package]) + item[:files].each do |file, signature| + next unless spec + + it "#{spec.gem_dir}#{file} matches checksum" do + expect(md5("#{spec.gem_dir}#{file}")).to eq(signature) + end + end + end + + private + + def md5(file) + Digest::MD5.hexdigest(File.read(file)) + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..37d41dc --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +ENV["RAILS_ENV"] ||= "test" +require File.expand_path("../config/environment", __dir__) + +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? + +require "spec_helper" +require "rspec/rails" + +require "decidim/dev" + +Decidim::Dev.dummy_app_path = File.expand_path(File.join(__dir__, "..")) + +require "decidim/dev/test/base_spec_helper" + +# Add additional requires below this line. Rails is not loaded until this point! + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end + +RSpec.configure do |config| + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! +end diff --git a/spec/shared/visiting_organization_homepage.rb b/spec/shared/visiting_organization_homepage.rb new file mode 100644 index 0000000..7d980be --- /dev/null +++ b/spec/shared/visiting_organization_homepage.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +shared_context "when visiting organization homepage" do + let(:organization) { create(:organization) } + + before do + switch_to_host(organization.host) + visit decidim.root_path + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..97af286 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed + config.order = :random + + config.before do + I18n.available_locales = [:en, :ca, :es] + I18n.default_locale = :en + # rubocop:disable Rails/I18nLocaleAssignment + I18n.locale = :en + # rubocop:enable Rails/I18nLocaleAssignment + Decidim.available_locales = [:en, :ca, :es] + Decidim.default_locale = :en + Capybara.server = :puma + end +end diff --git a/spec/system/homepage_spec.rb b/spec/system/homepage_spec.rb new file mode 100644 index 0000000..97af286 --- /dev/null +++ b/spec/system/homepage_spec.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed + config.order = :random + + config.before do + I18n.available_locales = [:en, :ca, :es] + I18n.default_locale = :en + # rubocop:disable Rails/I18nLocaleAssignment + I18n.locale = :en + # rubocop:enable Rails/I18nLocaleAssignment + Decidim.available_locales = [:en, :ca, :es] + Decidim.default_locale = :en + Capybara.server = :puma + end +end diff --git a/spec/system/platoniq_footer_spec.rb b/spec/system/platoniq_footer_spec.rb new file mode 100644 index 0000000..9a09705 --- /dev/null +++ b/spec/system/platoniq_footer_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "Has Platoniq footer", perform_enqueued: true do + include_context "when visiting organization homepage" + + it "renders the platoniq logo in the footer" do + expect(page).to have_content("Made with ♥ by") + expect(page).to have_xpath("//img[@alt='Platoniq Foundation - Creativity and Democracy']") + end +end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb deleted file mode 100644 index c05709a..0000000 --- a/test/application_system_test_case.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb deleted file mode 100644 index cc8337f..0000000 --- a/test/channels/application_cable/connection_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase - # test "connects with cookies" do - # cookies.signed[:user_id] = 42 - # - # connect - # - # assert_equal connection.user_id, "42" - # end -end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/system/.keep b/test/system/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 8e820b2..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" - -class ActiveSupport::TestCase - # Run tests in parallel with specified workers - parallelize(workers: :number_of_processors) - - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end