Commit Graph

266 Commits

Author SHA1 Message Date
Javi Martín
f5c2a3d4ef Add and apply BlockAlignment rubocop rule
This will make it easier to run rubocop with `--autocorrect` when
dealing with the LineLength rule.
2023-08-18 14:56:17 +02:00
Javi Martín
e19205cfe5 Use variables instead of constants in dev seeds
While running the `dev_seed` twice, as we do in the tests, we were
getting the following warnings:

```
db/dev_seeds/proposals.rb:1: warning: already initialized constant
IMAGE_FILES

db/dev_seeds/budgets.rb:1: warning: already initialized constant
INVESTMENT_IMAGE_FILES
```

So we're extracting a method which allows us to use local variables
while removing duplication.

We had this warning with every version of Ruby, not just Ruby 2.7, but
since we're getting rid of all the warnings, we're taking care of this
one as well.
2023-01-26 17:58:12 +01:00
Javi Martín
a98c363d4d Allow seeding a specific tenant with db:dev_seed
Until now, running `db:dev_seed` created development data for the
default tenant but it was impossible to create this data for other
tenants.

Now the tenant can be provided as a parameter.

Note that, in order to be able to execute this task twice while running
the tests, we need to use `load` instead of `require_relative`, since
`require_relative` doesn't load the file again if it's already loaded.

Also note that having two optional parameters in a rake task results in
a cumbersome syntax to execute it. To avoid this, we're simply removing
the `print_log` parameter, which was used mainly for the test
environment. Now we use a different logic to get the same result.

From now on it won't be possible to pass the option to avoid the log in
the development environment. I don't know a developer who's ever used
this option, though, and it can always be done using `> /dev/null`.
2022-11-09 18:19:20 +01:00
Javi Martín
7189a2368e Drop all tenant schemas before running db:dev_seed
When running this task we truncate all tables; however, doing so doesn't
execute the `after_destroy` callback which drops the generated schema.
That meant we could run into a situation where there are schemas in the
database with no associated tenant, leading to data inconsistencies.

So we're now destroying the tenants (alongside their schemas) before
truncating the rest of the database tables.
2022-11-09 18:19:20 +01:00
Javi Martín
480ab6a9da Use truncate_all instead of DatabaseCleaner
Performance tests show both methods of truncating the database take
about the same time, so we can remove one dependency and we don't lose
anything in the process.
2022-08-24 18:11:56 +02:00
Javi Martín
490fe5fd11 Make dev seeds independent on available locales
Some developers work on CONSUL installations where Spanish and/or
English aren't part of the available locales. In those cases, the
`dev_seed` task was crashing because we were using attributes like
`name_en` and `name_es`.

So we're using attributes for random locales instead.

We're using a proc so we don't have code like this all over the place:

random_locales.map do |locale|
  I18n.with_locale(locale) do
    phase.name = I18n.t("budgets.phase.#{phase.kind}")
    phase.save!
  end
end

This would make the code harder to read and would execute a `save!` once
per locale, which would make the task much slower.

We could also avoid the procs writing something like:

def random_locales_attributes(**attribute_names_with_values)
  random_locales.each_with_object({}) do |locale, attributes|
    I18n.with_locale(locale) do
      attribute_names_with_values.each do |attribute_name, (i18n_key, i18n_args)|
        value = I18n.t(i18n_key, (i18n_args || {}).merge(language: I18n.t("i18n.language.name")))
        attributes["#{attribute_name}_#{locale.to_s.underscore}"] = value
      end
    end
  end
end

And calling the method with with:

random_locales_attributes(name: ["seeds.budgets.name", year: Date.current.year - 1])

However, this code would also be different that what we usually do, we'd
have to apply some magic to pass the `language:` parameter, and the
strings wouldn't be recognized by i18n-tasks, so we aren't sure we're
really gaining anything.
2021-12-14 20:05:07 +01:00
Javi Martín
9514ece2c2 Prioritize English and Spanish in dev seeds
These locales are officially maintained by CONSUL developers, so we're
using them when available.

This way we'll be able to use `random_locales` in places where we're
manually using English and Spanish, giving support to other locales
while maintaining compatibility with the current version.
2021-12-13 15:15:28 +01:00
Senén Rodero Rodríguez
cbe84450ac Add Goals seeds and translations
Extracted from the official United Nations Sustainable Development
Goals website [1].

[1] https://www.un.org/sustainabledevelopment/sustainable-development-goals/
2020-12-02 12:38:03 +01:00
Javi Martín
9427f01442 Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
2020-04-24 15:43:54 +02:00
Javi Martín
f3df3f4fbc Remove people proposal model
This model isn't used anywhere, since it was created as part of a
feature which couldn't be completed.

This commit reverts commit 46e5d6a9.
2019-10-30 02:26:42 +01:00
lalo
46e5d6a9fa Create Legislation::PeopleProposal model 2019-06-06 17:22:49 +02:00
voodoorai2000
d0b8fef6b3 Delete spending proposals 2019-05-31 18:22:59 +02:00
Julian Herrero
8e5e757b00 Include default custom pages in developers seed 2019-03-22 12:29:42 +01:00
decabeza
abdeafc2dd Fix hound warnings on dev_seeds 2019-02-25 15:34:15 +01:00
Javi Martín
7317238382 Reduce the number of locales for milestones seeds
Creating records for every locale was taking too long now that CONSUL is
available in 15 languages.
2019-01-24 12:03:02 +01:00
Javi Martín
2fdd367f22 Move milestone dev seeds to their own file 2018-12-11 19:22:55 +01:00
Angel Perez
f568f9baab Add Legislation::Proposal seeds 2018-08-06 09:39:17 -04:00
Bertocq
2aa4b5cad6 Add AdminNotification seed data 2018-07-25 18:34:33 +02:00
Pierre Mesure
1ebcf04186 Adding images and seeds for the homepage 2018-06-15 14:26:29 +02:00
Bertocq
fcdc24a78c Avoid db:dev_seed log print when run from its test
The db:dev_seed rake logs info as it progresses as information for the
developer. But that's not needed when ran from its tests file, and it
bloats the travis/rspec output with unnecessary information.

Now the task will always log info unless the rake task receives an
optional argument.
2018-04-14 20:28:43 +02:00
rgarcia
f7bfe5e171 Extend dev seeds to have notifications for all users
Even though an action that triggers a notification is made, the
notification is created in a separate step, reflecting how it is done
in the corresponding controller

https://github.com/AyuntamientoMadrid/consul/blob/master/app/controllers
/comments_controller.rb#L16
2018-03-23 11:48:16 +01:00
Bertocq
54e6c5fc5c Split dev_seeds into individual files for sections
Why:

Its a really huge script, and conflicts are hard to resolve on forks,
with indivudal scripts its easier to make custom changes.

How:

Following @mariacheca example using require_relative and a file under
the db/dev_seeds/ folder
2018-02-22 11:04:47 +01:00
María Checa
24bca36639 Merge branch 'master' into admin-newsletter-emails 2018-02-14 16:07:13 +01:00
María Checa
20de8c81f7 Added newsletters to dev_seeds 2018-02-14 16:06:33 +01:00
Bertocq
31cece096b Verify manager & moderator sample users in dev_seeds 2018-02-08 18:23:29 +01:00
Bertocq
ffe7d4baad Fix rubocop issues at dev seeds 2018-01-30 03:31:41 +01:00
Bertocq
a4fb568654 Improve dev seeds comments adding them to investments 2018-01-30 03:29:20 +01:00
Bertocq
2b8a32198b Improve dev_seeds generations around Budgets & Investments 2018-01-23 16:01:40 +01:00
Bertocq
c30c47cbb5 Improve default city map with 4 districts, and more real fake geozones 2018-01-23 15:59:24 +01:00
Bertocq
60515708e0 Fix indentations at dev seeds script 2018-01-23 15:57:38 +01:00
rgarcia
d3d05f9cee Add guide to create a proposal or investment
During a Participatory Budget, some users are getting confused and
creating a proposal instead of a budget investment. This intermediate
page should help them create investments

Adding a feature flag just in case other forks don’t need this feature
and setting seeds and dev_seeds for appropriate initial setup
2018-01-18 21:09:21 +01:00
Bertocq
eeefa646a4 Default dev seeds geolocation at madrid, and geolocate all investments 2018-01-18 01:39:43 +01:00
Bertocq
66691b644a Refactor Budget::PHASES constant to Budget::Phase::PHASE_KINDS 2018-01-16 12:18:13 +01:00
Bertocq
baa3c5280f Remove TODO's from code, write reminder action on related issue 2018-01-09 23:53:09 +01:00
María Checa
cd53884d72 Updated dev_seeds 2018-01-09 00:09:56 +01:00
Bertocq
e1ec4ad967 Fix minimum Proposal title & question random length on dev seeds 2018-01-06 14:20:57 +01:00
Bertocq
46dc559301 Filter out nil related contents while listing them 2017-12-31 20:30:45 +01:00
BertoCQ
d534b02b3c Merge pull request #2206 from consul/related-contents-score
Related contents score
2017-12-20 15:13:12 +01:00
Bertocq
065b0ed3c8 Create Related Content Scores 2017-12-20 02:36:10 +01:00
decabeza
a0192be46f adds skip_map to dev_seeds 2017-12-20 02:18:21 +01:00
María Checa
853e655e0c Changed related_contents_report_threshold setting value 2017-12-19 13:13:20 +01:00
Bertocq
15e881b81a Increase dev seeds creating communities, topics and comments on topics & polls 2017-12-15 13:47:10 +01:00
Alberto García
19925de06b Merge pull request #2170 from consul/design
Design improvements
2017-12-14 11:31:31 +01:00
Raimond Garcia
11e80fbc92 Merge pull request #1903 from wairbut-m2c/aperez-enable-disable-proposals
Add enable/disable option for 'Proposals' feature
2017-12-08 11:41:13 +01:00
decabeza
cbaf1ae6c1 adds setting to allow images for proposals and investment projects 2017-12-06 20:44:43 +01:00
María Checa
56e10f9532 Merge pull request #2160 from consul/relationables
Related Content model and Relatable concern
2017-12-05 15:19:42 +01:00
Bertocq
88d098242c Add missing public_stats feature flag on dev seeds 2017-12-04 18:03:35 +01:00
Bertocq
e02f511b3a Add times_reported integer attribute to RelatedContent 2017-11-29 19:02:14 +01:00
decabeza
510d4822a4 adds new setting for site title meta tag 2017-11-24 14:12:01 +01:00
Angel Perez
ab9d612128 'Proposals' feature can be enabled/disabled
Fixes #1886
2017-11-17 13:10:55 -04:00