100 Commits

Author SHA1 Message Date
Javi Martín
53ff81dfdf Unify code applying the colors of a process
We had some duplication because the `css_for_process_header` was using
an instance variable, and so it couldn't be called from a partial where
this instance variable wasn't available.

Using a local variable and passing it as a parameter (as we should
always do) solves the issue and lets us simplify the code.
2025-03-06 18:25:45 +01:00
Javi Martín
c28ff49f10 Move investments search form partial to a component
As a bonus, we now have a few less helper methods :).
2024-11-11 15:04:40 +01:00
Javi Martín
f721e88af8 Remove instance_double usage in CommentsHelper tests
Lately (not sure since when), from time to time we've been getting these
failures in our CI:

```
Failures:

  1) CommentsHelper#comment_author_class returns is-author if author is the commenting user
     Failure/Error: comment = instance_double(Comment, user_id: author_id)
       the Comment class does not implement the instance method: user_id
     # ./spec/helpers/comments_helper_spec.rb:48:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:40:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:39:in `block (2 levels) in <top (required)>'

  2) CommentsHelper#comment_author_class returns an empty string if commenter is not the author
     Failure/Error: comment = instance_double(Comment, user_id: author_id - 1)
       the Comment class does not implement the instance method: user_id
     # ./spec/helpers/comments_helper_spec.rb:55:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:40:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:39:in `block (2 levels) in <top (required)>'
```

It might be related to the upgrade of rspec-rails done in commit
6fe222148 or maybe due to a change in github actions that caused some
tests to fail, as described in commits bedcb5bca and 3e44eeaee.

What might be causing the issue is the usage of `instance_double`
stubbing different methods in different tests (not sure this is the
cause, though).

We've seen that somebody got a similar error [1] (although it might not
have been for the same reason) and one of the maintainers of rspec-mocks
replied:

> I would recommend switching to double (as you mentioned) or
> refactoring to use something more defined.

So we're simply using `double`, which is what we usually use when
stubbing objects in the tests. Doing so is faster than further
investigating why the `instance_double` isn't reliable 100% of the time.

[1] See issue 1587 in https://github.com/rspec/rspec-mocks/
2024-11-06 15:21:51 +01:00
taitus
9300fe5a58 Add an apply RSpec/StringAsInstanceDoubleConstant rubocop rule
This rule was added in 3.1.0. Applying it allows you to start defining a way of doing
this in the project, helping to maintain consistency.
2024-10-08 18:43:07 +02:00
Senén Rodero Rodríguez
0643606dcd Add new setting to enable/disable map marker clustering 2024-01-29 17:56:54 +01:00
Senén Rodero Rodríguez
57c257e91c Extract settings table partial to a component 2024-01-25 18:29:38 +01:00
Javi Martín
05757c7f02 Add and apply RSpec/Rails/InferredSpecType rule
This rule was added in rubocop-rspec 2.14.0.
2023-09-06 19:00:56 +02:00
Javi Martín
8e276e2891 Add FactoryBot/ConsistentParenthesesStyle rule
This rule was added in rubocop-rspec 2.14.0. We were already applying it
most of the time.
2023-09-06 19:00:56 +02:00
Javi Martín
f79a21f071 Add and apply RSpec/BeEq rubocop rule
This rule was added in rubocop-rspec 2.9.0. Once again, we were applying
it about 50% of the time.
2023-09-06 19:00:56 +02:00
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
ad26c5cf9f Fix background images with special characters
Just like we did for budgets, we're doing the same thing in all the
places where we render background images attached by either regular
users or administrators.

This way we correctly render background images with characters like
brackets or quotes.
2023-06-27 15:06:30 +02:00
Javi Martín
b98244afd9 Remove votes query optimizations
Just like we did in commit 0214184b2d for investments, we're removing
some possible optimizations (we don't have any benchmarks proving they
affect performance at all) in order to simplify the code.

The investement votes component `delegate` code was accidentally left
but isn't used since commit 0214184b2, so we're removing it now that
we're removing the `voted_for?` helper method.
2022-02-21 18:47:13 +01:00
Javi Martín
65c9786db7 Apply Layout/RedundantLineBreak rule to short lines
We're not adding the rule because it would apply the current line length
rule of 110 characters per line. We still haven't decided whether we'll
keep that rule or make lines shorter so they're easier to read,
particularly when vertically splitting the editor window.

So, for now, I'm applying the rule to lines which are about 90
characters long.
2021-09-03 11:49:53 +02:00
Javi Martín
d0243764a2 Extract component to render a list of links
This way it's easier to refactor it and/or change it.

Back in commit c156621a4 I wrote:

> Generally speaking, I'm not a big fan of helpers, but there are
> methods which IMHO qualify as helpers when (...) many Rails helpers,
> like `tag`, follow these principles.

It's time to modify these criteria a little bit. In some situations,
it's great to have a helper method so it can be easily used in view
(like `link_to`). However, from the maintenance point of view, helper
methods are usually messy because extracting methods requires making
sure there isn't another helper method with that name.

So we can use the best part of these worlds and provide a helper so it
can be easily called from the view, but internally make that helper
render a component and enjoy the advantages associated with using an
isolated Ruby class.
2021-07-05 22:27:39 +02:00
Javi Martín
d8d5b7f60a Extract budget executions filters to a component 2021-06-29 20:07:55 +02:00
Javi Martín
82e8de094b Extract budget form to a component
This way it will be easier to change it and reuse it.
2021-06-08 14:25:43 +02:00
Javi Martín
7c4515d6ce Simplify code to generate "See more" link
We can skip the `link_to(*options) if options` part if we accept anchor
tags in the `link_list` helper.
2021-02-02 20:05:40 +01:00
Javi Martín
d1ab8ac29b Split li tags in link list helper
This way we generate the same HTML as we generate everywhere where we
manually generate lists of links. Having a blank space betwwen tags
results in a space being introduced when the elements are displayed
inline (or with `inline-block`).

So in places where we don't want that space between the elements we have
to use a flex layout.
2021-01-27 15:56:58 +01:00
Javi Martín
7680bfc94b Use aria-current to mark the current element
This way screen reader users will be notified that the element is the
current one.

I'm not entirely sure whether `aria-current="page"` is more appropriate
than `aria-current="true"`, since it's a general helper which can be
used for any collection of links.
2020-12-07 15:28:56 +01:00
Javi Martín
55d2cfe5b1 Use link list helper in admin menus
For now we're not including lists with nested lists.
2020-12-07 15:28:56 +01:00
Javi Martín
c156621a4c Add method to generate a list of links
A list of links is a very common pattern in the web, and we use it in
many places. Here we're applying it to one of the most simple ones; the
help page.

Generally speaking, I'm not a big fan of helpers, but there are methods
which IMHO qualify as helpers when:

* They do not deal with application objects but mainly strings and
  arrays
* They return text or an HTML tag
* Their logic is simple and splitting it into several methods is not
  necessary

Many Rails helpers, like `tag`, follow these principles.
2020-12-07 15:28:56 +01:00
Senén Rodero Rodríguez
06dcbd699c Extract block to configure remote census in tests
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-11-02 11:42:39 +01:00
Javi Martín
5332ae609e Filter investments only by assigned staff
In commit 74083df1 we added the possibility to assign administrators and
valuators to budgets, so they would only manage the budgets they're
assigned to.

However, when filtering projects, we were still showing all
administrators and valuators as options to filter investments. It makes
more sense to only show the valuators and administrators assigned to the
current budget.

Note this change only affects the view, and so malicious users could
technically send any other administrator or valuator ID. In this case,
they would get empty results since those administrators/valuators
wouldn't have any investments assigned, so taking this case into account
is not necessary.
2020-09-08 19:11:38 +02:00
Ziyan Junaideen
1e3e8c1304 Add approval voting to budgets
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-08-06 12:38:18 +02:00
Javi Martín
958d373247 Fix duplicate records in investments by tag
When an investment had been assigned a user tag and a valuation tag with
the same name, it appeared twice when filtering by tag.

This is because by design, in order to provide compatibility with scopes
using "select" or "distinct", the method `tagged_with` doesn't select
unique records.

Forcing the query to return unique records solves the issue.
2020-04-09 21:09:28 +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
a04a289850 Simplify testing arrays exact contents
Instead of testing the contents of each element, we can test the whole
array at once.
2019-09-29 23:24:53 +02:00
Javi Martín
da121ebc53 Remove redundant setting resets in after blocks
Settings are stored in the database, and so any changes to the settings
done during the tests are automatically rolled back between one test and
the next one.

There were also a few places where we weren't using an `after` block but
changing the setting at the end of the test.
2019-09-23 13:47:45 +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
488461b8ac Remove consecutive blank lines 2019-09-10 20:02:15 +02:00
Javi Martín
71d9ddd849 Apply rule to end files with a newline character 2019-09-10 20:02:15 +02:00
taitus
5953e87c71 Update help text and add dynamic example text
- Display help text and example text according to
  remote census configuration:

  Examples with expecte results:
  * With remote census without :date_of_birth and :postal_code:
    -> "To verify a user, your application needs: Document number"
    -> "Required fields for each user must be separated by commas and
        each user must be separated by semicolons."
    -> "Example: 12345678Z; 87654321Y"

  * With remote census with :date_of_birth required:
    -> "To verify a user, your application needs: Document number,
        Day of birth (dd/mm/yyyy)"
    -> "Required fields for each user must be separated by commas and
        each user must be separated by semicolons."
    -> "Example: 12345678Z, 01/01/1980; 87654321Y, 01/02/1990"

  * With remote census with :date_of_birth and :postal_code required:
    -> "To verify a user, your application needs: Document number,
        Day of birth (dd/mm/yyyy) and Postal Code"
    -> "Required fields for each user must be separated by commas and
        each user must be separated by semicolons."
    -> "Example: 12345678Z, 01/01/1980, 28001; 87654321Y, 01/02/1990, 28002"
2019-07-29 13:10:09 +02:00
taitus
12b6b1df05 Add new param to partial '_setting_table'
When we reuse the partial '_setting_table' to render the 3 types
of remote census settings, we need customize setting_name key by
default to clarify the information to render.

- Add new param 'setting_name' to partial '_setting_table'
- Create new setting helper method to use new setting_name param
  to display a more clarify setting name on table.
2019-07-29 13:10:09 +02:00
voodoorai2000
cb9c3696f4 Use budget investments in useful specs 2019-05-31 18:23:03 +02:00
voodoorai2000
d0b8fef6b3 Delete spending proposals 2019-05-31 18:22:59 +02:00
Javi Martín
31515ddd45 Include blank and null ballots in booth totals
Just the same way it's done for all polls.
2019-05-30 17:22:41 +02:00
decabeza
f47ec9d7dc Fix hound warnings 2019-03-26 18:21:19 +01:00
decabeza
eda6ea7f12 Merge branch 'master' into dashboard 2019-03-26 16:45:48 +01:00
decabeza
26741d9560 Fix hound warnings 2019-02-20 13:56:58 +01:00
Julian Nicolas Herrero
53530ba99b Merge pull request #3287 from consul/use_double_quotes_in_specs
Change single quotes to double quotes in folder /spec
2019-02-18 13:26:49 +01:00
Javier Martín
b330de01f6 Merge pull request #3148 from matisnape/budget_investments_sorting_columns
Add sort links to admin tables
2019-02-15 19:19:11 +01:00
Julian Herrero
31ac8b7f55 Change single quotes to double quotes 2019-02-15 11:40:39 +01:00
decabeza
2695e19e2f Fix hound warnings 2019-01-29 17:54:02 +01:00
Manu
14d64e94d0 rspec tests were added for the process banner 2019-01-21 12:02:27 -05:00
Anna Anks Nowak
3fd7b3d216 Extract setting icon and direction to methods 2019-01-10 16:11:51 +01:00
decabeza
546105d989 Merge branch 'master' into dashboard-master 2018-10-19 01:48:37 +02:00
voodoorai2000
ccd342bb51 Fix flaky spec for translations
This spec was causing a side effect on another spec[2], making it fail 😌

I think it was because no translation had been called yet, in the failing spec, and so the the i18n backend translations had not been initialized, and was always returning empty translations for any locale. This might have been due to tampering with translations in the this newly introduced spec.

By forcing translations to load after this new spec, the other spec passes again

[2] https://github.com/AyuntamientoMadrid/consul/blob/master/spec/features/localization_spec.rb#L20
2018-10-10 12:47:40 +02:00
voodoorai2000
0a0261900c Display language name or language key
There where two issues with the current implementation:

- There was a possible duplication between looking up the language name in key "locale" and in key "i18n.language.name"

- The "default" option was not being picked up, as the fallback always returned the default locale's translation, "English"

With this implementation there is only a single place to put the language name: i18n.language.name. I think this place is easier to find and understand for Crowdin translators than a "locale" key hidden in general.yml

If the translation is not found we display the language key, instead of English, which makes more sense to me too 😌

Solution based on recent comments[1] on a related I18n issue

[1] https://github.com/svenfuchs/i18n/issues/365#issuecomment-419263847
2018-10-05 18:08:41 +02:00
Juan Salvador Pérez García
e5f9cf6710 Fixed #239
Proposals dashboard refactored to dashboard.
Added missing specs for the dashboard.
2018-07-24 15:52:43 +02:00
Juan Salvador Pérez García
8bb3d5b3ab frozen_string_literal removed
frozen_string_literal magic comment has been removed until a decission
is taken regarding to its convenience.
2018-07-17 17:53:18 +02:00