Commit Graph

29 Commits

Author SHA1 Message Date
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
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
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
431074c99f Add save! method to ActiveModel models
This way we make it clear we expect records to be valid when we save
them, just like we do with ActiveRecord models.
2019-10-23 14:32:42 +02:00
Javi Martín
1004ac01f8 Add and apply Style/SafeNavigation rubocop rule
We were already using it most of the time, but not always.
2019-10-22 17:37:51 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
rgarcia
618c6f8f36 uses method instead of db attribute to check for sms verification 2017-09-06 12:25:55 +02:00
kikito
f0b8cfd4a2 Time.now -> Time.current 2016-11-23 19:19:19 +01:00
rgarcia
bb3c4c6399 adds consistency to ruby code style
Keep a blank line before and after private
Keep a blank line before and after protected
Remove extra empty line at class body end
Remove extra blank line
Add final newline
Use 2 (not 3) spaces for indentation
Use 2 (not 4) spaces for indentation
Remove space before comma
Add space after comma
Remove trailing whitespaces
Remove unnecessary spacing
Use snake_case for variable names
Do not use then for multi-line if
Remove unused block argument - i
Use the new Ruby 1.9 hash syntax
Remove unused assignment to variable
Indent when as deep as case
Align attributes
Align end with def
2016-11-15 11:18:43 +01:00
kikito
f596beaaf5 removes unnecessary conditions from before_actions in verification/letter_controller 2015-10-20 17:33:16 +02:00
kikito
18db6482f9 makes sure verifications only happen for signed in users when doing a letter verification 2015-10-20 17:18:28 +02:00
kikito
0d0806c9ae improvements in the letter verification error messages 2015-10-20 16:19:17 +02:00
rgarcia
5fe1bb3eee verifies the letter's code 2015-10-19 22:58:44 +02:00
rgarcia
5ac2784294 removes unnecessary layout 2015-10-19 20:32:55 +02:00
rgarcia
a6fd1fb489 moves letter verification to letter controller 2015-10-19 19:38:22 +02:00
rgarcia
fd8684e713 redirects to show after asking for letter 2015-10-19 19:32:53 +02:00
rgarcia
f0b1f1901e fixes typo 2015-09-28 12:05:06 +02:00
rgarcia
24a60bdbf2 removes unnecessary condition and flash 2015-09-28 11:59:03 +02:00
Alberto Garcia Cabeza
0b2cf1e2bb Changes final verification step page 2015-09-14 19:18:50 +02:00
Juanjo Bazán
f517d7f410 adds before action for verified users 2015-09-11 16:44:52 +02:00
rgarcia
abc68dc868 refactors lock tries [#279] 2015-09-10 20:26:49 +02:00
rgarcia
b7c1b4acee renames verify? methods [#395] 2015-09-10 20:08:11 +02:00
rgarcia
cdda0ec34a removes unused i18n key [#395] 2015-09-10 14:31:33 +02:00
rgarcia
16dd609ad0 adds verification tries to letter code [#332] 2015-09-10 11:43:25 +02:00
rgarcia
4d97063887 removes unused spec 2015-09-02 21:59:51 +02:00
rgarcia
99d779bcec adds letter code verification 2015-09-02 21:57:03 +02:00
Alberto Garcia Cabeza
da86c5d6e0 Adds styles for verification account process 2015-09-02 12:34:08 +02:00
Juanjo Bazán
50dcbcdf9b moves Letter to Verification namespace 2015-08-29 12:07:43 +02:00
rgarcia
f7d22f64b6 adds letter verification 2015-08-27 23:58:31 +02:00