Commit Graph

7361 Commits

Author SHA1 Message Date
Javi Martín
92bfc9ed17 Use text instead of IDs in feature specs
This way we write the tests from the user's point of view: users can see
(for example) a proposal with the title "Make everything awesome", but
they don't see a proposal with a certain ID.

There are probably dozens, if not hundreds, of places where we could
write tests this way. However, it's very hard to filter which ones are
safe to edit, since not many of them have an HTML class we can use in
the tests, and adding a class might generate conflicts with CSS styles.

So, for now, I'm only changing the ones allowing us to cleanly remove
useless assignements while maintaining the code vertically aligned.
2019-09-30 14:29:15 +02:00
Javi Martín
eac7427755 Remove line auto-assigning a variable to nil
This is one of the most strange behaviours in ruby: if a variable
doesn't exist, assigning to itself will return `nil`.

So a line like:

mdmkdfm = ooops if mdmkdfm.respond_to?(:uiqpior)

Surprisingly will not raise any errors: the nonexistent `mdmkdfm`
variable will be evaluated to `nil`, `mdmkdfm.respond_to?(:uiqpior)`
will evaluate to `nil.respond_to?(:uiqpior)`, which will return `false`,
and then the line will be evaluated as `mdmkdfm = ooops if false`, which
will return `nil`.

Maybe in the future Ruby will change this behaviour. We hope CONSUL is
now in better shape if that ever happens :).
2019-09-29 22:52:53 +02:00
Javi Martín
7ee9c0d042 Remove obsolete method to get voted headings
This method isn't used since commit e47cbe2a, where we replaced it with
`headings_voted_within_group`.
2019-09-29 22:31:13 +02:00
Javi Martín
3b11f8b567 Avoid duplicate records in current_or_recounting
Joining two scopes with `+` does not remove duplicate records. Luckily
now that we've upgraded to Rails 5, we can join scopes using `.or`.

The test was testing for the presence of elements, bud didn't test for
duplicate records. Testing the exact contents of the array revealed this
behaviour.
2019-09-26 19:58:02 +02:00
Javi Martín
45c6a70d91 Fix extra nil added to assigned investment IDs
When `valuator_group` was `nil`, `[valuator_group&.investment_ids]` is
evaluated to `nil`, and so we were adding an extra element to the array.

We could add a `compact` call to the resulting array, but I find it
easier to convert `nil` to an array using `to_a`.
2019-09-26 19:58:02 +02:00
Javi Martín
4e72d9f3b7 Remove useless assignments to return values 2019-09-25 12:43:44 +02:00
Javi Martín
9d627f2db9 Remove redundant I18nContent scope
Since two records cannot have the same key, having a scope that will
always return just one record is the same as using `find_by_key`.
2019-09-24 19:29:46 +02:00
Javi Martín
cb2069858c Remove unnecessary code
It looks like these variables were left by accident. The Ruby
interpreter was giving us warnings about unused variables.
2019-09-24 18:49:40 +02:00
Javi Martín
06030933a4 Remove obsolete poll answers variable
This code is obsolete since commit c6e4b248.
2019-09-24 18:29:33 +02:00
Javi Martín
f767f231dc Remove obsolete notices in booth assignments
This code is obsolete since commit 085e6ecb.
2019-09-24 18:26:11 +02:00
Javier Martín
989b2e23f7 Merge pull request #3711 from consul/fix_managers_suggestions
Allow managers to read investment suggestions
2019-09-24 14:32:20 +02:00
Senén Rodero Rodríguez
d1af36d1be Remove uneeded lines
Rails form already add an error class when image or document attachments
has validations errors.
2019-09-23 10:51:25 +02:00
Javier Martín
eaa87513c9 Merge pull request #3693 from DenisNikolski/booths-search
Add search form on admin booths
2019-09-22 03:09:50 +02:00
DenisNikolski
5627c8ccf4 add test for booths search 2019-09-21 16:25:20 +03:00
Javi Martín
53670602e0 Allow managers to read investment suggestions
When creating a budget investment with an unverified manager (for
example, a manager who isn't part of the local census), there's a
request to `Budgets::InvestmentsController#suggest`. Since the manager
isn't verified, suggestions can't be obtained.

There are serveral ways to fix this problem:

* Add a `suggest` action to Management::Budgets::InvestmentsController,
doing the same thing the main `suggest` action does.
* Give unverified users permission to access investment suggestions
* Give managers permission to access investment suggestions

I've chosen the last one because I thought it was simple and only
changed existing behaviour for managers, but any other solution would be
as valid. I haven't added the `phase: "accepting"` condition to keep it
simple, since a read-only action like this one in the management portal
isn't gonna create security risks.
2019-09-20 12:51:26 +02:00
Javier Martín
3c49ae3386 Merge pull request #3496 from LextrendIT/feature/refactor_embedded_video
Refactor embed video helper to disconnect from @proposal
2019-09-14 00:02:41 +02:00
DenisNikolski
6f085b5696 add search form on admin booths 2019-09-12 23:02:39 +03:00
Javier Martín
f5a6df4316 Merge pull request #3692 from consul/admin-booth-assignments
Hide polls created by users on admin poll booth assigments
2019-09-12 12:54:42 +02:00
Javier Martín
760deb1682 Merge pull request #3613 from consul/dashboard-related-content
Add related content section on proposal dashboard
2019-09-12 12:52:32 +02:00
decabeza
8440208597 Hide comments count on selected proposals 2019-09-11 22:18:43 +02:00
decabeza
1a0f0215a7 Hide related content on selected proposals 2019-09-11 22:18:42 +02:00
decabeza
b15048ec7d Hide proposal code on selected proposals 2019-09-11 22:17:40 +02:00
decabeza
e879fddba4 Hide view mode on selected proposals list 2019-09-11 22:17:40 +02:00
decabeza
abf04bea4c Add related content section on proposal dashboard 2019-09-11 19:45:19 +02:00
Javi Martín
9d6ed7a085 Show only defined columns on inserted rows
When we were inserting a row or replacing an existing one (just like we
do when we click the link to select an investment), we were entering a
row containing all columns, and all of them were displayed even if they
had been excluded using the column selector.

This caused the table to move in a strange way, which sometimes made the
investment selection tests fail.
2019-09-11 19:38:34 +02:00
Javi Martín
c6fc0062d7 Fix typo 2019-09-11 18:49:59 +02:00
decabeza
08e820c134 Hide polls created by users on admin poll booth assigments 2019-09-11 18:44:32 +02:00
Javier Martín
88afeda085 Merge pull request #3656 from consul/fix_alert_text
Fix text confirming investment heading support
2019-09-11 15:34:50 +02:00
Javi Martín
af6a494344 Apply JavaScript rule to use the dot notation
We were using the dot notation in most places, but not everywhere.
2019-09-11 14:03:24 +02:00
Javi Martín
044da18af1 Apply JavaScript rules to prevent shadowing
Using the same variable name makes the code more difficult to read.

We're also enabling the `no-param-reassing` rule since we accidentally
reassigned params in commit 824dd26d, and this rule will prevent us from
doing so in the future.
2019-09-11 14:03:24 +02:00
Javi Martín
86c9f53c2d Use undefined instead of void
We originally wrote `undefined` in CoffeeScript.

CoffeeScript compiled it to `void 0` when generating the JavaScript
files. However, the reason to do so was the `undefined` variable was
mutable before ECMAScript 5. Using `undefined` is more intuitive, and
nowadays there's no reason to use `void 0`.
2019-09-11 14:03:24 +02:00
Javi Martín
5211f47842 Add and apply ESLint spacing rules
For now we're only adding rules related to spacing and double quotes,
following the same rules we use in Ruby, which are the same rules
CoffeeScript followed when compiling these files.

We're also using the recommended ESLint rules, which will warn us about
many JavaScript common pitfalls, the `strict` rule which enforces using
strict mode, and the `no-console` rule, which will prevent us from
shipping code meant for debugging.

Although it's arguably more common to use the JSON format to define
these rules, I've chosen YAML because it's the format we use in all our
linters.
2019-09-11 14:03:24 +02:00
Javi Martín
ec5af1f1bc Remove unnecessary return statements
These statements were automatically added by CoffeeScript.

I'm only removing the obvious cases; there might be more cases where the
`return` statement isn't necessary.
2019-09-11 14:03:24 +02:00
Javi Martín
d93a029ce5 Convert CofeeScript to JavaScript
Compiled using `coffee -c` with CoffeeScript 1.12.6.
2019-09-11 14:03:24 +02:00
Javi Martín
2f10005739 Fix text confirming investment heading support
We accidentally removed the `count` option in commit 55fb14ac, which
made the translation return a hash.

The test is a bit hacky, which makes me think changing the user
interface would probably be a better solution.
2019-09-11 03:18:12 +02:00
Javi Martín
d8be18d6a9 Use double quotes in CoffeeScript
We accidentally added some single quotes recently.
2019-09-11 03:14:17 +02:00
Javi Martín
f83f0f08be Fix typo 2019-09-11 03:14:17 +02:00
Javi Martín
cc7e0d586b Reduce local variables usage in CoffeeScript
Local variables are one of the things CoffeeScript doesn't compile to
modern JavaScript automatically: it uses `var` instead of `const` or
`let`.

Besides, using `$this = $(this)` is usually done to reference the
current object in another function where the current object is a
different one. Here we were using it with no clear purpose.
2019-09-11 03:14:17 +02:00
Javi Martín
ba325526ae Use Array.apply to repeat a loop
In JavaScript we cannot easily repeat something N times, and
CoffeeScript's range loop compiles into complex JavaScript.

We could also use `Array.from({ length: N })`, but that's not supported
by old browsers like Internet Explorer 11.
2019-09-11 03:14:17 +02:00
Javi Martín
00d7c92e86 Don't assign in conditionals
The assignment operator can easily be mistaken with the equality
operator when used in a condition, making the code more difficult to
read.
2019-09-11 03:14:17 +02:00
Javi Martín
86e704d8a4 Use strict mode in JavaScript
Strict mode is supported by 98% of the browsers, including Internet
Explorer 10, and it helps developers avoid common JavaScript pitfalls.
2019-09-11 03:14:17 +02:00
Javi Martín
747767386a Use this instead of @ in CoffeeScript
We're using `this` most of the time, and it's what's used in JavaScript.
2019-09-11 03:14:17 +02:00
Javi Martín
aa458b8c87 Extract functions in foundation extras
In foundation extras we were assigning functions to local variables, but
in the rest of the CoffeeScript files we use them as object properties.
2019-09-11 03:14:17 +02:00
Javi Martín
dcc838b3d8 Make conditions easier to read
Combining both the inline and "traditional" `if` styles made the code
difficult to read, particularly when compiled to JavaScript.
2019-09-11 03:14:17 +02:00
Javi Martín
1634cd5263 Use each instead of $.each
Iterating through the jQuery elements with `each` is more similar to
other iterators we use. Furthermore, we avoid declaring the `index`
variable we don't use.
2019-09-11 03:14:17 +02:00
Javi Martín
3b5d295cdc Simplify function call 2019-09-11 03:14:17 +02:00
Javi Martín
879cc2571f Use different names for variable and parameter
Using the same name means from that point the name doesn't refer to the
original parameter, which might be confusing when reading the method.
2019-09-11 03:14:17 +02:00
Javi Martín
c55a1a9faf Simplify finding rows for sortable tables
Including the table body is more intuitive than excluding the first row
and the table foot.
2019-09-11 03:14:17 +02:00
Javi Martín
936aa7af0f Simplify adding rows to sortable tables
The `append` method can handle arrays, so there's no need to loop
through each element.

There's more to improve on this method, like the `asc` variable being
global to a table instead of depending on the current column, but for
now I'm only refactoring and maintaining the current behaviour.
2019-09-11 03:14:16 +02:00
Javi Martín
4d7c124188 Remove unnecessary conditions
The code won't do anything if there are no elements, so there's no need
to check that condition.
2019-09-11 03:14:16 +02:00