Commit Graph

1273 Commits

Author SHA1 Message Date
Javi Martín
7be72df5bf Remove redundant I18n resets in after blocks
We already configure `I18n.locale` and we reset Globalize's fallbacks
before every test.

On the other hand, RSpec automatically resets anything which is stub
with `allow`, so there's no need to use `and_call_original` in an
`after` block.
2019-09-23 13:47:45 +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
766f82a576 Apply RSpec/ExampleWording rubocop rule
This rule was improved in rubocop-rspec 1.35.0 and now it detects a case
it didn't detect in the past.
2019-09-19 16:31:23 +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
969a4e21c9 Apply RSpec/RepeatedExample rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
044eabd7ef Apply Rspec/LetSetup rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
58ba517717 Apply RSpec/ExampleWording rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
adc5906253 Apply Rails/PluralizationGrammar rubocop rule 2019-09-10 21:43:38 +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
e252d82cdb Apply IndentationWidth rubocop rule 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
Javier Martín
67ae821360 Merge pull request #3686 from consul/lowercase_tags
Fix flaky specs for uppercase tags
2019-09-10 15:04:17 +02:00
Javi Martín
49751f46ec Fix tests for uppercase tags
The tests in the `spec/lib/graphql_spec.rb` failed sometimes because
creating a record with a tag list of ["health"] when both "health" and
"Health" tags exist might assign either one of them. These tests usually
pass because we create two records and just by chance usually one of the
records gets one tag and the other one gets the other tag. However, the
test was written as if we expected the first record to get the first tag
and the second record to get the second tag, while very often the tests
were passing because the first record got the second tag and the second
record got the first tag. And when both records get the same tag, the
tests fail.

So I've changed these tests to tags are assigned directly and, since we
want to test the `tag_list` method, I've also added some tests to the
Tag model, which reflect the current behaviour: a random tag is assigned
when several tags with the same case-insensitive name exist.

Another option to assign the right tag to the record we're creating
would be to add `ActsAsTaggableOn.strict_case_match = true` to an
initializer. However, that would also create new tags on the database
when we accidentally assign a tag like "hEaLth" (like in the test we add
in this commit). Ideally we would have a strict case match for existing
tags and a non-strict case match for new tags, but I haven't found a way
to do it.
2019-09-07 16:43:41 +02:00
Javi Martín
b5d25134d4 Create less headings in budget investment tests
We don't need to create a heading every time we create an investment; we
can use an existing one by default.

Some tests are now much faster and don't fail on Travis due to reaching
Capybara's timeout anymore.
2019-09-07 13:26:52 +02:00
Javi Martín
c574a4d93a Fix DirectMessage.today on different time zones
The dates are saved on UTC times on the database. So, for example,
if living in West Australia, `Date.current.beginning_of_day` will be
stored as UTC's yesterday at 15:15:00, while `Date.current.end_of_day`
will be stored as UTC's today at 15:14:59.

When we use the `DATE` database function, PostgreSQL will select the
records with the same UTC date as the current UTC date. However, we need
the records with the same application date (as defined in
`config.time_zone`) as the current application date. The test passed
(for us) because we were using `beginning_of_day + 3.hours` to make sure
we were creating records when the date in Madrid was the same as the UTC
date.

Using a ruby interval for the time condition solves the problem.
2019-08-28 20:32:40 +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
bddfee2b86 Remove system count column for old polls
System count isn't a relevant number because the important one is the
number of votes counted by poll officers. We're still maintaining it for
a month in case poll officers would like to review the results.
2019-08-07 20:31:45 +02:00
taitus
6e62ea81a9 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
bc36c5a987 Allow to Management::Document works with CustomCensusAPI
- Allow receive new fields :date_of_birth and :postal_code
- Send new fields to CensusCaller call method to allow use
  on RemoteCensusAPI
2019-07-29 13:10:09 +02:00
taitus
b9a8e5a254 Houndci-bot: Resolve indentation suggestion 2019-07-29 13:10:09 +02:00
taitus
d07f9312e5 Allow any configuration of required fields
- Add the methods "parse_date_of_birth" and "parse_postal_code"
  to recover the correct position of their values depending on the
  configuration of the remote census.
2019-07-29 13:10:09 +02:00
taitus
626d2b3c2b Allow to Signature works with CustomCensusAPI
- Send new fields to CensusCaller call method to
  allow use on CustomCensusAPI
2019-07-29 13:10:09 +02:00
taitus
0bf88abcf1 Allow to SignatureSheet parse new fields
- In the previous version, each signature was equivalent to a document
  and we separated them by commas.
  Now each signature may also need the fields birth date and postal code.
  So we separated each signature with a semicolon and separated each of
  its fields by commas.
  Example old version: "12345678X, 87654321Y"
  Example new version:
  "12345678X, 31/12/1980, 28001; 87654321Y, 31/12/1981, 28002"

- Update translations:
 "Write the numbers separated by commas (,)" to
 "Write the numbers separated by semicolons (;)"
2019-07-29 13:10:09 +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
taitus
cc49587fe4 Update FailedCensusCall with new fields 2019-07-29 13:10:09 +02:00
taitus
ff5f7ad401 Naming: Ambiguos ‘date_of_birth'
Actually we are using 'date_of_birth' as method and as attribute
accessor.
- Refactor 'date_of_birth' method to 'response_date_of_birth’
2019-07-29 13:10:09 +02:00
taitus
dd14fd8649 Add new model presence validates
- Only validate :date_of_birth and :postal_code presence when the application
  has configured Custom Census and their alias fields has values.
- Only validate :year_of_birth presence when :date_of_birth is not configured
  to send to Custom Census
2019-07-29 13:10:09 +02:00
taitus
3e383d7c1f Add new fields to form
- Add :date_of_birth and :postal_code
- Only display new fields when aplication has configured the
custom census API and contains alias values for fields. Add 2
class Setting methods to check this feature:
  - force_presence_date_of_birth?
  - force_presence_postal_code?
2019-07-29 13:10:09 +02:00
taitus
2ba722a711 Allow to Officing::Residence works with CustomCensusAPI
- Allow receive new fields :date_of_birth and :postal_code
- Send new fields to CensusCaller call method to allow use on CustomCensusAPI
2019-07-29 13:10:09 +02:00
taitus
637675a1f5 Add content to the Remote Census Configuration tab
- Render remote census configuration content on settings index.
 - Update type method from Setting
   On Admin::SettingsController#index we are using 'all_settings' to
   group all settings by 'type' method.
   'type' method return the first part of key when split by '.'
   To allow use by example: all_settings["remote_census.general"]
   and recover only settings related with this key we have added new
   'elsif' on 'type' method.
2019-07-29 13:10:09 +02:00
Senén Rodero Rodríguez
615bfadca8 Add local_census_records importation model
This model without database allow us to validate incoming file extension and
headers and also does the following during importation process:

* Ignore empty rows
* Classifiy rows in two groups: created_records, invalid_records
2019-07-29 13:07:24 +02:00
Senén Rodero Rodríguez
0239efef9d Allow administrators to run local census records importation
Allow only administrator users to run local census records importation
process
2019-07-29 13:07:24 +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
d1587ecc62 Add sanitization to clear trailing whitespaces 2019-07-29 13:07:24 +02:00
Senén Rodero Rodríguez
f071ca6cb5 Create LocalCensusRecords index page
* Create admin controller and routes
* Add pagination
* Add search by document_number
* Add EN and ES translations
* Add index specs
* Add missing model specs
2019-07-29 13:07:24 +02:00
Senén Rodero Rodríguez
5fa1bd8a6f Allow administrator users the ability to manage all LocalCensusRecords
Also check that other kind of users are not able to manage
LocalCensusRecords.
2019-07-29 13:07:24 +02:00
taitus
91ba5ff879 Fix flakys specs 2019-06-27 09:21:18 +02:00
taitus
d2506358ef Fix found Hound violations 2019-06-27 09:21:18 +02:00
taitus
4272b60339 Create Remote Translations Caller
This module is used in a callback model and in charge of
  - extracting resources associated from RemoteTranslation and preparing
    its fields to be sent to the MicrosoftTranslateClient thought DelayedJobs
  - receive the response from MicrosoftTranslateClient and update resource
    with his translates

Co-authored-by: javierm <elretirao@gmail.com>
2019-06-27 09:21:18 +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
1565a5a71d Fix most of Hound offenses 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
e8f53cb8b7 Add translations to budget investments pg_search_scope
Some Budget::Investment attributes are now translatable so we need to
include all existing translations on pg_search model scope.
2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
88ce8d7990 Add sanitization shared spec to budget investment 2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
eb2e402a92 Fix budget investments sorting by title
As we cannot order budget investments by any translatable field through
AR queries we are doing the same using ruby Array sort method and doing
array pagination manually with Kaminari 'paginate_array' helper method.
2019-06-27 09:20:24 +02:00
Senén Rodero Rodríguez
bb2ee6dd3c Fix search_by_title_or_id method
Results were not including records without translations for current
locale (I18n.locale). Now we search for given title against all
translation fallbacks for current locale.
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
2079706845 Enable soft deletion of Proposal::Translations 2019-06-27 09:19:37 +02:00