Commit Graph

38 Commits

Author SHA1 Message Date
Javi Martín
d18c627392 Add and apply Layout/EmptyLinesAfterModuleInclusion rule
This rule was added in rubocop 1.79. We were inconsistent about it, so
we're adding it to get more consistency.
2025-11-05 14:27:12 +01:00
taitus
9d7fa9d0f8 Unify notice responders for budget investments create action 2024-11-26 17:58:10 +01: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
11832cc07d Make it easier to customize allowed parameters
When customizing CONSUL, one of the most common actions is adding a new
field to a form.

This requires modifying the permitted/allowed parameters. However, in
most cases, the method returning these parameters returned an instance
of `ActionController::Parameters`, so adding more parameters to it
wasn't easy.

So customizing the code required copying the method returning those
parameters and adding the new ones. For example:

```
def something_params
  params.require(:something).permit(
    :one_consul_attribute,
    :another_consul_attribute,
    :my_custom_attribute
  )
end
```

This meant that, if the `something_params` method changed in CONSUL, the
customization of this method had to be updated as well.

So we're extracting the logic returning the parameters to a method which
returns an array. Now this code can be customized without copying the
original method:

```
alias_method :consul_allowed_params, :allowed_params

def allowed_params
  consul_allowed_params + [:my_custom_attribute]
end
```
2022-04-07 19:35:40 +02:00
Javi Martín
b671b9f4d8 Move investment form partial to a component 2021-07-09 03:51:59 +02:00
Javi Martín
758cdaf8d7 Extract controllers to support investments
Since we're going to add an action to remove supports, having a separate
controller makes things easier.

Note there was a strange piece of code which assumed users were not
verified if they couldn't vote investments. Now the code is also
strange, since it assumes users are not verified if they can't create
votes. We might need to revisit these conditions if our logic changes in
the future.
2021-06-14 14:42:03 +02:00
Javi Martín
071da81be6 Add notice when supporting an investment
It was hard to notice what was going on when supporting one investment
which was at the bottom of the investment index page.

I wonder whether we should add the title of the investment to this text;
I'm not doing so because we don't do that anywhere else.
2021-06-14 14:42:03 +02:00
Javi Martín
0214184b2d Remove investment supports query optimizations
In the previous commit I mentioned:

> If I'm right, the `investment_votes` instance variable only exists to
> avoid several database queries to get whether the current user has
> supported each of the investments.
>
> However, that doesn't make much sense when only one investment is
> shown.

Now let's discuss the case when there are several investments, like in
the investments index:

* There are 10 investments per page by default
* Each query takes less than a millisecond
* We still make a query per investment to check whether the current user
  voted in a different group
* AFAIK, there have been no performance tests showing these
  optimizations make the request to the investments index significantly
  faster
* These optimizations make the code way more complex than it is without
  them

Considering all these points, I'm removing the optimizations. I'm fine
with adding `includes` calls to preload records and avoid N+1 queries
even if there are no performance tests showing they make the application
faster because the effect on the code complexity is negligible. But
that's not the case here.

Note we're using `defined?` instead of the `||=` operator because the
`||=` operator will not serve its purpose when the result of the
operation returns `false`.
2021-06-14 14:41:57 +02:00
Javi Martín
5fab843184 Simplify managing investment votes
If I'm right, the `investment_votes` instance variable only exists to
avoid several database queries to get whether the current user has
supported each of the investments.

However, that doesn't make much sense when only one investment is shown.
In this case, the number of queries stays the same, and so we can
simplify the code by rendering the component with an optional parameter.
2021-06-14 14:41:51 +02:00
decabeza
0488b3735f Hide single heading select on new budget investment form 2021-06-11 12:37:56 +02:00
Melvin Lammerts
c34aa54122 Remove skip map checkbox 2021-06-03 11:13:52 +02:00
taitus
be6390cc71 Allow to create an investment with documents
In the Management section when creating an investment we were not passing the
document attributes, so we were never able to associate documents.

Make the nested_documentable spec compatible with the Management section.
2021-04-09 16:21:00 +02:00
taitus
82cd019b40 Allow to create an investment with images
In the Management section when creating an investment we were not passing the
images attributes, so we were never able to associate images.

Make the nested_imageable spec compatible with the Management section.
2021-04-09 16:20:59 +02:00
taitus
7a34a338f4 Allow to create an investment with a geolocation.
In the Management section when creating an investment we were not passing the
map attributes, so we were never able to associate a geolocation.
2021-04-09 16:20:59 +02:00
Javi Martín
b5bc3117ac Add feature flags on budget controllers
Although we had this feature flag in most places, we forgot to add it in
some of the controllers.
2021-03-31 14:53:14 +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
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
Senén Rodero Rodríguez
661ca5a568 Add budget investments translation interface
* Adapt translatable spec helper method to work with budget investments
* Remove old attributes from strong parameters
* Add missing locales to admin.yml and budgets.yml
* Change SpendingProposal.title_max_length and
  SpendingProposal.description_max_lenght to Budget::Investment methods
* Add budget investment translatable attribute translations
2019-06-27 09:20:24 +02:00
Julian Herrero
b122302c58 Use find instead of find_by_id
Better raise a 404 HTML NotFound exception than any other unexpected error.
2019-06-03 17:54:19 +02:00
rgarcia
998b4d9e39 Load budgets using slugs 2019-06-03 16:54:39 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
Julian Herrero
23b6e38915 Remove unused before_action 2019-01-25 08:54:28 +01:00
rgarcia
82a2dd622b hotfix to load categories on error 2018-12-28 09:43:08 +01:00
Julian Herrero
bf7112f090 make parameter 'skip_map' accessible on creating an investment 2018-12-27 18:39:27 +01:00
Raimond Garcia
22d28d9c79 Merge branch 'master' into issue#1575-tag-administration 2017-06-29 19:09:54 +02:00
Bertocq
f6fe9cc7d2 Fix all Layout/SpaceAroundOperators rubocop issues and remove file list from rubocop_todo list 2017-06-26 18:04:20 +02:00
Eduardo Martinez Echevarria
8dd52110db Use category scope instead of condition on kind on Tag 2017-06-23 17:34:55 +02:00
Juanjo Bazán
e922a11aa3 permits fields in management investment creation 2017-05-19 11:32:14 +02:00
rgarcia
17946b292b fixes specs 2017-01-13 16:37:39 +01:00
rgarcia
be10972406 fixes management specs 2017-01-08 13:39:01 +01:00
kikito
54bd5aeeb1 adds @budget param to apply_filters_and_search 2016-12-22 20:26:21 +01:00
kikito
2a258fc558 Refactors set_investment_votes 2016-12-14 13:42:12 +01:00
kikito
8d60ea1d3c Refactors apply_filters_and_search to inside investment model 2016-12-14 13:39:54 +01:00
kikito
748fd8becf Makes all tests pass in bi management 2016-12-07 19:16:37 +01:00
kikito
b3be1633af Fixes all management bi issues except filtering by geozone 2016-12-07 16:35:27 +01:00
kikito
e793a0d8e1 Adapts management::budget_investments to new budgets 2016-12-06 18:05:58 +01:00
kikito
882565aeca Adds more controller variables and uses them in investment controller 2016-12-05 17:35:40 +01:00
kikito
003056fe75 Moves bi management controller 2016-12-02 19:16:31 +01:00