From 631f396e755728c4b2ac3b070ed7389d3b5aabef Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 6 Jul 2017 11:16:53 +0200 Subject: [PATCH 01/26] Fix dev_seeds to comply with budget related uniqueness names --- db/dev_seeds.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index c0655bfe7..9a55b8c00 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -384,12 +384,12 @@ Budget::PHASES.each_with_index do |phase, i| ) ) - (1..([1, 2, 3].sample)).each do - group = budget.groups.create!(name: Faker::StarWars.planet) + (1..([1, 2, 3].sample)).each do |i| + group = budget.groups.create!(name: "#{Faker::StarWars.planet} #{i}") geozones = Geozone.reorder("RANDOM()").limit([2, 5, 6, 7].sample) geozones.each do |geozone| - group.headings << group.headings.create!(name: geozone.name, + group.headings << group.headings.create!(name: "#{geozone.name} #{i}", price: rand(1..100) * 100000, population: rand(1..50) * 10000) end From a9c928505d405e4ac63cb6f53fe8e982a382712c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 6 Jul 2017 15:56:51 +0200 Subject: [PATCH 02/26] Fix indentation on annotator overrides scss file --- app/assets/stylesheets/annotator_overrides.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/annotator_overrides.scss b/app/assets/stylesheets/annotator_overrides.scss index c2cbe68ff..fcc127ecd 100644 --- a/app/assets/stylesheets/annotator_overrides.scss +++ b/app/assets/stylesheets/annotator_overrides.scss @@ -132,7 +132,7 @@ background: hsla(51, 91, 75, 0.5); .weight-4 { - background: hsla(51, 91, 75, 0.75); + background: hsla(51, 91, 75, 0.75); } } From dbc3af917a7460fd87d048f332186de4bd929cad Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 7 Jul 2017 21:24:45 +0200 Subject: [PATCH 03/26] Update rubocop_todo list with rubocop --auto-gen-config --- .rubocop_todo.yml | 703 +++++++++++++++++++++++++++++++--------------- 1 file changed, 483 insertions(+), 220 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5ce274570..ffe5432ad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,268 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-11-25 13:34:56 +0100 using RuboCop version 0.45.0. +# on 2017-07-07 21:23:30 +0200 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 23 +# Cop supports --auto-correct. +# Configuration parameters: Include, TreatCommentsAsGroupSeparators. +# Include: **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + +# Offense count: 45 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedHashRocketStyle, SupportedHashRocketStyles, EnforcedColonStyle, SupportedColonStyles, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/AlignHash: + Exclude: + - 'app/controllers/officing/results_controller.rb' + - 'spec/controllers/legislation/annotations_controller_spec.rb' + - 'spec/features/admin/banners_spec.rb' + +# Offense count: 50 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: with_first_parameter, with_fixed_indentation +Layout/AlignParameters: + Enabled: false + +# Offense count: 11 +# Cop supports --auto-correct. +Layout/ClosingParenthesisIndentation: + Exclude: + - 'spec/features/site_customization/custom_pages_spec.rb' + - 'spec/models/legislation/annotation_spec.rb' + - 'spec/rails_helper.rb' + +# Offense count: 51 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: leading, trailing +Layout/DotPosition: + Exclude: + - 'app/controllers/admin/poll/officer_assignments_controller.rb' + - 'app/controllers/admin/poll/polls_controller.rb' + - 'app/controllers/admin/poll/recounts_controller.rb' + - 'app/controllers/officing/final_recounts_controller.rb' + - 'app/controllers/officing/recounts_controller.rb' + - 'app/controllers/officing/residence_controller.rb' + - 'app/controllers/officing/results_controller.rb' + - 'app/models/poll/officer.rb' + - 'app/models/tag_cloud.rb' + - 'app/models/verification/management/managed_user.rb' + - 'lib/merged_comment_tree.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'bin/rspec' + - 'bin/spring' + - 'spec/features/debates_spec.rb' + - 'spec/features/proposal_ballots_spec.rb' + - 'spec/features/proposals_spec.rb' + - 'spec/mailers/devise_mailer_spec.rb' + - 'spec/models/debate_spec.rb' + - 'spec/models/proposal_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'app/controllers/admin/budget_investment_milestones_controller.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundMethodBody: + Exclude: + - 'app/models/abilities/administrator.rb' + - 'lib/graph_ql/api_types_creator.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'spec/factories.rb' + - 'spec/models/proposal_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstParameterIndentation: + Exclude: + - 'app/controllers/users_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Layout/IndentArray: + EnforcedStyle: consistent + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/IndentHash: + Exclude: + - 'spec/controllers/legislation/annotations_controller_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent +Layout/IndentHeredoc: + Exclude: + - 'spec/factories.rb' + - 'spec/models/legislation/draft_version_spec.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: normal, rails +Layout/IndentationConsistency: + Exclude: + - 'spec/features/tracks_spec.rb' + - 'spec/models/budget/investment_spec.rb' + - 'spec/models/legislation/draft_version_spec.rb' + - 'spec/models/proposal_spec.rb' + +# Offense count: 23 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Layout/LeadingCommentSpace: + Exclude: + - 'Capfile' + - 'app/controllers/budgets/ballot/lines_controller.rb' + - 'spec/features/budgets/ballots_spec.rb' + - 'spec/features/comments/poll_questions_spec.rb' + - 'spec/features/officing/voters_spec.rb' + - 'spec/support/common_actions.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineArrayBraceLayout: + Exclude: + - 'app/controllers/valuation/budget_investments_controller.rb' + - 'app/controllers/valuation/spending_proposals_controller.rb' + - 'app/helpers/search_helper.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineHashBraceLayout: + Exclude: + - 'app/controllers/valuation/budget_investments_controller.rb' + - 'app/controllers/valuation/spending_proposals_controller.rb' + - 'app/models/budget/investment.rb' + - 'app/models/debate.rb' + - 'app/models/proposal.rb' + - 'app/models/spending_proposal.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'app/controllers/legislation/annotations_controller.rb' + - 'app/controllers/users_controller.rb' + - 'app/models/comment.rb' + - 'app/models/organization.rb' + - 'app/models/user.rb' + - 'spec/features/site_customization/custom_pages_spec.rb' + - 'spec/models/legislation/annotation_spec.rb' + - 'spec/rails_helper.rb' + +# Offense count: 71 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'app/controllers/admin/poll/officer_assignments_controller.rb' + - 'app/controllers/admin/poll/polls_controller.rb' + - 'app/controllers/admin/poll/recounts_controller.rb' + - 'app/controllers/officing/final_recounts_controller.rb' + - 'app/controllers/officing/recounts_controller.rb' + - 'app/controllers/officing/residence_controller.rb' + - 'app/controllers/officing/results_controller.rb' + - 'app/models/poll/officer.rb' + - 'app/models/tag_cloud.rb' + - 'app/models/verification/management/managed_user.rb' + - 'lib/merged_comment_tree.rb' + - 'spec/models/comment_spec.rb' + - 'spec/models/debate_spec.rb' + - 'spec/models/proposal_spec.rb' + - 'spec/models/user_spec.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/MultilineOperationIndentation: + Exclude: + - 'app/controllers/officing/results_controller.rb' + - 'app/helpers/users_helper.rb' + - 'app/helpers/valuation_helper.rb' + - 'app/models/user.rb' + - 'app/models/verification/letter.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceAfterColon: + Exclude: + - 'spec/features/admin/site_customization/pages_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceBeforeFirstArg: + Exclude: + - 'spec/factories.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/SpaceInsideRangeLiteral: + Exclude: + - 'app/models/legislation/annotation.rb' + +# Offense count: 38 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'spec/controllers/comments_controller_spec.rb' + - 'spec/controllers/debates_controller_spec.rb' + - 'spec/controllers/legislation/annotations_controller_spec.rb' + - 'spec/controllers/legislation/answers_controller_spec.rb' + - 'spec/lib/cache_spec.rb' + - 'spec/models/comment_spec.rb' + - 'spec/models/debate_spec.rb' + - 'spec/models/proposal_spec.rb' + - 'spec/models/user_spec.rb' + +# Offense count: 2 +Lint/HandleExceptions: + Exclude: + - 'app/controllers/legislation/annotations_controller.rb' + - 'spec/lib/graphql_spec.rb' + # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. @@ -14,79 +271,128 @@ Lint/InheritException: Exclude: - 'app/controllers/concerns/feature_flags.rb' -# Offense count: 13 +# Offense count: 1 +Lint/LiteralInCondition: + Exclude: + - 'app/models/budget/investment.rb' + +# Offense count: 51 Lint/ParenthesesAsGroupedExpression: Exclude: + - 'spec/factories.rb' - 'spec/features/admin/organizations_spec.rb' + - 'spec/features/budgets/investments_spec.rb' + - 'spec/features/campaigns_spec.rb' - 'spec/features/debates_spec.rb' + - 'spec/features/management/managed_users_spec.rb' + - 'spec/features/management/proposals_spec.rb' + - 'spec/features/management/spending_proposals_spec.rb' + - 'spec/features/management/users_spec.rb' - 'spec/features/proposals_spec.rb' - 'spec/models/debate_spec.rb' -# Offense count: 4 +# Offense count: 13 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: + Exclude: + - 'app/models/poll/final_recount.rb' + - 'app/models/poll/null_result.rb' + - 'app/models/poll/partial_result.rb' + - 'app/models/poll/recount.rb' + - 'app/models/poll/white_result.rb' + +# Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: - 'app/controllers/admin/spending_proposals_controller.rb' - 'app/models/ahoy/data_source.rb' + - 'lib/graph_ql/api_types_creator.rb' + - 'lib/graph_ql/query_type_creator.rb' + - 'spec/controllers/concerns/has_orders_spec.rb' + - 'spec/factories.rb' - 'spec/spec_helper.rb' -# Offense count: 5 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. Lint/UnusedMethodArgument: Exclude: - 'app/controllers/organizations/registrations_controller.rb' - - 'app/controllers/users/omniauth_callbacks_controller.rb' - 'app/controllers/users/registrations_controller.rb' + - 'app/mailers/mailer.rb' - 'app/models/abilities/everyone.rb' - - 'app/models/abilities/valuator.rb' -# Offense count: 135 +# Offense count: 278 Lint/UselessAssignment: Enabled: false -# Offense count: 41 -Metrics/AbcSize: - Max: 44 +# Offense count: 1 +Lint/Void: + Exclude: + - 'app/controllers/polls_controller.rb' -# Offense count: 4 +# Offense count: 74 +Metrics/AbcSize: + Max: 54 + +# Offense count: 454 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 1071 + +# Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 205 + Max: 256 -# Offense count: 5 +# Offense count: 10 Metrics/CyclomaticComplexity: - Max: 8 + Max: 10 -# Offense count: 52 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives. +# Offense count: 171 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 307 + Max: 2542 -# Offense count: 28 +# Offense count: 53 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 38 + Max: 49 -# Offense count: 2 +# Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 193 + Max: 214 -# Offense count: 3 +# Offense count: 7 Metrics/PerceivedComplexity: Max: 11 -# Offense count: 4 +# Offense count: 6 # Cop supports --auto-correct. Performance/RedundantMatch: Exclude: + - 'app/controllers/valuation/budget_investments_controller.rb' - 'app/controllers/valuation/spending_proposals_controller.rb' - 'app/helpers/embed_videos_helper.rb' -# Offense count: 4 +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. +Rails/Blank: + Exclude: + - 'app/controllers/management/base_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Rails/Delegate: + Exclude: + - 'app/models/poll/question.rb' + +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: Whitelist. # Whitelist: find_by_sql @@ -96,18 +402,38 @@ Rails/DynamicFindBy: - 'app/controllers/users/registrations_controller.rb' - 'spec/features/management/users_spec.rb' -# Offense count: 4 +# Offense count: 2 +Rails/FilePath: + Exclude: + - 'app/controllers/sandbox_controller.rb' + - 'spec/spec_helper.rb' + +# Offense count: 16 # Cop supports --auto-correct. # Configuration parameters: Include. # Include: app/models/**/*.rb Rails/FindBy: Exclude: + - 'app/models/budget/ballot.rb' + - 'app/models/geozone.rb' + - 'app/models/legislation/question.rb' + - 'app/models/officing/residence.rb' + - 'app/models/poll/voter.rb' - 'app/models/setting.rb' + - 'app/models/signature.rb' + - 'app/models/user.rb' - 'app/models/verification/email.rb' - 'app/models/verification/management/email.rb' - 'app/models/verification/residence.rb' -# Offense count: 24 +# Offense count: 1 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/HasAndBelongsToMany: + Exclude: + - 'app/models/poll.rb' + +# Offense count: 37 # Cop supports --auto-correct. # Configuration parameters: Include. # Include: spec/**/*, test/**/* @@ -117,20 +443,40 @@ Rails/HttpPositionalArguments: - 'spec/controllers/concerns/has_filters_spec.rb' - 'spec/controllers/concerns/has_orders_spec.rb' - 'spec/controllers/debates_controller_spec.rb' + - 'spec/controllers/graphql_controller_spec.rb' + - 'spec/controllers/legislation/annotations_controller_spec.rb' + - 'spec/controllers/legislation/answers_controller_spec.rb' - 'spec/controllers/management/sessions_controller_spec.rb' - 'spec/controllers/pages_controller_spec.rb' - 'spec/controllers/users/registrations_controller_spec.rb' -# Offense count: 12 +# Offense count: 20 Rails/OutputSafety: Exclude: + - 'app/controllers/admin/legislation/draft_versions_controller.rb' + - 'app/controllers/admin/legislation/processes_controller.rb' + - 'app/controllers/admin/legislation/questions_controller.rb' + - 'app/controllers/budgets/investments_controller.rb' - 'app/controllers/spending_proposals_controller.rb' - 'app/helpers/application_helper.rb' - 'app/helpers/text_with_links_helper.rb' - 'app/helpers/users_helper.rb' - 'app/helpers/valuation_helper.rb' -# Offense count: 9 +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. +Rails/Present: + Exclude: + - 'app/controllers/management/document_verifications_controller.rb' + +# Offense count: 70 +# Configuration parameters: Blacklist. +# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters +Rails/SkipsModelValidations: + Enabled: false + +# Offense count: 10 Style/AccessorMethodName: Exclude: - 'app/controllers/application_controller.rb' @@ -138,34 +484,17 @@ Style/AccessorMethodName: - 'app/controllers/management/proposals_controller.rb' - 'app/controllers/management/spending_proposals_controller.rb' - 'app/controllers/proposals_controller.rb' + - 'lib/merged_comment_tree.rb' -# Offense count: 30 +# Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/AlignHash: +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: braces, no_braces, context_dependent +Style/BracesAroundHashParameters: Exclude: - - 'spec/features/admin/banners_spec.rb' + - 'app/models/concerns/searchable.rb' -# Offense count: 21 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: with_first_parameter, with_fixed_indentation -Layout/AlignParameters: - Exclude: - - 'app/helpers/search_helper.rb' - - 'app/models/verification/management/email.rb' - - 'bin/rspec' - - 'bin/spring' - - 'spec/features/admin/spending_proposals_spec.rb' - - 'spec/features/spending_proposals_spec.rb' - - 'spec/features/valuation/spending_proposals_spec.rb' - - 'spec/features/verification/verified_user_spec.rb' - - 'spec/i18n_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/rails_helper.rb' - -# Offense count: 57 +# Offense count: 119 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: @@ -178,32 +507,28 @@ Style/ClassVars: - 'app/models/organization.rb' - 'app/models/user.rb' -# Offense count: 1 +# Offense count: 6 # Cop supports --auto-correct. -Layout/ClosingParenthesisIndentation: +Style/ColonMethodCall: Exclude: - - 'spec/rails_helper.rb' + - 'spec/models/budget/investment_spec.rb' -# Offense count: 4 +# Offense count: 12 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: + - 'app/controllers/admin/poll/booth_assignments_controller.rb' + - 'app/controllers/admin/poll/officer_assignments_controller.rb' + - 'app/controllers/admin/poll/questions_controller.rb' - 'app/controllers/comments_controller.rb' - 'app/controllers/management/spending_proposals_controller.rb' + - 'app/controllers/officing/final_recounts_controller.rb' + - 'app/controllers/officing/recounts_controller.rb' - 'app/controllers/spending_proposals_controller.rb' - 'app/controllers/verification/sms_controller.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: leading, trailing -Layout/DotPosition: - Exclude: - - 'app/models/banner.rb' - - 'app/models/tag_cloud.rb' - - 'app/models/verification/management/managed_user.rb' + - 'lib/graph_ql/api_types_creator.rb' # Offense count: 1 Style/DoubleNegation: @@ -216,79 +541,46 @@ Style/EmptyCaseCondition: Exclude: - 'app/models/concerns/verification.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Layout/FirstParameterIndentation: +# Offense count: 2 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Style/FileName: Exclude: - - 'app/controllers/users_controller.rb' + - 'Capfile' + - 'Gemfile' -# Offense count: 32 +# Offense count: 56 # Configuration parameters: MinBodyLength. Style/GuardClause: Enabled: false -# Offense count: 6 +# Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: MaxLineLength. Style/IfUnlessModifier: Exclude: - 'app/controllers/annotations_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/graphql_controller.rb' + - 'app/controllers/legislation/annotations_controller.rb' + - 'app/controllers/valuation/budget_investments_controller.rb' - 'app/controllers/verification/letter_controller.rb' - 'app/controllers/welcome_controller.rb' - 'app/helpers/embed_videos_helper.rb' + - 'app/mailers/mailer.rb' - 'app/models/proposal.rb' - 'app/models/spending_proposal.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/IndentArray: - EnforcedStyle: consistent - # Offense count: 4 # Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/IndentHash: - EnforcedStyle: consistent - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: normal, rails -Layout/IndentationConsistency: - Exclude: - - 'spec/features/tracks_spec.rb' - - 'spec/models/proposal_spec.rb' - -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Layout/IndentationWidth: - Exclude: - - 'app/controllers/annotations_controller.rb' - - 'app/helpers/flags_helper.rb' - - 'app/mailers/devise_mailer.rb' - - 'app/mailers/mailer.rb' - - 'app/models/ahoy/data_source.rb' - - 'app/models/comment_notifier.rb' - - 'app/models/concerns/search_cache.rb' - - 'spec/features/comments/proposals_spec.rb' - - 'spec/features/moderation/users_spec.rb' - - 'spec/features/tracks_spec.rb' - - 'spec/features/verification/verified_user_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: line_count_dependent, lambda, literal Style/Lambda: Exclude: - - 'app/models/banner.rb' + - 'app/models/comment.rb' - 'app/models/direct_message.rb' + - 'app/models/vote.rb' + - 'lib/graph_ql/api_types_creator.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -304,101 +596,58 @@ Style/MethodDefParentheses: Exclude: - 'spec/helpers/comments_helper_spec.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: symmetrical, new_line, same_line -Layout/MultilineArrayBraceLayout: - Exclude: - - 'app/controllers/valuation/spending_proposals_controller.rb' - - 'app/helpers/search_helper.rb' - # Offense count: 1 Style/MultilineBlockChain: Exclude: - 'app/controllers/valuation/spending_proposals_controller.rb' -# Offense count: 2 -# Cop supports --auto-correct. -Layout/MultilineBlockLayout: - Exclude: - - 'app/models/banner.rb' - - 'spec/features/users_auth_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: symmetrical, new_line, same_line -Layout/MultilineHashBraceLayout: - Exclude: - - 'app/controllers/valuation/spending_proposals_controller.rb' - - 'app/models/debate.rb' - - 'app/models/proposal.rb' - - 'app/models/spending_proposal.rb' - -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. Style/MultilineIfThen: Exclude: - 'app/controllers/management/users_controller.rb' - - 'lib/census_api.rb' -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: symmetrical, new_line, same_line -Layout/MultilineMethodCallBraceLayout: - Exclude: - - 'app/controllers/users_controller.rb' - - 'app/models/comment.rb' - - 'app/models/organization.rb' - - 'app/models/user.rb' - - 'spec/rails_helper.rb' - -# Offense count: 33 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'app/models/banner.rb' - - 'app/models/tag_cloud.rb' - - 'app/models/verification/management/managed_user.rb' - - 'spec/models/comment_spec.rb' - - 'spec/models/debate_spec.rb' - - 'spec/models/proposal_spec.rb' - - 'spec/models/user_spec.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/MultilineOperationIndentation: - Exclude: - - 'app/helpers/users_helper.rb' - - 'app/helpers/valuation_helper.rb' - - 'app/models/verification/letter.rb' - -# Offense count: 5 +# Offense count: 15 # Cop supports --auto-correct. Style/MutableConstant: Exclude: - 'app/models/activity.rb' + - 'app/models/budget/reclassified_vote.rb' + - 'app/models/legislation/draft_version.rb' + - 'app/models/poll/null_result.rb' + - 'app/models/poll/partial_result.rb' + - 'app/models/poll/white_result.rb' - 'app/models/proposal.rb' + - 'app/models/signature_sheet.rb' + - 'app/models/site_customization/content_block.rb' + - 'app/models/site_customization/image.rb' + - 'app/models/site_customization/page.rb' + - 'lib/graph_ql/api_types_creator.rb' - 'lib/tag_sanitizer.rb' - 'lib/wysiwyg_sanitizer.rb' -# Offense count: 17 +# Offense count: 29 # Cop supports --auto-correct. Style/NestedParenthesizedCalls: Exclude: - 'spec/features/debates_spec.rb' + - 'spec/features/emails_spec.rb' + - 'spec/features/valuation/budget_investments_spec.rb' - 'spec/features/valuation/spending_proposals_spec.rb' - 'spec/helpers/settings_helper_spec.rb' - 'spec/helpers/verification_helper_spec.rb' -# Offense count: 12 +# Offense count: 1 # Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Exclude: + - 'app/controllers/officing/results_controller.rb' + +# Offense count: 54 +# Cop supports --auto-correct. +# Configuration parameters: Strict. Style/NumericLiterals: MinDigits: 9 @@ -414,9 +663,9 @@ Style/NumericPredicate: - 'app/helpers/banners_helper.rb' - 'app/helpers/debates_helper.rb' - 'app/helpers/votes_helper.rb' + - 'app/models/budget/ballot.rb' - 'app/models/concerns/conflictable.rb' - 'app/models/concerns/taggable.rb' - - 'app/models/concerns/verification.rb' - 'app/models/debate.rb' - 'app/models/lock.rb' - 'app/models/user.rb' @@ -439,7 +688,7 @@ Style/ParenthesesAroundCondition: - 'app/models/debate.rb' - 'app/models/proposal.rb' -# Offense count: 6 +# Offense count: 11 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ # NamePrefixBlacklist: is_, has_, have_ @@ -451,10 +700,11 @@ Style/PredicateName: - 'app/controllers/concerns/has_orders.rb' - 'app/helpers/banners_helper.rb' - 'app/helpers/debates_helper.rb' + - 'app/models/budget/ballot.rb' - 'app/models/user.rb' - 'lib/census_api.rb' -# Offense count: 3 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: compact, exploded @@ -462,18 +712,20 @@ Style/RaiseArgs: Exclude: - 'app/controllers/management/base_controller.rb' - 'app/controllers/users/omniauth_callbacks_controller.rb' + - 'app/controllers/valuation/budget_investments_controller.rb' - 'app/controllers/valuation/spending_proposals_controller.rb' -# Offense count: 16 +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'app/controllers/graphql_controller.rb' + - 'app/models/legislation/annotation.rb' + +# Offense count: 55 # Cop supports --auto-correct. Style/RedundantParentheses: - Exclude: - - 'app/controllers/admin/settings_controller.rb' - - 'app/helpers/proposals_helper.rb' - - 'spec/features/admin/organizations_spec.rb' - - 'spec/features/debates_spec.rb' - - 'spec/features/proposals_spec.rb' - - 'spec/models/debate_spec.rb' + Enabled: false # Offense count: 3 # Cop supports --auto-correct. @@ -484,43 +736,54 @@ Style/RegexpLiteral: - 'app/helpers/embed_videos_helper.rb' - 'spec/customization_engine_spec.rb' -# Offense count: 2 +# Offense count: 6 # Cop supports --auto-correct. Style/RescueModifier: Exclude: - - 'app/controllers/concerns/commentable_actions.rb' + - 'app/controllers/budgets/investments_controller.rb' + - 'app/controllers/concerns/search.rb' - 'app/controllers/verification/sms_controller.rb' + - 'app/models/concerns/measurable.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil. +Style/SafeNavigation: + Exclude: + - 'app/models/signature.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiteralsInInterpolation: + Exclude: + - 'spec/features/budgets/investments_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArguments: + Exclude: + - 'app/controllers/legislation/answers_controller.rb' # Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'app/controllers/admin/settings_controller.rb' - - 'app/controllers/notifications_controller.rb' - - 'app/controllers/organizations/registrations_controller.rb' - - 'lib/manager_authenticator.rb' - - 'spec/factories.rb' - -# Offense count: 13 # Configuration parameters: SupportedStyles. +# SupportedStyles: snake_case, camelCase +Style/VariableName: + EnforcedStyle: snake_case + +# Offense count: 107 +# Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: snake_case, normalcase, non_integer Style/VariableNumber: - EnforcedStyle: normalcase + Enabled: false -# Offense count: 9 +# Offense count: 31 # Cop supports --auto-correct. # Configuration parameters: SupportedStyles, WordRegex. # SupportedStyles: percent, brackets Style/WordArray: EnforcedStyle: percent - MinSize: 3 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'app/models/concerns/searchable.rb' + MinSize: 9 From 8b2b21c6d7639e3de500fa94f59f06ea1da51e70 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 00:56:14 +0200 Subject: [PATCH 04/26] Remove Tolk, Crowdin substituted it Why: * Crowdin now hosts all consul translations publicly so anyone can contribute https://crowdin.com/project/consul/invite * Crowdin makes easy for non-tech people to contribute, once we have a demo site we'll be able to offer "on site" translation * If you still use Tolk, we recommend removing this commit (but adding tolk gem to ./Gemfile_custom file to avoid future merge conflicts) How: * Reverting changes introduced with 9610a6a933c950712c5b19f14f4f83c896cd42dd --- Gemfile | 1 - Gemfile.lock | 5 ----- config/initializers/tolk.rb | 25 --------------------- config/routes.rb | 1 - config/secrets.yml.example | 3 --- db/migrate/20170708225159_remove_tolk.rb | 10 +++++++++ db/schema.rb | 28 +----------------------- 7 files changed, 11 insertions(+), 62 deletions(-) delete mode 100644 config/initializers/tolk.rb create mode 100644 db/migrate/20170708225159_remove_tolk.rb diff --git a/Gemfile b/Gemfile index 0f00da1ba..929a88187 100644 --- a/Gemfile +++ b/Gemfile @@ -59,7 +59,6 @@ gem 'sitemap_generator', '~> 5.3.1' gem 'ahoy_matey', '~> 1.6.0' gem 'groupdate', '~> 3.2.0' # group temporary data -gem 'tolk', '~> 2.0.0' # Web interface for translations gem 'browser' gem 'turnout', '~> 2.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index de9002e3a..ad5c0383e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -387,7 +387,6 @@ GEM rvm1-capistrano3 (1.4.0) capistrano (~> 3.0) sshkit (>= 1.2) - safe_yaml (1.0.4) safely_block (0.2.0) errbase sass (3.4.23) @@ -445,9 +444,6 @@ GEM tilt (2.0.7) timecop (0.8.1) tins (1.13.2) - tolk (2.0.0) - rails (>= 4.0) - safe_yaml (>= 0.8.6) turbolinks (2.5.3) coffee-rails turnout (2.4.0) @@ -559,7 +555,6 @@ DEPENDENCIES spring spring-commands-rspec sprockets (~> 3.7.1) - tolk (~> 2.0.0) turbolinks turnout (~> 2.4.0) uglifier (~> 3.2.0) diff --git a/config/initializers/tolk.rb b/config/initializers/tolk.rb deleted file mode 100644 index 2284aa921..000000000 --- a/config/initializers/tolk.rb +++ /dev/null @@ -1,25 +0,0 @@ -# encoding: utf-8 - -# Tolk config file. Generated on January 14, 2016 12:09 -# See github.com/tolk/tolk for more informations - -Tolk.config do |config| - - # If you need to add a mapping do it like this : - # May we suggest you use http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - # config.mapping['en-AU'] = 'English (Australia)' - # config.mapping['es-MX'] = 'Spanish (Mexico)' - # config.mapping['fr-ES'] = 'Frañol !' - # config.mapping['is'] = 'Icelandic' - # config.mapping['vi'] = 'Vietnamese' - - # Master source of strings to be translated - config.primary_locale_name = 'en' -end - -Tolk::ApplicationController.authenticator = proc { - authenticate_or_request_with_http_basic do |username, password| - username == Rails.application.secrets.translate_username && - password == Rails.application.secrets.translate_password - end -} diff --git a/config/routes.rb b/config/routes.rb index bdf1e22f3..ea12cf1ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -416,7 +416,6 @@ Rails.application.routes.draw do end mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql' - mount Tolk::Engine => '/translate', :as => 'tolk' # more info pages get 'more-information', to: 'pages#show', id: 'more_info/index', as: 'more_info' diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 6e67e57c8..f67ea65c0 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -33,9 +33,6 @@ production: &production google_oauth2_key: "" google_oauth2_secret: "" - translate_username: "" - translate_password: "" - rollbar_server_token: "" server_name: "" diff --git a/db/migrate/20170708225159_remove_tolk.rb b/db/migrate/20170708225159_remove_tolk.rb new file mode 100644 index 000000000..d07c88ebb --- /dev/null +++ b/db/migrate/20170708225159_remove_tolk.rb @@ -0,0 +1,10 @@ +class RemoveTolk < ActiveRecord::Migration + def change + remove_index :tolk_translations, column: [:phrase_id, :locale_id] + remove_index :tolk_locales, column: :name + + drop_table :tolk_translations + drop_table :tolk_phrases + drop_table :tolk_locales + end +end diff --git a/db/schema.rb b/db/schema.rb index 0787b5ed1..440fb2a9a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170704105112) do +ActiveRecord::Schema.define(version: 20170708225159) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -860,32 +860,6 @@ ActiveRecord::Schema.define(version: 20170704105112) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree - create_table "tolk_locales", force: :cascade do |t| - t.string "name" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "tolk_locales", ["name"], name: "index_tolk_locales_on_name", unique: true, using: :btree - - create_table "tolk_phrases", force: :cascade do |t| - t.text "key" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "tolk_translations", force: :cascade do |t| - t.integer "phrase_id" - t.integer "locale_id" - t.text "text" - t.text "previous_text" - t.boolean "primary_updated", default: false - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "tolk_translations", ["phrase_id", "locale_id"], name: "index_tolk_translations_on_phrase_id_and_locale_id", unique: true, using: :btree - create_table "users", force: :cascade do |t| t.string "email", default: "" t.string "encrypted_password", default: "", null: false From 3dd459f18accd7941febcf37e3277febc55839d1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 11:59:51 +0200 Subject: [PATCH 05/26] Fix valuation english translation to English --- config/locales/en/valuation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en/valuation.yml b/config/locales/en/valuation.yml index ecfbc113f..e07cbc520 100644 --- a/config/locales/en/valuation.yml +++ b/config/locales/en/valuation.yml @@ -87,7 +87,7 @@ en: back: Back heading: Investment project info: Author info - association_name: Asociación + association_name: Association by: Sent by sent: Sent at geozone: Scope From dd8ff5284ffd4a8dc825e2f1ed4f14a32cb7212d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 13:06:44 +0200 Subject: [PATCH 06/26] Update Code of Conduct to contributor covenant 1.4 --- CODE_OF_CONDUCT.md | 76 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 65c05c574..e4bc6af67 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,22 +1,74 @@ -# Contributor Code of Conduct +# Contributor Covenant Code of Conduct -As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. +## Our Pledge -We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery -* Personal attacks -* Trolling or insulting/derogatory comments +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment -* Publishing other's private information, such as physical or electronic addresses, without explicit permission -* Other unethical or unprofessional conduct. +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. +## Our Responsibilities -This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) \ No newline at end of file +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at consul@madrid.es. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ From 0b967dac89fe019aea02062977cf6e10c5f3aca0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 13:37:15 +0200 Subject: [PATCH 07/26] Fix english translation for budget investment share --- config/locales/en/mailers.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index 65da97b55..3b6706929 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -72,7 +72,7 @@ en: follow_link: "Participatory Budgets" sincerely: "Sincerely," signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" - share: "Comparte tu proyecto" + share: "Share your project" budget_investment_unfeasible: hi: "Dear user," new_html: "For all these, we invite you to elaborate a new investment that ajusts to the conditions of this process. You can do it following this link: %{url}." @@ -100,4 +100,4 @@ en: participate_url: "participate in the final voting" thanks: "Thank you again for participating." sincerely: "Sincererly" - signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" \ No newline at end of file + signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" From b1caefdf9a842ce61568340827242bdc15511c2e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 13:14:56 +0200 Subject: [PATCH 08/26] Use i18n to localize date on view --- app/views/budgets/investments/_milestones.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/budgets/investments/_milestones.html.erb b/app/views/budgets/investments/_milestones.html.erb index 87cd1cdd6..53738979a 100644 --- a/app/views/budgets/investments/_milestones.html.erb +++ b/app/views/budgets/investments/_milestones.html.erb @@ -13,7 +13,7 @@

<%= milestone.title %>

- <%= t("budgets.investments.show.milestone_publish_date", publish_date: milestone.created_at.strftime("%d/%m/%Y")) %> + <%= t("budgets.investments.show.milestone_publish_date", publish_date: l(milestone.created_at.to_date)) %>

<%= milestone.description %>

From 824a672292e371df07b3e8f6ec3251e685efe5aa Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 14:35:45 +0200 Subject: [PATCH 09/26] Fix spectations for localized milestone date --- spec/features/budgets/investments_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index dfb64a755..937ae76ef 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -392,7 +392,8 @@ feature 'Budget Investments' do scenario "Show milestones", :js do user = create(:user) investment = create(:budget_investment) - milestone = create(:budget_investment_milestone, investment: investment, title: "New text to show") + milestone = create(:budget_investment_milestone, investment: investment, title: "New text to show", + created_at: DateTime.new(2015, 9, 19).utc) login_as(user) visit budget_investment_path(budget_id: investment.budget.id, id: investment.id) @@ -402,7 +403,7 @@ feature 'Budget Investments' do within("#tab-milestones") do expect(page).to have_content(milestone.title) expect(page).to have_content(milestone.description) - expect(page).to have_content("Published #{milestone.created_at.strftime("%d/%m/%Y")}") + expect(page).to have_content("Published 2015-09-19") end end From 51a22e87330850ae302bf7148b5bdf24370988f0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 17:07:56 +0200 Subject: [PATCH 10/26] Fix english translation string for figcaption --- config/locales/en/pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en/pages.yml b/config/locales/en/pages.yml index 0b23d63b1..e1c6bcc29 100644 --- a/config/locales/en/pages.yml +++ b/config/locales/en/pages.yml @@ -39,7 +39,7 @@ en: feature_3_html: "Then there is a support phase to prioritize the most interesting, the most supported are evaluated by the City to see if they are viable and how much they are worth." feature_4_html: "At the end there is a vote phase and you decide which of the approved projects to spend the budget on." image_alt: "Different phases of a participatory budget" - figcaption_html: '"Support phase" and "Voting" phase of participatory budgets.' + figcaption_html: '"Support" and "Voting" phases of participatory budgets.' polls: title: "Polls" description: "Citizen proposals that reach 1% of support will be put to a vote." @@ -81,4 +81,4 @@ en: info_code: 'Now introduce the code you received in letter:' password: Password submit: Verify my account - title: Verify your account \ No newline at end of file + title: Verify your account From 74e2c406d4e052fa4454e2148ea950be25422fb8 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 01:01:32 +0200 Subject: [PATCH 11/26] Upgrade initialjs-rails gem version In order to avoid some html validations a PR was opened https://github.com/dgilperez/initialjs-rails/pull/6 and later on merged with some extra specs coverage https://github.com/dgilperez/initialjs-rails/pull/7 Thanks @dgilperez and @decabeza!! --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 0f00da1ba..da6092296 100644 --- a/Gemfile +++ b/Gemfile @@ -42,7 +42,7 @@ gem 'ckeditor', '~> 4.2.3' gem 'invisible_captcha', '~> 0.9.2' gem 'cancancan', '~> 1.16.0' gem 'social-share-button', '~> 0.10' -gem 'initialjs-rails', '0.2.0.4' +gem 'initialjs-rails', '0.2.0.5' gem 'unicorn', '~> 5.3.0' gem 'paranoia', '~> 2.3.1' gem 'rinku', '~> 2.0.2', require: 'rails_rinku' diff --git a/Gemfile.lock b/Gemfile.lock index de9002e3a..9aa99d8b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -199,7 +199,7 @@ GEM parser (>= 2.2.3.0) rainbow (~> 2.2) terminal-table (>= 1.5.1) - initialjs-rails (0.2.0.4) + initialjs-rails (0.2.0.5) railties (>= 3.1, < 6.0) invisible_captcha (0.9.2) rails (>= 3.2.0) @@ -521,7 +521,7 @@ DEPENDENCIES graphql (~> 1.6.3) groupdate (~> 3.2.0) i18n-tasks (~> 0.9.15) - initialjs-rails (= 0.2.0.4) + initialjs-rails (= 0.2.0.5) invisible_captcha (~> 0.9.2) jquery-rails (~> 4.3.1) jquery-ui-rails From 4e4f316f944ec57b785e389c1b1f7ce1fe0ecf8e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 01:11:12 +0200 Subject: [PATCH 12/26] Reorganize development and test gems --- Gemfile | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index f0544aeb8..1e159fa14 100644 --- a/Gemfile +++ b/Gemfile @@ -74,24 +74,14 @@ gem 'graphql', '~> 1.6.3' gem 'graphiql-rails', '~> 1.4.1' group :development, :test do - # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-commands-rspec' - gem 'rspec-rails', '~> 3.6' - gem 'capybara', '~> 2.14.0' gem 'factory_girl_rails', '~> 4.8.0' - gem 'fuubar' gem 'launchy' gem 'quiet_assets' gem 'letter_opener_web', '~> 1.3.1' gem 'i18n-tasks', '~> 0.9.15' - gem 'capistrano', '~> 3.8.1', require: false - gem 'capistrano-bundler', '~> 1.2', require: false - gem "capistrano-rails", '~> 1.2.3', require: false - gem 'rvm1-capistrano3', require: false - gem 'capistrano3-delayed-job', '~> 1.7.3' gem "bullet", '~> 5.5.1' gem "faker", '~> 1.7.3' gem 'rubocop', '~> 0.49.1', require: false @@ -103,14 +93,20 @@ group :test do gem 'poltergeist', '~> 1.15.0' gem 'coveralls', '~> 0.8.21', require: false gem 'email_spec' + gem 'rspec-rails', '~> 3.6' + gem 'capybara', '~> 2.14.0' + gem 'fuubar' end group :development do gem 'mdl', require: false - # Access an IRB console on exception pages or by using <%= console %> in views gem 'scss_lint', require: false gem 'web-console', '3.3.0' - + gem 'capistrano', '~> 3.8.1', require: false + gem 'capistrano-bundler', '~> 1.2', require: false + gem "capistrano-rails", '~> 1.2.3', require: false + gem 'rvm1-capistrano3', require: false + gem 'capistrano3-delayed-job', '~> 1.7.3' end eval_gemfile './Gemfile_custom' From 5763ee03f4c374de249114058e8b541b41293fcc Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 01:11:46 +0200 Subject: [PATCH 13/26] Sort gem names alphabetically for dev and test groups --- Gemfile | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 1e159fa14..45d8fc526 100644 --- a/Gemfile +++ b/Gemfile @@ -74,39 +74,39 @@ gem 'graphql', '~> 1.6.3' gem 'graphiql-rails', '~> 1.4.1' group :development, :test do - gem 'byebug' - gem 'spring' - gem 'spring-commands-rspec' - gem 'factory_girl_rails', '~> 4.8.0' - gem 'launchy' - gem 'quiet_assets' - gem 'letter_opener_web', '~> 1.3.1' - gem 'i18n-tasks', '~> 0.9.15' gem "bullet", '~> 5.5.1' gem "faker", '~> 1.7.3' - gem 'rubocop', '~> 0.49.1', require: false + gem 'byebug' + gem 'factory_girl_rails', '~> 4.8.0' + gem 'i18n-tasks', '~> 0.9.15' gem 'knapsack' + gem 'launchy' + gem 'letter_opener_web', '~> 1.3.1' + gem 'quiet_assets' + gem 'rubocop', '~> 0.49.1', require: false + gem 'spring' + gem 'spring-commands-rspec' end group :test do - gem 'database_cleaner' - gem 'poltergeist', '~> 1.15.0' - gem 'coveralls', '~> 0.8.21', require: false - gem 'email_spec' - gem 'rspec-rails', '~> 3.6' gem 'capybara', '~> 2.14.0' + gem 'coveralls', '~> 0.8.21', require: false + gem 'database_cleaner' + gem 'email_spec' gem 'fuubar' + gem 'poltergeist', '~> 1.15.0' + gem 'rspec-rails', '~> 3.6' end group :development do - gem 'mdl', require: false - gem 'scss_lint', require: false - gem 'web-console', '3.3.0' + gem "capistrano-rails", '~> 1.2.3', require: false gem 'capistrano', '~> 3.8.1', require: false gem 'capistrano-bundler', '~> 1.2', require: false - gem "capistrano-rails", '~> 1.2.3', require: false - gem 'rvm1-capistrano3', require: false gem 'capistrano3-delayed-job', '~> 1.7.3' + gem 'mdl', require: false + gem 'rvm1-capistrano3', require: false + gem 'scss_lint', require: false + gem 'web-console', '3.3.0' end eval_gemfile './Gemfile_custom' From efa2e7c7743583dc6d61c777225c29d97035285f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 01:13:59 +0200 Subject: [PATCH 14/26] Remove bcrypt gem, never used --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index 45d8fc526..c6d6d79af 100644 --- a/Gemfile +++ b/Gemfile @@ -24,8 +24,6 @@ gem 'sprockets', '~> 3.7.1' gem 'devise', '~> 3.5.7' gem 'devise_security_extension' -# Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-facebook', '~> 4.0.0' From 100926162e7377709ba506c662906153f844510d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 01:15:35 +0200 Subject: [PATCH 15/26] Remove therubyracer gem, never used --- Gemfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Gemfile b/Gemfile index c6d6d79af..9ae636fc7 100644 --- a/Gemfile +++ b/Gemfile @@ -10,9 +10,6 @@ gem 'sass-rails', '~> 5.0', '>= 5.0.4' gem 'uglifier', '~> 3.2.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2.1' -# See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby - # Use jquery as the JavaScript library gem 'jquery-rails', '~> 4.3.1' gem 'jquery-ui-rails' From 862a30b4933c1bc46bea73934aa12aec1eca535f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 01:16:34 +0200 Subject: [PATCH 16/26] Remove unnecesary comments on gemfile --- Gemfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 9ae636fc7..549607124 100644 --- a/Gemfile +++ b/Gemfile @@ -1,22 +1,15 @@ source 'https://rubygems.org' -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.9' -# Use PostgreSQL + gem 'pg', '~> 0.20.0' -# Use SCSS for stylesheets gem 'sass-rails', '~> 5.0', '>= 5.0.4' -# Use Uglifier as compressor for JavaScript assets gem 'uglifier', '~> 3.2.0' -# Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2.1' -# Use jquery as the JavaScript library gem 'jquery-rails', '~> 4.3.1' gem 'jquery-ui-rails' -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' -# Fix sprockets on the gem 'sprockets', '~> 3.7.1' gem 'devise', '~> 3.5.7' From 3f9d95f6a3c3e771f70f55b75d08c2279e1db08e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 9 Jul 2017 01:39:06 +0200 Subject: [PATCH 17/26] Sort all gems in Gemfile --- .rubocop_todo.yml | 8 ---- Gemfile | 105 +++++++++++++++++++++------------------------- Gemfile.lock | 4 -- 3 files changed, 48 insertions(+), 69 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ffe5432ad..b21c1f65c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 23 -# Cop supports --auto-correct. -# Configuration parameters: Include, TreatCommentsAsGroupSeparators. -# Include: **/Gemfile, **/gems.rb -Bundler/OrderedGems: - Exclude: - - 'Gemfile' - # Offense count: 45 # Cop supports --auto-correct. # Configuration parameters: EnforcedHashRocketStyle, SupportedHashRocketStyles, EnforcedColonStyle, SupportedColonStyles, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. diff --git a/Gemfile b/Gemfile index 549607124..3b018afe4 100644 --- a/Gemfile +++ b/Gemfile @@ -2,70 +2,62 @@ source 'https://rubygems.org' gem 'rails', '4.2.9' -gem 'pg', '~> 0.20.0' -gem 'sass-rails', '~> 5.0', '>= 5.0.4' -gem 'uglifier', '~> 3.2.0' -gem 'coffee-rails', '~> 4.2.1' -gem 'jquery-rails', '~> 4.3.1' -gem 'jquery-ui-rails' -gem 'turbolinks' - -gem 'sprockets', '~> 3.7.1' - -gem 'devise', '~> 3.5.7' -gem 'devise_security_extension' -gem 'omniauth' -gem 'omniauth-twitter' -gem 'omniauth-facebook', '~> 4.0.0' -gem 'omniauth-google-oauth2', '~> 0.4.0' - -gem 'kaminari', '~> 1.0.1' -gem 'ancestry', '~> 2.2.2' gem 'acts-as-taggable-on' -gem 'responders', '~> 2.4.0' +gem 'acts_as_votable' +gem 'ahoy_matey', '~> 1.6.0' +gem 'ancestry', '~> 2.2.2' +gem 'browser' +gem 'cancancan', '~> 1.16.0' +gem 'ckeditor', '~> 4.2.3' +gem 'cocoon' +gem 'coffee-rails', '~> 4.2.1' +gem 'daemons' +gem 'dalli' +gem 'delayed_job_active_record', '~> 4.1.0' +gem 'devise', '~> 3.5.7' +gem 'devise-async' +gem 'devise_security_extension' gem 'foundation-rails', '~> 6.2.4.0' gem 'foundation_rails_helper', '~> 2.0.0' -gem 'acts_as_votable' -gem 'ckeditor', '~> 4.2.3' -gem 'invisible_captcha', '~> 0.9.2' -gem 'cancancan', '~> 1.16.0' -gem 'social-share-button', '~> 0.10' -gem 'initialjs-rails', '0.2.0.5' -gem 'unicorn', '~> 5.3.0' -gem 'paranoia', '~> 2.3.1' -gem 'rinku', '~> 2.0.2', require: 'rails_rinku' -gem 'savon' -gem 'dalli' -gem 'rollbar', '~> 2.14.1' -gem 'delayed_job_active_record', '~> 4.1.0' -gem 'daemons' -gem 'devise-async' -gem 'newrelic_rpm', '~> 4.1.0.333' -gem 'whenever', require: false -gem 'pg_search' -gem 'sitemap_generator', '~> 5.3.1' - -gem 'ahoy_matey', '~> 1.6.0' -gem 'groupdate', '~> 3.2.0' # group temporary data - -gem 'browser' -gem 'turnout', '~> 2.4.0' -gem 'redcarpet', '~> 3.4.0' -gem 'rubyzip', '~> 1.2.0' - -gem 'paperclip' -gem 'rails-assets-markdown-it', source: 'https://rails-assets.org' - -gem 'cocoon' - -gem 'graphql', '~> 1.6.3' gem 'graphiql-rails', '~> 1.4.1' +gem 'graphql', '~> 1.6.3' +gem 'groupdate', '~> 3.2.0' # group temporary data +gem 'initialjs-rails', '0.2.0.5' +gem 'invisible_captcha', '~> 0.9.2' +gem 'jquery-rails', '~> 4.3.1' +gem 'jquery-ui-rails' +gem 'kaminari', '~> 1.0.1' +gem 'newrelic_rpm', '~> 4.1.0.333' +gem 'omniauth' +gem 'omniauth-facebook', '~> 4.0.0' +gem 'omniauth-google-oauth2', '~> 0.4.0' +gem 'omniauth-twitter' +gem 'paperclip' +gem 'paranoia', '~> 2.3.1' +gem 'pg', '~> 0.20.0' +gem 'pg_search' +gem 'rails-assets-markdown-it', source: 'https://rails-assets.org' +gem 'redcarpet', '~> 3.4.0' +gem 'responders', '~> 2.4.0' +gem 'rinku', '~> 2.0.2', require: 'rails_rinku' +gem 'rollbar', '~> 2.14.1' +gem 'rubyzip', '~> 1.2.0' +gem 'sass-rails', '~> 5.0', '>= 5.0.4' +gem 'savon' +gem 'sitemap_generator', '~> 5.3.1' +gem 'social-share-button', '~> 0.10' +gem 'sprockets', '~> 3.7.1' +gem 'turbolinks' +gem 'turnout', '~> 2.4.0' +gem 'uglifier', '~> 3.2.0' +gem 'unicorn', '~> 5.3.0' +gem 'whenever', require: false group :development, :test do gem "bullet", '~> 5.5.1' - gem "faker", '~> 1.7.3' gem 'byebug' gem 'factory_girl_rails', '~> 4.8.0' + gem "faker", '~> 1.7.3' gem 'i18n-tasks', '~> 0.9.15' gem 'knapsack' gem 'launchy' @@ -81,15 +73,14 @@ group :test do gem 'coveralls', '~> 0.8.21', require: false gem 'database_cleaner' gem 'email_spec' - gem 'fuubar' gem 'poltergeist', '~> 1.15.0' gem 'rspec-rails', '~> 3.6' end group :development do - gem "capistrano-rails", '~> 1.2.3', require: false gem 'capistrano', '~> 3.8.1', require: false gem 'capistrano-bundler', '~> 1.2', require: false + gem "capistrano-rails", '~> 1.2.3', require: false gem 'capistrano3-delayed-job', '~> 1.7.3' gem 'mdl', require: false gem 'rvm1-capistrano3', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 64dc79385..a6eb21f32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -170,9 +170,6 @@ GEM activesupport (>= 4.1) railties (>= 4.1) tzinfo (~> 1.2, >= 1.2.2) - fuubar (2.2.0) - rspec-core (~> 3.0) - ruby-progressbar (~> 1.4) geocoder (1.4.3) globalid (0.4.0) activesupport (>= 4.2.0) @@ -512,7 +509,6 @@ DEPENDENCIES faker (~> 1.7.3) foundation-rails (~> 6.2.4.0) foundation_rails_helper (~> 2.0.0) - fuubar graphiql-rails (~> 1.4.1) graphql (~> 1.6.3) groupdate (~> 3.2.0) From 8f97bd86b7268bf669d533edebe7b28d7bf90be2 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 12:38:18 +0200 Subject: [PATCH 18/26] Specify version for all gems --- Gemfile | 62 ++++++++++++++++++++++++++-------------------------- Gemfile.lock | 60 +++++++++++++++++++++++++------------------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Gemfile b/Gemfile index 3b018afe4..678845e36 100644 --- a/Gemfile +++ b/Gemfile @@ -2,77 +2,77 @@ source 'https://rubygems.org' gem 'rails', '4.2.9' -gem 'acts-as-taggable-on' -gem 'acts_as_votable' +gem 'acts-as-taggable-on', '~> 4.0.0' +gem 'acts_as_votable', '~> 0.10.0' gem 'ahoy_matey', '~> 1.6.0' gem 'ancestry', '~> 2.2.2' -gem 'browser' +gem 'browser', '~> 2.3.0' gem 'cancancan', '~> 1.16.0' gem 'ckeditor', '~> 4.2.3' -gem 'cocoon' +gem 'cocoon', '~> 1.2.9' gem 'coffee-rails', '~> 4.2.1' -gem 'daemons' -gem 'dalli' +gem 'daemons', '~> 1.2.4' +gem 'dalli', '~> 2.7.6' gem 'delayed_job_active_record', '~> 4.1.0' gem 'devise', '~> 3.5.7' -gem 'devise-async' -gem 'devise_security_extension' +gem 'devise-async', '~> 0.10.2' +gem 'devise_security_extension', '~> 0.10.0' gem 'foundation-rails', '~> 6.2.4.0' gem 'foundation_rails_helper', '~> 2.0.0' gem 'graphiql-rails', '~> 1.4.1' gem 'graphql', '~> 1.6.3' -gem 'groupdate', '~> 3.2.0' # group temporary data -gem 'initialjs-rails', '0.2.0.5' +gem 'groupdate', '~> 3.2.0' +gem 'initialjs-rails', '~> 0.2.0.5' gem 'invisible_captcha', '~> 0.9.2' gem 'jquery-rails', '~> 4.3.1' -gem 'jquery-ui-rails' +gem 'jquery-ui-rails', '~> 6.0.1' gem 'kaminari', '~> 1.0.1' gem 'newrelic_rpm', '~> 4.1.0.333' -gem 'omniauth' +gem 'omniauth', '~> 1.6.1' gem 'omniauth-facebook', '~> 4.0.0' gem 'omniauth-google-oauth2', '~> 0.4.0' -gem 'omniauth-twitter' -gem 'paperclip' +gem 'omniauth-twitter', '~> 1.4.0' +gem 'paperclip', '~> 5.1.0' gem 'paranoia', '~> 2.3.1' gem 'pg', '~> 0.20.0' -gem 'pg_search' -gem 'rails-assets-markdown-it', source: 'https://rails-assets.org' +gem 'pg_search', '~> 2.0.1' +gem 'rails-assets-markdown-it', '~> 8.2.1', source: 'https://rails-assets.org' gem 'redcarpet', '~> 3.4.0' gem 'responders', '~> 2.4.0' gem 'rinku', '~> 2.0.2', require: 'rails_rinku' gem 'rollbar', '~> 2.14.1' gem 'rubyzip', '~> 1.2.0' gem 'sass-rails', '~> 5.0', '>= 5.0.4' -gem 'savon' +gem 'savon', '~> 2.11.1' gem 'sitemap_generator', '~> 5.3.1' gem 'social-share-button', '~> 0.10' gem 'sprockets', '~> 3.7.1' -gem 'turbolinks' +gem 'turbolinks', '~> 2.5.3' gem 'turnout', '~> 2.4.0' gem 'uglifier', '~> 3.2.0' gem 'unicorn', '~> 5.3.0' -gem 'whenever', require: false +gem 'whenever', '~> 0.9.7', require: false group :development, :test do gem "bullet", '~> 5.5.1' - gem 'byebug' + gem 'byebug', '~> 9.0.6' gem 'factory_girl_rails', '~> 4.8.0' gem "faker", '~> 1.7.3' gem 'i18n-tasks', '~> 0.9.15' - gem 'knapsack' - gem 'launchy' + gem 'knapsack', '~> 1.13.3' + gem 'launchy', '~> 2.4.3' gem 'letter_opener_web', '~> 1.3.1' - gem 'quiet_assets' + gem 'quiet_assets', '~> 1.1.0' gem 'rubocop', '~> 0.49.1', require: false - gem 'spring' - gem 'spring-commands-rspec' + gem 'spring', '~> 2.0.1' + gem 'spring-commands-rspec', '~> 1.0.4' end group :test do gem 'capybara', '~> 2.14.0' gem 'coveralls', '~> 0.8.21', require: false - gem 'database_cleaner' - gem 'email_spec' + gem 'database_cleaner', '~> 1.5.3' + gem 'email_spec', '~> 2.1.0' gem 'poltergeist', '~> 1.15.0' gem 'rspec-rails', '~> 3.6' end @@ -82,10 +82,10 @@ group :development do gem 'capistrano-bundler', '~> 1.2', require: false gem "capistrano-rails", '~> 1.2.3', require: false gem 'capistrano3-delayed-job', '~> 1.7.3' - gem 'mdl', require: false - gem 'rvm1-capistrano3', require: false - gem 'scss_lint', require: false - gem 'web-console', '3.3.0' + gem 'mdl', '~> 0.4.0', require: false + gem 'rvm1-capistrano3', '~> 1.4.0', require: false + gem 'scss_lint', '~> 0.53.0', require: false + gem 'web-console', '~> 3.3.0' end eval_gemfile './Gemfile_custom' diff --git a/Gemfile.lock b/Gemfile.lock index a6eb21f32..f2a314780 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -480,13 +480,13 @@ PLATFORMS ruby DEPENDENCIES - acts-as-taggable-on - acts_as_votable + acts-as-taggable-on (~> 4.0.0) + acts_as_votable (~> 0.10.0) ahoy_matey (~> 1.6.0) ancestry (~> 2.2.2) - browser + browser (~> 2.3.0) bullet (~> 5.5.1) - byebug + byebug (~> 9.0.6) cancancan (~> 1.16.0) capistrano (~> 3.8.1) capistrano-bundler (~> 1.2) @@ -494,17 +494,17 @@ DEPENDENCIES capistrano3-delayed-job (~> 1.7.3) capybara (~> 2.14.0) ckeditor (~> 4.2.3) - cocoon + cocoon (~> 1.2.9) coffee-rails (~> 4.2.1) coveralls (~> 0.8.21) - daemons - dalli - database_cleaner + daemons (~> 1.2.4) + dalli (~> 2.7.6) + database_cleaner (~> 1.5.3) delayed_job_active_record (~> 4.1.0) devise (~> 3.5.7) - devise-async - devise_security_extension - email_spec + devise-async (~> 0.10.2) + devise_security_extension (~> 0.10.0) + email_spec (~> 2.1.0) factory_girl_rails (~> 4.8.0) faker (~> 1.7.3) foundation-rails (~> 6.2.4.0) @@ -513,28 +513,28 @@ DEPENDENCIES graphql (~> 1.6.3) groupdate (~> 3.2.0) i18n-tasks (~> 0.9.15) - initialjs-rails (= 0.2.0.5) + initialjs-rails (~> 0.2.0.5) invisible_captcha (~> 0.9.2) jquery-rails (~> 4.3.1) - jquery-ui-rails + jquery-ui-rails (~> 6.0.1) kaminari (~> 1.0.1) - knapsack - launchy + knapsack (~> 1.13.3) + launchy (~> 2.4.3) letter_opener_web (~> 1.3.1) - mdl + mdl (~> 0.4.0) newrelic_rpm (~> 4.1.0.333) - omniauth + omniauth (~> 1.6.1) omniauth-facebook (~> 4.0.0) omniauth-google-oauth2 (~> 0.4.0) - omniauth-twitter - paperclip + omniauth-twitter (~> 1.4.0) + paperclip (~> 5.1.0) paranoia (~> 2.3.1) pg (~> 0.20.0) - pg_search + pg_search (~> 2.0.1) poltergeist (~> 1.15.0) - quiet_assets + quiet_assets (~> 1.1.0) rails (= 4.2.9) - rails-assets-markdown-it! + rails-assets-markdown-it (~> 8.2.1)! redcarpet (~> 3.4.0) responders (~> 2.4.0) rinku (~> 2.0.2) @@ -542,21 +542,21 @@ DEPENDENCIES rspec-rails (~> 3.6) rubocop (~> 0.49.1) rubyzip (~> 1.2.0) - rvm1-capistrano3 + rvm1-capistrano3 (~> 1.4.0) sass-rails (~> 5.0, >= 5.0.4) - savon - scss_lint + savon (~> 2.11.1) + scss_lint (~> 0.53.0) sitemap_generator (~> 5.3.1) social-share-button (~> 0.10) - spring - spring-commands-rspec + spring (~> 2.0.1) + spring-commands-rspec (~> 1.0.4) sprockets (~> 3.7.1) - turbolinks + turbolinks (~> 2.5.3) turnout (~> 2.4.0) uglifier (~> 3.2.0) unicorn (~> 5.3.0) - web-console (= 3.3.0) - whenever + web-console (~> 3.3.0) + whenever (~> 0.9.7) BUNDLED WITH 1.15.1 From 69f4e1c683d8f3c0f4fc390075226fa21119b359 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 7 Jul 2017 23:05:38 +0200 Subject: [PATCH 19/26] Fix all rubocop Metrics/LineLength issues (140+) --- .rubocop_todo.yml | 6 - app/controllers/account_controller.rb | 8 +- .../legislation/draft_versions_controller.rb | 7 +- .../admin/legislation/processes_controller.rb | 6 +- .../admin/legislation/questions_controller.rb | 6 +- .../poll/booth_assignments_controller.rb | 8 +- .../poll/officer_assignments_controller.rb | 13 +- .../admin/spending_proposals_controller.rb | 12 +- .../budgets/investments_controller.rb | 6 +- .../concerns/commentable_actions.rb | 5 +- .../legislation/annotations_controller.rb | 5 +- .../legislation/answers_controller.rb | 3 +- .../document_verifications_controller.rb | 5 +- .../management/proposals_controller.rb | 5 +- .../spending_proposals_controller.rb | 3 +- .../officing/final_recounts_controller.rb | 5 +- .../officing/recounts_controller.rb | 5 +- .../officing/results_controller.rb | 3 +- .../organizations/registrations_controller.rb | 3 +- app/controllers/proposals_controller.rb | 6 +- .../spending_proposals_controller.rb | 3 +- .../budget_investments_controller.rb | 19 +- .../spending_proposals_controller.rb | 21 ++- app/helpers/comments_helper.rb | 4 +- app/helpers/valuation_helper.rb | 6 +- app/mailers/mailer.rb | 3 +- app/models/abilities/administrator.rb | 3 +- app/models/abilities/moderator.rb | 3 +- app/models/budget/ballot/line.rb | 3 +- app/models/comment.rb | 4 +- app/models/legislation/answer.rb | 6 +- app/models/legislation/process.rb | 10 +- app/models/legislation/question.rb | 3 +- app/models/organization.rb | 6 +- app/models/proposal_notification.rb | 6 +- app/models/verification/residence.rb | 4 +- lib/census_api.rb | 22 ++- .../legislation/answers_controller_spec.rb | 9 +- spec/features/admin/poll/questions_spec.rb | 6 +- spec/features/budgets/investments_spec.rb | 6 +- .../comments/budget_investments_spec.rb | 12 +- spec/features/comments/debates_spec.rb | 12 +- .../comments/legislation_annotations_spec.rb | 164 +++++++++++++----- .../comments/legislation_questions_spec.rb | 15 +- spec/features/comments/proposals_spec.rb | 12 +- spec/features/debates_spec.rb | 3 +- spec/features/legacy_legislation_spec.rb | 6 +- .../legislation/draft_versions_spec.rb | 62 ++++--- .../management/budget_investments_spec.rb | 18 +- spec/features/proposal_notifications_spec.rb | 5 +- spec/features/proposals_spec.rb | 3 +- spec/features/users_auth_spec.rb | 3 +- spec/features/verification/letter_spec.rb | 3 +- .../level_three_verification_spec.rb | 3 +- spec/lib/census_api_spec.rb | 16 +- spec/lib/manager_authenticator_spec.rb | 5 +- spec/models/legislation/annotation_spec.rb | 86 +++++++-- spec/models/residence_spec.rb | 4 +- .../verification/management/document_spec.rb | 5 +- spec/support/common_actions.rb | 10 +- spec/support/verifiable.rb | 3 +- 61 files changed, 514 insertions(+), 203 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ffe5432ad..a2039a25a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -351,12 +351,6 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 10 -# Offense count: 171 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 2542 - # Offense count: 53 # Configuration parameters: CountComments. Metrics/MethodLength: diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index c46b6e42f..3b6808de9 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -23,10 +23,12 @@ class AccountController < ApplicationController def account_params if @account.organization? - params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name]) + params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, + organization_attributes: [:name, :responsible_name]) else - params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter, :official_position_badge) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, + :email_on_direct_message, :email_digest, :newsletter, :official_position_badge) end end -end \ No newline at end of file +end diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 0d84addbf..914745ba0 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -8,7 +8,8 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def create if @draft_version.save - redirect_to admin_legislation_process_draft_versions_path, notice: t('admin.legislation.draft_versions.create.notice', link: legislation_process_draft_version_path(@process, @draft_version).html_safe) + link = legislation_process_draft_version_path(@process, @draft_version).html_safe + redirect_to admin_legislation_process_draft_versions_path, notice: t('admin.legislation.draft_versions.create.notice', link: link) else flash.now[:error] = t('admin.legislation.draft_versions.create.error') render :new @@ -17,7 +18,9 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def update if @draft_version.update(draft_version_params) - redirect_to edit_admin_legislation_process_draft_version_path(@process, @draft_version), notice: t('admin.legislation.draft_versions.update.notice', link: legislation_process_draft_version_path(@process, @draft_version).html_safe) + link = legislation_process_draft_version_path(@process, @draft_version).html_safe + notice = t('admin.legislation.draft_versions.update.notice', link: link) + redirect_to edit_admin_legislation_process_draft_version_path(@process, @draft_version), notice: notice else flash.now[:error] = t('admin.legislation.draft_versions.update.error') render :edit diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index fb4e8ee3f..5d8d828cd 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -9,7 +9,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def create if @process.save - redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.create.notice', link: legislation_process_path(@process).html_safe) + link = legislation_process_path(@process).html_safe + redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.create.notice', link: link) else flash.now[:error] = t('admin.legislation.processes.create.error') render :new @@ -18,7 +19,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def update if @process.update(process_params) - redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.update.notice', link: legislation_process_path(@process).html_safe) + link = legislation_process_path(@process).html_safe + redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.update.notice', link: link) else flash.now[:error] = t('admin.legislation.processes.update.error') render :edit diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index c8335e6df..054e3e353 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -13,7 +13,8 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll def create @question.author = current_user if @question.save - redirect_to admin_legislation_process_questions_path, notice: t('admin.legislation.questions.create.notice', link: legislation_process_question_path(@process, @question).html_safe) + notice = t('admin.legislation.questions.create.notice', link: legislation_process_question_path(@process, @question).html_safe) + redirect_to admin_legislation_process_questions_path, notice: notice else flash.now[:error] = t('admin.legislation.questions.create.error') render :new @@ -22,7 +23,8 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll def update if @question.update(question_params) - redirect_to edit_admin_legislation_process_question_path(@process, @question), notice: t('admin.legislation.questions.update.notice', link: legislation_process_question_path(@process, @question).html_safe) + notice = t('admin.legislation.questions.update.notice', link: legislation_process_question_path(@process, @question).html_safe) + redirect_to edit_admin_legislation_process_question_path(@process, @question), notice: notice else flash.now[:error] = t('admin.legislation.questions.update.error') render :edit diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index f81382bf8..4eb591d02 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -15,12 +15,14 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController end def show - @booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id]) + @booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, + officer_assignments: [officer: [:user]]).find(params[:id]) @voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date} end def create - @booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll_id], booth_id: booth_assignment_params[:booth_id]) + @booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll_id], + booth_id: booth_assignment_params[:booth_id]) if @booth_assignment.save notice = t("admin.poll_booth_assignments.flash.create") @@ -63,4 +65,4 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController @search = search_params[:search] end -end \ No newline at end of file +end diff --git a/app/controllers/admin/poll/officer_assignments_controller.rb b/app/controllers/admin/poll/officer_assignments_controller.rb index f37ef9ab8..07f206f92 100644 --- a/app/controllers/admin/poll/officer_assignments_controller.rb +++ b/app/controllers/admin/poll/officer_assignments_controller.rb @@ -43,7 +43,9 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController else notice = t("admin.poll_officer_assignments.flash.error_create") end - redirect_to by_officer_admin_poll_officer_assignments_path(poll_id: create_params[:poll_id], officer_id: create_params[:officer_id]), notice: notice + + redirect_params = { poll_id: create_params[:poll_id], officer_id: create_params[:officer_id] } + redirect_to by_officer_admin_poll_officer_assignments_path(redirect_params), notice: notice end def destroy @@ -54,7 +56,9 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController else notice = t("admin.poll_officer_assignments.flash.error_destroy") end - redirect_to by_officer_admin_poll_officer_assignments_path(poll_id: @officer_assignment.poll_id, officer_id: @officer_assignment.officer_id), notice: notice + + redirect_params = { poll_id: @officer_assignment.poll_id, officer_id: @officer_assignment.officer_id } + redirect_to by_officer_admin_poll_officer_assignments_path(redirect_params), notice: notice end private @@ -68,7 +72,8 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController end def load_booth_assignment - @booth_assignment = ::Poll::BoothAssignment.includes(:poll).find_by(poll_id: create_params[:poll_id], booth_id: create_params[:booth_id]) + find_params = { poll_id: create_params[:poll_id], booth_id: create_params[:booth_id] } + @booth_assignment = ::Poll::BoothAssignment.includes(:poll).find_by(find_params) end def load_poll @@ -89,4 +94,4 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController @search = search_params[:search] end -end \ No newline at end of file +end diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index b5923f2f6..899a32486 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -7,7 +7,9 @@ class Admin::SpendingProposalsController < Admin::BaseController load_and_authorize_resource def index - @spending_proposals = SpendingProposal.scoped_filter(params, @current_filter).order(cached_votes_up: :desc, created_at: :desc).page(params[:page]) + @spending_proposals = SpendingProposal.scoped_filter(params, @current_filter) + .order(cached_votes_up: :desc, created_at: :desc) + .page(params[:page]) end def show @@ -33,13 +35,15 @@ class Admin::SpendingProposalsController < Admin::BaseController def summary @spending_proposals = SpendingProposal.group(:geozone).sum(:price).sort_by{|geozone, count| geozone.present? ? geozone.name : "z"} - @spending_proposals_with_supports = SpendingProposal.with_supports.group(:geozone).sum(:price).sort_by{|geozone, count| geozone.present? ? geozone.name : "z"} + @spending_proposals_with_supports = SpendingProposal.with_supports.group(:geozone).sum(:price) + .sort_by{|geozone, count| geozone.present? ? geozone.name : "z"} end private def spending_proposal_params - params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :administrator_id, :tag_list, valuator_ids: []) + params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, + :administrator_id, :tag_list, valuator_ids: []) end def load_admins @@ -54,4 +58,4 @@ class Admin::SpendingProposalsController < Admin::BaseController @tags = ActsAsTaggableOn::Tag.spending_proposal_tags end -end \ No newline at end of file +end diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 9ad48c1b7..16144cb27 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -28,7 +28,8 @@ module Budgets respond_to :html, :js def index - @investments = @investments.apply_filters_and_search(@budget, params, @current_filter).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render + @investments = @investments.apply_filters_and_search(@budget, params, @current_filter) + .send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render @investment_ids = @investments.pluck(:id) load_investment_votes(@investments) @tag_cloud = tag_cloud @@ -102,7 +103,8 @@ module Budgets end def investment_params - params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, :organization_name, :location, :terms_of_service) + params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, + :organization_name, :location, :terms_of_service) end def load_ballot diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 195d10459..62bcdaaac 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -88,7 +88,8 @@ module CommentableActions end def set_geozone - @resource.geozone = Geozone.find(params[resource_name.to_sym].try(:[], :geozone_id)) if params[resource_name.to_sym].try(:[], :geozone_id).present? + geozone_id = params[resource_name.to_sym].try(:[], :geozone_id) + @resource.geozone = Geozone.find(geozone_id) if geozone_id.present? end def load_categories @@ -109,4 +110,4 @@ module CommentableActions nil end -end \ No newline at end of file +end diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index fa46e5348..352fce266 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -102,8 +102,9 @@ class Legislation::AnnotationsController < ApplicationController end def convert_ranges_parameters - if params[:legislation_annotation] && params[:legislation_annotation][:ranges] && params[:legislation_annotation][:ranges].is_a?(String) - params[:legislation_annotation][:ranges] = JSON.parse(params[:legislation_annotation][:ranges]) + annotation = params[:legislation_annotation] + if annotation && annotation[:ranges] && annotation[:ranges].is_a?(String) + params[:legislation_annotation][:ranges] = JSON.parse(annotation[:ranges]) end rescue JSON::ParserError end diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb index 36f87de1f..2e7e058e7 100644 --- a/app/controllers/legislation/answers_controller.rb +++ b/app/controllers/legislation/answers_controller.rb @@ -18,9 +18,10 @@ class Legislation::AnswersController < Legislation::BaseController format.html { redirect_to legislation_process_question_path(@process, @question) } end else + alert = t('legislation.questions.participation.phase_not_open') respond_to do |format| format.js { render json: {}, status: :not_found } - format.html { redirect_to legislation_process_question_path(@process, @question), alert: t('legislation.questions.participation.phase_not_open') } + format.html { redirect_to legislation_process_question_path(@process, @question), alert: alert } end end end diff --git a/app/controllers/management/document_verifications_controller.rb b/app/controllers/management/document_verifications_controller.rb index 510e4fa93..687d8ee52 100644 --- a/app/controllers/management/document_verifications_controller.rb +++ b/app/controllers/management/document_verifications_controller.rb @@ -43,7 +43,8 @@ class Management::DocumentVerificationsController < Management::BaseController end def clean_document_number - params[:document_verification][:document_number] = params[:document_verification][:document_number].gsub(/[^a-z0-9]+/i, "").upcase unless params[:document_verification][:document_number].blank? + return if params[:document_verification][:document_number].blank? + params[:document_verification][:document_number] = params[:document_verification][:document_number].gsub(/[^a-z0-9]+/i, "").upcase end -end \ No newline at end of file +end diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb index 1a30526f5..54616c05b 100644 --- a/app/controllers/management/proposals_controller.rb +++ b/app/controllers/management/proposals_controller.rb @@ -34,7 +34,8 @@ class Management::ProposalsController < Management::BaseController end def proposal_params - params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :geozone_id) + params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, + :responsible_name, :tag_list, :terms_of_service, :geozone_id) end def resource_model @@ -53,4 +54,4 @@ class Management::ProposalsController < Management::BaseController @comment_flags = managed_user ? managed_user.comment_flags(comments) : {} end -end \ No newline at end of file +end diff --git a/app/controllers/management/spending_proposals_controller.rb b/app/controllers/management/spending_proposals_controller.rb index 6b2c4c0f1..f68c54f46 100644 --- a/app/controllers/management/spending_proposals_controller.rb +++ b/app/controllers/management/spending_proposals_controller.rb @@ -17,7 +17,8 @@ class Management::SpendingProposalsController < Management::BaseController @spending_proposal.author = managed_user if @spending_proposal.save - redirect_to management_spending_proposal_path(@spending_proposal), notice: t('flash.actions.create.notice', resource_name: t("activerecord.models.spending_proposal", count: 1)) + notice = t('flash.actions.create.notice', resource_name: t("activerecord.models.spending_proposal", count: 1)) + redirect_to management_spending_proposal_path(@spending_proposal), notice: notice else render :new end diff --git a/app/controllers/officing/final_recounts_controller.rb b/app/controllers/officing/final_recounts_controller.rb index 8be6e1a91..3efd6a682 100644 --- a/app/controllers/officing/final_recounts_controller.rb +++ b/app/controllers/officing/final_recounts_controller.rb @@ -15,7 +15,8 @@ class Officing::FinalRecountsController < Officing::BaseController end def create - @final_recount = ::Poll::FinalRecount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, date: final_recount_params[:date]) + @final_recount = ::Poll::FinalRecount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, + date: final_recount_params[:date]) @final_recount.officer_assignment_id = @officer_assignment.id @final_recount.count = final_recount_params[:count] @@ -45,4 +46,4 @@ class Officing::FinalRecountsController < Officing::BaseController params.permit(:officer_assignment_id, :count, :date) end -end \ No newline at end of file +end diff --git a/app/controllers/officing/recounts_controller.rb b/app/controllers/officing/recounts_controller.rb index 9e3989c05..b7ebf6acc 100644 --- a/app/controllers/officing/recounts_controller.rb +++ b/app/controllers/officing/recounts_controller.rb @@ -14,7 +14,8 @@ class Officing::RecountsController < Officing::BaseController end def create - @recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, date: @officer_assignment.date) + @recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, + date: @officer_assignment.date) @recount.officer_assignment_id = @officer_assignment.id @recount.count = recount_params[:count] @@ -44,4 +45,4 @@ class Officing::RecountsController < Officing::BaseController params.permit(:officer_assignment_id, :count) end -end \ No newline at end of file +end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index b6377e25b..3a921a0d9 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -126,7 +126,8 @@ class Officing::ResultsController < Officing::BaseController def load_partial_results if @officer_assignments.present? - @partial_results = ::Poll::PartialResult.where(officer_assignment_id: @officer_assignments.map(&:id)).order(:booth_assignment_id, :date) + @partial_results = ::Poll::PartialResult.where(officer_assignment_id: @officer_assignments.map(&:id)) + .order(:booth_assignment_id, :date) end end diff --git a/app/controllers/organizations/registrations_controller.rb b/app/controllers/organizations/registrations_controller.rb index a77534d8c..0fd45e9f7 100644 --- a/app/controllers/organizations/registrations_controller.rb +++ b/app/controllers/organizations/registrations_controller.rb @@ -32,7 +32,8 @@ class Organizations::RegistrationsController < Devise::RegistrationsController private def sign_up_params - params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, :terms_of_service, organization_attributes: [:name, :responsible_name]) + params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, :terms_of_service, + organization_attributes: [:name, :responsible_name]) end end diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 0dab0fa9e..8b75a10cf 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -74,7 +74,8 @@ class ProposalsController < ApplicationController private def proposal_params - params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :geozone_id) + params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, + :responsible_name, :tag_list, :terms_of_service, :geozone_id) end def retired_params @@ -109,7 +110,8 @@ class ProposalsController < ApplicationController end def load_featured - @featured_proposals = Proposal.not_archived.sort_by_confidence_score.limit(3) if (!@advanced_search_terms && @search_terms.blank? && @tag_filter.blank? && params[:retired].blank?) + return unless !@advanced_search_terms && @search_terms.blank? && @tag_filter.blank? && params[:retired].blank? + @featured_proposals = Proposal.not_archived.sort_by_confidence_score.limit(3) if @featured_proposals.present? set_featured_proposal_votes(@featured_proposals) @resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id)) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 5f8b04717..91ad8641c 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -30,7 +30,8 @@ class SpendingProposalsController < ApplicationController @spending_proposal.author = current_user if @spending_proposal.save - notice = t('flash.actions.create.spending_proposal', activity: "#{t('layouts.header.my_activity_link')}") + activity = "#{t('layouts.header.my_activity_link')}" + notice = t('flash.actions.create.spending_proposal', activity: activity) redirect_to @spending_proposal, notice: notice, flash: { html_safe: true } else render :new diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index c01f87c38..e64dcdb0d 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -12,11 +12,13 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController def index @heading_filters = heading_filters - if current_user.valuator? && @budget.present? - @investments = @budget.investments.scoped_filter(params_for_current_valuator, @current_filter).order(cached_votes_up: :desc).page(params[:page]) - else - @investments = Budget::Investment.none.page(params[:page]) - end + @investments = if current_user.valuator? && @budget.present? + @budget.investments.scoped_filter(params_for_current_valuator, @current_filter) + .order(cached_votes_up: :desc) + .page(params[:page]) + else + Budget::Investment.none.page(params[:page]) + end end def valuate @@ -63,11 +65,14 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController end def valuation_params - params.require(:budget_investment).permit(:price, :price_first_year, :price_explanation, :feasibility, :unfeasibility_explanation, :duration, :valuation_finished, :internal_comments) + params.require(:budget_investment).permit(:price, :price_first_year, :price_explanation, :feasibility, :unfeasibility_explanation, + :duration, :valuation_finished, :internal_comments) end def restrict_access_to_assigned_items - raise ActionController::RoutingError.new('Not Found') unless current_user.administrator? || Budget::ValuatorAssignment.exists?(investment_id: params[:id], valuator_id: current_user.valuator.id) + return if current_user.administrator? || + Budget::ValuatorAssignment.exists?(investment_id: params[:id], valuator_id: current_user.valuator.id) + raise ActionController::RoutingError.new('Not Found') end def valid_price_params? diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index 1273b80b6..53efcbc2e 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -10,11 +10,13 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def index @geozone_filters = geozone_filters - if current_user.valuator? - @spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(cached_votes_up: :desc).page(params[:page]) - else - @spending_proposals = SpendingProposal.none.page(params[:page]) - end + @spending_proposals = if current_user.valuator? + SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter) + .order(cached_votes_up: :desc) + .page(params[:page]) + else + SpendingProposal.none.page(params[:page]) + end end def valuate @@ -54,7 +56,8 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def valuation_params params[:spending_proposal][:feasible] = nil if params[:spending_proposal][:feasible] == 'nil' - params.require(:spending_proposal).permit(:price, :price_first_year, :price_explanation, :feasible, :feasible_explanation, :time_scope, :valuation_finished, :internal_comments) + params.require(:spending_proposal).permit(:price, :price_first_year, :price_explanation, :feasible, :feasible_explanation, + :time_scope, :valuation_finished, :internal_comments) end def params_for_current_valuator @@ -62,7 +65,9 @@ class Valuation::SpendingProposalsController < Valuation::BaseController end def restrict_access_to_assigned_items - raise ActionController::RoutingError.new('Not Found') unless current_user.administrator? || ValuationAssignment.exists?(spending_proposal_id: params[:id], valuator_id: current_user.valuator.id) + return if current_user.administrator? || + ValuationAssignment.exists?(spending_proposal_id: params[:id], valuator_id: current_user.valuator.id) + raise ActionController::RoutingError.new('Not Found') end def valid_price_params? @@ -77,4 +82,4 @@ class Valuation::SpendingProposalsController < Valuation::BaseController @spending_proposal.errors.empty? end -end \ No newline at end of file +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 3f760f73c..1936f843c 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -78,7 +78,9 @@ module CommentsHelper def require_verified_resident_for_commentable?(commentable, current_user) return false if current_user.administrator? || current_user.moderator? - commentable.respond_to?(:comments_for_verified_residents_only?) && commentable.comments_for_verified_residents_only? && !current_user.residence_verified? + commentable.respond_to?(:comments_for_verified_residents_only?) && + commentable.comments_for_verified_residents_only? && + !current_user.residence_verified? end def comments_closed_for_commentable?(commentable) diff --git a/app/helpers/valuation_helper.rb b/app/helpers/valuation_helper.rb index 4913b3d00..cc6a8e741 100644 --- a/app/helpers/valuation_helper.rb +++ b/app/helpers/valuation_helper.rb @@ -2,7 +2,9 @@ module ValuationHelper def valuator_select_options(valuator = nil) if valuator.present? - Valuator.where.not(id: valuator.id).order("description ASC").order("users.email ASC").includes(:user).collect { |v| [ v.description_or_email, v.id ] }.prepend([valuator.description_or_email, valuator.id]) + Valuator.where.not(id: valuator.id).order("description ASC").order("users.email ASC") + .includes(:user).collect { |v| [ v.description_or_email, v.id ] } + .prepend([valuator.description_or_email, valuator.id]) else Valuator.all.order("description ASC").order("users.email ASC").includes(:user).collect { |v| [ v.description_or_email, v.id ] } end @@ -27,4 +29,4 @@ module ValuationHelper simple_format_no_tags_no_sanitize(safe_html_with_links(field.html_safe)) if field.present? end -end \ No newline at end of file +end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index fc2d926b4..32a8ebe4b 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -11,7 +11,8 @@ class Mailer < ApplicationMailer @email_to = @commentable.author.email with_user(@commentable.author) do - mail(to: @email_to, subject: t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase)) if @commentable.present? && @commentable.author.present? + subject = t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase) + mail(to: @email_to, subject: subject) if @commentable.present? && @commentable.author.present? end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 2dd0d4031..bc2fea5d4 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -32,7 +32,8 @@ module Abilities can :mark_featured, Debate can :unmark_featured, Debate - can :comment_as_administrator, [Debate, Comment, Proposal, Poll::Question, Budget::Investment, Legislation::Question, Legislation::Annotation] + can :comment_as_administrator, [Debate, Comment, Proposal, Poll::Question, Budget::Investment, + Legislation::Question, Legislation::Annotation] can [:search, :create, :index, :destroy], ::Administrator can [:search, :create, :index, :destroy], ::Moderator diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index 479223b21..796bb185a 100644 --- a/app/models/abilities/moderator.rb +++ b/app/models/abilities/moderator.rb @@ -5,7 +5,8 @@ module Abilities def initialize(user) merge Abilities::Moderation.new(user) - can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll::Question, Legislation::Question, Legislation::Annotation] + can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll::Question, + Legislation::Question, Legislation::Annotation] end end end diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb index 2b70953f1..a3c24b631 100644 --- a/app/models/budget/ballot/line.rb +++ b/app/models/budget/ballot/line.rb @@ -22,7 +22,8 @@ class Budget end def check_valid_heading - errors.add(:heading, "This heading's budget is invalid, or a heading on the same group was already selected") unless ballot.valid_heading?(heading) + return if ballot.valid_heading?(heading) + errors.add(:heading, "This heading's budget is invalid, or a heading on the same group was already selected") end def check_selected diff --git a/app/models/comment.rb b/app/models/comment.rb index 44bb1f6f3..1db9809ee 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,6 +3,8 @@ class Comment < ActiveRecord::Base include HasPublicAuthor include Graphqlable + COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation).freeze + acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases acts_as_votable @@ -13,7 +15,7 @@ class Comment < ActiveRecord::Base validates :body, presence: true validates :user, presence: true - validates :commentable_type, inclusion: { in: ["Debate", "Proposal", "Budget::Investment", "Poll::Question", "Legislation::Question", "Legislation::Annotation"] } + validates :commentable_type, inclusion: { in: COMMENTABLE_TYPES } validate :validate_body_length diff --git a/app/models/legislation/answer.rb b/app/models/legislation/answer.rb index cd415d0d4..7ee6119b5 100644 --- a/app/models/legislation/answer.rb +++ b/app/models/legislation/answer.rb @@ -2,8 +2,10 @@ class Legislation::Answer < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :answers, counter_cache: true - belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', inverse_of: :answers, counter_cache: true + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', + inverse_of: :answers, counter_cache: true + belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', + inverse_of: :answers, counter_cache: true belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers validates :question, presence: true, uniqueness: { scope: :user_id} diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 59ab99433..b6043df57 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -4,8 +4,10 @@ class Legislation::Process < ActiveRecord::Base PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase draft_publication result_publication).freeze - has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id', dependent: :destroy - has_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' + has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', + foreign_key: 'legislation_process_id', dependent: :destroy + has_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', + foreign_key: 'legislation_process_id' has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id', dependent: :destroy validates :title, presence: true @@ -64,7 +66,9 @@ class Legislation::Process < ActiveRecord::Base def valid_date_ranges errors.add(:end_date, :invalid_date_range) if end_date && start_date && end_date < start_date errors.add(:debate_end_date, :invalid_date_range) if debate_end_date && debate_start_date && debate_end_date < debate_start_date - errors.add(:allegations_end_date, :invalid_date_range) if allegations_end_date && allegations_start_date && allegations_end_date < allegations_start_date + if allegations_end_date && allegations_start_date && allegations_end_date < allegations_start_date + errors.add(:allegations_end_date, :invalid_date_range) + end end end diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 09449b449..71ce100ea 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -5,7 +5,8 @@ class Legislation::Question < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' - has_many :question_options, -> { order(:id) }, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question + has_many :question_options, -> { order(:id) }, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', + dependent: :destroy, inverse_of: :question has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question has_many :comments, as: :commentable, dependent: :destroy diff --git a/app/models/organization.rb b/app/models/organization.rb index 37b46df55..e5b568818 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -35,7 +35,11 @@ class Organization < ActiveRecord::Base end def self.search(text) - text.present? ? joins(:user).where("users.email = ? OR users.phone_number = ? OR organizations.name ILIKE ?", text, text, "%#{text}%") : none + if text.present? + joins(:user).where("users.email = ? OR users.phone_number = ? OR organizations.name ILIKE ?", text, text, "%#{text}%") + else + none + end end def self.name_max_length diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index 9f36679a4..bd4211a85 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -14,8 +14,10 @@ class ProposalNotification < ActiveRecord::Base def minimum_interval return true if proposal.try(:notifications).blank? - if proposal.notifications.last.created_at > (Time.current - Setting[:proposal_notification_minimum_interval_in_days].to_i.days).to_datetime - errors.add(:title, I18n.t('activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid', interval: Setting[:proposal_notification_minimum_interval_in_days])) + interval = Setting[:proposal_notification_minimum_interval_in_days] + minimum_interval = (Time.current - interval.to_i.days).to_datetime + if proposal.notifications.last.created_at > minimum_interval + errors.add(:title, I18n.t('activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid', interval: interval)) end end diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index c14bba85d..9eaf89555 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -38,8 +38,8 @@ class Verification::Residence end def allowed_age - return if errors[:date_of_birth].any? - errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless Age.in_years(date_of_birth) >= User.minimum_required_age + return if errors[:date_of_birth].any? || Age.in_years(date_of_birth) >= User.minimum_required_age + errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) end def document_number_uniqueness diff --git a/lib/census_api.rb b/lib/census_api.rb index 1d945d904..066c0be95 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -92,7 +92,27 @@ class CensusApi end def stubbed_valid_response - {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: { item: {fecha_nacimiento_string: "31-12-1980", identificador_documento: "12345678Z", descripcion_sexo: "Varón", nombre: "José", apellido1: "García" }}, datos_vivienda: {item: {codigo_postal: "28013", codigo_distrito: "01"}}}}} + { + get_habita_datos_response: { + get_habita_datos_return: { + datos_habitante: { + item: { + fecha_nacimiento_string: "31-12-1980", + identificador_documento: "12345678Z", + descripcion_sexo: "Varón", + nombre: "José", + apellido1: "García" + } + }, + datos_vivienda: { + item: { + codigo_postal: "28013", + codigo_distrito: "01" + } + } + } + } + } end def stubbed_invalid_response diff --git a/spec/controllers/legislation/answers_controller_spec.rb b/spec/controllers/legislation/answers_controller_spec.rb index 569ea2879..629935643 100644 --- a/spec/controllers/legislation/answers_controller_spec.rb +++ b/spec/controllers/legislation/answers_controller_spec.rb @@ -13,7 +13,8 @@ describe Legislation::AnswersController do it 'should create an ahoy event' do sign_in @user - post :create, process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id } + post :create, process_id: @process.id, question_id: @question.id, + legislation_answer: { legislation_question_option_id: @question_option.id } expect(Ahoy::Event.where(name: :legislation_answer_created).count).to eq 1 expect(Ahoy::Event.last.properties['legislation_answer_id']).to eq Legislation::Answer.last.id end @@ -22,7 +23,8 @@ describe Legislation::AnswersController do sign_in @user expect do - xhr :post, :create, process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id } + xhr :post, :create, process_id: @process.id, question_id: @question.id, + legislation_answer: { legislation_question_option_id: @question_option.id } end.to change { @question.reload.answers_count }.by(1) end @@ -31,7 +33,8 @@ describe Legislation::AnswersController do @process.update_attribute(:debate_end_date, Date.current - 1.day) expect do - xhr :post, :create, process_id: @process.id, question_id: @question.id, legislation_answer: { legislation_question_option_id: @question_option.id } + xhr :post, :create, process_id: @process.id, question_id: @question.id, + legislation_answer: { legislation_question_option_id: @question_option.id } end.to_not change { @question.reload.answers_count } end end diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index 2a1e100f0..e9b9f277a 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -33,8 +33,10 @@ feature 'Admin poll questions' do poll = create(:poll, name: 'Movies') title = "Star Wars: Episode IV - A New Hope" description = %{ - During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet. - Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy.... + During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR, an armored space station + with enough power to destroy an entire planet. + Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her + people and restore freedom to the galaxy.... } visit admin_questions_path diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 937ae76ef..ca86587f0 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -593,9 +593,9 @@ feature 'Budget Investments' do end scenario 'Order by cost (only when balloting)' do - create(:budget_investment, :selected, heading: heading, title: 'Build a nice house', price: 1000).update_column(:confidence_score, 10) - create(:budget_investment, :selected, heading: heading, title: 'Build an ugly house', price: 1000).update_column(:confidence_score, 5) - create(:budget_investment, :selected, heading: heading, title: 'Build a skyscraper', price: 20000) + create(:budget_investment, :selected, heading: heading, title: 'Build a nice house', price: 1000).update_column(:confidence_score, 10) + create(:budget_investment, :selected, heading: heading, title: 'Build an ugly house', price: 1000).update_column(:confidence_score, 5) + create(:budget_investment, :selected, heading: heading, title: 'Build a skyscraper', price: 20000) visit budget_investments_path(budget, heading_id: heading.id) diff --git a/spec/features/comments/budget_investments_spec.rb b/spec/features/comments/budget_investments_spec.rb index 7e96b1f80..587a1c517 100644 --- a/spec/features/comments/budget_investments_spec.rb +++ b/spec/features/comments/budget_investments_spec.rb @@ -62,9 +62,12 @@ feature 'Commenting Budget::Investments' do end scenario 'Comment order' do - c1 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + c1 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) visit budget_investment_path(investment.budget, investment, order: :most_voted) @@ -118,7 +121,8 @@ feature 'Commenting Budget::Investments' do end scenario 'Sanitizes comment body for security' do - create :comment, commentable: investment, body: " click me http://www.url.com" + create :comment, commentable: investment, + body: " click me http://www.url.com" visit budget_investment_path(investment.budget, investment) diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index 2a4d46ec3..76320a848 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -62,9 +62,12 @@ feature 'Commenting debates' do end scenario 'Comment order' do - c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) visit debate_path(debate, order: :most_voted) @@ -118,7 +121,8 @@ feature 'Commenting debates' do end scenario 'Sanitizes comment body for security' do - create :comment, commentable: debate, body: " click me http://www.url.com" + create :comment, commentable: debate, + body: " click me http://www.url.com" visit debate_path(debate) diff --git a/spec/features/comments/legislation_annotations_spec.rb b/spec/features/comments/legislation_annotations_spec.rb index 7727d8204..87896df03 100644 --- a/spec/features/comments/legislation_annotations_spec.rb +++ b/spec/features/comments/legislation_annotations_spec.rb @@ -8,7 +8,9 @@ feature 'Commenting legislation questions' do scenario 'Index' do 3.times { create(:comment, commentable: legislation_annotation) } - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) expect(page).to have_css('.comment', count: 4) @@ -24,6 +26,9 @@ feature 'Commenting legislation questions' do parent_comment = create(:comment, commentable: legislation_annotation) first_child = create(:comment, commentable: legislation_annotation, parent: parent_comment) second_child = create(:comment, commentable: legislation_annotation, parent: parent_comment) + href = legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) visit comment_path(parent_comment) @@ -32,7 +37,7 @@ feature 'Commenting legislation questions' do expect(page).to have_content first_child.body expect(page).to have_content second_child.body - expect(page).to have_link "Go back to #{legislation_annotation.title}", href: legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + expect(page).to have_link "Go back to #{legislation_annotation.title}", href: href end scenario 'Collapsable comments', :js do @@ -40,7 +45,9 @@ feature 'Commenting legislation questions' do child_comment = create(:comment, body: "First subcomment", commentable: legislation_annotation, parent: parent_comment) grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_annotation, parent: child_comment) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) expect(page).to have_css('.comment', count: 3) @@ -62,21 +69,33 @@ feature 'Commenting legislation questions' do end scenario 'Comment order' do - c1 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + c1 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :most_voted) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation, + order: :most_voted) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :newest) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation, + order: :newest) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :oldest) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation, + order: :oldest) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) @@ -88,17 +107,26 @@ feature 'Commenting legislation questions' do old_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current - 10) new_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :most_voted) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation, + order: :most_voted) expect(new_root.body).to appear_before(old_root.body) expect(old_child.body).to appear_before(new_child.body) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :newest) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation, + order: :newest) expect(new_root.body).to appear_before(old_root.body) expect(new_child.body).to appear_before(old_child.body) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :oldest) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation, + order: :oldest) expect(old_root.body).to appear_before(new_root.body) expect(old_child.body).to appear_before(new_child.body) @@ -107,7 +135,9 @@ feature 'Commenting legislation questions' do scenario 'Turns links into html links' do create :comment, commentable: legislation_annotation, body: 'Built with http://rubyonrails.org/' - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) within all('.comment').last do expect(page).to have_content 'Built with http://rubyonrails.org/' @@ -118,9 +148,12 @@ feature 'Commenting legislation questions' do end scenario 'Sanitizes comment body for security' do - create :comment, commentable: legislation_annotation, body: " click me http://www.url.com" + create :comment, commentable: legislation_annotation, + body: " click me http://www.url.com" - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) within all('.comment').last do expect(page).to have_content "click me http://www.url.com" @@ -133,7 +166,9 @@ feature 'Commenting legislation questions' do per_page = 10 (per_page + 2).times { create(:comment, commentable: legislation_annotation)} - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) expect(page).to have_css('.comment', count: per_page) within("ul.pagination") do @@ -149,7 +184,9 @@ feature 'Commenting legislation questions' do feature 'Not logged user' do scenario 'can not see comments forms' do create(:comment, commentable: legislation_annotation) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) expect(page).to have_content 'You must Sign in or Sign up to leave a comment' within('#comments') do @@ -161,7 +198,9 @@ feature 'Commenting legislation questions' do scenario 'Create', :js do login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: 'Have you thought about...?' click_button 'Publish comment' @@ -174,7 +213,9 @@ feature 'Commenting legislation questions' do scenario 'Errors on create', :js do login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) click_button 'Publish comment' @@ -188,7 +229,9 @@ feature 'Commenting legislation questions' do comment = legislation_annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) click_link "Reply" @@ -208,7 +251,9 @@ feature 'Commenting legislation questions' do comment = legislation_annotation.comments.first login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) click_link "Reply" @@ -227,7 +272,10 @@ feature 'Commenting legislation questions' do parent = parent.children.first end - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) + expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end @@ -235,7 +283,9 @@ feature 'Commenting legislation questions' do comment = create(:comment, commentable: legislation_annotation) login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) within "#comment_#{comment.id}" do page.find("#flag-expand-comment-#{comment.id}").click @@ -252,7 +302,9 @@ feature 'Commenting legislation questions' do Flag.flag(user, comment) login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) within "#comment_#{comment.id}" do page.find("#unflag-expand-comment-#{comment.id}").click @@ -269,7 +321,9 @@ feature 'Commenting legislation questions' do comment = create(:comment, commentable: legislation_annotation) login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) within "#comment_#{comment.id}" do page.find("#flag-expand-comment-#{comment.id}").click @@ -282,7 +336,10 @@ feature 'Commenting legislation questions' do comment = create(:comment, commentable: legislation_annotation, body: 'this should be visible') comment.user.erase - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) + within "#comment_#{comment.id}" do expect(page).to have_content('User deleted') expect(page).to have_content('this should be visible') @@ -292,7 +349,10 @@ feature 'Commenting legislation questions' do scenario 'Submit button is disabled after clicking', :js do legislation_annotation = create(:legislation_annotation) login_as(user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: 'Testing submit button!' click_button 'Publish comment' @@ -309,7 +369,9 @@ feature 'Commenting legislation questions' do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am moderating!" check "comment-as-moderator-legislation_annotation_#{legislation_annotation.id}" @@ -331,7 +393,9 @@ feature 'Commenting legislation questions' do comment = legislation_annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) click_link "Reply" @@ -355,7 +419,9 @@ feature 'Commenting legislation questions' do moderator = create(:moderator) login_as(moderator.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) expect(page).to_not have_content "Comment as administrator" end @@ -366,7 +432,9 @@ feature 'Commenting legislation questions' do admin = create(:administrator) login_as(admin.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am your Admin!" check "comment-as-administrator-legislation_annotation_#{legislation_annotation.id}" @@ -388,7 +456,9 @@ feature 'Commenting legislation questions' do comment = legislation_annotation.comments.first login_as(manuela) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) click_link "Reply" @@ -412,7 +482,9 @@ feature 'Commenting legislation questions' do admin = create(:administrator) login_as(admin.user) - visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) expect(page).to_not have_content "Comment as moderator" end @@ -432,7 +504,9 @@ feature 'Commenting legislation questions' do create(:vote, voter: @manuela, votable: @comment, vote_flag: true) create(:vote, voter: @pablo, votable: @comment, vote_flag: false) - visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, + @legislation_annotation.draft_version, + @legislation_annotation) within("#comment_#{@comment.id}_votes") do within(".in_favor") do @@ -448,7 +522,9 @@ feature 'Commenting legislation questions' do end scenario 'Create', :js do - visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, + @legislation_annotation.draft_version, + @legislation_annotation) within("#comment_#{@comment.id}_votes") do find(".in_favor a").click @@ -466,7 +542,9 @@ feature 'Commenting legislation questions' do end scenario 'Update', :js do - visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, + @legislation_annotation.draft_version, + @legislation_annotation) within("#comment_#{@comment.id}_votes") do find('.in_favor a').click @@ -485,7 +563,9 @@ feature 'Commenting legislation questions' do end xscenario 'Trying to vote multiple times', :js do - visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, + @legislation_annotation.draft_version, + @legislation_annotation) within("#comment_#{@comment.id}_votes") do find('.in_favor a').click @@ -510,8 +590,14 @@ feature 'Commenting legislation questions' do feature "Merged comment threads", :js do let!(:draft_version) { create(:legislation_draft_version, :published) } - let!(:annotation1) { create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5}]) } - let!(:annotation2) { create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10}]) } + let!(:annotation1) do + create(:legislation_annotation, draft_version: draft_version, text: "my annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5}]) + end + let!(:annotation2) do + create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10}]) + end background do login_as user diff --git a/spec/features/comments/legislation_questions_spec.rb b/spec/features/comments/legislation_questions_spec.rb index 064a72ae0..50eb60172 100644 --- a/spec/features/comments/legislation_questions_spec.rb +++ b/spec/features/comments/legislation_questions_spec.rb @@ -25,6 +25,7 @@ feature 'Commenting legislation questions' do parent_comment = create(:comment, commentable: legislation_question) first_child = create(:comment, commentable: legislation_question, parent: parent_comment) second_child = create(:comment, commentable: legislation_question, parent: parent_comment) + href = legislation_process_question_path(legislation_question.process, legislation_question) visit comment_path(parent_comment) @@ -33,7 +34,7 @@ feature 'Commenting legislation questions' do expect(page).to have_content first_child.body expect(page).to have_content second_child.body - expect(page).to have_link "Go back to #{legislation_question.title}", href: legislation_process_question_path(legislation_question.process, legislation_question) + expect(page).to have_link "Go back to #{legislation_question.title}", href: href end scenario 'Collapsable comments', :js do @@ -63,9 +64,12 @@ feature 'Commenting legislation questions' do end scenario 'Comment order' do - c1 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + c1 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) visit legislation_process_question_path(legislation_question.process, legislation_question, order: :most_voted) @@ -119,7 +123,8 @@ feature 'Commenting legislation questions' do end scenario 'Sanitizes comment body for security' do - create :comment, commentable: legislation_question, body: " click me http://www.url.com" + create :comment, commentable: legislation_question, + body: " click me http://www.url.com" visit legislation_process_question_path(legislation_question.process, legislation_question) diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index d10a11de7..173dad2e6 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -62,9 +62,12 @@ feature 'Commenting proposals' do end scenario 'Comment order' do - c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) visit proposal_path(proposal, order: :most_voted) @@ -118,7 +121,8 @@ feature 'Commenting proposals' do end scenario 'Sanitizes comment body for security' do - create :comment, commentable: proposal, body: " click me http://www.url.com" + create :comment, commentable: proposal, + body: " click me http://www.url.com" visit proposal_path(proposal) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index b1357bb1c..749c7a373 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -189,11 +189,12 @@ feature 'Debates' do scenario 'JS injection is prevented but autolinking is respected' do author = create(:user) + js_injection_string = " click me http://example.org" login_as(author) visit new_debate_path fill_in 'debate_title', with: 'Testing auto link' - fill_in 'debate_description', with: " click me http://example.org" + fill_in 'debate_description', with: js_injection_string check 'debate_terms_of_service' click_button 'Start a debate' diff --git a/spec/features/legacy_legislation_spec.rb b/spec/features/legacy_legislation_spec.rb index 5df3b8f76..8ccc7fcb0 100644 --- a/spec/features/legacy_legislation_spec.rb +++ b/spec/features/legacy_legislation_spec.rb @@ -77,8 +77,10 @@ feature 'Legacy Legislation' do scenario 'Search' do legacy_legislation = create(:legacy_legislation) - annotation1 = create(:annotation, legacy_legislation: legacy_legislation, text: "my annotation", ranges: [{"start" => "/div[1]", "startOffset" => 5, "end" => "/div[1]", "endOffset" => 10}]) - annotation2 = create(:annotation, legacy_legislation: legacy_legislation, text: "my other annotation", ranges: [{"start" => "/div[1]", "startOffset" => 12, "end" => "/div[1]", "endOffset" => 19}]) + annotation1 = create(:annotation, legacy_legislation: legacy_legislation, text: "my annotation", + ranges: [{"start" => "/div[1]", "startOffset" => 5, "end" => "/div[1]", "endOffset" => 10}]) + annotation2 = create(:annotation, legacy_legislation: legacy_legislation, text: "my other annotation", + ranges: [{"start" => "/div[1]", "startOffset" => 12, "end" => "/div[1]", "endOffset" => 19}]) visit legacy_legislation_path(legacy_legislation) diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index f0a798b85..ea2cb854d 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -10,9 +10,12 @@ feature 'Legislation Draft Versions' do context "See draft text page" do before(:each) do @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", status: "published") - @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", status: "published") - @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", status: "draft") + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", + body: "Body of the first version", status: "published") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", + body: "Body of the second version", status: "published") + @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", + body: "Body of the third version", status: "draft") end it "shows the text body for this version" do @@ -64,7 +67,8 @@ feature 'Legislation Draft Versions' do context "for final versions" do it "does not show the comments panel" do - final_version = create(:legislation_draft_version, process: @process, title: "Final version", body: "Final body", status: "published", final_version: true) + final_version = create(:legislation_draft_version, process: @process, title: "Final version", + body: "Final body", status: "published", final_version: true) visit legislation_process_draft_version_path(@process, final_version) @@ -78,9 +82,12 @@ feature 'Legislation Draft Versions' do context "See changes page" do before(:each) do @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version", status: "published") - @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version", status: "published") - @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", changelog: "Changes for third version", status: "draft") + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", + changelog: "Changes for first version", status: "published") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", + changelog: "Changes for second version", status: "published") + @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", + changelog: "Changes for third version", status: "draft") end it "shows the changes for this version" do @@ -173,8 +180,10 @@ feature 'Legislation Draft Versions' do scenario 'View annotations and comments' do draft_version = create(:legislation_draft_version, :published) - annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10}]) - annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start" => "/p[1]", "startOffset" => 12, "end" => "/p[1]", "endOffset" => 19}]) + annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10}]) + create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 12, "end" => "/p[1]", "endOffset" => 19}]) comment = create(:comment, commentable: annotation1) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -190,7 +199,8 @@ feature 'Legislation Draft Versions' do scenario "Publish new comment for an annotation from comments box" do draft_version = create(:legislation_draft_version, :published) - annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]) + annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -212,8 +222,10 @@ feature 'Legislation Draft Versions' do scenario 'View annotations and comments in an included range' do draft_version = create(:legislation_draft_version, :published) - annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5}]) - annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10}]) + annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 5}]) + annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", + ranges: [{"start" => "/p[1]", "startOffset" => 1, "end" => "/p[1]", "endOffset" => 10}]) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -232,8 +244,10 @@ feature 'Legislation Draft Versions' do context "Annotations page" do background do @draft_version = create(:legislation_draft_version, :published) - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]) - @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", ranges: [{"start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11}]) + create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", + ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]) + create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", + ranges: [{"start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11}]) end scenario "See all annotations for a draft version" do @@ -246,10 +260,14 @@ feature 'Legislation Draft Versions' do context "switching versions" do background do @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, :published, process: @process, title: "Version 1", body: "Text with quote for version 1") - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1", ranges: [{"start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30}]) - @draft_version_2 = create(:legislation_draft_version, :published, process: @process, title: "Version 2", body: "Text with quote for version 2") - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2", ranges: [{"start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30}]) + @draft_version_1 = create(:legislation_draft_version, :published, process: @process, + title: "Version 1", body: "Text with quote for version 1") + create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1", + ranges: [{"start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30}]) + @draft_version_2 = create(:legislation_draft_version, :published, process: @process, + title: "Version 2", body: "Text with quote for version 2") + create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2", + ranges: [{"start" => "/p[1]", "startOffset" => 11, "end" => "/p[1]", "endOffset" => 30}]) end scenario "without js" do @@ -278,12 +296,14 @@ feature 'Legislation Draft Versions' do context "Annotation comments page" do background do @draft_version = create(:legislation_draft_version, :published) - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]) - @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", ranges: [{"start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11}]) + create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", + ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[1]", "endOffset" => 11}]) + @annotation = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", + ranges: [{"start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11}]) end scenario "See one annotation with replies for a draft version" do - visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2) + visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation) expect(page).to_not have_content "ipsum" expect(page).to_not have_content "my annotation" diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index edf0980b1..f0fbbefe3 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -84,13 +84,16 @@ feature 'Budget Investments' do expect(page).to have_css('.budget-investment', count: 1) expect(page).to have_content(budget_investment1.title) expect(page).to_not have_content(budget_investment2.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", + text: budget_investment1.title) end end scenario "by heading" do - budget_investment1 = create(:budget_investment, budget: @budget, title: "Hey ho", heading: create(:budget_heading, name: "District 9")) - budget_investment2 = create(:budget_investment, budget: @budget, title: "Let's go", heading: create(:budget_heading, name: "Area 52")) + budget_investment1 = create(:budget_investment, budget: @budget, title: "Hey ho", + heading: create(:budget_heading, name: "District 9")) + budget_investment2 = create(:budget_investment, budget: @budget, title: "Let's go", + heading: create(:budget_heading, name: "Area 52")) user = create(:user, :level_two) login_managed_user(user) @@ -108,7 +111,8 @@ feature 'Budget Investments' do expect(page).to have_css('.budget-investment', count: 1) expect(page).to_not have_content(budget_investment1.title) expect(page).to have_content(budget_investment2.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", + text: budget_investment2.title) end end end @@ -135,8 +139,10 @@ feature 'Budget Investments' do within("#budget-investments") do expect(page).to have_css('.budget-investment', count: 2) - expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", + text: budget_investment1.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", + text: budget_investment2.title) end end diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index a10e41a7d..2c12c85c8 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -65,7 +65,8 @@ feature 'Proposal Notifications' do scenario "Show notifications" do proposal = create(:proposal) notification1 = create(:proposal_notification, proposal: proposal, title: "Hey guys", body: "Just wanted to let you know that...") - notification2 = create(:proposal_notification, proposal: proposal, title: "Another update", body: "We are almost there please share with your peoples!") + notification2 = create(:proposal_notification, proposal: proposal, title: "Another update", + body: "We are almost there please share with your peoples!") visit proposal_path(proposal) @@ -144,4 +145,4 @@ feature 'Proposal Notifications' do end -end \ No newline at end of file +end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 8faa899f9..5ec0d36fd 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -331,13 +331,14 @@ feature 'Proposals' do scenario 'JS injection is prevented but autolinking is respected' do author = create(:user) + js_injection_string = " click me http://example.org" login_as(author) visit new_proposal_path fill_in 'proposal_title', with: 'Testing auto link' fill_in 'proposal_question', with: 'Should I stay or should I go?' fill_in 'proposal_summary', with: 'In summary, what we want is...' - fill_in 'proposal_description', with: " click me http://example.org" + fill_in 'proposal_description', with: js_injection_string fill_in 'proposal_responsible_name', with: 'Isabel Garcia' check 'proposal_terms_of_service' diff --git a/spec/features/users_auth_spec.rb b/spec/features/users_auth_spec.rb index 566c1c233..c082ba85a 100644 --- a/spec/features/users_auth_spec.rb +++ b/spec/features/users_auth_spec.rb @@ -6,6 +6,7 @@ feature 'Users' do context 'Sign up' do scenario 'Success' do + message = "You have been sent a message containing a verification link. Please click on this link to activate your account." visit '/' click_link 'Register' @@ -17,7 +18,7 @@ feature 'Users' do click_button 'Register' - expect(page).to have_content "You have been sent a message containing a verification link. Please click on this link to activate your account." + expect(page).to have_content message confirm_email diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index 828dde908..6291557f0 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -11,7 +11,8 @@ feature 'Verify Letter' do click_link "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting your maximum security code (only required for the final votes). In a few days we will send it to the address featuring in the data we have on file." + expect(page).to have_content "Thank you for requesting your maximum security code (only required for the final votes). In a few days"\ + " we will send it to the address featuring in the data we have on file." user.reload diff --git a/spec/features/verification/level_three_verification_spec.rb b/spec/features/verification/level_three_verification_spec.rb index 419facf3a..ff88f8477 100644 --- a/spec/features/verification/level_three_verification_spec.rb +++ b/spec/features/verification/level_three_verification_spec.rb @@ -87,6 +87,7 @@ feature 'Level three verification' do click_link "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting your maximum security code (only required for the final votes). In a few days we will send it to the address featuring in the data we have on file." + expect(page).to have_content "Thank you for requesting your maximum security code (only required for the final votes)."\ + " In a few days we will send it to the address featuring in the data we have on file." end end diff --git a/spec/lib/census_api_spec.rb b/spec/lib/census_api_spec.rb index 274101f22..8e2be6301 100644 --- a/spec/lib/census_api_spec.rb +++ b/spec/lib/census_api_spec.rb @@ -23,13 +23,25 @@ describe CensusApi do end it 'adds upper and lowercase letter when the letter is present' do - expect(api.get_document_number_variants(1, '1234567A')).to eq(['1234567', '01234567', '1234567a', '1234567A', '01234567a', '01234567A']) + expect(api.get_document_number_variants(1, '1234567A')).to eq(%w(1234567 01234567 1234567a 1234567A 01234567a 01234567A)) end end describe '#call' do let(:invalid_body) { {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {}}}} } - let(:valid_body){ {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {item: {fecha_nacimiento_string: "1-1-1980"}}}}} } + let(:valid_body) do + { + get_habita_datos_response: { + get_habita_datos_return: { + datos_habitante: { + item: { + fecha_nacimiento_string: "1-1-1980" + } + } + } + } + } + end it "returns the response for the first valid variant" do allow(api).to receive(:get_response_body).with(1, "00123456").and_return(invalid_body) diff --git a/spec/lib/manager_authenticator_spec.rb b/spec/lib/manager_authenticator_spec.rb index c53a26f5e..8f27a61d3 100644 --- a/spec/lib/manager_authenticator_spec.rb +++ b/spec/lib/manager_authenticator_spec.rb @@ -51,8 +51,9 @@ describe ManagerAuthenticator do end it 'should call the verification user method' do + message = { ub: {user_key: "31415926", date: "20151031135905"} } allow(@authenticator).to receive(:application_authorized?).and_return(true) - expect(@authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: { ub: {user_key: "31415926", date: "20151031135905"} }) + expect(@authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message) @authenticator.auth end @@ -62,4 +63,4 @@ describe ManagerAuthenticator do @authenticator.auth end end -end \ No newline at end of file +end diff --git a/spec/models/legislation/annotation_spec.rb b/spec/models/legislation/annotation_spec.rb index 0daca383a..ffcffd6e3 100644 --- a/spec/models/legislation/annotation_spec.rb +++ b/spec/models/legislation/annotation_spec.rb @@ -10,38 +10,102 @@ RSpec.describe Legislation::Annotation, type: :model do end it "calculates the context for multinode annotations" do + quote = "ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam"\ + " erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex"\ + " ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum"\ + " dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril"\ + " delenit augue duis dolore te feugait nulla facilisi."\ + "\n\n"\ + "Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi"\ + " tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis"\ + " ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id."\ + "\n\n"\ + "His audiam" annotation = create(:legislation_annotation, draft_version: draft_version, - quote: "ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. - -Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id. - -His audiam", + quote: quote, ranges: [{"start" => "/p[1]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11}] ) - expect(annotation.context).to eq("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.\n\nHis audiamdeserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu.") + context = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt"\ + " ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper"\ + " suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit"\ + " esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui"\ + " blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\nExpetenda tincidunt in sed, ex"\ + " partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute"\ + " aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit"\ + " iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.\n\nHis audiamdeserunt in, eum"\ + " ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at"\ + " quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim"\ + " alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu." + expect(annotation.context).to eq(context) end it "calculates the context for multinode annotations 2" do + quote = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla"\ + " facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore"\ + " te feugait nulla facilisi.\r\n\r\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant"\ + " aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo" annotation = create(:legislation_annotation, draft_version: draft_version, - quote: "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\r\n\r\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo", + quote: quote, ranges: [{"start" => "/p[1]", "startOffset" => 273, "end" => "/p[2]", "endOffset" => 190}] ) - expect(annotation.context).to eq("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\r\n\r\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.") + context = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna"\ + " aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut"\ + " aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit"\ + " esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui"\ + " blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\r\n\r\nExpetenda tincidunt in sed, ex"\ + " partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute"\ + " aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit"\ + " iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id." + expect(annotation.context).to eq(context) end it "calculates the context for multinode annotations 3" do - draft_version = create(:legislation_draft_version, body: "The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.\r\n\r\nThe licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.\r\n\r\nDevelopers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.\r\n\r\nA secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.\r\n\r\nThe GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.\r\n\r\nAn older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.") + body = "The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed"\ + " to ensure cooperation with the community in the case of network server software.\r\n\r\nThe licenses for most software and"\ + " other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public"\ + " Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free"\ + " software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General"\ + " Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for"\ + " them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces"\ + " of it in new free programs, and that you know you can do these things.\r\n\r\nDevelopers that use our General Public Licenses"\ + " protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you"\ + " legal permission to copy, distribute and/or modify the software.\r\n\r\nA secondary benefit of defending all users' freedom"\ + " is that improvements made in alternate versions of the program, if they receive widespread use, become available for other"\ + " developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation."\ + " However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License"\ + " permits making a modified version and letting the public access it on a server without ever releasing its source code to the"\ + " public.\r\n\r\nThe GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified"\ + " source code becomes available to the community. It requires the operator of a network server to provide the source code of"\ + " the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly"\ + " accessible server, gives the public access to the source code of the modified version.\r\n\r\nAn older license, called the"\ + " Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license,"\ + " not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this"\ + " license." + draft_version = create(:legislation_draft_version, body: body) + + quote = "By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a"\ + " program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to"\ + " freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of"\ + " free software (and charge for them if you wish)" annotation = create(:legislation_annotation, draft_version: draft_version, - quote: "By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish)", + quote: quote, ranges: [{"start" => "/p[2]", "startOffset" => 127, "end" => "/p[3]", "endOffset" => 223}] ) - expect(annotation.context).to eq("The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.") + context = "The licenses for most software and other practical works are designed to take away your freedom to share and change the"\ + " works. By contrast, our General Public Licenses are intended to guarantee your freedom to share"\ + " and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of"\ + " free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have"\ + " the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code"\ + " or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know"\ + " you can do these things." + + expect(annotation.context).to eq(context) end end diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index 954394d1c..9ba93b2c7 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -25,7 +25,9 @@ describe Verification::Residence do end it "should validate user has allowed age" do - residence = Verification::Residence.new("date_of_birth(3i)" => "1", "date_of_birth(2i)" => "1", "date_of_birth(1i)" => (5.years.ago.year).to_s) + residence = Verification::Residence.new("date_of_birth(3i)" => "1", + "date_of_birth(2i)" => "1", + "date_of_birth(1i)" => (5.years.ago.year).to_s) expect(residence).to_not be_valid expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate") end diff --git a/spec/models/verification/management/document_spec.rb b/spec/models/verification/management/document_spec.rb index 076c68b67..d4bc4e4da 100644 --- a/spec/models/verification/management/document_spec.rb +++ b/spec/models/verification/management/document_spec.rb @@ -25,7 +25,10 @@ describe Verification::Management::Document do end it "returns false when the user is user's minimum required age" do - census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, User.minimum_required_age.years.ago.month, User.minimum_required_age.years.ago.day)) + date_of_birth = Date.new(User.minimum_required_age.years.ago.year, + User.minimum_required_age.years.ago.month, + User.minimum_required_age.years.ago.day) + census_response = double(date_of_birth: date_of_birth) expect(Verification::Management::Document.new.under_age?(census_response)).to be false end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 209ddf800..8b8470293 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -25,8 +25,9 @@ module CommonActions end def login_as_authenticated_manager + expected_response = {login: login, user_key: user_key, date: date}.with_indifferent_access login, user_key, date = "JJB042", "31415926", Time.current.strftime("%Y%m%d%H%M%S") - allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return({login: login, user_key: user_key, date: date}.with_indifferent_access) + allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(expected_response) visit management_sign_in_path(login: login, clave_usuario: user_key, fecha_conexion: date) end @@ -219,8 +220,11 @@ module CommonActions end def create_archived_proposals - [create(:proposal, title: "This is an expired proposal", created_at: Setting["months_to_archive_proposals"].to_i.months.ago), - create(:proposal, title: "This is an oldest expired proposal", created_at: (Setting["months_to_archive_proposals"].to_i + 2).months.ago)] + months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i + [ + create(:proposal, title: "This is an expired proposal", created_at: months_to_archive_proposals.months.ago), + create(:proposal, title: "This is an oldest expired proposal", created_at: (months_to_archive_proposals + 2).months.ago) + ] end def tag_names(tag_cloud) diff --git a/spec/support/verifiable.rb b/spec/support/verifiable.rb index 9112c67cf..9f6be1355 100644 --- a/spec/support/verifiable.rb +++ b/spec/support/verifiable.rb @@ -65,7 +65,8 @@ shared_examples_for "verifiable" do user2 = create(:user, verified_at: nil, residence_verified_at: Time.current, unconfirmed_phone: nil) user3 = create(:user, verified_at: nil, confirmed_phone: nil) - user4 = create(:user, verified_at: Time.current, residence_verified_at: Time.current, unconfirmed_phone: "123456789", confirmed_phone: "123456789") + user4 = create(:user, verified_at: Time.current, residence_verified_at: Time.current, + unconfirmed_phone: "123456789", confirmed_phone: "123456789") expect(model.incomplete_verification).to include(user1) expect(model.incomplete_verification).to include(user2) From 2b85deabec96371f51530ca452e9011cc165f901 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 14:24:55 +0200 Subject: [PATCH 20/26] Recalculate heading winners on incompatibility change Why: * We should recalculate winners also when an incompatible investment is flagged as compatible again How: * Removing the condition to recalculate that was checking only for a winner investment flagged as incompatible * Extending the Budget::Result model spec to cover that new scenario --- app/models/budget/investment.rb | 2 +- spec/models/budget/result_spec.rb | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 5fcf2e882..6a83b28a2 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -204,7 +204,7 @@ class Budget end def recalculate_heading_winners - Budget::Result.new(budget, heading).calculate_winners if incompatible_changed? && winner? && incompatible? + Budget::Result.new(budget, heading).calculate_winners if incompatible_changed? end def set_responsible_name diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb index 85eb14f3e..a650e25c5 100644 --- a/spec/models/budget/result_spec.rb +++ b/spec/models/budget/result_spec.rb @@ -15,7 +15,7 @@ describe Budget::Result do investment4 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600, winner: false) investment5 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500, winner: false) - Budget::Result.new(budget, heading).calculate_winners + described_class.new(budget, heading).calculate_winners expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id]) end @@ -29,7 +29,7 @@ describe Budget::Result do investment4 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600) investment5 = create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) - Budget::Result.new(budget, heading).calculate_winners + described_class.new(budget, heading).calculate_winners expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id]) end @@ -49,6 +49,20 @@ describe Budget::Result do expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id]) end end - end + context "When an incompatible is flagged as compatible again" do + it "recalculates winners taking it in consideration" do + investment1 = create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 900) + investment2 = create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) + investment3 = create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) + investment4 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600) + investment5 = create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) + + investment3.incompatible = false + investment3.save + + expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment3.id]) + end + end + end end From efacd0def32df2850deb19998ddf7d94b788146b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 15:12:14 +0200 Subject: [PATCH 21/26] Make calculate_winners explicitly delayed Why: * As seen on preproduction and production environments on Madrid's fork. Budget::Result#calculate_winners is very costly when done to all headings for a given budget (as requested on Admin::BudgetsController#calculate_winners) but its not when done individually for only a heading (as requested on Budget::Investment#recalculate_heading_winners) How: * Removing `handle_asynchronously :calculate_winners` from bellow Budget::Result#calculate_winners definition, to avoid making any call delayed. And explicitly calling `.delay` only when needed (on Admin::BudgetsController#calculate_winners) --- app/controllers/admin/budgets_controller.rb | 2 +- app/models/budget/result.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index b37351028..7caf4f35c 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -20,7 +20,7 @@ class Admin::BudgetsController < Admin::BaseController def calculate_winners return unless @budget.balloting_process? - @budget.headings.each { |heading| Budget::Result.new(@budget, heading).calculate_winners } + @budget.headings.each { |heading| Budget::Result.new(@budget, heading).delay.calculate_winners } redirect_to admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'winners'), notice: I18n.t("admin.budgets.winners.calculated") end diff --git a/app/models/budget/result.rb b/app/models/budget/result.rb index aa6c4c7ac..d034e50ef 100644 --- a/app/models/budget/result.rb +++ b/app/models/budget/result.rb @@ -15,7 +15,6 @@ class Budget set_winner if inside_budget? end end - handle_asynchronously :calculate_winners def investments heading.investments.selected.sort_by_ballots From 3a94fe4cc24aa2f335c581709ba9b95eb60662f1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 16:03:31 +0200 Subject: [PATCH 22/26] Fix indentation on if-else assignement --- .../valuation/budget_investments_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index e64dcdb0d..135a3e44c 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -13,11 +13,11 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController def index @heading_filters = heading_filters @investments = if current_user.valuator? && @budget.present? - @budget.investments.scoped_filter(params_for_current_valuator, @current_filter) - .order(cached_votes_up: :desc) - .page(params[:page]) + @budget.investments.scoped_filter(params_for_current_valuator, @current_filter) + .order(cached_votes_up: :desc) + .page(params[:page]) else - Budget::Investment.none.page(params[:page]) + Budget::Investment.none.page(params[:page]) end end From 2fba9de33b697a9c6ff62045c807a61c61b031e7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 17:07:00 +0200 Subject: [PATCH 23/26] Don't display incompatible investment's table if empty --- app/views/budgets/results/show.html.erb | 10 ++++++---- spec/features/budgets/results_spec.rb | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index 2343e652c..f2b9ae7f8 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -42,8 +42,10 @@ heading_price: @heading.price, investments: @investments.compatible %> - <%= render 'results_table', results_type: :incompatible, - title: t("budgets.results.incompatibles"), - heading_price: @heading.price, - investments: @investments.incompatible %> + <% if @investments.incompatible.present? %> + <%= render 'results_table', results_type: :incompatible, + title: t("budgets.results.incompatibles"), + heading_price: @heading.price, + investments: @investments.incompatible %> + <% end %> diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb index cd9cb0912..0e70fdaab 100644 --- a/spec/features/budgets/results_spec.rb +++ b/spec/features/budgets/results_spec.rb @@ -55,4 +55,14 @@ feature 'Results' do expect(page).to have_content "You do not have permission to carry out the action" end + scenario "No incompatible investments", :js do + investment3.incompatible = false + investment3.save + + visit budget_path(budget) + click_link "See results" + + expect(page).not_to have_content "Incompatibles" + end + end From 741a342bb0fd26a385356788c84dc2b788b41426 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 17:34:05 +0200 Subject: [PATCH 24/26] Restrict compatilibility edit on admin investment form Why: * A non-winner but compatible investment shouldn't be marked as incompatible How: * Show incompatilibility checkbox only if investment is winner or incompatible --- .../admin/budget_investments/edit.html.erb | 2 ++ spec/features/admin/budget_investments_spec.rb | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index 1e21ee706..c33039021 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -63,6 +63,7 @@
+ <% if @investment.incompatible? || @investment.winner? %>

<%= t("admin.budget_investments.edit.compatibility") %>

<%= f.label :incompatible do %> @@ -70,6 +71,7 @@ <%= t("admin.budget_investments.edit.mark_as_incompatible") %> <% end %>
+ <% end %>

<%= t("admin.budget_investments.edit.selection") %>

<%= f.label :selected do %> diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 57dedcb54..925f105b0 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -312,7 +312,7 @@ feature 'Admin budget investments' do context "Edit" do scenario "Change title, incompatible, description or heading" do - budget_investment = create(:budget_investment, :selected) + budget_investment = create(:budget_investment, :incompatible) create(:budget_heading, group: budget_investment.group, name: "Barbate") visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) @@ -321,7 +321,7 @@ feature 'Admin budget investments' do fill_in 'budget_investment_title', with: 'Potatoes' fill_in 'budget_investment_description', with: 'Carrots' select "#{budget_investment.group.name}: Barbate", from: 'budget_investment[heading_id]' - check "budget_investment_incompatible" + uncheck "budget_investment_incompatible" check "budget_investment_selected" click_button 'Update' @@ -329,10 +329,21 @@ feature 'Admin budget investments' do expect(page).to have_content 'Potatoes' expect(page).to have_content 'Carrots' expect(page).to have_content 'Barbate' - expect(page).to have_content 'Incompatible' + expect(page).to have_content 'Compatibility: Compatible' expect(page).to have_content 'Selected' end + scenario "Compatible non-winner can't edit incompatibility" do + budget_investment = create(:budget_investment, :selected) + create(:budget_heading, group: budget_investment.group, name: "Tetuan") + + visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment) + click_link 'Edit' + + expect(page).not_to have_content 'Compatibility' + expect(page).not_to have_content 'Mark as incompatible' + end + scenario "Add administrator" do budget_investment = create(:budget_investment) administrator = create(:administrator, user: create(:user, username: 'Marta', email: 'marta@admins.org')) From 49f48ddf4be50b932799739143bbbf3455bc410c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 17:48:04 +0200 Subject: [PATCH 25/26] Highlight current heading on results list --- app/assets/stylesheets/layout.scss | 5 +++++ app/views/budgets/results/show.html.erb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 9673cdc88..e223ffa56 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -236,6 +236,11 @@ a { border-bottom: 2px solid $brand; color: $brand; } + + &.bold { + font-weight: bold; + color: $brand; + } } &.no-margin-top { diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index f2b9ae7f8..278ae012b 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -26,7 +26,8 @@ <% @budget.headings.each do |heading| %> -
  • + <% active_class = heading.id.to_s == params[:heading_id] ? 'bold' : '' %> +
  • <%= link_to heading.name, budget_results_path(@budget, heading_id: heading.id) %>
  • From 11a793d63f201e8ab7a1c81794e3815928a8db28 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 10 Jul 2017 19:41:04 +0200 Subject: [PATCH 26/26] Hide incompatible and non-winner investments by default --- .../budgets/results/_results_table.html.erb | 8 +++-- app/views/budgets/results/show.html.erb | 2 +- spec/features/budgets/results_spec.rb | 30 +++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/views/budgets/results/_results_table.html.erb b/app/views/budgets/results/_results_table.html.erb index 993060562..f391e8d50 100644 --- a/app/views/budgets/results/_results_table.html.erb +++ b/app/views/budgets/results/_results_table.html.erb @@ -1,4 +1,6 @@ -
    +

    <%= title %> @@ -28,7 +30,9 @@ <% amount_available = heading_price %> <% investments.each do |investment| %> - + <% if investment.winner? %> diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index 278ae012b..eb31124ec 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -35,7 +35,7 @@

    - <%= link_to t("budgets.results.hide_discarded_link"), "#", class: "js-toggle-link button hollow margin-bottom", data: {'toggle-selector' => '.js-discarded', 'toggle-text' => t("budgets.results.show_all_link")} %> + <%= link_to t("budgets.results.show_all_link"), "#", class: "js-toggle-link button hollow margin-bottom", data: {'toggle-selector' => '.js-discarded', 'toggle-text' => t("budgets.results.hide_discarded_link")} %> <%= render 'results_table', results_type: :compatible, diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb index 0e70fdaab..3b2d05c65 100644 --- a/spec/features/budgets/results_spec.rb +++ b/spec/features/budgets/results_spec.rb @@ -17,6 +17,21 @@ feature 'Results' do visit budget_path(budget) click_link "See results" + within("#budget-investments-compatible") do + expect(page).to have_content investment1.title + expect(page).to have_content investment2.title + expect(page).not_to have_content investment3.title + expect(page).not_to have_content investment4.title + + expect(investment1.title).to appear_before(investment2.title) + end + end + + scenario "Show non winner & incomaptible investments", :js do + visit budget_path(budget) + click_link "See results" + click_link "Show all" + within("#budget-investments-compatible") do expect(page).to have_content investment1.title expect(page).to have_content investment2.title @@ -31,21 +46,6 @@ feature 'Results' do end end - scenario "Displays non winner investments", :js do - visit budget_path(budget) - click_link "See results" - click_link "Hide discarded" - - within("#budget-investments-compatible") do - expect(page).to have_content investment1.title - expect(page).to have_content investment2.title - expect(page).not_to have_content investment3.title - expect(page).not_to have_content investment4.title - - expect(investment1.title).to appear_before(investment2.title) - end - end - scenario "If budget is in a phase different from finished results can't be accessed" do budget.update phase: (Budget::PHASES - ["finished"]).sample visit budget_path(budget)