Commit Graph

24 Commits

Author SHA1 Message Date
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
d410fcbc0e Split scope tests
In the scenario where we want to test scopes and use `match_array`, we
usually declare variables we never use, which raises a warning in the
Ruby interpreter (since the main cause for an unused variable is a
typo).

So I've decided to just split the tests into cases where every record is
returned and cases were no records are returned, just like we do in
other places.

There are several other options we've considered:

1. Don't declare unused variables, but declare the ones we use
2. Prefix unused variables with un underscore
3. Declare just one variable being an array containing all elements, and
access the elements using Array#[]
4. Don't declare any variables, and compare results against attributes
such as titles

None of these options was met with enthusiasm.
2019-09-30 15:46:58 +02:00
Javi Martín
f27beb1e47 Simplify testing array contents
We were testing for the size and the content of the elements when we
could test for the array itself.
2019-09-24 21:32:52 +02:00
Javi Martín
66334b5757 Add globalizable tests for all translatable models
So now we test in depth at the model level, and can be a bit more
relaxed about integration tests for translations.

Note we're defining some extra factories to make sure all translatable
attributes with presence validation rules are mandatory. This way we can
simplify the way we obtain required fields, using `required_attribute?`.
Otherwise, fields having an `unless` condition in their presence
validation rules would count as mandatory even when they're not.
2019-09-23 18:01:44 +02:00
Javi Martín
488461b8ac Remove consecutive blank lines 2019-09-10 20:02:15 +02:00
Javi Martín
dadbf873ba Order translations using ruby
Joining the translations table caused duplicate records to appear.
Ordering with SQL is simply too hard because we need to consider
fallback locales.

Thanks Senén for providing most of the tests in the poll spec.
2019-06-03 18:35:59 +02:00
Julian Herrero
31ac8b7f55 Change single quotes to double quotes 2019-02-15 11:40:39 +01:00
Julian Herrero
a963a99c55 Use correct scope to sort headings by name 2019-02-13 13:35:09 +01:00
Julian Herrero
29a704bd60 Show headings in budgets landing page when translations are missing 2019-02-13 13:35:09 +01:00
Julian Herrero
922600252c Make budget headings translatable 2019-02-13 13:35:07 +01:00
Julian Herrero
2081269a67 fix Hound violations 2019-01-02 10:46:31 +01:00
Julian Herrero
25e1afea48 fix map rendering for budget headings 2018-12-14 15:37:22 +01:00
Matheus Miranda
06f07b1139 Add map to sidebar on Heading's page
Signed-off-by: Matheus Miranda <matheusmirandalacerda@gmail.com>
2018-11-16 09:05:23 +01:00
Bertocq
198ff0cd1f Use updatable slug factory trait to sluggable concern
Slugs should only be updated on certain conditions, we need a trait that
meets that conditions and the name of the trait passed as a mandatory &
named argument on the sluggable concern
2018-02-04 23:04:48 +01:00
iagirre
0e11e21b2a Merged with master and solved conflicts 2018-01-10 13:23:39 +01:00
iagirre
f0724ce13a Changes suggested in the PR made 2018-01-10 13:13:05 +01:00
Bertocq
3e5b13ae4d Enable RSpec/LetBeforeExamples cop & fix issues
Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetBeforeExamples
2018-01-07 02:28:06 +01:00
Bertocq
c2b5083d4f Fix missing and extra spacing 2017-12-16 17:59:16 +01:00
iagirre
aed0013e79 Spec fixed 2017-10-31 15:54:17 +01:00
iagirre
bfcbb6c0ad Validation in model and in form added. When users makes the on focus on population field an explanation appears. Some specs added to test the model validations 2017-10-31 13:04:30 +01:00
iagirre
f7e96067b0 Actions for budgets' headings added. Edit headings, delete headings if not budget investments associated and add link in order to see budgets investments filtered by the heading.
Cambios para hacer commit:
	modificado:    app/controllers/admin/budget_headings_controller.rb
	modificado:    app/models/budget/heading.rb
	nuevo archivo: app/views/admin/budget_headings/_errors.html.erb
	nuevo archivo: app/views/admin/budget_headings/edit.js.erb
	nuevo archivo: app/views/admin/budget_headings/update.js.erb
	modificado:    app/views/admin/budgets/_group.html.erb
	nuevo archivo: app/views/admin/budgets/_heading.html.erb
	nuevo archivo: app/views/admin/budgets/_heading_form.html.erb
	modificado:    config/locales/en/activerecord.yml
	modificado:    config/locales/es/activerecord.yml
	modificado:    spec/features/admin/budgets_spec.rb
	modificado:    spec/models/budget/heading_spec.rb
2017-09-25 15:40:17 +02:00
Bertocq
512059e021 Increase Budget, Heading and Group model specs to cover slug uniqueness
Why:

* Slug must be unique among:
 1. Budget slug: among other budgets
 2. Group slug: among other groups from its budget
 3. Heading slug: among other headings from all the groups from its budget

How:

* Adding checks for all possible scenarios on each model specs
2017-07-05 12:33:17 +02:00
Bertocq
73e0a5a88d Add to Budget Budget::Heading Budget::Group specs the sluggable shared example
Why:

* Those classes have a slug attribute that needs to be filled

How:

* Just adding the shared example to Budget model spec, and creating the model spec file for Heading and Group to include it as well
2017-07-04 18:40:54 +02:00