Skip to content

Commit

Permalink
Initial cleanup (#4)
Browse files Browse the repository at this point in the history
* Add GH CI result to README.md

* Ignore .rspec-failures

* i18n spec file

* homepage and other spec files

* Remove test directory

* Fix README rubocop suggestion

* i18n_spec to english

* default locale to :ca, edit en.yml

* Platoniq and EU logos in footer

* More spec files to go with the new footer

* Edited expected checksum in overrides_spec.rb

* remove eu logo

* public.sw.js* in .gitignor

* Remove cached ublic/sw.js* files

* correct platoniq footer spec

* Remove lingering EU footer files

* default locale to :en to be overwritten with env variable
  • Loading branch information
HHassig authored Jun 27, 2024
1 parent 2aecb8b commit d3f7dfb
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 37 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
Binary file added app/packs/images/platoniq-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions app/views/layouts/decidim/footer/_mini.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="mini-footer">
<div class="mini-footer__content flex-wrap gap-8">
<div class="flex justify-start gap-10 items-center text-white">
<div>
<a rel="decidim noopener noreferrer" href="https://journal.platoniq.net/" target="_blank" data-external-link="false">
<span class="text-xs"><%= t("platoniq.footer.text") %></span>
<%= image_pack_tag("media/images/platoniq-logo.png", alt: t("platoniq.footer.logo"), class: "max-h-8 block") %>
</a>
</div>
<div>
<a rel="decidim noopener noreferrer" href="https://decidim.org/" target="_blank" data-external-link="false">
<%= image_pack_tag("media/images/decidim-logo.svg", alt: t("layouts.decidim.footer.decidim_logo"), class: "max-h-8 block") %>
</a>
<div class="text-xs mt-2 [&_a]:underline">
<%= t("layouts.decidim.footer.made_with_open_source").html_safe %>
</div>
</div>
</div>
<a class="flex gap-1 hover:opacity-50" rel="license noopener noreferrer" href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" data-external-link="false">
<span class="sr-only"><%= t("layouts.decidim.footer.cc_by_license") %></span>
<%= icon "creative-commons-line", class: "w-6 h-6 fill-current" %>
<%= icon "creative-commons-by-line", class: "w-6 h-6 fill-current" %>
<%= icon "creative-commons-sa-line", class: "w-6 h-6 fill-current" %>
</a>
</div>
</div>
13 changes: 13 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 31 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions config/locales/platoniq.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
en:
platoniq:
footer:
logo: Platoniq Foundation - Creativity and Democracy
text: Made with ♥ by
3 changes: 3 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require "decidim/core/test/factories"
32 changes: 32 additions & 0 deletions spec/i18n_spec.rb
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions spec/shared/visiting_organization_homepage.rb
Original file line number Diff line number Diff line change
@@ -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
102 changes: 102 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d3f7dfb

Please sign in to comment.