Commit Graph

1106 Commits

Author SHA1 Message Date
Javi Martín
df959b74f6 Make migrations reversible
While I don't use this feature, there are developers who do. It's useful
when running migrations and changing branches.

I'm raising an `ActiveRecord::IrreversibleMigration` exception in every
`drop_table` migration because these migrations were all done before
version 1.0.0, and so making all of them reversible would be too much
work for little benefit.
2019-10-24 21:20:17 +02:00
Javi Martín
91a3184281 Simplify creating timestamps in migrations
We were using the `timestamps` method most of the time, but sometimes we
were creating the columns manually.

Note editing past migrations if fine as long as the SQL they generate
remains identical, which is the case here.
2019-10-24 21:20:16 +02:00
Javi Martín
55addaa58a Apply rubocop rules to migration files
There are some rules which only affect migration files, and we cannot
enable them if we're excluding those files from being inspected.

We're also changing migrations related to the Rails/TimeZone rule
slightly because these fields were already changed afterwards, so we
aren't changing the schema.
2019-10-24 20:35:13 +02:00
Javi Martín
9028d82f77 Remove unnecessary enconding magic comment
This comment isn't necessary since Ruby 2.0, where UTF-8 became the
default encoding.

I've found this issue thanks to the EmptyLineAfterMagicComment rubocop
rule.
2019-10-24 17:56:03 +02:00
Javi Martín
d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +02:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
49e55b4dc4 Apply Rails/DynamicFindBy rubocop rule
We were already using `find_by` most of the time.

Since there are false positives related to our `find_by_slug_or_id!` and
`find_by_manger_login` methods, which cannot be replaced with `find_by`,
I'm adding it indicating the "refactor" severity.
2019-10-23 20:05:40 +02:00
Javi Martín
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00
Javi Martín
68ca29fa8b Convert markdown to HTML on demand
We were converting markdown to HTML every time we saved a record, which
has the same problems as sanitizing HTML before saving it to the
database, particularly because the body of a legislation draft is stored
in a translations table.

Performance-wise this isn't a problem: converting a text with more than
200_000 characters takes about a milisecond on my machine.

Note we need to modify a migration generated by globalize, since the
method `create_translation_table!` would fail now that we don't define
`translates :body_html` in the model.
2019-10-21 21:32:43 +02:00
Shaun Schwartz
04b1bc9fca Add timestamps to Budget::Heading & Budget::Group 2019-10-20 17:36:36 +02:00
Javi Martín
18d386c1ad Fix duplicate usernames in dev seeds task
Sometimes Faker::Name.name generated the same name for two different
users, causing the task to crash in development or a test to fail while
testing.
2019-10-09 22:59:15 +02:00
Javi Martín
7782ed73b6 Remove unneeded _html suffix
Although this translation has HTML, we aren't marking them as HTML safe
since we're using `I18n.t` instead of Rails' helper `t` method. So using
the `_html` suffix is counterintuitive in this case.
2019-10-09 19:46:47 +02:00
Javi Martín
d6eb9f8fb6 Add and apply ShadowingOuterLocalVariable rule
Naming two variables the same way is confusing at the very least, and
can lead to hard to debug errors. That's why the Ruby interpreter issues
a warning when we do so.
2019-10-05 14:47:19 +02:00
Javi Martín
ad14636255 Use Tag instead of ActsAsTaggableOn::Tag
It's shorter, it's easier to extend its behaviour, and it's easier to
integrate with other parts of our application, like translations.
2019-10-05 03:38:44 +02:00
voodoorai2000
488e19f8a0 Add original_heading_id to investments
Investments can be reclassified to a different heading during the participatory budget process.

Whilst we are recording this change of heading in the `previous_heading_id` attribute, we are only keeping the _last_ heading. If there are multiple reclassifications we lose this chain of reclassifications.

In this commit we are adding an `original_heading_id` attribute, that will only be set once, when creating the investment, and will not get lost with multiple reclassificaitons of an investment.
2019-09-12 16:49:01 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javi Martín
a21240b230 Use Date.current and Time.current
Using Date.today and Time.now might lead to inconsistencies if the time
zone the application uses is not the same as the system time zone.
2019-08-28 20:32:40 +02:00
Javi Martín
765d405df1 Use Rails 5 conventions in migrations and models
We forgot to add these changes to pull requests which were in
development before we upgraded to Rails 5.

We're also moving the rubocop rules to the basic files, so we're
notified when we inherit from `ActiveRecord::Base`.
2019-08-07 13:53:27 +02:00
Javi Martín
c3bcb10c2b Make WebSection seeds idempotent
Each time we were loading the seeds file, more web sections were
created.

On production it meant running `db:seeds` several times created the
records even if they already existed.

During the test, it meant 5 more records were created before every test,
so after ending a test run, thousands of records existed, making banner
tests very slow.
2019-08-06 22:00:29 +02:00
taitus
5d68e1a43d Add new fields to signature
- Add :date_of_birth and :postal_code to Signature to allow send these
  fields to CustomCensusAPI

- Add new model presence validates: Only validate :date_of_birth and
  :postal_code presence when the application has configured Remote Census
  and their alias fields has values.
2019-07-29 13:10:09 +02:00
taitus
837c45599d Rename SignatureSheet column
This new functionality will allow to retrieve in the signature sheet
the document number, the date of birth and the postal code.

So we renamed :document_numbers to :required_fields_to_veriry to
clarify and adjust the name to its use.
2019-07-29 13:10:09 +02:00
Senén Rodero Rodríguez
3c39dccad4 Add uniqueness validation to document_number and document_type pair 2019-07-29 13:07:24 +02:00
Senén Rodero Rodríguez
c4ef33e6f8 Add index to local census records document_number
This will speed up searching by document_number
2019-07-29 13:07:24 +02:00
voodoorai2000
251326ea9a Revert removal of translated attributes from default tables
We removed these columns from their original tables as Globalize raises a warning when making queries on the corresponding translated columns.

Since then we have decided to migrate from Globalize to Mobility, which does not raise these warnings.

We are still concerned about possible inconsistencies in the database due to maintaining these columns. However until we clear the problems out with the Mobility support team we are bringing them back.
2019-06-27 09:21:19 +02:00
taitus
04810f5080 Create RemoteTranslation model
- Each RemoteTranslation is associated with a resource (through polymorphic)
  and has the locale to we want translate.
- After create a RemoteTranslation we create a enqueue_remote_translation
  method that will be send remote translation instance to remote translation
  client
2019-06-27 09:20:25 +02:00
Senén Rodero Rodríguez
522b1c9ef7 Add budget investment translations to dev_seeds
Update budget investments development seeds with translations for all avaialble locales.
2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
f116477d6d Enable soft_deletion of Budget::Investment::Translations 2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
66f885f8e4 Rename deprecated attributes in budget investments
To avoid deprecation warning thrown by Globalize after gem update. We
are going to keep these attributes with different names until next
release when we will be able to destroy them.
2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
eefb9ca4f7 Add budget investment translations
Also fix sort_by_title method [1]

[1] Use ruby sort instead of active record order scope because Globalize
does not provide a way to search over all available fallbacks when
translation for current locale does not exist.
2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
8103a16031 Add proposals translations to dev_seeds
Update proposal development seeds with translations for all avaialble
locales.
2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
78055555cf Add debates translations to dev_seeds
Update debates development seeds with translations for all avaialble
locales.
2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
2079706845 Enable soft deletion of Proposal::Translations 2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
4ce006ec96 Enable soft deletion of Comment::Translations 2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
16b3ec6e5f Rename deprecated attributes from comments
To avoid deprecation warning thrown by Globalize after gem update.
2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
158af0217d Add comments translations
Co-Authored-By: Sebastia <sebastia.roig@gmail.com>
2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
096a9f6bb8 Enable soft deletion of Debate::Translations 2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
e6c9027042 Rename deprecated fields from debates
To avoid deprecation warning thrown by globalize after gem update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
740c738fc5 Add debate translations 2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
e6b3b85e48 Rename proposal deprecated fields
After adding new translations to proposal we no longer need this
attributes in proposals database table, but we keep them with a
deprecated name until next release where we drop them completely.

Also related column indexes where dropped.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
02be0c61f9 Add proposal translations
Adapt retire form to include needed translations and move validations
from controller to model.

Also change sanitizable concern to sanitize not marked for destruction
translations.
2019-06-27 09:19:36 +02:00
taitus
5343448c5a Remove deprecated attributes from Budget::Phase
Some fields from Budget::Phase are translatable and we no longer need them. This commit will remove the annoying deprecation warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
taitus
3b81bf67d1 Remove deprecated attributes from Budget::Heading
Some fields from Budget::Heading are translatable and we no longer need them. This commit will remove the annoying deprecation warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
taitus
952f03bb58 Remove deprecated attributes from Budget::Group
Some fields from Budget::Group are translatable and we no longer need them. This commit will remove the annoying deprecation warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
taitus
b5e17eac07 Remove deprecated attributes from Budgets
Some fields from Budget are translatable and we no longer need them. This commit will remove the annoying deprecation warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
e847aa22f7 Remove deprecated attributes from Widget::Card
Some fields from Widget::Card are translatable and we no longer need
them. This commit will remove the annoying deprecation warning thrown
by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
6e49a09a21 Remove deprecated attributes from SiteCustomization::Page
Some fields from SiteCustomization::page are translatable and we no
longer need them. This commit will remove the annoying deprecation
warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
9f1ca4941f Remove deprecated attibutes from Legislation::Question::Option
Some fields from Legislation::Question::Option are translatable and we
no longer need them. This commit will remove the annoying deprecation
warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
8b33a48e0e Remove deprecated attributes from Legislation::Question
Some fields from Legislation::Question are translatable and we no
longer need them. This commit will remove the annoying deprecation
warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
957959e11d Remove deprecated attributes from Legislation::Process
Some fields from Legislation::Process are translatable and we no longer
need them. This commit will remove the annoying deprecation warning
thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
e28a1a4a8e Remove deprecated attributes from Legislation::Draft::Version
Some fields from LegislationDraftVersion are translatable and we no
longer need them. This commit will remove the annoying deprecation
warning thrown by Globalize gem after gem version update.
2019-06-27 09:19:36 +02:00