From 0255b203497b3a11d776dd2853fe456fe7599a0d Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Thu, 16 Nov 2023 12:04:25 +0000 Subject: [PATCH 1/3] Update RuboCop empty lines layout config Enable all empty lines layout cops and auto correct all Ruby files. Before this change we had at least two different styles around empty lines so this ensure consistency across Ruby files. - `Layout/EmptyLineAfterGuardClause` - `Layout/EmptyLineAfterMagicComment` - `Layout/EmptyLineBetweenDefs` - `Layout/EmptyLines` - `Layout/EmptyLinesAroundAccessModifier` - `Layout/EmptyLinesAroundArguments` - `Layout/EmptyLinesAroundAttributeAccessor` - `Layout/EmptyLinesAroundBeginBody` - `Layout/EmptyLinesAroundBlockBody` - `Layout/EmptyLinesAroundClassBody` - `Layout/EmptyLinesAroundMethodBody` - `Layout/EmptyLinesAroundModuleBody` - `Layout/LeadingEmptyLines` - `Layout/TrailingEmptyLines` Ignores: - `Layout/EmptyLineAfterMultilineCondition` - `Layout/EmptyLinesAroundExceptionHandlingKeywords` Instead we use are own `EmptyLineAroundRescuedExceptions` cop. --- .ruby-style.yml | 19 +- .../admin_censor_rule_controller.rb | 1 - app/controllers/admin_comment_controller.rb | 3 +- app/controllers/admin_general_controller.rb | 2 - .../admin_holiday_imports_controller.rb | 2 - app/controllers/admin_holidays_controller.rb | 2 - .../admin_incoming_message_controller.rb | 1 - .../admin_info_request_event_controller.rb | 3 +- .../admin_outgoing_message_controller.rb | 1 - ...admin_public_body_categories_controller.rb | 2 - .../admin_public_body_controller.rb | 5 +- .../admin_public_body_headings_controller.rb | 2 - app/controllers/admin_request_controller.rb | 2 - .../admin_spam_addresses_controller.rb | 2 - app/controllers/admin_track_controller.rb | 2 - app/controllers/admin_user_controller.rb | 1 - .../alaveteli_pro/base_controller.rb | 2 - .../draft_info_request_batches_controller.rb | 1 + .../embargo_extensions_controller.rb | 1 + .../alaveteli_pro/embargoes_controller.rb | 2 + .../alaveteli_pro/info_requests_controller.rb | 5 +- .../alaveteli_pro/pages_controller.rb | 2 - .../payment_methods_controller.rb | 2 - .../alaveteli_pro/plans_controller.rb | 1 + .../stripe_webhooks_controller.rb | 1 + .../alaveteli_pro/subscriptions_controller.rb | 3 +- app/controllers/api_controller.rb | 5 +- app/controllers/application_controller.rb | 3 +- app/controllers/concerns/hashable_params.rb | 2 +- .../concerns/prominence_headers.rb | 1 + .../concerns/translatable_params.rb | 4 +- app/controllers/followups_controller.rb | 1 + app/controllers/general_controller.rb | 1 - app/controllers/holiday_controller.rb | 2 - .../public_body_change_requests_controller.rb | 1 - app/controllers/public_body_controller.rb | 3 +- app/controllers/refusal_advice_controller.rb | 1 + app/controllers/request_controller.rb | 11 +- app/controllers/request_game_controller.rb | 2 - app/controllers/services_controller.rb | 3 - app/controllers/track_controller.rb | 4 +- app/controllers/user_controller.rb | 8 +- .../user_profile/about_me_controller.rb | 1 + .../users/confirmations_controller.rb | 2 - app/controllers/users/messages_controller.rb | 1 - app/controllers/users/sessions_controller.rb | 2 +- app/controllers/widget_votes_controller.rb | 2 - app/controllers/widgets_controller.rb | 2 - app/helpers/admin/prominence_helper.rb | 1 + app/helpers/admin_comments_helper.rb | 1 - app/helpers/admin_users_helper.rb | 1 - app/helpers/alaveteli_pro/account_helper.rb | 2 - app/helpers/alaveteli_pro/dashboard_helper.rb | 2 - .../alaveteli_pro/info_requests_helper.rb | 2 + app/helpers/analytics_helper.rb | 3 - app/helpers/config_helper.rb | 2 - app/helpers/health_checks_helper.rb | 2 - app/helpers/highlight_helper.rb | 1 + app/helpers/link_to_helper.rb | 2 +- app/helpers/notification_mailer_helper.rb | 1 - app/helpers/prominence_helper.rb | 2 + app/helpers/public_body_helper.rb | 2 - app/helpers/refusal_advice_helper.rb | 1 + app/helpers/track_helper.rb | 1 - app/mailers/alaveteli_pro/account_mailer.rb | 1 - app/mailers/alaveteli_pro/embargo_mailer.rb | 2 + app/mailers/info_request_batch_mailer.rb | 1 - app/mailers/outgoing_mailer.rb | 6 +- app/mailers/reminder_mailer.rb | 1 - app/mailers/request_mailer.rb | 3 +- app/mailers/track_mailer.rb | 1 - app/models/alaveteli_pro/account_request.rb | 1 + .../alaveteli_pro/activity_list/comment.rb | 2 - .../activity_list/embargo_expiry.rb | 2 - .../activity_list/followup_resent.rb | 2 - .../activity_list/followup_sent.rb | 2 - .../alaveteli_pro/activity_list/item.rb | 2 - .../alaveteli_pro/activity_list/list.rb | 2 - .../activity_list/new_response.rb | 2 - .../alaveteli_pro/activity_list/overdue.rb | 2 - .../activity_list/request_resent.rb | 2 - .../activity_list/request_sent.rb | 2 - .../activity_list/very_overdue.rb | 2 - .../embargo/translated_constants.rb | 2 - .../alaveteli_pro/invoice_collection.rb | 2 + app/models/alaveteli_pro/request_filter.rb | 2 - .../alaveteli_pro/subscription_collection.rb | 2 + .../to_do_list/expiring_embargo.rb | 1 - app/models/alaveteli_pro/to_do_list/item.rb | 2 - app/models/alaveteli_pro/to_do_list/list.rb | 2 - .../alaveteli_pro/to_do_list/new_response.rb | 2 - .../to_do_list/overdue_request.rb | 1 - .../to_do_list/very_overdue_request.rb | 1 - app/models/censor_rule.rb | 1 + app/models/comment.rb | 1 + .../concerns/alaveteli_pro/phase_counts.rb | 3 - .../alaveteli_pro/request_summaries.rb | 1 - .../concerns/info_request/title_validation.rb | 1 + .../concerns/public_body_derived_fields.rb | 3 - app/models/dataset/value_set.rb | 1 + app/models/foi_attachment.rb | 3 +- app/models/guess.rb | 2 + app/models/holiday_import.rb | 2 +- app/models/incoming_message.rb | 15 +- app/models/incoming_message_error.rb | 1 - app/models/info_request.rb | 23 +- app/models/info_request/batch_pagination.rb | 2 + .../info_request/prominence/calculator.rb | 2 - .../prominence/not_embargoed_query.rb | 1 - .../prominence/searchable_query.rb | 1 - app/models/info_request/sluggable.rb | 1 + app/models/info_request/state.rb | 1 - app/models/info_request/state/calculator.rb | 1 - app/models/info_request_batch.rb | 1 + app/models/info_request_event.rb | 5 +- app/models/legislation/reference.rb | 1 + app/models/mail_server_log.rb | 2 +- app/models/mail_server_log/delivery_status.rb | 1 + .../delivery_status/translated_constants.rb | 2 - .../delivery_status_serializer.rb | 2 +- app/models/outgoing_message.rb | 3 + .../template/batch_request.rb | 1 - app/models/project/export/info_request.rb | 4 + app/models/project/queue.rb | 1 + app/models/public_body.rb | 3 +- .../public_body/calculated_home_page.rb | 2 + app/models/raw_email.rb | 1 + app/models/refusal_advice.rb | 1 + app/models/request_classification.rb | 1 - app/models/track_thing.rb | 3 +- .../track_thing/translated_constants.rb | 2 - app/models/track_things_sent_email.rb | 1 - app/models/user.rb | 4 + app/models/user/slug.rb | 2 + app/services/info_request_batch_metrics.rb | 1 - app/validators/change_email_validator.rb | 1 - config/deploy.rb | 2 - config/initializers/alaveteli.rb | 1 - .../new_framework_defaults_7_0.rb | 2 - config/initializers/secure_headers.rb | 1 - config/routes.rb | 5 - db/migrate/011_add_created_updated_fields.rb | 1 - db/migrate/026_add_many_null_constraints.rb | 2 - db/migrate/042_unique_user_urls.rb | 1 - db/migrate/074_create_holidays.rb | 1 - db/migrate/096_create_translation_tables.rb | 1 - .../100_remove_redundant_raw_email_columns.rb | 1 + db/migrate/101_add_hash_to_info_request.rb | 1 + db/migrate/102_add_locale_to_users.rb | 1 + db/migrate/103_add_user_bounce_columns.rb | 1 + db/migrate/104_create_foi_attachments.rb | 1 - db/migrate/110_add_user_no_limit.rb | 1 + ...tention_requested_flag_to_info_requests.rb | 1 + .../115_add_receive_email_alerts_to_user.rb | 1 + ...dd_info_requests_count_to_public_bodies.rb | 3 - ...152540_add_body_to_info_request_batches.rb | 1 - ...add_default_short_name_to_public_bodies.rb | 2 - ...0140528110536_update_track_things_index.rb | 2 - ...1107_create_category_translation_tables.rb | 2 + .../lib/alaveteli_features.rb | 1 + .../lib/alaveteli_features/collection.rb | 2 + .../lib/alaveteli_features/feature.rb | 4 + .../install/install_generator.rb | 2 +- .../lib/alaveteli_features/helpers.rb | 2 + .../lib/alaveteli_features/spec_helpers.rb | 2 + lib/acts_as_xapian/acts_as_xapian.rb | 30 +- lib/alaveteli_file_types.rb | 4 + lib/alaveteli_localization.rb | 1 + lib/alaveteli_mail_poller.rb | 2 +- lib/alaveteli_rate_limiter/ip_rate_limiter.rb | 1 + .../ip_rate_limiter/defaults.rb | 1 - lib/alaveteli_rate_limiter/window.rb | 2 +- lib/alaveteli_text_masker.rb | 2 - lib/analytics_event.rb | 2 - lib/attachment_to_html/adapters/pdf.rb | 1 + lib/attachment_to_html/adapters/rtf.rb | 2 - lib/attachment_to_html/view.rb | 2 - lib/confidence_intervals.rb | 1 + .../empty_lines_around_rescued_exceptions.rb | 88 ++++++ lib/data_export.rb | 4 +- lib/date_quarter.rb | 1 - .../acts_as_xapian/templates/migration.rb | 2 +- lib/graphs.rb | 2 +- lib/has_tag_string/has_tag_string.rb | 3 + lib/health_checks.rb | 1 - lib/health_checks/health_checkable.rb | 2 - lib/i18n_fixes.rb | 2 +- lib/languages.rb | 1 + lib/mail_handler.rb | 4 +- lib/mail_handler/backends/mail_backend.rb | 7 + lib/mail_handler/backends/mail_extensions.rb | 2 - lib/mail_handler/reply_handler.rb | 2 + lib/no_constraint_disabling.rb | 2 - lib/normalize_string.rb | 2 +- lib/public_body_csv.rb | 3 +- lib/routing_filters.rb | 1 + lib/tasks/storage/storage.rb | 3 + lib/tasks/usage.rb | 2 - lib/typeahead_search.rb | 4 +- lib/user_spam_scorer.rb | 3 + lib/user_stats.rb | 2 - lib/world_foi_websites.rb | 1 - lib/xapian_queries.rb | 1 - script/redact-raw-emails.rb | 1 + script/switch-theme.rb | 2 + .../admin_censor_rule_controller_spec.rb | 79 ------ .../admin_comment_controller_spec.rb | 22 -- .../admin_general_controller_spec.rb | 35 --- .../admin_holiday_imports_controller_spec.rb | 15 - .../admin_holidays_controller_spec.rb | 23 -- .../admin_incoming_message_controller_spec.rb | 19 -- ...dmin_info_request_event_controller_spec.rb | 4 - .../admin_outgoing_message_controller_spec.rb | 20 -- ..._public_body_categories_controller_spec.rb | 32 --- .../admin_public_body_controller_spec.rb | 49 ---- ...in_public_body_headings_controller_spec.rb | 36 --- .../admin_raw_email_controller_spec.rb | 4 - .../admin_request_controller_spec.rb | 7 - .../admin_spam_addresses_controller_spec.rb | 7 - .../admin_track_controller_spec.rb | 4 - .../controllers/admin_user_controller_spec.rb | 11 - ...ers_account_anonymising_controller_spec.rb | 3 - ...n_users_account_closing_controller_spec.rb | 2 - ...n_users_account_erasing_controller_spec.rb | 3 - ...ers_account_suspensions_controller_spec.rb | 2 - .../admin_users_sessions_controller_spec.rb | 7 - .../account_request_controller_spec.rb | 15 - ...uest_authority_searches_controller_spec.rb | 2 - .../dashboard_controller_spec.rb | 2 - .../alaveteli_pro/embargo_controller_spec.rb | 11 - .../embargo_extensions_controller_spec.rb | 9 - .../info_request_batches_controller_spec.rb | 1 - .../info_requests_controller_spec.rb | 4 - .../alaveteli_pro/pages_controller_spec.rb | 4 - .../payment_methods_controller_spec.rb | 20 -- .../alaveteli_pro/plans_controller_spec.rb | 16 -- .../public_bodies_controller_spec.rb | 1 - .../stripe_webhooks_controller_spec.rb | 27 -- .../subscriptions_controller_spec.rb | 93 ------- .../announcements_controller_spec.rb | 10 - spec/controllers/api_controller_spec.rb | 1 - spec/controllers/comment_controller_spec.rb | 11 - .../alaveteli_pro/stripe_namespace_spec.rb | 5 - .../concerns/hashable_params_spec.rb | 2 - .../concerns/translatable_params_spec.rb | 9 - spec/controllers/followups_controller_spec.rb | 23 -- spec/controllers/general_controller_spec.rb | 11 - spec/controllers/help_controller_spec.rb | 15 - .../one_time_passwords_controller_spec.rb | 18 -- .../delivery_statuses_controller_spec.rb | 1 - .../password_changes_controller_spec.rb | 30 -- ...ic_body_change_requests_controller_spec.rb | 6 - .../public_body_controller_spec.rb | 6 - .../public_tokens_controller_spec.rb | 2 - spec/controllers/reports_controller_spec.rb | 8 - spec/controllers/request_controller_spec.rb | 67 ----- .../request_game_controller_spec.rb | 8 - spec/controllers/services_controller_spec.rb | 8 - .../controllers/statistics_controller_spec.rb | 1 - spec/controllers/track_controller_spec.rb | 12 - spec/controllers/user_controller_spec.rb | 39 --- .../user_profile/about_me_controller_spec.rb | 37 --- .../users/confirmations_controller_spec.rb | 12 - .../users/messages_controller_spec.rb | 6 - .../users/sessions_controller_spec.rb | 14 - .../widget_votes_controller_spec.rb | 11 - spec/controllers/widgets_controller_spec.rb | 22 -- spec/factories/censor_rules.rb | 3 - spec/factories/comments.rb | 2 - spec/factories/dataset_value_sets.rb | 1 + spec/factories/foi_attchments.rb | 2 - spec/factories/holidays.rb | 2 - spec/factories/info_request_batches.rb | 1 - spec/factories/info_request_events.rb | 3 - spec/factories/info_requests.rb | 1 - spec/factories/mail_server_log_dones.rb | 2 - spec/factories/mail_server_logs.rb | 2 - spec/factories/outgoing_messages.rb | 2 - spec/factories/pro_accounts.rb | 2 - spec/factories/public_bodies.rb | 2 - spec/factories/public_body_change_requests.rb | 2 - spec/factories/request_classifications.rb | 2 - spec/factories/track_things.rb | 2 - spec/factories/users.rb | 1 - spec/helpers/admin_comments_helper_spec.rb | 3 - spec/helpers/admin_helper_spec.rb | 11 - spec/helpers/admin_raw_emails_helper_spec.rb | 4 - spec/helpers/admin_users_helper_spec.rb | 4 - ..._request_authority_searches_helper_spec.rb | 2 - .../alaveteli_pro/dashboard_helpers_spec.rb | 3 - spec/helpers/analytics_helper_spec.rb | 4 - spec/helpers/application_helper_spec.rb | 19 -- spec/helpers/currency_helper_spec.rb | 1 - spec/helpers/date_time_helper_spec.rb | 9 - spec/helpers/health_checks_helper_spec.rb | 3 - spec/helpers/highlight_helper_spec.rb | 9 - spec/helpers/info_request_helper_spec.rb | 47 ---- spec/helpers/link_to_helper_spec.rb | 1 - spec/helpers/public_body_helper_spec.rb | 13 - spec/helpers/stripe_helper_spec.rb | 8 - spec/helpers/track_helper_spec.rb | 20 -- spec/helpers/widget_helper_spec.rb | 4 - spec/integration/admin_censor_rule_spec.rb | 9 - spec/integration/admin_import_csv_spec.rb | 2 - .../admin_outgoing_message_edit_spec.rb | 4 - .../admin_public_body_category_edit_spec.rb | 2 - .../admin_public_body_category_new_spec.rb | 1 - .../admin_public_body_heading_edit_spec.rb | 1 - .../integration/admin_public_body_new_spec.rb | 1 - spec/integration/admin_spec.rb | 8 - .../admin_user_controller_edit_spec.rb | 3 - spec/integration/alaveteli_dsl.rb | 1 - .../alaveteli_pro/add_remove_embargo_spec.rb | 5 - spec/integration/alaveteli_pro/admin_spec.rb | 4 - .../alaveteli_pro/batch_request_spec.rb | 3 - .../alaveteli_pro/receive_response_spec.rb | 2 - .../alaveteli_pro/view_batch_request_spec.rb | 15 - .../alaveteli_pro/view_request_spec.rb | 21 -- spec/integration/change_email_address_spec.rb | 1 - spec/integration/classify_request_spec.rb | 38 --- spec/integration/cookie_stripping_spec.rb | 2 - spec/integration/create_request_spec.rb | 5 - spec/integration/download_request_spec.rb | 32 --- spec/integration/errors_spec.rb | 6 - .../globalize_strip_attributes_spec.rb | 2 - spec/integration/incoming_mail_spec.rb | 1 - spec/integration/ip_spoofing_spec.rb | 2 - spec/integration/localisation_spec.rb | 12 - .../public_body_change_request_spec.rb | 4 - spec/integration/reports_controller_spec.rb | 4 - spec/integration/request_controller_spec.rb | 8 - .../request_game_controller_spec.rb | 4 - spec/integration/search_request_spec.rb | 3 - spec/integration/send_user_message_spec.rb | 2 - .../integration/sign_in_with_redirect_spec.rb | 3 - spec/integration/signin_spec.rb | 2 - spec/integration/track_alerts_spec.rb | 3 - spec/integration/user_profile_updates_spec.rb | 13 - spec/integration/view_request_spec.rb | 16 -- .../xapian_search_highlighting_spec.rb | 2 - spec/integration/zipping_pdf_files_spec.rb | 2 - spec/lib/acts_as_xapian_spec.rb | 25 -- spec/lib/alaveteli_external_command_spec.rb | 2 - .../alaveteli_gettext/fuzzy_cleaner_spec.rb | 4 - spec/lib/alaveteli_localization_spec.rb | 26 -- spec/lib/alaveteli_mail_poller_spec.rb | 27 -- .../backends/pstore_database_spec.rb | 14 - .../ip_rate_limiter/defaults_spec.rb | 14 - .../ip_rate_limiter/whitelist_spec.rb | 8 - .../ip_rate_limiter_spec.rb | 21 -- .../rate_limiter_spec.rb | 14 - spec/lib/alaveteli_rate_limiter/rule_spec.rb | 14 - .../lib/alaveteli_rate_limiter/window_spec.rb | 12 - spec/lib/alaveteli_spam_term_checker_spec.rb | 8 - spec/lib/alaveteli_text_masker_spec.rb | 13 - .../adapters/could_not_convert_spec.rb | 8 - .../adapters/google_docs_viewer_spec.rb | 7 - .../attachment_to_html/adapters/pdf_spec.rb | 14 - .../attachment_to_html/adapters/rtf_spec.rb | 11 - .../attachment_to_html/adapters/text_spec.rb | 8 - .../attachment_to_html_spec.rb | 4 - spec/lib/attachment_to_html/view_spec.rb | 20 -- spec/lib/basic_encoding_spec.rb | 63 ----- spec/lib/confidence_intervals_spec.rb | 2 - ...ty_lines_around_rescued_exceptions_spec.rb | 81 ++++++ spec/lib/data_export_spec.rb | 11 - spec/lib/database_collation_spec.rb | 8 - spec/lib/date_quarter_spec.rb | 3 - spec/lib/default_late_calculator_spec.rb | 8 - spec/lib/graphs_spec.rb | 13 - .../health_checks/checks/period_check_spec.rb | 7 - .../health_checks/health_checkable_spec.rb | 22 -- spec/lib/health_checks/health_checks_spec.rb | 9 - spec/lib/i18n_interpolation_spec.rb | 1 - spec/lib/languages_spec.rb | 4 - .../backends/mail_backend_spec.rb | 28 -- spec/lib/mail_handler/mail_handler_spec.rb | 23 -- spec/lib/patch_tag_helper_spec.rb | 1 - spec/lib/public_body_csv_spec.rb | 13 - spec/lib/quiet_open_spec.rb | 2 - spec/lib/safe_redirect_spec.rb | 11 - spec/lib/theme_spec.rb | 2 - spec/lib/typeahead_search_spec.rb | 12 - spec/lib/user_spam_scorer_spec.rb | 59 ---- spec/lib/user_stats_spec.rb | 15 - spec/lib/world_foi_websites_spec.rb | 4 - .../alaveteli_pro/account_mailer_spec.rb | 2 - .../alaveteli_pro/embargo_mailer_spec.rb | 7 - spec/mailers/application_mailer_spec.rb | 8 - spec/mailers/contact_mailer_spec.rb | 4 - .../mailers/info_request_batch_mailer_spec.rb | 2 - spec/mailers/notification_mailer_spec.rb | 3 - spec/mailers/outgoing_mailer_spec.rb | 10 - spec/mailers/reminder_mailer_spec.rb | 4 - spec/mailers/request_mailer_spec.rb | 42 --- spec/mailers/survey_mailer_spec.rb | 11 - spec/mailers/track_mailer_spec.rb | 4 - spec/models/ability_spec.rb | 37 --- .../activity_list/comment_spec.rb | 7 - .../activity_list/embargo_expiry_spec.rb | 5 - .../activity_list/followup_resent_spec.rb | 5 - .../activity_list/followup_sent_spec.rb | 5 - .../alaveteli_pro/activity_list/item_spec.rb | 1 - .../alaveteli_pro/activity_list/list_spec.rb | 8 - .../activity_list/new_response_spec.rb | 5 - .../activity_list/overdue_spec.rb | 7 - .../activity_list/request_resent_spec.rb | 5 - .../activity_list/request_sent_spec.rb | 5 - .../activity_list/very_overdue_spec.rb | 7 - spec/models/alaveteli_pro/embargo_spec.rb | 23 -- .../alaveteli_pro/request_filter_spec.rb | 10 - .../request_summary_category_spec.rb | 1 - .../alaveteli_pro/request_summary_spec.rb | 1 - .../subscription_collection_spec.rb | 28 -- .../models/alaveteli_pro/subscription_spec.rb | 28 -- .../subscription_with_discount_spec.rb | 9 - .../to_do_list/expiring_embargo_spec.rb | 17 -- .../alaveteli_pro/to_do_list/item_spec.rb | 6 - .../alaveteli_pro/to_do_list/list_spec.rb | 8 - .../to_do_list/new_response_spec.rb | 17 -- .../to_do_list/overdue_request_spec.rb | 18 -- .../to_do_list/very_overdue_request_spec.rb | 18 -- spec/models/alaveteli_pro/with_tax_spec.rb | 2 - spec/models/censor_rule_spec.rb | 19 -- spec/models/comment_spec.rb | 19 -- spec/models/customstates.rb | 7 +- spec/models/foi_attachment_spec.rb | 17 -- spec/models/has_tag_string_tag_spec.rb | 5 - spec/models/holiday_import_spec.rb | 10 - spec/models/holiday_spec.rb | 3 - spec/models/incoming_message_error_spec.rb | 3 - spec/models/incoming_message_spec.rb | 43 --- spec/models/info_request/pro_query_spec.rb | 3 - .../prominence/been_published_query_spec.rb | 2 - .../prominence/calculator_spec.rb | 21 -- .../embargo_expired_today_query_spec.rb | 3 - .../prominence/embargo_expiring_query_spec.rb | 3 - .../prominence/embargoed_query_spec.rb | 3 - .../prominence/not_embargoed_query_spec.rb | 3 - .../prominence/public_query_spec.rb | 3 - .../prominence/searchable_query_spec.rb | 3 - .../visible_to_requester_query_spec.rb | 4 - .../authority_only_spec.rb | 14 - .../response_gatekeeper/base_spec.rb | 10 - .../response_gatekeeper/nobody_spec.rb | 4 - .../response_gatekeeper/spam_checker_spec.rb | 21 -- .../info_request/response_gatekeeper_spec.rb | 4 - .../response_rejection/base_spec.rb | 6 - .../response_rejection/bounce_spec.rb | 4 - .../response_rejection/holding_pen_spec.rb | 6 - .../info_request/response_rejection_spec.rb | 4 - .../state/awaiting_response_query_spec.rb | 3 - .../info_request/state/calculator_spec.rb | 1 - .../state/clarification_needed_query_spec.rb | 2 - .../info_request/state/complete_query_spec.rb | 2 - .../info_request/state/other_query_spec.rb | 2 - .../info_request/state/overdue_query_spec.rb | 2 - .../state/response_received_query_spec.rb | 2 - .../state/very_overdue_query_spec.rb | 2 - spec/models/info_request/state_spec.rb | 11 - spec/models/info_request_batch_spec.rb | 6 - spec/models/info_request_event_spec.rb | 28 -- spec/models/info_request_spec.rb | 260 ------------------ .../delivery_status_serializer_spec.rb | 6 - .../mail_server_log/delivery_status_spec.rb | 25 -- spec/models/mail_server_log/exim_line_spec.rb | 16 -- .../mail_server_log/postfix_line_spec.rb | 16 -- spec/models/mail_server_log_spec.rb | 26 -- spec/models/notification_spec.rb | 7 - .../template/batch_request_spec.rb | 12 - .../incoming_message_followup_spec.rb | 10 - .../template/initial_request_spec.rb | 10 - .../template/internal_review_spec.rb | 12 - spec/models/outgoing_message_spec.rb | 94 ------- spec/models/post_redirect_spec.rb | 6 - spec/models/pro_account_spec.rb | 12 - spec/models/profile_photo_spec.rb | 3 - .../category_collection_spec.rb | 5 - spec/models/public_body_category_link_spec.rb | 4 - spec/models/public_body_category_spec.rb | 15 - .../models/public_body_change_request_spec.rb | 21 -- spec/models/public_body_heading_spec.rb | 10 - spec/models/public_body_spec.rb | 119 -------- spec/models/raw_email_spec.rb | 5 - spec/models/request_classification_spec.rb | 4 - spec/models/role_spec.rb | 16 -- spec/models/spam_address_spec.rb | 6 - spec/models/track_thing_spec.rb | 1 - .../user/transaction_calculator_spec.rb | 19 -- spec/models/user_spec.rb | 92 ------- spec/models/widget_vote_spec.rb | 4 - spec/models/xapian_spec.rb | 5 - spec/script/handle-mail-replies_spec.rb | 2 - spec/script/mailin_spec.rb | 3 - spec/support/email_helpers.rb | 1 - ...shared_examples_for_activity_list_items.rb | 6 - ...examples_for_network_errors_during_send.rb | 4 - .../shared_examples_for_phase_counts.rb | 8 - .../shared_examples_for_viewing_requests.rb | 10 - .../validators/change_email_validator_spec.rb | 8 - spec/validators/contact_validator_spec.rb | 4 - spec/validators/not_nil_validator_spec.rb | 2 - .../reply_to_address_validator_spec.rb | 4 - .../_announcement.html.erb_spec.rb | 4 - .../_to_do_list.html.erb_spec.rb | 5 - .../admin_public_body/edit.html.erb_spec.rb | 3 - .../admin_public_body/show.html.erb_spec.rb | 4 - .../views/admin_request/show.html.erb_spec.rb | 6 - spec/views/admin_user/show.html.erb_spec.rb | 4 - .../account_request/index.html.erb_spec.rb | 8 - .../dashboard/_announcements.html.erb_spec.rb | 4 - .../_cancel_subscription.html.erb_spec.rb | 6 - .../to_admin_message.text.erb_spec.rb | 1 - .../followups/_followup.html.erb_spec.rb | 22 -- .../general/_log_in_bar.html.erb_spec.rb | 2 - .../general/_opengraph_tags.html.erb_spec.rb | 3 - .../_responsive_topnav.html.erb_spec.rb | 7 - .../_site_wide_announcement.html.erb_spec.rb | 4 - .../messages/_very_overdue.text.erb_spec.rb | 1 - spec/views/public_body/show.html.erb_spec.rb | 8 - .../add_public_body.text.erb_spec.rb | 1 - spec/views/reports/new.erb_spec.rb | 4 - .../request/_after_actions.html.erb_spec.rb | 1 - spec/views/request/details.html.erb_spec.rb | 1 - spec/views/request/show.html.erb_spec.rb | 7 - spec/views/request_game/play.html.erb_spec.rb | 2 - spec/views/user/sign.html.erb_spec.rb | 3 - .../already_registered.text.erb_spec.rb | 2 - .../changeemail_already_used.text.erb_spec.rb | 2 - .../changeemail_confirm.text.erb_spec.rb | 2 - .../confirm_login.text.erb_spec.rb | 2 - 531 files changed, 413 insertions(+), 3964 deletions(-) create mode 100644 lib/custom_cops/empty_lines_around_rescued_exceptions.rb create mode 100644 spec/lib/custom_cops/empty_lines_around_rescued_exceptions_spec.rb diff --git a/.ruby-style.yml b/.ruby-style.yml index 358c53b0e0..31013e58ab 100644 --- a/.ruby-style.yml +++ b/.ruby-style.yml @@ -2,6 +2,7 @@ require: - rubocop-performance - rubocop-rails + - ./lib/custom_cops/empty_lines_around_rescued_exceptions.rb AllCops: TargetRubyVersion: 3.0 @@ -136,13 +137,13 @@ Layout/EmptyComment: Enabled: false Layout/EmptyLineAfterGuardClause: - Enabled: false + Enabled: true Layout/EmptyLineAfterMagicComment: - Enabled: false + Enabled: true Layout/EmptyLineAfterMultilineCondition: - Enabled: false + Enabled: false # we prefer EmptyLinesAroundRescuedExceptions instead Layout/EmptyLineBetweenDefs: Enabled: true @@ -154,24 +155,22 @@ Layout/EmptyLinesAroundAccessModifier: Enabled: true Layout/EmptyLinesAroundArguments: - Enabled: false + Enabled: true Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false + Enabled: true Layout/EmptyLinesAroundBeginBody: - Enabled: false + Enabled: true Layout/EmptyLinesAroundBlockBody: Enabled: true - Exclude: - - spec/**/* Layout/EmptyLinesAroundClassBody: Enabled: true Layout/EmptyLinesAroundExceptionHandlingKeywords: - Enabled: false + Enabled: false # we prefer EmptyLinesAroundRescuedExceptions instead Layout/EmptyLinesAroundMethodBody: Enabled: true @@ -239,7 +238,7 @@ Layout/LeadingCommentSpace: Enabled: true Layout/LeadingEmptyLines: - Enabled: false + Enabled: true Layout/LineContinuationLeadingSpace: Enabled: false diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb index 99c9415c63..e18b4a9800 100644 --- a/app/controllers/admin_censor_rule_controller.rb +++ b/app/controllers/admin_censor_rule_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminCensorRuleController < AdminController - before_action :set_editor, only: [:create, :update] before_action :set_censor_rule, only: [:edit, :update, :destroy] before_action :set_subject_and_censor_rule_and_form_url, only: [:new, :create] diff --git a/app/controllers/admin_comment_controller.rb b/app/controllers/admin_comment_controller.rb index 7f0655b58b..4a154a3cbe 100644 --- a/app/controllers/admin_comment_controller.rb +++ b/app/controllers/admin_comment_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminCommentController < AdminController - before_action :set_comment, only: [:edit, :update] def index @@ -30,6 +29,7 @@ def edit def update raise ActiveRecord::RecordNotFound if cannot? :admin, @comment + old_body = @comment.body.dup old_visible = @comment.visible old_attention = @comment.attention_requested @@ -75,5 +75,4 @@ def set_comment def comment_hidden?(old_visibility, old_body) !@comment.visible && old_visibility && old_body == @comment.body end - end diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb index 8d125e732c..b879b14852 100644 --- a/app/controllers/admin_general_controller.rb +++ b/app/controllers/admin_general_controller.rb @@ -102,7 +102,6 @@ def timeline # Recent events @events_title = get_events_title - @events = WillPaginate::Collection.create((params[:page] or 1), 100) do |pager| # create a hash for each model type being returned info_request_event_ids = {} @@ -140,7 +139,6 @@ def timeline # set the total entries for the page to the overall number of results pager.total_entries = timestamps.size end - end def stats diff --git a/app/controllers/admin_holiday_imports_controller.rb b/app/controllers/admin_holiday_imports_controller.rb index 118c3d2456..9d1cb9b0ba 100644 --- a/app/controllers/admin_holiday_imports_controller.rb +++ b/app/controllers/admin_holiday_imports_controller.rb @@ -1,5 +1,4 @@ class AdminHolidayImportsController < AdminController - def new @holiday_import = HolidayImport.new(holiday_import_params) @holiday_import.populate if @holiday_import.valid? @@ -30,5 +29,4 @@ def holiday_import_params {} end end - end diff --git a/app/controllers/admin_holidays_controller.rb b/app/controllers/admin_holidays_controller.rb index 86dd2f4e02..e347e62691 100644 --- a/app/controllers/admin_holidays_controller.rb +++ b/app/controllers/admin_holidays_controller.rb @@ -1,5 +1,4 @@ class AdminHolidaysController < AdminController - before_action :set_holiday, only: [:edit, :update, :destroy] def index @@ -67,5 +66,4 @@ def holiday_params def set_holiday @holiday = Holiday.find(params[:id]) end - end diff --git a/app/controllers/admin_incoming_message_controller.rb b/app/controllers/admin_incoming_message_controller.rb index d6a0443105..8d8302fcf7 100644 --- a/app/controllers/admin_incoming_message_controller.rb +++ b/app/controllers/admin_incoming_message_controller.rb @@ -1,5 +1,4 @@ class AdminIncomingMessageController < AdminController - before_action :set_incoming_message, only: [:edit, :update, :destroy, :redeliver] before_action :set_info_request, :check_info_request diff --git a/app/controllers/admin_info_request_event_controller.rb b/app/controllers/admin_info_request_event_controller.rb index 4f71e83191..c93a6dd506 100644 --- a/app/controllers/admin_info_request_event_controller.rb +++ b/app/controllers/admin_info_request_event_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminInfoRequestEventController < AdminController - before_action :set_info_request_event, only: [:update] # used so due dates get fixed @@ -13,6 +12,7 @@ def update if @info_request_event.event_type != 'response' raise "can only mark responses as requires clarification" end + @info_request_event.described_state = 'waiting_clarification' @info_request_event.calculated_state = 'waiting_clarification' # TODO: deliberately don't update described_at so doesn't reenter search? @@ -29,5 +29,4 @@ def update def set_info_request_event @info_request_event = InfoRequestEvent.find(params[:id]) end - end diff --git a/app/controllers/admin_outgoing_message_controller.rb b/app/controllers/admin_outgoing_message_controller.rb index f057c715c9..49ddc76caf 100644 --- a/app/controllers/admin_outgoing_message_controller.rb +++ b/app/controllers/admin_outgoing_message_controller.rb @@ -1,5 +1,4 @@ class AdminOutgoingMessageController < AdminController - before_action :set_outgoing_message, only: [:edit, :destroy, :update, :resend] before_action :set_info_request, :check_info_request before_action :set_is_initial_message, only: [:edit, :destroy] diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb index 1ebf8f3471..35e7494ee9 100644 --- a/app/controllers/admin_public_body_categories_controller.rb +++ b/app/controllers/admin_public_body_categories_controller.rb @@ -1,5 +1,4 @@ class AdminPublicBodyCategoriesController < AdminController - include TranslatableParams before_action :set_public_body_category, only: [:edit, :update, :destroy] @@ -104,5 +103,4 @@ def public_body_category_params def set_public_body_category @public_body_category = PublicBodyCategory.find(params[:id]) end - end diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 494edd9eb7..597cd8090c 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminPublicBodyController < AdminController - include TranslatableParams before_action :set_public_body, only: [:edit, :update, :destroy] @@ -191,6 +190,7 @@ def import_csv AlaveteliLocalization. available_locales) raise "dry run mismatched real run" if !errors.empty? + notes.push("Import was successful.") end end @@ -219,10 +219,12 @@ def retrieve_csv_data(tempfile_name) unless /csv_upload-\d{8}-\d{1,5}/.match(tempfile_name) raise "Invalid filename in upload_csv: #{tempfile_name}" end + tempfile_path = File.join(Dir.tmpdir, tempfile_name) unless File.exist?(tempfile_path) raise "Missing file in upload_csv: #{tempfile_name}" end + csv_contents = File.read(tempfile_path) File.delete(tempfile_path) csv_contents @@ -278,5 +280,4 @@ def public_body_params def set_public_body @public_body = PublicBody.find(params[:id]) end - end diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb index 36c28ddb1c..f432c0392d 100644 --- a/app/controllers/admin_public_body_headings_controller.rb +++ b/app/controllers/admin_public_body_headings_controller.rb @@ -1,5 +1,4 @@ class AdminPublicBodyHeadingsController < AdminController - include TranslatableParams before_action :set_public_body_heading, only: [:edit, :update, :destroy] @@ -118,5 +117,4 @@ def public_body_heading_params def set_public_body_heading @public_body_heading = PublicBodyHeading.find(params[:id]) end - end diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 309c09dee3..851a639c33 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminRequestController < AdminController - before_action :set_info_request, :check_info_request, only: %i[ show edit update destroy move generate_upload_url hide ] @@ -44,7 +43,6 @@ def update old_tag_string = @info_request.tag_string old_comments_allowed = @info_request.comments_allowed - if @info_request.update(info_request_params) @info_request.log_event( 'edit', diff --git a/app/controllers/admin_spam_addresses_controller.rb b/app/controllers/admin_spam_addresses_controller.rb index 92830fdc88..2aafce48e4 100644 --- a/app/controllers/admin_spam_addresses_controller.rb +++ b/app/controllers/admin_spam_addresses_controller.rb @@ -1,5 +1,4 @@ class AdminSpamAddressesController < AdminController - before_action :set_spam_address, only: [:destroy] def index @@ -37,5 +36,4 @@ def spam_address_params def set_spam_address @spam_address = SpamAddress.find(params[:id]) end - end diff --git a/app/controllers/admin_track_controller.rb b/app/controllers/admin_track_controller.rb index dbfe29ba88..e67cdafaca 100644 --- a/app/controllers/admin_track_controller.rb +++ b/app/controllers/admin_track_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminTrackController < AdminController - before_action :set_track_thing, only: [:destroy] def index @@ -32,5 +31,4 @@ def destroy def set_track_thing @track_thing = TrackThing.find(params[:id]) end - end diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index 4c43fbd704..434c477062 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -197,7 +197,6 @@ def check_role_requirements end render action: 'edit' and return false end - end def set_admin_user diff --git a/app/controllers/alaveteli_pro/base_controller.rb b/app/controllers/alaveteli_pro/base_controller.rb index e4c47ba883..040e9132ce 100644 --- a/app/controllers/alaveteli_pro/base_controller.rb +++ b/app/controllers/alaveteli_pro/base_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AlaveteliPro::BaseController < ApplicationController - before_action :pro_user_authenticated? before_action :set_in_pro_area @@ -45,5 +44,4 @@ def pro_user_authenticated?(reason_params = nil) def set_in_pro_area @in_pro_area = true end - end diff --git a/app/controllers/alaveteli_pro/draft_info_request_batches_controller.rb b/app/controllers/alaveteli_pro/draft_info_request_batches_controller.rb index 5a6a36419c..d4ae9e747a 100644 --- a/app/controllers/alaveteli_pro/draft_info_request_batches_controller.rb +++ b/app/controllers/alaveteli_pro/draft_info_request_batches_controller.rb @@ -32,6 +32,7 @@ def update_bodies when 'remove' public_body = PublicBody.find(update_bodies_params[:public_body_id]) raise ActiveRecord::RecordNotFound unless @draft + @draft.public_bodies.delete(public_body) @draft.destroy! if @draft.public_bodies.empty? end diff --git a/app/controllers/alaveteli_pro/embargo_extensions_controller.rb b/app/controllers/alaveteli_pro/embargo_extensions_controller.rb index d00ad8c16a..5faa105ed6 100644 --- a/app/controllers/alaveteli_pro/embargo_extensions_controller.rb +++ b/app/controllers/alaveteli_pro/embargo_extensions_controller.rb @@ -61,6 +61,7 @@ def create_batch flash[:notice] = _('Your requests will now be private ' \ 'until {{expiry_date}}.', expiry_date: new_expiry_date) + rescue ActiveRecord::RecordInvalid flash[:error] = _("Sorry, something went wrong updating your " \ "requests' privacy settings, please try again.") diff --git a/app/controllers/alaveteli_pro/embargoes_controller.rb b/app/controllers/alaveteli_pro/embargoes_controller.rb index 656a3a6b87..987fa3d3f0 100644 --- a/app/controllers/alaveteli_pro/embargoes_controller.rb +++ b/app/controllers/alaveteli_pro/embargoes_controller.rb @@ -16,6 +16,7 @@ def create # shouldn't be reachable because CanCan should catch it, but just in case raise PermissionDenied end + @embargo = AlaveteliPro::Embargo.new(embargo_params) if @embargo.save flash[:notice] = _("Your request will now be private on " \ @@ -37,6 +38,7 @@ def destroy @info_request = @embargo.info_request # Embargoes cannot be updated individually on batch requests raise PermissionDenied if @info_request.info_request_batch_id + if @embargo.destroy @info_request.log_event('expire_embargo', {}) flash[:notice] = _("Your request is now public!") diff --git a/app/controllers/alaveteli_pro/info_requests_controller.rb b/app/controllers/alaveteli_pro/info_requests_controller.rb index d751e985b4..76f5760ca4 100644 --- a/app/controllers/alaveteli_pro/info_requests_controller.rb +++ b/app/controllers/alaveteli_pro/info_requests_controller.rb @@ -20,7 +20,6 @@ def index @per_page = 10 @request_summaries = request_summaries.paginate page: @page, per_page: @per_page - end def new @@ -64,7 +63,6 @@ def show_errors render "new" end - def all_models_valid? @info_request.valid? && @outgoing_message.valid? && \ (@embargo.nil? || @embargo.present? && @embargo.valid?) @@ -72,12 +70,14 @@ def all_models_valid? def set_draft return unless params[:draft_id] + @draft_info_request = current_user.draft_info_requests.find(params[:draft_id]) end def set_public_body return unless params[:public_body] + @public_body = PublicBody.find_by_url_name(params[:public_body]) end @@ -102,6 +102,7 @@ def create_initial_objects def destroy_draft return unless params[:draft_id] + current_user.draft_info_requests.destroy(params[:draft_id]) end diff --git a/app/controllers/alaveteli_pro/pages_controller.rb b/app/controllers/alaveteli_pro/pages_controller.rb index d72ad11862..ee03056c5a 100644 --- a/app/controllers/alaveteli_pro/pages_controller.rb +++ b/app/controllers/alaveteli_pro/pages_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AlaveteliPro::PagesController < AlaveteliPro::BaseController - skip_before_action :pro_user_authenticated? def show @@ -15,5 +14,4 @@ def show raise ActiveRecord::RecordNotFound end end - end diff --git a/app/controllers/alaveteli_pro/payment_methods_controller.rb b/app/controllers/alaveteli_pro/payment_methods_controller.rb index 9d310042ea..4ee73d51df 100644 --- a/app/controllers/alaveteli_pro/payment_methods_controller.rb +++ b/app/controllers/alaveteli_pro/payment_methods_controller.rb @@ -20,7 +20,6 @@ def update Stripe::AuthenticationError, Stripe::APIConnectionError, Stripe::StripeError => e - if send_exception_notifications? ExceptionNotifier.notify_exception(e, env: request.env) end @@ -41,5 +40,4 @@ def authenticate email_subject: _('To update your payment details') ) end - end diff --git a/app/controllers/alaveteli_pro/plans_controller.rb b/app/controllers/alaveteli_pro/plans_controller.rb index cc33c016c4..23f4f5fa51 100644 --- a/app/controllers/alaveteli_pro/plans_controller.rb +++ b/app/controllers/alaveteli_pro/plans_controller.rb @@ -39,6 +39,7 @@ def authenticate def check_has_current_subscription # TODO: This doesn't take the plan in to account return unless @user.pro_account.try(:subscription?) + flash[:error] = _('You are already subscribed to this plan') redirect_to subscriptions_path end diff --git a/app/controllers/alaveteli_pro/stripe_webhooks_controller.rb b/app/controllers/alaveteli_pro/stripe_webhooks_controller.rb index 957b7d89fe..cbae7eef91 100644 --- a/app/controllers/alaveteli_pro/stripe_webhooks_controller.rb +++ b/app/controllers/alaveteli_pro/stripe_webhooks_controller.rb @@ -103,6 +103,7 @@ def check_for_event_type def notify_exception(error) return unless send_exception_notifications? + ExceptionNotifier.notify_exception(error, env: request.env) end diff --git a/app/controllers/alaveteli_pro/subscriptions_controller.rb b/app/controllers/alaveteli_pro/subscriptions_controller.rb index cf40483e1e..e7bbb87514 100644 --- a/app/controllers/alaveteli_pro/subscriptions_controller.rb +++ b/app/controllers/alaveteli_pro/subscriptions_controller.rb @@ -69,7 +69,6 @@ def create Stripe::AuthenticationError, Stripe::APIConnectionError, Stripe::StripeError => e - flash[:error] = case e.message when /No such coupon/ @@ -201,6 +200,7 @@ def check_allowed_to_subscribe_to_pro def check_has_current_subscription # TODO: This doesn't take the plan in to account return if @user.pro_account.try(:subscription?) + flash[:notice] = _("You don't currently have a Pro subscription") redirect_to pro_plans_path end @@ -241,6 +241,7 @@ def check_plan_exists def prevent_duplicate_submission # TODO: This doesn't take the plan in to account return unless @user.pro_account.try(:subscription?) + json_redirect_to alaveteli_pro_dashboard_path end diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 64c5ed2ba5..985291c824 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -239,13 +239,11 @@ def body_request_events @events = @events.where("info_request_events.created_at > ?", event.created_at) end - if feed_type == "atom" render template: "api/request_events", formats: [:atom], layout: false elsif feed_type == "json" @event_data = [] @events.each do |json_event| - request = json_event.info_request this_event = { request_id: request.id, @@ -269,8 +267,10 @@ def body_request_events end protected + def check_api_key raise PermissionDenied, "Missing required parameter 'k'" if params[:k].nil? + @public_body = PublicBody.find_by_api_key(params[:k].gsub(' ', '+')) raise PermissionDenied if @public_body.nil? end @@ -291,6 +291,7 @@ def check_request_ownership end private + def make_url(*args) "http://" + AlaveteliConfiguration.domain + "/" + args.join("/") end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 260d379e1f..ac0fd25680 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base class PermissionDenied < StandardError end + class RouteNotFound < StandardError end @@ -378,7 +379,6 @@ def check_read_only end redirect_to frontpage_url end - end # Convert URL name for sort by order, to Xapian query @@ -452,6 +452,7 @@ def set_last_body(public_body) def country_from_ip return AlaveteliGeoIP.country_code_from_ip(user_ip) if user_ip + AlaveteliConfiguration.iso_country_code end diff --git a/app/controllers/concerns/hashable_params.rb b/app/controllers/concerns/hashable_params.rb index 90c9f1e8fd..3d33f66a50 100644 --- a/app/controllers/concerns/hashable_params.rb +++ b/app/controllers/concerns/hashable_params.rb @@ -7,7 +7,7 @@ module HashableParams def params_to_unsafe_hash(input_params) return {} if input_params.blank? + input_params.to_unsafe_h end - end diff --git a/app/controllers/concerns/prominence_headers.rb b/app/controllers/concerns/prominence_headers.rb index 2e9bf188da..22f3f550ce 100644 --- a/app/controllers/concerns/prominence_headers.rb +++ b/app/controllers/concerns/prominence_headers.rb @@ -16,6 +16,7 @@ def with_prominence def set_prominence_headers return unless with_prominence + send("set_#{ with_prominence.prominence }_headers") end diff --git a/app/controllers/concerns/translatable_params.rb b/app/controllers/concerns/translatable_params.rb index add0f7f0e4..e7fb534978 100644 --- a/app/controllers/concerns/translatable_params.rb +++ b/app/controllers/concerns/translatable_params.rb @@ -1,7 +1,7 @@ module TranslatableParams - def translatable_params(params, **keys) return {} unless params + WhitelistedParams.new(**keys).whitelist(params) end @@ -51,7 +51,5 @@ def slice_translations_params(sliced_params) end sliced_params end - end - end diff --git a/app/controllers/followups_controller.rb b/app/controllers/followups_controller.rb index e5278ae283..0e33ba77be 100644 --- a/app/controllers/followups_controller.rb +++ b/app/controllers/followups_controller.rb @@ -146,6 +146,7 @@ def send_followup @outgoing_message, @outgoing_message.incoming_message_followup ).deliver_now + rescue *OutgoingMessage.expected_send_errors => e authority_name = @outgoing_message.info_request.public_body.name @outgoing_message.record_email_failure(e.message) diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index b5918ed050..ec0391cb28 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -6,7 +6,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class GeneralController < ApplicationController - MAX_RESULTS = 500 skip_before_action :html_response, only: :version diff --git a/app/controllers/holiday_controller.rb b/app/controllers/holiday_controller.rb index 5dc229c904..0bd9623567 100644 --- a/app/controllers/holiday_controller.rb +++ b/app/controllers/holiday_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class HolidayController < ApplicationController - # This will be tidied up into a proper calendar display etc. For now # we have a very basic page that allows us to see what a due date will # be given a start date. This isn't exposed anywhere yet. @@ -20,5 +19,4 @@ def due_date @due_date.strftime("%F")]).to_a.collect(&:day).sort end end - end diff --git a/app/controllers/public_body_change_requests_controller.rb b/app/controllers/public_body_change_requests_controller.rb index 64788ef137..73d21c9c8f 100644 --- a/app/controllers/public_body_change_requests_controller.rb +++ b/app/controllers/public_body_change_requests_controller.rb @@ -59,5 +59,4 @@ def catch_spam def set_render_recaptcha @render_recaptcha = !@user end - end diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index f116ee780d..e98e33a336 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -92,7 +92,6 @@ def show end format.json { render json: @public_body.json_for_api } end - end end @@ -193,9 +192,9 @@ def list_all_csv def search_typeahead query = params[:query] return head :bad_request unless query + flash[:search_params] = params.slice(:query, :bodies, :page) @xapian_requests = typeahead_search(query, model: PublicBody) render partial: "public_body/search_ahead" end - end diff --git a/app/controllers/refusal_advice_controller.rb b/app/controllers/refusal_advice_controller.rb index b882045b56..84b190f2a7 100644 --- a/app/controllers/refusal_advice_controller.rb +++ b/app/controllers/refusal_advice_controller.rb @@ -21,6 +21,7 @@ def create def authenticate return unless info_request + authenticated?(as: info_request.user) || ask_to_login(as: info_request.user) end diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 4d1fc59cd2..d486b621d1 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -121,9 +121,11 @@ def similar if @page > MAX_RESULTS / PER_PAGE raise ActiveRecord::RecordNotFound, "Sorry. No pages after #{MAX_RESULTS / PER_PAGE}." end + @info_request = InfoRequest.find_by_url_title!(params[:url_title]) return render_hidden if cannot?(:read, @info_request) + @xapian_object = ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, offset: (@page - 1) * @per_page, @@ -302,6 +304,7 @@ def new @outgoing_message.info_request, @outgoing_message ).deliver_now + rescue *OutgoingMessage.expected_send_errors => e # Catch a wide variety of potential ActionMailer failures and # record the exception reason so administrators don't have to @@ -338,6 +341,7 @@ def show_request_event if @info_request_event.info_request.embargo raise ActiveRecord::RecordNotFound end + if @info_request_event.is_incoming_message? redirect_to incoming_message_url(@info_request_event.incoming_message), status: :moved_permanently elsif @info_request_event.is_outgoing_message? @@ -452,6 +456,7 @@ def download_entire_request else # Test for whole request being hidden or requester-only return render_hidden if cannot?(:read, @info_request) + cache_file_path = @info_request.make_zip_cache_path(@user) unless File.exist?(cache_file_path) FileUtils.mkdir_p(File.dirname(cache_file_path)) @@ -546,6 +551,7 @@ def assign_state_transition_variables def state_transitions_empty?(transitions) return true if transitions.nil? + transitions[:pending].empty? && \ transitions[:complete].empty? && \ transitions[:other].empty? @@ -558,9 +564,11 @@ def make_request_zip(info_request, file_path) message_index = 0 info_request.incoming_messages.each do |message| next unless can?(:read, message) + message_index += 1 message.get_attachments_for_display.each do |attachment| next unless can?(:read, attachment) + filename = "#{message_index}_#{attachment.url_part_number}_#{attachment.display_filename}" zipfile.get_output_stream(filename) do |f| body = message.apply_masks(attachment.default_body, attachment.content_type) @@ -619,6 +627,7 @@ def render_new_compose if public_body.nil? # TODO: proper 404 raise ActiveRecord::RecordNotFound, "None found" end + public_body.id end elsif params[:public_body_id] @@ -681,7 +690,6 @@ def render_new_compose redirect_to public_body_url(@info_request.public_body) end nil - end def render_new_preview @@ -711,6 +719,7 @@ def redirect_numeric_id_to_url_title # We don't want to leak the title of embargoed or hidden requests, so # don't even redirect on if the user can't access the request return render_hidden if cannot?(:read, @info_request) + redirect_to request_url(@info_request, format: params[:format]) end end diff --git a/app/controllers/request_game_controller.rb b/app/controllers/request_game_controller.rb index 6e3a9906dd..3f171493ef 100644 --- a/app/controllers/request_game_controller.rb +++ b/app/controllers/request_game_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class RequestGameController < ApplicationController - def play session[:request_game] = Time.zone.now @@ -61,5 +60,4 @@ def stop flash[:notice] = _('Thank you for helping us keep the site tidy!') redirect_to frontpage_url end - end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 3e5fad9a09..4e58a57831 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -1,7 +1,6 @@ # controllers/services_controller.rb: class ServicesController < ApplicationController - skip_before_action :html_response before_action :set_info_request, :check_info_request, only: %i[ @@ -34,7 +33,6 @@ def other_country_message else country_data = WorldFOIWebsites.by_code(site_country_code) - text = if WorldFOIWebsites.can_ask_the_eu?(user_country_code) if country_data no_user_site_eu_msg(country_data[:country_name]) @@ -138,5 +136,4 @@ def no_user_site_eu_msg(country_name = nil) def ask_the_eu_link %q(Ask The EU) end - end diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index b89a5331ed..f3537fe9d4 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -54,6 +54,7 @@ def track_list def track_public_body @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise ActiveRecord::RecordNotFound, "None found" if @public_body.nil? + # If found by historic name, or alternate locale name, redirect to new name if @public_body.url_name != params[:url_name] redirect_to track_public_body_url(url_name: @public_body.url_name, feed: params[:feed], event_type: params[:event_type]) @@ -77,6 +78,7 @@ def track_public_body def track_user @track_user = User.find_by_url_name(params[:url_name]) raise ActiveRecord::RecordNotFound, "No such user" if @track_user.nil? + @track_thing = TrackThing.create_track_for_user(@track_user) return atom_feed_internal if params[:feed] == 'feed' @@ -163,6 +165,7 @@ def atom_feed if @track_thing.track_medium != 'feed' raise "can only view feeds for feed tracks, not email ones" end + redirect_to do_track_url(@track_thing, 'feed'), status: :moved_permanently end @@ -247,5 +250,4 @@ def delete_all_type destroy_all redirect_to SafeRedirect.new(params[:r]).path end - end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 625b827b7d..3dd0977586 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -89,6 +89,7 @@ def wall # TODO: combine these as OR query @xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse') @xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil) + rescue @xapian_requests = nil @xapian_comments = nil @@ -126,7 +127,6 @@ def wall format.html { @has_json = true } format.json { render json: @display_user.json_for_api } end - end # Create new account form @@ -182,6 +182,7 @@ def signup end nil end + rescue ActionController::ParameterMissing flash[:error] = _('Invalid form submission') render action: :sign @@ -348,7 +349,6 @@ def set_profile_photo @user.set_profile_photo(@profile_photo) draft_profile_photo.destroy - if @user.get_about_me_for_html_display.empty? flash[:notice] = { partial: "user/update_profile_photo" } redirect_to edit_profile_about_me_url @@ -362,7 +362,6 @@ def set_profile_photo end def clear_profile_photo - # check they are logged in (the upload photo option is anyway only available when logged in) unless authenticated? flash[:error] = _("You need to be logged in to clear your profile photo.") @@ -569,6 +568,7 @@ def set_show_requests @xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse') @xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil) # TODO: make this rescue specific to errors thrown when xapian is not working + rescue @xapian_requests = nil @xapian_comments = nil @@ -591,6 +591,7 @@ def show_about_me? return false unless @display_user.active? return true if @display_user.confirmed_not_spam? return true if @user + false end @@ -633,5 +634,4 @@ def spam_should_be_blocked? AlaveteliConfiguration.block_spam_signups || AlaveteliConfiguration.enable_anti_spam end - end diff --git a/app/controllers/user_profile/about_me_controller.rb b/app/controllers/user_profile/about_me_controller.rb index a1987c9836..434f4016e0 100644 --- a/app/controllers/user_profile/about_me_controller.rb +++ b/app/controllers/user_profile/about_me_controller.rb @@ -13,6 +13,7 @@ def update # TODO: Use strong params to require :user key return redirect_to user_url(@user) unless params[:user] + @user.about_me = params[:user][:about_me] unless @user.confirmed_not_spam? diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 8584347fac..ee142b52d1 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -1,5 +1,4 @@ class Users::ConfirmationsController < UserController - def confirm post_redirect = PostRedirect.find_by_email_token(params[:email_token]) @@ -43,5 +42,4 @@ def confirm_user!(user) user.confirm! user end - end diff --git a/app/controllers/users/messages_controller.rb b/app/controllers/users/messages_controller.rb index 90220a5c65..c4e42eb494 100644 --- a/app/controllers/users/messages_controller.rb +++ b/app/controllers/users/messages_controller.rb @@ -1,6 +1,5 @@ # Allowing users to send user-to-user messages class Users::MessagesController < UserController - before_action :set_recipient, :check_recipient_accepts_messages, :check_can_send_messages, diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index fa1cf15dd8..3e02e0e408 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -52,6 +52,7 @@ def create else send_confirmation_mail @user_signin end + rescue ActionController::ParameterMissing flash[:error] = _('Invalid form submission') render template: 'user/sign' @@ -73,5 +74,4 @@ def spam_should_be_blocked? AlaveteliConfiguration.block_spam_signins || AlaveteliConfiguration.enable_anti_spam end - end diff --git a/app/controllers/widget_votes_controller.rb b/app/controllers/widget_votes_controller.rb index cf04d0f63c..d5338ddc0c 100644 --- a/app/controllers/widget_votes_controller.rb +++ b/app/controllers/widget_votes_controller.rb @@ -7,7 +7,6 @@ require 'securerandom' class WidgetVotesController < ApplicationController - before_action :check_widget_config, :find_info_request, :check_prominence # Track interest in a request from a non-logged in user @@ -46,5 +45,4 @@ def check_prominence head :forbidden end end - end diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb index b2c801b475..4484734993 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class WidgetsController < ApplicationController - before_action :check_widget_config, :find_info_request, :check_prominence def show @@ -51,5 +50,4 @@ def check_prominence head :forbidden end end - end diff --git a/app/helpers/admin/prominence_helper.rb b/app/helpers/admin/prominence_helper.rb index e39fabf882..25a653d78c 100644 --- a/app/helpers/admin/prominence_helper.rb +++ b/app/helpers/admin/prominence_helper.rb @@ -14,6 +14,7 @@ def prominence_icon(prominenceable) def highlight_prominence(prominenceable) prominence = prominenceable.try(:prominence) || prominenceable return prominence unless HIGHLIGHT[prominence] + tag.span prominence, class: HIGHLIGHT[prominence] end end diff --git a/app/helpers/admin_comments_helper.rb b/app/helpers/admin_comments_helper.rb index 959a5330b6..3e36004231 100644 --- a/app/helpers/admin_comments_helper.rb +++ b/app/helpers/admin_comments_helper.rb @@ -1,4 +1,3 @@ - module AdminCommentsHelper def comment_labels(comment) html = '' diff --git a/app/helpers/admin_users_helper.rb b/app/helpers/admin_users_helper.rb index 5625f62aa9..1aa526d4a4 100644 --- a/app/helpers/admin_users_helper.rb +++ b/app/helpers/admin_users_helper.rb @@ -22,5 +22,4 @@ def closed_label def role_label(role) content_tag(:span, role.name, class: 'label') end - end diff --git a/app/helpers/alaveteli_pro/account_helper.rb b/app/helpers/alaveteli_pro/account_helper.rb index 2dd5feb1e7..6828b3f8e2 100644 --- a/app/helpers/alaveteli_pro/account_helper.rb +++ b/app/helpers/alaveteli_pro/account_helper.rb @@ -1,5 +1,4 @@ module AlaveteliPro::AccountHelper - def billing_frequency(billing_unit) case billing_unit when 'day' @@ -22,5 +21,4 @@ def card_expiry_message(month, year) def subscription_amount(subscription) AlaveteliPro::WithTax.new(subscription).amount_with_tax end - end diff --git a/app/helpers/alaveteli_pro/dashboard_helper.rb b/app/helpers/alaveteli_pro/dashboard_helper.rb index 039bfa63b3..a14a0d1dc1 100644 --- a/app/helpers/alaveteli_pro/dashboard_helper.rb +++ b/app/helpers/alaveteli_pro/dashboard_helper.rb @@ -1,5 +1,4 @@ module AlaveteliPro::DashboardHelper - def activity_item_description(activity_item) _(activity_item.description, description_urls(activity_item)) end @@ -11,4 +10,3 @@ def description_urls(activity_item) end end end - diff --git a/app/helpers/alaveteli_pro/info_requests_helper.rb b/app/helpers/alaveteli_pro/info_requests_helper.rb index aa40191732..efe4a85f32 100644 --- a/app/helpers/alaveteli_pro/info_requests_helper.rb +++ b/app/helpers/alaveteli_pro/info_requests_helper.rb @@ -1,11 +1,13 @@ module AlaveteliPro::InfoRequestsHelper def embargo_publish_at(embargo) return unless embargo && embargo.publish_at + I18n.l(embargo.publish_at, format: '%-d %B %Y') end def embargo_extend_from(embargo) return unless embargo && embargo.publish_at + I18n.l(embargo.calculate_expiring_notification_at, format: '%-d %B %Y') end diff --git a/app/helpers/analytics_helper.rb b/app/helpers/analytics_helper.rb index 539dc4aee2..1d0116c1b6 100644 --- a/app/helpers/analytics_helper.rb +++ b/app/helpers/analytics_helper.rb @@ -1,11 +1,9 @@ module AnalyticsHelper - # helpers for embedding Google Analytics code # # Event categories and actions should be drawn from the list in the # lib/analytics_events.rb file (add your own there when making new ones) - # Public: Constructs a String consisting of a Google Analytics (GA) tracking # event function call with the (mandatory) event category and action params # and optional label and value params. @@ -100,5 +98,4 @@ def format_event_label(label, is_script=false) "'#{label}'" end end - end diff --git a/app/helpers/config_helper.rb b/app/helpers/config_helper.rb index f5f1e9fb98..fc82412715 100644 --- a/app/helpers/config_helper.rb +++ b/app/helpers/config_helper.rb @@ -1,5 +1,4 @@ module ConfigHelper - def site_name AlaveteliConfiguration.site_name end @@ -12,5 +11,4 @@ def send_exception_notifications? !AlaveteliConfiguration.exception_notifications_from.blank? && !AlaveteliConfiguration.exception_notifications_to.blank? end - end diff --git a/app/helpers/health_checks_helper.rb b/app/helpers/health_checks_helper.rb index 297e2e702b..44803c9c25 100644 --- a/app/helpers/health_checks_helper.rb +++ b/app/helpers/health_checks_helper.rb @@ -1,8 +1,6 @@ module HealthChecksHelper - def check_status(check) style = check.ok? ? '' : 'color: red' content_tag(:b, check.message, style: style) end - end diff --git a/app/helpers/highlight_helper.rb b/app/helpers/highlight_helper.rb index 8258337f30..e597ea85a4 100644 --- a/app/helpers/highlight_helper.rb +++ b/app/helpers/highlight_helper.rb @@ -52,6 +52,7 @@ def excerpt(text, phrase, options = {}) end return unless (matches = text.match(regex)) + phrase = matches[0] unless separator.empty? diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index ff0a6fd102..1090026b2f 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -6,7 +6,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ module LinkToHelper - # Links to various models # Requests @@ -313,6 +312,7 @@ def message_url(message, options = {}) anchor ||= dom_id(message) return "##{anchor}" if options[:anchor_only] + default_options = { anchor: anchor } default_options[:nocache] = anchor if options.delete(:cachebust) diff --git a/app/helpers/notification_mailer_helper.rb b/app/helpers/notification_mailer_helper.rb index 328bf628e4..b0bccddccd 100644 --- a/app/helpers/notification_mailer_helper.rb +++ b/app/helpers/notification_mailer_helper.rb @@ -1,4 +1,3 @@ - module NotificationMailerHelper # Group an array of notifications into a hash keyed by their # info_request_event's event_type string diff --git a/app/helpers/prominence_helper.rb b/app/helpers/prominence_helper.rb index 18802402bc..231d49b922 100644 --- a/app/helpers/prominence_helper.rb +++ b/app/helpers/prominence_helper.rb @@ -54,6 +54,7 @@ def notice def contact_us return if current_user&.is_admin? + contact_us_notice( contact_us_link: link_to(_('contact us'), help_contact_path) ) @@ -93,6 +94,7 @@ def reason def default_prominence_reason return '' if current_user&.is_admin? + self.class.default_prominence_reason end end diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb index 8f278130b9..609f117525 100644 --- a/app/helpers/public_body_helper.rb +++ b/app/helpers/public_body_helper.rb @@ -1,5 +1,4 @@ module PublicBodyHelper - # Public: The reasons a request can't be made to a PublicBody # The returned reasons are ordered by priority. For example, if the body no # longer exists there is no reason to ask for its contact details if we don't @@ -53,5 +52,4 @@ def type_of_authority(public_body) _("A public authority") end end - end diff --git a/app/helpers/refusal_advice_helper.rb b/app/helpers/refusal_advice_helper.rb index 7c09d33ba0..0f07803f3f 100644 --- a/app/helpers/refusal_advice_helper.rb +++ b/app/helpers/refusal_advice_helper.rb @@ -2,6 +2,7 @@ module RefusalAdviceHelper def refusal_advice_actionable?(action, info_request:) return true unless action.target.key?(:internal) + current_user && current_user == info_request&.user end diff --git a/app/helpers/track_helper.rb b/app/helpers/track_helper.rb index c054ebeb83..97e8115c44 100644 --- a/app/helpers/track_helper.rb +++ b/app/helpers/track_helper.rb @@ -1,5 +1,4 @@ module TrackHelper - def already_subscribed_notice(track_thing) case track_thing.track_type when 'request_updates' diff --git a/app/mailers/alaveteli_pro/account_mailer.rb b/app/mailers/alaveteli_pro/account_mailer.rb index b33d9f0c18..593a6e38d0 100644 --- a/app/mailers/alaveteli_pro/account_mailer.rb +++ b/app/mailers/alaveteli_pro/account_mailer.rb @@ -4,7 +4,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ module AlaveteliPro class AccountMailer < ApplicationMailer - def account_request(account_request) @account_request = account_request set_reply_to_headers(nil, 'Reply-To' => @account_request.email) diff --git a/app/mailers/alaveteli_pro/embargo_mailer.rb b/app/mailers/alaveteli_pro/embargo_mailer.rb index 403c1793f0..068da118c4 100644 --- a/app/mailers/alaveteli_pro/embargo_mailer.rb +++ b/app/mailers/alaveteli_pro/embargo_mailer.rb @@ -22,6 +22,7 @@ def self.alert_expiring info_request_event_id: alert_event_id).exists? end next if info_requests.empty? + expiring_alert(user, info_requests).deliver_now info_requests.each do |info_request| alert_event_id = info_request.last_embargo_set_event.id @@ -51,6 +52,7 @@ def self.alert_expired info_request_event_id: alert_event_id).exists? end next if info_requests.empty? + expired_alert(user, info_requests).deliver_now info_requests.each do |info_request| alert_event_id = info_request.last_embargo_expire_event.id diff --git a/app/mailers/info_request_batch_mailer.rb b/app/mailers/info_request_batch_mailer.rb index 774e3303c4..34bd24f7b6 100644 --- a/app/mailers/info_request_batch_mailer.rb +++ b/app/mailers/info_request_batch_mailer.rb @@ -5,7 +5,6 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class InfoRequestBatchMailer < ApplicationMailer - def batch_sent(info_request_batch, unrequestable, user) @info_request_batch = info_request_batch @unrequestable = unrequestable diff --git a/app/mailers/outgoing_mailer.rb b/app/mailers/outgoing_mailer.rb index 1c256fbffd..fa373e305b 100644 --- a/app/mailers/outgoing_mailer.rb +++ b/app/mailers/outgoing_mailer.rb @@ -52,6 +52,7 @@ def self.name_and_email_for_followup(info_request, incoming_message_followup) incoming_message_followup.from_email) end end + # Used in the preview of followup def self.name_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? @@ -61,6 +62,7 @@ def self.name_for_followup(info_request, incoming_message_followup) incoming_message_followup.safe_from_name || info_request.public_body.name end end + # Used when making list of followup places to remove duplicates def self.email_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? @@ -69,6 +71,7 @@ def self.email_for_followup(info_request, incoming_message_followup) incoming_message_followup.from_email end end + # Subject to use for followup def self.subject_for_followup(info_request, outgoing_message, options = {}) if outgoing_message.what_doing == 'internal_review' @@ -78,6 +81,7 @@ def self.subject_for_followup(info_request, outgoing_message, options = {}) html: options[:html]) end end + # Whether we have a valid email address for a followup def self.is_followupable?(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? @@ -87,6 +91,7 @@ def self.is_followupable?(info_request, incoming_message_followup) true end end + # Message-ID to use def self.id_for_message(outgoing_message) message_id = "ogm-" + outgoing_message.id.to_s @@ -95,5 +100,4 @@ def self.id_for_message(outgoing_message) message_id += "@" + AlaveteliConfiguration.incoming_email_domain "<" + message_id + ">" end - end diff --git a/app/mailers/reminder_mailer.rb b/app/mailers/reminder_mailer.rb index 78b91e4e7b..d5936e0195 100644 --- a/app/mailers/reminder_mailer.rb +++ b/app/mailers/reminder_mailer.rb @@ -1,4 +1,3 @@ - class ReminderMailer < ApplicationMailer # Send reminder message to administrator def public_holidays(name, email, subject) diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index 499f8ae43d..d614721967 100644 --- a/app/mailers/request_mailer.rb +++ b/app/mailers/request_mailer.rb @@ -364,6 +364,7 @@ def self.alert_new_response_reminders alert_new_response_reminders_internal(days, "new_response_reminder_#{i+1}") end end + def self.alert_new_response_reminders_internal(days_since, type_code) info_requests = InfoRequest. where_old_unclassified(days_since). @@ -457,7 +458,6 @@ def self.alert_not_clarified_request # Send email alert to request submitter for new comments on the request. def self.alert_comment_on_request - # We only check comments made in the last month - this means if the # cron jobs broke for more than a month events would be lost, but no # matter. I suspect the performance gain will be needed (with an index on updated_at) @@ -542,5 +542,4 @@ def self.alert_comment_on_request def set_footer_template @footer_template = 'default' end - end diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb index 72dc5b891c..89b1fe3ce3 100644 --- a/app/mailers/track_mailer.rb +++ b/app/mailers/track_mailer.rb @@ -151,5 +151,4 @@ def self.alert_tracks_loop def set_footer_template @footer_template = 'default_with_unsubscribe' end - end diff --git a/app/models/alaveteli_pro/account_request.rb b/app/models/alaveteli_pro/account_request.rb index 05ed9c88d9..fb77031c49 100644 --- a/app/models/alaveteli_pro/account_request.rb +++ b/app/models/alaveteli_pro/account_request.rb @@ -21,6 +21,7 @@ class AlaveteliPro::AccountRequest def initialize(attributes = {}) return unless attributes + attributes.each do |name, value| send("#{name}=", value) end diff --git a/app/models/alaveteli_pro/activity_list/comment.rb b/app/models/alaveteli_pro/activity_list/comment.rb index 4780614d36..d4c6a3c337 100644 --- a/app/models/alaveteli_pro/activity_list/comment.rb +++ b/app/models/alaveteli_pro/activity_list/comment.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class Comment < Item - def description if event.comment.user == event.info_request.user N_('You added a new annotation on your request to ' \ @@ -21,7 +20,6 @@ def description_urls def call_to_action_url comment_path(event.comment) end - end end end diff --git a/app/models/alaveteli_pro/activity_list/embargo_expiry.rb b/app/models/alaveteli_pro/activity_list/embargo_expiry.rb index eb224e3af7..1c0c6cc3cb 100644 --- a/app/models/alaveteli_pro/activity_list/embargo_expiry.rb +++ b/app/models/alaveteli_pro/activity_list/embargo_expiry.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class EmbargoExpiry < Item - def description N_("Your request to {{public_body_name}} \"{{info_request_title}}\" " \ "is now public.") @@ -10,7 +9,6 @@ def description def call_to_action_url info_request_path end - end end end diff --git a/app/models/alaveteli_pro/activity_list/followup_resent.rb b/app/models/alaveteli_pro/activity_list/followup_resent.rb index 80fd48b4b1..1e922062dc 100644 --- a/app/models/alaveteli_pro/activity_list/followup_resent.rb +++ b/app/models/alaveteli_pro/activity_list/followup_resent.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class FollowupResent < Item - def description case event.calculated_state when 'internal_review' @@ -16,7 +15,6 @@ def description def call_to_action_url outgoing_message_path(event.outgoing_message) end - end end end diff --git a/app/models/alaveteli_pro/activity_list/followup_sent.rb b/app/models/alaveteli_pro/activity_list/followup_sent.rb index 2dc155dce9..6f5592846d 100644 --- a/app/models/alaveteli_pro/activity_list/followup_sent.rb +++ b/app/models/alaveteli_pro/activity_list/followup_sent.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class FollowupSent < Item - def description case event.calculated_state when 'internal_review' @@ -16,7 +15,6 @@ def description def call_to_action_url outgoing_message_path(event.outgoing_message) end - end end end diff --git a/app/models/alaveteli_pro/activity_list/item.rb b/app/models/alaveteli_pro/activity_list/item.rb index 5956f0b085..96d84647f6 100644 --- a/app/models/alaveteli_pro/activity_list/item.rb +++ b/app/models/alaveteli_pro/activity_list/item.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class Item - include Rails.application.routes.url_helpers include LinkToHelper include ActionView::Helpers::DateHelper @@ -40,7 +39,6 @@ def description_urls def event_time event.created_at end - end end end diff --git a/app/models/alaveteli_pro/activity_list/list.rb b/app/models/alaveteli_pro/activity_list/list.rb index aa33ffa934..89d730f8b4 100644 --- a/app/models/alaveteli_pro/activity_list/list.rb +++ b/app/models/alaveteli_pro/activity_list/list.rb @@ -1,6 +1,5 @@ module AlaveteliPro module ActivityList - class List attr_accessor :user, :page, :per_page @@ -39,7 +38,6 @@ def activity_types "embargo_expiry" => ActivityList::EmbargoExpiry } end - end end end diff --git a/app/models/alaveteli_pro/activity_list/new_response.rb b/app/models/alaveteli_pro/activity_list/new_response.rb index f45d941424..99ce2d6d1b 100644 --- a/app/models/alaveteli_pro/activity_list/new_response.rb +++ b/app/models/alaveteli_pro/activity_list/new_response.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class NewResponse < Item - def description N_('Your request to {{public_body_name}} "{{info_request_title}}" received a new response.') end @@ -9,7 +8,6 @@ def description def call_to_action_url incoming_message_path(event.incoming_message) end - end end end diff --git a/app/models/alaveteli_pro/activity_list/overdue.rb b/app/models/alaveteli_pro/activity_list/overdue.rb index 2603c64c18..011c15cf7e 100644 --- a/app/models/alaveteli_pro/activity_list/overdue.rb +++ b/app/models/alaveteli_pro/activity_list/overdue.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class Overdue < Item - def description N_('{{public_body_name}} are delayed in responding to your request "{{info_request_title}}".') end @@ -13,7 +12,6 @@ def call_to_action def call_to_action_url new_request_followup_path(request_id: event.info_request.id, anchor: 'followup') end - end end end diff --git a/app/models/alaveteli_pro/activity_list/request_resent.rb b/app/models/alaveteli_pro/activity_list/request_resent.rb index 6e8cd242b8..aa0876903f 100644 --- a/app/models/alaveteli_pro/activity_list/request_resent.rb +++ b/app/models/alaveteli_pro/activity_list/request_resent.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class RequestResent < Item - def description N_('Your request "{{info_request_title}}" to {{public_body_name}} was resent.') end @@ -9,7 +8,6 @@ def description def call_to_action_url info_request_path end - end end end diff --git a/app/models/alaveteli_pro/activity_list/request_sent.rb b/app/models/alaveteli_pro/activity_list/request_sent.rb index a2a671285c..9ec29232cd 100644 --- a/app/models/alaveteli_pro/activity_list/request_sent.rb +++ b/app/models/alaveteli_pro/activity_list/request_sent.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class RequestSent < Item - def description N_('You sent a request "{{info_request_title}}" to {{public_body_name}}.') end @@ -9,7 +8,6 @@ def description def call_to_action_url info_request_path end - end end end diff --git a/app/models/alaveteli_pro/activity_list/very_overdue.rb b/app/models/alaveteli_pro/activity_list/very_overdue.rb index 385d57db9a..3b78bd5db5 100644 --- a/app/models/alaveteli_pro/activity_list/very_overdue.rb +++ b/app/models/alaveteli_pro/activity_list/very_overdue.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ActivityList class VeryOverdue < Item - def description N_('{{public_body_name}} became long overdue in responding to your request "{{info_request_title}}".') end @@ -15,7 +14,6 @@ def call_to_action_url anchor: 'followup', internal_review: 1) end - end end end diff --git a/app/models/alaveteli_pro/embargo/translated_constants.rb b/app/models/alaveteli_pro/embargo/translated_constants.rb index dcb00da9e1..7597539e95 100644 --- a/app/models/alaveteli_pro/embargo/translated_constants.rb +++ b/app/models/alaveteli_pro/embargo/translated_constants.rb @@ -1,6 +1,5 @@ class AlaveteliPro::Embargo module TranslatedConstants - def self.duration_labels { "3_months" => _("3 Months"), @@ -8,6 +7,5 @@ def self.duration_labels "12_months" => _("12 Months") }.freeze end - end end diff --git a/app/models/alaveteli_pro/invoice_collection.rb b/app/models/alaveteli_pro/invoice_collection.rb index 74a8dc4732..b1f00882e3 100644 --- a/app/models/alaveteli_pro/invoice_collection.rb +++ b/app/models/alaveteli_pro/invoice_collection.rb @@ -17,6 +17,7 @@ def initialize(customer) def retrieve(id) return unless @customer + AlaveteliPro::Invoice.new(invoices.retrieve(id)) end @@ -50,6 +51,7 @@ def each(&block) def invoices return [] unless @customer + @invoices ||= Stripe::Invoice.list(customer: @customer) end end diff --git a/app/models/alaveteli_pro/request_filter.rb b/app/models/alaveteli_pro/request_filter.rb index ef26664775..f6db10cd1f 100644 --- a/app/models/alaveteli_pro/request_filter.rb +++ b/app/models/alaveteli_pro/request_filter.rb @@ -1,6 +1,5 @@ module AlaveteliPro class RequestFilter - extend ActiveModel::Naming include ActiveModel::Conversion @@ -154,6 +153,5 @@ def filter_labels def filter_value filter_params.include?(@filter) ? filter_values[@filter] : filter_values[nil] end - end end diff --git a/app/models/alaveteli_pro/subscription_collection.rb b/app/models/alaveteli_pro/subscription_collection.rb index 011037b58a..7e2bb67167 100644 --- a/app/models/alaveteli_pro/subscription_collection.rb +++ b/app/models/alaveteli_pro/subscription_collection.rb @@ -26,6 +26,7 @@ def build def retrieve(id) return unless @customer + AlaveteliPro::Subscription.new(subscriptions.retrieve(id)) end @@ -59,6 +60,7 @@ def each(&block) def subscriptions return [] unless @customer + @customer.subscriptions end end diff --git a/app/models/alaveteli_pro/to_do_list/expiring_embargo.rb b/app/models/alaveteli_pro/to_do_list/expiring_embargo.rb index 5f6815a78c..55f5c6815d 100644 --- a/app/models/alaveteli_pro/to_do_list/expiring_embargo.rb +++ b/app/models/alaveteli_pro/to_do_list/expiring_embargo.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ToDoList class ExpiringEmbargo < Item - def description n_("{{count}} request will be made public this week.", "{{count}} requests will be made public this week.", diff --git a/app/models/alaveteli_pro/to_do_list/item.rb b/app/models/alaveteli_pro/to_do_list/item.rb index b8742235fb..41b8745df0 100644 --- a/app/models/alaveteli_pro/to_do_list/item.rb +++ b/app/models/alaveteli_pro/to_do_list/item.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ToDoList class Item - include Rails.application.routes.url_helpers attr_accessor :user @@ -16,7 +15,6 @@ def count def items [] end - end end end diff --git a/app/models/alaveteli_pro/to_do_list/list.rb b/app/models/alaveteli_pro/to_do_list/list.rb index 4d56d0a196..41c12c778d 100644 --- a/app/models/alaveteli_pro/to_do_list/list.rb +++ b/app/models/alaveteli_pro/to_do_list/list.rb @@ -1,6 +1,5 @@ module AlaveteliPro module ToDoList - class List attr_accessor :user @@ -22,7 +21,6 @@ def self.item_types ToDoList::OverdueRequest, ToDoList::VeryOverdueRequest ] end - end end end diff --git a/app/models/alaveteli_pro/to_do_list/new_response.rb b/app/models/alaveteli_pro/to_do_list/new_response.rb index 8bef8e6d80..fbfbd5a1c5 100644 --- a/app/models/alaveteli_pro/to_do_list/new_response.rb +++ b/app/models/alaveteli_pro/to_do_list/new_response.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ToDoList class NewResponse < Item - def description n_("{{count}} request has received a response.", "{{count}} requests have received a response.", @@ -31,7 +30,6 @@ def call_to_action "Update statuses.", count) end - end end end diff --git a/app/models/alaveteli_pro/to_do_list/overdue_request.rb b/app/models/alaveteli_pro/to_do_list/overdue_request.rb index 9586da3c46..c15b5f6562 100644 --- a/app/models/alaveteli_pro/to_do_list/overdue_request.rb +++ b/app/models/alaveteli_pro/to_do_list/overdue_request.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ToDoList class OverdueRequest < Item - def description n_("{{count}} request is delayed.", "{{count}} requests are delayed.", diff --git a/app/models/alaveteli_pro/to_do_list/very_overdue_request.rb b/app/models/alaveteli_pro/to_do_list/very_overdue_request.rb index 0c0655c5e8..e52f4bc0b8 100644 --- a/app/models/alaveteli_pro/to_do_list/very_overdue_request.rb +++ b/app/models/alaveteli_pro/to_do_list/very_overdue_request.rb @@ -1,7 +1,6 @@ module AlaveteliPro module ToDoList class VeryOverdueRequest < Item - def description n_("{{count}} request is long overdue.", "{{count}} requests are long overdue.", diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb index 5a40589cc4..0ecd281508 100644 --- a/app/models/censor_rule.rb +++ b/app/models/censor_rule.rb @@ -57,6 +57,7 @@ class CensorRule < ApplicationRecord def apply_to_text(text_to_censor) return nil if text_to_censor.nil? + text_to_censor.gsub(to_replace('UTF-8'), replacement) end diff --git a/app/models/comment.rb b/app/models/comment.rb index 747a66a7df..7a373b0068 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -111,6 +111,7 @@ def self.exceeded_creation_rate?(comments) def body ret = read_attribute(:body) return ret if ret.nil? + ret = ret.strip # remove excess linebreaks that unnecessarily space it out ret = ret.gsub(/(?:\n\s*){2,}/, "\n\n") diff --git a/app/models/concerns/alaveteli_pro/phase_counts.rb b/app/models/concerns/alaveteli_pro/phase_counts.rb index 7fa1b3f638..78d83d59bd 100644 --- a/app/models/concerns/alaveteli_pro/phase_counts.rb +++ b/app/models/concerns/alaveteli_pro/phase_counts.rb @@ -1,6 +1,5 @@ module AlaveteliPro module PhaseCounts - extend ActiveSupport::Concern def phase_counts @@ -23,7 +22,5 @@ def phase_counts! @phase_counts = hash_with_default.merge(raw_counts).with_indifferent_access end - end - end diff --git a/app/models/concerns/alaveteli_pro/request_summaries.rb b/app/models/concerns/alaveteli_pro/request_summaries.rb index 5ee8da0506..18d89c7e87 100644 --- a/app/models/concerns/alaveteli_pro/request_summaries.rb +++ b/app/models/concerns/alaveteli_pro/request_summaries.rb @@ -1,6 +1,5 @@ module AlaveteliPro module RequestSummaries - extend ActiveSupport::Concern included do diff --git a/app/models/concerns/info_request/title_validation.rb b/app/models/concerns/info_request/title_validation.rb index ea4e3b8277..f36c73803a 100644 --- a/app/models/concerns/info_request/title_validation.rb +++ b/app/models/concerns/info_request/title_validation.rb @@ -28,6 +28,7 @@ module InfoRequest::TitleValidation def title_formatting return unless title + errors.add(:title, poorly_formed_title_msg) if poorly_formed_title? errors.add(:title, generic_foi_title_msg) if generic_foi_title? end diff --git a/app/models/concerns/public_body_derived_fields.rb b/app/models/concerns/public_body_derived_fields.rb index a24bc147aa..0dd7bd9ec1 100644 --- a/app/models/concerns/public_body_derived_fields.rb +++ b/app/models/concerns/public_body_derived_fields.rb @@ -1,5 +1,4 @@ module PublicBodyDerivedFields - extend ActiveSupport::Concern included do @@ -15,7 +14,6 @@ def name=(value) write_attribute(:name, value) update_url_name end - end # Return the short name if present, or else long name @@ -42,5 +40,4 @@ def update_url_name simplify_url_part(short_or_long_name, 'body') end end - end diff --git a/app/models/dataset/value_set.rb b/app/models/dataset/value_set.rb index 8e452c9b88..64cdd8b718 100644 --- a/app/models/dataset/value_set.rb +++ b/app/models/dataset/value_set.rb @@ -36,6 +36,7 @@ class Dataset::ValueSet < ApplicationRecord def check_at_least_one_value_is_present return unless values.map(&:value).all?(&:blank?) + errors.add :values, :empty end end diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 1fe0e43211..2c93e8998e 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -134,6 +134,7 @@ def unmasked_body raw_email.mail, hexdigest: hexdigest ) + rescue MailHandler::MismatchedAttachmentHexdigest attributes = MailHandler.attempt_to_find_original_attachment_attributes( raw_email.mail, @@ -214,6 +215,7 @@ def extra_note # look up what it means in the DSN table. if @content_type == 'message/delivery-status' return "" unless @body.match(/Status:\s+([0-9]+\.([0-9]+\.[0-9]+))\s+/) + dsn = $1 dsn_part = 'X.' + $2 @@ -259,7 +261,6 @@ def display_filename filename.strip end - def ensure_filename! if filename.blank? calc_ext = AlaveteliFileTypes.mimetype_to_extension(content_type) diff --git a/app/models/guess.rb b/app/models/guess.rb index f75eafbf70..6eadf7a5e7 100644 --- a/app/models/guess.rb +++ b/app/models/guess.rb @@ -40,11 +40,13 @@ def [](key) def id_score return 1 unless self[:id] + similarity(self[:id], info_request.id) end def idhash_score return 1 unless self[:idhash] + similarity(self[:idhash], info_request.idhash) end diff --git a/app/models/holiday_import.rb b/app/models/holiday_import.rb index 782c949d01..2c438cc479 100644 --- a/app/models/holiday_import.rb +++ b/app/models/holiday_import.rb @@ -1,5 +1,4 @@ class HolidayImport - include ActiveModel::Validations attr_accessor :holidays, @@ -75,6 +74,7 @@ def populate_from_ical_feed return end cal.events.each { |cal_event| populate_from_ical_event(cal_event) } + rescue Errno::ENOENT, Exception => e if e.message == 'Invalid line in calendar string!' errors.add(:ical_feed_url, "Sorry, there's a problem with the format of that feed.") diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index f57bcac08f..859638a567 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -98,6 +98,7 @@ def parse_raw_email!(force = nil) # values in case we want to regenerate them (due to mail # parsing bugs, etc). raise "Incoming message id=#{id} has no raw_email" if raw_email.nil? + if !force.nil? || last_parsed.nil? ActiveRecord::Base.transaction do extract_attachments @@ -208,6 +209,7 @@ def apply_masks(text, content_type) def remove_lotus_quoting(text, replacement = "FOLDED_QUOTED_SECTION") text = text.dup return text if info_request.user_name.nil? + name = Regexp.escape(info_request.user_name) # To end of message sections @@ -216,12 +218,10 @@ def remove_lotus_quoting(text, replacement = "FOLDED_QUOTED_SECTION") # Some other sort of forwarding quoting text.gsub!(/^\s?#{name}\s+To\s+FOI requests at.*/im, "\n\n" + replacement) - # http://www.whatdotheyknow.com/request/229/response/809 text.gsub(/^\s?From: [^\n]+\n\s?Sent: [^\n]+\n\s?To:\s+['"]?#{name}['"]?\n\s?Subject:.*/im, "\n\n" + replacement) end - # Remove quoted sections from emails (eventually the aim would be for this # to do as good a job as GMail does) TODO: bet it needs a proper parser # TODO: and this FOLDED_QUOTED_SECTION stuff is a mess @@ -275,7 +275,6 @@ def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION") Further\s+communication\s+will\s+signify\s+your\s+consent\s+to\s+this\. /imx, replacement) - # To end of message sections # http://www.whatdotheyknow.com/request/123/response/192 # http://www.whatdotheyknow.com/request/235/response/513 @@ -291,7 +290,6 @@ def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION") # http://www.whatdotheyknow.com/request/refuse_and_recycling_collection#incoming-842 text.gsub!(/(#{original_message}\n.*)$/mi, replacement) - # Some silly Microsoft XML gets into parts marked as plain text. # e.g. http://www.whatdotheyknow.com/request/are_traffic_wardens_paid_commiss#incoming-401 # Don't replace with "replacement" as it's pretty messy @@ -330,6 +328,7 @@ def _cache_main_body_text self.cached_main_body_text_folded = folded_quoted_text.delete("\0") save! end + # Returns body text from main text part of email, converted to UTF-8, with uudecode removed, # emails and privacy sensitive things remove, censored, and folded to remove excess quoted text # (marked with FOLDED_QUOTED_SECTION) @@ -338,10 +337,12 @@ def get_main_body_text_folded _cache_main_body_text if cached_main_body_text_folded.nil? cached_main_body_text_folded end + def get_main_body_text_unfolded _cache_main_body_text if cached_main_body_text_unfolded.nil? cached_main_body_text_unfolded end + # Returns body text from main text part of email, converted to UTF-8 def get_main_body_text_internal parse_raw_email! @@ -414,6 +415,7 @@ def get_main_body_text_part(leaves=[]) # e.g. http://www.whatdotheyknow.com/request/cost_benefit_analysis_for_real_n return nil end + # otherwise return it assuming it is text (sometimes you get things # like binary/octet-stream, or the like, which are really text - TODO: if # you find an example, put URL here - perhaps we should be always returning @@ -535,6 +537,7 @@ def get_body_for_html_display(collapse_quoted_sections = true) def get_body_for_indexing # rubocop:disable Naming/AccessorMethodName return '' if Ability.guest.cannot?(:read, get_main_body_text_part) + get_body_for_quoting end @@ -545,6 +548,7 @@ def get_body_for_quoting text.gsub!("FOLDED_QUOTED_SECTION", " ") text.strip! raise "internal error" if text.nil? + text end @@ -565,6 +569,7 @@ def get_attachment_text_full text end + # Returns a version reduced to a sensible maximum size - this # is for performance reasons when showing snippets in search results. def get_attachment_text_clipped @@ -596,6 +601,7 @@ def _get_attachment_text_internal def get_text_for_indexing_full get_body_for_indexing + "\n\n" + get_attachment_text_full end + # Used for excerpts in search results, when loading full text would be too slow def get_text_for_indexing_clipped get_body_for_indexing + "\n\n" + get_attachment_text_clipped @@ -613,6 +619,7 @@ def self.find_all_unknown_mime_types if attachment.content_type.nil? raise "internal error incoming_message " + incoming_message.id.to_s end + if AlaveteliFileTypes.mimetype_to_extension(attachment.content_type).nil? $stderr.puts "Unknown type for /request/" + incoming_message.info_request.id.to_s + "#incoming-"+incoming_message.id.to_s $stderr.puts " " + attachment.filename.to_s + " " + attachment.content_type.to_s diff --git a/app/models/incoming_message_error.rb b/app/models/incoming_message_error.rb index e5ec686a2f..9551a3437e 100644 --- a/app/models/incoming_message_error.rb +++ b/app/models/incoming_message_error.rb @@ -19,6 +19,5 @@ # The unique_id field represents the unique identifier applied to a given # mail in the POP mailbox. class IncomingMessageError < ApplicationRecord - validates_presence_of :unique_id end diff --git a/app/models/info_request.rb b/app/models/info_request.rb index e3e799b6f0..59b63197a3 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -292,6 +292,7 @@ def self._id_string_to_i(id_string) # address and make this kind of error. def self._clean_idhash(hash) return unless hash + hash.gsub(/l/, "1").gsub(/o/, "0") end @@ -695,7 +696,6 @@ def self.log_overdue_event_type(event_type) ) info_request.user.notify(event) if info_request.use_notifications? end - end def self.request_sent_types @@ -768,16 +768,19 @@ def is_external? def user_name return external_user_name if is_external? + user&.name end def from_name return external_user_name if is_external? + outgoing_messages.first&.from_name || user_name end def safe_from_name return external_user_name if is_external? + apply_censor_rules_to_text(from_name) end @@ -898,6 +901,7 @@ def email_subject_followup(opts = {}) def legislation return Legislation.find!(law_used) if law_used + public_body&.legislation || Legislation.default end @@ -908,6 +912,7 @@ def find_existing_outgoing_message(body) # Has this email already been received here? Based just on message id. def already_received?(email) return false unless email.message_id + incoming_messages.any? { email.message_id == _1.message_id } end @@ -1040,6 +1045,7 @@ def calculate_status(cached_value_ok=false) if cached_value_ok && @cached_calculated_status return @cached_calculated_status end + @cached_calculated_status = @@custom_states_loaded ? theme_calculate_status : base_calculate_status end @@ -1051,6 +1057,7 @@ def base_calculate_status Time.zone.now.strftime("%Y-%m-%d") > date_very_overdue_after.strftime("%Y-%m-%d") return 'waiting_response_overdue' if Time.zone.now.strftime("%Y-%m-%d") > date_response_required_by.strftime("%Y-%m-%d") + 'waiting_response' end @@ -1188,6 +1195,7 @@ def set_due_dates(sent_event) def date_initial_request_last_sent_at date = read_attribute(:date_initial_request_last_sent_at) return date.to_date if date + calculate_date_initial_request_last_sent_at end @@ -1207,6 +1215,7 @@ def late_calculator def date_response_required_by date = read_attribute(:date_response_required_by) return date if date + calculate_date_response_required_by end @@ -1221,6 +1230,7 @@ def calculate_date_response_required_by def date_very_overdue_after date = read_attribute(:date_very_overdue_after) return date if date + calculate_date_very_overdue_after end @@ -1263,7 +1273,6 @@ def recipient_name_and_email recipient_email) end - def public_response_events condition = <<-SQL info_request_events.event_type = ? @@ -1302,6 +1311,7 @@ def get_last_public_outgoing_event # Text from the the initial request, for use in summary display def initial_request_text return '' if outgoing_messages.empty? + body_opts = { censor_rules: applicable_censor_rules } first_message = outgoing_messages.first first_message.is_public? ? first_message.get_text_for_indexing(true, body_opts) : '' @@ -1340,6 +1350,7 @@ def get_previous_email_sent_to(info_request_event) info_request_events.each do |e| if ((info_request_event.is_sent_sort? && e.is_sent_sort?) || (info_request_event.is_followup_sort? && e.is_followup_sort?)) && e.outgoing_message_id == info_request_event.outgoing_message_id break if e.id == info_request_event.id + last_email = e.params[:email] end end @@ -1354,6 +1365,7 @@ def display_status(cached_value_ok=false) # envelope from address until we abandoned it. def magic_email(prefix_part) raise "id required to create a magic email" unless id + InfoRequest.magic_email_for_id(prefix_part, id) end @@ -1471,6 +1483,7 @@ def who_can_followup_to(skip_message = nil) end incoming_messages.reverse.each do |incoming_message| next if incoming_message == skip_message + incoming_message.safe_from_name next unless incoming_message.is_public? @@ -1533,11 +1546,13 @@ def masks def is_owning_user?(user) return false unless user + user.id == user_id || user.owns_every_request? end def is_actual_owning_user?(user) return false unless user + user.id == user_id end @@ -1619,6 +1634,7 @@ def similar_ids(limit=10) def move_to_public_body(destination_public_body, opts = {}) return nil unless destination_public_body.try(:persisted?) + old_body = public_body editor = opts.fetch(:editor) @@ -1652,6 +1668,7 @@ def move_to_public_body(destination_public_body, opts = {}) def move_to_user(destination_user, opts = {}) return nil unless destination_user.try(:persisted?) + old_user = user editor = opts.fetch(:editor) @@ -1759,6 +1776,7 @@ def request_summary_categories def holding_pen_request? return true if url_title == 'holding_pen' + self == self.class.holding_pen_request end @@ -1915,6 +1933,7 @@ def set_defaults def set_law_used return if law_used_changed? + self.law_used = public_body.legislation.key if public_body end diff --git a/app/models/info_request/batch_pagination.rb b/app/models/info_request/batch_pagination.rb index 91ec018ea7..4b802f73c3 100644 --- a/app/models/info_request/batch_pagination.rb +++ b/app/models/info_request/batch_pagination.rb @@ -2,11 +2,13 @@ module InfoRequest::BatchPagination def next_in_batch return nil unless info_request_batch + batch_sibling_requests_ordered_by_id[index_in_batch + 1] || first_in_batch end def prev_in_batch return nil unless info_request_batch + batch_sibling_requests_ordered_by_id[index_in_batch - 1] end diff --git a/app/models/info_request/prominence/calculator.rb b/app/models/info_request/prominence/calculator.rb index 9194df3ae4..357261de1e 100644 --- a/app/models/info_request/prominence/calculator.rb +++ b/app/models/info_request/prominence/calculator.rb @@ -1,7 +1,6 @@ class InfoRequest module Prominence class Calculator - def initialize(info_request) @info_request = info_request end @@ -33,7 +32,6 @@ def is_hidden? def to_s @info_request.read_attribute(:prominence) end - end end end diff --git a/app/models/info_request/prominence/not_embargoed_query.rb b/app/models/info_request/prominence/not_embargoed_query.rb index d8f9c99558..8b53a9799c 100644 --- a/app/models/info_request/prominence/not_embargoed_query.rb +++ b/app/models/info_request/prominence/not_embargoed_query.rb @@ -1,7 +1,6 @@ class InfoRequest module Prominence class NotEmbargoedQuery - def initialize(relation = InfoRequest) @relation = relation end diff --git a/app/models/info_request/prominence/searchable_query.rb b/app/models/info_request/prominence/searchable_query.rb index bd8d396969..0bbbdc40ce 100644 --- a/app/models/info_request/prominence/searchable_query.rb +++ b/app/models/info_request/prominence/searchable_query.rb @@ -11,4 +11,3 @@ def call end end end - diff --git a/app/models/info_request/sluggable.rb b/app/models/info_request/sluggable.rb index 1a6fcf387b..ff005a5c75 100644 --- a/app/models/info_request/sluggable.rb +++ b/app/models/info_request/sluggable.rb @@ -27,6 +27,7 @@ def title=(title) def url_title(opts = {}) _url_title = super() return _url_title.gsub(/[_0-9]+$/, "") if opts[:collapse] + _url_title end diff --git a/app/models/info_request/state.rb b/app/models/info_request/state.rb index 0c4d51d73a..b0e5133fbc 100644 --- a/app/models/info_request/state.rb +++ b/app/models/info_request/state.rb @@ -1,6 +1,5 @@ class InfoRequest module State - def self.all states = [ 'waiting_response', diff --git a/app/models/info_request/state/calculator.rb b/app/models/info_request/state/calculator.rb index cc1bdc92a9..f380eb8020 100644 --- a/app/models/info_request/state/calculator.rb +++ b/app/models/info_request/state/calculator.rb @@ -1,7 +1,6 @@ class InfoRequest module State class Calculator - def initialize(info_request) @info_request = info_request end diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb index 9e2451d9a8..5f38b36176 100644 --- a/app/models/info_request_batch.rb +++ b/app/models/info_request_batch.rb @@ -315,6 +315,7 @@ def log_event(*args) def is_owning_user?(user) return false unless user + user.id == user_id || user.owns_every_request? end diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index a1e2920fad..dc25750a7b 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -322,6 +322,7 @@ def display_status if status return _("Internal review request") if status == 'internal_review' return _("Clarification") if status == 'waiting_response' + raise _("unknown status {{status}}", status: status) end # TRANSLATORS: "Follow up" in this context means a further @@ -371,6 +372,7 @@ def same_email_as_previous_send? curr_addr = params[:email] return true if prev_addr.nil? && curr_addr.nil? return false if prev_addr.nil? || curr_addr.nil? + MailHandler.address_from_string(prev_addr) == MailHandler.address_from_string(curr_addr) end @@ -419,6 +421,7 @@ def set_calculated_state!(state) def foi_attachment return unless params[:attachment_id] + @foi_attachment ||= FoiAttachment.find(params[:attachment_id]) end @@ -437,7 +440,6 @@ def previous_events(opts = {}) where(info_request_id: info_request_id). where('created_at < ?', created_at). order(order) - end def subsequent_events(opts = {}) @@ -538,6 +540,7 @@ def indexed_by_search? return false end return false if event_type == 'comment' && !comment.visible + return true end false diff --git a/app/models/legislation/reference.rb b/app/models/legislation/reference.rb index 00f2591906..a24c9da235 100644 --- a/app/models/legislation/reference.rb +++ b/app/models/legislation/reference.rb @@ -29,6 +29,7 @@ def initialize(legislation:, reference:) def to_s return parent_reference if sub_elements.empty? + parent_reference + "(#{sub_elements.join(')(')})" end diff --git a/app/models/mail_server_log.rb b/app/models/mail_server_log.rb index 701df4e9f6..25d6b9c1a2 100644 --- a/app/models/mail_server_log.rb +++ b/app/models/mail_server_log.rb @@ -240,6 +240,7 @@ def delivery_status DeliveryStatusSerializer.load(read_attribute(:delivery_status)) # TODO: This rescue can be removed when there are no more cached # MTA-specific statuses + rescue ArgumentError warn %q(MailServerLog#delivery_status rescuing from invalid delivery status. Run bundle exec rake temp:cache_delivery_status to update @@ -336,5 +337,4 @@ def redact_hostname(line) def redact_idhash(line, idhash) line.gsub(idhash, _('[REDACTED]')) end - end diff --git a/app/models/mail_server_log/delivery_status.rb b/app/models/mail_server_log/delivery_status.rb index b3ac1ed8fe..da2ffbd6b7 100644 --- a/app/models/mail_server_log/delivery_status.rb +++ b/app/models/mail_server_log/delivery_status.rb @@ -27,6 +27,7 @@ def humanize def <=>(other) return nil unless other + a = TranslatedConstants.humanized.keys.index(to_sym) b = TranslatedConstants.humanized.keys.index(other.to_sym) a <=> b diff --git a/app/models/mail_server_log/delivery_status/translated_constants.rb b/app/models/mail_server_log/delivery_status/translated_constants.rb index c0b21fcb9c..e43e1e453f 100644 --- a/app/models/mail_server_log/delivery_status/translated_constants.rb +++ b/app/models/mail_server_log/delivery_status/translated_constants.rb @@ -1,6 +1,5 @@ class MailServerLog::DeliveryStatus module TranslatedConstants - def self.humanized # The order of these is important as we use the keys for sorting in #<=> { @@ -17,6 +16,5 @@ def self.to_s! sent: _('sent'), delivered: _('delivered') }.freeze end - end end diff --git a/app/models/mail_server_log/delivery_status_serializer.rb b/app/models/mail_server_log/delivery_status_serializer.rb index 3e4ad21b09..fd41b59f09 100644 --- a/app/models/mail_server_log/delivery_status_serializer.rb +++ b/app/models/mail_server_log/delivery_status_serializer.rb @@ -21,7 +21,7 @@ def self.load(value) # Returns a String or nil def self.dump(value) return unless value + value.to_s end - end diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 80a489226f..dfa8e2d94a 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -139,11 +139,13 @@ def set_signature_name(name) def from_name return info_request.external_user_name if info_request.is_external? + super || info_request.user_name end def safe_from_name return info_request.external_user_name if info_request.is_external? + info_request.apply_censor_rules_to_text(from_name) end @@ -412,6 +414,7 @@ def default_letter=(text) def cache_from_name return if read_attribute(:from_name) + self.from_name = info_request.user_name if info_request end diff --git a/app/models/outgoing_message/template/batch_request.rb b/app/models/outgoing_message/template/batch_request.rb index 223f890190..14b7c4737f 100644 --- a/app/models/outgoing_message/template/batch_request.rb +++ b/app/models/outgoing_message/template/batch_request.rb @@ -34,7 +34,6 @@ def template_string(replacements) msg += signoff(replacements) msg += "\n\n" end - end end end diff --git a/app/models/project/export/info_request.rb b/app/models/project/export/info_request.rb index d5563b74d3..4c1bc97742 100644 --- a/app/models/project/export/info_request.rb +++ b/app/models/project/export/info_request.rb @@ -43,21 +43,25 @@ def extraction_submission def status_contributor return project.owner.name unless status_submission + status_submission.user.name end def dataset_contributor return unless extraction_submission + extraction_submission.user.name end def extracted_values return unless extraction_submission + extraction_submission.resource.values end def extracted_values_as_hash return {} unless extracted_values + extracted_values.joins(:key).pluck('dataset_keys.title', :value).to_h end end diff --git a/app/models/project/queue.rb b/app/models/project/queue.rb index adb5c169c5..857c7147fc 100644 --- a/app/models/project/queue.rb +++ b/app/models/project/queue.rb @@ -60,6 +60,7 @@ def sample def remember_current(info_request) return backend.clear_current unless info_request + backend.current = info_request end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 5b3168a882..68d651d18f 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -307,6 +307,7 @@ def self.find_by_url_name_with_historic(name) raise "Two bodies with the same historical URL name: #{name}" end return unless old.size == 1 + # does acts_as_versioned provide a method that returns the current version? PublicBody.find(old.first) end @@ -631,6 +632,7 @@ def is_foi_officer?(user) our_domain = request_email_domain return false if user_domain.nil? || our_domain.nil? + our_domain == user_domain end @@ -951,7 +953,6 @@ def request_email_if_requestable "Request email doesn't look like a valid email address") end end - end def name_for_search diff --git a/app/models/public_body/calculated_home_page.rb b/app/models/public_body/calculated_home_page.rb index afedc45c63..a14e2888f7 100644 --- a/app/models/public_body/calculated_home_page.rb +++ b/app/models/public_body/calculated_home_page.rb @@ -39,6 +39,7 @@ def calculated_home_page! # Ensure the home page has the HTTP protocol at the start of the URL def ensure_home_page_protocol return unless home_page.present? + home_page[URI.regexp(%w(http https))] ? home_page : "https://#{home_page}" end @@ -46,6 +47,7 @@ def ensure_home_page_protocol def guess_home_page return unless request_email_domain return if excluded_calculated_home_page_domain?(request_email_domain) + "https://www.#{request_email_domain}" end diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index e428acb02c..c7d7466464 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -60,6 +60,7 @@ def valid_to_reply_to? return false if prefix.match(no_reply_regexp) return false if empty_return_path? return false if auto_submitted? + true end diff --git a/app/models/refusal_advice.rb b/app/models/refusal_advice.rb index eb19e41452..3a6e772e20 100644 --- a/app/models/refusal_advice.rb +++ b/app/models/refusal_advice.rb @@ -35,6 +35,7 @@ def actions def snippets scope = OutgoingMessage::Snippet.with_tag('refusal_advice') return scope.with_tag('internal_review') if @options[:internal_review] + scope.without_tag('internal_review') end diff --git a/app/models/request_classification.rb b/app/models/request_classification.rb index bd195f3fa5..6dc0a23452 100644 --- a/app/models/request_classification.rb +++ b/app/models/request_classification.rb @@ -35,5 +35,4 @@ def self.league_table(size, conditions=nil) query = query.where(*conditions) if conditions query end - end diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 4c1aa88755..43be628d40 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -26,7 +26,6 @@ # TODO: TrackThing looks like a good candidate for single table inheritance class TrackThing < ApplicationRecord - TRACK_MEDIUMS = %w(email_daily feed) belongs_to :info_request, @@ -55,6 +54,7 @@ class TrackThing < ApplicationRecord # posting def self.find_existing(tracking_user, track) return nil if tracking_user.nil? + where(tracking_user_id: tracking_user.id, track_query: track.track_query, track_type: track.track_type).first @@ -293,5 +293,4 @@ def search_query_params feed_sortby: 'described' } end - end diff --git a/app/models/track_thing/translated_constants.rb b/app/models/track_thing/translated_constants.rb index cb43554b62..4d5a5480d3 100644 --- a/app/models/track_thing/translated_constants.rb +++ b/app/models/track_thing/translated_constants.rb @@ -1,6 +1,5 @@ class TrackThing module TranslatedConstants - def self.track_types # { TRACK_TYPE => DESCRIPTION } { 'request_updates' => _('Individual requests'), @@ -10,6 +9,5 @@ def self.track_types 'user_updates' => _('People'), 'search_query' => _('Search queries') } end - end end diff --git a/app/models/track_things_sent_email.rb b/app/models/track_things_sent_email.rb index 4b247982e9..18bb3514bb 100644 --- a/app/models/track_things_sent_email.rb +++ b/app/models/track_things_sent_email.rb @@ -33,5 +33,4 @@ def self.delete_old_track_things_sent_email TrackThingsSentEmail. where("updated_at < (now() - interval '1 month')").delete_all end - end diff --git a/app/models/user.rb b/app/models/user.rb index 992bd25e83..ee15eee72e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -242,6 +242,7 @@ def self.authenticate_from_form(params, specific_user_login = false) # Case-insensitively find a user from their email def self.find_user_by_email(email) return nil if email.blank? + where('lower(email) = lower(?)', email.strip).first end @@ -492,6 +493,7 @@ def prominence return 'hidden' if banned? return 'backpage' if closed? return 'backpage' unless email_confirmed? + 'normal' end @@ -581,6 +583,7 @@ def show_profile_photo? def about_me_already_exists? return false if about_me.blank? + self.class.where(about_me: about_me).where.not(id: id).any? end @@ -717,6 +720,7 @@ def assign_role_features(_role) def setup_pro_account(role) return unless role == Role.pro_role + pro_account || build_pro_account if feature_enabled?(:pro_pricing) end diff --git a/app/models/user/slug.rb b/app/models/user/slug.rb index 926e1ae4c0..4c59b80fcd 100644 --- a/app/models/user/slug.rb +++ b/app/models/user/slug.rb @@ -20,12 +20,14 @@ module User::Slug def should_generate_new_friendly_id? return true unless url_name + !url_name_changed? && name_changed? && active? end def normalize_friendly_id(_value) value = read_attribute(:name) return super('user') if value =~ /^[\d_\.]+$/ + super(value).gsub('-', '_') end diff --git a/app/services/info_request_batch_metrics.rb b/app/services/info_request_batch_metrics.rb index 5915bb1d6e..f90670a186 100644 --- a/app/services/info_request_batch_metrics.rb +++ b/app/services/info_request_batch_metrics.rb @@ -16,7 +16,6 @@ def initialize(info_request_batch) def metrics @metrics ||= @info_request_batch.info_requests. includes(public_body: :translations).map do |info_request| - url = show_alaveteli_pro_request_url(info_request.url_title) status = InfoRequest::State.short_description( info_request.calculate_status(true) diff --git a/app/validators/change_email_validator.rb b/app/validators/change_email_validator.rb index d3c51b59d0..72f391338c 100644 --- a/app/validators/change_email_validator.rb +++ b/app/validators/change_email_validator.rb @@ -76,5 +76,4 @@ def email_belongs_to_user?(email) def correct_password? logged_in_user.has_this_password?(password) end - end diff --git a/config/deploy.rb b/config/deploy.rb index f647dd4d05..e3be3360e5 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -38,7 +38,6 @@ end end - # Not in the rake namespace because we're also specifying app-specific arguments here namespace :xapian do desc 'Rebuilds the Xapian index as per the ./scripts/destroy-and-rebuild-xapian-index script' @@ -48,7 +47,6 @@ end namespace :deploy do - [:start, :stop, :restart].each do |t| desc "#{t.to_s.capitalize} Alaveteli service defined in /etc/init.d/" task t, roles: :app, except: { no_release: true } do diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb index f20c588aac..96891c9edc 100644 --- a/config/initializers/alaveteli.rb +++ b/config/initializers/alaveteli.rb @@ -25,7 +25,6 @@ # Mime::Type.register "text/richtext", :rtf # Mime::Type.register "application/x-mobile", :mobile - # Domain for URLs (so can work for scripts, not just web pages) ActionMailer::Base.default_url_options[:host] = AlaveteliConfiguration.domain diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb index a0cb0276c1..1cd17e47f7 100644 --- a/config/initializers/new_framework_defaults_7_0.rb +++ b/config/initializers/new_framework_defaults_7_0.rb @@ -92,7 +92,6 @@ # "Referrer-Policy" => "strict-origin-when-cross-origin" # } - # ** Please read carefully, this must be configured in config/application.rb ** # Change the format of the cache entry. # Changing this default means that all new cache entries added to the cache @@ -102,7 +101,6 @@ # When you're ready to change format, add this to `config/application.rb` (NOT this file): # config.active_support.cache_format_version = 7.0 - # Cookie serializer: 2 options # # If you're upgrading and haven't set `cookies_serializer` previously, your cookie serializer diff --git a/config/initializers/secure_headers.rb b/config/initializers/secure_headers.rb index 6129358dff..556505f543 100644 --- a/config/initializers/secure_headers.rb +++ b/config/initializers/secure_headers.rb @@ -1,5 +1,4 @@ ::SecureHeaders::Configuration.default do |config| - # https://tools.ietf.org/html/rfc6797 if AlaveteliConfiguration.force_ssl config.hsts = "max-age=#{20.years.to_i}; includeSubdomains" diff --git a/config/routes.rb b/config/routes.rb index 44e850665e..65e53fb440 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -186,7 +186,6 @@ def matches?(request) #### end - #### Followups controller match '/request/:request_id/followups/new' => 'followups#new', :as => :new_request_followup, @@ -839,7 +838,6 @@ def matches?(request) #### Pro Pricing constraints FeatureConstraint.new(:pro_pricing) do - namespace :alaveteli_pro, path: :pro, as: :pro do resources :plans, only: [:index], path: :pricing end @@ -862,12 +860,10 @@ def matches?(request) match '/pro/subscriptions/stripe-webhook' => 'stripe_webhooks#receive', :via => :post end - end #### Alaveteli Pro constraints FeatureConstraint.new(:alaveteli_pro) do - scope module: :alaveteli_pro do resources :account_request, :only => [:index, :create], path: :pro do collection do @@ -932,7 +928,6 @@ def matches?(request) :via => :get, :defaults => { :pro => '1' } end - end #### diff --git a/db/migrate/011_add_created_updated_fields.rb b/db/migrate/011_add_created_updated_fields.rb index 2f0edd5964..377c170efb 100644 --- a/db/migrate/011_add_created_updated_fields.rb +++ b/db/migrate/011_add_created_updated_fields.rb @@ -18,7 +18,6 @@ def self.up # Users add_column :users, :created_at, :datetime add_column :users, :updated_at, :datetime - end def self.down diff --git a/db/migrate/026_add_many_null_constraints.rb b/db/migrate/026_add_many_null_constraints.rb index 0e98514b67..dd064a1e9b 100644 --- a/db/migrate/026_add_many_null_constraints.rb +++ b/db/migrate/026_add_many_null_constraints.rb @@ -47,7 +47,6 @@ def self.up change_column :incoming_messages, :updated_at, :datetime, null: false change_column :incoming_messages, :user_classified, :boolean, null: false, default: false change_column :incoming_messages, :is_bounce, :boolean, null: false, default: false - end def self.down @@ -98,6 +97,5 @@ def self.down change_column :incoming_messages, :updated_at, :datetime, null: true change_column :incoming_messages, :user_classified, :boolean, null: true, default: false change_column :incoming_messages, :is_bounce, :boolean, null: true, default: false - end end diff --git a/db/migrate/042_unique_user_urls.rb b/db/migrate/042_unique_user_urls.rb index ecf9d80ee9..6eff24a850 100644 --- a/db/migrate/042_unique_user_urls.rb +++ b/db/migrate/042_unique_user_urls.rb @@ -19,5 +19,4 @@ def self.down add_index :users, :url_name, unique: false end end - end diff --git a/db/migrate/074_create_holidays.rb b/db/migrate/074_create_holidays.rb index 32872afd3b..df2201ee85 100644 --- a/db/migrate/074_create_holidays.rb +++ b/db/migrate/074_create_holidays.rb @@ -62,7 +62,6 @@ def self.up holidays.sort.each { |date, desc| Holiday.create day: date, description: desc } - end def self.down diff --git a/db/migrate/096_create_translation_tables.rb b/db/migrate/096_create_translation_tables.rb index 08b6dedf7c..6eccddc08b 100644 --- a/db/migrate/096_create_translation_tables.rb +++ b/db/migrate/096_create_translation_tables.rb @@ -25,7 +25,6 @@ def self.up end end - def self.down PublicBody.drop_translation_table! end diff --git a/db/migrate/100_remove_redundant_raw_email_columns.rb b/db/migrate/100_remove_redundant_raw_email_columns.rb index 51fdea1c3b..596cf171f9 100644 --- a/db/migrate/100_remove_redundant_raw_email_columns.rb +++ b/db/migrate/100_remove_redundant_raw_email_columns.rb @@ -3,6 +3,7 @@ def self.up remove_column :raw_emails, :data_text remove_column :raw_emails, :data_binary end + def self.down end end diff --git a/db/migrate/101_add_hash_to_info_request.rb b/db/migrate/101_add_hash_to_info_request.rb index 8f72d1d599..9eb9e50e2a 100644 --- a/db/migrate/101_add_hash_to_info_request.rb +++ b/db/migrate/101_add_hash_to_info_request.rb @@ -11,6 +11,7 @@ def self.up end change_column :info_requests, :idhash, :string, null: false end + def self.down remove_column :info_requests, :idhash end diff --git a/db/migrate/102_add_locale_to_users.rb b/db/migrate/102_add_locale_to_users.rb index 27aa38ca13..19e0b6fa1d 100644 --- a/db/migrate/102_add_locale_to_users.rb +++ b/db/migrate/102_add_locale_to_users.rb @@ -2,6 +2,7 @@ class AddLocaleToUsers < ActiveRecord::Migration[4.2] # 2.3 def self.up add_column :users, :locale, :string end + def self.down remove_column :users, :locale end diff --git a/db/migrate/103_add_user_bounce_columns.rb b/db/migrate/103_add_user_bounce_columns.rb index d4ac9a181d..3c067d34b0 100644 --- a/db/migrate/103_add_user_bounce_columns.rb +++ b/db/migrate/103_add_user_bounce_columns.rb @@ -5,6 +5,7 @@ def self.up add_column :users, :email_bounced_at, :datetime add_column :users, :email_bounce_message, :text, default: "", null: false end + def self.down remove_column :users, :email_bounced_at remove_column :users, :email_bounce_message diff --git a/db/migrate/104_create_foi_attachments.rb b/db/migrate/104_create_foi_attachments.rb index a7a5dd2111..3f2805ffe2 100644 --- a/db/migrate/104_create_foi_attachments.rb +++ b/db/migrate/104_create_foi_attachments.rb @@ -1,4 +1,3 @@ - class CreateFoiAttachments < ActiveRecord::Migration[4.2] # 2.3 def self.up create_table :foi_attachments do |t| diff --git a/db/migrate/110_add_user_no_limit.rb b/db/migrate/110_add_user_no_limit.rb index 25f2cd4538..efd56d8fbc 100644 --- a/db/migrate/110_add_user_no_limit.rb +++ b/db/migrate/110_add_user_no_limit.rb @@ -4,6 +4,7 @@ class AddUserNoLimit < ActiveRecord::Migration[4.2] # 2.3 def self.up add_column :users, :no_limit, :boolean, default: false, null: false end + def self.down remove_column :users, :no_limit end diff --git a/db/migrate/114_add_attention_requested_flag_to_info_requests.rb b/db/migrate/114_add_attention_requested_flag_to_info_requests.rb index e6df33d6f5..c8e3b13588 100644 --- a/db/migrate/114_add_attention_requested_flag_to_info_requests.rb +++ b/db/migrate/114_add_attention_requested_flag_to_info_requests.rb @@ -4,6 +4,7 @@ class AddAttentionRequestedFlagToInfoRequests < ActiveRecord::Migration[4.2] # 2 def self.up add_column :info_requests, :attention_requested, :boolean, default: false end + def self.down remove_column :info_requests, :attention_requested end diff --git a/db/migrate/115_add_receive_email_alerts_to_user.rb b/db/migrate/115_add_receive_email_alerts_to_user.rb index 587227e7f3..0783808bae 100644 --- a/db/migrate/115_add_receive_email_alerts_to_user.rb +++ b/db/migrate/115_add_receive_email_alerts_to_user.rb @@ -2,6 +2,7 @@ class AddReceiveEmailAlertsToUser < ActiveRecord::Migration[4.2] # 2.3 def self.up add_column :users, :receive_email_alerts, :boolean, default: true, null: false end + def self.down remove_column :users, :receive_email_alerts end diff --git a/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb b/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb index e97dfa5c07..7af784c7e2 100644 --- a/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb +++ b/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb @@ -5,12 +5,9 @@ def self.up PublicBody.connection.execute("UPDATE public_bodies SET info_requests_count = (SELECT COUNT(*) FROM info_requests WHERE public_body_id = public_bodies.id);") - - end def self.down remove_column :public_bodies, :info_requests_count end - end diff --git a/db/migrate/20131024152540_add_body_to_info_request_batches.rb b/db/migrate/20131024152540_add_body_to_info_request_batches.rb index 5b62fc2be2..a21786ac1f 100644 --- a/db/migrate/20131024152540_add_body_to_info_request_batches.rb +++ b/db/migrate/20131024152540_add_body_to_info_request_batches.rb @@ -7,5 +7,4 @@ def up def down remove_column :info_request_batches, :body end - end diff --git a/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb b/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb index 52c3037f37..a364e1f516 100644 --- a/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb +++ b/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb @@ -1,5 +1,4 @@ class AddDefaultShortNameToPublicBodies < ActiveRecord::Migration[4.2] # 3.2 - def up change_column_default(:public_bodies, :short_name, '') end @@ -7,5 +6,4 @@ def up def down change_column_default(:public_bodies, :short_name, nil) end - end diff --git a/db/migrate/20140528110536_update_track_things_index.rb b/db/migrate/20140528110536_update_track_things_index.rb index 61270ce480..6e763eaa11 100644 --- a/db/migrate/20140528110536_update_track_things_index.rb +++ b/db/migrate/20140528110536_update_track_things_index.rb @@ -1,5 +1,4 @@ class UpdateTrackThingsIndex < ActiveRecord::Migration[4.2] # 3.2 - def up if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" execute "ALTER TABLE track_things_sent_emails DROP CONSTRAINT fk_track_request_public_body" @@ -13,5 +12,4 @@ def down execute "ALTER TABLE track_things_sent_emails ADD CONSTRAINT fk_track_request_public_body FOREIGN KEY (user_id) REFERENCES users(id)" end end - end diff --git a/db/migrate/20140716131107_create_category_translation_tables.rb b/db/migrate/20140716131107_create_category_translation_tables.rb index 802b48681c..5acc66836b 100644 --- a/db/migrate/20140716131107_create_category_translation_tables.rb +++ b/db/migrate/20140716131107_create_category_translation_tables.rb @@ -2,9 +2,11 @@ class CreateCategoryTranslationTables < ActiveRecord::Migration[4.2] # 3.2 class PublicBodyCategory < ApplicationRecord translates :title, :description end + class PublicBodyHeading < ApplicationRecord translates :name end + def up default_locale = AlaveteliLocalization.default_locale diff --git a/gems/alaveteli_features/lib/alaveteli_features.rb b/gems/alaveteli_features/lib/alaveteli_features.rb index 66860937bb..5ee5fe278b 100644 --- a/gems/alaveteli_features/lib/alaveteli_features.rb +++ b/gems/alaveteli_features/lib/alaveteli_features.rb @@ -19,6 +19,7 @@ def self.groups def self.backend return @backend if @backend + if tables_exist? @backend = Flipper.new(Flipper::Adapters::ActiveRecord.new) else diff --git a/gems/alaveteli_features/lib/alaveteli_features/collection.rb b/gems/alaveteli_features/lib/alaveteli_features/collection.rb index a4fd23ffc7..5d5b841add 100644 --- a/gems/alaveteli_features/lib/alaveteli_features/collection.rb +++ b/gems/alaveteli_features/lib/alaveteli_features/collection.rb @@ -22,6 +22,7 @@ def initialize(klass) @klass = klass return unless klass.const_defined?(:CollectionMethods) + extend klass::CollectionMethods end @@ -37,6 +38,7 @@ def all def each(*_args, &block) return to_enum(:each) unless block_given? + all.each(&block) end end diff --git a/gems/alaveteli_features/lib/alaveteli_features/feature.rb b/gems/alaveteli_features/lib/alaveteli_features/feature.rb index c3b0125588..452ccea0a3 100644 --- a/gems/alaveteli_features/lib/alaveteli_features/feature.rb +++ b/gems/alaveteli_features/lib/alaveteli_features/feature.rb @@ -61,6 +61,7 @@ def all_role_features def role_features raise ActorNotDefinedError unless actor + select { |feature| (feature.roles & actor.roles).any? } end end @@ -90,6 +91,7 @@ def roles? def enabled? raise ActorNotDefinedError unless actor + feature_enabled?(key, actor) && condition.call end @@ -99,11 +101,13 @@ def disabled? def enable raise ActorNotDefinedError unless actor + enable_actor(key, actor) end def disable raise ActorNotDefinedError unless actor + disable_actor(key, actor) end end diff --git a/gems/alaveteli_features/lib/alaveteli_features/generators/alaveteli_features/install/install_generator.rb b/gems/alaveteli_features/lib/alaveteli_features/generators/alaveteli_features/install/install_generator.rb index f3461f1e71..42dfed0044 100644 --- a/gems/alaveteli_features/lib/alaveteli_features/generators/alaveteli_features/install/install_generator.rb +++ b/gems/alaveteli_features/lib/alaveteli_features/generators/alaveteli_features/install/install_generator.rb @@ -41,4 +41,4 @@ def complete puts "Enjoy!" end end -end \ No newline at end of file +end diff --git a/gems/alaveteli_features/lib/alaveteli_features/helpers.rb b/gems/alaveteli_features/lib/alaveteli_features/helpers.rb index 85ad17d157..6851b821ef 100644 --- a/gems/alaveteli_features/lib/alaveteli_features/helpers.rb +++ b/gems/alaveteli_features/lib/alaveteli_features/helpers.rb @@ -7,12 +7,14 @@ def feature_enabled?(feature, *args) def enable_actor(feature, user) # check feature hasn't already been enabled for the user return true if feature_enabled?(feature, user) + AlaveteliFeatures.backend.enable_actor(feature, user) end def disable_actor(feature, user) # check feature isn't already been disabled for the user return true unless feature_enabled?(feature, user) + AlaveteliFeatures.backend.disable_actor(feature, user) end end diff --git a/gems/alaveteli_features/lib/alaveteli_features/spec_helpers.rb b/gems/alaveteli_features/lib/alaveteli_features/spec_helpers.rb index 7a5b27cc47..1696f94b3b 100644 --- a/gems/alaveteli_features/lib/alaveteli_features/spec_helpers.rb +++ b/gems/alaveteli_features/lib/alaveteli_features/spec_helpers.rb @@ -18,12 +18,14 @@ def with_feature_disabled(feature) config.before(:each) do |example| features = [example.metadata[:feature]].flatten next if features.empty? + features.each { |f| with_feature_enabled(f) } end config.after(:each) do |example| features = [example.metadata[:feature]].flatten next if features.empty? + features.each { |f| with_feature_disabled(f) } end end diff --git a/lib/acts_as_xapian/acts_as_xapian.rb b/lib/acts_as_xapian/acts_as_xapian.rb index c4635e9eb1..818d436330 100644 --- a/lib/acts_as_xapian/acts_as_xapian.rb +++ b/lib/acts_as_xapian/acts_as_xapian.rb @@ -16,6 +16,7 @@ begin require 'xapian' $acts_as_xapian_bindings_available = true + rescue LoadError STDERR.puts "acts_as_xapian: No Ruby bindings for Xapian installed" $acts_as_xapian_bindings_available = false @@ -63,36 +64,47 @@ def self.bindings_available def self.db @@db end + def self.db_path=(db_path) @@db_path = db_path end + def self.db_path @@db_path end + def self.writable_db @@writable_db end + def self.stemmer @@stemmer end + def self.term_generator @@term_generator end + def self.enquire @@enquire end + def self.query_parser @@query_parser end + def self.values_by_prefix @@values_by_prefix end + def self.config @@config end + def self.max_wildcard_expansion=(max_wildcard_expansion) @@max_wildcard_expansion = max_wildcard_expansion end + def self.max_wildcard_expansion @@max_wildcard_expansion end @@ -215,6 +227,7 @@ def self.init_values(values) unless index.is_a? Integer raise "Value index '#{index}' must be an Integer, is #{index.class}" end + if @@values_by_number.include?(index) && @@values_by_number[index] != prefix raise "Already have value index '#{index}' in another model " \ "but with different prefix '#{@@values_by_number[index]}'" @@ -256,6 +269,7 @@ def self.init_terms(terms) raise "model and modelid are reserved for use as the model/id prefixes" end raise "Z is reserved for stemming terms" if term_code == "Z" + if @@terms_by_capital.include?(term_code) && @@terms_by_capital[term_code] != prefix raise "Already have code '#{term_code}' in another model but with different prefix " \ "'#{@@terms_by_capital[term_code]}'" @@ -328,6 +342,7 @@ def initialize_query(options) unless limit raise "please specifiy maximum number of results to return with parameter :limit" end + limit = limit.to_i sort_by_prefix = options[:sort_by_prefix] || nil sort_by_ascending = options[:sort_by_ascending].nil? ? true : options[:sort_by_ascending] @@ -342,6 +357,7 @@ def initialize_query(options) if value.nil? raise "couldn't find prefix '" + sort_by_prefix.to_s + "'" end + ActsAsXapian.enquire.sort_by_value_then_relevance!(value, sort_by_ascending) end if collapse_by_prefix.nil? @@ -351,6 +367,7 @@ def initialize_query(options) if value.nil? raise "couldn't find prefix '" + collapse_by_prefix + "'" end + ActsAsXapian.enquire.collapse_key = value end @@ -366,6 +383,7 @@ def initialize_query(options) else sleep delay end + tries += 1 delay *= 2 delay = MSET_MAX_DELAY if delay > MSET_MAX_DELAY @@ -411,6 +429,7 @@ def matches_estimated def spelling_correction correction = ActsAsXapian.query_parser.get_corrected_query_string return nil if correction.empty? + correction.force_encoding('UTF-8') end @@ -495,6 +514,7 @@ def initialize(model_classes, query_string, options = {}, user_query = nil) if model_class.class != Class && model_class.class != String raise "pass in the model class itself, or a string containing its name" end + model_class = model_class.constantize if model_class.class == String new_model_classes.push(model_class) end @@ -572,7 +592,6 @@ def log_description def correctly_encode(w) w.force_encoding('UTF-8') end - end # Search for models which contain theimportant terms taken from a specified @@ -757,6 +776,7 @@ def self.update_index(flush = false, verbose = false) end run_job(job, flush, verbose) end + rescue StandardError, NoMemoryError => error # print any error, and carry on so other things are indexed model_data = { model: job.try(:model), model_id: job.try(:model_id) } @@ -795,6 +815,7 @@ def self.run_job(job, flush, verbose) else raise "unknown ActsAsXapianJob action '#{job.action}'" end + rescue ActiveRecord::RecordNotFound => e # this can happen if the record was hand deleted in the database job.action = 'destroy' @@ -842,6 +863,7 @@ def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, unless ActsAsXapian._is_xapian_db(new_path) raise "found existing " + new_path + " which is not Xapian chert or glass database, please delete for me" end + FileUtils.rm_r(new_path) end FileUtils.cp_r(old_path, new_path) if update_existing @@ -876,6 +898,7 @@ def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, unless ActsAsXapian._is_xapian_db(temp_path) raise "temporary database found " + temp_path + " which is not Xapian chert or glass database, please delete for me" end + FileUtils.rm_r(temp_path) end FileUtils.mv old_path, temp_path if File.exist?(old_path) @@ -935,7 +958,6 @@ def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values end ActiveRecord::Base.establish_connection - end end end @@ -1121,6 +1143,7 @@ def xapian_mark_needs_index_if_reindex if respond_to?(:no_xapian_reindex) && no_xapian_reindex == true return true end + xapian_mark_needs_index end @@ -1135,6 +1158,7 @@ def xapian_create_job(action, model, model_id) model_id: model_id, action: action) end + rescue ActiveRecord::RecordNotUnique => e # Given the error handling in ActsAsXapian::update_index, we can just fail silently if # another process has inserted an acts_as_xapian_jobs record for this model. @@ -1147,7 +1171,6 @@ def xapian_create_job(action, model, model_id) # A hook method that can be used in tests to simulate e.g. an external process inserting a record def xapian_before_create_job_hook(action, model, model_id) end - end ###################################################################### @@ -1170,7 +1193,6 @@ def acts_as_xapian(options) after_destroy :xapian_mark_needs_destroy end end - end # Reopen ActiveRecord and include the acts_as_xapian method diff --git a/lib/alaveteli_file_types.rb b/lib/alaveteli_file_types.rb index 717d726295..5f9d436082 100644 --- a/lib/alaveteli_file_types.rb +++ b/lib/alaveteli_file_types.rb @@ -48,6 +48,7 @@ def filename_and_content_to_mimetype(filename, content) # TODO: we shouldn't have to check empty? here, but Mahoro sometimes returns a blank line :( # e.g. for InfoRequestEvent 17930 return nil if mahoro_type.nil? || mahoro_type.empty? + # text/plain types sometimes come with a charset mahoro_type.match(/^(.*);/) mahoro_type = $1 if $1 @@ -56,12 +57,14 @@ def filename_and_content_to_mimetype(filename, content) # mahoro returns junk "\012- application/msword" as mime type. mahoro_type.match(/([a-z0-9.-]+\/[a-z0-9.-]+)/) return $1 if $1 + # otherwise we got junk back from mahoro nil end def filename_to_mimetype(filename) return nil unless filename + if filename.match(/\.([^.]+)$/i) lext = $1.downcase if FileExtensionToMimeType.include?(lext) @@ -75,6 +78,7 @@ def mimetype_to_extension(mimetype) if FileExtensionToMimeTypeRev.include?(mimetype) return FileExtensionToMimeTypeRev[mimetype] end + nil end end diff --git a/lib/alaveteli_localization.rb b/lib/alaveteli_localization.rb index 80e450e99e..2c665b4065 100644 --- a/lib/alaveteli_localization.rb +++ b/lib/alaveteli_localization.rb @@ -60,6 +60,7 @@ def default_locale def default_locale?(other) return false if other.nil? + default_locale == other.to_s end diff --git a/lib/alaveteli_mail_poller.rb b/lib/alaveteli_mail_poller.rb index b7e3b2462f..9be8745107 100644 --- a/lib/alaveteli_mail_poller.rb +++ b/lib/alaveteli_mail_poller.rb @@ -62,6 +62,7 @@ def get_mail(popmail) received = true popmail.delete end + rescue Net::POPError, StandardError => error Rails.logger.warn "#{ self } error for #{ unique_id }" if send_exception_notifications? @@ -121,5 +122,4 @@ def start() def default_pop3 Net::POP3.new(settings[:address], settings[:port], false) end - end diff --git a/lib/alaveteli_rate_limiter/ip_rate_limiter.rb b/lib/alaveteli_rate_limiter/ip_rate_limiter.rb index 8be4cba95f..367d111f09 100644 --- a/lib/alaveteli_rate_limiter/ip_rate_limiter.rb +++ b/lib/alaveteli_rate_limiter/ip_rate_limiter.rb @@ -48,6 +48,7 @@ def record!(ip) def limit?(ip) ip = clean_ip(ip) return false if whitelist.include?(ip) + rule.limit?(records(ip.to_s)) end diff --git a/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults.rb b/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults.rb index 1cbe94060e..8a5f6dfbfb 100644 --- a/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults.rb +++ b/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults.rb @@ -1,4 +1,3 @@ - module AlaveteliRateLimiter class IPRateLimiter class Defaults diff --git a/lib/alaveteli_rate_limiter/window.rb b/lib/alaveteli_rate_limiter/window.rb index 1545d8a738..ca6cd42dea 100644 --- a/lib/alaveteli_rate_limiter/window.rb +++ b/lib/alaveteli_rate_limiter/window.rb @@ -1,4 +1,3 @@ - module AlaveteliRateLimiter class Window VALID_UNITS = %w( @@ -63,6 +62,7 @@ def ==(other) def validate_unit(unit) msg = "Invalid unit :#{ unit } - must be one of #{ VALID_UNITS }" raise ArgumentError, msg unless VALID_UNITS.include?(unit) + unit end end diff --git a/lib/alaveteli_text_masker.rb b/lib/alaveteli_text_masker.rb index a0dd232daf..9da9e24896 100644 --- a/lib/alaveteli_text_masker.rb +++ b/lib/alaveteli_text_masker.rb @@ -116,7 +116,6 @@ def apply_pdf_masks(text, options = {}) end end - def apply_binary_masks(text, options = {}) # Keep original size, so can check haven't resized it orig_size = text.bytesize @@ -175,5 +174,4 @@ def apply_text_masks(text, options = {}) censor_rules.reduce(text) { |t, rule| rule.apply_to_text(t) } end - end diff --git a/lib/analytics_event.rb b/lib/analytics_event.rb index 18d28e5951..f85de3660c 100644 --- a/lib/analytics_event.rb +++ b/lib/analytics_event.rb @@ -1,5 +1,4 @@ module AnalyticsEvent - # modules for standardising Strings used for event categories and actions module Category @@ -29,5 +28,4 @@ module Action PRO_NAV_WALL = "Wall" POSSIBLE_RELATED = "Possible related requests" end - end diff --git a/lib/attachment_to_html/adapters/pdf.rb b/lib/attachment_to_html/adapters/pdf.rb index 5787accf00..28c85c4609 100644 --- a/lib/attachment_to_html/adapters/pdf.rb +++ b/lib/attachment_to_html/adapters/pdf.rb @@ -22,6 +22,7 @@ def initialize(attachment, opts = {}) # Returns a Boolean def success? return false if contains_too_many_images? + has_content? || contains_images? end diff --git a/lib/attachment_to_html/adapters/rtf.rb b/lib/attachment_to_html/adapters/rtf.rb index 9ed0ff6f1c..e457680e8b 100644 --- a/lib/attachment_to_html/adapters/rtf.rb +++ b/lib/attachment_to_html/adapters/rtf.rb @@ -2,7 +2,6 @@ module AttachmentToHTML module Adapters # Convert application/rtf documents in to HTML class RTF < Adapter - attr_reader :tmpdir # Public: Initialize a RTF converter @@ -46,7 +45,6 @@ def convert sanitize_converted(html) end - end # Works around http://savannah.gnu.org/bugs/?42015 in unrtf ~> 0.21 diff --git a/lib/attachment_to_html/view.rb b/lib/attachment_to_html/view.rb index 7bc4a64db0..b3e5877e03 100644 --- a/lib/attachment_to_html/view.rb +++ b/lib/attachment_to_html/view.rb @@ -1,6 +1,5 @@ module AttachmentToHTML class View < ERB - def self.template @template || "#{ File.dirname(__FILE__) }/template.html.erb" end @@ -34,6 +33,5 @@ def inject_content(area, &block) instance_variable_set("@#{ area }".to_sym, block.call) self.class.send(:attr_accessor, area) end - end end diff --git a/lib/confidence_intervals.rb b/lib/confidence_intervals.rb index 5ddfa20cde..2ccfc7d76c 100644 --- a/lib/confidence_intervals.rb +++ b/lib/confidence_intervals.rb @@ -20,6 +20,7 @@ def ci_bounds(successes, total, power) raise "Can't calculate the CI for 0 observations" if total == 0 + z = Statistics2.pnormaldist(1 - power/2) phat = successes.to_f/total offset = z*Math.sqrt((phat*(1 - phat) + z*z/(4*total))/total) diff --git a/lib/custom_cops/empty_lines_around_rescued_exceptions.rb b/lib/custom_cops/empty_lines_around_rescued_exceptions.rb new file mode 100644 index 0000000000..f9f08f366a --- /dev/null +++ b/lib/custom_cops/empty_lines_around_rescued_exceptions.rb @@ -0,0 +1,88 @@ +require 'rubocop' + +module CustomCops + # Enforces empty line before rescued exceptions. Enforces no empty line after + # rescued exceptions. + # + # @example + # # bad + # begin + # do_something + # do_something_else + # rescue FooError + # error_notification + # handle_error + # end + # + # # good + # begin + # do_something + # do_something_else + # + # rescue FooError + # error_notification + # handle_error + # end + # + # # bad + # begin + # do_something + # do_something_else + # + # rescue FooError + # + # error_notification + # handle_error + # end + # + # # good + # begin + # do_something + # do_something_else + # + # rescue FooError + # error_notification + # handle_error + # end + # + class EmptyLinesAroundRescuedExceptions < RuboCop::Cop::Base + extend RuboCop::Cop::AutoCorrector + include RuboCop::Cop::RangeHelp + + MSG_BEFORE = 'Use empty line before rescued exceptions.' + MSG_AFTER = 'Avoid empty line after rescued exceptions.' + + def on_rescue(node) + return unless node.body.multiline? + + node.resbody_branches.each do |resbody| + next unless resbody.body && resbody.body.multiline? + + preceeding_line = processed_source[resbody.first_line - 2] + unless preceeding_line.blank? + add_offense(resbody, message: MSG_BEFORE) do |corrector| + range = range_by_whole_lines(resbody.source_range) + corrector.insert_before(range, "\n") + end + end + + first_line = processed_source[resbody.body.first_line - 2] + if first_line.blank? + add_offense(resbody, message: MSG_AFTER) do |corrector| + corrector.remove(range_of_first_line(resbody.body)) + end + end + end + end + + private + + def range_of_first_line(node) + buffer = processed_source.buffer + first_line = node.children.first.loc.first_line - 1 + begin_pos = buffer.line_range(first_line).begin_pos + end_pos = begin_pos + buffer.source_line(first_line).length + 1 + Parser::Source::Range.new(buffer, begin_pos, end_pos) + end + end +end diff --git a/lib/data_export.rb b/lib/data_export.rb index 71eee643ed..1692ff312e 100644 --- a/lib/data_export.rb +++ b/lib/data_export.rb @@ -112,6 +112,7 @@ def self.find_each_record(model) # Returns a String def self.csv_export(model, to_run, query=nil, header=nil, override={}, header_map={}) return unless is_required?(model.name, to_run) + # set query and header to default values unless supplied query ||= model header ||= model.column_names @@ -134,7 +135,6 @@ def self.csv_export(model, to_run, query=nil, header=nil, override={}, header_ma process_data(filename, display_header, header, override, query) end - def self.process_data(filename, display_header, column_data, overrides, query) CSV.open(filename, "wb") do |csv| csv << display_header @@ -164,6 +164,7 @@ def self.process_data(filename, display_header, column_data, overrides, query) def self.is_required?(model_name, to_run) return true unless to_run + to_run.include?(model_name) end @@ -175,5 +176,4 @@ def self.handle_error(err, data) puts data.inspect p "" end - end diff --git a/lib/date_quarter.rb b/lib/date_quarter.rb index 16f569593a..b1e6cf1e37 100644 --- a/lib/date_quarter.rb +++ b/lib/date_quarter.rb @@ -18,5 +18,4 @@ def quarters_between(start_at, finish_at) results end - end diff --git a/lib/generators/acts_as_xapian/templates/migration.rb b/lib/generators/acts_as_xapian/templates/migration.rb index 436aa9efc0..ee4d8a60a0 100644 --- a/lib/generators/acts_as_xapian/templates/migration.rb +++ b/lib/generators/acts_as_xapian/templates/migration.rb @@ -7,8 +7,8 @@ def self.up end add_index :acts_as_xapian_jobs, [:model, :model_id], unique: true end + def self.down drop_table :acts_as_xapian_jobs end end - diff --git a/lib/graphs.rb b/lib/graphs.rb index 1529cbd4de..a0e6447e61 100644 --- a/lib/graphs.rb +++ b/lib/graphs.rb @@ -1,7 +1,6 @@ require 'gnuplot' module Graphs - # the colour references given here are for the default palette # as provided by our basic gnuplot configuration, do not rely on them # if you have altered the gnuplot install @@ -31,6 +30,7 @@ module Graphs def select_as_columns(sql) hash_array = User.connection.select_all(sql) return if hash_array.empty? + columns = hash_array.first.values.map { |val| [val] } if hash_array.to_ary.size > 1 hash_array[1..-1].each do |result| diff --git a/lib/has_tag_string/has_tag_string.rb b/lib/has_tag_string/has_tag_string.rb index ab57393a0b..8b4e2c02b3 100644 --- a/lib/has_tag_string/has_tag_string.rb +++ b/lib/has_tag_string/has_tag_string.rb @@ -127,18 +127,21 @@ def get_tag_values(tag_as_string) end end raise TagNotFound unless found + results end # Adds a new tag to the model, if it isn't already there def add_tag_if_not_already_present(tag_as_string) return tag_string if has_tag?(tag_as_string) + self.tag_string = tag_string + ' ' + tag_as_string end # Removes tag to the model def remove_tag(tag_as_string) return tag_string unless has_tag?(tag_as_string) + self.tag_string = tag_string.sub(/\b#{tag_as_string}\b/, '').strip end end diff --git a/lib/health_checks.rb b/lib/health_checks.rb index 5d21cc1dc6..e6f681be2f 100644 --- a/lib/health_checks.rb +++ b/lib/health_checks.rb @@ -33,5 +33,4 @@ def ok? def assert_valid_check(check) check.respond_to?(:ok?) end - end diff --git a/lib/health_checks/health_checkable.rb b/lib/health_checks/health_checkable.rb index 1cebfd8d75..9ca811ff28 100644 --- a/lib/health_checks/health_checkable.rb +++ b/lib/health_checks/health_checkable.rb @@ -1,6 +1,5 @@ module HealthChecks module HealthCheckable - attr_accessor :failure_message, :success_message def initialize(args = {}) @@ -19,6 +18,5 @@ def ok? def message ok? ? success_message : failure_message end - end end diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb index daf18fbe2f..5cee141291 100644 --- a/lib/i18n_fixes.rb +++ b/lib/i18n_fixes.rb @@ -25,6 +25,7 @@ def n_(*keys) def gettext_interpolate(string, values) return string unless string.is_a?(String) + # $1, $2 don't work with SafeBuffer so casting to string as workaround safe = string.html_safe? string = string.to_str.gsub(MATCH) do @@ -45,7 +46,6 @@ def gettext_interpolate(string, values) safe ? string.html_safe : string end - # this monkeypatch corrects inconsistency with gettext_i18n_rails # where the latter deals with strings but rails i18n deals with # symbols for locales diff --git a/lib/languages.rb b/lib/languages.rb index 1b5dbd32f9..8a8c20853a 100644 --- a/lib/languages.rb +++ b/lib/languages.rb @@ -189,6 +189,7 @@ def self.get_language_name(locale) } locale = locale.to_s.sub("_", "-") # normalize return language_names[locale] if language_names[locale] + main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0] language_names[main_part] end diff --git a/lib/mail_handler.rb b/lib/mail_handler.rb index 189665da46..b5777a2a2e 100644 --- a/lib/mail_handler.rb +++ b/lib/mail_handler.rb @@ -3,7 +3,6 @@ require 'tmpdir' module MailHandler - require 'mail' require 'mail_handler/backends/mail_extensions' require 'mail_handler/backends/mail_backend' @@ -140,8 +139,8 @@ def get_attachment_text_one_file(content_type, body, charset = 'utf-8') text end - def get_attachment_text_from_zip_file(zip_file) + def get_attachment_text_from_zip_file(zip_file) text = "" zip_file.each do |entry| if entry.file? @@ -171,5 +170,4 @@ def get_attachment_text_from_zip_file(zip_file) # Turn instance methods into class methods extend self - end diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index 804f8f821a..55424db503 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -155,6 +155,7 @@ def get_all_addresses(mail, include_invalid: false) def empty_return_path?(mail) return false if mail['return-path'].nil? return true if mail['return-path'].value.blank? + false end @@ -177,6 +178,7 @@ def is_outlook?(part) if filename && AlaveteliFileTypes.filename_to_mimetype(filename) == 'application/vnd.ms-outlook' return true end + false end @@ -219,6 +221,7 @@ def decode_attached_part(part, parent_mail) # Attached mail didn't parse, so treat as binary part.content_type = 'application/octet-stream' end + rescue TNEFParsingError part.rfc822_attachment = nil part.content_type = 'application/octet-stream' @@ -280,6 +283,7 @@ def count_parts(part, parent_mail) # Choose the best part from alternatives def choose_best_alternative(mail) return mail.parts.detect(&:multipart?) if mail.parts.any?(&:multipart?) + if mail.html_part mail.html_part elsif mail.text_part @@ -433,6 +437,7 @@ def calculate_hexdigest(body) # check uuencoded attachments which can be located in plain text uuencoded_attributes = all_attributes.inject([]) do |acc, attrs| next acc unless attrs[:content_type] == 'text/plain' + acc += uudecode(attrs[:body], attrs[:url_part_number]) end attributes ||= uuencoded_attributes.find do |attrs| @@ -476,6 +481,7 @@ def address_from_name_and_email(name, email) raise "invalid email " + email + " passed to address_from_name_and_email" end return Mail::Address.new(email.dup).to_s if name.nil? + address = Mail::Address.new address.display_name = name.dup address.address = email.dup @@ -491,6 +497,7 @@ def address_from_string(string) def get_emails_within_received_headers(email) received_headers = Array(email['Received']) return [] if received_headers.empty? + received_headers.map(&:to_s). join(' '). scan(MySociety::Validate.email_find_regexp). diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index 1e0a028ff3..cc752d5cc4 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -13,7 +13,6 @@ class Message # A patched version of the parameter hash that handles nil values without throwing # an error. class ParameterHash < IndifferentHash - def encoded map.sort { |a,b| a.first.to_s <=> b.first.to_s }.map do |key_name, value| # The replacement of this commented out line is the change @@ -26,5 +25,4 @@ def encoded end.join(";\r\n\s") end end - end diff --git a/lib/mail_handler/reply_handler.rb b/lib/mail_handler/reply_handler.rb index 9133437db2..1b5edb5eb1 100644 --- a/lib/mail_handler/reply_handler.rb +++ b/lib/mail_handler/reply_handler.rb @@ -30,6 +30,7 @@ def self.permanently_failed_addresses(message) # Either we couldn’t find the Status field, or it was a transient failure break end + if section =~ /^Final-Recipient: rfc822;(.+)/ permanently_failed_recipients.push($1) end @@ -76,6 +77,7 @@ def self.is_oof?(message) return true if subject == "out of office" return true if subject == "out of office reply" return true if subject.end_with? "is out of the office" + false end diff --git a/lib/no_constraint_disabling.rb b/lib/no_constraint_disabling.rb index f6e00cf179..6e520d6fb8 100644 --- a/lib/no_constraint_disabling.rb +++ b/lib/no_constraint_disabling.rb @@ -24,7 +24,6 @@ def disable_referential_integrity module ActiveRecord class FixtureSet - def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}, config = ActiveRecord::Base) fixture_set_names = Array(fixture_set_names).map(&:to_s) class_names = ClassCache.new class_names, config @@ -107,6 +106,5 @@ def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {} end cached_fixtures(connection, fixture_set_names) end - end end diff --git a/lib/normalize_string.rb b/lib/normalize_string.rb index a1e42ddda7..a810421010 100644 --- a/lib/normalize_string.rb +++ b/lib/normalize_string.rb @@ -5,7 +5,6 @@ class EncodingNormalizationError < StandardError end def normalize_string_to_utf8(s, suggested_character_encoding=nil) - # Make a list of encodings to try: to_try = [] @@ -78,6 +77,7 @@ def convert_string_to_utf8_or_binary(s, suggested_character_encoding=nil) def convert_string_to_utf8(s, suggested_character_encoding=nil) result = normalize_string_to_utf8 s, suggested_character_encoding StringConversionResult.new(result, false) + rescue EncodingNormalizationError result = scrub(s) StringConversionResult.new(result, true) diff --git a/lib/public_body_csv.rb b/lib/public_body_csv.rb index 5438db936d..bf669adaac 100644 --- a/lib/public_body_csv.rb +++ b/lib/public_body_csv.rb @@ -17,7 +17,6 @@ # Ministry of Silly Walks,http://www.localhost # Department of Loneliness,http://localhost class PublicBodyCSV - def self.default_fields [:id, :name, @@ -54,6 +53,7 @@ def self.export PublicBody.includes(:translations, :tags).visible.find_each do |public_body| next if public_body.site_administration? + csv << public_body end @@ -94,5 +94,4 @@ def collect_public_body_attributes(public_body) end end end - end diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb index 8648fee425..540b53faf0 100644 --- a/lib/routing_filters.rb +++ b/lib/routing_filters.rb @@ -7,6 +7,7 @@ def prepend_locale?(locale) AlaveteliLocalization.available_locales.length > 1 && (self.class.include_default_locale? || !default_locale?(locale)) end + # And override the generation logic to use FastGettext.locale # rather than I18n.locale (the latter is what rails uses # internally and may look like `en-US`, whereas the former is diff --git a/lib/tasks/storage/storage.rb b/lib/tasks/storage/storage.rb index f608a67f0a..a9bcc3e315 100644 --- a/lib/tasks/storage/storage.rb +++ b/lib/tasks/storage/storage.rb @@ -63,6 +63,7 @@ def promote promotable_blobs.find_each.with_index do |blob, index| next unless secondary_service.exist?(blob.key) + blob.update(service_name: secondary_service.name) print "#{prefix}: Promote #{index + 1}/#{count}" @@ -135,6 +136,7 @@ def mirror_service? def mirror_service raise not_a_mirror unless mirror_service? + service end @@ -152,6 +154,7 @@ def mirror_primary_not_disk_service def disk_service raise mirror_primary_not_disk_service unless disk_service? + mirror_service.primary end diff --git a/lib/tasks/usage.rb b/lib/tasks/usage.rb index 8f760df83e..8ab63cc958 100644 --- a/lib/tasks/usage.rb +++ b/lib/tasks/usage.rb @@ -1,5 +1,4 @@ module Usage - def usage_message(message) puts '' puts message @@ -18,5 +17,4 @@ def check_for_env_vars(env_vars, example) usage_message usage end end - end diff --git a/lib/typeahead_search.rb b/lib/typeahead_search.rb index 38c4e2f70c..1d443be881 100644 --- a/lib/typeahead_search.rb +++ b/lib/typeahead_search.rb @@ -1,5 +1,4 @@ class TypeaheadSearch - include ConfigHelper attr_accessor :query, :model, :page, :per_page, :wildcard, :run_search @@ -17,6 +16,7 @@ def initialize(query, opts = {}) def xapian_search check_query return nil unless @run_search + ActsAsXapian.readable_init old_default_op = ActsAsXapian.query_parser.default_op ActsAsXapian.query_parser.default_op = Xapian::Query::OP_OR @@ -59,7 +59,6 @@ def check_query # don't run a search if there's no query @run_search = false if @query.blank? - end def run_query @@ -102,5 +101,4 @@ def collapse? 'request_collapse' end end - end diff --git a/lib/user_spam_scorer.rb b/lib/user_spam_scorer.rb index 2976af068e..109be1edbc 100644 --- a/lib/user_spam_scorer.rb +++ b/lib/user_spam_scorer.rb @@ -141,6 +141,7 @@ def spam?(user) def score(user) return 0 if user.comments.any? || user.track_things.any? + score_mappings.inject(0) do |score_count, score_mapping| if send(score_mapping.first, user) score_count + score_mapping.last @@ -206,11 +207,13 @@ def about_me_already_exists?(user) def user_agent_is_suspicious?(user) return false unless user.respond_to?(:user_agent) + suspicious_user_agents.include?(user.user_agent) end def ip_range_is_suspicious?(user) return false unless user.respond_to?(:ip) + suspicious_ip_ranges.any? { |range| IPAddr.new(range).include?(user.ip) } end diff --git a/lib/user_stats.rb b/lib/user_stats.rb index 42a7cd7f51..6fad12bfd2 100644 --- a/lib/user_stats.rb +++ b/lib/user_stats.rb @@ -2,7 +2,6 @@ # Public: methods for getting stats about users on a per domain basis class UserStats - # Returns a list of email domains people have used to sign up with and the # number of signups for each, ordered by popularity (most popular first) def self.list_user_domains(params={}) @@ -72,5 +71,4 @@ def self.unbanned_by_domain(domain, start_date=nil) eligible end end - end diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb index 822d66de8f..daef6cd7bf 100644 --- a/lib/world_foi_websites.rb +++ b/lib/world_foi_websites.rb @@ -161,5 +161,4 @@ def self.country_in_eu?(code) def self.is_ask_the_eu? AlaveteliConfiguration.domain == 'www.asktheeu.org' end - end diff --git a/lib/xapian_queries.rb b/lib/xapian_queries.rb index 958df79191..0eee8284c7 100644 --- a/lib/xapian_queries.rb +++ b/lib/xapian_queries.rb @@ -1,5 +1,4 @@ module XapianQueries - # These methods take some filter criteria expressed in a hash and convert them # into a xapian query referencing the terms and values stored by InfoRequestEvent. # Note that the params are request params and may contain irrelevant keys diff --git a/script/redact-raw-emails.rb b/script/redact-raw-emails.rb index bec0b3dc3c..93fe539c13 100755 --- a/script/redact-raw-emails.rb +++ b/script/redact-raw-emails.rb @@ -54,6 +54,7 @@ def censor_data(data, content_type) def censor(text) return unless text + @incoming_message.info_request.apply_censor_rules_to_text(text) end diff --git a/script/switch-theme.rb b/script/switch-theme.rb index a93ae2bc96..f4699f20d4 100755 --- a/script/switch-theme.rb +++ b/script/switch-theme.rb @@ -56,9 +56,11 @@ def show_themes $available_themes = Dir.entries(theme_directory).find_all do |local_theme_name| next if [".", ".."].index local_theme_name next unless local_theme_name + full_path = File.join theme_directory, local_theme_name next unless File.directory? full_path next unless File.directory? File.join(full_path, '.git') + local_theme_name end.sort diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb index d99c311e2a..ab3d095bae 100644 --- a/spec/controllers/admin_censor_rule_controller_spec.rb +++ b/spec/controllers/admin_censor_rule_controller_spec.rb @@ -4,7 +4,6 @@ before(:each) { basic_auth_login(@request) } describe 'GET index' do - let!(:global_rules) do 3.times.map { FactoryBot.create(:global_censor_rule) } end @@ -27,13 +26,10 @@ it 'renders the correct template' do expect(response).to render_template('index') end - end describe 'GET new' do - context 'global censor rule' do - before do get :new end @@ -65,11 +61,9 @@ it 'sets the URL for the form to POST to' do expect(assigns[:form_url]).to eq(admin_censor_rules_path) end - end context 'request_id param' do - let(:info_request) { FactoryBot.create(:info_request) } before do @@ -100,11 +94,9 @@ expect(assigns[:form_url]). to eq(admin_request_censor_rules_path(info_request)) end - end context 'user_id param' do - let(:user) { FactoryBot.create(:user) } before do @@ -134,12 +126,10 @@ it 'sets the URL for the form to POST to' do expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(user)) end - end # NOTE: This should be public_body_id but the resource is mapped as :bodies context 'body_id param' do - let(:public_body) { FactoryBot.create(:public_body) } before do @@ -170,15 +160,11 @@ expect(assigns[:form_url]). to eq(admin_body_censor_rules_path(public_body)) end - end - end describe 'POST create' do - context 'a global censor rule' do - let(:censor_rule_params) do params = FactoryBot.attributes_for(:global_censor_rule) # last_edit_editor gets set in the controller @@ -216,7 +202,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'calls expire_requests on the new censor_rule' do censor_rule = FactoryBot.build(:global_censor_rule) allow(CensorRule).to receive(:new) { censor_rule } @@ -233,11 +218,9 @@ def create_censor_rule admin_censor_rules_path ) end - end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -251,13 +234,10 @@ def create_censor_rule create_censor_rule expect(response).to render_template('new') end - end - end context 'request_id param' do - let(:censor_rule_params) do params = FactoryBot.attributes_for(:info_request_censor_rule) # last_edit_editor gets set in the controller @@ -301,7 +281,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'persists the censor rule' do post :create, params: { censor_rule: censor_rule_params, @@ -348,7 +327,6 @@ def create_censor_rule end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -368,12 +346,10 @@ def create_censor_rule } expect(response).to render_template('new') end - end end context 'user_id param' do - let(:user) { FactoryBot.create(:user) } let(:censor_rule_params) do @@ -411,7 +387,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'calls expire_requests on the new censor_rule' do allow(User).to receive(:find) { user } censor_rule = FactoryBot.build(:user_censor_rule, @@ -430,11 +405,9 @@ def create_censor_rule admin_user_path(assigns[:censor_rule].user) ) end - end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -454,13 +427,10 @@ def create_censor_rule } expect(response).to render_template('new') end - end - end context 'body_id param' do - let(:censor_rule_params) do params = FactoryBot.attributes_for(:public_body_censor_rule) # last_edit_editor gets set in the controller @@ -495,7 +465,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'persists the censor rule' do post :create, params: { censor_rule: censor_rule_params, @@ -540,7 +509,6 @@ def create_censor_rule end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -560,16 +528,12 @@ def create_censor_rule } expect(response).to render_template('new') end - end end - end describe 'GET edit' do - context 'a CensorRule with an associated InfoRequest' do - let(:censor_rule) { FactoryBot.create(:info_request_censor_rule) } it 'returns a successful response' do @@ -586,11 +550,9 @@ def create_censor_rule get :edit, params: { id: censor_rule.id } expect(assigns[:censor_rule]).to eq(censor_rule) end - end context 'a CensorRule with an associated User' do - let(:censor_rule) { FactoryBot.create(:user_censor_rule) } it 'returns a successful response' do @@ -607,11 +569,9 @@ def create_censor_rule get :edit, params: { id: censor_rule.id } expect(assigns[:censor_rule]).to eq(censor_rule) end - end context 'a CensorRule with an associated PublicBody' do - let(:censor_rule) { FactoryBot.create(:public_body_censor_rule) } it 'returns a successful response' do @@ -628,11 +588,9 @@ def create_censor_rule get :edit, params: { id: censor_rule.id } expect(assigns[:censor_rule]).to eq(censor_rule) end - end context 'a global rule' do - let(:censor_rule) { FactoryBot.create(:global_censor_rule) } it 'returns a successful response' do @@ -649,15 +607,11 @@ def create_censor_rule get :edit, params: { id: censor_rule.id } expect(assigns[:censor_rule]).to eq(censor_rule) end - end - end describe 'PUT update' do - context 'a global censor rule' do - let(:censor_rule) { FactoryBot.create(:global_censor_rule) } it 'finds the correct censor rule to edit' do @@ -679,7 +633,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'updates the censor rule' do put :update, params: { id: censor_rule.id, @@ -717,11 +670,9 @@ def create_censor_rule expect(response).to redirect_to(admin_censor_rules_path) end - end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -743,13 +694,10 @@ def create_censor_rule expect(response).to render_template('edit') end - end - end context 'a CensorRule with an associated InfoRequest' do - let(:censor_rule) { FactoryBot.create(:info_request_censor_rule) } it 'finds the correct censor rule to edit' do @@ -771,7 +719,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'updates the censor rule' do put :update, params: { id: censor_rule.id, @@ -811,11 +758,9 @@ def create_censor_rule admin_request_path(assigns[:censor_rule].info_request) ) end - end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -837,13 +782,10 @@ def create_censor_rule expect(response).to render_template('edit') end - end - end context 'a CensorRule with an associated User' do - let(:censor_rule) { FactoryBot.create(:user_censor_rule) } it 'finds the correct censor rule to edit' do @@ -907,7 +849,6 @@ def create_censor_rule end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -929,13 +870,10 @@ def create_censor_rule expect(response).to render_template('edit') end - end - end context 'a CensorRule with an associated PublicBody' do - let(:censor_rule) { FactoryBot.create(:public_body_censor_rule) } it 'finds the correct censor rule to edit' do @@ -957,7 +895,6 @@ def create_censor_rule end context 'successfully saving the censor rule' do - it 'updates the censor rule' do put :update, params: { id: censor_rule.id, @@ -997,11 +934,9 @@ def create_censor_rule admin_body_path(assigns[:censor_rule].public_body) ) end - end context 'unsuccessfully saving the censor rule' do - before(:each) do allow_any_instance_of(CensorRule).to receive(:save).and_return(false) end @@ -1023,17 +958,12 @@ def create_censor_rule expect(response).to render_template('edit') end - end - end - end describe 'DELETE destroy' do - context 'a global CensorRule' do - let(:censor_rule) { FactoryBot.create(:global_censor_rule) } it 'finds the correct censor rule to destroy' do @@ -1051,11 +981,9 @@ def create_censor_rule delete :destroy, params: { id: censor_rule.id } expect(response).to redirect_to(admin_censor_rules_path) end - end context 'a CensorRule with an associated InfoRequest' do - let(:censor_rule) { FactoryBot.create(:info_request_censor_rule) } it 'finds the correct censor rule to destroy' do @@ -1082,11 +1010,9 @@ def create_censor_rule expect(response). to redirect_to(admin_request_path(censor_rule.info_request)) end - end context 'a CensorRule with an associated User' do - let(:censor_rule) { FactoryBot.create(:user_censor_rule) } it 'finds the correct censor rule to destroy' do @@ -1112,11 +1038,9 @@ def create_censor_rule delete :destroy, params: { id: censor_rule.id } expect(response).to redirect_to(admin_user_path(censor_rule.user)) end - end context 'a CensorRule with an associated PublicBody' do - let(:censor_rule) { FactoryBot.create(:public_body_censor_rule) } it 'finds the correct censor rule to destroy' do @@ -1143,9 +1067,6 @@ def create_censor_rule expect(response). to redirect_to(admin_body_path(censor_rule.public_body)) end - end - end - end diff --git a/spec/controllers/admin_comment_controller_spec.rb b/spec/controllers/admin_comment_controller_spec.rb index 4eb0bb4ed7..28ebcb38bb 100644 --- a/spec/controllers/admin_comment_controller_spec.rb +++ b/spec/controllers/admin_comment_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AdminCommentController do - describe 'GET index' do let(:admin_user) { FactoryBot.create(:admin_user) } let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } @@ -61,7 +60,6 @@ end context 'if pro is enabled' do - it 'does not include comments on embargoed requests if the current user is a pro admin user' do with_feature_enabled(:alaveteli_pro) do @@ -84,7 +82,6 @@ end end end - end describe 'GET edit' do @@ -104,11 +101,8 @@ expect(assigns[:comment]).to eq(comment) end - context 'if pro is enabled' do - context 'if the current user cannot admin the comment' do - it 'raises ActiveRecord::RecordNotFound' do with_feature_enabled(:alaveteli_pro) do comment.info_request.create_embargo @@ -121,7 +115,6 @@ end context 'if the current user can admin the comment' do - it 'renders the edit template' do with_feature_enabled(:alaveteli_pro) do comment.info_request.create_embargo @@ -141,7 +134,6 @@ let(:atts) { FactoryBot.attributes_for(:comment, body: 'I am new') } context 'on valid data submission' do - it 'gets the comment' do sign_in admin_user put :update, params: { id: comment.id, comment: atts } @@ -190,13 +182,10 @@ it 'updates the comment' do expect(Comment.find(comment.id).attention_requested).to eq(true) end - end context 'the comment is being hidden' do - context 'without changing the text' do - it 'logs a "hide_comment" event' do atts = FactoryBot.attributes_for(:comment, attention_requested: true, @@ -207,11 +196,9 @@ last_event = Comment.find(comment.id).info_request_events.last expect(last_event.event_type).to eq('hide_comment') end - end context 'the text is changed as well' do - it 'logs an "edit_comment" event' do atts = FactoryBot.attributes_for(:comment, attention_requested: true, @@ -223,9 +210,7 @@ last_event = Comment.find(comment.id).info_request_events.last expect(last_event.event_type).to eq('edit_comment') end - end - end it 'shows a success notice' do @@ -250,7 +235,6 @@ end context 'on invalid data submission' do - it 'renders the edit template' do with_feature_enabled(:alaveteli_pro) do sign_in admin_user @@ -261,14 +245,10 @@ expect(response).to render_template('edit') end end - end - context 'if pro is enabled' do - context 'if the current user cannot admin the comment' do - it 'raises ActiveRecord::RecordNotFound' do with_feature_enabled(:alaveteli_pro) do comment.info_request.create_embargo @@ -281,7 +261,6 @@ end context 'if the current user can admin the comment' do - it 'updates the comment' do with_feature_enabled(:alaveteli_pro) do comment.info_request.create_embargo @@ -293,5 +272,4 @@ end end end - end diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb index 4558fd5434..1942cb0612 100644 --- a/spec/controllers/admin_general_controller_spec.rb +++ b/spec/controllers/admin_general_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AdminGeneralController do - describe "GET #index" do let(:admin_user) { FactoryBot.create(:admin_user) } let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } @@ -61,7 +60,6 @@ end context 'when there are request tasks' do - it 'assigns public_request_tasks to true' do undeliverable = FactoryBot. create(:incoming_message, @@ -70,11 +68,9 @@ get :index expect(assigns[:public_request_tasks]).to be true end - end context 'when there are no request tasks' do - it 'assigns public_request_tasks to false' do sign_in admin_user get :index @@ -111,24 +107,20 @@ end context 'when there are authority tasks' do - it 'assigns authority tasks to true' do update_body_request = FactoryBot.create(:update_body_request) sign_in admin_user get :index expect(assigns[:authority_tasks]).to be true end - end context 'when there are no authority tasks' do - it 'assigns authority tasks to false' do sign_in admin_user get :index expect(assigns[:authority_tasks]).to be false end - end it 'assigns comments requiring attention to the view' do @@ -139,51 +131,41 @@ end context 'when there are comment tasks' do - it 'assigns comment tasks to true' do comment = FactoryBot.create(:attention_requested_comment) sign_in admin_user get :index expect(assigns[:comment_tasks]).to be true end - end context 'when there are no authority tasks' do - it 'assigns authority tasks to false' do sign_in admin_user get :index expect(assigns[:comment_tasks]).to be false end - end context 'when there is nothing to do' do - it 'assigns nothing to do to true' do sign_in admin_user get :index expect(assigns[:nothing_to_do]).to be true end - end context 'when there is something to do' do - it 'assigns nothing to do to false' do comment = FactoryBot.create(:attention_requested_comment) sign_in admin_user get :index expect(assigns[:nothing_to_do]).to be false end - end context 'when the user is not a pro admin' do - context 'when pro is enabled' do - it 'does not assign embargoed requests that require admin to the view' do with_feature_enabled(:alaveteli_pro) do requires_admin_request = FactoryBot.create(:requires_admin_request) @@ -216,7 +198,6 @@ expect(assigns[:embargoed_attention_requests]).to be nil end end - end it 'does not assign embargoed requests that require admin to the view' do @@ -247,11 +228,9 @@ expect(assigns[:attention_requests]).to eq([]) expect(assigns[:embargoed_attention_requests]).to be nil end - end context 'when the user is a pro admin and pro is enabled' do - it 'assigns embargoed requests that require admin to the view' do with_feature_enabled(:alaveteli_pro) do requires_admin_request = FactoryBot.create(:requires_admin_request) @@ -287,17 +266,14 @@ end context 'when there is nothing to do' do - it 'assigns nothing to do to true' do sign_in pro_admin_user get :index expect(assigns[:nothing_to_do]).to be true end - end context 'when there is something to do' do - it 'assigns nothing to do to false' do with_feature_enabled(:alaveteli_pro) do attention_requested_request = @@ -308,14 +284,11 @@ expect(assigns[:nothing_to_do]).to be false end end - end end - end describe 'GET #timeline' do - before do info_request = FactoryBot.create(:info_request) public_body = FactoryBot.create(:public_body) @@ -343,7 +316,6 @@ end context 'when start_date is set' do - before do get :timeline, params: { all: 1, start_date: Time.utc(1970, 1, 1) } end @@ -351,11 +323,9 @@ it 'sets the title appropriately' do expect(assigns[:events_title]).to eq("All events, all time") end - end context 'when event_type is info_request_event' do - before do get :timeline, params: { all: 1, event_type: 'info_request_event' } end @@ -374,7 +344,6 @@ end context 'when event_type is authority_change' do - before do get :timeline, params: { all: 1, event_type: 'authority_change' } end @@ -390,13 +359,10 @@ "Authority changes in the last 2 days" ) end - end - end describe 'GET #stats' do - it 'assigns the number of public bodies to the view' do get :stats expect(assigns[:public_body_count]).to eq PublicBody.count @@ -454,6 +420,5 @@ "all_successful_requests" => 6, "all_new_requests" => 7 }) end - end end diff --git a/spec/controllers/admin_holiday_imports_controller_spec.rb b/spec/controllers/admin_holiday_imports_controller_spec.rb index e3f3786ba7..c17d3cb4aa 100644 --- a/spec/controllers/admin_holiday_imports_controller_spec.rb +++ b/spec/controllers/admin_holiday_imports_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminHolidayImportsController do - describe 'GET new' do - it 'renders the new template' do get :new expect(response).to render_template('new') @@ -15,7 +13,6 @@ end describe 'if the import is valid' do - it 'populates the import' do mock_import = double(HolidayImport, valid?: true, populate: nil) @@ -23,20 +20,16 @@ expect(mock_import).to receive(:populate) get :new end - end - end describe 'POST create' do - it 'creates an import' do post :create expect(assigns[:holiday_import]).to be_instance_of(HolidayImport) end describe 'when handling an iCal feed' do - let(:params) do { "holiday_import" => { @@ -64,11 +57,9 @@ post :create, params: params expect(Holiday.count).to eq(2) end - end describe 'if the import can be saved' do - before do mock_import = double(HolidayImport, save: true) allow(HolidayImport).to receive(:new).and_return(mock_import) @@ -82,11 +73,9 @@ it 'should redirect to the index' do expect(response).to redirect_to(admin_holidays_path) end - end describe 'if the import cannot be saved' do - before do mock_import = double(HolidayImport, save: false) allow(HolidayImport).to receive(:new).and_return(mock_import) @@ -96,10 +85,6 @@ it 'should render the new template' do expect(response).to render_template('new') end - end - end - - end diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb index b00d57a4ba..d55bc1f0b1 100644 --- a/spec/controllers/admin_holidays_controller_spec.rb +++ b/spec/controllers/admin_holidays_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminHolidaysController do - describe 'GET index' do - before do @holiday_one = FactoryBot.create(:holiday, day: Date.new(2010, 1, 1)) @holiday_two = FactoryBot.create(:holiday, day: Date.new(2011, 2, 2)) @@ -27,23 +25,17 @@ get :index expect(response).to render_template('index') end - end describe 'GET new' do - - describe 'when not using ajax' do - it 'renders the new template' do get :new expect(response).to render_template('new') end - end describe 'when using ajax' do - it 'renders the new form partial' do get :new, xhr: true expect(response).to render_template(partial: '_new_form') @@ -54,11 +46,9 @@ get :new expect(assigns[:holiday]).to be_instance_of(Holiday) end - end describe 'POST create' do - before do @holiday_params = { :description => "New Year's Day", 'day(1i)' => '2010', @@ -82,7 +72,6 @@ end context 'when there are errors' do - before do allow_any_instance_of(Holiday).to receive(:save).and_return(false) post :create, params: { holiday: @holiday_params } @@ -92,42 +81,34 @@ expect(response).to render_template('new') end end - end describe 'GET edit' do - before do @holiday = FactoryBot.create(:holiday) end describe 'when not using ajax' do - it 'renders the edit template' do get :edit, params: { id: @holiday.id } expect(response).to render_template('edit') end - end describe 'when using ajax' do - it 'renders the edit form partial' do get :edit, xhr: true, params: { id: @holiday.id } expect(response).to render_template(partial: '_edit_form') end - end it 'gets the holiday in the id param' do get :edit, params: { id: @holiday.id } expect(assigns[:holiday]).to eq(@holiday) end - end describe 'PUT update' do - before do @holiday = FactoryBot.create(:holiday, day: Date.new(2010, 1, 1), description: "Test Holiday") @@ -154,7 +135,6 @@ end context 'when there are errors' do - before do allow_any_instance_of(Holiday).to receive(:update).and_return(false) put :update, params: { @@ -167,11 +147,9 @@ expect(response).to render_template('edit') end end - end describe 'DELETE destroy' do - before(:each) do @holiday = FactoryBot.create(:holiday) delete :destroy, params: { id: @holiday.id } @@ -194,5 +172,4 @@ expect(response).to redirect_to(admin_holidays_path) end end - end diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 631ab20f9d..f805ca90e5 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe AdminIncomingMessageController, "when administering incoming messages" do - let(:admin_user) { FactoryBot.create(:admin_user) } let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } describe 'when destroying an incoming message' do - before(:each) do sign_in(admin_user) load_raw_emails_data @@ -63,7 +61,6 @@ end describe 'when redelivering an incoming message' do - before(:each) do sign_in(admin_user) load_raw_emails_data @@ -86,14 +83,12 @@ end it 'should succeed, even if a duplicate xapian indexing job is created' do - with_duplicate_xapian_job_creation do post :redeliver, params: { id: incoming_message.id, url_title: destination_info_request.url_title } end - end it 'shouldn\'t do anything if no message_id is supplied' do @@ -163,7 +158,6 @@ end describe 'when editing an incoming message' do - before do sign_in(admin_user) @incoming = FactoryBot.create(:incoming_message) @@ -204,7 +198,6 @@ end describe 'when updating an incoming message' do - before do sign_in(admin_user) @incoming = FactoryBot.create(:incoming_message, prominence: 'normal') @@ -269,7 +262,6 @@ def make_request(params=@default_params) end context 'if the incoming message saves correctly' do - it 'should redirect to the admin info request view' do make_request expect(response).to redirect_to admin_request_url(@incoming.info_request) @@ -279,18 +271,15 @@ def make_request(params=@default_params) make_request expect(flash[:notice]).to eq('Incoming message successfully updated.') end - end context 'if the incoming message is not valid' do - it 'should render the edit template' do make_request({ id: @incoming.id, incoming_message: { prominence: 'fantastic', prominence_reason: 'dull' } }) expect(response).to render_template("edit") end - end context 'if the request is embargoed', feature: :alaveteli_pro do @@ -333,7 +322,6 @@ def make_request(params=@default_params) before { sign_in(admin_user) } context "the user confirms deletion" do - it "destroys the selected messages" do post :bulk_destroy, params: { request_id: request.id, @@ -386,7 +374,6 @@ def make_request(params=@default_params) end context "not all the messages can be destroyed" do - it "set an error message in flash" do allow(spam2).to receive(:destroy).and_raise("random DB error") allow(IncomingMessage).to receive(:where).and_return([spam1, spam2]) @@ -399,13 +386,10 @@ def make_request(params=@default_params) expect(flash[:error]).to match(msg) end - end - end context "the user does not confirm deletion" do - it "does not destroy the messages" do post :bulk_destroy, params: { request_id: request.id, @@ -425,7 +409,6 @@ def make_request(params=@default_params) expect(response).to redirect_to(admin_request_url(request)) end - end context 'if the request is embargoed', feature: :alaveteli_pro do @@ -454,7 +437,5 @@ def make_request(params=@default_params) end end end - end - end diff --git a/spec/controllers/admin_info_request_event_controller_spec.rb b/spec/controllers/admin_info_request_event_controller_spec.rb index d69ff903f9..7f3cd7136e 100644 --- a/spec/controllers/admin_info_request_event_controller_spec.rb +++ b/spec/controllers/admin_info_request_event_controller_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' RSpec.describe AdminInfoRequestEventController do - describe 'PUT update' do let(:info_request_event) do info_request_event = FactoryBot.create(:response_event) end describe 'when handling valid data' do - it 'gets the info request event' do put :update, params: { id: info_request_event } expect(assigns[:info_request_event]).to eq(info_request_event) @@ -64,7 +62,5 @@ }.to raise_error(RuntimeError, "can only mark responses as requires clarification") end - end - end diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb index 801fca6270..bbeac8f847 100644 --- a/spec/controllers/admin_outgoing_message_controller_spec.rb +++ b/spec/controllers/admin_outgoing_message_controller_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe AdminOutgoingMessageController do - let(:admin_user) { FactoryBot.create(:admin_user) } let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } describe 'GET #edit' do - before { sign_in(admin_user) } let(:info_request) { FactoryBot.create(:info_request) } @@ -23,23 +21,19 @@ end context 'when the message is the initial outgoing message' do - it 'sets is_initial_message to true' do get :edit, params: { id: outgoing.id } expect(assigns[:is_initial_message]).to eq(true) end - end context 'when the message is not initial outgoing message' do - it 'sets is_initial_message to false' do outgoing = FactoryBot.create(:new_information_followup, info_request: info_request) get :edit, params: { id: outgoing.id } expect(assigns[:is_initial_message]).to eq(false) end - end context 'if the request is embargoed', feature: :alaveteli_pro do @@ -67,7 +61,6 @@ end describe 'DELETE #destroy' do - before { sign_in(admin_user) } let(:info_request) { FactoryBot.create(:info_request) } @@ -82,7 +75,6 @@ end context 'successfully destroying the message' do - it 'destroys the message' do delete :destroy, params: { id: outgoing.id } expect(assigns[:outgoing_message]).to_not be_persisted @@ -103,7 +95,6 @@ delete :destroy, params: { id: outgoing.id } expect(response).to redirect_to(admin_request_url(info_request)) end - end context 'unsuccessfully destroying the message' do @@ -127,11 +118,9 @@ expect(response). to redirect_to(edit_admin_outgoing_message_path(outgoing)) end - end context 'when the message is the initial outgoing message' do - it 'sets is_initial_message to true' do outgoing = FactoryBot.create(:initial_request) delete :destroy, params: { id: outgoing.id } @@ -143,11 +132,9 @@ delete :destroy, params: { id: outgoing.id } expect(assigns[:outgoing_message]).to be_persisted end - end context 'when the message is not initial outgoing message' do - it 'sets is_initial_message to false' do delete :destroy, params: { id: outgoing.id } expect(assigns[:is_initial_message]).to eq(false) @@ -157,7 +144,6 @@ delete :destroy, params: { id: outgoing.id } expect(assigns[:outgoing_message]).to_not be_persisted end - end context 'if the request is embargoed', feature: :alaveteli_pro do @@ -185,7 +171,6 @@ end describe 'PUT #update' do - before { sign_in(admin_user) } let(:info_request) { FactoryBot.create(:info_request) } @@ -264,7 +249,6 @@ def make_request(params = default_params) end context 'if the outgoing message saves correctly' do - it 'should redirect to the admin info request view' do make_request expect(response).to redirect_to admin_request_url(info_request) @@ -274,11 +258,9 @@ def make_request(params = default_params) make_request expect(flash[:notice]).to eq('Outgoing message successfully updated.') end - end context 'if the incoming message is not valid' do - it 'should render the edit template' do make_request({ id: outgoing.id, outgoing_message: { prominence: 'fantastic', @@ -286,7 +268,6 @@ def make_request(params = default_params) body: 'Some information please' } }) expect(response).to render_template("edit") end - end context 'if the request is embargoed', feature: :alaveteli_pro do @@ -376,5 +357,4 @@ def make_request(params = default_params) end end end - end diff --git a/spec/controllers/admin_public_body_categories_controller_spec.rb b/spec/controllers/admin_public_body_categories_controller_spec.rb index 3af79ee4af..0662563450 100644 --- a/spec/controllers/admin_public_body_categories_controller_spec.rb +++ b/spec/controllers/admin_public_body_categories_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminPublicBodyCategoriesController do - describe 'GET index' do - it 'responds successfully' do get :index expect(response).to be_successful @@ -36,7 +34,6 @@ PublicBodyCategoryLink.create!(public_body_heading_id: heading.id, public_body_category_id: with_heading.id) - get :index expect(assigns(:without_heading)).to eq([without_heading]) end @@ -45,11 +42,9 @@ get :index expect(response).to render_template('index') end - end describe 'GET new' do - it 'responds successfully' do get :new expect(response).to be_successful @@ -79,13 +74,10 @@ get :new expect(response).to render_template('new') end - end describe 'POST create' do - context 'on success' do - before(:each) do PublicBodyCategory.destroy_all @params = { category_tag: 'new_test_category', @@ -145,11 +137,9 @@ post :create, params: { public_body_category: @params } expect(response).to redirect_to(admin_categories_path) end - end context 'on success for multiple locales' do - before(:each) do PublicBodyCategory.destroy_all @params = { category_tag: 'new_test_category', @@ -188,11 +178,9 @@ expect(category.title).to eq('Mi Nuevo Category') end end - end context 'on failure' do - it 'renders the form if creating the record was unsuccessful' do post :create, params: { public_body_category: { title: '' } } expect(response).to render_template('new') @@ -206,11 +194,9 @@ } expect(assigns(:public_body_category).title).to eq('Need a description') end - end context 'on failure for multiple locales' do - before(:each) do @params = { category_tag: 'new_test_category', translations_attributes: { @@ -235,13 +221,10 @@ expect(assigns(:public_body_category).title).to eq('Mi Nuevo Category') end end - end - end describe 'GET edit' do - before do @category = FactoryBot.create(:public_body_category) AlaveteliLocalization.with_locale('es') do @@ -285,11 +268,9 @@ get :edit, params: { id: @category.id } expect(response).to render_template('edit') end - end describe 'PUT update' do - before do @heading = FactoryBot.create(:public_body_heading) @category = FactoryBot.create(:public_body_category) @@ -366,7 +347,6 @@ end context 'when the category has associated bodies' do - it 'does not save edits to category_tag' do body = FactoryBot.create(:public_body, tag_string: @tag) @@ -402,11 +382,9 @@ expect(response).to render_template('edit') end - end context 'on success' do - before(:each) do @params = { id: @category.id, public_body_category: { @@ -460,11 +438,9 @@ PublicBodyCategory.find(@category.id).translations.map(&:locale) ).to include(:en_GB) end - end context 'on success for multiple locales' do - it "saves edits to a public body category in another locale" do expect(@category.title(:es)).to eq('Los category') post :update, params: { @@ -615,11 +591,9 @@ expect(response).to redirect_to(edit_admin_category_path(@category)) end - end context 'on failure' do - it 'renders the form if creating the record was unsuccessful' do post :update, params: { id: @category.id, @@ -653,11 +627,9 @@ } expect(assigns(:public_body_category).title).to eq('Need a description') end - end context 'on failure for multiple locales' do - before(:each) do @params = { category_tag: 'new_test_category', translations_attributes: { @@ -690,13 +662,10 @@ expect(assigns(:public_body_category).title).to eq('Mi Nuevo Category') end end - end - end describe 'DELETE destroy' do - it 'destroys empty public body categories' do PublicBodyCategory.destroy_all @@ -730,6 +699,5 @@ post :destroy, params: { id: category.id } expect(response).to redirect_to(admin_categories_path) end - end end diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index ffaa8e633e..427a674005 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminPublicBodyController do - describe 'GET #index' do - it "returns successfully" do get :index expect(response).to be_successful @@ -18,7 +16,6 @@ get :index, params: { query: "humpa", locale: "es" } expect(assigns[:public_bodies]).to eq([ public_bodies(:humpadink_public_body) ]) end - end describe 'GET #show' do @@ -59,7 +56,6 @@ end context 'when pro is enabled' do - it 'does not include embargoed requests if the current user is not a pro admin user' do with_feature_enabled(:alaveteli_pro) do @@ -70,7 +66,6 @@ end end - it 'includes embargoed requests if the current user is a pro admin user' do with_feature_enabled(:alaveteli_pro) do @@ -81,11 +76,9 @@ end end end - end describe 'GET #new' do - it 'responds successfully' do get :new expect(response).to be_successful @@ -127,15 +120,11 @@ get :new, params: { change_request_id: change_request.id } expect(assigns[:change_request_user_response]).to match("Thanks for your suggestion to add A New Body") end - end - end describe "POST #create" do - context 'on success' do - before(:each) do @params = { public_body: { name: 'New Quango', short_name: 'nq', @@ -171,11 +160,9 @@ post :create, params: @params expect(response).to redirect_to(admin_body_path(assigns(:public_body))) end - end context 'on success for multiple locales' do - before(:each) do @params = { public_body: { name: 'New Quango', short_name: 'nq', @@ -220,11 +207,9 @@ expect(body.first_letter).to eq('L') end end - end context 'on failure' do - it 'renders the form if creating the record was unsuccessful' do post :create, params: { public_body: { @@ -245,11 +230,9 @@ } expect(assigns(:public_body).request_email).to eq('newquango@localhost') end - end context 'on failure for multiple locales' do - before(:each) do @params = { public_body: { name: '', request_email: 'newquango@localhost', @@ -273,11 +256,9 @@ expect(assigns(:public_body).name).to eq('Los Quango') end end - end context 'when the body is being created as a result of a change request' do - before do @change_request = FactoryBot.create(:add_body_request) post :create, @@ -307,13 +288,10 @@ it 'should mark the change request as closed' do expect(PublicBodyChangeRequest.find(@change_request.id).is_open).to be false end - end - end describe "GET #edit" do - before do @body = FactoryBot.create(:public_body) AlaveteliLocalization.with_locale('es') do @@ -376,11 +354,9 @@ expect(assigns[:change_request_user_response]).to match("Thanks for your suggestion to update the email address") end end - end describe "POST #update" do - before do @body = FactoryBot.create(:public_body) AlaveteliLocalization.with_locale('es') do @@ -407,7 +383,6 @@ end context 'on success' do - it 'saves edits to a public body heading' do post :update, params: @params body = PublicBody.find(@body.id) @@ -423,11 +398,9 @@ post :update, params: @params expect(response).to redirect_to(admin_body_path(@body)) end - end context 'on success for multiple locales' do - it 'saves edits to a public body heading in another locale' do expect(@body.name(:es)).to eq('Los Quango') post :update, params: { @@ -549,11 +522,9 @@ expect(body.name).to eq('Example Public Body FR') end end - end context 'on failure' do - it 'renders the form if creating the record was unsuccessful' do post :update, params: { id: @body.id, @@ -576,11 +547,9 @@ } expect(assigns(:public_body).request_email).to eq('updated@localhost') end - end context 'on failure for multiple locales' do - before(:each) do @params = { id: @body.id, public_body: { name: '', @@ -603,11 +572,9 @@ expect(assigns(:public_body).name).to eq('Mi Nuevo Body') end end - end context 'when the body is being updated as a result of a change request' do - before do @change_request = FactoryBot.create(:update_body_request) post :update, params: { @@ -636,12 +603,10 @@ it 'should mark the change request as closed' do expect(PublicBodyChangeRequest.find(@change_request.id).is_open).to be false end - end end describe "POST #destroy" do - it "does not destroy a public body that has associated requests" do id = public_bodies(:humpadink_public_body).id n = PublicBody.count @@ -656,12 +621,9 @@ expect(response).to redirect_to admin_bodies_path expect(PublicBody.count).to eq(n - 1) end - end - describe "POST #mass_tag" do - it "mass assigns tags" do condition = "public_body_translations.locale = ?" n = PublicBody.joins(:translations).where([condition, "en"]).count @@ -691,18 +653,14 @@ end describe "GET #import_csv" do - describe 'when handling a GET request' do - it 'should get the page successfully' do get :import_csv expect(response).to be_successful end - end describe 'when handling a POST request' do - before do allow(PublicBody).to receive(:import_csv).and_return([[],[]]) @file_object = fixture_file_upload('fake-authority-type.csv') @@ -714,7 +672,6 @@ end describe 'if there is a csv file param' do - it 'should assign the original filename to the view' do post :import_csv, params: { csv_file: @file_object, @@ -722,11 +679,9 @@ } expect(assigns[:original_csv_file]).to eq('fake-authority-type.csv') end - end describe 'if there is no csv file param, but there are temporary_csv_file and original_csv_file params' do - it 'should try and get the file contents from a temporary file whose name is passed as a param' do expect(@controller).to receive(:retrieve_csv_data).with('csv_upload-2046-12-31-394') post :import_csv, @@ -766,13 +721,11 @@ temporary_filename = assigns[:temporary_csv_file] expect(temporary_filename).to match(/csv_upload-#{Time.zone.now.strftime("%Y%m%d")}-\d{1,5}/) end - end end end describe "when administering public bodies and paying attention to authentication" do - before do config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = false @@ -873,7 +826,6 @@ def setup_emergency_credentials(username, password) end describe 'when asked for the admin current user' do - it 'returns the emergency account name for someone who logged in with the emergency account' do setup_emergency_credentials('biz', 'fuz') basic_auth_login(@request, "biz", "fuz") @@ -897,7 +849,6 @@ def setup_emergency_credentials(username, password) post :show, params: { id: public_bodies(:humpadink_public_body).id } expect(controller.send(:admin_current_user)).to eq("i_am_admin") end - end end end diff --git a/spec/controllers/admin_public_body_headings_controller_spec.rb b/spec/controllers/admin_public_body_headings_controller_spec.rb index 4411e124b2..4758065b31 100644 --- a/spec/controllers/admin_public_body_headings_controller_spec.rb +++ b/spec/controllers/admin_public_body_headings_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminPublicBodyHeadingsController do - describe 'GET new' do - it 'responds successfully' do get :new expect(response).to be_successful @@ -28,13 +26,10 @@ get :new expect(response).to render_template('new') end - end describe 'POST create' do - context 'on success' do - before(:each) do PublicBodyHeading.destroy_all @params = { translations_attributes: { @@ -73,11 +68,9 @@ post :create, params: { public_body_heading: @params } expect(response).to redirect_to(admin_categories_path) end - end context 'on success for multiple locales' do - before(:each) do PublicBodyHeading.destroy_all @params = { translations_attributes: { @@ -113,11 +106,9 @@ expect(heading.name).to eq('Mi Nuevo Heading') end end - end context 'on failure' do - it 'renders the form if creating the record was unsuccessful' do post :create, params: { public_body_heading: { name: '' } } expect(response).to render_template('new') @@ -130,11 +121,9 @@ } expect(assigns(:public_body_heading).name).to eq('Need a description') end - end context 'on failure for multiple locales' do - before(:each) do @params = { translations_attributes: { 'en' => { locale: 'en', @@ -156,13 +145,10 @@ expect(assigns(:public_body_heading).name).to eq('Mi Nuevo Heading') end end - end - end describe 'GET edit' do - before do @heading = FactoryBot.create(:public_body_heading) AlaveteliLocalization.with_locale('es') do @@ -190,11 +176,9 @@ get :edit, params: { id: @heading.id } expect(response).to render_template('edit') end - end describe 'PUT update' do - before do @heading = FactoryBot.create(:public_body_heading) AlaveteliLocalization.with_locale('es') do @@ -220,7 +204,6 @@ end context 'on success' do - before(:each) do @params = { id: @heading.id, public_body_heading: { @@ -261,11 +244,9 @@ post :update, params: @params expect(response).to redirect_to(edit_admin_heading_path(@heading)) end - end context 'on success for multiple locales' do - it 'saves edits to a public body heading in another locale' do expect(@heading.name(:es)).to eq('Los heading') post :update, params: { @@ -405,11 +386,9 @@ expect(response).to redirect_to(edit_admin_heading_path(@heading)) end - end context 'on failure' do - it 'renders the form if creating the record was unsuccessful' do post :update, params: { id: @heading.id, @@ -441,11 +420,9 @@ } expect(assigns(:public_body_heading).name).to eq('Need a description') end - end context 'on failure for multiple locales' do - before(:each) do @params = { translations_attributes: { 'en' => { id: @heading.translation_for(:en).id, @@ -475,13 +452,10 @@ expect(assigns(:public_body_heading).name).to eq('Mi Nuevo Heading') end end - end - end describe 'DELETE destroy' do - it 'destroys the public body heading' do PublicBodyHeading.destroy_all @@ -519,11 +493,9 @@ post :destroy, params: { id: heading.id } expect(response).to redirect_to(admin_categories_path) end - end context 'when reordering public body headings' do - render_views before do @@ -537,7 +509,6 @@ def make_request(params=@default_params) end context 'when handling valid input' do - it 'should reorder headings according to their position in the submitted params' do make_request expect(PublicBodyHeading.find(@second.id).display_order).to eq(0) @@ -551,7 +522,6 @@ def make_request(params=@default_params) end context 'when handling invalid input' do - before do @params = { headings: [@second.id, @first.id, @second.id + 1] } end @@ -567,12 +537,10 @@ def make_request(params=@default_params) expect(PublicBodyHeading.find(@first.id).display_order).to eq(0) expect(PublicBodyHeading.find(@second.id).display_order).to eq(1) end - end end context 'when reordering public body categories' do - render_views before do @@ -598,10 +566,8 @@ def make_request(params=@default_params) end context 'when handling valid input' do - it 'should reorder categories for the heading according to their position \ in the submitted params' do - expect(@heading.public_body_categories).to eq(@old_order) make_request expect(@heading.public_body_categories.reload).to eq(@new_order) @@ -614,7 +580,6 @@ def make_request(params=@default_params) end context 'when handling invalid input' do - before do @new_category = FactoryBot.create(:public_body_category) @params = @default_params.merge(categories: [@second_category.id, @@ -633,6 +598,5 @@ def make_request(params=@default_params) expect(@heading.public_body_categories.reload).to eq(@old_order) end end - end end diff --git a/spec/controllers/admin_raw_email_controller_spec.rb b/spec/controllers/admin_raw_email_controller_spec.rb index 3bf0025805..4f760f73ff 100644 --- a/spec/controllers/admin_raw_email_controller_spec.rb +++ b/spec/controllers/admin_raw_email_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminRawEmailController do - describe 'GET show' do - let(:raw_email) { FactoryBot.create(:incoming_message).raw_email } let(:admin_user) { FactoryBot.create(:admin_user) } @@ -90,9 +88,7 @@ get :show, params: { id: incoming_message.raw_email.id } expect(assigns[:rejected_reason]).to eq 'unknown reason' end - end - end describe 'text version' do diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 8cf634800f..fc1db9d8bf 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -26,9 +26,7 @@ expect(assigns[:info_requests].include?(info_request)).to be false end - context 'when pro is enabled' do - it 'does not include embargoed requests if the current user is not a pro admin user' do with_feature_enabled(:alaveteli_pro) do @@ -89,9 +87,7 @@ end end end - end - end describe 'GET #show' do @@ -168,7 +164,6 @@ end end end - end describe 'PUT #update' do @@ -323,7 +318,6 @@ end context 'when hiding an external request' do - before do @info_request = FactoryBot.create(:external_request) allow(InfoRequest).to receive(:find).with(@info_request.id). @@ -393,5 +387,4 @@ def make_request(params=@default_params) end end end - end diff --git a/spec/controllers/admin_spam_addresses_controller_spec.rb b/spec/controllers/admin_spam_addresses_controller_spec.rb index b26644c616..8ee4880b46 100644 --- a/spec/controllers/admin_spam_addresses_controller_spec.rb +++ b/spec/controllers/admin_spam_addresses_controller_spec.rb @@ -5,7 +5,6 @@ before { basic_auth_login @request } describe 'GET index' do - it 'lists the spam addresses' do 3.times { FactoryBot.create(:spam_address) } get :index @@ -21,11 +20,9 @@ get :index expect(response).to render_template('index') end - end describe 'POST create' do - let(:spam_params) { FactoryBot.attributes_for(:spam_address) } it 'creates a new spam address with the given parameters' do @@ -59,11 +56,9 @@ post :create, params: { spam_address: spam_params } expect(assigns(:spam_addresses)).to eq(SpamAddress.all) end - end describe 'DELETE destroy' do - before(:each) do @spam = FactoryBot.create(:spam_address) delete :destroy, params: { id: @spam.id } @@ -85,7 +80,5 @@ it 'redirects to the index action' do expect(response).to redirect_to(admin_spam_addresses_path) end - end - end diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index 875c74035c..8e104f49e2 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminTrackController do - describe 'GET index' do - it "shows the index page" do get :index expect(response).to render_template("index") @@ -16,8 +14,6 @@ post :destroy, params: { id: track.id } expect(TrackThing.where(id: track.id)).to be_empty end - end - end end diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index ed2e47d478..968b8ee696 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AdminUserController do - describe 'GET index' do - it 'renders the index template' do get :index expect(response).to render_template('index') @@ -133,7 +131,6 @@ get :index, params: { roles: %w[admin pro] } expect(assigns[:admin_users]).to eq([admin_user, pro_user]) end - end describe 'GET #show' do @@ -162,7 +159,6 @@ end context 'when pro is enabled' do - it 'does not include embargoed requests if the current user is not a pro admin user' do with_feature_enabled(:alaveteli_pro) do @@ -182,7 +178,6 @@ expect(assigns[:info_requests].include?(info_request)).to be true end end - end it "assigns the user's comments to the view" do @@ -204,7 +199,6 @@ end context 'when pro is enabled' do - it 'does not include comments on embargoed requests if the current user is not a pro admin user' do with_feature_enabled(:alaveteli_pro) do @@ -228,13 +222,10 @@ expect(assigns[:comments]).to eq([comment]) end end - end - end describe "POST #update" do - let(:admin_user) { FactoryBot.create(:admin_user) } before do @@ -354,11 +345,9 @@ user = User.find(user.id) expect(user.is_pro?).to be false end - end describe 'POST modify_comment_visibility' do - before(:each) do @user = FactoryBot.create(:user) request.env["HTTP_REFERER"] = admin_user_path(@user) diff --git a/spec/controllers/admin_users_account_anonymising_controller_spec.rb b/spec/controllers/admin_users_account_anonymising_controller_spec.rb index 02e8afe060..62a9eab7d6 100644 --- a/spec/controllers/admin_users_account_anonymising_controller_spec.rb +++ b/spec/controllers/admin_users_account_anonymising_controller_spec.rb @@ -26,7 +26,6 @@ ) end end - end context 'with valid params for anonymising' do @@ -70,7 +69,6 @@ def create ) end end - end context 'on a closed account with info requests' do @@ -88,6 +86,5 @@ def create expect(flash[:notice]).to eq('The user was anonymised.') end end - end end diff --git a/spec/controllers/admin_users_account_closing_controller_spec.rb b/spec/controllers/admin_users_account_closing_controller_spec.rb index 062ed89769..e18acc3f03 100644 --- a/spec/controllers/admin_users_account_closing_controller_spec.rb +++ b/spec/controllers/admin_users_account_closing_controller_spec.rb @@ -47,7 +47,5 @@ def create }.to raise_error(ActiveRecord::RecordNotFound) end end - end - end diff --git a/spec/controllers/admin_users_account_erasing_controller_spec.rb b/spec/controllers/admin_users_account_erasing_controller_spec.rb index d3bfe2752c..a72cbda78e 100644 --- a/spec/controllers/admin_users_account_erasing_controller_spec.rb +++ b/spec/controllers/admin_users_account_erasing_controller_spec.rb @@ -20,12 +20,10 @@ end context 'on an open account' do - it 'tells the admin that the user was not erased' do expect(flash[:error]).to eq('Something went wrong. The user could not be erased.') end end - end context 'with valid params for erasing' do @@ -66,6 +64,5 @@ def create expect(flash[:notice]).to eq('The user was erased.') end end - end end diff --git a/spec/controllers/admin_users_account_suspensions_controller_spec.rb b/spec/controllers/admin_users_account_suspensions_controller_spec.rb index 91cca34017..be198bcb20 100644 --- a/spec/controllers/admin_users_account_suspensions_controller_spec.rb +++ b/spec/controllers/admin_users_account_suspensions_controller_spec.rb @@ -48,7 +48,5 @@ expect(assigns[:suspension_reason]).to eq(default) end end - end - end diff --git a/spec/controllers/admin_users_sessions_controller_spec.rb b/spec/controllers/admin_users_sessions_controller_spec.rb index ca5dced3cf..4a48ea785c 100644 --- a/spec/controllers/admin_users_sessions_controller_spec.rb +++ b/spec/controllers/admin_users_sessions_controller_spec.rb @@ -5,7 +5,6 @@ let(:target_user) { FactoryBot.create(:user) } describe 'POST #create' do - before do sign_in admin_user end @@ -50,7 +49,6 @@ post :create, params: { id: target_user.id } expect(target_user.reload.email_confirmed).to eq(true) end - end context 'if the user cannot log in as the user' do @@ -70,13 +68,10 @@ to eq "You don't have permission to log in as #{ target_user.name }" end end - end - end describe 'DELETE #destroy' do - before do sign_in target_user end @@ -105,7 +100,5 @@ delete :destroy, session: { admin_id: admin_user.id } expect(response).to redirect_to(admin_user_path(target_user)) end - end - end diff --git a/spec/controllers/alaveteli_pro/account_request_controller_spec.rb b/spec/controllers/alaveteli_pro/account_request_controller_spec.rb index d6899bce73..3460959c1b 100644 --- a/spec/controllers/alaveteli_pro/account_request_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/account_request_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::AccountRequestController do - describe "#index" do it "renders index" do get :index @@ -31,7 +30,6 @@ end context 'if the account request is valid' do - it 'shows a notice' do post :create, params: { account_request: account_request_params } expect(flash[:notice]).not_to be nil @@ -48,42 +46,33 @@ mail = ActionMailer::Base.deliveries.first expect(mail.to.first).to eq AlaveteliConfiguration.pro_contact_email end - end context 'if the account request is not valid' do - it 'renders the index template' do post :create, params: { account_request: {} } expect(response).to render_template('index') end - end context 'when pro_pricing is enabled', feature: :pro_pricing do - it 'redirects to the pro plans' do post :create expect(response).to redirect_to pro_plans_path end - end context 'when pro_self_serve is enabled', feature: :pro_self_serve do - context 'when current user is signed out' do - it 'redirects to sign in' do post :create expect(response).to redirect_to( signin_path(token: get_last_post_redirect.token) ) end - end context 'when current user is signed in' do - let(:user) { FactoryBot.create(:user) } before do @@ -110,11 +99,7 @@ post :create expect(response).to redirect_to(alaveteli_pro_dashboard_path) end - end - end - end - end diff --git a/spec/controllers/alaveteli_pro/batch_request_authority_searches_controller_spec.rb b/spec/controllers/alaveteli_pro/batch_request_authority_searches_controller_spec.rb index 8fb5b03bf3..87c53d47db 100644 --- a/spec/controllers/alaveteli_pro/batch_request_authority_searches_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/batch_request_authority_searches_controller_spec.rb @@ -132,7 +132,6 @@ end describe '#new' do - before do sign_in pro_user end @@ -144,5 +143,4 @@ ) end end - end diff --git a/spec/controllers/alaveteli_pro/dashboard_controller_spec.rb b/spec/controllers/alaveteli_pro/dashboard_controller_spec.rb index 121f1a10b2..0d4e5407d2 100644 --- a/spec/controllers/alaveteli_pro/dashboard_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/dashboard_controller_spec.rb @@ -28,7 +28,6 @@ end context 'if a page param is passed' do - it 'assigns @page a numerical page param' do get :index, params: { page: 2 } expect(assigns[:page]).to eq 2 @@ -49,6 +48,5 @@ get :index expect(assigns[:activity_list]).to be_a AlaveteliPro::ActivityList::List end - end end diff --git a/spec/controllers/alaveteli_pro/embargo_controller_spec.rb b/spec/controllers/alaveteli_pro/embargo_controller_spec.rb index 1c125bb1dc..60cf5863b3 100644 --- a/spec/controllers/alaveteli_pro/embargo_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/embargo_controller_spec.rb @@ -15,7 +15,6 @@ let(:info_request) { FactoryBot.create(:info_request, user: pro_user) } context 'when the user is allowed to add an embargo' do - context 'because they are the owner' do before do with_feature_enabled(:alaveteli_pro) do @@ -36,7 +35,6 @@ it 'sets the expected duration' do expect(info_request.reload.embargo.embargo_duration).to eq('3_months') end - end context 'because they are a pro admin' do @@ -59,9 +57,7 @@ it 'sets the expected duration' do expect(info_request.reload.embargo.embargo_duration).to eq('3_months') end - end - end context "when the user is not allowed to update the embargo" do @@ -80,7 +76,6 @@ end end.to raise_error(CanCan::AccessDenied) end - end context "when the info_request is part of a batch request" do @@ -104,9 +99,7 @@ end end.to raise_error(CanCan::AccessDenied) end - end - end describe "#destroy" do @@ -130,7 +123,6 @@ end context 'they no longer have pro status' do - before do pro_user.remove_role(:pro) end @@ -139,9 +131,7 @@ expect { AlaveteliPro::Embargo.find(embargo.id) }. to raise_error(ActiveRecord::RecordNotFound) end - end - end context "because they are an admin" do @@ -162,7 +152,6 @@ expect(info_request.reload.info_request_events.last.event_type). to eq 'expire_embargo' end - end end diff --git a/spec/controllers/alaveteli_pro/embargo_extensions_controller_spec.rb b/spec/controllers/alaveteli_pro/embargo_extensions_controller_spec.rb index 1095c8f7d8..04f0c95346 100644 --- a/spec/controllers/alaveteli_pro/embargo_extensions_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/embargo_extensions_controller_spec.rb @@ -13,9 +13,7 @@ let(:embargo_expiry) { embargo.publish_at } describe '#create' do - context 'when the user is allowed to update the embargo' do - context 'because they are the owner' do before do with_feature_enabled(:alaveteli_pro) do @@ -45,7 +43,6 @@ to redirect_to show_alaveteli_pro_request_path( url_title: info_request.url_title) end - end context 'because they are a pro admin' do @@ -77,9 +74,7 @@ to redirect_to show_alaveteli_pro_request_path( url_title: info_request.url_title) end - end - end context 'when the user does not own the embargo' do @@ -112,9 +107,7 @@ expect(response).to redirect_to frontpage_path end end - end - end context 'when the embargo is not near expiry' do @@ -146,7 +139,6 @@ end end.to raise_error(ApplicationController::PermissionDenied) end - end context 'when the info_request is part of a batch request' do @@ -188,7 +180,6 @@ expect(flash[:error]).to eq(msg) end end - end describe '#create_batch' do diff --git a/spec/controllers/alaveteli_pro/info_request_batches_controller_spec.rb b/spec/controllers/alaveteli_pro/info_request_batches_controller_spec.rb index f6a5f95f09..369d285ed9 100644 --- a/spec/controllers/alaveteli_pro/info_request_batches_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/info_request_batches_controller_spec.rb @@ -195,7 +195,6 @@ end end - describe "#create" do let(:params) { { draft_id: draft.id } } let(:action) { post :create, params: params } diff --git a/spec/controllers/alaveteli_pro/info_requests_controller_spec.rb b/spec/controllers/alaveteli_pro/info_requests_controller_spec.rb index 8f7c8d1556..c1d664433f 100644 --- a/spec/controllers/alaveteli_pro/info_requests_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/info_requests_controller_spec.rb @@ -27,7 +27,6 @@ end context 'when no filters, searches or sort params are passed' do - it "assigns the user's request summaries" do get :index expect(assigns[:request_summaries].size).to eq 2 @@ -37,7 +36,6 @@ end context 'when a search is passed' do - it 'applies the search' do get :index, params: { alaveteli_pro_request_filter: { search: 'foo' @@ -45,9 +43,7 @@ } expect(assigns[:request_summaries].size).to eq 1 end - end - end describe "#preview" do diff --git a/spec/controllers/alaveteli_pro/pages_controller_spec.rb b/spec/controllers/alaveteli_pro/pages_controller_spec.rb index b963eab63b..1a113d1797 100644 --- a/spec/controllers/alaveteli_pro/pages_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/pages_controller_spec.rb @@ -1,11 +1,8 @@ require 'spec_helper' RSpec.describe AlaveteliPro::PagesController do - describe 'GET #show' do - context 'when asked for an existing template' do - before do get :show, params: { id: 'legal' } end @@ -24,7 +21,6 @@ end context 'when asked for a template that does not exist' do - it 'raises ActiveRecord::RecordNotFound' do expect { get :show, params: { id: 'nope' } diff --git a/spec/controllers/alaveteli_pro/payment_methods_controller_spec.rb b/spec/controllers/alaveteli_pro/payment_methods_controller_spec.rb index ff00f0db3e..d8c3bf88d1 100644 --- a/spec/controllers/alaveteli_pro/payment_methods_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/payment_methods_controller_spec.rb @@ -22,9 +22,7 @@ end describe 'POST #update' do - context 'without a signed-in user' do - before do post :update end @@ -33,7 +31,6 @@ expect(response). to redirect_to(signin_path(token: PostRedirect.last.token)) end - end context 'with a signed-in user' do @@ -69,7 +66,6 @@ end context 'with a successful transaction' do - before do post :update, params: { 'stripe_token' => new_token } end @@ -96,11 +92,9 @@ it 'shows a message to confirm the update' do expect(flash[:notice]).to eq('Your payment details have been updated') end - end context 'when the card is declined' do - before do StripeMock.prepare_card_error(:card_declined, :update_customer) @@ -116,11 +110,9 @@ retrieve(user.pro_account.stripe_customer_id) expect(reloaded.sources.data.map(&:id)).to match_array(card_ids) end - end context 'when we are rate limited' do - before do error = Stripe::RateLimitError.new StripeMock.prepare_error(error, :update_customer) @@ -135,11 +127,9 @@ it 'renders an error message' do expect(flash[:error]).to match(/There was a problem/) end - end context 'when Stripe receives an invalid request' do - before do error = Stripe::InvalidRequestError.new('message', 'param') StripeMock.prepare_error(error, :update_customer) @@ -154,11 +144,9 @@ it 'renders an error message' do expect(flash[:error]).to match(/There was a problem/) end - end context 'when we cannot authenticate with Stripe' do - before do error = Stripe::AuthenticationError.new StripeMock.prepare_error(error, :update_customer) @@ -173,11 +161,9 @@ it 'renders an error message' do expect(flash[:error]).to match(/There was a problem/) end - end context 'when we cannot connect to Stripe' do - before do error = Stripe::APIConnectionError.new StripeMock.prepare_error(error, :update_customer) @@ -192,11 +178,9 @@ it 'renders an error message' do expect(flash[:error]).to match(/There was a problem/) end - end context 'when Stripe returns a generic error' do - before do error = Stripe::StripeError.new StripeMock.prepare_error(error, :update_customer) @@ -211,11 +195,7 @@ it 'renders an error message' do expect(flash[:error]).to match(/There was a problem/) end - end - end - end - end diff --git a/spec/controllers/alaveteli_pro/plans_controller_spec.rb b/spec/controllers/alaveteli_pro/plans_controller_spec.rb index 3da26da3b0..16bddf17e3 100644 --- a/spec/controllers/alaveteli_pro/plans_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/plans_controller_spec.rb @@ -20,7 +20,6 @@ end describe 'GET #index' do - before do get :index end @@ -47,9 +46,7 @@ end describe 'GET #show' do - context 'without a signed-in user' do - before do get :show, params: { id: 'pro' } end @@ -62,7 +59,6 @@ it 'sets in_pro_area' do expect(assigns(:in_pro_area)).to be true end - end context 'with a signed-in user' do @@ -73,7 +69,6 @@ end context 'with a valid plan' do - before do get :show, params: { id: 'pro' } end @@ -89,11 +84,9 @@ it 'returns http success' do expect(response).to be_successful end - end context 'with a Stripe namespace' do - before do allow(AlaveteliConfiguration).to receive(:stripe_namespace). and_return('alaveteli') @@ -111,11 +104,9 @@ it 'returns http success' do expect(response).to be_successful end - end context 'with an existing subscription' do - before do sign_in user customer = @@ -138,7 +129,6 @@ end context 'with an existing customer id but no active subscriptions' do - before do sign_in user customer = @@ -160,21 +150,15 @@ it 'returns http success' do expect(response).to be_successful end - end context 'with an invalid plan' do - it 'returns ActiveRecord::RecordNotFound' do expect { get :show, params: { id: 'invalid-123' } }.to raise_error(ActiveRecord::RecordNotFound) end - end - end - end - end diff --git a/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb b/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb index 6dfd96e264..affa5bc55c 100644 --- a/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/public_bodies_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::PublicBodiesController do - describe "#index" do let!(:pro_user) { FactoryBot.create(:pro_user) } let!(:body) { FactoryBot.create(:public_body, name: 'example') } diff --git a/spec/controllers/alaveteli_pro/stripe_webhooks_controller_spec.rb b/spec/controllers/alaveteli_pro/stripe_webhooks_controller_spec.rb index e064e943ac..3c3078b801 100644 --- a/spec/controllers/alaveteli_pro/stripe_webhooks_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/stripe_webhooks_controller_spec.rb @@ -2,9 +2,7 @@ require 'stripe_mock' RSpec.describe AlaveteliPro::StripeWebhooksController, feature: [:alaveteli_pro, :pro_pricing] do - describe '#receive' do - let(:config_secret) { 'whsec_secret' } let(:signing_secret) { config_secret } let(:stripe_helper) { StripeMock.create_test_helper } @@ -82,7 +80,6 @@ def send_request end context 'the secret is not in the request' do - it 'returns a 401 Unauthorized response' do post :receive, params: payload expect(response.status).to eq(401) @@ -102,11 +99,9 @@ def send_request to eq('{"error":"Unable to extract timestamp and signatures ' \ 'from header"}') end - end context 'the secret_key does not match' do - let(:signing_secret) { 'whsec_fake' } before do @@ -129,11 +124,9 @@ def send_request to eq('{"error":"No signatures found matching the expected ' \ 'signature for payload"}') end - end context 'receiving an unhandled notification type' do - before do stripe_event.type = 'custom.unhandle_event' end @@ -141,11 +134,9 @@ def send_request it 'stores unhandled webhook' do expect { send_request }.to change(Webhook, :count).by(1) end - end context 'the timestamp is stale (possible replay attack)' do - let!(:stale_headers) do signed = signed_headers(payload: payload, signing_secret: signing_secret, @@ -167,11 +158,9 @@ def send_request mail = ActionMailer::Base.deliveries.first expect(mail.subject).to include(expected) end - end context 'the notification type is missing' do - let(:payload) do { id: '1234' } end @@ -190,18 +179,15 @@ def send_request mail = ActionMailer::Base.deliveries.first expect(mail.subject).to include(expected) end - end context 'when using namespaced plans' do - before do allow(AlaveteliConfiguration).to receive(:stripe_namespace). and_return('WDTK') end context 'the webhook does not reference our plan namespace' do - it 'returns a custom 200 response' do send_request expect(response.status).to eq(200) @@ -212,7 +198,6 @@ def send_request it 'does not store unhandled webhook' do expect { send_request }.to_not change(Webhook, :count) end - end context 'the webhook is for a matching namespaced plan' do @@ -238,11 +223,9 @@ def send_request expect(response.status).to eq(200) expect(response.body).to match('OK') end - end context 'the webhook data does not have namespaced plans' do - let(:stripe_event) do StripeMock.mock_webhook_event('invoice.payment_succeeded') end @@ -255,9 +238,7 @@ def send_request post :receive, params: payload }.not_to raise_error end - end - end describe 'a payment fails' do @@ -333,7 +314,6 @@ def send_request end describe 'a cancelled subscription is deleted at the end of the billing period' do - let!(:user) do _user = FactoryBot.create(:pro_user) _user.pro_account.stripe_customer_id = stripe_event.data.object.customer @@ -346,11 +326,9 @@ def send_request send_request expect(user.reload.is_pro?).to be false end - end describe 'updating the Stripe charge description when a payment succeeds' do - before do send_request end @@ -366,7 +344,6 @@ def send_request expect(Stripe::Charge.retrieve(charge.id).description). to eq('Alaveteli Professional: Test') end - end context 'when there is no charge for an invoice' do @@ -378,11 +355,7 @@ def send_request it 'does not attempt to update the nil charge' do expect(response.status).to eq(200) end - end - end - end - end diff --git a/spec/controllers/alaveteli_pro/subscriptions_controller_spec.rb b/spec/controllers/alaveteli_pro/subscriptions_controller_spec.rb index e0dcdd4864..4a548902a5 100644 --- a/spec/controllers/alaveteli_pro/subscriptions_controller_spec.rb +++ b/spec/controllers/alaveteli_pro/subscriptions_controller_spec.rb @@ -30,9 +30,7 @@ end describe 'POST #create' do - context 'without a signed-in user' do - before do post :create end @@ -41,7 +39,6 @@ expect(response). to redirect_to(signin_path(token: PostRedirect.last.token)) end - end context 'with a banned user' do @@ -105,13 +102,11 @@ authorise_subscription_path(assigns(:subscription).id) ) end - end # technically possible but have only managed to do so locally (and with # Safari) but just in case... context 'the form is resubmitted' do - let(:token) { stripe_helper.generate_card_token } let(:user) { FactoryBot.create(:user) } @@ -140,7 +135,6 @@ it 'redirects to the dashboard' do expect(response).to redirect_to(alaveteli_pro_dashboard_path) end - end context 'with a successful transaction' do @@ -192,7 +186,6 @@ end context 'with an existing customer but no active subscriptions' do - before do customer = Stripe::Customer.create(email: user.email, @@ -220,7 +213,6 @@ end context 'with an existing customer and an incomplete subscription' do - let(:customer) do Stripe::Customer.create( email: user.email, @@ -256,7 +248,6 @@ end context 'when the card is declined' do - before do StripeMock.prepare_card_error(:card_declined, :create_subscription) post :create, params: { @@ -277,11 +268,9 @@ it 'does not set new_pro_user in flash' do expect(flash[:new_pro_user]).to be_nil end - end context 'when we are rate limited' do - before do error = Stripe::RateLimitError.new StripeMock.prepare_error(error, :create_subscription) @@ -304,11 +293,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when Stripe receives an invalid request' do - before do error = Stripe::InvalidRequestError.new('message', 'param') StripeMock.prepare_error(error, :create_subscription) @@ -331,11 +318,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when we cannot authenticate with Stripe' do - before do error = Stripe::AuthenticationError.new StripeMock.prepare_error(error, :create_subscription) @@ -358,11 +343,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when we cannot connect to Stripe' do - before do error = Stripe::APIConnectionError.new StripeMock.prepare_error(error, :create_subscription) @@ -385,11 +368,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when Stripe returns a generic error' do - before do error = Stripe::StripeError.new StripeMock.prepare_error(error, :create_subscription) @@ -412,11 +393,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when uses invalid coupon' do - before do error = Stripe::InvalidRequestError.new('No such coupon', 'param') StripeMock.prepare_error(error, :create_subscription) @@ -439,11 +418,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when uses expired coupon' do - before do error = Stripe::InvalidRequestError.new('Coupon expired', 'param') StripeMock.prepare_error(error, :create_subscription) @@ -466,11 +443,9 @@ it 'redirects to the plan page' do expect(response).to redirect_to(plan_path('pro')) end - end context 'when invalid params are submitted' do - it 'redirects to the plan page if there is a plan' do post :create, params: { plan_id: 'pro' } expect(response).to redirect_to(plan_path('pro')) @@ -480,17 +455,12 @@ post :create expect(response).to redirect_to(pro_plans_path) end - end - end - end describe 'GET #authorise' do - context 'without a signed-in user' do - before do get :authorise, params: { id: 1 } end @@ -499,7 +469,6 @@ expect(response). to redirect_to(signin_path(token: PostRedirect.last.token)) end - end context 'with a signed-in user' do @@ -527,7 +496,6 @@ end shared_examples 'errored' do - it 'renders an error message' do authorise expect(flash[:error]).to match(/There was a problem/) @@ -539,7 +507,6 @@ end context 'when responding to JSON' do - include_context 'JSON request' it 'returns URL to the pro dashboard' do @@ -548,13 +515,10 @@ url: plan_path('pro') ) end - end - end context 'subscription not found' do - before do allow(pro_account.subscriptions).to receive(:retrieve).with('1'). and_return(nil) @@ -564,11 +528,9 @@ authorise expect(response.status).to eq 404 end - end context 'subscription require authorisation' do - before do subscription = double( :subscription, @@ -586,7 +548,6 @@ end context 'when responding to JSON' do - include_context 'JSON request' it 'should render payment intent client secret' do @@ -596,13 +557,10 @@ callback_url: authorise_subscription_path(1) ) end - end - end context 'subscription invoice open' do - before do subscription = double( :subscription, @@ -616,11 +574,9 @@ end include_examples 'errored' - end context 'subscription active' do - before do subscription = double( :subscription, @@ -655,7 +611,6 @@ end context 'when responding to JSON' do - include_context 'JSON request' it 'returns URL to the pro dashboard' do @@ -664,13 +619,10 @@ url: alaveteli_pro_dashboard_path ) end - end - end context 'when we are rate limited' do - before do error = Stripe::RateLimitError.new StripeMock.prepare_error(error, :retrieve_customer_subscription) @@ -683,11 +635,9 @@ mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Stripe::RateLimitError/) end - end context 'when Stripe receives an invalid request' do - before do error = Stripe::InvalidRequestError.new('message', 'param') StripeMock.prepare_error(error, :retrieve_customer_subscription) @@ -700,11 +650,9 @@ mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Stripe::InvalidRequestError/) end - end context 'when we cannot authenticate with Stripe' do - before do error = Stripe::AuthenticationError.new StripeMock.prepare_error(error, :retrieve_customer_subscription) @@ -717,11 +665,9 @@ mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Stripe::AuthenticationError/) end - end context 'when we cannot connect to Stripe' do - before do error = Stripe::APIConnectionError.new StripeMock.prepare_error(error, :retrieve_customer_subscription) @@ -734,11 +680,9 @@ mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Stripe::APIConnectionError/) end - end context 'when Stripe returns a generic error' do - before do error = Stripe::StripeError.new StripeMock.prepare_error(error, :retrieve_customer_subscription) @@ -751,17 +695,12 @@ mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Stripe::StripeError/) end - end - end - end describe 'GET #index' do - context 'without a signed-in user' do - before do get :index end @@ -770,11 +709,9 @@ expect(response). to redirect_to(signin_path(token: PostRedirect.last.token)) end - end context 'user has no Stripe id' do - let(:user) do user = FactoryBot.create(:pro_user) user.pro_account.update(stripe_customer_id: nil) @@ -789,11 +726,9 @@ get :index expect(response).to redirect_to(pro_plans_path) end - end context 'with a signed-in user' do - let(:user) { FactoryBot.create(:pro_user) } let!(:customer) do @@ -835,7 +770,6 @@ end context 'if a PRO_REFERRAL_COUPON is blank' do - it 'does not assign the discount code' do get :index expect(assigns[:discount_code]).to be_nil @@ -845,11 +779,9 @@ get :index expect(assigns[:discount_terms]).to be_nil end - end context 'if a PRO_REFERRAL_COUPON is set' do - before do allow(AlaveteliConfiguration). to receive(:pro_referral_coupon).and_return('PROREFERRAL') @@ -883,17 +815,12 @@ get :index expect(assigns[:discount_code]).to be_nil end - end - end - end describe 'DELETE #destroy' do - context 'without a signed-in user' do - before do delete :destroy, params: { id: '123' } end @@ -902,11 +829,9 @@ expect(response). to redirect_to(signin_path(token: PostRedirect.last.token)) end - end context 'user has no Stripe id' do - let(:user) do FactoryBot.create(:pro_user) end @@ -921,11 +846,9 @@ delete :destroy, params: { id: '123' } }.to raise_error ActiveRecord::RecordNotFound end - end context 'with a signed-in user' do - let(:user) { FactoryBot.create(:pro_user) } let(:plan) { stripe_helper.create_plan(id: 'test', product: product.id) } @@ -967,7 +890,6 @@ end context 'when destroying a subscription belonging to another user' do - let(:other_subscription) do customer = Stripe::Customer.create({ email: 'test@example.org', @@ -985,7 +907,6 @@ end context 'when we are rate limited' do - before do error = Stripe::RateLimitError.new StripeMock.prepare_error(error, :cancel_subscription) @@ -1004,11 +925,9 @@ it 'redirects to the subscriptions page' do expect(response).to redirect_to(subscriptions_path) end - end context 'when Stripe receives an invalid request' do - before do error = Stripe::InvalidRequestError.new('message', 'param') StripeMock.prepare_error(error, :cancel_subscription) @@ -1027,11 +946,9 @@ it 'redirects to the subscriptions page' do expect(response).to redirect_to(subscriptions_path) end - end context 'when we cannot authenticate with Stripe' do - before do error = Stripe::AuthenticationError.new StripeMock.prepare_error(error, :cancel_subscription) @@ -1050,11 +967,9 @@ it 'redirects to the subscriptions page' do expect(response).to redirect_to(subscriptions_path) end - end context 'when we cannot connect to Stripe' do - before do error = Stripe::APIConnectionError.new StripeMock.prepare_error(error, :cancel_subscription) @@ -1073,11 +988,9 @@ it 'redirects to the subscriptions page' do expect(response).to redirect_to(subscriptions_path) end - end context 'when Stripe returns a generic error' do - before do error = Stripe::StripeError.new StripeMock.prepare_error(error, :cancel_subscription) @@ -1096,20 +1009,14 @@ it 'redirects to the subscriptions page' do expect(response).to redirect_to(subscriptions_path) end - end context 'when invalid params are submitted' do - it 'redirects to the plan page if there is a plan' do delete :destroy, params: { id: 'unknown' } expect(response).to redirect_to(subscriptions_path) end - end - end - end - end diff --git a/spec/controllers/announcements_controller_spec.rb b/spec/controllers/announcements_controller_spec.rb index e9d0083ce4..54fa75dd52 100644 --- a/spec/controllers/announcements_controller_spec.rb +++ b/spec/controllers/announcements_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AnnouncementsController do - describe '#destroy' do - context 'valid announcement' do let(:announcement) { FactoryBot.create(:announcement) } @@ -21,11 +19,9 @@ delete :destroy, params: { id: announcement.id } expect(response.status).to eq 200 end - end context 'logged out' do - it 'stores announcement ID in session' do expect(session[:announcement_dismissals]).to be_nil delete :destroy, params: { id: announcement.id } @@ -37,20 +33,14 @@ delete :destroy, params: { id: announcement.id } expect(response.status).to eq 200 end - end - end context 'invalid announcement' do - it 'returns 403 status' do delete :destroy, params: { id: 'invalid' } expect(response.status).to eq 403 end - end - end - end diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 41711838e5..372074a79a 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe ApiController, "when using the API" do - describe 'checking API keys' do before do @number_of_requests = InfoRequest.count diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb index 77624b40a5..56b5974d60 100644 --- a/spec/controllers/comment_controller_spec.rb +++ b/spec/controllers/comment_controller_spec.rb @@ -221,7 +221,6 @@ end describe 'when handling a comment that looks like spam' do - let(:user) { FactoryBot.create(:user, locale: 'en', name: 'bob', @@ -230,7 +229,6 @@ let(:request) { FactoryBot.create(:info_request) } context 'when block_spam_comments? is true' do - before(:each) do allow(@controller).to receive(:block_spam_comments?).and_return(true) end @@ -298,11 +296,9 @@ } expect(response).to redirect_to show_request_path(request.url_title) end - end context 'when block_spam_comments? is false' do - before(:each) do allow(@controller).to receive(:block_spam_comments?).and_return(false) end @@ -337,15 +333,11 @@ } expect(response).to redirect_to show_request_path(request.url_title) end - end - end describe 'when commenting on an external request' do - describe 'when responding to a GET request on a successful request' do - before do @external_request = info_requests(:external_request) @external_request.described_state = 'successful' @@ -357,9 +349,7 @@ type: 'request' } expect(response).to be_successful end - end - end context 'when commenting on an embargoed request' do @@ -377,5 +367,4 @@ end end end - end diff --git a/spec/controllers/concerns/alaveteli_pro/stripe_namespace_spec.rb b/spec/controllers/concerns/alaveteli_pro/stripe_namespace_spec.rb index 909f282140..4f65320313 100644 --- a/spec/controllers/concerns/alaveteli_pro/stripe_namespace_spec.rb +++ b/spec/controllers/concerns/alaveteli_pro/stripe_namespace_spec.rb @@ -4,7 +4,6 @@ include AlaveteliPro::StripeNamespace context 'with namespace' do - before(:each) do allow(AlaveteliConfiguration).to receive(:stripe_namespace). and_return('namespace') @@ -21,11 +20,9 @@ expect(remove_stripe_namespace('namespace-string')).to eq('string') end end - end context 'without namespace' do - before(:each) do allow(AlaveteliConfiguration).to receive(:stripe_namespace). and_return('') @@ -42,7 +39,5 @@ expect(remove_stripe_namespace('string')).to eq('string') end end - end - end diff --git a/spec/controllers/concerns/hashable_params_spec.rb b/spec/controllers/concerns/hashable_params_spec.rb index 4c60da887a..c64345b3b8 100644 --- a/spec/controllers/concerns/hashable_params_spec.rb +++ b/spec/controllers/concerns/hashable_params_spec.rb @@ -40,7 +40,5 @@ expect(subject).to respond_to(:with_indifferent_access) end end - end - end diff --git a/spec/controllers/concerns/translatable_params_spec.rb b/spec/controllers/concerns/translatable_params_spec.rb index d93dfcea44..8b89f812c1 100644 --- a/spec/controllers/concerns/translatable_params_spec.rb +++ b/spec/controllers/concerns/translatable_params_spec.rb @@ -4,7 +4,6 @@ include TranslatableParams describe '#translatable_params' do - let(:keys) { { translated_keys: [ :name, :locale ], general_keys: [ :status ] } } @@ -26,21 +25,15 @@ end context 'when there are no params' do - it 'returns an empty hash' do expect(translatable_params(nil, **keys)).to eq({}) end - end - end - end RSpec.describe TranslatableParams::WhitelistedParams do - describe '#whitelist' do - let(:keys) { { translated_keys: [ :name, :locale ], general_keys: [ :status ] } } @@ -81,7 +74,5 @@ TranslatableParams::WhitelistedParams.new(**keys).whitelist(params) ).to eq(ActionController::Parameters.new(expected).permit!) end - end - end diff --git a/spec/controllers/followups_controller_spec.rb b/spec/controllers/followups_controller_spec.rb index cc7f57f455..7428984e57 100644 --- a/spec/controllers/followups_controller_spec.rb +++ b/spec/controllers/followups_controller_spec.rb @@ -9,7 +9,6 @@ let(:pro_user) { FactoryBot.create(:pro_user) } describe "GET #new" do - context "when not logged in" do it 'raises an ActiveRecord::RecordNotFound error for an embargoed request' do embargoed_request = FactoryBot.create(:embargoed_request) @@ -84,7 +83,6 @@ end context "logged in as the request owner" do - before(:each) do sign_in request_user end @@ -136,11 +134,9 @@ expect(response.body). to have_css("div#other_recipients ul li", text: "Frob") end - end context "the request is hidden" do - let(:hidden_request) do FactoryBot.create(:info_request_with_incoming, user: request_user, prominence: "hidden") @@ -161,13 +157,10 @@ } end.to raise_error ActionController::UnknownFormat end - end - end context 'when viewing a response for an external request' do - it "does not allow follow ups to external requests" do sign_in FactoryBot.create(:user) external_request = FactoryBot.create(:external_request) @@ -183,7 +176,6 @@ } expect(response).to be_successful end - end context 'when viewing a response for an embargoed request' do @@ -228,7 +220,6 @@ end describe "POST #preview" do - let(:dummy_message) do { body: "What a useless response! You suck.", what_doing: 'normal_sort' } @@ -293,7 +284,6 @@ end context "logged in as the request owner" do - before(:each) do sign_in request_user end @@ -331,7 +321,6 @@ } expect(response).to render_template('new') end - end context 'when viewing a response for an embargoed request' do @@ -348,11 +337,9 @@ end end end - end describe "POST #create" do - let(:dummy_message) do { body: "What a useless response! You suck.", what_doing: 'normal_sort' } @@ -363,7 +350,6 @@ end shared_examples_for 'successful_followup_sent' do - it 'sends the followup message' do post :create, params: { outgoing_message: dummy_message, @@ -379,7 +365,6 @@ expect(mail.to_addrs.first.to_s). to eq(request.public_body.request_email) end - end context "when not logged in" do @@ -458,7 +443,6 @@ end context 'a network error occurs while sending a followup' do - def send_request post :create, params: { outgoing_message: dummy_message, @@ -470,7 +454,6 @@ def send_request let(:outgoing_message) { request.reload.outgoing_messages.last } it_behaves_like 'NetworkSendErrors' - end it_behaves_like 'successful_followup_sent' @@ -486,7 +469,6 @@ def send_request end context 'the request is no longer open to "anybody"' do - before do request.update( allow_new_responses_from: 'authority_only', @@ -506,7 +488,6 @@ def send_request end it_behaves_like 'successful_followup_sent' - end it "updates the event status for successful followup sends if the request is waiting clarification" do @@ -566,7 +547,6 @@ def send_request end context "the same followup is submitted twice" do - before(:each) do post :create, params: { outgoing_message: dummy_message, @@ -596,9 +576,6 @@ def send_request expect(response.body). not_to include('Your follow up message has been sent on its way') end - end - end - end diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index a624d25926..f35d5817cb 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -72,7 +72,6 @@ end RSpec.describe GeneralController, "when showing the frontpage" do - render_views before do @@ -113,7 +112,6 @@ expect(successful_request_feed[:title]).to eq('Successful requests') end - it "should render the front page with default language and ignore the browser setting" do config = MySociety::Config.load_default config['USE_DEFAULT_BROWSER_LANGUAGE'] = false @@ -142,16 +140,13 @@ end describe 'when using locales' do - it "should use our test PO files rather than the application one" do get :frontpage, params: { locale: 'es' } expect(response.body).to match(/XOXO/) end - end describe 'when handling logged-in users' do - before do @user = FactoryBot.create(:user) sign_in @user @@ -181,7 +176,6 @@ get :frontpage, params: { post_redirect: 1 } expect(response).to be_successful end - end describe 'when handling pro users' do @@ -196,12 +190,9 @@ expect(@response).to redirect_to alaveteli_pro_dashboard_path end end - end - RSpec.describe GeneralController, 'when using xapian search' do - render_views # rebuild xapian index after fixtures loaded @@ -355,7 +346,6 @@ end context "when passed a non-HTML request" do - it "raises unknown format error" do expect do get :search, params: { combined: '"fancy dog"', format: :json } @@ -370,6 +360,5 @@ # noop end end - end end diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 18810286c3..b024e4bee8 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -4,12 +4,10 @@ render_views describe 'GET #index' do - it 'redirects to the about page' do get :index expect(response).to redirect_to(help_about_path) end - end describe 'GET #unhappy' do @@ -26,7 +24,6 @@ end context 'when a url_title param is supplied' do - it 'assigns the info_request' do get :unhappy, params: { url_title: info_request.url_title } expect(assigns[:info_request]).to eq info_request @@ -47,21 +44,17 @@ }.to raise_error ActiveRecord::RecordNotFound end end - end describe 'GET #about' do - it 'shows the about page' do get :about expect(response).to be_successful expect(response).to render_template('help/about') end - end describe 'GET #contact' do - it 'shows contact form' do get :contact expect(response).to be_successful @@ -69,7 +62,6 @@ end describe 'when requesting a page in a supported locale' do - before do # Prepend our fixture templates fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') @@ -80,7 +72,6 @@ get :contact, params: { locale: 'es' } expect(response.body).to match('contáctenos theme one') end - end context 'when a last_request_id cookie is set' do @@ -129,11 +120,9 @@ end end end - end describe 'POST #contact' do - it 'sends a contact message' do post :contact, params: { contact: { @@ -154,7 +143,6 @@ end context 'the site is configured to require reCAPTCHA' do - before do allow(AlaveteliConfiguration). to receive(:contact_form_recaptcha).and_return(true) @@ -178,7 +166,6 @@ expect(deliveries.size).to eq(0) deliveries.clear end - end it 'has rudimentary spam protection' do @@ -218,7 +205,5 @@ } expect(response).to redirect_to(frontpage_path) end - end - end diff --git a/spec/controllers/one_time_passwords_controller_spec.rb b/spec/controllers/one_time_passwords_controller_spec.rb index 84a98025c1..27035856c0 100644 --- a/spec/controllers/one_time_passwords_controller_spec.rb +++ b/spec/controllers/one_time_passwords_controller_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' RSpec.describe OneTimePasswordsController do - before :each do allow(AlaveteliConfiguration). to receive(:enable_two_factor_auth).and_return(true) end describe 'GET show' do - it 'redirects to the sign-in page without a signed in user' do get :show @@ -35,7 +33,6 @@ end context 'when 2factor auth is not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration). to receive(:enable_two_factor_auth).and_return(false) @@ -43,13 +40,10 @@ get :show }.to raise_error(ActiveRecord::RecordNotFound) end - end - end describe 'POST #create' do - it 'redirects to the sign-in page without a signed in user' do post :create expect(response). @@ -111,7 +105,6 @@ end context 'when 2factor auth is not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration). to receive(:enable_two_factor_auth).and_return(false) @@ -119,13 +112,10 @@ post :create }.to raise_error(ActiveRecord::RecordNotFound) end - end - end describe 'PUT #update' do - it 'redirects to the sign-in page without a signed in user' do put :update expect(response). @@ -181,7 +171,6 @@ end context 'when 2factor auth is not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration). to receive(:enable_two_factor_auth).and_return(false) @@ -189,13 +178,10 @@ put :update }.to raise_error(ActiveRecord::RecordNotFound) end - end - end describe 'DELETE #destroy' do - it 'redirects to the sign-in page without a signed in user' do user = FactoryBot.create(:user) delete :destroy @@ -251,7 +237,6 @@ end context 'when two factor auth is not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration). to receive(:enable_two_factor_auth).and_return(false) @@ -259,9 +244,6 @@ delete :destroy }.to raise_error(ActiveRecord::RecordNotFound) end - end - end - end diff --git a/spec/controllers/outgoing_messages/delivery_statuses_controller_spec.rb b/spec/controllers/outgoing_messages/delivery_statuses_controller_spec.rb index d791a9c6af..3cdb798607 100644 --- a/spec/controllers/outgoing_messages/delivery_statuses_controller_spec.rb +++ b/spec/controllers/outgoing_messages/delivery_statuses_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe OutgoingMessages::DeliveryStatusesController do - let(:logs) do lines = <<~EOF.split("\n") 2015-09-22 17:36:56 [2035] 1ZeQYq-0000Wm-1V => body@example.com F= P= R=dnslookup T=remote_smtp S=1685 H=mail.example.com [62.208.144.158]:25 C="250 2.0.0 Ok: queued as 95FC94583B8" QT=0s DT=0s\n diff --git a/spec/controllers/password_changes_controller_spec.rb b/spec/controllers/password_changes_controller_spec.rb index 5da8077c59..3badb9c931 100644 --- a/spec/controllers/password_changes_controller_spec.rb +++ b/spec/controllers/password_changes_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe PasswordChangesController do - describe 'GET new' do - it 'assigns the pretoken if supplied' do get :new, params: { pretoken: 'abcdef' } expect(assigns[:pretoken]).to eq('abcdef') @@ -42,13 +40,10 @@ get :new expect(response).to render_template(:new) end - end describe 'POST create' do - context 'when a user is signed in' do - it 'ignores an email submitted in the post params' do user = FactoryBot.create(:user) sign_in user @@ -69,16 +64,13 @@ end context 'when no user is signed in and no email is submitted' do - it 're-renders the form' do post :create expect(response).to render_template(:new) end - end context 'when receiving an email address of an existing user' do - it 'assigns the user' do user = FactoryBot.create(:user) post :create, params: { @@ -124,7 +116,6 @@ end context 'when a pretoken is supplied' do - it 'adds the pretoken to the post redirect uri' do user = FactoryBot.create(:user) pretoken = PostRedirect.create(user: user, uri: '/') @@ -151,7 +142,6 @@ expected = edit_password_change_url(post_redirect.token) expect(post_redirect.uri).to eq(expected) end - end it 'sends a confirmation email' do @@ -207,13 +197,10 @@ } expect(response).to render_template(:new) end - end - end describe 'GET edit' do - let(:user) { FactoryBot.create(:user) } let(:post_redirect) do PostRedirect.create(user: user, uri: frontpage_url) @@ -240,7 +227,6 @@ end context 'no user is specified' do - let(:post_redirect) { PostRedirect.new(user: nil) } it 'redirects to new for the user to enter their email' do @@ -253,16 +239,13 @@ expect(response). to redirect_to(new_password_change_path(pretoken: 'abcdef')) end - end context 'invalid token' do - it 'redirects to new to force an email confirmation' do get :edit, params: { id: 'invalid' } expect(response).to redirect_to new_password_change_path end - end context 'with enable_two_factor_auth disabled' do @@ -309,7 +292,6 @@ end describe 'PUT update' do - let(:user) { FactoryBot.create(:user) } let(:post_redirect) do PostRedirect.create(user: user, uri: frontpage_path) @@ -375,7 +357,6 @@ end context 'no user is specified' do - let(:post_redirect) { PostRedirect.new(user: nil) } it 'redirects to #new when a user cannot be found' do @@ -385,11 +366,9 @@ } expect(response).to redirect_to(new_password_change_path) end - end context 'invalid token' do - it 'redirects to new to force an email confirmation' do put :update, params: { id: 'invalid', @@ -397,11 +376,9 @@ } expect(response).to redirect_to new_password_change_path end - end context 'when a pretoken is supplied' do - it 'redirects to the post redirect uri' do pretoken = PostRedirect.create(user: user, uri: '/') put :update, params: { @@ -430,11 +407,9 @@ } expect(response).to redirect_to(show_user_profile_path(user.url_name)) end - end context 'when there is no pretoken' do - it 'redirects to the user profile on success' do put :update, params: { id: post_redirect.token, @@ -442,11 +417,9 @@ } expect(response).to redirect_to(show_user_profile_path(user.url_name)) end - end context 'when the user has two factor authentication enabled' do - let(:user) { FactoryBot.create(:user, :enable_otp) } before(:each) do @@ -522,9 +495,6 @@ expect(user.reload.hashed_password).to eq(old_hash) end - end - end - end diff --git a/spec/controllers/public_body_change_requests_controller_spec.rb b/spec/controllers/public_body_change_requests_controller_spec.rb index 8d3daeaa01..2355681bd8 100644 --- a/spec/controllers/public_body_change_requests_controller_spec.rb +++ b/spec/controllers/public_body_change_requests_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe PublicBodyChangeRequestsController do - describe 'GET #new' do - it "should show the form" do get :new expect(response).to render_template("new") @@ -19,11 +17,9 @@ get :new expect(assigns[:render_recaptcha]).to eq(false) end - end describe 'POST #create' do - before do @email = "test@example.com" name = "Test User" @@ -110,7 +106,6 @@ end context 'when handling a request for an update to an existing authority' do - before do @email = "test@example.com" name = "Test User" @@ -159,7 +154,6 @@ } expect(response).to redirect_to frontpage_url end - end end end diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index a7fd6a011c..4873bc3aa9 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -84,7 +84,6 @@ expect(flash[:search_params]).to eq(search_params) end - it 'should not show high page offsets as these are extremely slow to generate' do expect { get :show, params: { url_name: 'dfh', view: 'all', page: 25 } @@ -198,7 +197,6 @@ def make_single_language_example(locale) expect(response.body).to have_content('Hebrew Humpadinking') end - it "should list bodies in alphabetical order" do # Note that they are alphabetised by localised name get :list @@ -388,11 +386,9 @@ def make_single_language_example(locale) expect(assigns[:public_bodies]).to eq([ authority ]) expect(assigns[:tag]).to eq("Å") end - end RSpec.describe PublicBodyController, "when showing JSON version for API" do - it "should be successful" do get :show, params: { url_name: "dfh", format: "json", view: 'all' } @@ -402,7 +398,6 @@ def make_single_language_example(locale) expect(pb['url_name']).to eq('dfh') expect(pb['notes']).to eq('An albatross told me!!!') end - end RSpec.describe PublicBodyController, "when asked to export public bodies as CSV" do @@ -468,5 +463,4 @@ def make_single_language_example(locale) flash_params = flash[:search_params].to_unsafe_h expect(flash_params).to eq(search_params) end - end diff --git a/spec/controllers/public_tokens_controller_spec.rb b/spec/controllers/public_tokens_controller_spec.rb index 29fd4810ef..cf3b646189 100644 --- a/spec/controllers/public_tokens_controller_spec.rb +++ b/spec/controllers/public_tokens_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe PublicTokensController, type: :controller do - let(:ability) { Object.new.extend(CanCan::Ability) } let(:info_request) { FactoryBot.create(:embargoed_request) } @@ -206,5 +205,4 @@ end end end - end diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index bf78fd28d1..989b1bb07c 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe ReportsController do - describe 'POST #create' do let(:info_request) { FactoryBot.create(:info_request) } let(:user) { FactoryBot.create(:user) } @@ -157,7 +156,6 @@ expect(response).to render_template("new") expect(flash[:error]).to eq("Please choose a reason") end - end context "when reporting a comment (logged in)" do @@ -294,9 +292,7 @@ expect(response) .to redirect_to show_request_path(url_title: info_request.url_title) end - end - end describe "GET #new" do @@ -355,7 +351,6 @@ get :new, params: { request_id: info_request.url_title } }.to raise_error(ActiveRecord::RecordNotFound) end - end context "when reporting a comment (logged in)" do @@ -462,9 +457,6 @@ } }.to raise_error(ActiveRecord::RecordNotFound) end - end - end - end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 64b717e575..e4424ccb52 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -38,7 +38,6 @@ }.not_to raise_error expect(assigns[:page]).to eq(1) end - end RSpec.describe RequestController, "when showing one request" do @@ -155,7 +154,6 @@ end context 'when a cancelled pro views their embargoed request' do - before do pro_user.remove_role(:pro) end @@ -232,9 +230,7 @@ def make_request end describe 'when handling an update_status parameter' do - describe 'when the request is external' do - it 'should assign the "update status" flag to the view as falsey if the parameter is present' do get :show, params: { url_title: 'balalas', update_status: 1 } expect(assigns[:update_status]).to be_falsey @@ -244,7 +240,6 @@ def make_request get :show, params: { url_title: 'balalas' } expect(assigns[:update_status]).to be_falsey end - end it 'should assign the "update status" flag to the view as truthy if the parameter is present' do @@ -742,9 +737,7 @@ def expect_hidden(hidden_template) end context "the outgoing message includes an email address" do - context "there is no logged in user" do - it "displays a flash error message without escaping the HTML" do post :new, params: { info_request: { @@ -761,11 +754,9 @@ def expect_hidden(hidden_template) expect(response.body). to have_content('You do not need to include your email') end - end context "the user is logged in" do - it "displays a flash error message without escaping the HTML" do sign_in @user post :new, params: { @@ -782,13 +773,10 @@ def expect_hidden(hidden_template) expect(response.body). to have_content('You do not need to include your email') end - end - end context "the outgoing message includes a postcode" do - it 'displays an error message warning about the postcode' do post :new, params: { info_request: { @@ -802,11 +790,9 @@ def expect_hidden(hidden_template) expect(response.body).to have_content('Your request contains a postcode') end - end context 'a network error occurs while sending the initial request' do - def send_request sign_in @user post :new, params: { @@ -827,7 +813,6 @@ def send_request let(:outgoing_message) { request.reload.outgoing_messages.last } it_behaves_like 'NetworkSendErrors' - end it "should redirect pros to the pro version" do @@ -1106,7 +1091,6 @@ def send_request } expect(response).to redirect_to show_request_url(url_title: 'what_is_the_answer_to_the_ultima') - post :new, params: { info_request: { @@ -1160,7 +1144,6 @@ def send_request } expect(response).to redirect_to show_request_url(url_title: 'what_is_the_answer_to_the_ultima') - post :new, params: { info_request: { @@ -1194,9 +1177,7 @@ def send_request end describe 'when rendering a reCAPTCHA' do - context 'when new_request_recaptcha disabled' do - before do allow(AlaveteliConfiguration).to receive(:new_request_recaptcha) .and_return(false) @@ -1218,7 +1199,6 @@ def send_request end context 'when new_request_recaptcha is enabled' do - before do allow(AlaveteliConfiguration).to receive(:new_request_recaptcha) .and_return(true) @@ -1271,7 +1251,6 @@ def send_request end context 'when the reCAPTCHA information is not correct' do - before do allow(controller).to receive(:verify_recaptcha).and_return(false) end @@ -1334,22 +1313,16 @@ def send_request expect(response) .to redirect_to show_request_path(url_title: 'some_request_text') end - end - end - end context 'when the request subject line looks like spam' do - let(:user) { FactoryBot.create(:user, confirmed_not_spam: false) } let(:body) { FactoryBot.create(:public_body) } - context 'when given a string containing unicode characters' do - it 'converts the string to ASCII' do allow(AlaveteliConfiguration).to receive(:block_spam_requests). and_return(true) @@ -1370,7 +1343,6 @@ def send_request mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Spam request from user #{ user.id }/) end - end context 'when enable_anti_spam is false and block_spam_requests is true' do @@ -1400,11 +1372,9 @@ def send_request mail = ActionMailer::Base.deliveries.first expect(mail.subject).to match(/Spam request from user #{ user.id }/) end - end context 'when block_spam_subject? is true' do - before do allow(@controller).to receive(:block_spam_subject?).and_return(true) end @@ -1485,11 +1455,9 @@ def send_request expect(response) .to redirect_to show_request_path(url_title: 'hd_watch_jason_bourne_online_fre') end - end context 'when block_spam_subject? is false' do - before do allow(@controller).to receive(:block_spam_subject?).and_return(false) end @@ -1531,13 +1499,10 @@ def send_request expect(response) .to redirect_to show_request_path(url_title: 'hd_watch_jason_bourne_online_fre') end - end - end describe 'when the request is from an IP address in a blocked country' do - let(:user) { FactoryBot.create(:user, confirmed_not_spam: false) } let(:body) { FactoryBot.create(:public_body) } @@ -1548,7 +1513,6 @@ def send_request end context 'when block_restricted_country_ips? is true' do - before do allow(@controller). to receive(:block_restricted_country_ips?).and_return(true) @@ -1627,11 +1591,9 @@ def send_request expect(response) .to redirect_to show_request_path(url_title: 'some_request_content') end - end context 'when block_restricted_country_ips? is false' do - before do allow(@controller). to receive(:block_restricted_country_ips?).and_return(false) @@ -1673,17 +1635,13 @@ def send_request expect(response) .to redirect_to show_request_path(url_title: 'some_request_content') end - end - end - end # These go with the previous set, but use mocks instead of fixtures. # TODO harmonise these RSpec.describe RequestController, "when making a new request" do - before do @user = mock_model(User, id: 3481, name: 'Testy').as_null_object allow(@user).to receive(:get_undescribed_requests).and_return([]) @@ -1718,7 +1676,6 @@ def send_request get :new, params: { public_body_id: @body.id } expect(response).to render_template('user/banned') end - end RSpec.describe RequestController, "when viewing comments" do @@ -1744,12 +1701,9 @@ def send_request expect(s).not_to have_text(/You.*left an annotation/m) end end - end - RSpec.describe RequestController, "authority uploads a response from the web interface" do - before(:each) do # domain after the @ is used for authentication of FOI officers, so to test it # we need a user which isn't at localhost. @@ -1892,11 +1846,9 @@ def send_request expect(ir['public_body']['url_name']).to eq('tgq') expect(ir['user']['url_name']).to eq('bob_smith') end - end RSpec.describe RequestController, "when doing type ahead searches" do - before :each do update_xapian_index end @@ -1916,11 +1868,9 @@ def send_request expect(assigns[:per_page]).to eq(1) expect(assigns[:xapian_requests].results.size).to eq(1) end - end RSpec.describe RequestController, "when showing similar requests" do - before do update_xapian_index load_raw_emails_data @@ -1976,7 +1926,6 @@ def send_request get :similar, params: { url_title: badger_request.url_title } }.to raise_error(ActiveRecord::RecordNotFound) end - end RSpec.describe RequestController, "when the site is in read_only mode" do @@ -2008,9 +1957,7 @@ def send_request end RSpec.describe RequestController do - describe 'GET #details' do - let(:info_request) { FactoryBot.create(:info_request) } it 'renders the details template' do @@ -2024,7 +1971,6 @@ def send_request end context 'when the request is hidden' do - before do info_request.prominence = 'hidden' info_request.save! @@ -2039,11 +1985,9 @@ def send_request get :details, params: { url_title: info_request.url_title } expect(response).to render_template("request/hidden") end - end context 'when the request is embargoed' do - before do info_request.create_embargo(publish_at: Time.zone.now + 3.days) end @@ -2054,14 +1998,10 @@ def send_request }.to raise_error(ActiveRecord::RecordNotFound) end end - - end - end RSpec.describe RequestController do - describe 'GET #download_entire_request' do context 'when the request is embargoed' do let(:user) { FactoryBot.create(:user) } @@ -2106,7 +2046,6 @@ def send_request end context 'when the request is unclassified' do - it 'does not render the describe state form' do info_request = FactoryBot.create(:info_request) info_request.update(awaiting_description: true) @@ -2119,15 +2058,12 @@ def send_request expect(assigns[:show_other_user_update_status_action]).to eq(false) expect(assigns[:show_profile_photo]).to eq(false) end - end end end RSpec.describe RequestController do - describe 'GET #show_request_event' do - context 'when the event is an incoming message' do let(:event) { FactoryBot.create(:response_event) } @@ -2196,13 +2132,10 @@ def send_request end describe 'GET #search_typeahead' do - it "does not raise an error if there are no params" do expect { get :search_typeahead }.not_to raise_error end - end - end diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb index 1c1a0862ee..2a81f47014 100644 --- a/spec/controllers/request_game_controller_spec.rb +++ b/spec/controllers/request_game_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe RequestGameController do - describe "GET play" do - it "shows the game homepage" do get :play expect(response).to render_template('play') @@ -27,7 +25,6 @@ end context 'there are no requests' do - before do InfoRequest.destroy_all end @@ -36,11 +33,9 @@ get :play expect(response).to render_template('play') end - end context 'there are no old unclassified requests' do - before do InfoRequest.destroy_all FactoryBot.create(:info_request) @@ -73,9 +68,6 @@ expect(response.body). to have_link('more things you can do', href: test_url) end - end - end - end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 852ca06725..c9a52b6b36 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe ServicesController do - render_views describe '#other_country_message' do - # store and restore the locale in the context of the test suite to isolate # changes made in these tests before do @@ -42,7 +40,6 @@ end context 'when user not in the same country as site' do - it "shows a message when user country has no FOI website" do allow(AlaveteliConfiguration). to receive(:iso_country_code).and_return("DE") @@ -85,13 +82,10 @@ expect(response.body).to match(/in other countries/) expect(response.body).to match(/EU institutions/) end - end - end describe '#hidden_user_explanation' do - let(:admin_user) { FactoryBot.create(:admin_user) } let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } let(:user) { FactoryBot.create(:user, name: "P O'Toole") } @@ -141,7 +135,5 @@ end end end - end - end diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 985ae34c3e..abe472117b 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -2,7 +2,6 @@ RSpec.describe StatisticsController do describe "#index" do - before do allow(AlaveteliConfiguration). to receive(:minimum_requests_for_statistics).and_return 1 diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 92823a9088..b9e20347a9 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -82,14 +82,12 @@ end context 'when getting feeds' do - before do load_raw_emails_data update_xapian_index end it "should get the RSS feed" do - track_thing = track_things(:track_fancy_dog_request) get :track_request, params: { @@ -162,7 +160,6 @@ expect(response.media_type).to eq('application/atom+xml') end end - end describe "GET #track_search_query" do @@ -306,7 +303,6 @@ expect(tt.track_query) .to eq("requested_from:#{public_body.url_name} variety:sent") end - end describe "GET #track_user" do @@ -343,7 +339,6 @@ url_name: "there_is_no_such_user" } }.to raise_error(ActiveRecord::RecordNotFound) end - end describe "GET #track_list" do @@ -435,15 +430,12 @@ } }.to raise_error(RuntimeError, msg) end - end describe 'POST #delete_all_type' do - let(:track_thing) { FactoryBot.create(:search_track) } context 'when the user passed in the params is not logged in' do - it 'redirects to the signin page' do post :delete_all_type, params: { user: track_thing.tracking_user.id, @@ -452,11 +444,9 @@ expect(response). to redirect_to(signin_path(token: get_last_post_redirect.token)) end - end context 'when the user passed in the params is logged in' do - it 'deletes all tracks for the user of the type passed in the params' do sign_in track_thing.tracking_user post :delete_all_type, params: { @@ -486,8 +476,6 @@ } expect(flash[:notice]).to eq("You will no longer be emailed updates for those alerts") end - end - end end diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index aa33b6b755..cf6d7bd45d 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe UserController do - describe 'GET show' do - let(:user) { FactoryBot.create(:user) } it 'renders the show template' do @@ -39,7 +37,6 @@ # http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ # ControllerExampleGroup.html context 'when redirecting a show request to a canonical url' do - it 'redirects to lower case name if given one with capital letters' do get :show, params: { url_name: 'Bob_Smith' } expect(response).to redirect_to(show_user_path(url_name: 'bob_smith')) @@ -59,12 +56,10 @@ get :show, params: { url_name: 'bob_smith_bob_smith_bob_smith_bo_2' } expect(response).to be_successful end - end # Also doubles for when not logged in viewing another user's profile context 'when viewing a profile' do - def make_request get :show, params: { url_name: user.url_name, view: 'profile' } end @@ -84,12 +79,10 @@ def make_request expect(response.body). to match(/change password, subscriptions and more/) end - end # Also doubles for when not logged in viewing another user's requests context 'when viewing requests' do - def make_request get :show, params: { url_name: user.url_name, view: 'requests' } end @@ -126,11 +119,9 @@ def make_request get :show, params: { url_name: user.url_name, view: 'requests' } expect(assigns[:private_requests]).to be_empty end - end context 'when filtering requests' do - before do load_raw_emails_data update_xapian_index @@ -173,11 +164,9 @@ def make_request expect(actual).to match_array([info_requests(:naughty_chicken_request)]) end - end context 'when logged in viewing your own profile' do - def make_request get :show, params: { url_name: user.url_name, view: 'profile' } end @@ -195,11 +184,9 @@ def make_request expect(assigns[:show_batches]).to be false expect(response.body).to include('Change your password') end - end context 'when logged in viewing your own requests' do - def make_request get :show, params: { url_name: user.url_name, view: 'requests' } end @@ -294,11 +281,9 @@ def make_request get :show, params: { url_name: user.url_name, view: 'requests' } expect(assigns[:private_requests]).to match_array([info_request]) end - end context 'when logged in filtering your own requests' do - before do sign_in user end @@ -381,11 +366,9 @@ def make_request expect(assigns[:private_requests]).to match_array([request_1]) end - end context 'when logged in viewing other requests' do - def make_request get :show, params: { url_name: user.url_name, view: 'requests' } end @@ -481,7 +464,6 @@ def make_request end context 'when logged in filtering other requests' do - before do sign_in FactoryBot.create(:user) end @@ -563,7 +545,6 @@ def make_request expect(assigns[:private_requests]).to be_empty end - end context 'when the display_user does not have an about_me' do @@ -662,9 +643,7 @@ def make_request end describe 'POST set_profile_photo' do - context 'user is banned' do - before(:each) do @user = FactoryBot.create(:user, ban_text: 'Causing trouble') sign_in @user @@ -686,9 +665,7 @@ def make_request msg = 'Suspended users cannot edit their profile' expect(flash[:error]).to eq(msg) end - end - end describe 'POST #signup' do @@ -876,11 +853,9 @@ def make_request } expect(response).to render_template('confirm') end - end context 'when the IP is rate limited' do - before(:each) do limiter = double allow(limiter).to receive(:record) @@ -889,7 +864,6 @@ def make_request end context 'when block_rate_limited_ips? is true' do - before(:each) do allow(@controller). to receive(:block_rate_limited_ips?).and_return(true) @@ -943,11 +917,9 @@ def make_request } expect(flash[:error]).to match(/unable to sign up new users/) end - end context 'when block_rate_limited_ips? is false' do - before(:each) do allow(@controller). to receive(:block_rate_limited_ips?).and_return(false) @@ -977,13 +949,10 @@ def make_request } expect(User.where(email: 'rate-limited@localhost').count).to eq(1) end - end - end context 'using a spammy name or email from a known spam domain' do - before do spam_scorer = double allow(spam_scorer).to receive(:spam?).and_return(true) @@ -991,7 +960,6 @@ def make_request end context 'when spam_should_be_blocked? is true' do - before do allow(@controller). to receive(:spam_should_be_blocked?).and_return(true) @@ -1037,11 +1005,9 @@ def make_request } expect(response).to render_template('sign') end - end context 'when spam_should_be_blocked? is false' do - before do allow(@controller). to receive(:spam_should_be_blocked?).and_return(false) @@ -1071,9 +1037,7 @@ def make_request } expect(User.where(email: 'spammer@example.com').count).to eq(1) end - end - end # TODO: need to do bob@localhost signup and check that sends different email @@ -1275,7 +1239,6 @@ def make_request expect(flash[:notice][:partial]). to eq("user/update_profile_photo") end - end it "should let you change profile photo twice" do @@ -1308,7 +1271,6 @@ def make_request end RSpec.describe UserController, "when showing JSON version for API" do - it "should be successful" do get :show, params: { url_name: "bob_smith", format: "json" } @@ -1318,7 +1280,6 @@ def make_request expect(u['url_name']).to eq('bob_smith') expect(u['name']).to eq('Bob Smith') end - end RSpec.describe UserController, "when viewing the wall" do diff --git a/spec/controllers/user_profile/about_me_controller_spec.rb b/spec/controllers/user_profile/about_me_controller_spec.rb index ec787ac6dc..d5ca6a3b4b 100644 --- a/spec/controllers/user_profile/about_me_controller_spec.rb +++ b/spec/controllers/user_profile/about_me_controller_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe UserProfile::AboutMeController do - describe 'GET edit' do - it 'sets the title' do get :edit expect(assigns[:title]). @@ -11,17 +9,14 @@ end context 'without a logged in user' do - it 'redirects to the home page' do sign_in nil get :edit expect(response).to redirect_to(frontpage_path) end - end context 'with a logged in user' do - let(:user) { FactoryBot.create(:user) } it 'assigns the currently logged in user' do @@ -41,13 +36,10 @@ get :edit expect(response).to render_template(:edit) end - end - end describe 'PUT update' do - it 'sets the title' do put :update, params: { user: { about_me: 'My bio' } } expect(assigns[:title]). @@ -55,17 +47,14 @@ end context 'without a logged in user' do - it 'redirects to the sign in page' do sign_in nil put :update, params: { user: { about_me: 'My bio' } } expect(response).to redirect_to(frontpage_path) end - end context 'with a banned user' do - let(:banned_user) { FactoryBot.create(:user, ban_text: 'banned') } before :each do @@ -81,11 +70,9 @@ put :update, params: { user: { about_me: 'My bio' } } expect(response).to redirect_to(edit_profile_about_me_path) end - end context 'with valid attributes' do - let(:user) { FactoryBot.create(:user) } before :each do @@ -103,7 +90,6 @@ end context 'if the user has a profile photo' do - it 'sets a success message' do user.create_profile_photo!(data: load_file_fixture('parrot.png')) put :update, params: { user: { about_me: 'My bio' } } @@ -117,11 +103,9 @@ expect(response). to redirect_to(show_user_path(url_name: user.url_name)) end - end context 'if the user does not have a profile photo' do - it 'sets a message suggesting they add one' do put :update, params: { user: { about_me: 'My bio' } } expect(flash[:notice][:partial]).to eq("update_profile_text") @@ -131,13 +115,10 @@ put :update, params: { user: { about_me: 'My bio' } } expect(response).to redirect_to(set_profile_photo_path) end - end - end context 'with invalid attributes' do - let(:user) { FactoryBot.create(:user, about_me: 'My bio') } let(:invalid_text) { 'x' * 1000 } @@ -159,11 +140,9 @@ put :update, params: { user: { about_me: invalid_text } } expect(response).to render_template(:edit) end - end context 'with invalid parameters' do - let(:user) { FactoryBot.create(:user, about_me: 'My bio') } before :each do @@ -185,11 +164,9 @@ expect(response). to redirect_to(show_user_path(url_name: user.url_name)) end - end context 'with extra attributes' do - let(:user) { FactoryBot.create(:user) } before :each do @@ -217,11 +194,9 @@ } expect(user.reload.about_me).to eq('My bio') end - end context 'with spam attributes and a non-whitelisted user' do - let(:user) do FactoryBot.create(:user, name: 'JWahewKjWhebCd', confirmed_not_spam: false) @@ -258,11 +233,9 @@ } expect(user.reload.about_me).to eq('') end - end context 'with spam attributes and a whitelisted user' do - let(:user) do FactoryBot.create(:user, name: 'JWahewKjWhebCd', confirmed_not_spam: true) @@ -284,11 +257,9 @@ } expect(user.reload.about_me).to eq('http://example.com/$£$£$') end - end context 'with block_spam_about_me_text? returning true, spam content and a non-whitelisted user' do - let(:user) { FactoryBot.create(:user, confirmed_not_spam: false) } before :each do @@ -341,11 +312,9 @@ } expect(user.reload.about_me).to eq('') end - end context 'with block_spam_about_me_text? returning false, spam content and a whitelisted user' do - let(:user) do FactoryBot.create(:user, name: '12345', confirmed_not_spam: true) end @@ -365,11 +334,9 @@ } expect(user.reload.about_me).to eq('[HD] Watch Jason Bourne Online free MOVIE Full-HD') end - end context 'with block_spam_about_me_text? returning true, spam content and a whitelisted user' do - let(:user) { FactoryBot.create(:user, confirmed_not_spam: true) } before :each do @@ -387,10 +354,6 @@ } expect(user.reload.about_me).to eq('[HD] Watch Jason Bourne Online free MOVIE Full-HD') end - end - - end - end diff --git a/spec/controllers/users/confirmations_controller_spec.rb b/spec/controllers/users/confirmations_controller_spec.rb index cae05aefd3..24f1d9e65b 100644 --- a/spec/controllers/users/confirmations_controller_spec.rb +++ b/spec/controllers/users/confirmations_controller_spec.rb @@ -1,27 +1,21 @@ require 'spec_helper' RSpec.describe Users::ConfirmationsController do - describe 'GET confirm' do - context 'if the post redirect cannot be found' do - it 'renders bad_token' do get :confirm, params: { email_token: '' } expect(response).to render_template(:bad_token) end - end context 'if the post redirect email token invalid' do - it 'renders bad_token' do allow(PostRedirect).to receive(:find_by_email_token).with('abc'). and_return(double(:post_redirect, email_token_valid?: false)) get :confirm, params: { email_token: 'abc' } expect(response).to render_template(:bad_token) end - end context 'the post redirect circumstance is change_password' do @@ -85,7 +79,6 @@ end context 'if the currently logged in user is an admin' do - before :each do @admin = FactoryBot.create(:admin_user) @user = FactoryBot.create(:user, email_confirmed: false) @@ -110,7 +103,6 @@ it 'redirects to the post redirect uri' do expect(response).to redirect_to('/?post_redirect=1') end - end context <<-EOF do @@ -141,7 +133,6 @@ it 'redirects to the post redirect uri' do expect(response).to redirect_to('/?post_redirect=1') end - end context <<-EOF do @@ -173,11 +164,9 @@ it 'redirects to the post redirect uri' do expect(response).to redirect_to('/?post_redirect=1') end - end context 'if there is no logged in user' do - before :each do @user = FactoryBot.create(:user, email_confirmed: false) @post_redirect = PostRedirect.create(uri: '/', user: @user) @@ -200,7 +189,6 @@ it 'redirects to the post redirect uri' do expect(response).to redirect_to('/?post_redirect=1') end - end end end diff --git a/spec/controllers/users/messages_controller_spec.rb b/spec/controllers/users/messages_controller_spec.rb index 999ca4a21a..ed7a86d070 100644 --- a/spec/controllers/users/messages_controller_spec.rb +++ b/spec/controllers/users/messages_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe Users::MessagesController do - render_views let(:sender) { FactoryBot.create(:user, name: 'Bob Smith') } @@ -12,16 +11,13 @@ after { ActionMailer::Base.deliveries.clear } describe 'GET contact' do - context 'when not signed in' do - it 'redirects to signin page' do sign_in nil get :contact, params: { url_name: recipient.url_name } expect(response). to redirect_to(signin_path(token: get_last_post_redirect.token)) end - end it 'shows the contact form' do @@ -55,7 +51,6 @@ end describe 'POST contact' do - it 'shows an error if not given a subject line' do post :contact, params: { url_name: recipient.url_name, @@ -123,7 +118,6 @@ expect(deliveries.size).to eq(0) deliveries.clear end - end it 'sends the message' do diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 7a8f7f6531..ef7abffb5c 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' RSpec.describe Users::SessionsController do - before do # Don't call out to external url during tests allow(controller).to receive(:country_from_ip).and_return('gb') end describe 'GET new' do - it "should show sign in / sign up page" do get :new expect(response.body).to render_template('user/sign') @@ -47,9 +45,7 @@ get :new, params: { r: '/select_authority' } expect(response).to redirect_to(select_authority_path) end - end - end describe 'POST create' do @@ -233,11 +229,9 @@ def do_signin(email, password) session: { user_id: user.id } expect(session[:user_id]).to be_nil end - end context 'using a spammy name or email from a known spam domain' do - let(:user) do FactoryBot.create( :user, @@ -259,7 +253,6 @@ def do_signin(email, password) end context 'when spam_should_be_blocked? is true' do - before do allow(@controller). to receive(:spam_should_be_blocked?).and_return(true) @@ -284,11 +277,9 @@ def do_signin(email, password) do_signin(user.email, 'password1234') expect(response).to render_template('sign') end - end context 'when spam_should_be_blocked? is false' do - before do allow(@controller). to receive(:spam_should_be_blocked?).and_return(false) @@ -304,9 +295,7 @@ def do_signin(email, password) do_signin(user.email, 'password1234') expect(session[:user_id]).to eq user.id end - end - end it "should ask you to confirm your email if it isn't confirmed, after log in" do @@ -413,7 +402,6 @@ def do_signin(email, password) # And the redirect should still work, of course expect(response).to redirect_to(controller: 'request', action: 'list', post_redirect: 1) end - end describe 'GET destroy' do @@ -438,7 +426,5 @@ def do_signin(email, password) get :destroy, session: { user_id: user.id, ttl: Time.zone.now } expect(session[:ttl]).to be_nil end - end - end diff --git a/spec/controllers/widget_votes_controller_spec.rb b/spec/controllers/widget_votes_controller_spec.rb index 0c57d77b91..3c8a81dd1c 100644 --- a/spec/controllers/widget_votes_controller_spec.rb +++ b/spec/controllers/widget_votes_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe WidgetVotesController do - include LinkToHelper describe 'POST #create' do @@ -23,7 +22,6 @@ end context 'for a non-logged-in user without a tracking cookie' do - it 'sets a tracking cookie' do allow(SecureRandom).to receive(:hex).and_return(mock_cookie) post :create, params: { request_id: info_request.id } @@ -40,11 +38,9 @@ expect(votes.size).to eq(1) end - end context 'for a non-logged-in user with a tracking cookie' do - it 'retains the existing tracking cookie' do request.cookies['widget_vote'] = mock_cookie post :create, params: { request_id: info_request.id } @@ -61,33 +57,27 @@ expect(votes.size).to eq(1) end - end context 'when widgets are not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(false) expect { post :create, params: { request_id: info_request.id } }.to raise_error(ActiveRecord::RecordNotFound) end - end context "when the request's prominence is not 'normal'" do - it 'should return a 403' do info_request.prominence = 'hidden' info_request.save! post :create, params: { request_id: info_request.id } expect(response.code).to eq("403") end - end context 'when the request is embargoed' do - it 'should raise an ActiveRecord::RecordNotFound error' do embargoed_request = FactoryBot.create(:embargoed_request) expect { @@ -96,7 +86,6 @@ end end end - end def mock_cookie diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index d942d9ff7a..5994fd59ed 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe WidgetsController do - include LinkToHelper describe 'GET show' do - before do @info_request = FactoryBot.create(:info_request) allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(true) @@ -71,7 +69,6 @@ end context 'for a non-logged-in user with a tracking cookie' do - it 'will not find existing tracks' do request.cookies['widget_vote'] = mock_cookie get :show, params: { request_id: @info_request.id } @@ -93,11 +90,9 @@ get :show, params: { request_id: @info_request.id } expect(assigns[:existing_vote]).to be false end - end context 'for a non-logged-in user without a tracking cookie' do - it 'will not find existing tracks' do request.cookies['widget_vote'] = nil get :show, params: { request_id: @info_request.id } @@ -109,11 +104,9 @@ get :show, params: { request_id: @info_request.id } expect(assigns[:existing_vote]).to be false end - end context 'for a logged in user with tracks' do - it 'finds the existing track thing' do user = FactoryBot.create(:user) track = TrackThing.create_track_for_request(@info_request) @@ -126,11 +119,9 @@ expect(assigns[:existing_track]).to eq(track) end - end context 'for a logged in user without tracks' do - it 'does not find existing track things' do TrackThing.delete_all user = FactoryBot.create(:user) @@ -164,22 +155,18 @@ expect(assigns[:existing_vote]).to be false end - end context 'when widgets are not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(false) expect { get :show, params: { request_id: @info_request.id } }.to raise_error(ActiveRecord::RecordNotFound) end - end context "when the request's prominence is not 'normal'" do - it 'should return a 403' do @info_request.prominence = 'hidden' @info_request.save! @@ -197,13 +184,10 @@ expect(assigns[:existing_vote]).to be false end - end - end describe 'GET new' do - before do @info_request = FactoryBot.create(:info_request) allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(true) @@ -220,29 +204,23 @@ end context 'when widgets are not enabled' do - it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(false) expect { get :new, params: { request_id: @info_request.id } }.to raise_error(ActiveRecord::RecordNotFound) end - end context "when the request's prominence is not 'normal'" do - it 'should return a 403' do @info_request.prominence = 'hidden' @info_request.save! get :show, params: { request_id: @info_request.id } expect(response.code).to eq("403") end - end - end - end def mock_cookie diff --git a/spec/factories/censor_rules.rb b/spec/factories/censor_rules.rb index b2ae469e27..3ebe63c206 100644 --- a/spec/factories/censor_rules.rb +++ b/spec/factories/censor_rules.rb @@ -17,7 +17,6 @@ # FactoryBot.define do - factory :censor_rule do text { 'some text to redact' } replacement { '[REDACTED]' } @@ -43,7 +42,5 @@ factory :global_censor_rule do end - end - end diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index dca671debc..0fcbb7a3cc 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -15,7 +15,6 @@ # FactoryBot.define do - factory :comment do user info_request @@ -54,5 +53,4 @@ end end end - end diff --git a/spec/factories/dataset_value_sets.rb b/spec/factories/dataset_value_sets.rb index 7f5cbf5c3e..1300c3a387 100644 --- a/spec/factories/dataset_value_sets.rb +++ b/spec/factories/dataset_value_sets.rb @@ -35,6 +35,7 @@ after(:build) do |value_set, evaluator| next if value_set.values.count > 0 || evaluator.value_count.zero? + value_set.values = build_list( :dataset_value, evaluator.value_count, value_set: value_set ) diff --git a/spec/factories/foi_attchments.rb b/spec/factories/foi_attchments.rb index 6f672dc940..883a7c214d 100644 --- a/spec/factories/foi_attchments.rb +++ b/spec/factories/foi_attchments.rb @@ -1,5 +1,4 @@ FactoryBot.define do - factory :foi_attachment do sequence(:url_part_number) { |n| n + 1 } display_size { '0K' } @@ -63,5 +62,4 @@ body { 'something' } end end - end diff --git a/spec/factories/holidays.rb b/spec/factories/holidays.rb index e077716fbd..761b5c81a7 100644 --- a/spec/factories/holidays.rb +++ b/spec/factories/holidays.rb @@ -11,10 +11,8 @@ # FactoryBot.define do - factory :holiday do day { Date.new(2010, 1, 1) } description { "New Year's Day" } end - end diff --git a/spec/factories/info_request_batches.rb b/spec/factories/info_request_batches.rb index 1dae2e9ad3..576b7a2678 100644 --- a/spec/factories/info_request_batches.rb +++ b/spec/factories/info_request_batches.rb @@ -14,7 +14,6 @@ # FactoryBot.define do - factory :info_request_batch do sequence(:title) { |n| "Example Title #{n}" } user diff --git a/spec/factories/info_request_events.rb b/spec/factories/info_request_events.rb index 349e794aa6..355751b13f 100644 --- a/spec/factories/info_request_events.rb +++ b/spec/factories/info_request_events.rb @@ -18,7 +18,6 @@ # FactoryBot.define do - factory :info_request_event do info_request event_type { 'edit' } @@ -191,7 +190,5 @@ event_type { 'edit_attachment' } params { { attachment_id: 1 } } end - end - end diff --git a/spec/factories/info_requests.rb b/spec/factories/info_requests.rb index 93e58c69d8..dbe93378f1 100644 --- a/spec/factories/info_requests.rb +++ b/spec/factories/info_requests.rb @@ -37,7 +37,6 @@ # FactoryBot.define do - factory :info_request do sequence(:title) { |n| "Example Title #{n}" } public_body diff --git a/spec/factories/mail_server_log_dones.rb b/spec/factories/mail_server_log_dones.rb index 514aa6635c..db84923b76 100644 --- a/spec/factories/mail_server_log_dones.rb +++ b/spec/factories/mail_server_log_dones.rb @@ -11,12 +11,10 @@ # FactoryBot.define do - factory :mail_server_log_done do filename { "/var/log/mail/mail.log-#{ Date.current.to_fs(:number)} " } last_stat { Time.current } end - end diff --git a/spec/factories/mail_server_logs.rb b/spec/factories/mail_server_logs.rb index 12111025fe..e916dbd1ae 100644 --- a/spec/factories/mail_server_logs.rb +++ b/spec/factories/mail_server_logs.rb @@ -14,12 +14,10 @@ # FactoryBot.define do - factory :mail_server_log do info_request mail_server_log_done sequence(:order) { |n| n } line { 'log line' } end - end diff --git a/spec/factories/outgoing_messages.rb b/spec/factories/outgoing_messages.rb index 76dc070879..a0ee47aa55 100644 --- a/spec/factories/outgoing_messages.rb +++ b/spec/factories/outgoing_messages.rb @@ -19,7 +19,6 @@ # FactoryBot.define do - factory :outgoing_message do info_request prominence { 'normal' } @@ -90,5 +89,4 @@ end end end - end diff --git a/spec/factories/pro_accounts.rb b/spec/factories/pro_accounts.rb index 91c8ee2f32..848bc9d5a2 100644 --- a/spec/factories/pro_accounts.rb +++ b/spec/factories/pro_accounts.rb @@ -12,9 +12,7 @@ # FactoryBot.define do - factory :pro_account do association :user, factory: :pro_user end - end diff --git a/spec/factories/public_bodies.rb b/spec/factories/public_bodies.rb index 6b8d992522..111615abb5 100644 --- a/spec/factories/public_bodies.rb +++ b/spec/factories/public_bodies.rb @@ -27,7 +27,6 @@ # FactoryBot.define do - factory :public_body do sequence(:name) { |n| "Example Public Body #{n}" } sequence(:short_name) { |n| "Example Body #{n}" } @@ -61,5 +60,4 @@ request_email { '' } end end - end diff --git a/spec/factories/public_body_change_requests.rb b/spec/factories/public_body_change_requests.rb index d1cf93f55c..5192471971 100644 --- a/spec/factories/public_body_change_requests.rb +++ b/spec/factories/public_body_change_requests.rb @@ -18,7 +18,6 @@ # FactoryBot.define do - factory :public_body_change_request do user source_url { 'http://www.example.com' } @@ -31,5 +30,4 @@ public_body end end - end diff --git a/spec/factories/request_classifications.rb b/spec/factories/request_classifications.rb index 35359361bb..028890a017 100644 --- a/spec/factories/request_classifications.rb +++ b/spec/factories/request_classifications.rb @@ -11,10 +11,8 @@ # FactoryBot.define do - factory :request_classification do user info_request_event end - end diff --git a/spec/factories/track_things.rb b/spec/factories/track_things.rb index 125bb499b4..0118d25c2c 100644 --- a/spec/factories/track_things.rb +++ b/spec/factories/track_things.rb @@ -16,7 +16,6 @@ # FactoryBot.define do - factory :track_thing do track_medium { 'email_daily' } track_query { 'Example Query' } @@ -62,5 +61,4 @@ track_query { 'variety:sent' } end end - end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index e1be366b9b..a2f7f66652 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -40,7 +40,6 @@ # FactoryBot.define do - factory :user do sequence(:name) { |n| "Example User #{n}" } sequence(:email) { |n| "person#{n}@example.com" } diff --git a/spec/helpers/admin_comments_helper_spec.rb b/spec/helpers/admin_comments_helper_spec.rb index d8d938b529..8951019325 100644 --- a/spec/helpers/admin_comments_helper_spec.rb +++ b/spec/helpers/admin_comments_helper_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe AdminCommentsHelper do - include AdminCommentsHelper describe '#comment_labels' do - it 'adds no labels if the comment is not noteworthy' do expect(comment_labels(Comment.new)).to eq('') end @@ -16,5 +14,4 @@ expect(comment_labels(comment)).to eq(html) end end - end diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb index 3b1bbf1162..5355f22f77 100644 --- a/spec/helpers/admin_helper_spec.rb +++ b/spec/helpers/admin_helper_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe AdminHelper do - include AdminHelper include ERB::Util describe '#comment_visibility' do - it 'shows the status of a visible comment' do comment = FactoryBot.build(:visible_comment) expect(comment_visibility(comment)).to eq('Visible') @@ -16,11 +14,9 @@ comment = FactoryBot.build(:hidden_comment) expect(comment_visibility(comment)).to eq('Hidden') end - end describe '#sort_order_humanized' do - it 'returns the humanized value if one is available' do expect(sort_order_humanized('name_asc')).to eq('Name ▲') end @@ -32,18 +28,15 @@ it 'accepts a Symbol argument' do expect(sort_order_humanized(:name_asc)).to eq('Name ▲') end - end describe '#highlight_allow_new_responses_from' do - context 'anybody' do subject { highlight_allow_new_responses_from('anybody') } it 'does not highlight the default case' do expect(subject).to eq('anybody') end - end context 'authority_only' do @@ -53,7 +46,6 @@ expect(subject). to eq(%q(authority_only)) end - end context 'nobody' do @@ -63,7 +55,6 @@ expect(subject). to eq(%q(nobody)) end - end context 'an unhandled string' do @@ -72,8 +63,6 @@ it 'does not highlight an unhandled string' do expect(subject).to eq('unhandled') end - end - end end diff --git a/spec/helpers/admin_raw_emails_helper_spec.rb b/spec/helpers/admin_raw_emails_helper_spec.rb index c8ef72c91d..a382046ef8 100644 --- a/spec/helpers/admin_raw_emails_helper_spec.rb +++ b/spec/helpers/admin_raw_emails_helper_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe AdminRawEmailsHelper do - include AdminRawEmailsHelper describe '#address_list' do - it 'formats a list of addresses' do list = %w(a@example.com b@example.net @@ -34,7 +32,5 @@ it 'is html_safe' do expect(address_list('a@example.com')).to be_html_safe end - end - end diff --git a/spec/helpers/admin_users_helper_spec.rb b/spec/helpers/admin_users_helper_spec.rb index 7286215f03..37dbec2945 100644 --- a/spec/helpers/admin_users_helper_spec.rb +++ b/spec/helpers/admin_users_helper_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe AdminUsersHelper do - include AdminUsersHelper describe '#user_labels' do - it 'adds no labels if the user is not noteworthy' do expect(user_labels(User.new)).to eq('') end @@ -37,7 +35,5 @@ html += %q(admin) expect(user_labels(user)).to eq(html) end - end - end diff --git a/spec/helpers/alaveteli_pro/batch_request_authority_searches_helper_spec.rb b/spec/helpers/alaveteli_pro/batch_request_authority_searches_helper_spec.rb index 2b00b53dff..7785265b1e 100644 --- a/spec/helpers/alaveteli_pro/batch_request_authority_searches_helper_spec.rb +++ b/spec/helpers/alaveteli_pro/batch_request_authority_searches_helper_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::BatchRequestAuthoritySearchesHelper do - include AlaveteliPro::BatchRequestAuthoritySearchesHelper describe '#batch_authority_count' do @@ -56,5 +55,4 @@ ) end end - end diff --git a/spec/helpers/alaveteli_pro/dashboard_helpers_spec.rb b/spec/helpers/alaveteli_pro/dashboard_helpers_spec.rb index c025756997..70552f7c38 100644 --- a/spec/helpers/alaveteli_pro/dashboard_helpers_spec.rb +++ b/spec/helpers/alaveteli_pro/dashboard_helpers_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe AlaveteliPro::DashboardHelper do - include AlaveteliPro::DashboardHelper describe '#activity_item_description' do - it 'renders the activity_item description with links' do user = FactoryBot.create(:user) comment = FactoryBot.create(:comment, user: user) @@ -18,5 +16,4 @@ expect(activity_item_description(activity)).to eq expected end end - end diff --git a/spec/helpers/analytics_helper_spec.rb b/spec/helpers/analytics_helper_spec.rb index 5040ae4d7a..a2bd79bedc 100644 --- a/spec/helpers/analytics_helper_spec.rb +++ b/spec/helpers/analytics_helper_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AnalyticsHelper do - include AnalyticsHelper describe "#legacy_track_analytics_event" do @@ -80,9 +79,6 @@ }.to raise_error( ArgumentError, ':value option must be an Integer: "five"') end - end - end - end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index f74d073f7e..245cffcc86 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,21 +1,17 @@ require 'spec_helper' RSpec.describe ApplicationHelper do - include ApplicationHelper include LinkToHelper describe '#can_ask_the_eu?' do - it 'delegates to WorldFOIWebsites.can_ask_the_eu?' do expect(WorldFOIWebsites).to receive(:can_ask_the_eu?).with('US') can_ask_the_eu?('US') end - end describe '#render_flash' do - it 'returns a string when given a string' do expect(render_flash('some text')).to eq('some text') end @@ -24,11 +20,9 @@ flash = { 'inline' => 'some text' } expect(render_flash(flash)).to eq('some text') end - end describe '#read_asset_file' do - it "raises an Exception if it can't find the file" do expect { read_asset_file('nosuchfile.css') }. to raise_error(Sprockets::FileNotFound, @@ -45,11 +39,9 @@ expect(read_asset_file('responsive/application.css').encoding.to_s). to eq('UTF-8') end - end describe '#theme_installed?' do - let(:paths) { %w[theme_path app_path] } let(:view_paths) { double(ActionView::PathSet, paths: paths) } @@ -59,19 +51,15 @@ end context 'no theme is installed' do - let(:paths) { ['app_path'] } it 'returns false' do expect(theme_installed?).to eq false end - end - end describe '#theme_asset_exists?' do - let(:theme_view_path) do File.dirname(__FILE__) + "/../../lib/themes/alavetelitheme/lib/views" end @@ -105,7 +93,6 @@ end context 'without a theme installed' do - let(:paths) { [ app_view_path ] } it 'looks in the core app file path' do @@ -120,9 +107,7 @@ it 'returns true if the file exists' do expect(theme_asset_exists?('images/social-facebook.png')).to eq true end - end - end describe '#show_pro_upsell?' do @@ -161,13 +146,11 @@ end describe 'when creating an event description' do - it 'should generate a description for a request' do @info_request = FactoryBot.create(:info_request) @sent_event = @info_request.last_event expected = "Request sent to #{public_body_link_absolute(@info_request.public_body)} by #{request_user_link_absolute(@info_request)}" expect(event_description(@sent_event)).to match(expected) - end it 'should generate a description for a response' do @@ -183,7 +166,6 @@ expected = "Internal review request sent to #{public_body_link_absolute(@info_request_with_internal_review_request.public_body)} by #{request_user_link_absolute(@info_request_with_internal_review_request)}" expect(event_description(@response_event)).to match(expected) end - end describe 'site_wide_announcement' do @@ -204,5 +186,4 @@ expect(site_wide_announcement).to eq announcement end end - end diff --git a/spec/helpers/currency_helper_spec.rb b/spec/helpers/currency_helper_spec.rb index a0e9dcd354..84e5a82f5c 100644 --- a/spec/helpers/currency_helper_spec.rb +++ b/spec/helpers/currency_helper_spec.rb @@ -37,5 +37,4 @@ end end end - end diff --git a/spec/helpers/date_time_helper_spec.rb b/spec/helpers/date_time_helper_spec.rb index 07acda75a3..3ec0e26ec0 100644 --- a/spec/helpers/date_time_helper_spec.rb +++ b/spec/helpers/date_time_helper_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe DateTimeHelper do - include DateTimeHelper describe '#simple_date' do - it 'formats a date in html by default' do time = Time.utc(2012, 11, 07, 21, 30, 26) expect(self).to receive(:simple_date_html).with(time) @@ -22,11 +20,9 @@ time = Time.utc(2012, 11, 07, 21, 30, 26) expect { simple_date(time, format: :unknown) }.to raise_error(ArgumentError) end - end describe '#simple_date_html' do - it 'formats a date in a time tag' do Time.use_zone('London') do time = Time.utc(2012, 11, 07, 21, 30, 26) @@ -34,11 +30,9 @@ expect(simple_date_html(time)).to eq(expected) end end - end describe '#simple_date_text' do - it 'should respect time zones' do Time.use_zone('Australia/Sydney') do expect(simple_date_text(Time.utc(2012, 11, 07, 21, 30, 26))).to eq('November 08, 2012') @@ -48,11 +42,9 @@ it 'should handle Date objects' do expect(simple_date_text(Date.new(2012, 11, 21))).to eq('November 21, 2012') end - end describe '#simple_time' do - it 'returns 00:00:00 for a date' do expect(simple_time(Date.new(2012, 11, 21))).to eq('00:00:00') end @@ -66,6 +58,5 @@ time = Time.utc(2000, 'jan', 1, 20, 15, 1) expect(simple_time(time)).to eq('20:15:01') end - end end diff --git a/spec/helpers/health_checks_helper_spec.rb b/spec/helpers/health_checks_helper_spec.rb index 886ba2a672..84880e7fba 100644 --- a/spec/helpers/health_checks_helper_spec.rb +++ b/spec/helpers/health_checks_helper_spec.rb @@ -4,7 +4,6 @@ include HealthChecksHelper describe '#check_status' do - it 'warns that the check is failing' do check = double(message: 'Failed', ok?: false) expect(check_status(check)).to include('red') @@ -14,7 +13,5 @@ check = double(message: '', ok?: true) expect(check_status(check)).to include('style=""') end - end - end diff --git a/spec/helpers/highlight_helper_spec.rb b/spec/helpers/highlight_helper_spec.rb index c7e73ff679..88f260b679 100644 --- a/spec/helpers/highlight_helper_spec.rb +++ b/spec/helpers/highlight_helper_spec.rb @@ -4,7 +4,6 @@ include HighlightHelper describe '#highlight_and_excerpt' do - it 'excerpts text and highlights phrases' do text = "Quentin Nobble-Boston, Permanent Under-Secretary, Department for Humpadinking" phrases = ['humpadinking'] @@ -20,7 +19,6 @@ end context 'multiple matches' do - it 'highlights multiple matches' do text = <<-EOF Quentin Nobble-Boston, Permanent Under-Secretary, Department for Humpadinking @@ -48,13 +46,10 @@ matches = [/\b(humpadink\w*)\b/iu] expect(highlight_and_excerpt(text, matches, 15)).to eq(expected) end - end - end describe '#highlight_matches' do - it 'highlights' do assert_equal( "This is a beautiful morning", @@ -159,11 +154,9 @@ highlight_matches("one two three", %w[one two three]) { |word| "#{word}" } ) end - end describe '#excerpt' do - it 'excerpts' do assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", radius: 5)) assert_equal("This is a...", excerpt("This is a beautiful morning", "this", radius: 5)) @@ -240,7 +233,5 @@ assert_equal excerpt('This is a beautiful morning', 'a'), excerpt('This is a beautiful morning', 'a', separator: nil) end - end - end diff --git a/spec/helpers/info_request_helper_spec.rb b/spec/helpers/info_request_helper_spec.rb index a25c1d3185..a5ba41b807 100644 --- a/spec/helpers/info_request_helper_spec.rb +++ b/spec/helpers/info_request_helper_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequestHelper do - include InfoRequestHelper describe '#status_text' do @@ -33,7 +32,6 @@ end context 'waiting_response' do - it 'returns a description' do travel_to(Time.zone.parse('2014-12-31')) @@ -58,7 +56,6 @@ end context 'the body is not subject to foi' do - it 'links to the authorities section of the help page' do body.add_tag_if_not_already_present('foi_no') @@ -70,13 +67,10 @@ expect(status_text(info_request)).to include(expected) end - end - end context 'waiting_response_overdue' do - let(:body_link) do %Q(#{ body.name }) end @@ -103,7 +97,6 @@ end context 'the body is not subject to foi' do - it 'the description does not describe a legal obligation to reply' do body.add_tag_if_not_already_present('foi_no') @@ -129,14 +122,10 @@ travel_back end - end - end - context 'waiting_response_very_overdue' do - let(:body_link) do %Q(#{ body.name }) end @@ -166,7 +155,6 @@ end context 'the body is not subject to foi' do - it 'the description does not describe a legal obligation to reply' do body.add_tag_if_not_already_present('foi_no') @@ -197,7 +185,6 @@ travel_back end - end it 'does not add a followup link for external requests' do @@ -223,11 +210,9 @@ travel_back end - end context 'not_held' do - it 'returns a description' do body_link = %Q(#{ body.name }) @@ -238,11 +223,9 @@ expect(status_text(info_request)).to eq(expected) end - end context 'rejected' do - it 'returns a description' do body_link = %Q(#{ body.name }) @@ -252,31 +235,25 @@ expect(status_text(info_request)).to eq(expected) end - end context 'successful' do - it 'returns a description' do expected = 'The request was successful.' allow(info_request).to receive(:calculate_status).and_return("successful") expect(status_text(info_request)).to eq(expected) end - end context 'partially_successful' do - it 'returns a description' do expected = 'The request was partially successful.' allow(info_request).to receive(:calculate_status).and_return("partially_successful") expect(status_text(info_request)).to eq(expected) end - end context 'waiting_clarification' do - before do allow(info_request).to receive(:calculate_status).and_return("waiting_clarification") end @@ -330,22 +307,18 @@ status_text(info_request, is_owning_user: false) }.to raise_error(KeyError) end - end context 'gone_postal' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("gone_postal") expected = 'The authority would like to / has responded by ' \ 'postal mail to this request.' expect(status_text(info_request)).to eq(expected) end - end context 'internal_review' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("internal_review") expected = "Waiting for an internal review by " \ @@ -353,11 +326,9 @@ "of their handling of this request." expect(status_text(info_request)).to eq(expected) end - end context 'error_message' do - it 'returns a description' do allow(info_request). to receive(:public_body).and_return(double(url_name: 'foo')) @@ -372,22 +343,18 @@ expect(status_text(info_request)).to eq(expected) end - end context 'requires_admin' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("requires_admin") expected = 'This request has had an unusual response, and ' \ 'requires attention from the Alaveteli team.' expect(status_text(info_request)).to eq(expected) end - end context 'user_withdrawn' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("user_withdrawn") expected = 'This request has been withdrawn by the ' \ @@ -395,40 +362,33 @@ 'correspondence below.' expect(status_text(info_request)).to eq(expected) end - end context 'attention_requested' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("attention_requested") expected = 'This request has been reported as ' \ 'needing administrator attention.' expect(status_text(info_request)).to eq(expected) end - end context 'vexatious' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("vexatious") expected = 'This request has been reviewed by an administrator ' \ 'and is considered to be vexatious' expect(status_text(info_request)).to eq(expected) end - end context 'not_foi' do - it 'returns a description' do allow(info_request).to receive(:calculate_status).and_return("not_foi") expected = 'This request has been reviewed by an administrator ' \ 'and is considered not to be an FOI request' expect(status_text(info_request)).to eq(expected) end - end context 'awaiting_description' do @@ -577,13 +537,9 @@ render_to_file: false, old_unclassified: false) end - end - end - end - end describe '#js_correspondence_navigation' do @@ -611,7 +567,6 @@ jpeg_attachment)). to match('images/content_type/icon_image_jpeg_large.png') end - end context 'if no icon exists for the filetype' do @@ -626,7 +581,6 @@ to match('images/content_type/icon_unknown.png') end end - end describe '#attachment_path' do @@ -712,5 +666,4 @@ end end end - end diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index f3c76971cb..7b452fb537 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -42,7 +42,6 @@ url = incoming_message_url(incoming_message, cachebust: true) expect(url).to include("nocache=incoming-#{incoming_message.id}") end - end context 'for internal links' do diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb index 60b0cad328..a4886eca46 100644 --- a/spec/helpers/public_body_helper_spec.rb +++ b/spec/helpers/public_body_helper_spec.rb @@ -4,7 +4,6 @@ include PublicBodyHelper describe '#public_body_not_requestable_reasons' do - before do @body = FactoryBot.build(:public_body) end @@ -44,12 +43,9 @@ expect(reasons[1]).to match(/does not apply/) expect(reasons[2]).to match(/Make a request/) end - end - describe '#type_of_authority' do - it 'falls back to "A public authority"' do public_body = FactoryBot.build(:public_body) expect(type_of_authority(public_body)).to eq('A public authority') @@ -62,7 +58,6 @@ heading.add_category(category) public_body = FactoryBot.create(:public_body, tag_string: 'spec') - expect(type_of_authority(public_body)).to eq('Ünicode category') end @@ -78,9 +73,7 @@ expect(type_of_authority(public_body)).to eq(expected) end - context 'when associated with one category' do - it 'returns the description wrapped in an anchor tag' do category = FactoryBot.create(:public_body_category, category_tag: 'spec', description: 'spec category') @@ -94,7 +87,6 @@ end context 'when associated with several categories' do - it 'joins the category descriptions and capitalizes the first letter' do heading = FactoryBot.create(:public_body_heading) 3.times do |i| @@ -114,11 +106,9 @@ expect(type_of_authority(public_body)).to eq(description) end - end context 'when in a non-default locale' do - it 'creates the anchor href in the correct locale' do # Activate the routing filter, normally turned off for helper tests RoutingFilter.active = true @@ -133,9 +123,6 @@ expect(type_of_authority(public_body)).to eq(anchor) end end - end - end - end diff --git a/spec/helpers/stripe_helper_spec.rb b/spec/helpers/stripe_helper_spec.rb index b89f130ce4..02e461cdcd 100644 --- a/spec/helpers/stripe_helper_spec.rb +++ b/spec/helpers/stripe_helper_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe StripeHelper do - describe '#stripe_locale' do - class MockHelper include StripeHelper @@ -15,19 +13,13 @@ def initialize(locale) subject { MockHelper.new(locale).stripe_locale } context 'current local supported by Stripe' do - let(:locale) { 'en' } it { is_expected.to eq 'en' } - end context 'current local not supported by Stripe' do - let(:locale) { 'cy' } it { is_expected.to eq 'auto' } - end - end - end diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb index 2f4cb7b410..19afdadd6c 100644 --- a/spec/helpers/track_helper_spec.rb +++ b/spec/helpers/track_helper_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe TrackHelper do - include TrackHelper include LinkToHelper describe '#unsubscribe_notice' do - context 'with a search track' do let(:track_thing) { FactoryBot.build(:search_track) } @@ -15,7 +13,6 @@ 'Example%20Query/newest/advanced">this search.' expect(unsubscribe_notice(track_thing)).to eq(expected) end - end context 'with a user track' do @@ -26,7 +23,6 @@ "'#{ user_link(track_thing.tracked_user) }', a person." expect(unsubscribe_notice(track_thing)).to eq(expected) end - end context 'with a public body track' do @@ -38,7 +34,6 @@ "public authority." expect(unsubscribe_notice(track_thing)).to eq(expected) end - end context 'with a successful request track' do @@ -49,7 +44,6 @@ 'successful requests.' expect(unsubscribe_notice(track_thing)).to eq(expected) end - end context 'with a new request track' do @@ -60,7 +54,6 @@ 'new requests.' expect(unsubscribe_notice(track_thing)).to eq(expected) end - end context 'with a request update track' do @@ -71,13 +64,10 @@ "'#{ request_link(track_thing.info_request) }', a request." expect(unsubscribe_notice(track_thing)).to eq(expected) end - end - end describe 'when displaying notices for a search track' do - before do @track_thing = FactoryBot.build(:search_track) end @@ -101,11 +91,9 @@ expected = %Q(anything matching text 'Example Query') expect(track_description(@track_thing)).to eq(expected) end - end describe 'when displaying notices for a user track' do - before do @track_thing = FactoryBot.build(:user_track) end @@ -129,11 +117,9 @@ expected = %Q('#{user_link(@track_thing.tracked_user)}', a person) expect(track_description(@track_thing)).to eq(expected) end - end describe 'when displaying notices for a public body track' do - before do @track_thing = FactoryBot.build(:public_body_track) end @@ -160,7 +146,6 @@ end describe 'when displaying notices for a successful request track' do - before do @track_thing = FactoryBot.build(:successful_request_track) end @@ -187,7 +172,6 @@ end describe 'when displaying notices for a new request track' do - before do @track_thing = FactoryBot.build(:new_request_track) end @@ -211,11 +195,9 @@ expected = %Q(new requests) expect(track_description(@track_thing)).to eq(expected) end - end describe 'when displaying notices for a request update track' do - before do @track_thing = FactoryBot.build(:request_update_track) end @@ -239,7 +221,5 @@ expected = %Q('#{request_link(@track_thing.info_request)}', a request) expect(track_description(@track_thing)).to eq(expected) end - end - end diff --git a/spec/helpers/widget_helper_spec.rb b/spec/helpers/widget_helper_spec.rb index 81c4f26063..f3be9e0e2b 100644 --- a/spec/helpers/widget_helper_spec.rb +++ b/spec/helpers/widget_helper_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe WidgetHelper do - include WidgetHelper describe '#status_description' do - before do @info_request = FactoryBot.build(:info_request) end @@ -22,7 +20,5 @@ it 'should return unknown for an unknown status' do expect(status_description(@info_request, 'special_status')).to eq('Unknown') end - end - end diff --git a/spec/integration/admin_censor_rule_spec.rb b/spec/integration/admin_censor_rule_spec.rb index e8a4e8f687..7b2e626eb9 100644 --- a/spec/integration/admin_censor_rule_spec.rb +++ b/spec/integration/admin_censor_rule_spec.rb @@ -44,7 +44,6 @@ end describe "Authority censor rules" do - it 'clears the cache for existing requests when a new rule is added' do url_title = request.url_title visit show_request_path url_title: url_title @@ -114,11 +113,9 @@ expect(page).not_to have_content "I have a [REDACTED] answer for you" expect(page).to have_content "I have a rubbish answer for you" end - end describe "User censor rules" do - it 'clears the cache for existing requests when a new rule is added' do url_title = request.url_title visit show_request_path url_title: url_title @@ -188,11 +185,9 @@ expect(page).not_to have_content "I have a [REDACTED] answer for you" expect(page).to have_content "I have a rubbish answer for you" end - end describe "Request censor rules" do - it 'clears the cache for existing requests when a new rule is added' do request_id = request.id url_title = request.url_title @@ -265,11 +260,9 @@ expect(page).not_to have_content "I have a [REDACTED] answer for you" expect(page).to have_content "I have a rubbish answer for you" end - end describe "Global censor rules" do - it 'clears the cache for existing requests when a new rule is added' do url_title = request.url_title visit show_request_path url_title: url_title @@ -337,7 +330,5 @@ expect(page).not_to have_content "I have a [REDACTED] answer for you" expect(page).to have_content "I have a rubbish answer for you" end - end - end diff --git a/spec/integration/admin_import_csv_spec.rb b/spec/integration/admin_import_csv_spec.rb index 8c21fe99c7..b1f4f059f7 100644 --- a/spec/integration/admin_import_csv_spec.rb +++ b/spec/integration/admin_import_csv_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Importing a CSV' do - before do allow(AlaveteliConfiguration).to receive(:skip_admin_auth).and_return(false) @@ -26,5 +25,4 @@ expect(page).to have_content(expected) end end - end diff --git a/spec/integration/admin_outgoing_message_edit_spec.rb b/spec/integration/admin_outgoing_message_edit_spec.rb index ac64e5e019..e6df88bca9 100644 --- a/spec/integration/admin_outgoing_message_edit_spec.rb +++ b/spec/integration/admin_outgoing_message_edit_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Editing the OutgoingMessage body' do - let(:request) { FactoryBot.create(:info_request) } let(:ogm) { request.outgoing_messages.first } @@ -24,7 +23,6 @@ end context 'a censor rule applies to the request' do - before do FactoryBot.create(:info_request_censor_rule, text: 'information', @@ -66,7 +64,5 @@ expect(event.params). to include(body: 'Some information please. And a biscuit.') end - end - end diff --git a/spec/integration/admin_public_body_category_edit_spec.rb b/spec/integration/admin_public_body_category_edit_spec.rb index 3028a3029e..b1dea8d241 100644 --- a/spec/integration/admin_public_body_category_edit_spec.rb +++ b/spec/integration/admin_public_body_category_edit_spec.rb @@ -50,7 +50,6 @@ fill_in 'public_body_category_translations_attributes_es_title', with: 'New Category ES' fill_in 'public_body_category_translations_attributes_es_description', with: 'ES Description' click_button 'Save' - end @category.reload AlaveteliLocalization.with_locale(:fr) do @@ -61,5 +60,4 @@ expect(@category.title).to eq('New Category ES') end end - end diff --git a/spec/integration/admin_public_body_category_new_spec.rb b/spec/integration/admin_public_body_category_new_spec.rb index f02308a79a..ac3ea135eb 100644 --- a/spec/integration/admin_public_body_category_new_spec.rb +++ b/spec/integration/admin_public_body_category_new_spec.rb @@ -32,5 +32,4 @@ expect(page).to have_content("Description can't be blank") end end - end diff --git a/spec/integration/admin_public_body_heading_edit_spec.rb b/spec/integration/admin_public_body_heading_edit_spec.rb index ca3ea9bdff..512f572afe 100644 --- a/spec/integration/admin_public_body_heading_edit_spec.rb +++ b/spec/integration/admin_public_body_heading_edit_spec.rb @@ -57,5 +57,4 @@ expect(@heading.name).to eq('New Heading ES') end end - end diff --git a/spec/integration/admin_public_body_new_spec.rb b/spec/integration/admin_public_body_new_spec.rb index 5cab3df891..56195e784c 100644 --- a/spec/integration/admin_public_body_new_spec.rb +++ b/spec/integration/admin_public_body_new_spec.rb @@ -19,5 +19,4 @@ expect(page).to have_content('successfully created') end end - end diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb index edfc4c0a96..f0be089699 100644 --- a/spec/integration/admin_spec.rb +++ b/spec/integration/admin_spec.rb @@ -30,7 +30,6 @@ end it "allows redelivery of an incoming message to a closed request" do - # close request info_request = FactoryBot.create(:info_request_with_incoming) close_request(info_request) @@ -114,7 +113,6 @@ end describe 'when administering the holding pen' do - it "shows a rejection reason for an incoming message from an invalid address" do info_request = FactoryBot.create(:info_request, allow_new_responses_from: 'authority_only', @@ -130,7 +128,6 @@ end describe 'generating an upload url' do - it 'shows a flash message with instructions on forwarding the url' do request = FactoryBot.create(:info_request) authority_name = request.public_body.name @@ -151,13 +148,10 @@ expect(page).to have_link(url, href: url) expect(page).to have_content(message) end - end - end describe 'hide and notify' do - let(:user) { FactoryBot.create(:user, name: "Awkward > Name") } let(:request) { FactoryBot.create(:info_request, user: user) } @@ -181,7 +175,5 @@ to have_content('Your message to Awkward > Name has been sent') end end - end - end diff --git a/spec/integration/admin_user_controller_edit_spec.rb b/spec/integration/admin_user_controller_edit_spec.rb index 91a1cf7b98..b4bdcef0c9 100644 --- a/spec/integration/admin_user_controller_edit_spec.rb +++ b/spec/integration/admin_user_controller_edit_spec.rb @@ -14,7 +14,6 @@ end context 'when a user is banned' do - it 're-editing does not change their url_name' do using_session(@admin) do visit edit_admin_user_path(@user) @@ -24,7 +23,5 @@ expect(@user.reload.url_name).to eq('nasty_user_123') end - end - end diff --git a/spec/integration/alaveteli_dsl.rb b/spec/integration/alaveteli_dsl.rb index 98d2999b34..4314d3f9f3 100644 --- a/spec/integration/alaveteli_dsl.rb +++ b/spec/integration/alaveteli_dsl.rb @@ -1,5 +1,4 @@ module AlaveteliDsl - def browse_request(url_title) visit "/request/#{url_title}" end diff --git a/spec/integration/alaveteli_pro/add_remove_embargo_spec.rb b/spec/integration/alaveteli_pro/add_remove_embargo_spec.rb index 2f6e1e770c..7140b2470a 100644 --- a/spec/integration/alaveteli_pro/add_remove_embargo_spec.rb +++ b/spec/integration/alaveteli_pro/add_remove_embargo_spec.rb @@ -2,13 +2,11 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Adding/removing embargoes from requests' do - let(:pro_user) { FactoryBot.create(:pro_user) } let(:user) { FactoryBot.create(:user) } let!(:user_session) { login(user) } describe "adding an embargo to a request" do - let!(:info_request) do FactoryBot.create(:info_request, user: pro_user, title: 'My awesome request') @@ -36,11 +34,9 @@ expect(page).not_to have_content(info_request.title) end end - end describe 'removing an embargo from a request' do - let!(:info_request) do request = FactoryBot.create(:info_request, user: pro_user, title: 'My embargoed request') @@ -70,6 +66,5 @@ expect(page).to have_content(info_request.title) end end - end end diff --git a/spec/integration/alaveteli_pro/admin_spec.rb b/spec/integration/alaveteli_pro/admin_spec.rb index eac0bfd799..f941eebb5b 100644 --- a/spec/integration/alaveteli_pro/admin_spec.rb +++ b/spec/integration/alaveteli_pro/admin_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe "administering requests" do - before do update_xapian_index end @@ -39,9 +38,6 @@ end end end - end - end - end diff --git a/spec/integration/alaveteli_pro/batch_request_spec.rb b/spec/integration/alaveteli_pro/batch_request_spec.rb index 8c20822dc5..5ac3bdea6e 100644 --- a/spec/integration/alaveteli_pro/batch_request_spec.rb +++ b/spec/integration/alaveteli_pro/batch_request_spec.rb @@ -81,7 +81,6 @@ def search_results expect(first_page_results.include?(second_page_result)).to be false - # Adding to list # We can't rely on Xapian to give us a deterministic search result # ordering so we pluck some bodies out of the results we see @@ -224,7 +223,6 @@ def search_results expect(page).to have_content( "Requests in this batch will be private until " \ "#{AlaveteliPro::Embargo.three_months_from_now.strftime('%-d %B %Y')}") - end end @@ -328,7 +326,6 @@ def search_results end describe "managing embargoes on a batch request's page" do - it "allows the user to extend all the embargoes that are near expiry" do batch.info_requests.each do |info_request| info_request. diff --git a/spec/integration/alaveteli_pro/receive_response_spec.rb b/spec/integration/alaveteli_pro/receive_response_spec.rb index a5bb4c0ed9..e2dda15a0e 100644 --- a/spec/integration/alaveteli_pro/receive_response_spec.rb +++ b/spec/integration/alaveteli_pro/receive_response_spec.rb @@ -21,7 +21,5 @@ expect(page).to have_css("#info-request-#{info_request.id}") end end - end - end diff --git a/spec/integration/alaveteli_pro/view_batch_request_spec.rb b/spec/integration/alaveteli_pro/view_batch_request_spec.rb index 5154953b66..fcd494ce22 100644 --- a/spec/integration/alaveteli_pro/view_batch_request_spec.rb +++ b/spec/integration/alaveteli_pro/view_batch_request_spec.rb @@ -14,7 +14,6 @@ let(:embargo) { info_request.embargo } context 'a pro user viewing one of their own requests' do - it 'allows the user to view the request' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -25,7 +24,6 @@ include_examples 'allows annotations' context 'the request is not embargoed' do - it 'does not show an embargo end date' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -41,7 +39,6 @@ end context 'the user does not have a pro account' do - before do pro_user.remove_role(:pro) end @@ -54,13 +51,10 @@ end include_examples 'prevents setting an embargo' - end - end context 'the request is embargoed' do - let(:batch) do FactoryBot.create(:info_request_batch, :sent, :embargoed, user: pro_user) @@ -99,7 +93,6 @@ include_examples 'allows followups' context 'the embargo is expiring soon' do - before do embargo.update_attribute(:publish_at, embargo.publish_at - 88.days) info_request.reload @@ -111,11 +104,9 @@ expect(page).to have_content "Keep private for" end end - end context 'the embargo is not expiring soon' do - it 'does not show the option to extend the embargo' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -135,11 +126,9 @@ "period from #{expiring_notification}") end end - end context 'the user does not have pro status' do - before do pro_user.remove_role(:pro) end @@ -150,15 +139,11 @@ expect(page).not_to have_content "Keep private for" end end - end context 'the request has received a response' do it_behaves_like 'a request with response' end - end - end - end diff --git a/spec/integration/alaveteli_pro/view_request_spec.rb b/spec/integration/alaveteli_pro/view_request_spec.rb index fe3473631c..607f21c299 100644 --- a/spec/integration/alaveteli_pro/view_request_spec.rb +++ b/spec/integration/alaveteli_pro/view_request_spec.rb @@ -8,7 +8,6 @@ let!(:pro_user_session) { login(pro_user) } context 'a pro user viewing one of their own requests' do - it 'allows the user to view the request' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -19,7 +18,6 @@ include_examples 'allows annotations' context 'the request is not embargoed' do - it 'shows the privacy sidebar' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -49,7 +47,6 @@ end context 'the user does not have a pro account' do - before do pro_user.remove_role(:pro) end @@ -67,13 +64,10 @@ expect(page).not_to have_content "Keep private for" end end - end - end context 'the request is embargoed' do - let!(:embargo) do FactoryBot.create(:embargo, info_request: info_request) end @@ -102,19 +96,16 @@ include_examples 'allows the embargo to be lifted' context 'the user does not have pro status' do - before do pro_user.remove_role(:pro) end include_examples 'prevents setting an embargo' - end include_examples 'allows followups' context 'the embargo is expiring soon' do - before do embargo.update_attribute(:publish_at, embargo.publish_at - 88.days) info_request.reload @@ -137,11 +128,9 @@ to have_content("This request is private until " \ "#{expected.strftime('%-d %B %Y')}") end - end context 'the user does not have pro status' do - before do pro_user.remove_role(:pro) end @@ -155,13 +144,10 @@ expect(page).not_to have_content('Keep private for a further:') end end - end - end context 'the embargo is not expiring soon' do - it 'does not show the user the extend embargo section' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -185,7 +171,6 @@ end context 'the user does not have pro status' do - before do pro_user.remove_role(:pro) end @@ -201,19 +186,13 @@ to_not have_content("You will be able to extend this privacy " \ "period from #{expiring_notification}") end - end - end - end context 'the request has received a response' do it_behaves_like 'a request with response' end - end - end - end diff --git a/spec/integration/change_email_address_spec.rb b/spec/integration/change_email_address_spec.rb index 61ad1464af..58783a4c65 100644 --- a/spec/integration/change_email_address_spec.rb +++ b/spec/integration/change_email_address_spec.rb @@ -5,7 +5,6 @@ let(:user) { FactoryBot.create(:user) } it "sends a confirmation email if you get all the details right" do - using_session(login(user)) do visit signchangeemail_path fill_in "signchangeemail_old_email", with: user.email diff --git a/spec/integration/classify_request_spec.rb b/spec/integration/classify_request_spec.rb index 4af915453c..dc12ce406e 100644 --- a/spec/integration/classify_request_spec.rb +++ b/spec/integration/classify_request_spec.rb @@ -2,12 +2,10 @@ require 'integration/alaveteli_dsl' RSpec.describe 'classifying a request' do - let(:info_request) { FactoryBot.create(:info_request) } let(:user) { info_request.user } shared_examples_for 'authority is not subject to FOI law' do - it 'does not include "By law"' do info_request.public_body.add_tag_if_not_already_present('foi_no') using_session(login(user)) do @@ -15,22 +13,18 @@ expect(page).not_to have_content('By law') end end - end shared_examples_for 'authority is subject to FOI law' do - it 'does includes the text "By law"' do using_session(login(user)) do classify_request(info_request, classification) expect(page).to have_content('By law') end end - end shared_examples_for 'the donation link is configured' do - it 'shows the donation link' do allow(AlaveteliConfiguration).to receive(:donation_url). and_return('http://donations.example.com') @@ -43,13 +37,10 @@ href: 'http://donations.example.com') end end - end context 'when the request is internal' do - describe 'the requestor tries to classify their request' do - it 'sends an email including the message' do using_session(login(user)) do visit message_classification_path( @@ -73,7 +64,6 @@ end context 'marking request as error_message' do - let(:classification) { 'error_message1' } it 'displays a thank you message post redirect' do @@ -110,11 +100,9 @@ ) end end - end context 'marking request as internal_review' do - let(:classification) { 'internal_review1' } it 'displays a thank you message post redirect' do @@ -129,11 +117,9 @@ anchor: 'internal_review')) end end - end context 'marking request as not_held' do - let(:classification) { 'not_held1' } it 'displays a thank you message post redirect' do @@ -146,11 +132,9 @@ href: unhappy_url(info_request)) end end - end context 'marking request as partially_successful' do - let(:classification) { 'partially_successful1' } it 'displays a thank you message post redirect' do @@ -164,11 +148,9 @@ end include_examples 'the donation link is configured' - end context 'marking request as rejected' do - let(:classification) { 'rejected1' } it 'displays a thank you message post redirect' do @@ -179,11 +161,9 @@ expect(page).to have_content(message) end end - end context 'marking request as requires_admin' do - let(:classification) { 'requires_admin1' } it 'displays a thank you message post redirect' do @@ -220,11 +200,9 @@ ) end end - end context 'marking request as successful' do - let(:classification) { 'successful1' } it 'displays a thank you message post redirect' do @@ -244,7 +222,6 @@ include_examples 'the donation link is configured' context 'when annotations are disabled' do - before do allow_any_instance_of(ApplicationController). to receive(:feature_enabled?). @@ -257,7 +234,6 @@ end it 'does not display the annotations part of the message' do - using_session(login(user)) do classify_request(info_request, classification) message = "We're glad you got all the information that you wanted." @@ -266,15 +242,11 @@ expect(page).to have_content(message) expect(page).to_not have_content(unexpected) end - end - end - end context 'marking request as user_withdrawn' do - let(:classification) { 'user_withdrawn1' } it 'displays a thank you message post redirect' do @@ -287,11 +259,9 @@ expect(page).to have_content(message) end end - end context 'marking request as waiting_clarification' do - let(:classification) { 'waiting_clarification1' } it 'displays a thank you message post redirect' do @@ -303,11 +273,9 @@ expect(page).to have_content(message) end end - end context 'marking request as waiting_response' do - let(:classification) { 'waiting_response1' } it 'displays a thank you message post redirect' do @@ -322,11 +290,9 @@ include_examples 'authority is not subject to FOI law' include_examples 'authority is subject to FOI law' - end context 'marking overdue request as waiting_response' do - let(:classification) { 'waiting_response1' } before do @@ -349,11 +315,9 @@ include_examples 'authority is not subject to FOI law' include_examples 'authority is subject to FOI law' - end context 'marking very overdue request as waiting_responses' do - let(:classification) { 'waiting_response1' } before do @@ -372,7 +336,5 @@ expect(page).to have_content(message) end end - end - end diff --git a/spec/integration/cookie_stripping_spec.rb b/spec/integration/cookie_stripping_spec.rb index cceedd2bea..f4298d9352 100644 --- a/spec/integration/cookie_stripping_spec.rb +++ b/spec/integration/cookie_stripping_spec.rb @@ -2,10 +2,8 @@ require 'integration/alaveteli_dsl' RSpec.describe 'when making stripping cookies' do - it 'should not set a cookie when no significant session data is set' do get '/country_message' expect(response.headers['Set-Cookie']).to be_blank end - end diff --git a/spec/integration/create_request_spec.rb b/spec/integration/create_request_spec.rb index 6b456751d1..3e06ddc89e 100644 --- a/spec/integration/create_request_spec.rb +++ b/spec/integration/create_request_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe "When creating requests" do - before do update_xapian_index end @@ -32,11 +31,9 @@ # not the admin who confirmed it expect(info_request.user_id).to eq(post_redirect.user_id) end - end context 'the authority name contains an apostrophe' do - let(:user) { FactoryBot.create(:user) } let(:user_session) { login(user) } let(:public_body) do @@ -84,7 +81,5 @@ expect(page).to have_content("Dear Test's html authority") end end - end - end diff --git a/spec/integration/download_request_spec.rb b/spec/integration/download_request_spec.rb index 3601038aa5..d722b051bb 100644 --- a/spec/integration/download_request_spec.rb +++ b/spec/integration/download_request_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe 'when making a zipfile available' do - after do FileUtils.rm_rf(InfoRequest.download_zip_dir) end @@ -34,7 +33,6 @@ def sleep_and_receive_mail(name, info_request) end context 'when an html to pdf converter is supplied' do - before do # We want to test the contents of the pdf, and we don't know whether a # particular instance will have a working tool, so just copy the HTML @@ -47,10 +45,8 @@ def sleep_and_receive_mail(name, info_request) end context 'when an incoming message is made "requester_only"' do - it 'should not include the incoming message or attachments in a download of the entire request by a non-request owner but should retain them for owner and admin' do - # Non-owner can download zip with incoming and attachments non_owner = login(FactoryBot.create(:user)) info_request = FactoryBot.create(:info_request_with_pdf_attachment) @@ -91,16 +87,12 @@ def sleep_and_receive_mail(name, info_request) expect(zip.count).to eq(2) expect(zip.read('correspondence.pdf')).to match('hereisthetext') end - end - end context 'when an outgoing message is made "requester_only"' do - it 'should not include the outgoing message in a download of the entire request by a non-request owner but should retain them for owner and admin' do - # Non-owner can download zip with outgoing non_owner = login(FactoryBot.create(:user)) info_request = FactoryBot.create(:info_request) @@ -140,13 +132,10 @@ def sleep_and_receive_mail(name, info_request) expect(zip.count).to eq(1) expect(zip.read('correspondence.pdf')).to match('Some information please') end - end - end context 'when a message contains redacted material' do - it 'should use associated censor rules on outgoing messages' do non_owner = login(FactoryBot.create(:user)) info_request = FactoryBot.create(:info_request) @@ -188,21 +177,16 @@ def sleep_and_receive_mail(name, info_request) expect(zip.read('2_2_hello world.txt')).to match('Second hello') expect(zip.read('2_3_hello world.txt')).to match('REDACTED hello') end - end - end - end context 'when no html to pdf converter is supplied' do - before do allow(HTMLtoPDFConverter).to receive(:exist?).and_return(false) end it "should update the contents of the zipfile when the request changes" do - info_request = FactoryBot.create(:info_request_with_incoming, title: 'Example Title') request_owner = login(info_request.user) @@ -229,7 +213,6 @@ def sleep_and_receive_mail(name, info_request) end context 'when a request is "requester_only"' do - before do @non_owner = login(FactoryBot.create(:user)) @info_request = FactoryBot.create(:info_request_with_incoming, @@ -238,7 +221,6 @@ def sleep_and_receive_mail(name, info_request) @admin = login(FactoryBot.create(:admin_user)) end - it 'should allow a download of the request by the request owner and admin only' do # Requester can access the zip inspect_zip_download(@request_owner, @info_request) do |zip| @@ -263,7 +245,6 @@ def sleep_and_receive_mail(name, info_request) end context 'when a request is "hidden"' do - it 'should not allow a download of the request by an admin only' do @non_owner = login(FactoryBot.create(:user)) @info_request = FactoryBot.create(:info_request_with_incoming, @@ -289,14 +270,11 @@ def sleep_and_receive_mail(name, info_request) expect(zip.read('correspondence.txt')).to match('hereisthetext') end end - end context 'when an incoming message is made "requester_only"' do - it 'should not include the incoming message or attachments in a download of the entire request by a non-request owner but should retain them for owner and admin' do - # Non-owner can download zip with outgoing non_owner = login(FactoryBot.create(:user)) info_request = FactoryBot.create(:info_request_with_pdf_attachment) @@ -337,16 +315,12 @@ def sleep_and_receive_mail(name, info_request) expect(zip.count).to eq(2) expect(zip.read('correspondence.txt')).to match('hereisthetext') end - end - end context 'when an outgoing message is made "requester_only"' do - it 'should not include the outgoing message in a download of the entire request by a non-request owner but should retain them for owner and admin' do - # Non-owner can download zip with original message initially non_owner = login(FactoryBot.create(:user)) info_request = FactoryBot.create(:info_request) @@ -387,13 +361,10 @@ def sleep_and_receive_mail(name, info_request) expect(zip.count).to eq(1) expect(zip.read('correspondence.txt')).to match('Some information please') end - end - end context 'when a message contains redacted material' do - it 'should use associated censor rules on outgoing messages' do non_owner = login(FactoryBot.create(:user)) info_request = FactoryBot.create(:info_request) @@ -434,9 +405,7 @@ def sleep_and_receive_mail(name, info_request) expect(zip.read('2_2_hello world.txt')).to match('Second hello') expect(zip.read('2_3_hello world.txt')).to match("REDACTED hello") end - end - end it 'should successfully make a zipfile for an external request' do @@ -445,5 +414,4 @@ def sleep_and_receive_mail(name, info_request) inspect_zip_download(user, external_request) { |zip| expect(zip.count).to eq(1) } end end - end diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 7f3beb262c..228bd9298f 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe "When errors occur" do - before(:each) do # This should happen automatically before each test but doesn't with these integration # tests for some reason. @@ -10,18 +9,15 @@ context 'when considering all requests local (by default all in development)', local_requests: true do - it 'should show a full trace for general errors' do allow(InfoRequest).to receive(:find_by_url_title!).and_raise("An example error") get "/request/example" expect(response.body).to match('
English/) expect(response.body).to match(/#{@default_lang_home_link}/) end - end - end - end - end diff --git a/spec/integration/public_body_change_request_spec.rb b/spec/integration/public_body_change_request_spec.rb index 3f6c74b540..075b22ca11 100644 --- a/spec/integration/public_body_change_request_spec.rb +++ b/spec/integration/public_body_change_request_spec.rb @@ -2,14 +2,11 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Requesting changes to a public body' do - describe 'reporting an out of date email address' do - let(:public_body) { FactoryBot.create(:public_body) } let(:user) { FactoryBot.create(:user) } describe 'when not logged in' do - it "should not forget which public body you are updating during login" do visit show_public_body_path(url_name: public_body.url_name) click_link("Ask us to update FOI email") @@ -21,7 +18,6 @@ expect(page).to have_content "Ask us to update the email address" end - end end end diff --git a/spec/integration/reports_controller_spec.rb b/spec/integration/reports_controller_spec.rb index 959a306f40..d9494fcc7d 100644 --- a/spec/integration/reports_controller_spec.rb +++ b/spec/integration/reports_controller_spec.rb @@ -2,15 +2,12 @@ require 'integration/alaveteli_dsl' RSpec.describe ReportsController do - describe 'reporting a comment' do - let(:request) { FactoryBot.create(:info_request) } let(:comment) { FactoryBot.create(:comment, info_request: request) } let(:user) { FactoryBot.create(:user) } describe 'when not logged in' do - it "should redirect to the login page" do visit new_request_report_path(request_id: request.url_title, comment_id: comment.id) @@ -28,7 +25,6 @@ expect(page).to have_content "Report annotation on request" end - end end end diff --git a/spec/integration/request_controller_spec.rb b/spec/integration/request_controller_spec.rb index 690298115e..593405c6c6 100644 --- a/spec/integration/request_controller_spec.rb +++ b/spec/integration/request_controller_spec.rb @@ -2,9 +2,7 @@ require 'integration/alaveteli_dsl' RSpec.describe RequestController do - describe 'when the site is in read only mode' do - before do allow(AlaveteliConfiguration).to receive(:read_only). and_return("Down for maintenance") @@ -22,7 +20,6 @@ end context 'when annotations are disabled' do - before do allow_any_instance_of(ApplicationController). to receive(:feature_enabled?). @@ -43,13 +40,10 @@ visit new_request_path expect(page).to have_content(expected_message) end - end - end describe 'FOI officer uploading a reponse' do - let(:public_body) do FactoryBot.create(:public_body, request_email: "foi@example.com") end @@ -68,7 +62,5 @@ expect(page).to have_content(message) end end - end - end diff --git a/spec/integration/request_game_controller_spec.rb b/spec/integration/request_game_controller_spec.rb index e884a40618..6399cfe1db 100644 --- a/spec/integration/request_game_controller_spec.rb +++ b/spec/integration/request_game_controller_spec.rb @@ -2,9 +2,7 @@ require 'integration/alaveteli_dsl' RSpec.describe RequestGameController do - describe "classifying a request" do - let(:user) { FactoryBot.create(:user) } it 'displays a thank you message on completion' do @@ -26,7 +24,5 @@ expect(page).to have_content(message) end end - end - end diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb index d5265a1b6e..61425c184f 100644 --- a/spec/integration/search_request_spec.rb +++ b/spec/integration/search_request_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe "When searching" do - before(:each) do load_raw_emails_data update_xapian_index @@ -85,7 +84,6 @@ end context 'using JSON format' do - it 'should return JSON formatted results' do get '/feed/search/chicken.json' response_data = JSON.parse(response.body, symbolize_names: true) @@ -95,7 +93,6 @@ expect(response_data.first[:info_request][:title]). to eq('How much public money is wasted on breeding naughty chickens?') end - end it "should search for requests made to a tagged set of public authorities" do diff --git a/spec/integration/send_user_message_spec.rb b/spec/integration/send_user_message_spec.rb index 39caf845c1..2d06c51cf0 100644 --- a/spec/integration/send_user_message_spec.rb +++ b/spec/integration/send_user_message_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Sending a message to another user' do - let(:sender) { FactoryBot.create(:user) } let(:recipient) { FactoryBot.create(:user, name: "Awkward > Name") } @@ -33,5 +32,4 @@ expect(page.body).to include(message) end end - end diff --git a/spec/integration/sign_in_with_redirect_spec.rb b/spec/integration/sign_in_with_redirect_spec.rb index baf191ad7a..217587d11d 100644 --- a/spec/integration/sign_in_with_redirect_spec.rb +++ b/spec/integration/sign_in_with_redirect_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Signing in with a redirect parameter', local_requests: false do - context 'when not logged in' do let(:user) { FactoryBot.create(:user) } @@ -27,7 +26,6 @@ login!(user, r: 'https://www.example.com/malicious') expect(response.status).to eq(404) end - end context 'when already logged in' do @@ -66,7 +64,6 @@ expect(response.status).to eq(404) end end - end def login!(user, params = {}) diff --git a/spec/integration/signin_spec.rb b/spec/integration/signin_spec.rb index ebd5dbf866..2ceac845ba 100644 --- a/spec/integration/signin_spec.rb +++ b/spec/integration/signin_spec.rb @@ -33,7 +33,6 @@ def try_login(user, options = {}) end context 'when you give the right credentials' do - it 'logs you in' do try_login(user, { redirect: '/list' }) expect(page). @@ -92,7 +91,6 @@ def try_login(user, options = {}) # And the redirect should still work, of course expect(page).to have_current_path '/list?post_redirect=1' - end end end diff --git a/spec/integration/track_alerts_spec.rb b/spec/integration/track_alerts_spec.rb index 8f843596e7..3b0a87a0d8 100644 --- a/spec/integration/track_alerts_spec.rb +++ b/spec/integration/track_alerts_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe "When sending track alerts" do - before do # TODO: required to make sure xapian index can find files for raw emails # associated with fixtures - can be removed when fixtures no longer @@ -12,7 +11,6 @@ end it "should send alerts" do - info_request = FactoryBot.create(:info_request) user = FactoryBot.create(:user, last_daily_track_email: 3.days.ago) user_session = login(user) @@ -89,4 +87,3 @@ expect(mail.body).to include('el equipo de ') end end - diff --git a/spec/integration/user_profile_updates_spec.rb b/spec/integration/user_profile_updates_spec.rb index c0d4382009..93dbc7183e 100644 --- a/spec/integration/user_profile_updates_spec.rb +++ b/spec/integration/user_profile_updates_spec.rb @@ -2,13 +2,10 @@ require 'integration/alaveteli_dsl' RSpec.describe 'Updating your user profile' do - let(:user) { FactoryBot.create(:user) } describe 'updating about_me text' do - context "no profile picture set" do - it "page displays thank you message with nudge to upload photo" do using_session(login(user)) do msg = "Thanks for changing the text about you on your " \ @@ -21,11 +18,9 @@ expect(page).to have_content(msg) end end - end context "with profile picture set" do - before do user.create_profile_photo!(data: load_file_fixture('parrot.png')) end @@ -40,17 +35,13 @@ expect(page).to have_content(msg) end end - end - end describe 'adding a photo' do - let(:photo_file) { File.absolute_path('./spec/fixtures/files/parrot.jpg') } context "no about_me text set" do - it "page displays thank you message with nudge to upload photo" do using_session(login(user)) do msg = "Thanks for updating your profile photo.\n" \ @@ -72,11 +63,9 @@ expect(page).to have_content(msg) end end - end context "with about_me text set" do - before do user.about_me = "I am a test user" end @@ -93,8 +82,6 @@ expect(page).to have_content(msg) end end - end end - end diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 606f3e3616..20424be918 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -2,7 +2,6 @@ require 'integration/alaveteli_dsl' RSpec.describe "When viewing requests" do - before do @info_request = FactoryBot.create(:info_request) @unregistered = without_login @@ -34,7 +33,6 @@ end context "when a request is hidden by an admin" do - it 'should not retain any cached attachments to be served up by the webserver' do admin = login(FactoryBot.create(:admin_user)) non_owner = login(FactoryBot.create(:user)) @@ -73,17 +71,14 @@ attachment.reload }.to change { attachment.masked? }.from(true).to(false) end - end context 'when a response has prominence "normal"' do - before do @info_request = FactoryBot.create(:info_request_with_incoming) end it 'should show the message itself to any user' do - # unregistered unregistered = without_login using_session(unregistered) do @@ -109,11 +104,9 @@ expect(page).not_to have_content("This message has prominence 'hidden'.") end end - end context 'when a response has prominence "hidden"' do - before do @info_request = FactoryBot.create(:info_request_with_incoming) message = @info_request.incoming_messages.first @@ -124,7 +117,6 @@ it 'should show a hidden notice, not the message, to an unregistered user or the requester and the message itself to an admin ' do - # unregistered using_session(without_login) do browse_request(@info_request.url_title) @@ -153,11 +145,9 @@ expect(page).to have_content("You can only see it because you are logged in as a super user.") end end - end context 'when a response has prominence "requester_only"' do - before do @info_request = FactoryBot.create(:info_request_with_incoming) message = @info_request.incoming_messages.first @@ -168,7 +158,6 @@ it 'should show a hidden notice with login link to an unregistered user, and the message itself with a hidden note to the requester or an admin' do - # unregistered using_session(without_login) do browse_request(@info_request.url_title) @@ -196,11 +185,9 @@ expect(page).to have_content('You can only see it because you are logged in as a super user.') end end - end context 'when an outgoing message has prominence "requester_only"' do - before do @info_request = FactoryBot.create(:info_request) message = @info_request.outgoing_messages.first @@ -211,7 +198,6 @@ it 'should show a hidden notice with login link to an unregistered user, and the message itself with a hidden note to the requester or an admin' do - # unregistered using_session(without_login) do browse_request(@info_request.url_title) @@ -239,7 +225,5 @@ expect(page).to have_content('You can only see it because you are logged in as a super user.') end end - end - end diff --git a/spec/integration/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb index 76bc505735..a6f830d90a 100644 --- a/spec/integration/xapian_search_highlighting_spec.rb +++ b/spec/integration/xapian_search_highlighting_spec.rb @@ -1,4 +1,3 @@ - require 'spec_helper' RSpec.describe 'highlighting search results' do @@ -49,5 +48,4 @@ expect(highlight_matches(phrase, matches)).to eq('Māori') end - end diff --git a/spec/integration/zipping_pdf_files_spec.rb b/spec/integration/zipping_pdf_files_spec.rb index d008494139..58ed6b2304 100644 --- a/spec/integration/zipping_pdf_files_spec.rb +++ b/spec/integration/zipping_pdf_files_spec.rb @@ -2,7 +2,6 @@ require 'zip/filesystem' RSpec.describe 'zipping pdf files' do - it 'correctly records the size of the zipped file' do pdf_file = load_file_fixture('tfl.pdf') expected_size = pdf_file.size @@ -24,5 +23,4 @@ expect(zipped_size).to eq expected_size end - end diff --git a/spec/lib/acts_as_xapian_spec.rb b/spec/lib/acts_as_xapian_spec.rb index e7496d9182..0ec903dcc3 100644 --- a/spec/lib/acts_as_xapian_spec.rb +++ b/spec/lib/acts_as_xapian_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe ActsAsXapian do - before { update_xapian_index } describe '.update_index' do - it 'processes jobs that were queued after a job that errors' do job1, job2 = Array.new(2) do |_i| body = FactoryBot.create(:public_body) @@ -36,9 +34,7 @@ expect { job1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { job2.reload }.to raise_error(ActiveRecord::RecordNotFound) end - end - end RSpec.describe ActsAsXapian::FailedJob do @@ -47,7 +43,6 @@ let(:failed_job) { described_class.new(1, error, model_data) } describe '.new' do - it 'requires a job_id' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -59,35 +54,27 @@ it 'sets model_data to an empty hash by default' do expect(described_class.new(1, error).model_data).to eq({}) end - end describe '#job_id' do - it 'returns the job_id' do expect(failed_job.job_id).to eq(1) end - end describe '#error' do - it 'returns the error' do expect(failed_job.error).to eq(error) end - end describe '#model_data' do - it 'returns the model_data' do expect(failed_job.model_data).to eq(model_data) end - end describe '#full_message' do - it 'returns a message suitable for the exception notification' do error.set_backtrace(%w(BACKTRACE_L1 BACKTRACE_L2)) @@ -110,20 +97,16 @@ expect(failed_job.full_message).to eq(msg) end - end describe '#error_backtrace' do - it 'returns the error backtrace' do error.set_backtrace(%w(BACKTRACE_L1 BACKTRACE_L2)) expect(failed_job.error_backtrace).to eq("BACKTRACE_L1\nBACKTRACE_L2") end - end describe '#job_info' do - context 'with full job info' do let(:failed_job) { described_class.new(1, error, model_data) } @@ -167,13 +150,10 @@ end end end - end RSpec.describe ActsAsXapian::Search do - describe "#words_to_highlight" do - before do update_xapian_index end @@ -229,7 +209,6 @@ end context 'the :regex option' do - it 'wraps each words in a regex that matches the full word' do expected = [/\b(albatross)\b/iu] s = ActsAsXapian::Search.new([PublicBody], 'Albatross', limit: 1) @@ -241,12 +220,10 @@ s = ActsAsXapian::Search.new([PublicBody], 'department', limit: 1) expect(s.words_to_highlight(regex: true)).to eq(expected) end - end end describe '#spelling_correction' do - before do load_raw_emails_data update_xapian_index @@ -268,7 +245,5 @@ s = ActsAsXapian::Search.new([PublicBody], "bobby", limit: 100) expect(s.spelling_correction).to eq("bôbby") end - end - end diff --git a/spec/lib/alaveteli_external_command_spec.rb b/spec/lib/alaveteli_external_command_spec.rb index 9fd22d8028..9aac2cc7b5 100644 --- a/spec/lib/alaveteli_external_command_spec.rb +++ b/spec/lib/alaveteli_external_command_spec.rb @@ -109,7 +109,6 @@ end RSpec.describe "when running external commands" do - it "should detect a non-zero exit status" do expect($stderr).to receive(:puts).with(/Error from/) t = AlaveteliExternalCommand.run(error_script) @@ -121,5 +120,4 @@ t = AlaveteliExternalCommand.run(segfault_script) assert_nil t end - end diff --git a/spec/lib/alaveteli_gettext/fuzzy_cleaner_spec.rb b/spec/lib/alaveteli_gettext/fuzzy_cleaner_spec.rb index a01f93d69e..82d9481039 100644 --- a/spec/lib/alaveteli_gettext/fuzzy_cleaner_spec.rb +++ b/spec/lib/alaveteli_gettext/fuzzy_cleaner_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliGetText::FuzzyCleaner do - describe '#clean_po' do - it 'removes the fuzzy marker and msgstr from a single-line msgstr' do input = <<-EOF.strip_heredoc msgid "Some msgid" @@ -93,7 +91,5 @@ expect(subject.clean_po(input)).to eq(expected) end - end - end diff --git a/spec/lib/alaveteli_localization_spec.rb b/spec/lib/alaveteli_localization_spec.rb index 58173bb732..0c83416456 100644 --- a/spec/lib/alaveteli_localization_spec.rb +++ b/spec/lib/alaveteli_localization_spec.rb @@ -1,15 +1,12 @@ require 'spec_helper' RSpec.describe AlaveteliLocalization do - describe '.set_locales' do - before do AlaveteliLocalization.set_locales('en_GB es', 'en_GB') end context 'when dealing with FastGettext' do - it 'sets FastGettext.locale' do expect(FastGettext.locale).to eq("en_GB") end @@ -26,13 +23,10 @@ it 'sets FastGettext.default_available_locales' do expect(FastGettext.default_available_locales).to eq([:en_GB, :es]) end - end context 'when dealing with I18n' do - context 'when enforce_available_locales is true' do - around do |example| enforce_available_locales = I18n.config.enforce_available_locales I18n.config.enforce_available_locales = true @@ -44,7 +38,6 @@ AlaveteliLocalization.set_locales('nl en', 'nl') expect(I18n.default_locale).to eq(:nl) end - end it 'sets I18n.locale' do @@ -103,12 +96,10 @@ expect(body_with_non_default_locale.url_name).to eq 'non_default' end end - end end context 'when translating' do - it 'can correct translate 2 letter language locale' do AlaveteliLocalization.set_locales('cy', 'cy') expect(I18n.translate('date.abbr_month_names')).to include( @@ -132,7 +123,6 @@ 'sept.', 'oct.', 'nov.', 'déc.' ) end - end it 'sets the locales for the custom routing filter' do @@ -150,11 +140,9 @@ expect(AlaveteliLocalization.available_locales). to eq(%w[en_GB nl_BE es]) end - end describe '.set_session_locale' do - it 'sets the current locale' do AlaveteliLocalization.set_session_locale('es') expect(AlaveteliLocalization.locale).to eq('es') @@ -184,11 +172,9 @@ it 'accepts a symbol or a string' do expect(AlaveteliLocalization.set_session_locale(:es)).to eq('es') end - end describe '.with_locale' do - it 'yields control to i18n' do expect { |b| AlaveteliLocalization.with_locale(:es, &b) }. to yield_control @@ -200,7 +186,6 @@ end expect(result).to eq("es") end - end describe '.with_default_locale' do @@ -216,7 +201,6 @@ end describe '.locale' do - it 'returns the current locale' do expect(AlaveteliLocalization.locale).to eq('en') end @@ -225,11 +209,9 @@ AlaveteliLocalization.set_locales('en_GB', 'en_GB') expect(AlaveteliLocalization.locale).to eq('en_GB') end - end describe '.default_locale' do - it 'returns the current locale' do expect(AlaveteliLocalization.default_locale).to eq('en') end @@ -238,11 +220,9 @@ AlaveteliLocalization.set_locales('en_GB es', 'en_GB') expect(AlaveteliLocalization.default_locale).to eq('en_GB') end - end describe '.default_locale?' do - it 'returns true if the supplied locale is the default' do expect(AlaveteliLocalization.default_locale?('en')).to eq(true) end @@ -258,20 +238,16 @@ it 'returns false if the supplied locale is nil' do expect(AlaveteliLocalization.default_locale?(nil)).to eq(false) end - end describe '.available_locales' do - it 'returns an array of available locales' do AlaveteliLocalization.set_locales('en_GB es', 'en_GB') expect(AlaveteliLocalization.available_locales).to eq(%w[en_GB es]) end - end describe '.html_lang' do - it 'returns the current locale' do expect(AlaveteliLocalization.html_lang).to eq('en') end @@ -280,7 +256,5 @@ AlaveteliLocalization.set_locales('en_GB es', 'en_GB') expect(AlaveteliLocalization.html_lang).to eq('en-GB') end - end - end diff --git a/spec/lib/alaveteli_mail_poller_spec.rb b/spec/lib/alaveteli_mail_poller_spec.rb index e273466e26..15eab823bd 100644 --- a/spec/lib/alaveteli_mail_poller_spec.rb +++ b/spec/lib/alaveteli_mail_poller_spec.rb @@ -5,7 +5,6 @@ let(:poller) { AlaveteliMailPoller.new(pop3: mockpop3) } describe '.poll_for_incoming_loop' do - context 'if the mail retrieval config is not set to poll a POP server' do before do allow(AlaveteliConfiguration). @@ -16,13 +15,10 @@ expect(AlaveteliMailPoller).not_to receive(:new) AlaveteliMailPoller.poll_for_incoming_loop end - end - end describe '#poll_for_incoming' do - it 'starts and ends a session with the POP server' do expect(mockpop3).not_to be_started expect(mockpop3).to receive(:start).and_call_original @@ -37,7 +33,6 @@ it 'returns false' do expect(poller.poll_for_incoming).to be false end - end context 'if there is mail on the POP server' do @@ -59,7 +54,6 @@ end context 'if there is an error getting the unique ID of a mail' do - before do allow(mockpop3.mails.first). to receive(:unique_id). @@ -72,11 +66,9 @@ expect(notification.subject). to eq('[ERROR] (Net::POPError) "Error code"') end - end context 'if there is an error getting the text of a mail' do - before do allow(mockpop3.mails.first). to receive(:pop). @@ -91,7 +83,6 @@ end context 'if there is already an error for this mail' do - before do IncomingMessageError. create(unique_id: mockpop3.mails.first.unique_id, @@ -109,11 +100,9 @@ expect(incoming_message_error.retry_at). to be_within(5.seconds).of(Time.zone.now + 30.minutes) end - end context 'if there is no error for this mail' do - it 'stores the error for the unique ID with a time of 30 minutes from now' do poller.poll_for_incoming @@ -124,13 +113,10 @@ expect(incoming_message_error.retry_at). to be_within(5.seconds).of(Time.zone.now + 30.minutes) end - end - end context 'if there is an error receiving the mail' do - before do allow(RequestMailer).to receive(:receive). with(mockpop3.mails.first.pop, :poller). @@ -157,11 +143,9 @@ it 'returns false' do expect(poller.poll_for_incoming).to be false end - end context 'if there is an error deleting the mail' do - before do allow(mockpop3.mails.first). to receive(:delete). @@ -194,13 +178,10 @@ it 'returns true' do expect(poller.poll_for_incoming).to be true end - end context 'if mail has previously failed' do - context 'and the mail has no retry time' do - before do IncomingMessageError.create!( unique_id: mockpop3.mails.first.unique_id @@ -215,11 +196,9 @@ it 'returns false' do expect(poller.poll_for_incoming).to be false end - end context 'and the mail has not reached its retry time' do - before do IncomingMessageError.create!( unique_id: mockpop3.mails.first.unique_id, @@ -235,11 +214,9 @@ it 'returns false' do expect(poller.poll_for_incoming).to be false end - end context 'and the mail has reached its retry time' do - before do IncomingMessageError.create!( unique_id: mockpop3.mails.first.unique_id, @@ -256,13 +233,11 @@ it 'returns true' do expect(poller.poll_for_incoming).to be true end - end end end context 'if there is a timeout connecting to the POP server' do - before do allow(mockpop3).to receive(:start). and_raise(Timeout::Error, 'execution expired') @@ -274,8 +249,6 @@ expect(notification.subject). to eq('[ERROR] (Timeout::Error) "execution expired"') end - end - end end diff --git a/spec/lib/alaveteli_rate_limiter/backends/pstore_database_spec.rb b/spec/lib/alaveteli_rate_limiter/backends/pstore_database_spec.rb index b24445ca9f..af553c70b8 100644 --- a/spec/lib/alaveteli_rate_limiter/backends/pstore_database_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/backends/pstore_database_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliRateLimiter::Backends::PStoreDatabase do - let(:test_path) { Rails.root + '/tmp/test.pstore' } after(:each) do @@ -9,7 +8,6 @@ end describe '.new' do - it 'requires a path' do expect { subject }.to raise_error(KeyError) end @@ -25,11 +23,9 @@ subject = described_class.new(path: path) expect(subject.pstore.path).to eq(Pathname.new(path)) end - end describe '#get' do - it 'returns the values for the key' do subject = described_class.new(path: test_path) @@ -56,11 +52,9 @@ expect(subject.get('key1')).to eq(expected) end - end describe '#set' do - it 'sets a new record for the given keys' do subject = described_class.new(path: test_path) subject.set('key', []) @@ -78,11 +72,9 @@ expect(subject.get('key')).to eq(expected) end - end describe '#record' do - it 'records an event for a given IP and event' do subject = described_class.new(path: test_path) time = Time.zone.now.to_datetime @@ -92,11 +84,9 @@ expect(subject.get('key').last).to be_within(1.second).of(time) end end - end describe '#==' do - it 'is equal if the pstore paths are the same' do subject = described_class.new(path: test_path) expect(subject).to eq(subject.dup) @@ -107,11 +97,9 @@ path = "#{ Rails.root }/tmp/custom_database.pstore" expect(subject).not_to eq(described_class.new(path: path)) end - end describe '#destroy' do - it 'destroys the pstore' do subject = described_class.new(path: test_path) subject.set('1', '2') @@ -123,7 +111,5 @@ subject = described_class.new(path: test_path) expect { subject.destroy }.not_to raise_error end - end - end diff --git a/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults_spec.rb b/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults_spec.rb index 114b3ee91c..b06b4f47c8 100644 --- a/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/defaults_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliRateLimiter::IPRateLimiter::Defaults do - describe '.new' do - it 'sets the the default whitelist' do expect(subject.whitelist). to eq(AlaveteliRateLimiter::IPRateLimiter::Whitelist.new) @@ -35,48 +33,38 @@ subject = described_class.new(event_rules: event_rules) expect(subject.event_rules).to eq(event_rules) end - end describe '#whitelist' do - it 'returns the whitelist' do expect(subject.whitelist). to eq(AlaveteliRateLimiter::IPRateLimiter::Whitelist.new) end - end describe '#whitelist=' do - it 'sets the whitelist' do whitelist = double subject.whitelist = whitelist expect(subject.whitelist).to eq(whitelist) end - end describe '#event_rules' do - it 'returns the event_rules' do expect(subject.event_rules).to eq(described_class::EVENT_RULES) end - end describe '#whitelist=' do - it 'sets the whitelist' do event_rules = double subject.event_rules = event_rules expect(subject.event_rules).to eq(event_rules) end - end describe '#==' do - it 'is equal if its attributes are identical' do opts = { whitelist: double } subject = described_class.new(opts) @@ -89,7 +77,5 @@ subject2 = described_class.new(whitelist: whitelist) expect(subject).not_to eq(subject2) end - end - end diff --git a/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/whitelist_spec.rb b/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/whitelist_spec.rb index 8f64b3a62c..1a175a6322 100644 --- a/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/whitelist_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/ip_rate_limiter/whitelist_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliRateLimiter::IPRateLimiter::Whitelist do - describe '.new' do - it 'sets an empty whitelist by default' do expect(subject.addresses).to be_empty end @@ -46,11 +44,9 @@ addrs = %w(0.0.0.1 invalid 0.0.0.3) expect { described_class.new(addrs) }.to raise_error(ArgumentError) end - end describe '#include?' do - it 'returns true if an address is whitelisted' do subject = described_class.new(%w(0.0.0.0 0.0.0.1)) expect(subject.include?('0.0.0.0')).to eq(true) @@ -70,11 +66,9 @@ subject = described_class.new(%w(0.0.0.0 0.0.0.1)) expect { subject.include?('invalid') }.to raise_error(ArgumentError) end - end describe '#==' do - it 'returns true if the address list is the same' do subject = described_class.new(%w(0.0.0.0 0.0.0.1)) expect(subject).to eq(subject.dup) @@ -85,7 +79,5 @@ subject2 = described_class.new(%w(0.0.0.0 0.0.0.3)) expect(subject1).not_to eq(subject2) end - end - end diff --git a/spec/lib/alaveteli_rate_limiter/ip_rate_limiter_spec.rb b/spec/lib/alaveteli_rate_limiter/ip_rate_limiter_spec.rb index 0b00382fac..5d29eebffd 100644 --- a/spec/lib/alaveteli_rate_limiter/ip_rate_limiter_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/ip_rate_limiter_spec.rb @@ -1,13 +1,11 @@ require 'spec_helper' RSpec.describe AlaveteliRateLimiter::IPRateLimiter do - after(:each) do described_class.defaults! end describe '.defaults' do - it 'sets the defaults' do expect(described_class.defaults). to eq(AlaveteliRateLimiter::IPRateLimiter::Defaults.new) @@ -25,11 +23,9 @@ expect(described_class.defaults).to eq(defaults) end - end describe '.new' do - it 'requires a Rule' do expect { subject }.to raise_error(ArgumentError) end @@ -89,40 +85,32 @@ subject = described_class.new(:signup, whitelist: whitelist) expect(subject.whitelist).to eq(whitelist) end - end describe '#rule' do - it 'returns the rule attribute' do rule = AlaveteliRateLimiter::Rule.new(:signup, 1, double) expect(described_class.new(rule).rule).to eq(rule) end - end describe '#whitelist' do - it 'returns the whitelist attribute' do whitelist = double subject = described_class.new(:signup, whitelist: whitelist) expect(subject.whitelist).to eq(whitelist) end - end describe '#backend' do - it 'returns the backend attribute' do backend = double subject = described_class.new(:signup, backend: backend) expect(subject.backend).to eq(backend) end - end describe '#records' do - it 'returns the records in the backend' do ip = '127.0.0.1' backend = double @@ -131,11 +119,9 @@ subject = described_class.new(:signup, backend: backend) expect(subject.records(ip)).to eq(records) end - end describe '#record' do - it 'records an event for the IP in the backend' do backend = double subject = described_class.new(:signup, backend: backend) @@ -161,11 +147,9 @@ subject = described_class.new(:signup) expect { subject.record('invalid') }.to raise_error(ArgumentError) end - end describe '#record!' do - it 'purges old records before recording the new event' do attrs = { name: :test, count: 20, @@ -180,7 +164,6 @@ backend = AlaveteliRateLimiter::Backends::PStoreDatabase.new(path: path) - subject = described_class.new(rule, backend: backend) ip = '127.0.0.1' @@ -199,11 +182,9 @@ File.delete(path) end - end describe '#limit?' do - it 'returns false if the IP is in the whitelist' do whitelist = AlaveteliRateLimiter::IPRateLimiter::Whitelist.new(%(0.0.0.0)) subject = described_class.new(:signup, whitelist: whitelist) @@ -223,7 +204,5 @@ subject = described_class.new(rule) expect(subject.limit?('0.0.0.0')).to eq(false) end - end - end diff --git a/spec/lib/alaveteli_rate_limiter/rate_limiter_spec.rb b/spec/lib/alaveteli_rate_limiter/rate_limiter_spec.rb index 95dd69a6ce..f7af57e67a 100644 --- a/spec/lib/alaveteli_rate_limiter/rate_limiter_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/rate_limiter_spec.rb @@ -5,7 +5,6 @@ let(:rule) { AlaveteliRateLimiter::Rule.new(:test, 1, window) } describe '.new' do - it 'requires a Rule' do expect { subject }.to raise_error(ArgumentError) end @@ -33,29 +32,23 @@ subject = described_class.new(rule, backend: backend) expect(subject.backend).to eq(backend) end - end describe '#rule' do - it 'returns the rule attribute' do expect(described_class.new(rule).rule).to eq(rule) end - end describe '#backend' do - it 'returns the backend attribute' do backend = double subject = described_class.new(rule, backend: backend) expect(subject.backend).to eq(backend) end - end describe '#records' do - it 'returns the records in the backend' do id = '1' backend = double @@ -64,11 +57,9 @@ subject = described_class.new(rule, backend: backend) expect(subject.records(id)).to eq(records) end - end describe '#record' do - it 'records an event for the id in the backend' do backend = double subject = described_class.new(rule, backend: backend) @@ -82,11 +73,9 @@ expect(backend).to receive(:record).with('1') subject.record(1) end - end describe '#record!' do - it 'purges old records before recording the new event' do attrs = { name: :test, count: 20, @@ -119,7 +108,6 @@ File.delete(path) end - end describe '#limit?' do @@ -156,7 +144,5 @@ expect(subject.limit?('1', custom_rule)).to eq(false) end end - end - end diff --git a/spec/lib/alaveteli_rate_limiter/rule_spec.rb b/spec/lib/alaveteli_rate_limiter/rule_spec.rb index 6e7535e332..cd98094260 100644 --- a/spec/lib/alaveteli_rate_limiter/rule_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/rule_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliRateLimiter::Rule do - describe '.from_hash' do - it 'constructs a Rule with associated Window from a Hash' do attrs = { name: :test, count: 2, @@ -36,11 +34,9 @@ attrs = { name: :test, count: 1, window: { value: 1 } } expect { described_class.from_hash(attrs) }.to raise_error(KeyError) end - end describe '.new' do - it 'requires a name' do expect { subject }.to raise_error(ArgumentError) end @@ -65,11 +61,9 @@ it 'converts a numeric count to an Integer' do expect(described_class.new(:test, '1', double).count).to eq(1) end - end describe '#limit?' do - it 'returns true if the given records are over the limit' do records = [10, 5, 1].map { |i| i.minutes.ago } attrs = { name: :test, @@ -104,11 +98,9 @@ subject = described_class.from_hash(attrs) expect(subject.limit?([])).to eq(false) end - end describe '#records_in_window' do - it 'returns records in the window' do records = [1, 5, 10].map { |i| i.days.ago } attrs = { name: :test, @@ -118,21 +110,17 @@ expected = records[0..1] expect(subject.records_in_window(records)).to eq(expected) end - end describe '#window' do - it 'returns the window attribute' do window = double subject = described_class.new(:test, 1, window) expect(subject.window).to eq(window) end - end describe '#==' do - it 'returns true if the count and window are equal' do subject = described_class.new(:test, 1, double) expect(subject).to eq(subject.dup) @@ -157,7 +145,5 @@ subject2 = described_class.new(:test, 1, double('window2')) expect(subject1).not_to eq(subject2) end - end - end diff --git a/spec/lib/alaveteli_rate_limiter/window_spec.rb b/spec/lib/alaveteli_rate_limiter/window_spec.rb index 2792960e51..2aff903f9c 100644 --- a/spec/lib/alaveteli_rate_limiter/window_spec.rb +++ b/spec/lib/alaveteli_rate_limiter/window_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliRateLimiter::Window do - describe '.from_hash' do - it 'creates a Window from a Hash' do expected = described_class.new(3, :day) hash = { value: 3, unit: :day } @@ -19,11 +17,9 @@ hash = { value: 3 } expect { described_class.from_hash(hash) }.to raise_error(KeyError) end - end describe '.new' do - it 'requires a value' do expect { described_class.new(:hour) }.to raise_error(ArgumentError) end @@ -46,11 +42,9 @@ expect { described_class.new(1, :tomato) }. to raise_error(ArgumentError, msg) end - end describe '#include?' do - it 'returns true if an event is inside the window' do travel_to(Time.zone.parse('2016-10-21')) do subject = described_class.new(1, :day) @@ -64,11 +58,9 @@ expect(subject.include?(2.days.ago)).to eq(false) end end - end describe '#cutoff' do - it 'calculates the end of the window based on the attributes' do time = Time.zone.parse('2016-10-21') travel_to(time) do @@ -76,11 +68,9 @@ expect(subject.cutoff).to be_within(1.second).of(time - 1.hour) end end - end describe '#==' do - it 'returns true if the value and unit are equal' do subject = described_class.new(1, :hour) expect(subject).to eq(subject.dup) @@ -98,7 +88,5 @@ subject2 = described_class.new(1, :minute) expect(subject1).not_to eq(subject2) end - end - end diff --git a/spec/lib/alaveteli_spam_term_checker_spec.rb b/spec/lib/alaveteli_spam_term_checker_spec.rb index 03d516c45e..8b1a20fe9e 100644 --- a/spec/lib/alaveteli_spam_term_checker_spec.rb +++ b/spec/lib/alaveteli_spam_term_checker_spec.rb @@ -1,22 +1,18 @@ require 'spec_helper' RSpec.describe AlaveteliSpamTermChecker do - after(:each) do described_class.default_spam_terms = described_class::DEFAULT_SPAM_TERMS end describe '.default_spam_terms' do - it 'returns the DEFAULT_SPAM_TERMS if no custom terms have been set' do expect(described_class.default_spam_terms). to eq(described_class::DEFAULT_SPAM_TERMS) end - end describe '.default_spam_terms=' do - it 'sets custom terms' do described_class.default_spam_terms = [/a/, /b/, /c/] expect(described_class.default_spam_terms).to eq([/a/, /b/, /c/]) @@ -51,11 +47,9 @@ expect { described_class.default_spam_terms = Object.new }. to raise_error(TypeError) end - end describe '.new' do - it 'sets the default terms if none are given' do expect(subject.spam_terms).to eq(described_class.default_spam_terms) end @@ -94,7 +88,6 @@ expect { described_class.new(Object.new) }. to raise_error(TypeError) end - end describe '#spam?' do @@ -119,5 +112,4 @@ expect(subject.spam?('Request about PhD theses')).to eq(false) end end - end diff --git a/spec/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb index 52c178e4e4..376c7f5a9c 100644 --- a/spec/lib/alaveteli_text_masker_spec.rb +++ b/spec/lib/alaveteli_text_masker_spec.rb @@ -1,13 +1,10 @@ require 'spec_helper' RSpec.describe AlaveteliTextMasker do - let(:class_instance) { Class.new { include AlaveteliTextMasker }.new } describe '#apply_masks' do - context 'applying censor rules' do - before do @cheese_censor_rule = FactoryBot.build(:censor_rule, text: 'Stilton', @@ -61,18 +58,15 @@ expect(result). to eq("There was a cat called Jarlsberg, he wished that he was yellow.") end - end context 'applying masks to binary' do - it "replaces ASCII email addresses in Word documents" do data = "His email was foo@bar.com" result = class_instance.apply_masks(data, "application/vnd.ms-word") expect(result).to eq("His email was xxx@xxx.xxx") end - it "replaces UCS-2 addresses in Word documents" do data = "His email was f\000o\000o\000@\000b\000a\000r\000.\000c\000o\000m\000, indeed" expected = "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed" @@ -88,11 +82,9 @@ ) expect(result).to eq 'xxxxxxx world' end - end context 'applying masks to PDF' do - def pdf_replacement_test(use_ghostscript_compression) config = MySociety::Config.load_default previous = config['USE_GHOSTSCRIPT_COMPRESSION'] @@ -148,11 +140,9 @@ def pdf_replacement_test(use_ghostscript_compression) result = class_instance.apply_masks(pdf, "application/pdf") expect(result).to match "something about xxx@xxx.xxx.xx" end - end context 'applying masks to text' do - it "applies hard-coded privacy rules to HTML files" do data = "http://test.host/c/cheese" result = class_instance.apply_masks(data, 'text/html') @@ -222,9 +212,6 @@ def pdf_replacement_test(use_ghostscript_compression) result = class_instance.apply_masks(data, 'text/html', masks: [mask]) expect(result).to eq(expected) end - end - end - end diff --git a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb index 3221d1c9d5..b27da7b89c 100644 --- a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb +++ b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb @@ -1,36 +1,28 @@ require 'spec_helper' RSpec.describe AttachmentToHTML::Adapters::CouldNotConvert do - let(:attachment) { FactoryBot.build(:pdf_attachment) } let(:adapter) do AttachmentToHTML::Adapters::CouldNotConvert.new(attachment) end describe :title do - it 'uses the attachment filename for the title' do expect(adapter.title).to eq(attachment.display_filename) end - end describe :body do - it 'contains a message asking the user to download the file directly' do expected = "

Sorry, we were unable to convert this file to HTML. " \ "Please use the download link at the top right.

" expect(adapter.body).to eq(expected) end - end describe :success? do - it 'is always true' do expect(adapter.success?).to be true end - end - end diff --git a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb index 8f279a3fb8..f7276e0d45 100644 --- a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb +++ b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb @@ -21,28 +21,21 @@ end describe :title do - it 'uses the attachment filename for the title' do expect(adapter.title).to eq(attachment.display_filename) end - end describe :body do - it 'contains the google docs viewer iframe' do expected = %Q() expect(adapter.body).to eq(expected) end - end describe :success? do - it 'is always true' do expect(adapter.success?).to be true end - end - end diff --git a/spec/lib/attachment_to_html/adapters/pdf_spec.rb b/spec/lib/attachment_to_html/adapters/pdf_spec.rb index 0e02bb2bfe..5357d5f0bf 100644 --- a/spec/lib/attachment_to_html/adapters/pdf_spec.rb +++ b/spec/lib/attachment_to_html/adapters/pdf_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe AttachmentToHTML::Adapters::PDF do - let(:attachment) { FactoryBot.create(:pdf_attachment) } let(:adapter) { AttachmentToHTML::Adapters::PDF.new(attachment) } describe :tmpdir do - it 'defaults to the rails tmp directory' do expect(adapter.tmpdir).to eq(Rails.root.join('tmp')) end @@ -15,11 +13,9 @@ adapter = AttachmentToHTML::Adapters::PDF.new(attachment, tmpdir: '/tmp') expect(adapter.tmpdir).to eq('/tmp') end - end describe :title do - it 'uses the attachment filename for the title' do expect(adapter.title).to eq(attachment.display_filename) end @@ -27,12 +23,9 @@ it 'returns the title encoded as UTF-8' do expect(adapter.title.encoding).to eq(Encoding.find('UTF-8')) end - - end describe :body do - it 'extracts the body from the document' do expect(adapter.body).to include('thisisthebody') end @@ -54,7 +47,6 @@ end context 'PDF attachment with images' do - let(:attachment) do FactoryBot.create( :pdf_attachment, @@ -67,14 +59,10 @@ expect(adapter.body).to_not include('some content

') expect(adapter.success?).to be_truthy @@ -131,7 +119,5 @@ expect(adapter.success?).to be false end - end - end diff --git a/spec/lib/attachment_to_html/adapters/rtf_spec.rb b/spec/lib/attachment_to_html/adapters/rtf_spec.rb index fd2fd5fa18..ee4462b2f4 100644 --- a/spec/lib/attachment_to_html/adapters/rtf_spec.rb +++ b/spec/lib/attachment_to_html/adapters/rtf_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe AttachmentToHTML::Adapters::RTF do - let(:attachment) { FactoryBot.create(:rtf_attachment) } let(:adapter) { AttachmentToHTML::Adapters::RTF.new(attachment) } describe :tmpdir do - it 'defaults to the rails tmp directory' do expect(adapter.tmpdir).to eq(Rails.root.join('tmp')) end @@ -15,19 +13,15 @@ adapter = AttachmentToHTML::Adapters::RTF.new(attachment, tmpdir: '/tmp') expect(adapter.tmpdir).to eq('/tmp') end - end describe :title do - it 'uses the attachment filename for the title' do expect(adapter.title).to eq(attachment.display_filename) end - end describe :body do - it 'extracts the body from the document' do expect(adapter.body).to include('thisisthebody') end @@ -70,12 +64,9 @@ allow(AlaveteliExternalCommand).to receive(:run).and_return(nil) expect(adapter.body).to eq('') end - end - describe :success? do - it 'is truthy if the body has content excluding the tags' do allow(adapter).to receive(:body).and_return('

some content

') expect(adapter.success?).to be_truthy @@ -90,7 +81,5 @@ allow(adapter).to receive(:body).and_return('

') expect(adapter.success?).to be_falsey end - end - end diff --git a/spec/lib/attachment_to_html/adapters/text_spec.rb b/spec/lib/attachment_to_html/adapters/text_spec.rb index 862e739d3b..f6c6ca132d 100644 --- a/spec/lib/attachment_to_html/adapters/text_spec.rb +++ b/spec/lib/attachment_to_html/adapters/text_spec.rb @@ -1,20 +1,16 @@ require 'spec_helper' RSpec.describe AttachmentToHTML::Adapters::Text do - let(:attachment) { FactoryBot.create(:body_text) } let(:adapter) { AttachmentToHTML::Adapters::Text.new(attachment) } describe :title do - it 'uses the attachment filename for the title' do expect(adapter.title).to eq(attachment.display_filename) end - end describe :body do - it 'extracts the body from the document' do expect(adapter.body).to eq(attachment.body) end @@ -58,11 +54,9 @@ adapter = AttachmentToHTML::Adapters::Text.new(attachment) expect(adapter.body).to be_valid_encoding end - end describe :success? do - it 'is truthy if the body has content excluding the tags' do allow(adapter).to receive(:body).and_return('

some content

') expect(adapter.success?).to be_truthy @@ -77,7 +71,5 @@ allow(adapter).to receive(:body).and_return('

') expect(adapter.success?).to be_falsey end - end - end diff --git a/spec/lib/attachment_to_html/attachment_to_html_spec.rb b/spec/lib/attachment_to_html/attachment_to_html_spec.rb index a987dfa1c4..03df7916f8 100644 --- a/spec/lib/attachment_to_html/attachment_to_html_spec.rb +++ b/spec/lib/attachment_to_html/attachment_to_html_spec.rb @@ -6,7 +6,6 @@ let(:attachment) { FactoryBot.create(:body_text) } describe '#to_html' do - it 'sends the attachment to the correct adapter for conversion' do expect(AttachmentToHTML::Adapters::Text).to receive(:new).with(attachment, {}).and_call_original to_html(attachment) @@ -50,7 +49,6 @@ end describe 'when wrapping the content' do - it 'uses a the default wrapper' do attachment = FactoryBot.create(:pdf_attachment) expect(to_html(attachment)).to include(%Q(
)) @@ -63,9 +61,7 @@ allow_any_instance_of(AttachmentToHTML::Adapters::PDF).to receive(:success?).and_return(false) expect(to_html(attachment)).to include(%Q(
)) end - end - end describe '#extractable?' do diff --git a/spec/lib/attachment_to_html/view_spec.rb b/spec/lib/attachment_to_html/view_spec.rb index 3255d3d2a4..c301de0e7e 100644 --- a/spec/lib/attachment_to_html/view_spec.rb +++ b/spec/lib/attachment_to_html/view_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AttachmentToHTML::View do - let(:adapter) do double(:adapter, body: '

hello

', @@ -16,7 +15,6 @@ end describe '.template' do - after(:each) do AttachmentToHTML::View.template = nil end @@ -24,11 +22,9 @@ it 'has a default template location' do expect(AttachmentToHTML::View.template).to eq(default_template) end - end describe '.template=' do - after(:each) do AttachmentToHTML::View.template = nil end @@ -38,11 +34,9 @@ AttachmentToHTML::View.template = template expect(AttachmentToHTML::View.template).to eq(template) end - end describe :new do - it 'sets the title on initialization' do expect(view.title).to eq(adapter.title) end @@ -61,58 +55,46 @@ view = AttachmentToHTML::View.new(adapter, opts) expect(view.template).to eq(template) end - end describe :title= do - it 'allows the title to be set' do view.title = adapter.title expect(view.title).to eq(adapter.title) end - end describe :body= do - it 'allows the body to be set' do view.body = adapter.body expect(view.body).to eq(adapter.body) end - end describe :template= do - it 'allows the template to be set' do template = file_fixture_name('attachment_to_html/alternative_template.html.erb') view.template = template expect(view.template).to eq(template) end - end describe :wrapper do - it 'is set to wrapper by default' do expect(view.wrapper).to eq('wrapper') end - end describe :wrapper= do - it 'allows the wrapper div to be customised' do view.wrapper = 'wrap' expect(view.wrapper).to eq('wrap') end - end # Need to remove all whitespace to assert equal because # ERB adds additional indentation after ERB tags describe :render do - it 'renders the contents in to the template' do view.wrapper = 'wrap' expected = <<-HTML @@ -140,7 +122,5 @@ result = view.render { inject_content(:head_suffix) { content } } expect(result).to include(content) end - end - end diff --git a/spec/lib/basic_encoding_spec.rb b/spec/lib/basic_encoding_spec.rb index 3b0d652615..055ce8f88a 100644 --- a/spec/lib/basic_encoding_spec.rb +++ b/spec/lib/basic_encoding_spec.rb @@ -66,11 +66,8 @@ def bytes_to_binary_string( bytes, claimed_encoding = nil ) gb_18030_spam_string = bytes_to_binary_string gb_18030_bytes RSpec.describe "normalize_string_to_utf8" do - describe "when passed uniterpretable character data" do - it "should reject it as invalid" do - expect { normalize_string_to_utf8 random_string }.to raise_error(EncodingNormalizationError) @@ -78,72 +75,51 @@ def bytes_to_binary_string( bytes, claimed_encoding = nil ) expect { normalize_string_to_utf8 random_string, 'UTF-8' }.to raise_error(EncodingNormalizationError) - end end describe "when passed unlabelled Windows 1252 data" do - it "should correctly convert it to UTF-8" do - normalized = normalize_string_to_utf8 windows_1252_string expect(normalized).to eq("DASH – DASH") - end - end describe "when passed suggested Windows 1258 data" do - it "should raise EncodingNormalizationError" do - expect { normalize_string_to_utf8 windows_1258_string, 'windows-1258' }.to raise_error( EncodingNormalizationError, 'code converter not found (Windows-1258 to UTF-8)' ) - end - end describe "when passed suggested ISO-2022-JP data" do - it "should raise EncodingNormalizationError" do - expect { normalize_string_to_utf8 iso_2022_jp_string, 'iso-2022-jp' }.to raise_error( EncodingNormalizationError, '"\xE7" on ISO-2022-JP' ) - end - end describe "when passed GB 18030 data" do - it "should correctly convert it to UTF-8 if unlabelled" do - normalized = normalize_string_to_utf8 gb_18030_spam_string expect(normalized).to start_with("贵公司负责人") - end - end - end RSpec.describe "convert_string_to_utf8_or_binary" do - describe "when passed uninterpretable character data" do - it "should return it as a binary string" do - converted = convert_string_to_utf8_or_binary random_string expect(converted).to eq(random_string) expect(converted.encoding.to_s).to eq('ASCII-8BIT') @@ -151,75 +127,54 @@ def bytes_to_binary_string( bytes, claimed_encoding = nil ) converted = convert_string_to_utf8_or_binary random_string,'UTF-8' expect(converted).to eq(random_string) expect(converted.encoding.to_s).to eq('ASCII-8BIT') - end end describe "when passed unlabelled Windows 1252 data" do - it "should correctly convert it to UTF-8" do - converted = convert_string_to_utf8_or_binary windows_1252_string expect(converted).to eq("DASH – DASH") expect(converted.encoding.to_s).to eq('UTF-8') - end - end describe "when passed suggested Windows 1258 data" do - it "should return data as ASCII-8BIT" do - converted = convert_string_to_utf8_or_binary( windows_1258_string, 'windows-1258' ) expect(converted).to eq("DONG \xFE DONG".force_encoding('ASCII-8BIT')) expect(converted.encoding.to_s).to eq('ASCII-8BIT') - end - end describe "when passed suggested ISO-2022-JP data" do - it "should return data as ASCII-8BIT" do - converted = convert_string_to_utf8_or_binary( iso_2022_jp_string, 'iso-2022-jp' ) expect(converted).to eq("無効です\x92".force_encoding('ASCII-8BIT')) expect(converted.encoding.to_s).to eq('ASCII-8BIT') - end - end describe "when passed GB 18030 data" do - it "should correctly convert it to UTF-8 if unlabelled" do - converted = convert_string_to_utf8_or_binary gb_18030_spam_string expect(converted).to start_with("贵公司负责人") expect(converted.encoding.to_s).to eq('UTF-8') - end - end - end RSpec.describe "convert_string_to_utf8" do - describe "when passed uninterpretable character data" do - it "should return it as a valid utf8 string with non-utf8 characters removed and mark it as scrubbed" do - converted = convert_string_to_utf8 random_string expect(converted.string.encoding.to_s).to eq('UTF-8') @@ -231,65 +186,47 @@ def bytes_to_binary_string( bytes, claimed_encoding = nil ) expect(converted.string.encoding.to_s).to eq('UTF-8') expect(converted.string.valid_encoding?).to eq(true) expect(converted.scrubbed?).to eq(true) - end end describe "when passed unlabelled Windows 1252 data" do - it "should correctly convert it to UTF-8" do - converted = convert_string_to_utf8 windows_1252_string expect(converted.string).to eq("DASH – DASH") expect(converted.string.encoding.to_s).to eq('UTF-8') expect(converted.scrubbed?).to eq(false) - end - end describe "when passed suggested Windows 1258 data" do - it "should return scrubbed UTF-8 string" do - converted = convert_string_to_utf8(windows_1258_string, 'windows-1258') expect(converted.string).to eq("DONG DONG") expect(converted.string.encoding.to_s).to eq('UTF-8') expect(converted.scrubbed?).to eq(true) - end - end describe "when passed suggested ISO-2022-JP data" do - it "should return scrubbed UTF-8 string" do - converted = convert_string_to_utf8(iso_2022_jp_string, 'iso-2022-jp') expect(converted.string).to eq("無効です") expect(converted.string.encoding.to_s).to eq('UTF-8') expect(converted.scrubbed?).to eq(true) - end - end describe "when passed GB 18030 data" do - it "should correctly convert it to UTF-8 if unlabelled" do - converted = convert_string_to_utf8 gb_18030_spam_string expect(converted.string).to start_with("贵公司负责人") expect(converted.string.encoding.to_s).to eq('UTF-8') expect(converted.scrubbed?).to eq(false) - end - end - end diff --git a/spec/lib/confidence_intervals_spec.rb b/spec/lib/confidence_intervals_spec.rb index e09de6f686..d652a0d158 100644 --- a/spec/lib/confidence_intervals_spec.rb +++ b/spec/lib/confidence_intervals_spec.rb @@ -1,7 +1,6 @@ require 'confidence_intervals' RSpec.describe "ci_bounds" do - describe "when passed all successes" do it "should never return a high CI above 1" do ci = ci_bounds 16, 16, 0.01 @@ -26,5 +25,4 @@ expect(ci[1]).to be_within(0.001).of(0.8922) end end - end diff --git a/spec/lib/custom_cops/empty_lines_around_rescued_exceptions_spec.rb b/spec/lib/custom_cops/empty_lines_around_rescued_exceptions_spec.rb new file mode 100644 index 0000000000..f810e0aa85 --- /dev/null +++ b/spec/lib/custom_cops/empty_lines_around_rescued_exceptions_spec.rb @@ -0,0 +1,81 @@ +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' +require Rails.root.join('lib/custom_cops/empty_lines_around_rescued_exceptions') + +RSpec.describe CustomCops::EmptyLinesAroundRescuedExceptions, :config do + include RuboCop::RSpec::ExpectOffense + + it 'registers no offense when rescue body is just a single line' do + expect_no_offenses(<<~RUBY) + begin + do_something + rescue FooError + error_notification + handle_error + end + RUBY + end + + it 'registers no offense when resbody body is just a single line' do + expect_no_offenses(<<~RUBY) + begin + do_something + do_something_else + rescue FooError + handle_error + end + RUBY + end + + it 'registers an offense for missing extra newlines before rescued exceptions' do + expect_offense(<<~RUBY) + begin + do_something + do_something_else + rescue FooError + ^^^^^^^^^^^^^^^ Use empty line before rescued exceptions. + error_notification + handle_error + end + RUBY + + expect_correction(<<~RUBY) + begin + do_something + do_something_else + + rescue FooError + error_notification + handle_error + end + RUBY + end + + it 'registers an offense for newlines after rescued exceptions' do + expect_offense(<<~RUBY) + begin + do_something + do_something_else + + rescue FooError + ^^^^^^^^^^^^^^^ Avoid empty line after rescued exceptions. + + error_notification + handle_error + end + RUBY + + expect_correction(<<~RUBY) + begin + do_something + do_something_else + + rescue FooError + error_notification + handle_error + end + RUBY + end +end diff --git a/spec/lib/data_export_spec.rb b/spec/lib/data_export_spec.rb index 1892230205..2b627f9620 100644 --- a/spec/lib/data_export_spec.rb +++ b/spec/lib/data_export_spec.rb @@ -2,7 +2,6 @@ require Rails.root.join('lib/data_export') RSpec.describe DataExport do - describe '.case_insensitive_user_censor' do subject { described_class.case_insensitive_user_censor(text, user) } let(:text) { "Yours faithfully, #{ user.name }" } @@ -21,11 +20,9 @@ it { is_expected.to eq 'Yours faithfully, ' } end - end describe ".exportable_requests" do - let(:cut_off) { Date.today + 1 } it "includes eligible requests " do @@ -55,11 +52,9 @@ expect(exportable).to_not include(embargoed) end - end describe ".exportable_incoming_messages" do - let(:cut_off) { Date.today + 1 } it "includes eligible messages" do @@ -101,11 +96,9 @@ exportable = described_class.exportable_incoming_messages(cut_off) expect(exportable).to_not include(message) end - end describe ".exportable_outgoing_messages" do - let(:cut_off) { Date.today + 1 } it "includes eligible messages" do @@ -147,11 +140,9 @@ exportable = described_class.exportable_outgoing_messages(cut_off) expect(exportable).to_not include(message) end - end describe ".exportable_foi_attachments" do - let(:cut_off) { Date.today + 1 } it "includes eligible attachments" do @@ -203,7 +194,5 @@ exportable = described_class.exportable_foi_attachments(cut_off) expect(exportable).to_not include(attachment) end - end - end diff --git a/spec/lib/database_collation_spec.rb b/spec/lib/database_collation_spec.rb index 06f5a36bce..d7f30031df 100644 --- a/spec/lib/database_collation_spec.rb +++ b/spec/lib/database_collation_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe DatabaseCollation do - describe '.supports?' do - it 'delegates to an instance of the class' do collation = double connection = mock_connection @@ -12,21 +10,17 @@ expect(collation).to receive(:supports?).with('en_GB') DatabaseCollation.supports?('en_GB') end - end describe '.new' do - it 'requires a connection to be specified' do mock_connection = double expect(DatabaseCollation.new(mock_connection).connection). to eq(mock_connection) end - end describe '#supports?' do - it 'does not support collation if the database is not postgresql' do database = DatabaseCollation. new(mock_connection(adapter_name: 'MySQL')) @@ -58,9 +52,7 @@ database = DatabaseCollation.new(mock_connection) expect(database.supports?('default')).to be true end - end - end def mock_connection(connection_double_opts = {}) diff --git a/spec/lib/date_quarter_spec.rb b/spec/lib/date_quarter_spec.rb index a7c7e5a07d..51ff24f7a8 100644 --- a/spec/lib/date_quarter_spec.rb +++ b/spec/lib/date_quarter_spec.rb @@ -4,7 +4,6 @@ include DateQuarter describe '#quarters_between' do - it 'returns all the quarters in a year' do # This is a bit of a convoluted spec, since we have to convert each # Time in to an Integer to make a reasonable comparison @@ -25,7 +24,5 @@ end end end - end - end diff --git a/spec/lib/default_late_calculator_spec.rb b/spec/lib/default_late_calculator_spec.rb index 0c122a6b97..87465d531d 100644 --- a/spec/lib/default_late_calculator_spec.rb +++ b/spec/lib/default_late_calculator_spec.rb @@ -1,34 +1,26 @@ require 'spec_helper' RSpec.describe DefaultLateCalculator do - describe '.description' do - it 'returns the human description' do desc = %q(Defaults controlled by config/general.yml) expect(described_class.description).to eq(desc) end - end describe '#reply_late_after_days' do - it 'returns the value set in config/general.yml' do allow(AlaveteliConfiguration). to receive(:reply_late_after_days).and_return(7) expect(subject.reply_late_after_days).to eq(7) end - end describe '#reply_very_late_after_days' do - it 'returns the value set in config/general.yml' do allow(AlaveteliConfiguration). to receive(:reply_very_late_after_days).and_return(7) expect(subject.reply_very_late_after_days).to eq(7) end - end - end diff --git a/spec/lib/graphs_spec.rb b/spec/lib/graphs_spec.rb index 51738ab3ac..db49d10c8d 100644 --- a/spec/lib/graphs_spec.rb +++ b/spec/lib/graphs_spec.rb @@ -2,11 +2,9 @@ require Rails.root.join('lib/graphs') RSpec.describe Graphs do - let(:dummy_class) { Class.new { extend Graphs } } describe "when asked to select data as columns" do - let(:user1) { FactoryBot.create(:user) } let(:user2) { FactoryBot.create(:user) } @@ -23,7 +21,6 @@ result = dummy_class.select_as_columns(sql) expected = [[user1.name], [user1.id]] expect(result).to eq expected - end it "returns nil if there are no results" do @@ -36,11 +33,9 @@ expect { dummy_class.select_as_columns(sql) }. to raise_error(ActiveRecord::StatementInvalid) end - end describe "when asked to create a plottable dataset" do - let(:test_data) { [["title 1", "title 2"], [42, 15], [42, 57]] } it "returns a Gnuplot::DataSet object" do @@ -85,7 +80,6 @@ end describe "when asked to plot data from sql" do - let(:sql) { "SELECT name, id FROM users WHERE 1=0" } let(:test_data) { [["title 1", "title 2"], [42, 15], [42, 57]] } @@ -101,7 +95,6 @@ end context "select_as_columns returns data" do - it "calls create_dataset" do allow(dummy_class).to receive(:select_as_columns).with(sql) { test_data } expect(dummy_class).to receive(:create_dataset).with(test_data, {}) @@ -116,13 +109,10 @@ dummy_class.plot_data_from_sql(sql, {}, datasets) expect(datasets).to eq [mock_dataset] end - end - end describe "when asked to plot data from columns" do - let(:test_data) { [["title 1", "title 2"], [42, 15], [42, 57]] } it "calls create_dataset with the supplied data" do @@ -143,7 +133,6 @@ expect(dummy_class).not_to receive(:create_dataset) dummy_class.plot_data_from_columns(nil, {}, []) end - end describe "when asked to plot multiple datasets" do @@ -182,7 +171,5 @@ expect(dummy_class).to receive(:plot_data_from_sql).exactly(2).times dummy_class.plot_datasets(graph_param_sets, []) end - end - end diff --git a/spec/lib/health_checks/checks/period_check_spec.rb b/spec/lib/health_checks/checks/period_check_spec.rb index d736197154..d87bd70ba0 100644 --- a/spec/lib/health_checks/checks/period_check_spec.rb +++ b/spec/lib/health_checks/checks/period_check_spec.rb @@ -16,7 +16,6 @@ end describe :ok? do - it 'is successful if the subject is in the last day' do check = HealthChecks::Checks::PeriodCheck.new { Time.zone.now } expect(check.ok?).to be true @@ -26,11 +25,9 @@ check = HealthChecks::Checks::PeriodCheck.new { 2.days.ago } expect(check.ok?).to be false end - end describe :failure_message do - it 'includes the check subject in the default message' do subject = 2.days.ago check = HealthChecks::Checks::PeriodCheck.new { subject } @@ -43,11 +40,9 @@ check = HealthChecks::Checks::PeriodCheck.new(params) { subject } expect(check.failure_message).to include(subject.to_s) end - end describe :success_message do - it 'includes the check subject in the default message' do subject = Time.zone.now check = HealthChecks::Checks::PeriodCheck.new { subject } @@ -60,7 +55,5 @@ check = HealthChecks::Checks::PeriodCheck.new(params) { subject } expect(check.success_message).to include(subject.to_s) end - end - end diff --git a/spec/lib/health_checks/health_checkable_spec.rb b/spec/lib/health_checks/health_checkable_spec.rb index 2b1c3b86ef..0365d8a89b 100644 --- a/spec/lib/health_checks/health_checkable_spec.rb +++ b/spec/lib/health_checks/health_checkable_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe HealthChecks::HealthCheckable do - before(:each) do class MockCheck include HealthChecks::HealthCheckable @@ -10,7 +9,6 @@ class MockCheck end describe '#initialize' do - it 'allows a custom failure message to be set' do @subject = MockCheck.new(failure_message: 'F') expect(@subject.failure_message).to eq('F') @@ -20,63 +18,48 @@ class MockCheck @subject = MockCheck.new(success_message: 'S') expect(@subject.success_message).to eq('S') end - end describe '#name' do - it 'returns the name of the check' do expect(@subject.name).to eq('MockCheck') end - end describe '#ok?' do - it 'is intended to be overridden by the includer' do expect { @subject.ok? }.to raise_error(NotImplementedError) end - end describe '#failure_message' do - it 'returns a default message if one has not been set' do expect(@subject.failure_message).to eq('Failed') end - end describe '#failure_message=' do - it 'allows a custom failure message to be set' do @subject.failure_message = 'F' expect(@subject.failure_message).to eq('F') end - end describe '#success_message' do - it 'returns a default message if one has not been set' do expect(@subject.success_message).to eq('Success') end - end describe '#success_message=' do - it 'allows a custom success message to be set' do @subject.success_message = 'S' expect(@subject.success_message).to eq('S') end - end describe '#message' do - context 'if the check succeeds' do - before(:each) do allow(@subject).to receive_messages(ok?: true) end @@ -89,11 +72,9 @@ class MockCheck @subject.success_message = 'Custom Success' expect(@subject.message).to eq('Custom Success') end - end context 'if the check fails' do - before(:each) do allow(@subject).to receive_messages(ok?: false) end @@ -106,9 +87,6 @@ class MockCheck @subject.failure_message = 'Custom Failed' expect(@subject.message).to eq('Custom Failed') end - end - end - end diff --git a/spec/lib/health_checks/health_checks_spec.rb b/spec/lib/health_checks/health_checks_spec.rb index 6e68472fdf..37517bd238 100644 --- a/spec/lib/health_checks/health_checks_spec.rb +++ b/spec/lib/health_checks/health_checks_spec.rb @@ -4,7 +4,6 @@ include HealthChecks describe '#add' do - it 'adds a check to the collection and returns the check' do check = double('MockCheck', ok?: true) expect(add(check)).to eq(check) @@ -14,11 +13,9 @@ check = double('BadCheck') expect(add(check)).to eq(false) end - end describe '#all' do - it 'returns all the checks' do check1 = double('MockCheck', ok?: true) check2 = double('AnotherCheck', ok?: false) @@ -26,19 +23,15 @@ add(check2) expect(all).to include(check1, check2) end - end describe '#each' do - it 'iterates over each check' do expect(subject).to respond_to(:each) end - end describe '#ok?' do - it 'returns true if all checks are ok' do checks = [ double('MockCheck', ok?: true), @@ -71,7 +64,5 @@ expect(HealthChecks.ok?).to be false end - end - end diff --git a/spec/lib/i18n_interpolation_spec.rb b/spec/lib/i18n_interpolation_spec.rb index 62bc0095c0..2a8be86757 100644 --- a/spec/lib/i18n_interpolation_spec.rb +++ b/spec/lib/i18n_interpolation_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe "when using i18n" do - it "should not complain if we're missing variables from the string" do result = _('Hello', dip: 'hummus') expect(result).to eq('Hello') diff --git a/spec/lib/languages_spec.rb b/spec/lib/languages_spec.rb index 0a605bf5b1..1b74c53635 100644 --- a/spec/lib/languages_spec.rb +++ b/spec/lib/languages_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe LanguageNames do - describe '.get_language_name' do - it 'should return the name assigned to the language' do expect(LanguageNames.get_language_name('en')).to eq('English') end @@ -15,7 +13,5 @@ it 'should return the name assigned to the language/location combination' do expect(LanguageNames.get_language_name('zh_HK')).to eq('中文(香港)') end - end - end diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb index 37237ab3a9..37d6db9e7c 100644 --- a/spec/lib/mail_handler/backends/mail_backend_spec.rb +++ b/spec/lib/mail_handler/backends/mail_backend_spec.rb @@ -5,15 +5,12 @@ include MailHandler::Backends::MailBackend describe :backend do - it 'should return the name of the backend' do expect(backend).to eq('Mail') end - end describe :mail_from_raw_email do - subject { mail_from_raw_email(raw_email) } context 'when passed a binary string' do @@ -61,11 +58,9 @@ is_expected.to eq Mail.read_from_string(raw_email) end end - end describe :get_part_file_name do - it 'returns the part file name' do mail = get_fixture_mail('document-pdf.email') part = mail.attachments.first @@ -84,11 +79,9 @@ filename = get_part_file_name(part) expect(filename.valid_encoding?).to eq(true) end - end describe :get_part_body do - it 'returns the body of a part' do expected = <<-DOC Here's a PDF attachement which has a document/pdf content-type, @@ -104,11 +97,9 @@ part = MailHandler.get_attachment_leaves(mail).first expect(get_part_body(part).frozen?).to eq(false) end - end describe :get_subject do - it 'returns nil for a nil subject' do mail = Mail.new expect(get_subject(mail)).to be nil @@ -120,7 +111,6 @@ expect(get_subject(mail).force_encoding('UTF-8').valid_encoding?) .to be true end - end describe '#get_within_rfc822_subject' do @@ -137,31 +127,25 @@ end describe :first_from do - it 'finds the first from field' do mail = get_fixture_mail('raw_emails/1.email') expected = Mail::Address.new('FOI Person ').to_s expect(first_from(mail).to_s).to eq(expected) end - end describe :get_from_address do - it 'finds the first address' do mail = get_fixture_mail('raw_emails/1.email') expect(get_from_address(mail)).to eq('foiperson@localhost') end - end describe :get_from_name do - it 'finds the first from name' do mail = get_fixture_mail('raw_emails/1.email') expect(get_from_name(mail)).to eq('FOI Person') end - end describe '.get_all_addresses' do @@ -247,11 +231,9 @@ end end end - end describe :empty_return_path? do - it 'is false if the return path is nil' do mail = Mail.new expect(empty_return_path?(mail)).to be false @@ -268,11 +250,9 @@ mail['return-path'] = '' expect(empty_return_path?(mail)).to be true end - end describe :get_auto_submitted do - it 'returns the auto-submitted attribute' do mail = Mail.new mail['auto-submitted'] = 'xyz' @@ -283,24 +263,18 @@ mail = Mail.new expect(get_auto_submitted(mail)).to be_nil end - end describe :expand_and_normalize_parts do - context 'when given a multipart message' do - it 'should return a Mail::PartsList' do mail = get_fixture_mail('incoming-request-oft-attachments.email') expect(expand_and_normalize_parts(mail, mail).class).to eq(Mail::PartsList) end - end - end describe :address_from_name_and_email do - it 'returns an address string' do expected = 'Test User ' expect(address_from_name_and_email('Test User', 'test@example.com')).to eq(expected) @@ -312,7 +286,6 @@ address_from_name_and_email(name, 'test@example.com') expect(name).to eq(original) end - end describe '#decode_attached_part' do @@ -324,7 +297,6 @@ end describe :get_emails_within_received_headers do - it 'returns an empty list if there is no Received header' do mail = get_fixture_mail('bcc-contact-reply.email') expect(get_emails_within_received_headers(mail)).to eq([]) diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 43b69537c0..bb912d5eb3 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -7,7 +7,6 @@ def create_message_from(from_field) end RSpec.describe 'when creating a mail object from raw data' do - it "should be able to parse a large email without raising an exception" do m = Mail.new m.add_file(filename: "attachment.data", content: "a" * (8 * 1024 * 1024)) @@ -51,7 +50,6 @@ def create_message_from(from_field) expect(mail.subject).to eq('hello�') end - it 'should handle a UTF-7 subject' do mail = get_fixture_mail('utf-7-subject.email') expect(mail.subject). @@ -85,7 +83,6 @@ def create_message_from(from_field) end RSpec.describe 'when asked for the from name' do - it 'should return nil if there is a blank "From" field' do mail = create_message_from('') expect(MailHandler.get_from_name(mail)).to eq(nil) @@ -105,11 +102,9 @@ def create_message_from(from_field) mail = get_fixture_mail('track-response-webshield-bounce.email') expect(MailHandler.get_from_name(mail)).to eq(nil) end - end RSpec.describe 'when asked for the from address' do - it 'should return nil if there is a blank "From" field' do mail = create_message_from('') expect(MailHandler.get_from_address(mail)).to eq(nil) @@ -137,7 +132,6 @@ def create_message_from(from_field) end RSpec.describe 'when asked for all the addresses a mail has been sent to' do - it 'should return an array containing the envelope-to address and the to address, and the cc address if there is one' do mail_data = load_file_fixture('humberside-police-odd-mime-type.email') mail_data.gsub!('Envelope-to: request-5335-xxxxxxxx@whatdotheyknow.com', @@ -171,12 +165,9 @@ def create_message_from(from_field) mail = MailHandler.mail_from_raw_email(mail_data) expect(MailHandler.get_all_addresses(mail)).to eq([]) end - - end RSpec.describe 'when asked for auto_submitted' do - it 'should return a string value for an email with an auto-submitted header' do mail = get_fixture_mail('autoresponse-header.email') expect(MailHandler.get_auto_submitted(mail)).to eq('auto-replied') @@ -186,11 +177,9 @@ def create_message_from(from_field) mail = get_fixture_mail('incoming-request-plain.email') expect(MailHandler.get_auto_submitted(mail)).to eq(nil) end - end RSpec.describe 'when asked if there is an empty return path' do - it 'should return true if there is an empty return-path specified' do mail = get_fixture_mail('empty-return-path.email') expect(MailHandler.empty_return_path?(mail)).to eq(true) @@ -208,7 +197,6 @@ def create_message_from(from_field) end RSpec.describe 'when deriving a name, email and formatted address from a message from a line' do - def should_render_from_address(from_line, expected_result) mail = create_message_from(from_line) name = MailHandler.get_from_name(mail) @@ -252,18 +240,15 @@ def should_render_from_address(from_line, expected_result) '"FOI @ Person" ']) end - it 'should quote a name with quotes in it' do should_render_from_address('"FOI \" Person" ', ['FOI " Person', 'foiperson@localhost', '"FOI \" Person" ']) end - end RSpec.describe 'when getting the content type of a mail part' do - def expect_content_type(fixture_file, content_type) mail = get_fixture_mail(fixture_file) expect(MailHandler.get_content_type(mail)).to eq(content_type) @@ -288,11 +273,9 @@ def expect_content_type(fixture_file, content_type) expect(MailHandler.get_content_type(report.parts[1])).to eq('message/delivery-status') expect(MailHandler.get_content_type(report.parts[2])).to eq('message/rfc822') end - end RSpec.describe 'when getting header strings' do - def expect_header_string(fixture_file, header, header_string) mail = get_fixture_mail(fixture_file) expect(MailHandler.get_header_string(header, mail)).to eq(header_string) @@ -315,7 +298,6 @@ def expect_header_string(fixture_file, header, header_string) 'X-POST-MessageClass', '9; Autoresponder') end - end RSpec.describe "when parsing HTML mail" do @@ -324,7 +306,6 @@ def expect_header_string(fixture_file, header, header_string) plain_text = MailHandler.get_attachment_text_one_file('text/html', html) expect(plain_text).to match(/është/) end - end RSpec.describe "when getting the attachment text" do @@ -342,11 +323,9 @@ def expect_header_string(fixture_file, header, header_string) text = MailHandler.get_attachment_text_one_file('application/zip', zip_contents) expect(text.encoding.to_s).to eq('UTF-8') end - end RSpec.describe 'when getting attachment attributes' do - it 'should handle an Outlook attachment with HTML generated from RTF' do mail = get_fixture_mail('outlook-encoding-rtf.email') attribute_hashes = MailHandler.get_attachment_attributes(mail) @@ -550,11 +529,9 @@ def expect_header_string(fixture_file, header, header_string) expect(attr).to eq(expected_attributes[index]) end end - end RSpec.describe 'when getting the address part from an address string' do - it 'should handle non-ascii characters in the name input' do address = "\"Someone’s name\" " expect(MailHandler.address_from_string(address)).to eq('test@example.com') diff --git a/spec/lib/patch_tag_helper_spec.rb b/spec/lib/patch_tag_helper_spec.rb index 3b2ef132cc..9257b131a7 100644 --- a/spec/lib/patch_tag_helper_spec.rb +++ b/spec/lib/patch_tag_helper_spec.rb @@ -14,5 +14,4 @@ to eq('

content

') end end - end diff --git a/spec/lib/public_body_csv_spec.rb b/spec/lib/public_body_csv_spec.rb index c31474588d..0e21e34bcc 100644 --- a/spec/lib/public_body_csv_spec.rb +++ b/spec/lib/public_body_csv_spec.rb @@ -6,7 +6,6 @@ end describe '.default_fields' do - it 'has a default set of fields' do defaults = [:id, :name, @@ -25,7 +24,6 @@ end describe '.default_headers' do - it 'has a default set of headers' do defaults = ['Internal ID', 'Name', @@ -70,7 +68,6 @@ end describe '#fields' do - it 'has a default set of fields' do csv = PublicBodyCSV.new expect(csv.fields).to eq(PublicBodyCSV.default_fields) @@ -88,11 +85,9 @@ csv = PublicBodyCSV.new(fields: custom_fields) expect(csv.fields).to eq(custom_fields) end - end describe '#headers' do - it 'has a default set of headers' do csv = PublicBodyCSV.new expect(csv.headers).to eq(PublicBodyCSV.default_headers) @@ -103,20 +98,16 @@ csv = PublicBodyCSV.new(headers: custom_headers) expect(csv.headers).to eq(custom_headers) end - end describe '#rows' do - it 'is empty on instantiation' do csv = PublicBodyCSV.new expect(csv.rows).to be_empty end - end describe '#<<' do - it 'adds an elements attributes to the rows collection' do attrs = { name: 'Exported to CSV', short_name: 'CSV', @@ -133,11 +124,9 @@ expected = ["#{body.id},Exported to CSV,CSV,csv,exported,https://www.localhost,\"\",\"\",An exported authority,2007-10-25 10:51:01 UTC,2007-10-25 10:51:01 UTC,1"] expect(csv.rows).to eq(expected) end - end describe '#generate' do - it 'generates the csv' do attrs1 = { name: 'Exported to CSV 1', short_name: 'CSV1', @@ -173,7 +162,5 @@ csv << body2 expect(csv.generate).to eq(expected) end - end - end diff --git a/spec/lib/quiet_open_spec.rb b/spec/lib/quiet_open_spec.rb index ae68884355..547127b807 100644 --- a/spec/lib/quiet_open_spec.rb +++ b/spec/lib/quiet_open_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe "quietly_try_to_open" do - let(:controller) { double(ApplicationController) } let(:uri) { "http://example.com/feed" } @@ -18,5 +17,4 @@ expect(URI).to receive(:open).with(uri, read_timeout: 100).and_call_original controller.send(:quietly_try_to_open, uri, 100) end - end diff --git a/spec/lib/safe_redirect_spec.rb b/spec/lib/safe_redirect_spec.rb index f93aca97f4..1f86ea8b7a 100644 --- a/spec/lib/safe_redirect_spec.rb +++ b/spec/lib/safe_redirect_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe SafeRedirect do - describe '.new' do - it 'requires a redirect_parameter' do expect { subject }.to raise_error(ArgumentError) end @@ -16,7 +14,6 @@ it 'rejects an invalid redirect_parameter' do expect { described_class.new(123) }.to raise_error(URI::InvalidURIError) end - end describe '#path' do @@ -28,7 +25,6 @@ it 'returns the path' do expect(subject).to eq('/request/the_cost_of_boring') end - end context 'with query parameters' do @@ -37,7 +33,6 @@ it 'strips the query parameters' do expect(subject).to eq('/request/the_cost_of_boring') end - end context 'with an anchor' do @@ -46,7 +41,6 @@ it 'retains the anchor' do expect(subject).to eq('/request/the_cost_of_boring#incoming-1') end - end context 'with query parameters and an anchor' do @@ -55,7 +49,6 @@ it 'strips the query parameters and retains the anchor' do expect(subject).to eq('/request/the_cost_of_boring#incoming-1') end - end context 'with a host component' do @@ -64,7 +57,6 @@ it 'strips the host' do expect(subject).to eq('/request/hello') end - end context 'with an optional query' do @@ -75,9 +67,6 @@ it 'appends the query string' do expect(subject).to eq('/request/hello?emergency=1') end - end - end - end diff --git a/spec/lib/theme_spec.rb b/spec/lib/theme_spec.rb index 9f80334db9..0f8fd67053 100644 --- a/spec/lib/theme_spec.rb +++ b/spec/lib/theme_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe "theme_url_to_theme_name" do - it "should deal with a typical bare repo URL" do url = 'git://wherever/blah-theme.git' expect(theme_url_to_theme_name(url)).to eq('blah-theme') @@ -21,5 +20,4 @@ url = '/home/whoever/themes/blah-theme/' expect(theme_url_to_theme_name(url)).to eq('blah-theme') end - end diff --git a/spec/lib/typeahead_search_spec.rb b/spec/lib/typeahead_search_spec.rb index 2c5f00eb80..57c6662b35 100644 --- a/spec/lib/typeahead_search_spec.rb +++ b/spec/lib/typeahead_search_spec.rb @@ -4,7 +4,6 @@ let(:options) { { model: InfoRequestEvent } } describe "#initialize" do - it 'assigns the query' do expect(TypeaheadSearch.new("chicken", options).query).to eq("chicken") end @@ -38,11 +37,9 @@ it 'sets run_search to true' do expect(TypeaheadSearch.new("chicken", options).run_search).to be true end - end describe '#options' do - it 'sets the offset based on the page and per_page settings' do opts = options.merge(page: 2, per_page: 10) expect(TypeaheadSearch.new("chicken", opts).options[:offset]). @@ -86,11 +83,9 @@ expect(TypeaheadSearch.new("chicken", options).options[:sort_by_ascending]). to be true end - end describe "#xapian_search" do - before do update_xapian_index end @@ -153,7 +148,6 @@ def search_bodies(xapian_search) to match_array([info_requests(:naughty_chicken_request)]) end - it "returns a search with matches for the complete words in searches ending in short words" do search = TypeaheadSearch.new("chicken a", options).xapian_search @@ -161,7 +155,6 @@ def search_bodies(xapian_search) to match_array([info_requests(:naughty_chicken_request)]) end - it "returns a search with matches for the complete words and partial words in searches ending in longer words" do search = TypeaheadSearch.new("dog chick", options).xapian_search @@ -218,18 +211,15 @@ def search_bodies(xapian_search) end context 'when the exclude_tags option is used' do - it "returns a search excluding results with those tags" do opts = options.merge( model: PublicBody, exclude_tags: [ 'lonely_agency' ]) search = TypeaheadSearch.new("lonely", opts).xapian_search expect(search.results).to match_array([]) end - end context 'when max wildcard limit is reached' do - around do |example| ActsAsXapian.prepare_environment limit = ActsAsXapian.max_wildcard_expansion @@ -244,8 +234,6 @@ def search_bodies(xapian_search) change(search, :wildcard).from(true).to(false) ) end - end end end - diff --git a/spec/lib/user_spam_scorer_spec.rb b/spec/lib/user_spam_scorer_spec.rb index 353db2b64b..add5b71409 100644 --- a/spec/lib/user_spam_scorer_spec.rb +++ b/spec/lib/user_spam_scorer_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' RSpec.describe UserSpamScorer do - after(:each) { described_class.reset } describe '.currency_symbols' do - it 'sets a default currency_symbols value' do expect(described_class.currency_symbols). to eq(described_class::DEFAULT_CURRENCY_SYMBOLS) @@ -15,11 +13,9 @@ described_class.currency_symbols = %w(£ $) expect(described_class.currency_symbols).to eq(%w(£ $)) end - end describe '.score_mappings' do - it 'sets a default score_mappings value' do expect(described_class.score_mappings). to eq(described_class::DEFAULT_SCORE_MAPPINGS) @@ -29,11 +25,9 @@ described_class.score_mappings = { name_is_one_word?: 7 } expect(described_class.score_mappings).to eq({ name_is_one_word?: 7 }) end - end describe '.suspicious_domains' do - it 'sets a default suspicious_domains value' do expect(described_class.suspicious_domains). to eq(described_class::DEFAULT_SUSPICIOUS_DOMAINS) @@ -43,11 +37,9 @@ described_class.suspicious_domains = %w(example.com) expect(described_class.suspicious_domains).to eq(%w(example.com)) end - end describe '.spam_domains' do - it 'sets a default spam_domains value' do expect(described_class.spam_domains). to eq(described_class::DEFAULT_SPAM_DOMAINS ) @@ -57,11 +49,9 @@ described_class.spam_domains = %w(example.com) expect(described_class.spam_domains).to eq(%w(example.com)) end - end describe '.spam_name_formats' do - it 'sets a default spam_name_formats value' do expect(described_class.spam_name_formats). to eq(described_class::DEFAULT_SPAM_NAME_FORMATS) @@ -71,11 +61,9 @@ described_class.spam_name_formats = [/\A.*$/] expect(described_class.spam_name_formats).to eq([/\A.*$/]) end - end describe '.spam_about_me_formats' do - it 'sets a default spam_about_me_formats value' do expect(described_class.spam_about_me_formats). to eq(described_class::DEFAULT_SPAM_ABOUT_ME_FORMATS) @@ -85,11 +73,9 @@ described_class.spam_about_me_formats = [/\A.*$/] expect(described_class.spam_about_me_formats).to eq([/\A.*$/]) end - end describe '.spam_score_threshold' do - it 'sets a default spam_score_threshold value' do expect(described_class.spam_score_threshold). to eq(described_class::DEFAULT_SPAM_SCORE_THRESHOLD) @@ -99,11 +85,9 @@ described_class.spam_score_threshold = 1 expect(described_class.spam_score_threshold).to eq(1) end - end describe '.spam_tlds' do - it 'sets a default spam_tlds value' do expect(described_class.spam_tlds). to eq(described_class::DEFAULT_SPAM_TLDS) @@ -113,11 +97,9 @@ described_class.spam_tlds = %w(ru) expect(described_class.spam_tlds).to eq(%w(ru)) end - end describe '.reset' do - it 'resets the class instance variables' do attrs = described_class::CLASS_ATTRIBUTES @@ -140,11 +122,9 @@ it 'returns the list of attributes that were reset' do expect(described_class.reset).to eq(described_class::CLASS_ATTRIBUTES) end - end describe '.new' do - it 'sets a default currency_symbols value' do expect(subject.currency_symbols).to eq(described_class.currency_symbols) end @@ -211,11 +191,9 @@ scorer = described_class.new(spam_tlds: %w(com)) expect(scorer.spam_tlds).to eq(%w(com)) end - end describe '#spam?' do - it 'returns true if the user spam score is above the threshold' do user_attrs = { name: 'spammer', comments: [], track_things: [] } user = mock_model(User, user_attrs) @@ -242,11 +220,9 @@ scorer = described_class.new(attrs) expect(scorer.spam?(user)).to eq(false) end - end describe '#score' do - it 'returns 0 if no mappings return true' do user_attrs = { name: 'Bob Smith', comments: [], @@ -293,11 +269,9 @@ scorer = described_class.new(score_mappings: { invalid_method: 1 }) expect { scorer.score(user) }.to raise_error(NoMethodError) end - end describe '#name_is_all_lowercase?' do - it 'is true if the name is all lowercase' do user = mock_model(User, name: 'bob smith 123') expect(subject.name_is_all_lowercase?(user)).to eq(true) @@ -307,11 +281,9 @@ user = mock_model(User, name: 'Bob smith 123') expect(subject.name_is_all_lowercase?(user)).to eq(false) end - end describe '#name_is_one_word?' do - it 'is true if the name is one word' do user = mock_model(User, name: 'bobsmith123') expect(subject.name_is_one_word?(user)).to eq(true) @@ -321,11 +293,9 @@ user = mock_model(User, name: 'bob smith 123') expect(subject.name_is_one_word?(user)).to eq(false) end - end describe '#name_is_garbled?' do - it 'is true if the name includes 5 consecutive consonants' do user = mock_model(User, name: 'JWahewKjWhebCd') expect(subject.name_is_garbled?(user)).to eq(true) @@ -335,11 +305,9 @@ user = mock_model(User, name: 'Bob Smith') expect(subject.name_is_garbled?(user)).to eq(false) end - end describe '#name_includes_non_alpha_characters?' do - it 'is true if the name includes numbers' do user = mock_model(User, name: 'Bob smith 123') expect(subject.name_includes_non_alpha_characters?(user)).to eq(true) @@ -359,11 +327,9 @@ user = mock_model(User, name: 'Bob smith') expect(subject.name_includes_non_alpha_characters?(user)).to eq(false) end - end describe '#email_from_suspicious_domain?' do - it 'is true if the email is from a suspicious domain' do mock_suspicious_domains = %w(example.com example.net example.org) user = mock_model(User, email_domain: 'example.net') @@ -379,11 +345,9 @@ suspicious_domains: mock_suspicious_domains) expect(scorer.email_from_suspicious_domain?(user)).to eq(false) end - end describe '#email_from_spam_domain?' do - it 'is true if the email is from a spam domain' do mock_spam_domains = %w(example.com example.net example.org) user = mock_model(User, email_domain: 'example.net') @@ -397,11 +361,9 @@ scorer = described_class.new(spam_domains: mock_spam_domains) expect(scorer.email_from_spam_domain?(user)).to eq(false) end - end describe '#email_from_spam_tld?' do - it 'is true if the email is from a spam tld' do mock_spam_tlds = %w(com net org) user = mock_model(User, email_domain: 'example.net') @@ -415,11 +377,9 @@ scorer = described_class.new(spam_tlds: mock_spam_tlds) expect(scorer.email_from_spam_tld?(user)).to eq(false) end - end describe '#name_is_spam_format?' do - it 'is true if the name matches a spammy format' do mock_spam_formats = [/\A.*support.*\z/] user = mock_model(User, name: 'support') @@ -435,7 +395,6 @@ end context 'the default spam formats' do - it 'is true if it matches bitcoin' do user = mock_model(User, name: 'bitcointocash') expect(subject.name_is_spam_format?(user)).to eq(true) @@ -505,13 +464,10 @@ user = mock_model(User, name: 'Unify CRM') expect(subject.name_is_spam_format?(user)).to eq(true) end - end - end describe '#about_me_includes_currency_symbol?' do - it 'is true if the about me includes a currency symbol' do mock_currency_symbols = %w(£ $) user = mock_model(User, about_me: 'Spam for just $100') @@ -525,11 +481,9 @@ scorer = described_class.new(currency_symbols: mock_currency_symbols) expect(scorer.about_me_includes_currency_symbol?(user)).to eq(false) end - end describe '#about_me_is_link_only?' do - it 'is true if the about me is just a HTTP URL' do user = mock_model(User, about_me: 'http://example.com') expect(subject.about_me_is_link_only?(user)).to eq(true) @@ -559,11 +513,9 @@ user = mock_model(User, about_me: 'HTTP://EXAMPLE.COM') expect(subject.about_me_is_link_only?(user)).to eq(true) end - end describe '#about_me_is_spam_format?' do - it 'is true if the about me matches a spammy format' do mock_spam_formats = [/\A.*+\n{2,}https?:\/\/[^\s]+\z/] user = mock_model(User, about_me: <<-EOF.strip_heredoc) @@ -592,7 +544,6 @@ end context 'the default spam formats' do - it 'is true if it matches TEXT\n\nURL' do user = mock_model(User, about_me: <<-EOF.strip_heredoc) Some spam often looks like this spam @@ -621,13 +572,10 @@ EOF expect(subject.about_me_is_spam_format?(user)).to eq(true) end - end - end describe '#about_me_includes_anchor_tag?' do - it 'is true if the about me includes an a tag' do user = mock_model(User, about_me: 'Spam link here') expect(subject.about_me_includes_anchor_tag?(user)).to eq(true) @@ -640,7 +588,6 @@ end describe '#about_me_already_exists?' do - it 'is true if the about me already exists' do user = mock_model(User, about_me_already_exists?: true) expect(subject.about_me_already_exists?(user)).to eq(true) @@ -650,11 +597,9 @@ user = mock_model(User, about_me_already_exists?: false) expect(subject.about_me_already_exists?(user)).to eq(false) end - end describe '#user_agent_is_suspicious?' do - before { UserSpamScorer.suspicious_user_agents = ['cURL'] } after { UserSpamScorer.reset } @@ -672,11 +617,9 @@ user = mock_model(User) expect(subject.user_agent_is_suspicious?(user)).to eq(false) end - end describe '#ip_range_is_suspicious?' do - before { UserSpamScorer.suspicious_ip_ranges = ['127.0.0.0/8'] } after { UserSpamScorer.reset } @@ -694,7 +637,5 @@ user = mock_model(User) expect(subject.ip_range_is_suspicious?(user)).to eq(false) end - end - end diff --git a/spec/lib/user_stats_spec.rb b/spec/lib/user_stats_spec.rb index 39ed5af1b7..1dca7ef0da 100644 --- a/spec/lib/user_stats_spec.rb +++ b/spec/lib/user_stats_spec.rb @@ -1,11 +1,8 @@ require 'spec_helper' RSpec.describe UserStats do - describe ".list_user_domains" do - context "in general" do - before do User.destroy_all FactoryBot.create(:user, email: "test1@localhost") @@ -35,7 +32,6 @@ end context "when passed a start date" do - before do travel_to 1.week.ago FactoryBot.create(:user, email: "test@example.com") @@ -50,11 +46,9 @@ expect(UserStats.list_user_domains(start_date: 2.weeks.ago)). to eq(expected) end - end context "when passed a limit" do - before do FactoryBot.create(:user, email: "test@example.com") FactoryBot.create(:user, email: "test@yandex.com") @@ -66,9 +60,7 @@ expect(UserStats.list_user_domains.count).to eq(5) expect(UserStats.list_user_domains(limit: 4).count).to eq(4) end - end - end describe ".count_dormant_users" do @@ -95,14 +87,11 @@ end context "when passed a start date" do - it "only returns data for signups created since the start date" do expect(UserStats.count_dormant_users("example.com", 1.week.ago)). to eq(1) end - end - end describe ".unbanned_by_domain" do @@ -131,14 +120,10 @@ end context "when given a start date" do - it "only returns data for signups created since the start date" do expect(UserStats.unbanned_by_domain("example.com", 1.week.ago)). to match_array([@user2]) end - end - end - end diff --git a/spec/lib/world_foi_websites_spec.rb b/spec/lib/world_foi_websites_spec.rb index 7b2e3a7649..ac9a466b87 100644 --- a/spec/lib/world_foi_websites_spec.rb +++ b/spec/lib/world_foi_websites_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe WorldFOIWebsites do - describe '.can_ask_the_eu?' do - it 'is false if the current site is AskTheEU' do allow(AlaveteliConfiguration). to receive(:domain).and_return('www.asktheeu.org') @@ -17,7 +15,5 @@ it 'is true if the current user is in an EU country' do expect(described_class.can_ask_the_eu?('ES')).to eq(true) end - end - end diff --git a/spec/mailers/alaveteli_pro/account_mailer_spec.rb b/spec/mailers/alaveteli_pro/account_mailer_spec.rb index b2dca0ce49..8543a42503 100644 --- a/spec/mailers/alaveteli_pro/account_mailer_spec.rb +++ b/spec/mailers/alaveteli_pro/account_mailer_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::AccountMailer do - describe '#account_request' do let(:account_request) do AlaveteliPro::AccountRequest.new(email: 'test@localhost', @@ -50,5 +49,4 @@ to match("Training emails opt-in: #{account_request.training_emails}") end end - end diff --git a/spec/mailers/alaveteli_pro/embargo_mailer_spec.rb b/spec/mailers/alaveteli_pro/embargo_mailer_spec.rb index c5de3f7499..8257af5381 100644 --- a/spec/mailers/alaveteli_pro/embargo_mailer_spec.rb +++ b/spec/mailers/alaveteli_pro/embargo_mailer_spec.rb @@ -163,7 +163,6 @@ end describe '.alert_expired' do - it 'only sends one email per user' do AlaveteliPro::EmbargoMailer.alert_expired mails = ActionMailer::Base.deliveries @@ -234,7 +233,6 @@ end describe '#expired_alert' do - context "when there's just one embargo" do before do @message = AlaveteliPro::EmbargoMailer. @@ -254,11 +252,9 @@ it "sends the email from the pro contact address" do expect(@message.from).to eq [AlaveteliConfiguration.pro_contact_email] end - end context "when there are multiple embargoes" do - before do @message = AlaveteliPro::EmbargoMailer. expired_alert(pro_user, [expired_1, expired_2]). @@ -277,9 +273,6 @@ it "sends the email from the pro contact address" do expect(@message.from).to eq [AlaveteliConfiguration.pro_contact_email] end - end - end - end diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index dff823ad87..98ef8dc40d 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -1,10 +1,7 @@ require 'spec_helper' - RSpec.describe ApplicationMailer do - context 'when using plugins' do - def set_base_views ApplicationMailer.class_eval do @previous_view_paths = view_paths.dup @@ -58,7 +55,6 @@ def create_multipart_method(method_name) end describe 'when a plugin prepends its mail templates to the view paths' do - it 'should render a theme template in preference to a core template' do prepend_theme_views('theme_one') @mail = ApplicationMailer.simple @@ -101,11 +97,9 @@ def create_multipart_method(method_name) message_part = @mail.parts[0].to_s expect(message_part).to match("Core multipart") end - end describe 'when a plugin appends its mail templates to the view paths' do - it 'should render a core template in preference to a theme template' do append_theme_views('theme_one') @mail = ApplicationMailer.simple @@ -148,7 +142,6 @@ def create_multipart_method(method_name) message_part = @mail.parts[0].to_s expect(message_part).to match("Theme multipart") end - end after do @@ -156,5 +149,4 @@ def create_multipart_method(method_name) remove_mail_methods(%w[simple theme_only core_only neither multipart]) end end - end diff --git a/spec/mailers/contact_mailer_spec.rb b/spec/mailers/contact_mailer_spec.rb index b793993609..0b8590b3bd 100644 --- a/spec/mailers/contact_mailer_spec.rb +++ b/spec/mailers/contact_mailer_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe ContactMailer do - describe :to_admin_message do - it 'correctly quotes the name in a "from" address' do expect(ContactMailer.to_admin_message("A,B,C.", "test@example.com", @@ -88,7 +86,6 @@ end end end - end describe "#from_admin_message" do @@ -132,5 +129,4 @@ end end end - end diff --git a/spec/mailers/info_request_batch_mailer_spec.rb b/spec/mailers/info_request_batch_mailer_spec.rb index 83e1edb89e..1391bfe2b2 100644 --- a/spec/mailers/info_request_batch_mailer_spec.rb +++ b/spec/mailers/info_request_batch_mailer_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequestBatchMailer do - describe 'when sending batch sent notification' do - before do @user = FactoryBot.create(:user) @info_request_batch = FactoryBot.create( diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 06dc28f7ec..72c68d5418 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -600,11 +600,9 @@ end context 'when the subject has characters which need quoting' do - it 'should not error' do NotificationMailer.expire_embargo_notification(notification) end - end context 'when the subject has characters which could be HTML escaped' do @@ -654,7 +652,6 @@ 'notification_mailer/expire_embargo.txt', 'r:utf-8') expect(mail.body.encoded).to eq(expected_message) end - end describe '#overdue_notification' do diff --git a/spec/mailers/outgoing_mailer_spec.rb b/spec/mailers/outgoing_mailer_spec.rb index 95f1e3480b..0c1fae4681 100644 --- a/spec/mailers/outgoing_mailer_spec.rb +++ b/spec/mailers/outgoing_mailer_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe OutgoingMailer, " when working out follow up names and addresses" do - before do @info_request = mock_model(InfoRequest, recipient_name_and_email: 'test ', @@ -13,17 +12,14 @@ end describe 'if there is no incoming message being replied to' do - it 'should return the name and email address of the public body' do expect(OutgoingMailer.name_and_email_for_followup(@info_request, nil)).to eq('test ') expect(OutgoingMailer.name_for_followup(@info_request, nil)).to eq('Test Authority') expect(OutgoingMailer.email_for_followup(@info_request, nil)).to eq('test@example.com') end - end describe 'if the incoming message being replied to is not valid to reply to' do - before do allow(@incoming_message).to receive(:valid_to_reply_to?).and_return(false) end @@ -36,7 +32,6 @@ end describe 'if the incoming message is valid to reply to' do - before do allow(@incoming_message).to receive(:valid_to_reply_to?).and_return(true) end @@ -52,13 +47,10 @@ allow(@incoming_message).to receive(:safe_from_name).and_return(nil) expect(OutgoingMailer.name_for_followup(@info_request, @incoming_message)).to eq('Test Authority') end - end - end RSpec.describe OutgoingMailer, "when working out follow up subjects" do - before(:each) do load_raw_emails_data end @@ -122,7 +114,6 @@ end context "dealing with an internal review" do - it "prefixes the subject of the message with 'Internal review of " \ "Freedom of Information request'" do request = FactoryBot.create(:info_request_with_internal_review_request, @@ -142,6 +133,5 @@ to eq("Internal review of Freedom of Information request - " \ "Apostrophe's Test") end - end end diff --git a/spec/mailers/reminder_mailer_spec.rb b/spec/mailers/reminder_mailer_spec.rb index 8754accd99..944c31e51e 100644 --- a/spec/mailers/reminder_mailer_spec.rb +++ b/spec/mailers/reminder_mailer_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe ReminderMailer do - describe :public_holidays do - it 'correctly quotes the name in a "from" address' do expect(ReminderMailer.public_holidays("A,B,C.", "test@example.com", @@ -21,7 +19,5 @@ "test@example.com", "test").header['Return-Path'].to_s).to eq('do-not-reply-to-this-address@localhost') end - end - end diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 0a61857cfe..95328772ac 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe RequestMailer do - describe "when receiving incoming mail" do - before(:each) do load_raw_emails_data ActionMailer::Base.deliveries = [] @@ -146,7 +144,6 @@ expect(InfoRequest.holding_pen_request.incoming_messages.count).to eq(1) end - it "attaches messages with an info request address in the Received headers to the appropriate request" do ir = info_requests(:fancy_dog_request) expect(ir.incoming_messages.count).to eq(1) # in the fixture @@ -414,7 +411,6 @@ expect(deliveries.size).to eq(0) end - it "should not mutilate long URLs when trying to word wrap them" do long_url = 'http://www.this.is.quite.a.long.url.flourish.org/there.is.no.way.it.is.short.whatsoever' body = "This is a message with quite a long URL in it. It also has a paragraph, being this one that has quite a lot of text in it to. Enough to test the wrapping of itself. @@ -425,11 +421,9 @@ wrapped = MySociety::Format.wrap_email_body_by_paragraphs(body) expect(wrapped).to include(long_url) end - end describe 'when sending emails' do - it 'renders the footer partial for a user email' do expect_any_instance_of(RequestMailer).to receive(:set_footer_template) info_request = FactoryBot.create(:waiting_clarification_info_request) @@ -448,12 +442,9 @@ "The content of blah.txt") mail.message end - end - describe "when sending reminders to requesters to classify a response to their request" do - let(:old_request) do InfoRequest.destroy_all FactoryBot.create(:old_unclassified_request) @@ -479,7 +470,6 @@ def sent_alert_params(request, type) end context 'if the request is embargoed' do - it 'sends the reminder' do old_request.create_embargo(publish_at: Time.zone.now + 3.days) send_alerts @@ -488,22 +478,18 @@ def sent_alert_params(request, type) expect(mail.body).to match(/#{old_request.title}/) expect(mail.body).to match(/Letting everyone know whether you got the information/) end - end context 'if an alert matching the attributes of the reminder to be sent has already been sent' do - it 'should not send the reminder' do params = sent_alert_params(old_request, 'new_response_reminder_1') UserInfoRequestSentAlert.create!(params) expect(RequestMailer).not_to receive(:new_response_reminder_alert) send_alerts end - end context 'if no alert matching the attributes of the reminder to be sent has already been sent' do - before do allow(UserInfoRequestSentAlert).to receive(:find).and_return(nil) end @@ -520,8 +506,6 @@ def sent_alert_params(request, type) mail = deliveries[0] expect(mail.body).to match(/Letting everyone know whether you got the information/) end - - end context "if the request has use_notifications set to true" do @@ -532,11 +516,9 @@ def sent_alert_params(request, type) send_alerts end end - end describe "when sending mail when someone has updated an old unclassified request" do - let(:user) do FactoryBot.create(:user, name: "test name", email: "email@localhost") end @@ -567,11 +549,9 @@ def sent_alert_params(request, type) it 'should contain the request path' do expect(mail.body).to match(/request\/test_request/) end - end describe "when generating a fake response for an upload" do - before do @foi_officer = mock_model(User, name_and_email: "FOI officer's name and email") @request_user = mock_model(User) @@ -589,11 +569,9 @@ def sent_alert_params(request, type) "The content of blah.txt") expect(fake_email.subject).to eq("Re: Freedom of Information - Test request") end - end describe "when sending a new response email" do - let(:user) do FactoryBot.create(:user, name: "test name", email: "email@localhost") @@ -646,11 +624,9 @@ def sent_alert_params(request, type) expected_url = incoming_message_url(incoming_message, cachebust: true) expect(mail_url).to eq expected_url end - end describe "sending unclassified new response reminder alerts" do - before(:each) do load_raw_emails_data end @@ -677,11 +653,9 @@ def sent_alert_params(request, type) # Split on %23 as the redirect is URL encoded expect(mail_url.split('%23').last).to eq('describe_state_form_1') end - end describe "requires_admin" do - let(:user) do FactoryBot.create(:user, name: "Bruce Jones", email: "bruce@example.com") @@ -739,11 +713,9 @@ def sent_alert_params(request, type) end end end - end describe "sending overdue request alerts", focus: true do - before(:each) do @kitten_request = FactoryBot.create(:info_request, title: "Do you really own a kitten?") @@ -803,7 +775,6 @@ def kitten_mails it "sends alerts for requests where the last event forming the initial request is a followup being sent following a request for clarification" do - # Request is waiting clarification @kitten_request.set_described_state('waiting_clarification') @@ -863,7 +834,6 @@ def kitten_mails end context "very overdue alerts" do - it 'should not create HTML entities in the subject line' do info_request = FactoryBot.create(:info_request, title: "Here's a request") @@ -917,40 +887,31 @@ def kitten_mails expect(mails).to be_empty end end - end - end describe "not_clarified_alert" do - it 'should not create HTML entities in the subject line' do mail = RequestMailer.not_clarified_alert(FactoryBot.create(:info_request, title: "Here's a request"), FactoryBot.create(:incoming_message)) expect(mail.subject).to eq "Clarify your FOI request - Here's a request" end - end describe "comment_on_alert" do - it 'should not create HTML entities in the subject line' do mail = RequestMailer.comment_on_alert(FactoryBot.create(:info_request, title: "Here's a request"), FactoryBot.create(:comment)) expect(mail.subject).to eq "Somebody added a note to your FOI request - Here's a request" end - end describe "comment_on_alert_plural" do - it 'should not create HTML entities in the subject line' do mail = RequestMailer.comment_on_alert_plural(FactoryBot.create(:info_request, title: "Here's a request"), 2, FactoryBot.create(:comment)) expect(mail.subject).to eq "Some notes have been added to your FOI request - Here's a request" end - end describe "clarification required alerts" do - before(:each) do load_raw_emails_data end @@ -1042,7 +1003,6 @@ def force_updated_at_to_past(request) deliveries = ActionMailer::Base.deliveries expect(deliveries.size).to eq(0) end - end describe "comment alerts" do @@ -1133,7 +1093,5 @@ def force_updated_at_to_past(request) mail = deliveries[0] expect(mail.to_addrs.first.to_s).to eq(info_request.user.email) end - end - end diff --git a/spec/mailers/survey_mailer_spec.rb b/spec/mailers/survey_mailer_spec.rb index 8bf5bf0579..80dc47046f 100644 --- a/spec/mailers/survey_mailer_spec.rb +++ b/spec/mailers/survey_mailer_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe SurveyMailer do - describe 'survey alerts' do - before do allow(Survey).to receive(:enabled?).and_return(true) InfoRequest.destroy_all @@ -22,7 +20,6 @@ def get_surveyable_request(user = nil) end context 'when there is a requester who has not been sent a survey alert' do - it 'sends a survey alert' do get_surveyable_request SurveyMailer.alert_survey @@ -35,11 +32,9 @@ def get_surveyable_request(user = nil) expect(info_request.user.user_info_request_sent_alerts.size). to eq(1) end - end context 'when a user has made multiple qualifying requests' do - it 'does not send multiple alerts' do request = get_surveyable_request get_surveyable_request(request.user) @@ -49,7 +44,6 @@ def get_surveyable_request(user = nil) end context 'when a user can not be sent the survey' do - it 'does not send a survey alert' do allow_any_instance_of(User).to receive(:can_send_survey?). and_return(false) @@ -57,11 +51,9 @@ def get_surveyable_request(user = nil) SurveyMailer.alert_survey expect(ActionMailer::Base.deliveries.size).to eq(0) end - end context 'when survery is not enabled' do - before do allow(Survey).to receive(:enabled?).and_return(false) end @@ -69,9 +61,6 @@ def get_surveyable_request(user = nil) it 'does not send survey alerts ' do expect(SurveyMailer.alert_survey).to be_nil end - end - end - end diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb index 24a4121e68..c7e8c62c9a 100644 --- a/spec/mailers/track_mailer_spec.rb +++ b/spec/mailers/track_mailer_spec.rb @@ -135,7 +135,6 @@ TrackMailer.alert_tracks end end - end describe 'when a user should not be emailed' do @@ -178,11 +177,9 @@ it { is_expected.to eq(false) } end - end describe 'delivering the email' do - before :each do allow(AlaveteliConfiguration).to receive(:site_name). and_return("L'information") @@ -263,5 +260,4 @@ end end end - end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 293184420a..2456e7137b 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -193,7 +193,6 @@ end context 'with pro enabled' do - it 'should return false for an admin user' do with_feature_enabled(:alaveteli_pro) do expect(admin_ability).not_to be_able_to(:read, resource) @@ -228,7 +227,6 @@ end context 'with pro enabled' do - it 'should return false for an admin user' do with_feature_enabled(:alaveteli_pro) do expect(admin_ability).not_to be_able_to(:read, resource) @@ -240,7 +238,6 @@ expect(pro_admin_ability).to be_able_to(:read, resource) end end - end it 'should return false if the user does not own the right resource' do @@ -260,7 +257,6 @@ end context 'with pro enabled' do - it 'should return false for an admin user' do with_feature_enabled(:alaveteli_pro) do expect(admin_ability).not_to be_able_to(:read, resource) @@ -272,7 +268,6 @@ expect(pro_admin_ability).to be_able_to(:read, resource) end end - end context 'with project' do @@ -357,9 +352,7 @@ expect(owner_ability).to be_able_to(:read, resource) end end - end - end describe 'sharing InfoRequests' do @@ -669,7 +662,6 @@ end context "when the user owns the batch" do - it 'allows pro users to update the batch' do ability = Ability.new(resource.user) with_feature_enabled(:alaveteli_pro) do @@ -684,7 +676,6 @@ expect(ability).not_to be_able_to(:update, resource) end end - end context "when the user is a pro_admin" do @@ -832,7 +823,6 @@ ability = Ability.new(info_request.user) expect(ability).to be_able_to(:create_embargo, info_request) end - end it "allows pro admins to add an embargo" do @@ -857,9 +847,7 @@ expect(ability).to_not be_able_to(:create_embargo, batch_request) end end - end - end context 'the info request owner is not a pro user' do @@ -875,7 +863,6 @@ ability = Ability.new(user) expect(ability).not_to be_able_to(:create_embargo, info_request) end - end it "prevents pro admins adding an embargo" do @@ -884,7 +871,6 @@ expect(ability).not_to be_able_to(:create_embargo, info_request) end end - end context 'the info request was made anonymously', feature: :alaveteli_pro do @@ -904,13 +890,10 @@ ability = Ability.new(FactoryBot.create(:pro_admin_user)) expect(ability).not_to be_able_to(:create_embargo, info_request) end - end - end describe "Updating Embargoes" do - let(:embargo) do FactoryBot.create(:embargo, user: FactoryBot.create(:pro_user)) end @@ -965,7 +948,6 @@ end describe "Destroying Embargoes" do - let(:embargo) do FactoryBot.create(:embargo, user: FactoryBot.create(:pro_user)) end @@ -1016,11 +998,9 @@ expect(ability).not_to be_able_to(:destroy, embargo) end end - end describe "Destroying Batch Embargoes" do - let(:batch) do FactoryBot.create(:info_request_batch, :embargoed, user: FactoryBot.create(:pro_user)) @@ -1072,7 +1052,6 @@ expect(ability).not_to be_able_to(:destroy_embargo, batch) end end - end describe "Logging in as a user" do @@ -1082,7 +1061,6 @@ let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } context 'when the user has no roles' do - it 'allows an admin user to login as them' do with_feature_enabled(:alaveteli_pro) do ability = Ability.new(admin_user) @@ -1110,11 +1088,9 @@ expect(ability).not_to be_able_to(:login_as, user) end end - end context 'when the user is an admin' do - it 'allows an admin user to login as them' do with_feature_enabled(:alaveteli_pro) do ability = Ability.new(FactoryBot.create(:admin_user)) @@ -1142,11 +1118,9 @@ expect(ability).not_to be_able_to(:login_as, admin_user) end end - end context 'when the user is a pro' do - it 'does not allow an admin user to login as them' do with_feature_enabled(:alaveteli_pro) do ability = Ability.new(admin_user) @@ -1181,11 +1155,9 @@ expect(ability).to be_able_to(:login_as, pro_user) end end - end context 'when the user is a pro_admin user' do - it 'does not allow an admin user to login as them' do with_feature_enabled(:alaveteli_pro) do ability = Ability.new(admin_user) @@ -1266,7 +1238,6 @@ expect(ability).not_to be_able_to(:admin, info_request) end end - end context 'when the request is not embargoed' do @@ -1352,7 +1323,6 @@ expect(ability).not_to be_able_to(:admin, batch) end end - end context 'when the batch is not embargoed' do @@ -1440,7 +1410,6 @@ expect(ability).not_to be_able_to(:admin, comment) end end - end context 'when the request is not embargoed' do @@ -1525,7 +1494,6 @@ expect(ability).not_to be_able_to(:admin, AlaveteliPro::Embargo) end end - end describe 'reading API keys' do @@ -1535,7 +1503,6 @@ let(:pro_admin_user) { FactoryBot.create(:pro_admin_user) } context 'if pro is not enabled' do - it 'allows an admin user to read' do ability = Ability.new(admin_user) expect(ability).to be_able_to(:read, :api_key) @@ -1555,11 +1522,9 @@ ability = Ability.guest expect(ability).not_to be_able_to(:read, :api_key) end - end context 'if pro is enabled' do - it 'allows a pro admin user to read' do with_feature_enabled(:alaveteli_pro) do ability = Ability.new(pro_admin_user) @@ -1594,9 +1559,7 @@ expect(ability).not_to be_able_to(:read, :api_key) end end - end - end describe 'read projects', feature: :projects do diff --git a/spec/models/alaveteli_pro/activity_list/comment_spec.rb b/spec/models/alaveteli_pro/activity_list/comment_spec.rb index 4602cc5094..b5492f0490 100644 --- a/spec/models/alaveteli_pro/activity_list/comment_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/comment_spec.rb @@ -9,14 +9,12 @@ let!(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description for a comment from someone else' do expect(activity.description). to eq '{{commenter_name}} added a new annotation on your request to ' \ '{{public_body_name}} "{{info_request_title}}."' end - it 'gives an appropriate description for a comment from the requester' do info_request = event.info_request info_request.user = comment.user @@ -28,7 +26,6 @@ end describe '#description_urls' do - it 'returns a hash of :commenter_name, :public_body_name and :info_request_title' do expected_urls = @@ -43,18 +40,14 @@ expect(activity.description_urls). to eq expected_urls end - end it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the comment' do expect(activity.call_to_action_url). to eq comment_path(comment) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/embargo_expiry_spec.rb b/spec/models/alaveteli_pro/activity_list/embargo_expiry_spec.rb index dae38eec68..f6d07f2d36 100644 --- a/spec/models/alaveteli_pro/activity_list/embargo_expiry_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/embargo_expiry_spec.rb @@ -9,13 +9,11 @@ let!(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq 'Your request to {{public_body_name}} "{{info_request_title}}" ' \ 'is now public.' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" @@ -23,12 +21,9 @@ it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the info_request' do expect(activity.call_to_action_url). to eq request_path(info_request) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/followup_resent_spec.rb b/spec/models/alaveteli_pro/activity_list/followup_resent_spec.rb index 7d5d4d02df..ffc35a0f9c 100644 --- a/spec/models/alaveteli_pro/activity_list/followup_resent_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/followup_resent_spec.rb @@ -7,13 +7,11 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq 'Your follow up to {{public_body_name}} on ' \ '"{{info_request_title}}" was resent.' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" @@ -21,12 +19,9 @@ it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the followup' do expect(activity.call_to_action_url). to eq outgoing_message_path(event.outgoing_message) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/followup_sent_spec.rb b/spec/models/alaveteli_pro/activity_list/followup_sent_spec.rb index 5ff0a7dedb..7c4e155bf2 100644 --- a/spec/models/alaveteli_pro/activity_list/followup_sent_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/followup_sent_spec.rb @@ -7,13 +7,11 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq 'You sent a follow up to {{public_body_name}} on ' \ '"{{info_request_title}}".' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" @@ -21,12 +19,9 @@ it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the followup' do expect(activity.call_to_action_url). to eq outgoing_message_path(event.outgoing_message) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/item_spec.rb b/spec/models/alaveteli_pro/activity_list/item_spec.rb index 7c21648639..3a78b44a25 100644 --- a/spec/models/alaveteli_pro/activity_list/item_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/item_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::ActivityList::Item do - describe '.new' do it 'requires an event argument' do expect { described_class.new }.to raise_error(ArgumentError) diff --git a/spec/models/alaveteli_pro/activity_list/list_spec.rb b/spec/models/alaveteli_pro/activity_list/list_spec.rb index 4b317973d6..45afd1fd97 100644 --- a/spec/models/alaveteli_pro/activity_list/list_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/list_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::ActivityList::List do - describe '.new' do it 'requires a user, page and per_page arguments' do expect { described_class.new }.to raise_error(ArgumentError) @@ -14,7 +13,6 @@ expect(list.page).to eq 1 expect(list.per_page).to eq 10 end - end describe '#event_types' do @@ -29,11 +27,9 @@ event_types. include?("sent")).to be true end - end describe '#events' do - it "returns the user's info_request_events if included in the event types" do user = FactoryBot.create(:user) @@ -44,11 +40,9 @@ expect(list.events). to eq([info_request.last_event_forming_initial_request]) end - end describe '#current_items' do - it 'returns an array of items representing the current page of events' do user = FactoryBot.create(:user) info_request = FactoryBot.create(:info_request, user: user) @@ -69,7 +63,5 @@ expect(list.current_items.second). to be_a(AlaveteliPro::ActivityList::RequestSent) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/new_response_spec.rb b/spec/models/alaveteli_pro/activity_list/new_response_spec.rb index 68f65fec04..ccbee43868 100644 --- a/spec/models/alaveteli_pro/activity_list/new_response_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/new_response_spec.rb @@ -7,13 +7,11 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq 'Your request to {{public_body_name}}' \ ' "{{info_request_title}}" received a new response.' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" @@ -21,12 +19,9 @@ it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the response' do expect(activity.call_to_action_url). to eq incoming_message_path(event.incoming_message) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/overdue_spec.rb b/spec/models/alaveteli_pro/activity_list/overdue_spec.rb index f106a02c5c..e33cd1ea62 100644 --- a/spec/models/alaveteli_pro/activity_list/overdue_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/overdue_spec.rb @@ -7,33 +7,26 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq '{{public_body_name}} are delayed in responding to your' \ ' request "{{info_request_title}}".' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" describe '#call_to_action' do - it 'returns the text "Send a follow up"' do expect(activity.call_to_action).to eq('Send a follow up') end - end describe '#call_to_action_url' do - it 'returns the url of the info_request' do expect(activity.call_to_action_url). to eq new_request_followup_path(request_id: event.info_request.id, anchor: 'followup') end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/request_resent_spec.rb b/spec/models/alaveteli_pro/activity_list/request_resent_spec.rb index 0cf1605d26..3736d3b23a 100644 --- a/spec/models/alaveteli_pro/activity_list/request_resent_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/request_resent_spec.rb @@ -7,13 +7,11 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq 'Your request "{{info_request_title}}" to {{public_body_name}}' \ ' was resent.' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" @@ -21,12 +19,9 @@ it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the info_request' do expect(activity.call_to_action_url). to eq request_path(event.info_request) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/request_sent_spec.rb b/spec/models/alaveteli_pro/activity_list/request_sent_spec.rb index f78c9cff26..5c87b81532 100644 --- a/spec/models/alaveteli_pro/activity_list/request_sent_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/request_sent_spec.rb @@ -7,13 +7,11 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq 'You sent a request "{{info_request_title}}" to ' \ '{{public_body_name}}.' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" @@ -21,12 +19,9 @@ it_behaves_like "an ActivityList::Item with standard #call_to_action" describe '#call_to_action_url' do - it 'returns the url of the info_request' do expect(activity.call_to_action_url). to eq request_path(event.info_request) end - end - end diff --git a/spec/models/alaveteli_pro/activity_list/very_overdue_spec.rb b/spec/models/alaveteli_pro/activity_list/very_overdue_spec.rb index 625a504d92..524ee12c8b 100644 --- a/spec/models/alaveteli_pro/activity_list/very_overdue_spec.rb +++ b/spec/models/alaveteli_pro/activity_list/very_overdue_spec.rb @@ -7,34 +7,27 @@ let(:activity) { described_class.new(event) } describe '#description' do - it 'gives an appropriate description' do expect(activity.description). to eq '{{public_body_name}} became long overdue in responding ' \ 'to your request "{{info_request_title}}".' end - end it_behaves_like "an ActivityList::Item with standard #description_urls" describe '#call_to_action' do - it 'returns the text "Request an internal review"' do expect(activity.call_to_action).to eq('Request an internal review') end - end describe '#call_to_action_url' do - it 'returns the url of the info_request' do expect(activity.call_to_action_url). to eq new_request_followup_path(request_id: event.info_request.id, anchor: 'followup', internal_review: 1) end - end - end diff --git a/spec/models/alaveteli_pro/embargo_spec.rb b/spec/models/alaveteli_pro/embargo_spec.rb index 288f12d182..f2bd3fc01f 100644 --- a/spec/models/alaveteli_pro/embargo_spec.rb +++ b/spec/models/alaveteli_pro/embargo_spec.rb @@ -108,7 +108,6 @@ expect(latest_event.params[:embargo_extension_id]). to be_nil end - end describe 'extending' do @@ -141,7 +140,6 @@ end describe 'expiring scope' do - it 'includes embargoes expiring in less than a week' do embargo = FactoryBot.create(:embargo, publish_at: Time.now + 6.days) expect(AlaveteliPro::Embargo.expiring.include?(embargo)).to be true @@ -151,11 +149,9 @@ embargo = FactoryBot.create(:embargo, publish_at: Time.now + 8.days) expect(AlaveteliPro::Embargo.expiring.include?(embargo)).to be false end - end describe '#expiring_soon?' do - it 'returns true if the embargo expires in less than a week' do embargo = FactoryBot.build(:embargo, publish_at: Time.zone.now + 6.days) @@ -179,11 +175,9 @@ publish_at: Time.zone.now.beginning_of_day) expect(embargo.expiring_soon?).to be false end - end describe '#expired?' do - it 'returns false if the publication date is in the future' do embargo = FactoryBot.build(:embargo, publish_at: Time.zone.now + 1.day) @@ -200,13 +194,10 @@ embargo = FactoryBot.build(:embargo, publish_at: Time.zone.now) expect(embargo.expired?).to be true end - end describe '.expire_publishable' do - shared_examples_for 'successful_expiry' do - it 'deletes the embargo' do AlaveteliPro::Embargo.expire_publishable expect(info_request.reload.embargo).to be_nil @@ -220,7 +211,6 @@ where(event_type: 'expire_embargo') expect(expiry_events.size).to eq 1 end - end context 'for an embargo whose publish_at date has passed' do @@ -252,7 +242,6 @@ end context 'when the request has use_notifications: true' do - it 'notifies the user of the event' do info_request = FactoryBot.create(:use_notifications_request) embargo = FactoryBot.create(:expiring_embargo, @@ -261,18 +250,14 @@ AlaveteliPro::Embargo.expire_publishable expect(Notification.count).to eq 1 end - end context 'when the request has use_notifications: false' do - it 'does not notify the user of the event' do AlaveteliPro::Embargo.expire_publishable expect(Notification.count).to eq 0 end - end - end context 'for an embargo whose publish_at date is today' do @@ -286,34 +271,27 @@ end end end - end describe '.three_months_from_now' do - it 'returns midnight 91 days from now' do expect(AlaveteliPro::Embargo.three_months_from_now). to eq(Time.zone.now.beginning_of_day + 91.days) end - end describe '.six_months_from_now' do - it 'returns midnight 182 days from now' do expect(AlaveteliPro::Embargo.six_months_from_now). to eq(Time.zone.now.beginning_of_day + 182.days) end - end describe '.twelve_months_from_now' do - it 'returns midnight 364 days from now' do expect(AlaveteliPro::Embargo.twelve_months_from_now). to eq(Time.zone.now.beginning_of_day + 364.days) end - end describe '#calculate_expiring_notification_at' do @@ -450,5 +428,4 @@ def event_count end end end - end diff --git a/spec/models/alaveteli_pro/request_filter_spec.rb b/spec/models/alaveteli_pro/request_filter_spec.rb index 046cadfdc3..8f754468ba 100644 --- a/spec/models/alaveteli_pro/request_filter_spec.rb +++ b/spec/models/alaveteli_pro/request_filter_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliPro::RequestFilter do - describe '#update' do - it 'assigns the filter' do request_filter = described_class.new request_filter.update(filter: 'awaiting_response') @@ -27,11 +25,9 @@ request_filter.update(filter: '') expect(request_filter.filter).to be nil end - end describe '#filter_capital_label' do - def expect_label(label, filter) request_filter = described_class.new request_filter.update(filter: filter) @@ -73,7 +69,6 @@ def expect_label(label, filter) end describe '#filter_label' do - def expect_label(label, filter) request_filter = described_class.new request_filter.update(filter: filter) @@ -115,7 +110,6 @@ def expect_label(label, filter) end describe '#order_options' do - it 'returns a list of sort order options in label, parameter form' do expected = [['Last updated', 'updated_at_desc'], ['First created', 'created_at_asc'], @@ -125,18 +119,15 @@ def expect_label(label, filter) end describe '#persisted?' do - it 'returns false' do expect(described_class.new.persisted?).to be false end - end describe '#results' do let(:user) { FactoryBot.create(:user) } context 'when no attributes are supplied' do - it 'sorts the requests by most recently updated' do first_request = FactoryBot.create(:info_request, user: user) second_request = FactoryBot.create(:info_request, user: user) @@ -184,7 +175,6 @@ def expect_label(label, filter) end context 'when the filter is "draft"' do - it 'returns draft requests' do draft_request = FactoryBot.create(:draft_info_request, user: user) diff --git a/spec/models/alaveteli_pro/request_summary_category_spec.rb b/spec/models/alaveteli_pro/request_summary_category_spec.rb index c2f53259fd..c28acfce0d 100644 --- a/spec/models/alaveteli_pro/request_summary_category_spec.rb +++ b/spec/models/alaveteli_pro/request_summary_category_spec.rb @@ -75,5 +75,4 @@ expect(described_class.embargo_expiring.slug).to eq "embargo_expiring" end end - end diff --git a/spec/models/alaveteli_pro/request_summary_spec.rb b/spec/models/alaveteli_pro/request_summary_spec.rb index 30da118b53..69e1c3aafc 100644 --- a/spec/models/alaveteli_pro/request_summary_spec.rb +++ b/spec/models/alaveteli_pro/request_summary_spec.rb @@ -209,7 +209,6 @@ end end - describe "setting categories" do context "when the request is a draft request" do let(:draft) { FactoryBot.create(:draft_info_request) } diff --git a/spec/models/alaveteli_pro/subscription_collection_spec.rb b/spec/models/alaveteli_pro/subscription_collection_spec.rb index 617fbbd87d..f79916dfc8 100644 --- a/spec/models/alaveteli_pro/subscription_collection_spec.rb +++ b/spec/models/alaveteli_pro/subscription_collection_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe AlaveteliPro::SubscriptionCollection do - let(:collection) { described_class.new(customer) } let(:customer) { double(:customer) } @@ -10,7 +9,6 @@ let(:incomplete_subscription) { double(:subscription, status: 'incomplete') } describe '.for_customer' do - it 'should return instance for customer' do collection = described_class.for_customer(customer) expect(collection).to be_a described_class @@ -20,19 +18,15 @@ expect(described_class).to receive(:new).with(customer) described_class.for_customer(customer) end - end describe '.new' do - it 'should store customer instance variable' do expect(collection.instance_variable_get(:@customer)).to eq customer end - end describe '#build' do - let(:collection) { described_class.new(customer) } let(:subscription) { collection.build } @@ -47,23 +41,18 @@ it 'should set customer object' do expect(subscription.customer).to eq customer end - end describe '#retrieve' do - context 'without customer' do - let(:customer) { nil } it 'returns nil' do expect(collection.retrieve(123)).to eq nil end - end context 'with Stripe subscriptions' do - let(:subscriptions) do Stripe::ListObject.new end @@ -79,13 +68,10 @@ expect(collection.retrieve(123)).to be_a AlaveteliPro::Subscription expect(collection.retrieve(123)).to eq subscription end - end - end describe '#current' do - before do allow(customer).to receive(:subscriptions).and_return( [active_subscription, past_due_subscription, incomplete_subscription] @@ -97,11 +83,9 @@ active_subscription, past_due_subscription ] end - end describe '#incomplete' do - before do allow(customer).to receive(:subscriptions).and_return( [active_subscription, past_due_subscription, incomplete_subscription] @@ -111,23 +95,18 @@ it 'should return any incomplete subscription' do expect(collection.incomplete).to match_array [incomplete_subscription] end - end describe '#each' do - context 'without customer' do - let(:customer) { nil } it 'returns no subscriptions' do expect(collection.count).to eq 0 end - end context 'with Stripe subscriptions' do - let(:subscriptions) do Stripe::ListObject.new end @@ -146,11 +125,9 @@ it 'wraps subscriptions as AlaveteliPro::Subscription objects' do expect(collection.to_a).to all(be_a AlaveteliPro::Subscription) end - end context 'without Stripe subscriptions' do - before do allow(customer).to receive(:subscriptions).and_return( [active_subscription, incomplete_subscription, active_subscription] @@ -164,17 +141,12 @@ it 'wraps subscriptions as AlaveteliPro::Subscription objects' do expect(collection.to_a).to all(be_a AlaveteliPro::Subscription) end - end context 'without block' do - it 'should return a Enumerator' do expect(collection.each).to be_a Enumerator end - end - end - end diff --git a/spec/models/alaveteli_pro/subscription_spec.rb b/spec/models/alaveteli_pro/subscription_spec.rb index c686503396..9df99e6287 100644 --- a/spec/models/alaveteli_pro/subscription_spec.rb +++ b/spec/models/alaveteli_pro/subscription_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' RSpec.describe AlaveteliPro::Subscription do - let(:object) { Stripe::Subscription.new } let(:subscription) { described_class.new(object) } describe '#active?' do - it 'should return true if status is active' do object.status = 'active' expect(subscription.active?).to eq true @@ -16,11 +14,9 @@ object.status = 'other' expect(subscription.active?).to eq false end - end describe '#incomplete?' do - it 'should return true if status is incomplete' do object.status = 'incomplete' expect(subscription.incomplete?).to eq true @@ -30,11 +26,9 @@ object.status = 'other' expect(subscription.incomplete?).to eq false end - end describe '#latest_invoice' do - subject { subscription.latest_invoice } it 'should retrieve and return a Stripe Invoice object' do @@ -44,25 +38,20 @@ and_return(mock_invoice) is_expected.to eq mock_invoice end - end describe '#invoice_open?' do - subject { subscription.invoice_open? } context 'when subscription complete' do - before do allow(subscription).to receive(:incomplete?).and_return(false) end it { is_expected.to eq false } - end context 'when subscription incomplete' do - before do allow(subscription).to receive(:incomplete?).and_return(true) end @@ -80,13 +69,10 @@ ) is_expected.to eq false end - end - end describe '#payment_intent' do - subject { subscription.payment_intent } before do @@ -94,7 +80,6 @@ end context 'with latest_invoice' do - let(:invoice) { double('Stripe::Invoice', payment_intent: 'pi_123') } it 'should retrieve and return a Stripe Payment Intent object' do @@ -103,24 +88,18 @@ and_return(mock_payment_intent) expect(subscription.payment_intent).to eq mock_payment_intent end - end context 'without latest_invoice' do - let(:invoice) { nil } it { is_expected.to eq nil } - end - end describe '#require_authorisation?' do - subject { subscription.require_authorisation? } context 'when invoice open' do - before do allow(subscription).to receive(:invoice_open?).and_return(true) end @@ -145,23 +124,18 @@ ) is_expected.to eq false end - end context 'when invoice closed' do - before do allow(subscription).to receive(:invoice_open?).and_return(false) end it { is_expected.to eq false } - end - end describe 'missing methods' do - it 'should delegate methods to object' do mock_coupon = double(:coupon) expect { subscription.coupon }.to raise_error(NoMethodError) @@ -169,7 +143,5 @@ expect(subscription.coupon).to eq mock_coupon expect(subscription.__getobj__.coupon).to eq mock_coupon end - end - end diff --git a/spec/models/alaveteli_pro/subscription_with_discount_spec.rb b/spec/models/alaveteli_pro/subscription_with_discount_spec.rb index 1014ac99d1..cad1525a53 100644 --- a/spec/models/alaveteli_pro/subscription_with_discount_spec.rb +++ b/spec/models/alaveteli_pro/subscription_with_discount_spec.rb @@ -15,7 +15,6 @@ subject { described_class.new(subscription) } describe '#amount' do - context 'no discount is set' do it 'returns the original stripe plan amount' do expect(subject.amount).to eq(833) @@ -50,11 +49,9 @@ expect(subject.amount).to eq(0) end end - end describe '#discounted?' do - context 'there is no discount' do it 'returns false' do expect(subject.discounted?).to be false @@ -89,11 +86,9 @@ expect(subject.discounted?).to be true end end - end describe '#discount_name' do - context 'no discount is set' do it { expect(subject.discount_name).to be_nil } end @@ -115,11 +110,9 @@ expect(subject.discount_name).to eq('PROBETA') end end - end describe '#free?' do - context 'the price is > 0' do let(:coupon) do double(:coupon, id: '50_off', amount_off: nil, @@ -159,7 +152,5 @@ expect(subject.free?).to be true end end - end - end diff --git a/spec/models/alaveteli_pro/to_do_list/expiring_embargo_spec.rb b/spec/models/alaveteli_pro/to_do_list/expiring_embargo_spec.rb index 8e85ecd316..3ad0aaad4a 100644 --- a/spec/models/alaveteli_pro/to_do_list/expiring_embargo_spec.rb +++ b/spec/models/alaveteli_pro/to_do_list/expiring_embargo_spec.rb @@ -12,7 +12,6 @@ end describe '#description' do - it 'gives a description for one expiring embargo' do expect(@expiring_embargo.description).to eq "1 request will be made public this week." end @@ -22,29 +21,22 @@ AlaveteliPro::RequestSummary.create_or_update_from(embargo2.info_request) expect(@expiring_embargo.description).to eq "2 requests will be made public this week." end - end describe '#items' do - it 'returns the expiring embargoes' do expect(@expiring_embargo.items).to eq [embargo] end - end describe '#url' do - context 'when there is one item' do - it 'returns a link to the embargoed request' do expect(@expiring_embargo.url).to eq show_request_path(embargo.info_request.url_title) end - end context 'when there is more than one item' do - it 'returns a link to the info request list with a "embargoed" filter' do embargo2 = FactoryBot.create(:expiring_embargo, user: user) AlaveteliPro::RequestSummary. @@ -53,23 +45,17 @@ .to eq alaveteli_pro_info_requests_path('alaveteli_pro_request_filter[filter]' => 'embargoes_expiring') end - end - end describe '#call_to_action' do - context 'when there is one item' do - it 'returns an appropriate text' do expect(@expiring_embargo.call_to_action).to eq 'Publish this request or keep it private for longer.' end - end context 'when there is more than one item' do - it 'returns an appropriate text' do embargo2 = FactoryBot.create(:expiring_embargo, user: user) AlaveteliPro::RequestSummary. @@ -77,9 +63,6 @@ expect(@expiring_embargo.call_to_action). to eq 'Publish these requests or keep them private for longer.' end - end - end - end diff --git a/spec/models/alaveteli_pro/to_do_list/item_spec.rb b/spec/models/alaveteli_pro/to_do_list/item_spec.rb index 6ef738f11c..d141f076d7 100644 --- a/spec/models/alaveteli_pro/to_do_list/item_spec.rb +++ b/spec/models/alaveteli_pro/to_do_list/item_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliPro::ToDoList::Item do - describe '.new' do - it 'requires a user' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -13,16 +11,12 @@ list = described_class.new(user) expect(list.user).to eq user end - end describe '#count' do - it 'returns a count of the number of items' do user = FactoryBot.create(:user) expect(described_class.new(user).count).to eq 0 end - end - end diff --git a/spec/models/alaveteli_pro/to_do_list/list_spec.rb b/spec/models/alaveteli_pro/to_do_list/list_spec.rb index e1f00b09da..7ee010833c 100644 --- a/spec/models/alaveteli_pro/to_do_list/list_spec.rb +++ b/spec/models/alaveteli_pro/to_do_list/list_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe AlaveteliPro::ToDoList::List do - describe '.new' do - it 'requires a user' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -13,22 +11,18 @@ list = described_class.new(user) expect(list.user).to eq user end - end describe '#items' do - it 'returns to do list items' do user = FactoryBot.create(:user) described_class.new(user).items.each do |item| expect(item).to be_kind_of AlaveteliPro::ToDoList::Item end end - end describe '#active_items' do - it 'returns items whose count is greater than zero' do user = FactoryBot.create(:user) new_response = double('new_response', count: 1) @@ -44,7 +38,5 @@ expect(described_class.new(user).active_items) .to eq([new_response, overdue_request]) end - end - end diff --git a/spec/models/alaveteli_pro/to_do_list/new_response_spec.rb b/spec/models/alaveteli_pro/to_do_list/new_response_spec.rb index 3e440a281f..d82c131a1f 100644 --- a/spec/models/alaveteli_pro/to_do_list/new_response_spec.rb +++ b/spec/models/alaveteli_pro/to_do_list/new_response_spec.rb @@ -12,7 +12,6 @@ end describe '#description' do - it 'gives a description for one response' do expect(@new_response.description). to eq "1 request has received a response." @@ -24,29 +23,22 @@ expect(@new_response.description). to eq "2 requests have received a response." end - end describe '#items' do - it 'returns the requests that have received a response' do expect(@new_response.items).to eq [info_request] end - end describe '#url' do - context 'when there is one item' do - it 'returns a link to the request' do expect(@new_response.url).to eq show_request_path(info_request.url_title) end - end context 'when there is more than one item' do - it 'returns a link to the info request list with a "response_received" filter' do request = FactoryBot.create(:old_unclassified_request, user: user) AlaveteliPro::RequestSummary.create_or_update_from(request) @@ -54,31 +46,22 @@ .to eq alaveteli_pro_info_requests_path('alaveteli_pro_request_filter[filter]' => 'response_received') end - end - end describe '#call_to_action' do - context 'when there is one item' do - it 'returns an appropriate text' do expect(@new_response.call_to_action).to eq 'Update its status.' end - end context 'when there is more than one item' do - it 'returns an appropriate text' do request = FactoryBot.create(:old_unclassified_request, user: user) AlaveteliPro::RequestSummary.create_or_update_from(request) expect(@new_response.call_to_action).to eq 'Update statuses.' end - end - end - end diff --git a/spec/models/alaveteli_pro/to_do_list/overdue_request_spec.rb b/spec/models/alaveteli_pro/to_do_list/overdue_request_spec.rb index e4a8711d1c..bd2cc347ea 100644 --- a/spec/models/alaveteli_pro/to_do_list/overdue_request_spec.rb +++ b/spec/models/alaveteli_pro/to_do_list/overdue_request_spec.rb @@ -13,7 +13,6 @@ end describe '#description' do - it 'gives a description for one response' do travel_to(Time.zone.parse('2015-12-01')) do AlaveteliPro::RequestSummary.create_or_update_from(info_request) @@ -31,33 +30,26 @@ expect(@overdue_request.description).to eq "2 requests are delayed." end end - end describe '#items' do - it 'returns the requests that are overdue' do travel_to(Time.zone.parse('2015-12-01')) do expect(@overdue_request.items).to eq [info_request] end end - end describe '#url' do - context 'when there is one item' do - it 'returns a link to the request' do travel_to(Time.zone.parse('2015-12-01')) do expect(@overdue_request.url).to eq show_request_path(info_request.url_title) end end - end context 'when there is more than one item' do - it 'returns a link to the info request list with a "overdue" filter' do request = travel_to(Time.zone.parse('2015-11-01')) do FactoryBot.create(:info_request, user: user) @@ -70,15 +62,11 @@ 'overdue') end end - end - end describe '#call_to_action' do - context 'when there is one item' do - it 'returns an appropriate text' do travel_to(Time.zone.parse('2015-12-01')) do AlaveteliPro::RequestSummary.create_or_update_from(info_request) @@ -86,13 +74,10 @@ .to eq 'Send a follow up (or request an internal review).' end end - end context 'when there is more than one item' do - it 'returns an appropriate text' do - travel_to(Time.zone.parse('2015-11-01')) do FactoryBot.create(:info_request, user: user) end @@ -101,9 +86,6 @@ .to eq 'Send follow ups (or request internal reviews).' end end - end - end - end diff --git a/spec/models/alaveteli_pro/to_do_list/very_overdue_request_spec.rb b/spec/models/alaveteli_pro/to_do_list/very_overdue_request_spec.rb index 374be5288e..9fb05e310d 100644 --- a/spec/models/alaveteli_pro/to_do_list/very_overdue_request_spec.rb +++ b/spec/models/alaveteli_pro/to_do_list/very_overdue_request_spec.rb @@ -13,7 +13,6 @@ end describe '#description' do - it 'gives a description for one response' do travel_to(Time.zone.parse('2016-01-01')) do expect(@very_overdue_request.description).to eq "1 request is long overdue." @@ -29,33 +28,26 @@ expect(@very_overdue_request.description).to eq "2 requests are long overdue." end end - end describe '#items' do - it 'returns the requests that are very overdue' do travel_to(Time.zone.parse('2016-01-01')) do expect(@very_overdue_request.items).to eq [info_request] end end - end describe '#url' do - context 'when there is one item' do - it 'returns a link to the request' do travel_to(Time.zone.parse('2016-01-01')) do expect(@very_overdue_request.url).to eq show_request_path(info_request.url_title) end end - end context 'when there is more than one item' do - it 'returns a link to the info request list with a "very_overdue" filter' do request = travel_to(Time.zone.parse('2015-11-01')) do FactoryBot.create(:info_request, user: user) @@ -68,28 +60,21 @@ 'very_overdue') end end - end - end describe '#call_to_action' do - context 'when there is one item' do - it 'returns an appropriate text' do travel_to(Time.zone.parse('2016-01-01')) do expect(@very_overdue_request.call_to_action) .to eq 'Request an internal review (or send another followup).' end end - end context 'when there is more than one item' do - it 'returns an appropriate text' do - request = travel_to(Time.zone.parse('2015-11-01')) do FactoryBot.create(:info_request, user: user) end @@ -99,9 +84,6 @@ .to eq 'Request internal reviews (or send other followups).' end end - end - end - end diff --git a/spec/models/alaveteli_pro/with_tax_spec.rb b/spec/models/alaveteli_pro/with_tax_spec.rb index 2d09cc5233..5c0aba59ff 100644 --- a/spec/models/alaveteli_pro/with_tax_spec.rb +++ b/spec/models/alaveteli_pro/with_tax_spec.rb @@ -5,7 +5,6 @@ subject { described_class.new(plan) } describe '#amount_with_tax' do - context 'with the default tax rate' do it 'adds 20% tax to the plan amount' do expect(subject.amount_with_tax).to eq(1000) @@ -27,5 +26,4 @@ it 'delegates to the stripe plan' do expect(subject.amount).to eq(833) end - end diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb index db0fed29cd..7d7d923079 100644 --- a/spec/models/censor_rule_spec.rb +++ b/spec/models/censor_rule_spec.rb @@ -19,9 +19,7 @@ require 'spec_helper' RSpec.describe CensorRule do - describe '#apply_to_text' do - it 'applies the rule to the text' do rule = FactoryBot.build(:censor_rule, text: 'secret') text = 'Some secret text' @@ -60,11 +58,9 @@ --REMOVED EOF end - end describe '#apply_to_binary' do - it 'applies the rule to the text' do rule = FactoryBot.build(:censor_rule, text: 'secret') text = 'Some secret text' @@ -155,7 +151,6 @@ xxxxxxxxxxxx EOF end - end describe '#expire_requests' do @@ -190,7 +185,6 @@ with(InfoRequest, :all) rule.expire_requests end - end describe '#censorable_requests' do @@ -252,7 +246,6 @@ end RSpec.describe 'when validating rules' do - it 'must have the text to redact' do censor_rule = CensorRule.new censor_rule.valid? @@ -279,7 +272,6 @@ end describe 'when validating a regexp rule' do - before do @censor_rule = CensorRule.new(regexp: true, text: '*', @@ -294,13 +286,11 @@ end describe 'if a regexp error is produced' do - it 'should add an error message to the text field with the regexp error message' do allow(Regexp).to receive(:new).and_raise(RegexpError.new("very bad regexp")) expect(@censor_rule.valid?).to eq(false) expect(@censor_rule.errors[:text]).to eq(["very bad regexp"]) end - end describe 'if a regexp contains unescaped characters' do @@ -318,23 +308,17 @@ end describe 'if no regexp error is produced' do - it 'should not add any error message to the text field' do allow(Regexp).to receive(:new) @censor_rule.valid? expect(@censor_rule.errors[:text]).to eq([]) end - end - end - end RSpec.describe 'when handling global rules' do - describe 'an instance without user_id, request_id or public_body_id' do - before do @global_rule = CensorRule.new end @@ -342,11 +326,9 @@ it 'should return a value of true from is_global?' do expect(@global_rule.is_global?).to eq(true) end - end describe '.global' do - before do @global_rule = CensorRule.create!(text: 'hide me', replacement: 'nothing to see here', @@ -372,5 +354,4 @@ @user_rule.destroy if @user_rule end end - end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 22ae7a8b96..ca1ef892fe 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -17,7 +17,6 @@ require 'spec_helper' RSpec.describe Comment do - include Rails.application.routes.url_helpers include LinkToHelper @@ -42,11 +41,9 @@ expect(comment.visible).to eq(true) expect(@hidden_request.comments.visible).to eq([]) end - end describe '.embargoed' do - before(:each) do @info_request = FactoryBot.create(:info_request) @request_comment = FactoryBot.create(:comment, @@ -63,11 +60,9 @@ it "doesn't include comments on requests without embargoes" do expect(Comment.embargoed.include?(@request_comment)).to be false end - end describe '.not_embargoed' do - before(:each) do @info_request = FactoryBot.create(:info_request) @request_comment = FactoryBot.create(:comment, @@ -84,7 +79,6 @@ it "includes comments on requests without embargoes" do expect(Comment.not_embargoed.include?(@request_comment)).to be true end - end # rubocop:disable Layout/FirstArrayElementIndentation @@ -212,7 +206,6 @@ end describe '#hidden?' do - it 'returns true if the comment is not visible' do comment = Comment.new(visible: false) expect(comment.hidden?).to eq(true) @@ -222,11 +215,9 @@ comment = Comment.new(visible: true) expect(comment.hidden?).to eq(false) end - end describe '#destroy' do - it 'destroys the associated info_request_events' do comment = FactoryBot.create(:comment) events = comment.info_request_events @@ -234,21 +225,17 @@ events.select { |event| event.reload && event.persisted? } expect(events).to be_empty end - end describe '#report_reasons' do - let(:comment) { FactoryBot.build(:comment) } it 'returns an array of strings' do expect(comment.report_reasons).to all(be_a(String)) end - end describe '#report!' do - let(:comment) { FactoryBot.create(:comment) } let(:user) { FactoryBot.create(:user) } @@ -294,11 +281,9 @@ expect(most_recent_event.params). to include(message: "Comment is bad, please hide") end - end describe '#last_report' do - let(:comment) { FactoryBot.create(:comment) } let(:user) { FactoryBot.create(:user) } @@ -320,11 +305,9 @@ expect(comment.info_request_events.last.event_type).to eq("edit_comment") expect(comment.last_report.event_type).to eq("report_comment") end - end describe '#last_reported_at' do - let(:comment) { FactoryBot.create(:comment) } let(:user) { FactoryBot.create(:user) } @@ -338,7 +321,6 @@ expect(comment.reload.last_reported_at). to be_within(3.seconds).of(expected) end - end describe '#hide' do @@ -363,5 +345,4 @@ expect(event.params[:visible]).to eq(false) end end - end diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb index da8bb2e8c3..218ad684c0 100644 --- a/spec/models/customstates.rb +++ b/spec/models/customstates.rb @@ -1,5 +1,4 @@ module InfoRequestCustomStates - def self.included(base) base.extend(ClassMethods) end @@ -7,19 +6,23 @@ def self.included(base) # Mixin methods for InfoRequest def theme_calculate_status return 'waiting_classification' if awaiting_description + waiting_response = described_state == "waiting_response" || described_state == "deadline_extended" return described_state unless waiting_response + if described_state == 'deadline_extended' return 'deadline_extended' if Time.zone.now.strftime("%Y-%m-%d") < date_deadline_extended.strftime("%Y-%m-%d") return 'waiting_response_very_overdue' if Time.zone.now.strftime("%Y-%m-%d") > Holiday.due_date_from_working_days(date_deadline_extended, 15).strftime("%Y-%m-%d") + return 'waiting_response_overdue' end return 'waiting_response_very_overdue' if Time.zone.now.strftime("%Y-%m-%d") > date_very_overdue_after.strftime("%Y-%m-%d") return 'waiting_response_overdue' if Time.zone.now.strftime("%Y-%m-%d") > date_response_required_by.strftime("%Y-%m-%d") + 'waiting_response' end @@ -58,7 +61,6 @@ def theme_extra_states end module RequestControllerCustomStates - def theme_describe_state(info_request) # called after the core describe_state code. It should # end by raising an error if the status is unknown @@ -72,5 +74,4 @@ def theme_describe_state(info_request) raise "unknown calculate_status " + info_request.calculate_status end end - end diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb index 8d9ce5f0cb..f1de59d5d0 100644 --- a/spec/models/foi_attachment_spec.rb +++ b/spec/models/foi_attachment_spec.rb @@ -54,7 +54,6 @@ end describe '#body=' do - it "sets the body" do attachment = FoiAttachment.new attachment.body = "baz" @@ -108,11 +107,9 @@ ActiveStorage::Blob.services.fetch(blob.service_name).exist?(blob.key) }.from(false).to(true) end - end describe '#body' do - context 'when masked' do let(:foi_attachment) { FactoryBot.create(:body_text) } @@ -183,11 +180,9 @@ ) end end - end describe '#body_as_text' do - it 'has a valid UTF-8 string when newly created' do foi_attachment = FactoryBot.create(:body_text) expect(foi_attachment.body_as_text.string.encoding.to_s).to eq('UTF-8') @@ -201,7 +196,6 @@ expect(foi_attachment.body_as_text.string.valid_encoding?).to be true end - it 'has a true scrubbed? value if the body has been coerced to valid UTF-8' do foi_attachment = FactoryBot.create(:body_text) foi_attachment.body = "\x0FX\x1C\x8F\xA4\xCF\xF6\x8C\x9D\xA7\x06\xD9\xF7\x90lo" @@ -213,11 +207,9 @@ foi_attachment.body = "κόσμε" expect(foi_attachment.body_as_text.scrubbed?).to be false end - end describe '#default_body' do - it 'returns valid UTF-8 for a text attachment' do foi_attachment = FactoryBot.create(:body_text) expect(foi_attachment.default_body.encoding.to_s).to eq('UTF-8') @@ -228,11 +220,9 @@ foi_attachment = FactoryBot.create(:pdf_attachment) expect(foi_attachment.default_body.encoding.to_s).to eq('ASCII-8BIT') end - end describe '#unmasked_body' do - let(:foi_attachment) { FactoryBot.create(:body_text) } subject(:unmasked_body) { foi_attachment.unmasked_body } @@ -289,11 +279,9 @@ ) end end - end describe 'masked?' do - let(:foi_attachment) do FoiAttachment.new(body: 'foo', masked_at: Time.zone.now) end @@ -319,7 +307,6 @@ it { is_expected.to eq(false) } end - end describe '#main_body_part?' do @@ -347,18 +334,15 @@ end describe '#ensure_filename!' do - it 'should create a filename for an instance with a blank filename' do attachment = FoiAttachment.new attachment.filename = '' attachment.ensure_filename! expect(attachment.filename).to eq('attachment.bin') end - end describe '#has_body_as_html?' do - it 'should be true for a pdf attachment' do expect(FactoryBot.build(:pdf_attachment).has_body_as_html?).to be true end @@ -366,7 +350,6 @@ it 'should be false for an html attachment' do expect(FactoryBot.build(:html_attachment).has_body_as_html?).to be false end - end describe '#name_of_content_type' do diff --git a/spec/models/has_tag_string_tag_spec.rb b/spec/models/has_tag_string_tag_spec.rb index 1b0d433e64..60dd633e5e 100644 --- a/spec/models/has_tag_string_tag_spec.rb +++ b/spec/models/has_tag_string_tag_spec.rb @@ -19,7 +19,6 @@ end RSpec.describe HasTagString::HasTagStringTag, 'taggable model' do - class ModelWithTag < ApplicationRecord has_tag_string after_initialize { self.name ||= 'test' } @@ -64,7 +63,6 @@ def self.up t.string :name t.timestamps null: false end - end def self.down @@ -153,7 +151,6 @@ def self.down expect(subject).to match([model_3, model_1, model_2]) end end - end describe '#add_tag_if_not_already_present' do @@ -179,7 +176,6 @@ def self.down end RSpec.describe HasTagString::HasTagStringTag, " when fiddling with tag strings" do - it "should be able to make a new tag and save it" do @tag = HasTagString::HasTagStringTag.new @tag.model_type = 'PublicBody' @@ -187,5 +183,4 @@ def self.down @tag.name = "moo" @tag.save! end - end diff --git a/spec/models/holiday_import_spec.rb b/spec/models/holiday_import_spec.rb index 6416cd3ef2..4f1421f96a 100644 --- a/spec/models/holiday_import_spec.rb +++ b/spec/models/holiday_import_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe HolidayImport do - it 'validates the presence of a feed if the source is a feed' do holiday_import = HolidayImport.new(source: 'feed') expect(holiday_import.valid?).to be false @@ -87,7 +86,6 @@ end describe 'when populating a set of holidays to import from suggestions' do - it 'should populate holidays from the suggestions' do holidays = [ { date: Date.new(2014, 1, 1), name: "New Year's Day", @@ -119,11 +117,9 @@ expect(@holiday_import.populated).to eq(true) end - end describe 'when populating a set of holidays to import from a feed' do - before do @holiday_import = HolidayImport.new(source: 'feed', ical_feed_url: 'http://www.example.com', @@ -153,11 +149,9 @@ expected = ["Sorry we couldn't find that feed."] expect(@holiday_import.errors[:ical_feed_url]).to eq(expected) end - end describe '#save' do - it 'saves all holidays' do holiday = Holiday.new holiday_import = HolidayImport.new @@ -165,11 +159,9 @@ expect(holiday).to receive(:save) holiday_import.save end - end describe '#save!' do - it 'saves all holidays' do holiday = Holiday.new holiday_import = HolidayImport.new @@ -177,7 +169,5 @@ expect(holiday).to receive(:save!) holiday_import.save! end - end - end diff --git a/spec/models/holiday_spec.rb b/spec/models/holiday_spec.rb index 2fc77d65a3..5e84926f3d 100644 --- a/spec/models/holiday_spec.rb +++ b/spec/models/holiday_spec.rb @@ -13,9 +13,7 @@ require 'spec_helper' RSpec.describe Holiday do - describe '.new' do - it 'should require a day' do holiday = Holiday.new expect(holiday.valid?).to be false @@ -24,7 +22,6 @@ end describe " when calculating due date" do - def due_date(ymd) Holiday.due_date_from_working_days(Date.strptime(ymd), 20).strftime("%F") end diff --git a/spec/models/incoming_message_error_spec.rb b/spec/models/incoming_message_error_spec.rb index fcfbbcec19..cd54bfbd8b 100644 --- a/spec/models/incoming_message_error_spec.rb +++ b/spec/models/incoming_message_error_spec.rb @@ -14,13 +14,10 @@ require 'spec_helper' RSpec.describe IncomingMessageError do - describe '.new' do - it 'requres a unique ID' do expect(IncomingMessageError.new).not_to be_valid expect(IncomingMessageError.new(unique_id: 'xxx')).to be_valid end end - end diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 3db732cc62..a2f217bc08 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -69,7 +69,6 @@ end describe '#from_name' do - it 'returns the name in the From: field of an email' do raw_email_data = <<-EOF.strip_heredoc From: FOI Person @@ -113,11 +112,9 @@ expect(message.from_name). to eq('Coordenação de Relacionamento, Pesquisa e Informação/CEDI') end - end describe '#safe_from_name' do - it 'applies the info request censor rules to from_name' do raw_email_data = <<-EOF.strip_heredoc From: FOI Person @@ -136,11 +133,9 @@ expect(message.safe_from_name).to eq('FOI [REDACTED]') end - end describe '#from_email' do - it 'returns the email address in the From header' do raw_email_data = <<-EOF.strip_heredoc From: FOI Person @@ -167,11 +162,9 @@ message.parse_raw_email!(true) expect(message.from_email).to eq('') end - end describe '#from_email_domain' do - it 'returns the domain part of the email address in the From header' do raw_email_data = <<-EOF.strip_heredoc From: FOI Person @@ -198,11 +191,9 @@ message.parse_raw_email!(true) expect(message.from_email_domain).to eq('') end - end describe '#subject' do - it 'returns the Subject: field of an email' do raw_email_data = <<-EOF.strip_heredoc From: FOI Person @@ -243,11 +234,9 @@ message.parse_raw_email!(true) expect(message.subject).to eq('Câmara Responde: Banco de ideias') end - end describe '#sent_at' do - it 'uses the Date header if the mail has one' do raw_email_data = <<-EOF.strip_heredoc From: FOI Person @@ -277,7 +266,6 @@ message.parse_raw_email!(true) expect(message.sent_at).to eq(message.created_at) end - end describe '#specific_from_name?' do @@ -323,7 +311,6 @@ end describe '#apply_masks' do - before(:each) do @im = incoming_messages(:useless_incoming_message) @@ -400,7 +387,6 @@ result = @im.apply_masks(data, 'application/vnd.ms-word') expect(result).to eq(expected) end - end describe '#get_body_for_indexing' do @@ -428,18 +414,15 @@ end describe '#get_body_for_quoting' do - it 'does not incorrectly cache without the FOLDED_QUOTED_SECTION marker' do message = FactoryBot.create(:plain_incoming_message) message.get_body_for_quoting expect(message.get_main_body_text_folded). to include('FOLDED_QUOTED_SECTION') end - end describe '#get_attachment_text_full' do - it 'strips null bytes from the extracted clipped text' do message = FactoryBot.create(:incoming_message) FactoryBot. @@ -447,11 +430,9 @@ message.reload expect(message.get_attachment_text_clipped).to eq("hi\n\n") end - end describe '#_extract_text' do - it 'does not generate incompatible character encodings' do message = FactoryBot.create(:incoming_message) FactoryBot.create(:body_text, @@ -467,7 +448,6 @@ expect { message._extract_text }. to_not raise_error end - end describe '#legislation' do @@ -567,7 +547,6 @@ expect(request.last_public_response_at).to be_within(1.second). of(response_event.created_at) end - end RSpec.describe 'when destroying a message' do @@ -631,7 +610,6 @@ end RSpec.describe IncomingMessage, " when dealing with incoming mail" do - before(:each) do @im = incoming_messages(:useless_incoming_message) load_raw_emails_data @@ -742,7 +720,6 @@ incoming_message.get_body_for_html_display end - it 'should handle a main body part that is just quoted content in an email that has no subject' do i = IncomingMessage.new @@ -751,12 +728,9 @@ allow(i).to receive(:subject).and_return(nil) i.get_body_for_html_display end - - end RSpec.describe IncomingMessage, " display attachments" do - it "should not show slashes in filenames" do foi_attachment = FoiAttachment.new # http://www.whatdotheyknow.com/request/post_commercial_manager_librarie#incoming-17233 @@ -774,11 +748,9 @@ expected_display_filename = foi_attachment.within_rfc822_subject.gsub(/\//, " ") + ".txt" expect(foi_attachment.display_filename).to eq(expected_display_filename) end - end RSpec.describe IncomingMessage, " folding quoted parts of emails" do - it 'should fold an example lotus notes quoted part converted from HTML correctly' do ir = info_requests(:fancy_dog_request) receive_incoming_mail('lotus-notes-quoting.email', @@ -827,7 +799,6 @@ # check that the quoted section incorporates both quoted messages expect(body_text).not_to match('Subject: RE: Freedom of Information request') end - end RSpec.describe IncomingMessage, " when uudecoding bad messages" do @@ -911,7 +882,6 @@ def populate_raw_email(fixture) 'bah.txt' ]) end - end RSpec.describe IncomingMessage, "when messages are attached to messages" do @@ -970,7 +940,6 @@ def populate_raw_email(fixture) expect(attachments[0].body).to match('Date: Fri, 23 May 2008') end end - end RSpec.describe IncomingMessage, "when Outlook messages are attached to messages" do @@ -1032,11 +1001,9 @@ def populate_raw_email(fixture) expect { im.get_main_body_text_folded }.not_to raise_error expect { im.cached_attachment_text_clipped }.not_to raise_error end - end RSpec.describe IncomingMessage, "when extracting attachments" do - before do load_raw_emails_data end @@ -1056,7 +1023,6 @@ def populate_raw_email(fixture) new_attachment_attributes = attachment_attributes.merge(body: "No way!", hexdigest: "74d2c0a41e074f9cebe49324d5b47414") - # Simulate parsing with the original attachments allow(MailHandler).to receive(:get_attachment_attributes).and_return([attachment_attributes]) incoming_message = incoming_messages(:useless_incoming_message) @@ -1155,11 +1121,9 @@ def populate_raw_email(fixture) expected = "

Line 1

\n\n

Line 2

" expect(incoming_message.get_body_for_html_display).to include(expected) end - end RSpec.describe IncomingMessage, 'when getting clipped attachment text' do - it 'should clip to characters not bytes' do incoming_message = FactoryBot.build(:incoming_message) # This character is 2 bytes so the string should get sliced unless @@ -1168,13 +1132,10 @@ def populate_raw_email(fixture) allow(incoming_message).to receive(:_get_attachment_text_internal).and_return(multibyte_string) expect(incoming_message.get_attachment_text_clipped.length).to eq(500_002) end - end RSpec.describe IncomingMessage, 'when getting the main body text' do - context 'when the main body text is more than 1MB' do - before do @incoming_message = FactoryBot.create(:incoming_message) allow(@incoming_message).to receive(:get_main_body_text_internal). @@ -1189,11 +1150,9 @@ def populate_raw_email(fixture) expect { @incoming_message.get_main_body_text_unfolded }. to raise_error(RuntimeError, expected_text) end - end context 'when main body attachment goes missing' do - let(:incoming_message) { FactoryBot.create(:incoming_message) } before do @@ -1220,7 +1179,5 @@ def populate_raw_email(fixture) 'hereisthetext' ) end - end - end diff --git a/spec/models/info_request/pro_query_spec.rb b/spec/models/info_request/pro_query_spec.rb index d26998a8f6..3055c588c6 100644 --- a/spec/models/info_request/pro_query_spec.rb +++ b/spec/models/info_request/pro_query_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::ProQuery do - describe '#call' do - it 'includes requests made by pro users' do pro_user = FactoryBot.create(:pro_user) info_request = FactoryBot.create(:info_request, user: pro_user) @@ -20,6 +18,5 @@ expect(described_class.new.call.include?(external_request)) .to be false end - end end diff --git a/spec/models/info_request/prominence/been_published_query_spec.rb b/spec/models/info_request/prominence/been_published_query_spec.rb index ea6845ccef..2f7b1a2fe5 100644 --- a/spec/models/info_request/prominence/been_published_query_spec.rb +++ b/spec/models/info_request/prominence/been_published_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::BeenPublishedQuery do - describe '#call' do subject { described_class.new.call } @@ -14,6 +13,5 @@ is_expected.to include re_embargoed_request is_expected.to_not include embargoed_request end - end end diff --git a/spec/models/info_request/prominence/calculator_spec.rb b/spec/models/info_request/prominence/calculator_spec.rb index 20f6283847..7ff53e1e1c 100644 --- a/spec/models/info_request/prominence/calculator_spec.rb +++ b/spec/models/info_request/prominence/calculator_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::Calculator do - let(:info_request) { FactoryBot.build(:info_request) } let(:embargoed_request) { FactoryBot.create(:embargoed_request) } @@ -16,7 +15,6 @@ def expect_embargoed_value(prominence, method, value) end describe '#is_public?' do - it 'returns true if its prominence is normal' do expect_value('normal', :is_public?, true) end @@ -34,7 +32,6 @@ def expect_embargoed_value(prominence, method, value) end context 'when there is an embargo' do - it 'returns false if its prominence is normal' do expect_embargoed_value('normal', :is_public?, false) end @@ -50,13 +47,10 @@ def expect_embargoed_value(prominence, method, value) it 'returns false if its prominence is requester_only' do expect_embargoed_value('requester_only', :is_public?, false) end - end - end describe '#is_searchable?' do - it 'returns true if its prominence is normal' do expect_value('normal', :is_searchable?, true) end @@ -74,7 +68,6 @@ def expect_embargoed_value(prominence, method, value) end context 'when there is an embargo' do - it 'returns false if its prominence is normal' do expect_embargoed_value('normal', :is_searchable?, false) end @@ -90,13 +83,10 @@ def expect_embargoed_value(prominence, method, value) it 'returns false if its prominence is requester_only' do expect_embargoed_value('requester_only', :is_searchable?, false) end - end - end describe '#is_private?' do - it 'returns false if its prominence is normal' do expect_value('normal', :is_private?, false) end @@ -113,9 +103,7 @@ def expect_embargoed_value(prominence, method, value) expect_value('requester_only', :is_private?, true) end - context 'when there is an embargo' do - it 'returns true if its prominence is normal' do expect_embargoed_value('normal', :is_private?, true) end @@ -131,13 +119,10 @@ def expect_embargoed_value(prominence, method, value) it 'returns true if its prominence is requester_only' do expect_embargoed_value('requester_only', :is_private?, true) end - end - end describe '#is_requester_only?' do - it 'returns false if its prominence is normal' do expect_value('normal', :is_requester_only?, false) end @@ -153,11 +138,9 @@ def expect_embargoed_value(prominence, method, value) it 'returns true if its prominence is requester_only' do expect_value('requester_only', :is_requester_only?, true) end - end describe '#is_hidden?' do - it 'returns false if its prominence is normal' do expect_value('normal', :is_hidden?, false) end @@ -173,15 +156,11 @@ def expect_embargoed_value(prominence, method, value) it 'returns false if its prominence is requester_only' do expect_value('requester_only', :is_hidden?, false) end - end describe '#to_s' do - it 'returns the prominence of the request' do expect_value('normal', :to_s, 'normal') end - end - end diff --git a/spec/models/info_request/prominence/embargo_expired_today_query_spec.rb b/spec/models/info_request/prominence/embargo_expired_today_query_spec.rb index 7fca8db55a..d733e77062 100644 --- a/spec/models/info_request/prominence/embargo_expired_today_query_spec.rb +++ b/spec/models/info_request/prominence/embargo_expired_today_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper.rb' RSpec.describe InfoRequest::Prominence::EmbargoExpiredTodayQuery do - describe '#call' do let(:info_request) { info_request = FactoryBot.create(:info_request) } @@ -33,7 +32,5 @@ expect(described_class.new.call).to include info_request end - end - end diff --git a/spec/models/info_request/prominence/embargo_expiring_query_spec.rb b/spec/models/info_request/prominence/embargo_expiring_query_spec.rb index d0df8d6a89..207e13ff92 100644 --- a/spec/models/info_request/prominence/embargo_expiring_query_spec.rb +++ b/spec/models/info_request/prominence/embargo_expiring_query_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper.rb' RSpec.describe InfoRequest::Prominence::EmbargoExpiringQuery do - describe '#call' do - it 'includes requests that have embargoes expiring within a week' do embargo = FactoryBot.create(:embargo, publish_at: Time.now + 4.days) @@ -20,6 +18,5 @@ info_request = FactoryBot.create(:info_request) expect(described_class.new.call).not_to include info_request end - end end diff --git a/spec/models/info_request/prominence/embargoed_query_spec.rb b/spec/models/info_request/prominence/embargoed_query_spec.rb index c11d564818..c4df92fb83 100644 --- a/spec/models/info_request/prominence/embargoed_query_spec.rb +++ b/spec/models/info_request/prominence/embargoed_query_spec.rb @@ -1,14 +1,11 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::EmbargoedQuery do - describe '#call' do - it 'limits the requests to those that have embargoes' do info_request = FactoryBot.create(:info_request) embargoed_request = FactoryBot.create(:embargoed_request) expect(described_class.new.call).to eq([embargoed_request]) end - end end diff --git a/spec/models/info_request/prominence/not_embargoed_query_spec.rb b/spec/models/info_request/prominence/not_embargoed_query_spec.rb index cc5f4155a0..0c2ceacf77 100644 --- a/spec/models/info_request/prominence/not_embargoed_query_spec.rb +++ b/spec/models/info_request/prominence/not_embargoed_query_spec.rb @@ -1,13 +1,10 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::NotEmbargoedQuery do - describe '#call' do - it 'limits the requests to those that do not have embargoes' do embargoed_request = FactoryBot.create(:embargoed_request) expect(described_class.new.call).not_to include(embargoed_request) end - end end diff --git a/spec/models/info_request/prominence/public_query_spec.rb b/spec/models/info_request/prominence/public_query_spec.rb index 24ef44582e..16a3ade655 100644 --- a/spec/models/info_request/prominence/public_query_spec.rb +++ b/spec/models/info_request/prominence/public_query_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::PublicQuery do - describe '#call' do - it 'returns only results with a normal or backpaged prominence' do normal_request = FactoryBot.create(:info_request) backpaged_request = FactoryBot.create(:info_request, prominence: 'backpage') @@ -19,5 +17,4 @@ expect(described_class.new.call).not_to include(embargoed_request) end end - end diff --git a/spec/models/info_request/prominence/searchable_query_spec.rb b/spec/models/info_request/prominence/searchable_query_spec.rb index 7c03c0c721..b0e9d85722 100644 --- a/spec/models/info_request/prominence/searchable_query_spec.rb +++ b/spec/models/info_request/prominence/searchable_query_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::SearchableQuery do - describe '#call' do - it 'returns only results with a normal prominence' do normal_request = FactoryBot.create(:info_request) hidden_request = FactoryBot.create(:info_request, prominence: 'hidden') @@ -16,5 +14,4 @@ expect(described_class.new.call).not_to include(embargoed_request) end end - end diff --git a/spec/models/info_request/prominence/visible_to_requester_query_spec.rb b/spec/models/info_request/prominence/visible_to_requester_query_spec.rb index f79cfb47e4..1d1dc050d9 100644 --- a/spec/models/info_request/prominence/visible_to_requester_query_spec.rb +++ b/spec/models/info_request/prominence/visible_to_requester_query_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::Prominence::VisibleToRequesterQuery do - describe '#call' do - it 'returns results with normal, backpaged or requester_only prominence' do normal_request = FactoryBot.create(:info_request) backpaged_request = @@ -22,7 +20,5 @@ embargoed_request = FactoryBot.create(:embargoed_request) expect(described_class.new.call).to include(embargoed_request) end - end - end diff --git a/spec/models/info_request/response_gatekeeper/authority_only_spec.rb b/spec/models/info_request/response_gatekeeper/authority_only_spec.rb index c2d0f068f7..f96021e740 100644 --- a/spec/models/info_request/response_gatekeeper/authority_only_spec.rb +++ b/spec/models/info_request/response_gatekeeper/authority_only_spec.rb @@ -1,22 +1,18 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseGatekeeper::AuthorityOnly do - it 'inherits from Base' do expect(described_class.superclass). to eq(InfoRequest::ResponseGatekeeper::Base) end - describe '#allow?' do - it 'requires an email' do gatekeeper = described_class.new(FactoryBot.build(:info_request)) expect { gatekeeper.allow? }.to raise_error(ArgumentError) end context 'if the email has no From address' do - it 'does not allow the email' do raw = <<-EOF.strip_heredoc To: request-123@example.com @@ -42,11 +38,9 @@ gatekeeper.allow?(email) expect(gatekeeper.reason).to eq(reason) end - end context 'if the email is not from the authority' do - it 'does not allow the email' do raw = <<-EOF.strip_heredoc From: spam@example.org @@ -74,11 +68,9 @@ gatekeeper.allow?(email) expect(gatekeeper.reason).to eq(reason) end - end context 'if the email is from the authority' do - it 'allows the email' do raw = <<-EOF.strip_heredoc From: authority@example.com @@ -105,11 +97,9 @@ expect(gatekeeper.reason).to be_nil end - end context 'if the request already has a reply from a given domain' do - it 'allows the email' do raw = <<-EOF.strip_heredoc From: someone@example.org @@ -126,7 +116,6 @@ expect(gatekeeper.allow?(email)).to eq(true) end - it 'sets the reason to nil' do raw = <<-EOF.strip_heredoc From: someone@example.org @@ -142,9 +131,6 @@ expect(gatekeeper.reason).to be_nil end - end - end - end diff --git a/spec/models/info_request/response_gatekeeper/base_spec.rb b/spec/models/info_request/response_gatekeeper/base_spec.rb index f443067b47..2b6a9f3296 100644 --- a/spec/models/info_request/response_gatekeeper/base_spec.rb +++ b/spec/models/info_request/response_gatekeeper/base_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseGatekeeper::Base do - describe '.new' do - it 'requires an info_request' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -25,21 +23,17 @@ gatekeeper = described_class.new(info_request) expect(gatekeeper.reason).to be_nil end - end describe '#info_request' do - it 'returns the info_request' do info_request = FactoryBot.build(:info_request) gatekeeper = described_class.new(info_request) expect(gatekeeper.info_request).to eq(info_request) end - end describe '#allow?' do - it 'requires an email' do gatekeeper = described_class.new(FactoryBot.build(:info_request)) expect { gatekeeper.allow? }.to raise_error(ArgumentError) @@ -50,18 +44,14 @@ gatekeeper = described_class.new(FactoryBot.build(:info_request)) expect(gatekeeper.allow?(email)).to eq(true) end - end describe '#rejection_action' do - it 'delegates to the info_request' do info_request = FactoryBot. build(:info_request, handle_rejected_responses: 'holding_pen') gatekeeper = described_class.new(info_request) expect(gatekeeper.rejection_action).to eq('holding_pen') end - end - end diff --git a/spec/models/info_request/response_gatekeeper/nobody_spec.rb b/spec/models/info_request/response_gatekeeper/nobody_spec.rb index 6cf2380416..fc4b8ddaad 100644 --- a/spec/models/info_request/response_gatekeeper/nobody_spec.rb +++ b/spec/models/info_request/response_gatekeeper/nobody_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseGatekeeper::Nobody do - it 'inherits from Base' do expect(described_class.superclass). to eq(InfoRequest::ResponseGatekeeper::Base) end describe '.new' do - it 'requires an info_request' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -32,7 +30,5 @@ gatekeeper = described_class.new(info_request) expect(gatekeeper.reason).to eq(reason) end - end - end diff --git a/spec/models/info_request/response_gatekeeper/spam_checker_spec.rb b/spec/models/info_request/response_gatekeeper/spam_checker_spec.rb index dd35def57d..2fe73dff80 100644 --- a/spec/models/info_request/response_gatekeeper/spam_checker_spec.rb +++ b/spec/models/info_request/response_gatekeeper/spam_checker_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseGatekeeper::SpamChecker do - describe '.new' do - it 'sets a default spam_action' do default = AlaveteliConfiguration.incoming_email_spam_action expect(described_class.new.spam_action).to eq(default) @@ -31,45 +29,35 @@ expect(described_class.new(spam_threshold: 'x').spam_threshold). to eq('x') end - end describe '#spam_action' do - it 'returns the spam_action' do expect(described_class.new(spam_action: 'x').spam_action).to eq('x') end - end describe '#rejection_action' do - it 'is an alias for #spam_action' do gatekeeper = described_class.new expect(gatekeeper.rejection_action).to eq(gatekeeper.spam_action) end - end describe '#spam_header' do - it 'returns the spam_header' do expect(described_class.new(spam_header: 'x').spam_header).to eq('x') end - end describe '#spam_threshold' do - it 'returns the spam_threshold' do expect(described_class.new(spam_threshold: 'x').spam_threshold). to eq('x') end - end describe '#allow?' do - it 'allows a mail if the spam checker is not configured' do spam_email = <<-EOF.strip_heredoc From: spam@example.org @@ -119,18 +107,15 @@ end describe '#reason' do - it 'returns the reason that the email was rejected' do gatekeeper = described_class.new(spam_threshold: 10.0) message = 'Incoming message has a spam score above the configured ' \ 'threshold (10.0).' expect(gatekeeper.reason).to eq(message) end - end describe '#spam?' do - it 'is spam if the email has a spam score above the spam threshold' do spam_email = <<-EOF.strip_heredoc From: spammer@example.org @@ -174,11 +159,9 @@ gatekeeper = described_class.new(attrs) expect(gatekeeper.spam?(email)).to eq(false) end - end describe '#spam_score' do - it 'returns the spam score of an email' do spam_email = <<-EOF.strip_heredoc From: spammer@example.org @@ -203,11 +186,9 @@ gatekeeper = described_class.new expect(gatekeeper.spam_score(email)).to eq(0.0) end - end describe '#configured?' do - it 'requires a spam_action to be configured' do gatekeeper = described_class.new(spam_action: nil) expect(gatekeeper).to_not be_configured @@ -229,7 +210,5 @@ spam_threshold: 10.0 } expect(described_class.new(attrs)).to be_configured end - end - end diff --git a/spec/models/info_request/response_gatekeeper_spec.rb b/spec/models/info_request/response_gatekeeper_spec.rb index 19f1c3370f..29553ac402 100644 --- a/spec/models/info_request/response_gatekeeper_spec.rb +++ b/spec/models/info_request/response_gatekeeper_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseGatekeeper do - describe '.for' do - it 'returns a new ResponseGatekeeper for known gatekeepers' do const = 'InfoRequest::ResponseGatekeeper::SPECIALIZED_CLASSES' specialized_classes = { 'known' => described_class::Base, @@ -24,7 +22,5 @@ expect { described_class.for('unknown', double('info_request')) }. to raise_error(err) end - end - end diff --git a/spec/models/info_request/response_rejection/base_spec.rb b/spec/models/info_request/response_rejection/base_spec.rb index b98f517daa..f55a3f222e 100644 --- a/spec/models/info_request/response_rejection/base_spec.rb +++ b/spec/models/info_request/response_rejection/base_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseRejection::Base do - describe '.new' do - it 'requires an info_request' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -40,11 +38,9 @@ rejection = described_class.new(*args) expect(rejection.raw_email_data).to eq(raw_email_data) end - end describe '#reject' do - it 'returns true' do args = [double('info_request'), double('email'), double('raw_email_data')] rejection = described_class.new(*args) @@ -56,7 +52,5 @@ rejection = described_class.new(*args) expect(rejection.reject('')).to eq(true) end - end - end diff --git a/spec/models/info_request/response_rejection/bounce_spec.rb b/spec/models/info_request/response_rejection/bounce_spec.rb index a682f9e705..836d69ab02 100644 --- a/spec/models/info_request/response_rejection/bounce_spec.rb +++ b/spec/models/info_request/response_rejection/bounce_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseRejection::Bounce do - it 'inherits from Base' do expect(described_class.superclass). to eq(InfoRequest::ResponseRejection::Base) end describe '#reject' do - it 'does nothing and returns true if the mail has no From address' do raw_email = <<-EOF.strip_heredoc To: Requester @@ -87,7 +85,5 @@ ActionMailer::Base.deliveries.clear end - end - end diff --git a/spec/models/info_request/response_rejection/holding_pen_spec.rb b/spec/models/info_request/response_rejection/holding_pen_spec.rb index 8098ac125e..83a690bbfc 100644 --- a/spec/models/info_request/response_rejection/holding_pen_spec.rb +++ b/spec/models/info_request/response_rejection/holding_pen_spec.rb @@ -1,23 +1,19 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseRejection::HoldingPen do - it 'inherits from Base' do expect(described_class.superclass). to eq(InfoRequest::ResponseRejection::Base) end describe '.new' do - it 'finds and sets the holding_pen' do rejection = described_class.new(double, double, double) expect(rejection.holding_pen).to be_holding_pen_request end - end describe '.reject' do - it 'returns false if the info_request is the holding_pen' do holding_pen = InfoRequest.holding_pen_request rejection = described_class.new(holding_pen, double, double) @@ -39,7 +35,5 @@ expect(InfoRequest.holding_pen_request.incoming_messages.count).to eq(1) end - end - end diff --git a/spec/models/info_request/response_rejection_spec.rb b/spec/models/info_request/response_rejection_spec.rb index 3a395fdf6d..4ea92ed35a 100644 --- a/spec/models/info_request/response_rejection_spec.rb +++ b/spec/models/info_request/response_rejection_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::ResponseRejection do - describe '.for' do - it 'returns a new ResponseRejection for known rejections' do const = 'InfoRequest::ResponseRejection::SPECIALIZED_CLASSES' specialized_classes = { 'known' => described_class::Base, @@ -26,7 +24,5 @@ expect { described_class.for('unknown', *args) }. to raise_error(err) end - end - end diff --git a/spec/models/info_request/state/awaiting_response_query_spec.rb b/spec/models/info_request/state/awaiting_response_query_spec.rb index a3549c18fc..79756d2a98 100644 --- a/spec/models/info_request/state/awaiting_response_query_spec.rb +++ b/spec/models/info_request/state/awaiting_response_query_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe InfoRequest::State::AwaitingResponseQuery do - describe '#call' do - it 'includes those that are waiting for a response, and not waiting for description' do info_request = FactoryBot.create(:info_request) @@ -15,6 +13,5 @@ expect(described_class.new.call.include?(old_unclassified_request)) .to be false end - end end diff --git a/spec/models/info_request/state/calculator_spec.rb b/spec/models/info_request/state/calculator_spec.rb index 4a43fe6ad1..dc8cd013da 100644 --- a/spec/models/info_request/state/calculator_spec.rb +++ b/spec/models/info_request/state/calculator_spec.rb @@ -43,7 +43,6 @@ info_request.save! expect(calculator.phase).to eq(:response_received) end - end describe '#transitions' do diff --git a/spec/models/info_request/state/clarification_needed_query_spec.rb b/spec/models/info_request/state/clarification_needed_query_spec.rb index 8ae6d2c885..312c7ce086 100644 --- a/spec/models/info_request/state/clarification_needed_query_spec.rb +++ b/spec/models/info_request/state/clarification_needed_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::State::ClarificationNeededQuery do - describe '#call' do let(:info_request) { FactoryBot.create(:waiting_clarification_info_request) } @@ -16,6 +15,5 @@ expect(described_class.new.call.include?(info_request)) .to be false end - end end diff --git a/spec/models/info_request/state/complete_query_spec.rb b/spec/models/info_request/state/complete_query_spec.rb index 181f0b6db2..0eabe64b69 100644 --- a/spec/models/info_request/state/complete_query_spec.rb +++ b/spec/models/info_request/state/complete_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::State::CompleteQuery do - describe '#call' do let(:info_request) { FactoryBot.create(:successful_request) } @@ -16,6 +15,5 @@ expect(described_class.new.call.include?(info_request)) .to be false end - end end diff --git a/spec/models/info_request/state/other_query_spec.rb b/spec/models/info_request/state/other_query_spec.rb index a13ee05ebb..60dd031026 100644 --- a/spec/models/info_request/state/other_query_spec.rb +++ b/spec/models/info_request/state/other_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::State::OtherQuery do - describe '#call' do let(:info_request) { FactoryBot.create(:info_request_with_internal_review_request) } @@ -16,6 +15,5 @@ expect(described_class.new.call.include?(info_request)) .to be false end - end end diff --git a/spec/models/info_request/state/overdue_query_spec.rb b/spec/models/info_request/state/overdue_query_spec.rb index 136bde23c7..a7a87c87ca 100644 --- a/spec/models/info_request/state/overdue_query_spec.rb +++ b/spec/models/info_request/state/overdue_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::State::OverdueQuery do - describe '#call' do let(:info_request) { FactoryBot.create(:info_request) } @@ -37,6 +36,5 @@ .to be false end end - end end diff --git a/spec/models/info_request/state/response_received_query_spec.rb b/spec/models/info_request/state/response_received_query_spec.rb index 7db1d7307c..e95a448453 100644 --- a/spec/models/info_request/state/response_received_query_spec.rb +++ b/spec/models/info_request/state/response_received_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::State::ResponseReceivedQuery do - describe '#call' do let(:info_request) { FactoryBot.create(:info_request) } @@ -15,6 +14,5 @@ expect(described_class.new.call.include?(info_request)) .to be false end - end end diff --git a/spec/models/info_request/state/very_overdue_query_spec.rb b/spec/models/info_request/state/very_overdue_query_spec.rb index 2451a8723a..72803ac04c 100644 --- a/spec/models/info_request/state/very_overdue_query_spec.rb +++ b/spec/models/info_request/state/very_overdue_query_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe InfoRequest::State::VeryOverdueQuery do - describe '#call' do let(:info_request) { FactoryBot.create(:info_request) } @@ -37,6 +36,5 @@ .to be false end end - end end diff --git a/spec/models/info_request/state_spec.rb b/spec/models/info_request/state_spec.rb index 8e330c0556..068b7f3cfd 100644 --- a/spec/models/info_request/state_spec.rb +++ b/spec/models/info_request/state_spec.rb @@ -1,14 +1,11 @@ require 'spec_helper' RSpec.describe InfoRequest::State do - describe :all do - it 'includes "waiting_response"' do expect(InfoRequest::State.all.include?("waiting_response")) .to be true end - end describe '.unhappy' do @@ -36,7 +33,6 @@ end describe :phases do - it 'returns an array' do expect(InfoRequest::State.phases).to be_a Array end @@ -45,11 +41,9 @@ expect(InfoRequest::State.phases.include?({ name: _('Complete'), scope: :complete })) end - end describe :short_description do - it 'returns a short description for a valid state' do expect(InfoRequest::State.short_description('attention_requested')) .to eq 'Reported' @@ -61,7 +55,6 @@ end context 'when a theme is in use' do - before do InfoRequest.send(:require, 'models/customstates') InfoRequest.send(:include, InfoRequestCustomStates) @@ -77,13 +70,10 @@ expect { InfoRequest::State.short_description('meow') } .to raise_error 'unknown status meow' end - end - end describe :phase_params do - it 'returns hyphenised versions of the phases' do expect(InfoRequest::State.phase_params) .to eq({ awaiting_response: "awaiting-response", @@ -95,5 +85,4 @@ other: "other" }) end end - end diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index ba53794930..4572a83659 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -148,7 +148,6 @@ ) ).to be_nil end - end context '#existing_batch' do @@ -300,7 +299,6 @@ end end end - end context "when sending batches" do @@ -476,7 +474,6 @@ expect(example.embargo).to be_nil end end - end it_behaves_like "RequestSummaries" @@ -708,7 +705,6 @@ before { allow(batch).to receive(:requestable_public_bodies) { [body] } } it { is_expected.to eq false } end - end describe '#should_summarise?' do @@ -733,7 +729,6 @@ before { allow(batch).to receive(:all_requests_created?) { true } } it { is_expected.to eq true } end - end describe "#log_event" do @@ -756,7 +751,6 @@ end end - describe '#is_owning_user?' do subject { info_request_batch.is_owning_user?(user) } diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 6142a15434..44b58f6a53 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -205,7 +205,6 @@ end context "the incoming_message is not hidden" do - it "updates the parent info_request's last_public_response_at value" do im = FactoryBot.create(:incoming_message) response_event = FactoryBot. @@ -215,22 +214,18 @@ expect(request.last_public_response_at).to be_within(1.second). of response_event.created_at end - end context "the event is not a response" do - it "does not update the info_request's last_public_response_at value" do expect_any_instance_of(InfoRequestEvent).not_to receive(:update_request) event = FactoryBot.create(:info_request_event, event_type: 'comment', info_request: request) expect(request.last_public_response_at).to be_nil end - end context "the incoming_message is hidden" do - it "sets the parent info_request's last_public_response_at to nil" do im = FactoryBot.create(:incoming_message, prominence: 'hidden') response_event = FactoryBot. @@ -239,21 +234,17 @@ incoming_message: im) expect(request.last_public_response_at).to be_nil end - end context "the event is for a comment" do - it "enqueues NotifyCacheJob job for the comment" do event = FactoryBot.build(:comment_event) expect(NotifyCacheJob).to receive(:perform_later).with(event.comment) event.save end - end context "the event is for an foi_attachment" do - it "enqueues NotifyCacheJob job for the attachment" do attachment = mock_model(FoiAttachment) allow(FoiAttachment).to receive(:find).and_return(attachment) @@ -261,18 +252,15 @@ expect(NotifyCacheJob).to receive(:perform_later).with(attachment) event.save end - end context "the event is for a request" do - it "enqueues NotifyCacheJob job for the request" do event = FactoryBot.build(:info_request_event) expect(NotifyCacheJob).to receive(:perform_later). with(event.info_request) event.save end - end it "calls the request's create_or_update_request_summary on create" do @@ -281,7 +269,6 @@ expect(event.info_request).to receive(:create_or_update_request_summary) event.save! end - end describe "should know" do @@ -437,7 +424,6 @@ expect(TrackThingsSentEmail.where(info_request_event_id: event.id)). to be_empty end - end describe "editing requests" do @@ -491,7 +477,6 @@ end describe '#resets_due_dates?' do - it 'returns true if the event is a sending of the request' do info_request_event = FactoryBot.create(:sent_event) expect(info_request_event.resets_due_dates?).to be true @@ -521,9 +506,7 @@ end end - describe '#is_request_sending?' do - it 'returns true if the event type is "sent"' do info_request_event = FactoryBot.create(:sent_event) expect(info_request_event.is_request_sending?).to be true @@ -550,9 +533,7 @@ end end - describe '#is_clarification?' do - it 'should return false if there has been no request for clarification' do info_request = FactoryBot.create(:info_request_with_incoming) event = info_request.log_event('followup_sent', {}) @@ -596,7 +577,6 @@ end describe '#recheck_due_dates' do - context 'if the event is a response that is then labelled as a clarification request' do let(:response_event) do @@ -624,11 +604,9 @@ expect(info_request.reload.date_initial_request_last_sent_at). to eq(Time.zone.now.to_date) end - end context 'if there is no subsequent followup' do - it 'does not reset the due dates on the request' do info_request = response_event.info_request expect(info_request.reload.date_initial_request_last_sent_at). @@ -637,11 +615,8 @@ expect(info_request.reload.date_initial_request_last_sent_at). to eq(1.month.ago.to_date) end - end - end - end # Testing a private callback helper @@ -748,7 +723,6 @@ end end - # INDEXING HELPERS # # Technically don't need to test because these are private, but we want to @@ -819,7 +793,6 @@ end end - describe '#requested_from' do it "should return an array of translated public body url_name values" do ire = FactoryBot.create(:info_request_event) @@ -924,5 +897,4 @@ expect(event.foi_attachment).to eq(attachment) end end - end diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 711dc22586..c1001ea408 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -146,7 +146,6 @@ end describe '#law_used' do - it 'defaults law used to foi' do expect(InfoRequest.new.law_used).to eq('foi') end @@ -156,7 +155,6 @@ end context 'with public body' do - let(:foi) { FactoryBot.build(:public_body) } let(:eir) { FactoryBot.build(:public_body, :eir_only) } @@ -174,13 +172,10 @@ expect { request.valid? }.to_not change(request, :law_used). from('eir') end - end - end describe 'creating a new request' do - it "sets the url_title from the supplied title" do info_request = FactoryBot.create(:info_request, title: "Test title") expect(info_request.url_title).to eq("test_title") @@ -224,13 +219,10 @@ first_request.save! expect(first_request.url_title).to eq("test_title_2") end - end - end describe '.find_by_incoming_email' do - let(:info_request) { FactoryBot.create(:info_request) } it "recognises its own incoming email" do @@ -278,11 +270,9 @@ InfoRequest.find_by_incoming_email(deleted_request_address) expect(found_info_request).to be_nil end - end describe '.matching_incoming_email' do - it 'only finds the supplied requests' do 2.times { FactoryBot.create(:info_request) } @@ -321,22 +311,17 @@ it 'is empty when passed nil' do expect(described_class.matching_incoming_email(nil)).to be_empty end - end describe '.holding_pen_request' do - context 'when the holding pen exists' do - it 'finds a request with title "Holding pen"' do holding_pen = FactoryBot.create(:info_request, title: 'Holding pen') expect(InfoRequest.holding_pen_request).to eq(holding_pen) end - end context 'when no holding pen exists' do - before do InfoRequest.where(title: 'Holding pen').destroy_all @holding_pen = InfoRequest.holding_pen_request @@ -366,13 +351,10 @@ expect(@holding_pen.outgoing_messages.first.body). to eq(expected_message) end - end - end describe '.reject_incoming_at_mta' do - before do @request = FactoryBot.create(:info_request) @request.update(updated_at: 6.months.ago, @@ -412,7 +394,6 @@ end end - describe '.stop_new_responses_on_old_requests' do subject { described_class.stop_new_responses_on_old_requests } let(:request) { FactoryBot.create(:info_request) } @@ -473,7 +454,6 @@ allow_new_responses_from: 'nobody', editor: 'InfoRequest.stop_new_responses_on_old_requests') end - end describe '#reopen_to_new_responses' do @@ -501,11 +481,9 @@ to change { info_request.reload.updated_at.to_date }. from(8.months.ago.to_date).to(Time.zone.now.to_date) end - end describe '#receive' do - it 'creates a new incoming message' do info_request = FactoryBot.create(:info_request) email, raw_email = email_and_raw_email @@ -562,7 +540,6 @@ end describe 'notifying the request owner' do - context 'when the request has use_notifications: true' do let(:info_request) do FactoryBot.create(:info_request, use_notifications: true) @@ -608,7 +585,6 @@ not_to change { Notification.count } end end - end describe 'receiving mail from different sources' do @@ -622,7 +598,6 @@ end context 'when accepting mail from any source is enabled' do - it 'processes mail where no source is specified' do with_feature_enabled(:accept_mail_from_anywhere) do email, raw_email = email_and_raw_email @@ -649,14 +624,11 @@ expect(info_request.incoming_messages.last).to be_persisted end end - end context 'when accepting mail from any source is not enabled' do - context 'when accepting mail from the poller is enabled for the request user' do - before do AlaveteliFeatures. backend[:accept_mail_from_poller]. @@ -678,12 +650,10 @@ info_request.receive(email, raw_email, source: :mailin) expect(info_request.incoming_messages.count).to eq(0) end - end context 'when accepting mail from the poller is not enabled for the request user' do - it 'ignores mail from the poller' do email, raw_email = email_and_raw_email info_request.receive(email, raw_email, source: :poller) @@ -696,13 +666,11 @@ expect(info_request.incoming_messages.count).to eq(1) expect(info_request.incoming_messages.last).to be_persisted end - end end end context 'allowing new responses' do - it 'from nobody' do travel_to(5.days.ago) @@ -844,11 +812,9 @@ override_stop_new_responses: true) expect(info_request.incoming_messages.count).to eq(1) end - end context 'handling rejected responses' do - it 'bounces rejected responses if the mail has a from address' do attrs = { allow_new_responses_from: 'nobody', handle_rejected_responses: 'bounce' } @@ -911,7 +877,6 @@ expect { info_request.receive(email, raw_email) }. to raise_error(err) end - end it "uses instance-specific spam handling first" do @@ -1055,7 +1020,6 @@ end context 'when email has already been received' do - let(:info_request) { FactoryBot.create(:info_request) } before do @@ -1068,9 +1032,7 @@ info_request.incoming_messages.count } end - end - end describe "#url_title" do @@ -1086,9 +1048,7 @@ end describe '#move_to_public_body' do - context 'with no options' do - it 'requires an :editor option' do request = FactoryBot.create(:info_request) new_body = FactoryBot.create(:public_body) @@ -1096,11 +1056,9 @@ request.move_to_public_body(new_body) }.to raise_error IndexError end - end context 'with the :editor option' do - it 'moves the info request to the new public body' do request = FactoryBot.create(:info_request) new_body = FactoryBot.create(:public_body) @@ -1187,7 +1145,6 @@ end context 'updating counter caches' do - let(:request) { FactoryBot.create(:info_request) } let(:old_body) { request.public_body } let(:new_body) { FactoryBot.create(:public_body) } @@ -1256,17 +1213,12 @@ to change { old_body.reload.info_requests_visible_classified_count }. from(1).to(0) end - end - end - end describe '#move_to_user' do - context 'with no options' do - it 'requires an :editor option' do request = FactoryBot.create(:info_request) new_user = FactoryBot.create(:user) @@ -1274,11 +1226,9 @@ request.move_to_user(new_user) }.to raise_error IndexError end - end context 'with the :editor option' do - it 'moves the info request to the new user' do request = FactoryBot.create(:info_request) new_user = FactoryBot.create(:user) @@ -1356,7 +1306,6 @@ end context 'updating counter caches' do - it "increments the new user's info_requests_count " do request = FactoryBot.create(:info_request) new_user = FactoryBot.create(:user) @@ -1375,15 +1324,11 @@ expect { request.move_to_user(new_user, editor: editor) }. to change { old_user.reload.info_requests_count }.from(1).to(0) end - end - end - end describe '#destroy' do - let(:info_request) { FactoryBot.create(:info_request) } it "calls update_counter_cache" do @@ -1464,7 +1409,6 @@ end describe '#expire' do - let(:info_request) { FactoryBot.create(:info_request) } it "clears the attachment masked" do @@ -1502,11 +1446,9 @@ expect(FileUtils).to receive(:rm_rf).exactly(expected_calls).times info_request.expire end - end describe '#clear_attachment_masks!' do - let(:info_request) { FactoryBot.create(:info_request_with_plain_incoming) } let(:attachment) { info_request.foi_attachments.first } @@ -1518,11 +1460,9 @@ attachment.masked_at }.from(Time).to(nil) end - end describe '#initial_request_text' do - it 'returns an empty string if the first outgoing message is hidden' do info_request = FactoryBot.create(:info_request) first_message = info_request.outgoing_messages.first @@ -1535,11 +1475,9 @@ info_request = FactoryBot.create(:info_request) expect(info_request.initial_request_text).to eq('Some information please') end - end describe '.find_existing' do - it 'returns a request with the params given' do info_request = FactoryBot.create(:info_request) expect(InfoRequest.find_existing(info_request.title, @@ -1571,17 +1509,14 @@ "Some information please")). to eq(info_request) end - end describe '#find_existing_outgoing_message' do - it 'returns an outgoing message with the body text given' do info_request = FactoryBot.create(:info_request) expect(info_request.find_existing_outgoing_message('Some information please')). to eq(info_request.outgoing_messages.first) end - end describe '#already_received?' do @@ -1649,7 +1584,6 @@ end describe '#is_external?' do - it 'returns true if there is an external url' do info_request = InfoRequest.new(external_url: "demo_url") expect(info_request.is_external?).to eq(true) @@ -1659,7 +1593,6 @@ info_request = InfoRequest.new(external_url: nil) expect(info_request.is_external?).to eq(false) end - end describe '#user_name' do @@ -1766,7 +1699,6 @@ end describe '#late_calculator' do - it 'returns a DefaultLateCalculator' do expect(subject.late_calculator). to be_instance_of(DefaultLateCalculator) @@ -1775,17 +1707,14 @@ it 'caches the late calculator' do expect(subject.late_calculator).to equal(subject.late_calculator) end - end describe "#is_followupable?" do - let(:message_without_reply_to) { FactoryBot.create(:incoming_message) } let(:valid_request) { FactoryBot.create(:info_request) } let(:unfollowupable_body) { FactoryBot.create(:public_body, request_email: "") } context "it is possible to reply to the public body" do - it "returns true" do expect(valid_request.is_followupable?(message_without_reply_to)). to eq(true) @@ -1795,12 +1724,9 @@ valid_request.is_followupable?(message_without_reply_to) expect(valid_request.followup_bad_reason).to be_nil end - end - context "the message has a valid reply address" do - let(:request) do FactoryBot.create(:info_request, public_body: unfollowupable_body) end @@ -1818,11 +1744,9 @@ request.is_followupable?(dummy_message) expect(request.followup_bad_reason).to be_nil end - end context "an external request" do - let(:info_request) { InfoRequest.new(external_url: "demo_url") } it "returns false" do @@ -1834,11 +1758,9 @@ info_request.is_followupable?(message_without_reply_to) expect(info_request.followup_bad_reason).to eq("external") end - end context "belongs to an unfollowupable PublicBody" do - let(:request) do FactoryBot.create(:info_request, public_body: unfollowupable_body) end @@ -1852,9 +1774,7 @@ expect(request.followup_bad_reason). to eq(unfollowupable_body.not_requestable_reason) end - end - end describe '#report!' do @@ -1894,11 +1814,9 @@ attention_requested: true ) end - end describe '#legislation' do - let(:legislation) { Legislation.new(key: 'abc') } context 'with valid law_used' do @@ -1928,7 +1846,6 @@ end context 'without law_used, with public body present' do - let(:public_body) { FactoryBot.build(:public_body) } let(:info_request) do FactoryBot.build(:info_request, law_used: nil, public_body: public_body) @@ -1938,11 +1855,9 @@ allow(public_body).to receive(:legislation).and_return(legislation) expect(info_request.legislation).to eq legislation end - end context 'without law_used or public body present' do - let(:info_request) do FactoryBot.build(:info_request, law_used: nil, public_body: nil) end @@ -1951,9 +1866,7 @@ allow(Legislation).to receive(:default).and_return(legislation) expect(info_request.legislation).to eq legislation end - end - end describe 'when validating' do @@ -1971,7 +1884,6 @@ end describe 'when generating a user name slug' do - let(:public_body) do FactoryBot.build(:public_body, url_name: 'example_body') end @@ -1985,7 +1897,6 @@ it 'should generate a slug for an example user name' do expect(info_request.user_name_slug).to eq('example_body_example_user') end - end describe '.guess_by_incoming_email' do @@ -2300,7 +2211,6 @@ end context 'a reply with a subject that matches a previous incoming_message subject' do - before do FactoryBot.create(:incoming_message, subject: subject_line, info_request: info_request) @@ -2357,11 +2267,9 @@ it { is_expected.to match_array([guess_1, guess_2]) } end - end describe "making up the URL title" do - before do @info_request = InfoRequest.new end @@ -2375,11 +2283,9 @@ @info_request.title = '1234' expect(@info_request.url_title).to eq('request') end - end describe '#title=' do - let(:test_requests) do 3.times.map { FactoryBot.create(:info_request, title: 'URL test') } end @@ -2397,7 +2303,6 @@ request.update(title: request.title.dup) expect(request.url_title).to eq('url_test_2') end - end describe '#last_event_id_needing_description' do @@ -2419,7 +2324,6 @@ let(:info_request) { FactoryBot.create(:info_request) } it { is_expected.to eq 0 } end - end describe '#last_event' do @@ -2432,7 +2336,6 @@ end context 'when the request has events' do - before do 3.times do FactoryBot.create(:info_request_event, info_request: info_request) @@ -2442,11 +2345,9 @@ it 'returns the most recent event' do expect(info_request.reload.last_event).to eq(last_event) end - end context 'when the request has no events' do - before do info_request.info_request_events.destroy_all end @@ -2454,13 +2355,10 @@ it 'returns nil' do expect(info_request.reload.last_event).to be_nil end - end - end describe 'when managing the cache directories' do - before do @info_request = info_requests(:fancy_dog_request) end @@ -2474,11 +2372,9 @@ other_locale_path = File.join(Rails.root, 'cache', 'views', 'es', 'request', '101', '101') expect(@info_request.foi_fragment_cache_directories.include?(other_locale_path)).to eq(true) end - end describe "when emailing" do - before do @info_request = info_requests(:fancy_dog_request) end @@ -2504,26 +2400,21 @@ info_request_events(:useless_incoming_message_event).destroy update_xapian_index end - end describe "#postal_email" do - let(:public_body) do FactoryBot.create(:public_body, request_email: "test@localhost") end context "there is no list of incoming messages to followup" do - it "returns the public body's request_email" do request = FactoryBot.create(:info_request, public_body: public_body) expect(request.postal_email).to eq("test@localhost") end - end context "there is a list of incoming messages to followup" do - it "returns the email address from the last message in the chain" do request = FactoryBot.create(:info_request, public_body: public_body) incoming_message = FactoryBot.create(:plain_incoming_message, @@ -2534,26 +2425,20 @@ ) expect(request.postal_email).to eq("bob@example.com") end - end - end describe "#postal_email_name" do - let(:public_body) { FactoryBot.create(:public_body, name: "Ministry of Test") } context "there is no list of incoming messages to followup" do - it "returns the public body name" do request = FactoryBot.create(:info_request, public_body: public_body) expect(request.postal_email_name).to eq("Ministry of Test") end - end context "there is a list of incoming messages to followup" do - it "returns the email name from the last message in the chain" do request = FactoryBot.create(:info_request, public_body: public_body) incoming_message = FactoryBot.create(:plain_incoming_message, @@ -2564,13 +2449,10 @@ ) expect(request.postal_email_name).to eq("Bob Responder") end - end - end describe "when calculating the status" do - before do travel_to Time.utc(2007, 10, 14, 23, 59) do @info_request = FactoryBot.create(:info_request) @@ -2622,7 +2504,6 @@ end context 'when in a timezone offset from UTC' do - before do @default_zone = Time.zone zone = ActiveSupport::TimeZone["Australia/Sydney"] @@ -2680,11 +2561,9 @@ end end end - end describe "when using a plugin and calculating the status" do - before do InfoRequest.send(:require, 'models/customstates') InfoRequest.send(:include, InfoRequestCustomStates) @@ -2713,11 +2592,9 @@ allow(Time).to receive(:now).and_return(when_overdue) expect(@ir.calculate_status).to eq('waiting_response_overdue') end - end describe 'when asked if a user is the owning user for this request' do - before do @mock_user = mock_model(User) @info_request = InfoRequest.new(user: @mock_user) @@ -2741,11 +2618,9 @@ allow(@other_mock_user).to receive(:owns_every_request?).and_return(true) expect(@info_request.is_owning_user?(@other_mock_user)).to be true end - end describe 'when asked if it requires admin' do - before do @info_request = InfoRequest.new end @@ -2764,11 +2639,9 @@ @info_request.described_state = 'waiting_response' expect(@info_request.requires_admin?).to be false end - end describe 'when asked for old unclassified requests' do - context "returning records" do let(:recent_date) { Time.zone.now - 20.days } let(:old_date) { Time.zone.now - 22.days } @@ -2845,7 +2718,6 @@ def create_old_unclassified_holding_pen request end - it "returns records over 21 days old" do old_unclassified_request = create_old_unclassified_request results = InfoRequest.where_old_unclassified @@ -2876,11 +2748,9 @@ def create_old_unclassified_holding_pen expect(results).not_to include(old_unclassified_holding_pen) end end - end describe 'when asked for random old unclassified requests with normal prominence' do - it "does not return requests that don't have normal prominence" do dog_request = info_requests(:fancy_dog_request) old_unclassified = @@ -2901,11 +2771,9 @@ def create_old_unclassified_holding_pen where(prominence: 'normal').limit(1).order(Arel.sql('random()')) expect(old_unclassified.length).to eq(0) end - end describe 'when asked to count old unclassified requests with normal prominence' do - it "does not return requests that don't have normal prominence" do dog_request = info_requests(:fancy_dog_request) old_unclassified = InfoRequest.where_old_unclassified. @@ -2922,11 +2790,9 @@ def create_old_unclassified_holding_pen where(prominence: 'normal').count expect(old_unclassified).to eq(0) end - end describe 'when an instance is asked if it is old and unclassified' do - before do allow(Time).to receive(:now).and_return(Time.utc(2007, 11, 9, 23, 59)) @info_request = FactoryBot.create(:info_request, @@ -2965,11 +2831,9 @@ def create_old_unclassified_holding_pen it 'returns true if it is awaiting description, isn\'t the holding pen and hasn\'t had an event in 21 days' do expect(@info_request.is_external? || @info_request.is_old_unclassified?).to be true end - end describe '#apply_censor_rules_to_text' do - it 'applies each censor rule to the text' do rule_1 = FactoryBot.build(:censor_rule, text: '1') rule_2 = FactoryBot.build(:censor_rule, text: '2') @@ -2981,11 +2845,9 @@ def create_old_unclassified_holding_pen expect(info_request.apply_censor_rules_to_text('1 3 2')).to eq(expected) end - end describe '#apply_censor_rules_to_binary' do - it 'applies each censor rule to the text' do rule_1 = FactoryBot.build(:censor_rule, text: '1') rule_2 = FactoryBot.build(:censor_rule, text: '2') @@ -2998,11 +2860,9 @@ def create_old_unclassified_holding_pen expect(info_request.apply_censor_rules_to_binary(text)).to eq('x 3 x') end - end describe '#apply_masks' do - before(:each) do @request = FactoryBot.create(:info_request) @@ -3077,11 +2937,9 @@ def create_old_unclassified_holding_pen result = @request.apply_masks(data, 'application/vnd.ms-word') expect(result).to eq(expected) end - end describe '#prominence' do - let(:info_request) { FactoryBot.build(:info_request) } it 'returns the prominence of the request' do @@ -3089,18 +2947,14 @@ def create_old_unclassified_holding_pen end context ':decorate option is true' do - it 'returns a prominence calculator' do expect(InfoRequest.new.prominence(decorate: true)) .to be_a(InfoRequest::Prominence::Calculator) end - end - end describe 'when asked for the last public response event' do - before do @info_request = FactoryBot.create(:info_request_with_incoming) @incoming_message = @info_request.incoming_messages.first @@ -3123,11 +2977,9 @@ def create_old_unclassified_holding_pen @incoming_message.save! expect(@info_request.get_last_public_response_event).to eq(@incoming_message.response_event) end - end describe 'keeping track of the last public response date' do - let(:user) { FactoryBot.create(:user) } it 'does not set last_public_response_at date if there is no response' do @@ -3258,11 +3110,9 @@ def create_old_unclassified_holding_pen expect(request.last_public_response_at). to be_within(1.second).of(event.created_at) end - end describe 'when asked for the last public outgoing event' do - before do @info_request = FactoryBot.create(:info_request) @outgoing_message = @info_request.outgoing_messages.first @@ -3285,11 +3135,9 @@ def create_old_unclassified_holding_pen @outgoing_message.save! expect(@info_request.get_last_public_outgoing_event).to eq(@outgoing_message.info_request_events.first) end - end describe 'when asked who can be sent a followup' do - before do @info_request = FactoryBot.create(:info_request_with_plain_incoming) @incoming_message = @info_request.incoming_messages.first @@ -3337,11 +3185,9 @@ def create_old_unclassified_holding_pen @public_body.request_email, nil]]) end - end describe 'when generating json for the api' do - before do @user = mock_model(User, json_for_api: { id: 20, url_name: 'alaveteli_user', @@ -3358,21 +3204,17 @@ def create_old_unclassified_holding_pen ban_text: '', about_me: 'Hi' }) end - end describe 'when working out a subject for request emails' do - it 'creates a standard request subject' do info_request = FactoryBot.build(:info_request) expected_text = "Freedom of Information request - #{info_request.title}" expect(info_request.email_subject_request).to eq(expected_text) end - end describe 'when working out a subject for a followup emails' do - it "is not confused by an nil subject in the incoming message" do ir = info_requests(:fancy_dog_request) im = mock_model(IncomingMessage, @@ -3392,19 +3234,15 @@ def create_old_unclassified_holding_pen @info_request = InfoRequest.new(external_url: 'http://www.example.com') expect(@info_request.user_json_for_api).to eq({ name: 'Anonymous user' }) end - end describe "#set_described_state and #log_event" do - context "a request" do - let(:request) { InfoRequest.create!(title: "My request", public_body: public_bodies(:geraldine_public_body), user: users(:bob_smith_user)) } context "a series of events on a request" do - it "has sensible events after the initial request has been made" do # An initial request is sent # FIXME: The logic that changes the status when a message @@ -3536,11 +3374,9 @@ def create_old_unclassified_holding_pen expect(events[4].described_state).to eq("waiting_response") expect(events[4].calculated_state).to eq("waiting_response") end - end context "another series of events on a request" do - it "has sensible event states" do # An initial request is sent request.log_event('sent', {}) @@ -3582,11 +3418,9 @@ def create_old_unclassified_holding_pen expect(events[2].described_state).to eq("rejected") expect(events[2].calculated_state).to eq("rejected") end - end context "another series of events on a request" do - it "has sensible event states" do # An initial request is sent request.log_event('sent', {}) @@ -3631,11 +3465,9 @@ def create_old_unclassified_holding_pen expect(events[2].described_state).to eq("successful") expect(events[2].calculated_state).to eq("successful") end - end context "another series of events on a request" do - it "has sensible event states" do # An initial request is sent request.log_event('sent', {}) @@ -3654,11 +3486,8 @@ def create_old_unclassified_holding_pen expect(events[1].described_state).to eq("gone_postal") expect(events[1].calculated_state).to eq("gone_postal") end - end - end - end describe '#save' do @@ -3686,7 +3515,6 @@ def create_old_unclassified_holding_pen end describe 'when changing a described_state' do - it "changes the counts on its PublicBody without saving a new version" do pb = public_bodies(:geraldine_public_body) old_version_count = pb.versions.count @@ -3718,11 +3546,9 @@ def create_old_unclassified_holding_pen expect(pb.info_requests_visible_count).to eq(old_visible_count) expect(pb.versions.count).to eq(old_version_count) end - end describe 'when changing prominence' do - it "changes the counts on its PublicBody without saving a new version" do pb = public_bodies(:geraldine_public_body) old_version_count = pb.versions.count @@ -3757,11 +3583,9 @@ def create_old_unclassified_holding_pen expect(pb.info_requests_visible_count).to eq(old_visible_count) expect(pb.versions.count).to eq(old_version_count) end - end describe InfoRequest, 'when getting similar requests' do - before(:each) do update_xapian_index end @@ -3784,13 +3608,11 @@ def create_old_unclassified_holding_pen end describe InfoRequest, 'when constructing the list of recent requests' do - before(:each) do update_xapian_index end describe 'when there are fewer than five successful requests' do - it 'lists the most recently sent and successful requests by the creation date of the request event' do # Make sure the newest response is listed first even if a request @@ -3810,20 +3632,16 @@ def create_old_unclassified_holding_pen end previous = event end - end - end it 'coalesces duplicate requests' do request_events, request_events_all_successful = InfoRequest.recent_requests expect(request_events.map(&:info_request).select { |x|x.url_title =~ /^spam/ }.length).to eq(1) end - end describe InfoRequest, "when constructing a list of requests by query" do - before(:each) do load_raw_emails_data update_xapian_index @@ -3934,7 +3752,6 @@ def apply_filters(filters) results = apply_filters(latest_status: 'awaiting') expect(results.include?(info_requests(:fancy_dog_request))).to eq(true) end - end describe "making a zip cache path for a user" do @@ -4137,7 +3954,6 @@ def email_and_raw_email(opts = {}) end describe '#state' do - it 'returns a State::Calculator' do expect(InfoRequest.new.state).to be_a InfoRequest::State::Calculator end @@ -4255,7 +4071,6 @@ def email_and_raw_email(opts = {}) end describe '#embargo_expired?' do - context 'when the embargo has expired' do let!(:info_request) do request = FactoryBot.create(:info_request) @@ -4269,7 +4084,6 @@ def email_and_raw_email(opts = {}) it 'returns true' do expect(info_request.embargo_expired?).to be true end - end context 'when the embargo has not expired' do @@ -4283,25 +4097,20 @@ def email_and_raw_email(opts = {}) it 'returns false' do expect(info_request.embargo_expired?).to be false end - end context 'when there is no embargo' do - it 'returns false' do info_request = FactoryBot.build(:info_request) expect(info_request.embargo_expired?).to be false end - end - end describe '#embargo_expiring?' do let(:info_request) { FactoryBot.create(:info_request) } context 'when the embargo is expiring' do - before do FactoryBot.create(:expiring_embargo, info_request: info_request) end @@ -4309,11 +4118,9 @@ def email_and_raw_email(opts = {}) it 'returns true' do expect(info_request.reload.embargo_expiring?).to be true end - end context 'the embargo has already expired' do - let(:embargo) do FactoryBot.create(:expiring_embargo, info_request: info_request) end @@ -4329,11 +4136,9 @@ def email_and_raw_email(opts = {}) expect(info_request.reload.embargo_expiring?).to be false end end - end context 'when the embargo is not expiring soon' do - before do FactoryBot.create(:embargo, info_request: info_request) end @@ -4341,33 +4146,26 @@ def email_and_raw_email(opts = {}) it 'returns false' do expect(info_request.reload.embargo_expiring?).to be false end - end context 'when there is no embargo' do - it 'returns false' do expect(info_request.embargo_expiring?).to be false end - end - end describe '#embargo_pending_expiry?' do let(:info_request) { FactoryBot.create(:info_request) } context 'when the embargo is in force' do - it 'returns false' do FactoryBot.create(:expiring_embargo, info_request: info_request) expect(info_request.reload.embargo_pending_expiry?).to be false end - end context 'the embargo publication date has passed' do - let(:embargo) do FactoryBot.create(:expiring_embargo, info_request: info_request) end @@ -4383,28 +4181,21 @@ def email_and_raw_email(opts = {}) expect(info_request.reload.embargo_pending_expiry?).to be true end end - end context 'when there is no embargo' do - it 'returns false' do expect(info_request.embargo_pending_expiry?).to be false end - end - end - end RSpec.describe InfoRequest do - describe '#date_initial_request_last_sent_at' do let(:info_request) { FactoryBot.create(:info_request) } context 'when there is a value stored in the database' do - it 'returns the date the initial request was last sent' do expect(info_request).not_to receive(:last_event_forming_initial_request) expect(info_request.date_initial_request_last_sent_at) @@ -4413,7 +4204,6 @@ def email_and_raw_email(opts = {}) end context 'when there is no value stored in the database' do - it 'calculates the date the initial request was last sent' do info_request.date_initial_request_last_sent_at = nil expect(info_request) @@ -4423,7 +4213,6 @@ def email_and_raw_email(opts = {}) .to eq Time.now.to_date end end - end describe '#calculate_date_initial_request_last_sent_at' do @@ -4438,14 +4227,12 @@ def email_and_raw_email(opts = {}) expect(info_request.calculate_date_initial_request_last_sent_at) .to eq(Time.now.to_date) end - end describe '#last_event_forming_initial_request' do let(:info_request) { FactoryBot.create(:info_request) } context 'when there is a value in the database' do - it 'returns the last sending event of the request from the database' do sending_event = info_request .info_request_events @@ -4472,11 +4259,9 @@ def email_and_raw_email(opts = {}) expect(info_request.last_event_forming_initial_request). to eq failure_event end - end context 'when there is no value in the database' do - before do info_request.last_event_forming_initial_request_id = nil end @@ -4537,27 +4322,22 @@ def email_and_raw_email(opts = {}) expect { info_request.last_event_forming_initial_request } .to raise_error(RuntimeError) end - end - end describe '#date_response_required_by' do let(:info_request) { FactoryBot.create(:info_request) } context 'when there is a value stored in the database' do - it 'returns the date a response is required by' do travel_to(Time.zone.parse('2014-12-31')) do expect(info_request.date_response_required_by) .to eq Time.zone.parse('2015-01-28') end end - end context 'when there is no value stored in the database' do - it 'returns the date a response is required by' do travel_to(Time.zone.parse('2014-12-31')) do info_request.date_response_required_by = nil @@ -4568,9 +4348,7 @@ def email_and_raw_email(opts = {}) .to eq Time.zone.parse('2015-01-28') end end - end - end describe '#calculate_date_response_required_by' do @@ -4582,25 +4360,21 @@ def email_and_raw_email(opts = {}) .to eq Time.zone.parse('2015-01-28') end end - end describe '#date_very_overdue_after' do let(:info_request) { FactoryBot.create(:info_request) } context 'when there is a value stored in the database' do - it 'returns the date a response is very overdue after' do travel_to(Time.zone.parse('2014-12-31')) do expect(info_request.date_very_overdue_after) .to eq Time.zone.parse('2015-02-25') end end - end context 'when there is no value stored in the database' do - it 'returns the date a response is very overdue after' do travel_to(Time.zone.parse('2014-12-31')) do info_request.date_very_overdue_after = nil @@ -4611,9 +4385,7 @@ def email_and_raw_email(opts = {}) .to eq Time.zone.parse('2015-02-25') end end - end - end describe '#calculate_date_very_overdue_after' do @@ -4625,7 +4397,6 @@ def email_and_raw_email(opts = {}) .to eq Time.zone.parse('2015-02-25') end end - end describe '#log_event' do @@ -4639,17 +4410,14 @@ def email_and_raw_email(opts = {}) end context 'if options are passed' do - it 'sets :created_at on the event using the :created_at param' do time = Time.zone.now.beginning_of_day event = info_request.log_event('overdue', {}, { created_at: time }) expect(event.created_at).to eq time end - end context 'if the event resets due dates' do - it 'sets the due dates for the request' do # initial request sent travel_to(Time.zone.parse('2014-12-31')) { info_request } @@ -4678,7 +4446,6 @@ def email_and_raw_email(opts = {}) end context 'if there is no last_event_time on the info request' do - it 'sets the last_event_time on the info request to the event creation time' do info_request.last_event_time = nil @@ -4735,18 +4502,15 @@ def email_and_raw_email(opts = {}) expect(info_request.date_very_overdue_after) .to eq Time.zone.parse('2015-02-26') end - end describe '.log_overdue_events' do - let(:info_request) { FactoryBot.create(:info_request) } let(:use_notifications_request) do FactoryBot.create(:use_notifications_request) end context 'when an InfoRequest is not overdue' do - it 'does not create an event' do travel_to(Time.zone.parse('2014-12-31')) { info_request } travel_to(Time.zone.parse('2015-01-15')) do @@ -4757,11 +4521,9 @@ def email_and_raw_email(opts = {}) expect(overdue_events.size).to eq 0 end end - end context 'when an InfoRequest is overdue and does not have an overdue event' do - it "creates an overdue event at the beginning of the first day after the request's due date" do travel_to(Time.zone.parse('2014-12-31')) { info_request } @@ -4804,7 +4566,6 @@ def email_and_raw_email(opts = {}) context 'when an InfoRequest has been overdue, and has an overdue event but has had its due dates reset' do - it "creates an overdue event at the beginning of the first day after the request's due date" do travel_to(Time.zone.parse('2014-12-31')) { info_request } @@ -4830,24 +4591,18 @@ def email_and_raw_email(opts = {}) expect(overdue_event.created_at) .to eq Time.zone.parse('2015-02-28').beginning_of_day end - end - end - end describe '.log_very_overdue_events' do - let(:info_request) { FactoryBot.create(:info_request) } let(:use_notifications_request) do FactoryBot.create(:use_notifications_request) end context 'when a request is not very overdue' do - it 'should not create an event' do - travel_to(Time.zone.parse('2014-12-31')) { info_request } travel_to(Time.zone.parse('2015-01-30')) do @@ -4861,7 +4616,6 @@ def email_and_raw_email(opts = {}) end context 'when an InfoRequest is very overdue and does not have an overdue event' do - it "creates an overdue event at the beginning of the first day after the request's date_very_overdue_after" do travel_to(Time.zone.parse('2014-12-31')) { info_request } @@ -4905,7 +4659,6 @@ def email_and_raw_email(opts = {}) context 'when an InfoRequest has been very overdue, and has a very_overdue event but has had its due dates reset' do - it "creates a very_overdue event at the beginning of the first day after the request's date_very_overdue_after" do travel_to(Time.zone.parse('2014-12-31')) { info_request } @@ -4931,22 +4684,17 @@ def email_and_raw_email(opts = {}) expect(very_overdue_event.created_at). to eq Time.zone.parse('2015-04-25').beginning_of_day end - - end - end end describe '#last_embargo_set_event' do - context 'if no embargo has been set' do let(:info_request) { FactoryBot.create(:info_request) } it 'returns nil' do expect(info_request.last_embargo_set_event).to be_nil end - end context 'if embargoes have been set' do @@ -4968,31 +4716,25 @@ def email_and_raw_email(opts = {}) embargo_extension: { gid: embargo_extension.to_global_id.to_s } ) end - end - end describe '#last_embargo_expire_event' do let(:info_request) { FactoryBot.create(:info_request) } context 'if no embargo has been set' do - it 'returns nil' do expect(info_request.last_embargo_expire_event).to be_nil end - end context 'if an embargo has been set' do let(:embargo) { FactoryBot.create(:embargo, info_request: info_request) } context 'the embargo has not yet expired' do - it 'returns nil' do expect(info_request.last_embargo_expire_event).to be_nil end - end it 'returns the last "expire_embargo" event' do @@ -5003,9 +4745,7 @@ def email_and_raw_email(opts = {}) expect(last_embargo_set_event.event_type).to eq 'expire_embargo' end - end - end describe '#should_summarise?' do diff --git a/spec/models/mail_server_log/delivery_status_serializer_spec.rb b/spec/models/mail_server_log/delivery_status_serializer_spec.rb index 6e8ca47ec1..7a1ddcaed2 100644 --- a/spec/models/mail_server_log/delivery_status_serializer_spec.rb +++ b/spec/models/mail_server_log/delivery_status_serializer_spec.rb @@ -1,19 +1,15 @@ require 'spec_helper' RSpec.describe MailServerLog::DeliveryStatusSerializer do - describe '.dump' do - it 'returns a String representation of the delivery status' do status = MailServerLog::DeliveryStatus.new(:delivered) result = MailServerLog::DeliveryStatusSerializer.dump(status) expect(result).to eq 'delivered' end - end describe '.load' do - it 'returns a DeliveryStatus' do status = MailServerLog::DeliveryStatus.new(:sent) result = MailServerLog::DeliveryStatusSerializer.load('sent') @@ -24,7 +20,5 @@ expect { MailServerLog::DeliveryStatusSerializer.load('whut') }. to raise_error(ArgumentError, "Invalid delivery status: whut") end - end - end diff --git a/spec/models/mail_server_log/delivery_status_spec.rb b/spec/models/mail_server_log/delivery_status_spec.rb index 6f10924724..24d59dad03 100644 --- a/spec/models/mail_server_log/delivery_status_spec.rb +++ b/spec/models/mail_server_log/delivery_status_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe MailServerLog::DeliveryStatus do - describe '.new' do - it 'requires a status argument' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -11,49 +9,39 @@ it 'requires a valid status' do expect { described_class.new(:invalid) }.to raise_error(ArgumentError) end - end describe '#to_sym' do - it 'returns the status as a Symbol' do expect(described_class.new(:delivered).to_sym).to eq(:delivered) end - end describe '#to_s' do - it 'returns the status as an untranslated String' do AlaveteliLocalization.with_locale(:es) do expect(described_class.new(:sent).to_s).to eq('sent') end end - end describe '#to_s!' do - it 'returns the status as a translated String' do AlaveteliLocalization.with_locale(:es) do expect(described_class.new(:sent).to_s!).to eq('expedido') end end - end describe '#capitalize' do - it 'returns the status as a capitalized translated String' do AlaveteliLocalization.with_locale(:es) do expect(described_class.new(:sent).capitalize).to eq('Expedido') end end - end describe '#inspect' do - it 'returns the default format' do subject = described_class.new(:delivered) obj_id = format("0x00%x", (subject.object_id << 1)) @@ -61,11 +49,9 @@ %Q(#<#{described_class}:#{obj_id} @status=:delivered>) expect(subject.inspect).to eq(expected) end - end describe '#<=>' do - let(:statuses) do [:delivered, :unknown, @@ -91,11 +77,9 @@ it { expect(a >= b).to eq(false) } it { expect(a <= b).to eq(true) } it { expect(a == b).to eq(false) } - end describe '#delivered?' do - it 'returns true when the status is :delivered' do status = described_class.new(:delivered) expect(status.delivered?).to eq(true) @@ -105,11 +89,9 @@ status = described_class.new(:sent) expect(status.delivered?).to eq(false) end - end describe '#sent?' do - it 'returns true when the status is :sent' do status = described_class.new(:sent) expect(status.sent?).to eq(true) @@ -124,11 +106,9 @@ status = described_class.new(:failed) expect(status.sent?).to eq(false) end - end describe '#failed?' do - it 'returns true when the status is :failed' do status = described_class.new(:failed) expect(status.failed?).to eq(true) @@ -138,11 +118,9 @@ status = described_class.new(:delivered) expect(status.failed?).to eq(false) end - end describe '#unknown?' do - it 'returns true when the status is :unknown' do status = described_class.new(:unknown) expect(status.unknown?).to eq(true) @@ -152,11 +130,9 @@ status = described_class.new(:delivered) expect(status.unknown?).to eq(false) end - end describe '#humanize' do - it 'returns a humanized string for the :delivered status' do status = described_class.new(:delivered) expect(status.humanize).to eq('This message has been delivered.') @@ -178,5 +154,4 @@ to eq("We don't know the delivery status for this message.") end end - end diff --git a/spec/models/mail_server_log/exim_line_spec.rb b/spec/models/mail_server_log/exim_line_spec.rb index 290805b5ae..eb079574f4 100644 --- a/spec/models/mail_server_log/exim_line_spec.rb +++ b/spec/models/mail_server_log/exim_line_spec.rb @@ -1,26 +1,20 @@ require 'spec_helper' RSpec.describe MailServerLog::EximLine do - describe '.new' do - it 'requires a line argument' do expect { described_class.new }.to raise_error(ArgumentError) end - end describe '#to_s' do - it 'returns the log line' do line = '2016-02-03 06:58:11 [16003] 1aQrOE-0004A7-TL <= request-313973-1650c56a@localhost U=alaveteli P=local S=3098 id=ogm-512169+56b3a50ac0cf4-6717@localhost T="Freedom of Information request - Rspec" from for foi@body.example.com foi@body.example.com' expect(described_class.new(line).to_s).to eq(line) end - end describe '#<=>' do - let(:lines) { %w(A C B).map { |s| described_class.new(s) } } it { expect(lines.sort.map(&:to_s)).to eq(%w(A B C)) } @@ -34,11 +28,9 @@ it { expect(a >= b).to eq(false) } it { expect(a <= b).to eq(true) } it { expect(a == b).to eq(false) } - end describe '#inspect' do - it 'returns the default format' do subject = described_class.new('log line') obj_id = format("0x00%x", (subject.object_id << 1)) @@ -46,11 +38,9 @@ %Q(#<#{described_class}:#{obj_id} @line="log line">) expect(subject.inspect).to eq(expected) end - end describe '#flag' do - it 'returns nil if a flag cannot be parsed from the line' do expect(described_class.new('garbage').flag).to eq(nil) end @@ -96,11 +86,9 @@ line = '2016-04-06 12:01:08 [14935] 1anlCu-0003st-1p <= <> R=1anlCt-0003sm-LG U=Debian-exim P=local S=2934 T="Mail delivery failed: returning message to sender" from <> for request-326806-hk82iwn7@localhost' expect(described_class.new(line).flag).to eq('<= <>') end - end describe '#status' do - it 'returns nil if a status cannot be parsed from the line' do expect(described_class.new('garbage').status).to eq(nil) end @@ -149,11 +137,9 @@ line = '2016-04-06 12:01:08 [14935] 1anlCu-0003st-1p <= <> R=1anlCt-0003sm-LG U=Debian-exim P=local S=2934 T="Mail delivery failed: returning message to sender" from <> for request-326806-hk82iwn7@localhost' expect(described_class.new(line).status).to eq(:bounce_arrival) end - end describe '#delivery_status' do - it 'returns an unknown status if a delivery status cannot be parsed from the line' do expected = MailServerLog::DeliveryStatus.new(:unknown) expect(described_class.new('garbage').delivery_status).to eq(expected) @@ -208,7 +194,5 @@ expected = MailServerLog::DeliveryStatus.new(:failed) expect(described_class.new(line).delivery_status).to eq(expected) end - end - end diff --git a/spec/models/mail_server_log/postfix_line_spec.rb b/spec/models/mail_server_log/postfix_line_spec.rb index f10961efd4..769cfd48f8 100644 --- a/spec/models/mail_server_log/postfix_line_spec.rb +++ b/spec/models/mail_server_log/postfix_line_spec.rb @@ -1,26 +1,20 @@ require 'spec_helper' RSpec.describe MailServerLog::PostfixLine do - describe '.new' do - it 'requires a line argument' do expect { described_class.new }.to raise_error(ArgumentError) end - end describe '#to_s' do - it 'returns the log line' do line = 'Oct 2 08:57:45 ubuntu-precise-64 postfix/pickup[7843]: E9B4F420D5: uid=1001 from=' expect(described_class.new(line).to_s).to eq(line) end - end describe '#inspect' do - it 'returns the default format' do subject = described_class.new('log line') obj_id = format("0x00%x", (subject.object_id << 1)) @@ -28,11 +22,9 @@ %Q(#<#{described_class}:#{obj_id} @line="log line">) expect(subject.inspect).to eq(expected) end - end describe '#<=>' do - let(:lines) { %w(A C B).map { |s| described_class.new(s) } } it { expect(lines.sort.map(&:to_s)).to eq(%w(A B C)) } @@ -46,11 +38,9 @@ it { expect(a >= b).to eq(false) } it { expect(a <= b).to eq(true) } it { expect(a == b).to eq(false) } - end describe '#flag' do - it 'returns nil if a flag cannot be parsed from the line' do expect(described_class.new('garbage').flag).to eq(nil) end @@ -74,11 +64,9 @@ line = 'Oct 10 13:22:49 host postfix/qmgr[1706]: A323688C523:from=, status=expired, returned to sender' expect(described_class.new(line).flag).to eq('status=expired') end - end describe '#status' do - it 'returns nil if a status cannot be parsed from the line' do expect(described_class.new('garbage').status).to eq(nil) end @@ -102,11 +90,9 @@ line = 'Oct 10 13:22:49 host postfix/qmgr[1706]: A323688C523:from=, status=expired, returned to sender' expect(described_class.new(line).status).to eq(:expired) end - end describe '#delivery_status' do - it 'returns an unknown status if a delivery status cannot be parsed from the line' do expected = MailServerLog::DeliveryStatus.new(:unknown) expect(described_class.new('garbage').delivery_status).to eq(expected) @@ -135,7 +121,5 @@ expected = MailServerLog::DeliveryStatus.new(:failed) expect(described_class.new(line).delivery_status).to eq(expected) end - end - end diff --git a/spec/models/mail_server_log_spec.rb b/spec/models/mail_server_log_spec.rb index 4a90d64790..67800f61cf 100644 --- a/spec/models/mail_server_log_spec.rb +++ b/spec/models/mail_server_log_spec.rb @@ -167,7 +167,6 @@ end describe '.request_exim_sent?' do - it "returns true when a log line says the message was sent" do line = "Apr 28 15:53:37 server exim[12105]: 2016-04-28 15:53:37 " \ "[12105] 1avnJx-00039F-Hs <= " \ @@ -204,7 +203,6 @@ expect(MailServerLog.request_exim_sent?(info_request)).to be false end end - end context "Postfix" do @@ -282,26 +280,21 @@ end describe '#line' do - it 'returns the line attribute' do log = MailServerLog.new(line: 'log line') expect(log.line).to eq('log line') end context ':decorate option is truthy' do - context 'using the :exim MTA' do - it 'returns an EximLine containing the line attribute' do log = MailServerLog.new(line: 'log line') expect(log.line(decorate: true)). to eq(MailServerLog::EximLine.new('log line')) end - end context 'using the :postfix MTA' do - before do allow(AlaveteliConfiguration).to receive(:mta_log_type).and_return('postfix') end @@ -311,13 +304,10 @@ expect(log.line(decorate: true)). to eq(MailServerLog::PostfixLine.new('log line')) end - end - end context ':redact option is truthy' do - it 'redacts the info request id hash' do log = FactoryBot.create(:mail_server_log) line = log.line += " #{ log.info_request.incoming_email }" @@ -393,7 +383,6 @@ end describe '#delivery_status' do - context 'if there is a stored value' do let(:log) do FactoryBot.create(:mail_server_log, line: "log text **") @@ -418,7 +407,6 @@ expect(log).to_not receive(:line) log.reload.delivery_status end - end # TODO: This can be removed when there are no more cached MTA-specific @@ -457,7 +445,6 @@ end context 'there is not a stored value' do - it 'parses the line text' do log = MailServerLog.new(line: "…<=…") expect(log.delivery_status). @@ -480,11 +467,9 @@ status = MailServerLog::DeliveryStatus.new(:sent) expect(log.delivery_status).to eq(status) end - end context 'using the :postfix MTA' do - before do allow(AlaveteliConfiguration).to receive(:mta_log_type).and_return('postfix') end @@ -502,15 +487,11 @@ status = MailServerLog::DeliveryStatus.new(:delivered) expect(log.delivery_status).to eq(status) end - end - end - end describe '#is_owning_user?' do - it 'returns true if the user is the owning user of the info request' do log = FactoryBot.build(:mail_server_log) request = mock_model(InfoRequest, is_owning_user?: true) @@ -524,13 +505,10 @@ allow(log).to receive(:info_request).and_return(request) expect(log.is_owning_user?(double(:user))).to eq(false) end - end describe '.check_recent_requests_have_been_sent' do - context 'if all recent requests have been sent' do - it 'returns true' do info_request = FactoryBot.create(:info_request, created_at: Time.zone.now - 5.days) @@ -538,11 +516,9 @@ and_return(true) expect(MailServerLog.check_recent_requests_have_been_sent).to eq(true) end - end context 'if a recent request has not been sent' do - it 'returns false' do info_request = FactoryBot.create(:info_request, created_at: Time.zone.now - 5.days) @@ -564,8 +540,6 @@ expect($stderr).to receive(:puts).with(expected_message) MailServerLog.check_recent_requests_have_been_sent end - end - end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index ebe6804bfb..54e9b358e3 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -165,7 +165,6 @@ end context 'and the expiry of the embargo is pending' do - it 'returns false when the publication date has been reached' do travel_to(embargo_expiring_request.embargo.publish_at) do expect(notification.expired).to be false @@ -177,7 +176,6 @@ expect(notification.expired).to be false end end - end context "and the embargo has been removed" do @@ -208,15 +206,12 @@ end context 'and a new embargo has not been created' do - it 'returns false' do expect(notification.expired).to be false end - end context 'and a new embargo has been created' do - before do FactoryBot.create(:embargo, info_request: embargo_expired_request) notification.reload @@ -225,9 +220,7 @@ it 'returns true' do expect(notification.expired).to be true end - end - end context "when the notification is for an overdue request" do diff --git a/spec/models/outgoing_message/template/batch_request_spec.rb b/spec/models/outgoing_message/template/batch_request_spec.rb index 9f4bc0ac77..ca78bff297 100644 --- a/spec/models/outgoing_message/template/batch_request_spec.rb +++ b/spec/models/outgoing_message/template/batch_request_spec.rb @@ -1,18 +1,14 @@ require 'spec_helper' RSpec.describe OutgoingMessage::Template::BatchRequest do - describe '.placeholder_salutation' do - it 'returns the placeholder salutation' do expect(described_class.placeholder_salutation). to eq('Dear [Authority name],') end - end describe '#body' do - it 'returns the expected template text' do expected = "Dear [Authority name],\n\n\n\nYours faithfully,\n\n" expect(subject.body).to eq(expected) @@ -23,19 +19,15 @@ expected = "Dear [Authority name],\n\nA custom letter\n\n\n\nYours faithfully,\n\n" expect(subject.body(opts)).to eq(expected) end - end describe '#salutation' do - it 'returns the salutation' do expect(subject.salutation).to eq('Dear [Authority name],') end - end describe '#letter' do - it 'returns the letter' do expect(subject.letter).to eq('') end @@ -43,15 +35,11 @@ it 'returns a custom letter' do expect(subject.letter(letter: 'custom')).to eq("\n\ncustom") end - end describe '#signoff' do - it 'returns the signoff' do expect(subject.signoff).to eq('Yours faithfully,') end - end - end diff --git a/spec/models/outgoing_message/template/incoming_message_followup_spec.rb b/spec/models/outgoing_message/template/incoming_message_followup_spec.rb index 21be1cde5d..bec1e3c6ff 100644 --- a/spec/models/outgoing_message/template/incoming_message_followup_spec.rb +++ b/spec/models/outgoing_message/template/incoming_message_followup_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe OutgoingMessage::Template::IncomingMessageFollowup do - describe '#body' do - it 'requires a :public_body_name key' do msg = 'Missing required key: public_body_name' expect { subject.body }.to raise_error(ArgumentError, msg) @@ -20,20 +18,16 @@ expected = "Dear A body,\n\nA custom letter\n\n\n\nYours sincerely,\n\n" expect(subject.body(opts)).to eq(expected) end - end describe '#salutation' do - it 'returns the salutation' do expect(subject.salutation(public_body_name: 'A body')). to eq('Dear A body,') end - end describe '#letter' do - it 'returns the letter' do expect(subject.letter).to eq('') end @@ -41,15 +35,11 @@ it 'returns a custom letter' do expect(subject.letter(letter: 'custom')).to eq("\n\ncustom") end - end describe '#signoff' do - it 'returns the signoff' do expect(subject.signoff).to eq('Yours sincerely,') end - end - end diff --git a/spec/models/outgoing_message/template/initial_request_spec.rb b/spec/models/outgoing_message/template/initial_request_spec.rb index 33170a9921..bcdf449e14 100644 --- a/spec/models/outgoing_message/template/initial_request_spec.rb +++ b/spec/models/outgoing_message/template/initial_request_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe OutgoingMessage::Template::InitialRequest do - describe '#body' do - it 'requires a :public_body_name key' do msg = 'Missing required key: public_body_name' expect { subject.body }.to raise_error(ArgumentError, msg) @@ -20,11 +18,9 @@ expected = "Dear A body,\n\nA custom letter\n\n\n\nYours faithfully,\n\n" expect(subject.body(opts)).to eq(expected) end - end describe '#salutation' do - context 'when a public_body_name is given' do it 'returns the salutation' do expect(subject.salutation(public_body_name: 'A body')). @@ -37,11 +33,9 @@ expect(subject.salutation).to eq('Dear [Authority name],') end end - end describe '#letter' do - it 'returns the letter' do expect(subject.letter).to eq('') end @@ -49,15 +43,11 @@ it 'returns a custom letter' do expect(subject.letter(letter: 'custom')).to eq("\n\ncustom") end - end describe '#signoff' do - it 'returns the signoff' do expect(subject.signoff).to eq('Yours faithfully,') end - end - end diff --git a/spec/models/outgoing_message/template/internal_review_spec.rb b/spec/models/outgoing_message/template/internal_review_spec.rb index a9ed1b8b60..bc76ff1727 100644 --- a/spec/models/outgoing_message/template/internal_review_spec.rb +++ b/spec/models/outgoing_message/template/internal_review_spec.rb @@ -1,18 +1,14 @@ require 'spec_helper' RSpec.describe OutgoingMessage::Template::InternalReview do - describe '.details_placeholder' do - it 'returns the internal review placeholder text' do expect(described_class.details_placeholder). to eq('GIVE DETAILS ABOUT YOUR COMPLAINT HERE') end - end describe '#body' do - it 'requires a :public_body_name key' do attrs = { info_request_title: 'a', url: 'b' } msg = 'Missing required key: public_body_name' @@ -67,20 +63,16 @@ expected = "Dear A body,\n\nA custom letter\n\n\nYours faithfully,\n\n" expect(subject.body(attrs)).to eq(expected) end - end describe '#salutation' do - it 'returns the salutation' do expect(subject.salutation(public_body_name: 'A body')). to eq('Dear A body,') end - end describe '#letter' do - it 'returns the letter' do attrs = { public_body_name: 'A body', info_request_title: 'a test title', @@ -109,15 +101,11 @@ it 'returns a custom letter' do expect(subject.letter(letter: 'custom')).to eq("\n\ncustom") end - end describe '#signoff' do - it 'returns the signoff' do expect(subject.signoff).to eq('Yours faithfully,') end - end - end diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb index 084f8b2de9..86aab5fbde 100644 --- a/spec/models/outgoing_message_spec.rb +++ b/spec/models/outgoing_message_spec.rb @@ -47,18 +47,15 @@ end describe '.fill_in_salutation' do - it 'replaces the batch request salutation with the body name' do text = 'Dear [Authority name],' public_body = FactoryBot.build(:public_body, name: 'A Body') expect(described_class.fill_in_salutation(text, public_body)). to eq('Dear A Body,') end - end describe '.with_body' do - let(:message) { FactoryBot.create(:initial_request, body: "foo\r\nbar") } it 'should return message if body matches exactly' do @@ -66,7 +63,6 @@ end context 'when using PostgreSQL database' do - before do if ActiveRecord::Base.connection.adapter_name != 'PostgreSQL' skip 'These tests only work for PostgreSQL' @@ -86,9 +82,7 @@ expect(OutgoingMessage.with_body("foo\nbar\nbaz")).to_not include(message) expect(OutgoingMessage.with_body("foo\r\nbar\r\nbaz")).to_not include(message) end - end - end describe '.expected_send_errors' do @@ -107,11 +101,9 @@ class TestError < StandardError; end it { is_expected.to include(TestError) } end - end describe '#initialize' do - it 'does not censor the #body' do attrs = { status: 'ready', message_type: 'initial_request', @@ -123,11 +115,9 @@ class TestError < StandardError; end expect_any_instance_of(OutgoingMessage).not_to receive(:body).and_call_original OutgoingMessage.find(message.id) end - end describe '#default_letter' do - it 'reloads the default body when set after initialization' do req = FactoryBot.build(:info_request) message = described_class.new(info_request: req) @@ -142,11 +132,9 @@ class TestError < StandardError; end message.default_letter = 'test' expect(message.body).not_to include('test') end - end describe '#what_doing' do - it 'allows a value of normal_sort' do message = FactoryBot.build(:initial_request, what_doing: 'normal_sort') @@ -177,7 +165,6 @@ class TestError < StandardError; end expect(message.errors[:what_doing_dummy]). to eq(['Please choose what sort of reply you are making.']) end - end describe '#destroy' do @@ -200,7 +187,6 @@ class TestError < StandardError; end end describe '#from' do - it 'uses the user name and request magic email' do user = FactoryBot.create(:user, name: 'Spec User 862') request = FactoryBot.create(:info_request, user: user) @@ -208,13 +194,10 @@ class TestError < StandardError; end expected = "Spec User 862 " expect(message.from).to eq(expected) end - end describe '#to' do - context 'when sending an initial request' do - it 'uses the public body name and email' do body = FactoryBot.create(:public_body, name: 'Example Public Body', short_name: 'EPB') @@ -223,11 +206,9 @@ class TestError < StandardError; end expected = 'FOI requests at EPB ' expect(message.to).to eq(expected) end - end context 'when following up to an incoming message' do - it 'uses the safe_from_name if the incoming message has a valid address' do message = FactoryBot.build(:internal_review_request) @@ -257,26 +238,20 @@ class TestError < StandardError; end expected = 'FOI requests at EPB ' expect(message.to).to eq(expected) end - end - end describe '#subject' do - context 'when sending an initial request' do - it 'uses the request title with the law prefixed' do request = FactoryBot.create(:info_request, title: 'Example Request') message = FactoryBot.build(:initial_request, info_request: request) expected = 'Freedom of Information request - Example Request' expect(message.subject).to eq(expected) end - end context 'when sending a followup that is not a reply to an incoming message' do - it 'prefixes the initial request subject with Re:' do request = FactoryBot.create(:info_request, title: 'Example Request') message = FactoryBot.build(:new_information_followup, @@ -285,11 +260,9 @@ class TestError < StandardError; end expected = 'Re: Freedom of Information request - Example Request' expect(message.subject).to eq(expected) end - end context 'when following up to an incoming message' do - it 'uses the request title prefixed with Re: if the incoming message does not have a valid reply address' do request = FactoryBot.create(:info_request, title: 'Example Request') message = FactoryBot.build(:new_information_followup, @@ -345,24 +318,19 @@ class TestError < StandardError; end expect(message.subject).to eq('Re: FOI REF#123456789') end - end context 'when requesting an internal review' do - it 'prefixes the request title with the internal review message' do request = FactoryBot.create(:info_request, title: 'Example Request') message = FactoryBot.build(:internal_review_request, info_request: request) expected = 'Internal review of Freedom of Information request - Example Request' expect(message.subject).to eq(expected) end - end - end describe '#body' do - it 'returns the body attribute' do attrs = { status: 'ready', message_type: 'initial_request', @@ -538,7 +506,6 @@ class TestError < StandardError; end end context "when a censor rule changes the default text" do - before do opts = { text: 'Regulation 1049/2001', replacement: 'the law', @@ -568,13 +535,10 @@ class TestError < StandardError; end to include("Please sign at the bottom with your name, or alter " \ "the \"Yours faithfully,\" signature") end - end - end context "when it's an internal review" do - it "adds an error message if the text has not been changed" do outgoing_message = OutgoingMessage.new(status: 'ready', @@ -614,11 +578,9 @@ class TestError < StandardError; end "correspondence is available on the Internet at " \ "this address") end - end context "when it's an followup" do - it "adds an error message if the text has not been changed" do outgoing_message = OutgoingMessage.new(status: 'ready', @@ -630,11 +592,8 @@ class TestError < StandardError; end expect(outgoing_message.errors.messages[:body]). to include("Please enter your follow up message") end - end - end - end describe '#from_name' do @@ -706,13 +665,11 @@ class TestError < StandardError; end end describe '#apply_masks' do - before(:each) do @message = FactoryBot.create(:initial_request) @default_opts = { last_edit_editor: 'unknown', last_edit_comment: 'none' } - end it 'replaces text with global censor rules' do @@ -782,13 +739,10 @@ class TestError < StandardError; end result = @message.apply_masks(data, 'application/vnd.ms-word') expect(result).to eq(expected) end - end describe '#get_default_message' do - context 'an initial_request' do - it 'produces the expected text for a batch request template' do public_body = FactoryBot.build(:public_body, name: 'a test public body') @@ -804,11 +758,9 @@ class TestError < StandardError; end expected_text = "Dear a test public body,\n\n\n\nYours faithfully,\n\n" expect(outgoing_message.get_default_message).to eq(expected_text) end - end context 'a followup' do - it 'produces the expected text for a followup' do public_body = FactoryBot.build(:public_body, name: 'a test public body') @@ -844,11 +796,9 @@ class TestError < StandardError; end expected_text = "Dear helpdesk,\n\n\n\nYours sincerely,\n\n" expect(outgoing_message.get_default_message).to eq(expected_text) end - end context 'an internal_review' do - it 'produces the expected text for an internal review request' do public_body = FactoryBot.build(:public_body, name: 'a test public body') @@ -883,13 +833,10 @@ class TestError < StandardError; end expect(outgoing_message.get_default_message).to eq(expected_text) end - end - end describe '#get_body_for_html_display' do - before do @outgoing_message = OutgoingMessage.new({ status: 'ready', @@ -936,7 +883,6 @@ class TestError < StandardError; end @outgoing_message.body = split_line expect(@outgoing_message.get_body_for_html_display).to include(expected) end - end describe '#get_text_for_indexing' do @@ -979,7 +925,6 @@ class TestError < StandardError; end end describe '#is_owning_user?' do - it 'returns true if the user is the owning user of the info request' do request = FactoryBot.build(:info_request) message = FactoryBot.build(:initial_request, info_request: request) @@ -992,13 +937,10 @@ class TestError < StandardError; end message = FactoryBot.build(:initial_request, info_request: request) expect(message.is_owning_user?(user)).to eq(false) end - end describe '#smtp_message_ids' do - context 'a sent message' do - it 'returns one smtp_message_id when a message has been sent once' do message = FactoryBot.create(:initial_request) smtp_id = message.info_request_events.first.params[:smtp_message_id] @@ -1021,11 +963,9 @@ class TestError < StandardError; end message.info_request_events.first.update(params: {}) expect(message.smtp_message_ids).to be_empty end - end context 'a resent message' do - it 'returns an smtp_message_id each time the message has been sent' do message = FactoryBot.create(:initial_request) smtp_id_1 = message.info_request_events.first.params[:smtp_message_id] @@ -1101,21 +1041,16 @@ class TestError < StandardError; end expect(message.smtp_message_ids). to eq([smtp_id_1, smtp_id_3]) end - end - end describe '#mta_ids' do - context 'when exim is the MTA' do - before do allow(AlaveteliConfiguration).to receive(:mta_log_type).and_return("exim") end context 'a sent message' do - it 'returns one mta_id when a message has been sent once' do message = FactoryBot.create(:initial_request) body_email = message.info_request.public_body.request_email @@ -1163,11 +1098,9 @@ class TestError < StandardError; end expect(message.mta_ids).to be_empty end - end context 'a resent message' do - it 'returns an mta_id each time the message has been sent' do message = FactoryBot.create(:initial_request) body_email = message.info_request.public_body.request_email @@ -1285,13 +1218,11 @@ class TestError < StandardError; end end context 'when Postfix is the MTA' do - before do allow(AlaveteliConfiguration).to receive(:mta_log_type).and_return("postfix") end context 'a sent message' do - it 'returns one mta_id when a message has been sent once' do message = FactoryBot.create(:initial_request) body_email = message.info_request.public_body.request_email @@ -1327,11 +1258,9 @@ class TestError < StandardError; end expect(message.mta_ids).to be_empty end - end context 'a resent message' do - it 'returns an mta_id each time the message has been sent' do message = FactoryBot.create(:initial_request) body_email = message.info_request.public_body.request_email @@ -1457,15 +1386,11 @@ class TestError < StandardError; end to eq(%w(1A6A236F4E08 3A6A236F4E08)) end end - end - end describe '#mail_server_logs' do - context 'when exim is the MTA' do - before do allow(AlaveteliConfiguration). to receive(:mta_log_type).and_return('exim') @@ -1596,7 +1521,6 @@ class TestError < StandardError; end to eq(expected_lines.scan(/[^\n]*\n/)) end - it 'handles log lines where a delivery status cant be parsed' do message = FactoryBot.create(:initial_request) body_email = message.info_request.public_body.request_email @@ -1621,11 +1545,9 @@ class TestError < StandardError; end expect(message.mail_server_logs.map(&:line)). to eq(expected_lines.scan(/[^\n]*\n/)) end - end context 'when postfix is the MTA' do - before do allow(AlaveteliConfiguration). to receive(:mta_log_type).and_return('postfix') @@ -1734,13 +1656,10 @@ class TestError < StandardError; end expect(message.mail_server_logs.map(&:line)). to eq(expected_lines.scan(/[^\n]*\n/)) end - end - end describe '#delivery_status' do - it 'returns a failed status if the message send failed' do message = FactoryBot.create(:failed_sent_request_event).outgoing_message status = MailServerLog::DeliveryStatus.new(:failed) @@ -1767,7 +1686,6 @@ class TestError < StandardError; end end context 'when the MTA is exim' do - before do allow(AlaveteliConfiguration). to receive(:mta_log_type).and_return('exim') @@ -1815,13 +1733,10 @@ class TestError < StandardError; end status = MailServerLog::DeliveryStatus.new(:failed) expect(message.delivery_status).to eq(status) end - end - end context 'when the MTA is postfix' do - before do allow(AlaveteliConfiguration). to receive(:mta_log_type).and_return('postfix') @@ -1896,7 +1811,6 @@ class TestError < StandardError; end expect(message.delivery_status).to eq(status) end end - end describe '#prepare_message_for_resend' do @@ -1922,7 +1836,6 @@ class TestError < StandardError; end outgoing_message.status = 'failed' expect{ subject }.to change{ outgoing_message.status }.to('ready') end - end describe '#record_email_failure' do @@ -1950,13 +1863,10 @@ class TestError < StandardError; end it 'updates OutgoingMessage#last_sent_at' do expect{ subject }.to change{ outgoing_message.last_sent_at } end - end - end RSpec.describe OutgoingMessage, " when making an outgoing message" do - before do @om = outgoing_messages(:useless_outgoing_message) @outgoing_message = OutgoingMessage.new({ @@ -1973,7 +1883,6 @@ class TestError < StandardError; end expect(@outgoing_message.get_text_for_indexing).not_to include("foo@bar.com") end - it "should include email addresses in outgoing messages" do expect(@outgoing_message.body).to include("foo@bar.com") end @@ -1992,15 +1901,12 @@ class TestError < StandardError; end expected_text = "Dear A test public body,\n\nPlease pass this on to the person who conducts Freedom of Information reviews.\n\nI am writing to request an internal review of A test public body's handling of my FOI request 'A test title'.\n\n[ GIVE DETAILS ABOUT YOUR COMPLAINT HERE ]\n\nA full history of my FOI request and all correspondence is available on the Internet at this address: http://test.host/request/a_test_title\n\nYours faithfully," expect(outgoing_message.body).to eq(expected_text) end - end RSpec.describe OutgoingMessage, "when validating the format of the message body" do - it 'should handle a salutation with a bracket in it' do outgoing_message = FactoryBot.build(:initial_request) allow(outgoing_message).to receive(:get_salutation).and_return("Dear Bob (Robert,") expect { outgoing_message.valid? }.not_to raise_error end - end diff --git a/spec/models/post_redirect_spec.rb b/spec/models/post_redirect_spec.rb index cac55bd3dd..02c5e9132e 100644 --- a/spec/models/post_redirect_spec.rb +++ b/spec/models/post_redirect_spec.rb @@ -18,7 +18,6 @@ require 'spec_helper' RSpec.describe PostRedirect do - describe '.generate_verifiable_token' do subject do described_class.generate_verifiable_token( @@ -44,16 +43,13 @@ end describe '#valid?' do - it 'is false if an invalid circumstance is provided' do pr = PostRedirect.new(circumstance: 'invalid') expect(pr).to_not be_valid end - end describe '#email_token_valid?' do - subject { post_redirect.email_token_valid? } # Using attributes_for as PostRedirect redirect assigns attributes in @@ -90,9 +86,7 @@ it { is_expected.to eq false } end - end - end RSpec.describe PostRedirect, " when constructing" do diff --git a/spec/models/pro_account_spec.rb b/spec/models/pro_account_spec.rb index 3f452b1e90..2c0df6cac5 100644 --- a/spec/models/pro_account_spec.rb +++ b/spec/models/pro_account_spec.rb @@ -43,7 +43,6 @@ end describe 'validations' do - let(:user) { FactoryBot.build(:pro_user) } subject(:pro_account) { FactoryBot.build(:pro_account, user: user) } @@ -53,11 +52,9 @@ pro_account.user = nil expect(pro_account).not_to be_valid end - end describe '#update_stripe_customer', feature: :pro_pricing do - let(:user) { FactoryBot.build(:pro_user) } let(:pro_account) { FactoryBot.build(:pro_account, user: user) } @@ -92,7 +89,6 @@ end context 'with pro_pricing disabled' do - it 'does not store Stripe customer ID' do with_feature_disabled(:pro_pricing) do expect { @@ -126,13 +122,10 @@ ) end end - end - end describe '#stripe_customer' do - subject { pro_account.stripe_customer } context 'with invalid Stripe customer ID' do @@ -144,7 +137,6 @@ expect { pro_account.stripe_customer }. to raise_error Stripe::InvalidRequestError end - end context 'with valid Stripe customer ID' do @@ -155,9 +147,7 @@ it 'finds the Stripe::Customer linked to the ProAccount' do expect(pro_account.stripe_customer).to eq(customer) end - end - end describe '#subscription?' do @@ -195,7 +185,5 @@ before { pro_account.stripe_customer_id = nil } it { is_expected.to eq false } end - end - end diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb index 3eb7888d93..29a60e0903 100644 --- a/spec/models/profile_photo_spec.rb +++ b/spec/models/profile_photo_spec.rb @@ -14,7 +14,6 @@ require 'spec_helper' RSpec.describe ProfilePhoto, "when constructing a new photo" do - before do @mock_user = mock_model(User) end @@ -63,6 +62,4 @@ expect(profile_photo.image.width).to eq(198) expect(profile_photo.image.height).to eq(289) end - - end diff --git a/spec/models/public_body_category/category_collection_spec.rb b/spec/models/public_body_category/category_collection_spec.rb index c16801a334..029d4094f4 100644 --- a/spec/models/public_body_category/category_collection_spec.rb +++ b/spec/models/public_body_category/category_collection_spec.rb @@ -2,7 +2,6 @@ RSpec.describe PublicBodyCategory::CategoryCollection do context "requesting data" do - before do data = [ "Local and regional", [ "local_council", "Local councils", "a local council" ], @@ -13,11 +12,9 @@ end describe 'when asked for headings' do - it 'should return a list of headings' do expect(@categories.headings).to eq(['Local and regional', 'Miscellaneous']) end - end describe 'when asked for categories with headings' do @@ -34,8 +31,6 @@ end end - - describe 'when asked for tags by headings' do it 'should return a hash of tags keyed by heading' do expect(@categories.by_heading).to eq({ 'Local and regional' => ['local_council'], diff --git a/spec/models/public_body_category_link_spec.rb b/spec/models/public_body_category_link_spec.rb index 4cdbb54dbb..268e9b8399 100644 --- a/spec/models/public_body_category_link_spec.rb +++ b/spec/models/public_body_category_link_spec.rb @@ -14,7 +14,6 @@ require 'spec_helper' RSpec.describe PublicBodyHeading, 'when validating' do - it 'should set a default display order based on the next available display order' do heading = FactoryBot.create(:public_body_heading) category = FactoryBot.create(:public_body_category) @@ -35,7 +34,6 @@ expect(category_link).not_to be_valid expect(category_link.errors[:public_body_heading]).to eq(["can't be blank"]) end - end RSpec.describe PublicBodyCategoryLink do @@ -68,7 +66,6 @@ end RSpec.describe PublicBodyCategoryLink, 'when setting a category display order' do - it 'should return 0 if there are no public body headings' do heading = FactoryBot.create(:public_body_heading) expect(PublicBodyCategoryLink.next_display_order(heading)).to eq(0) @@ -82,7 +79,6 @@ expect(PublicBodyCategoryLink.next_display_order(heading)).to eq(1) end - end RSpec.describe PublicBodyCategoryLink, '.by_display_order' do diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb index b3409747eb..29a4786a19 100644 --- a/spec/models/public_body_category_spec.rb +++ b/spec/models/public_body_category_spec.rb @@ -14,9 +14,7 @@ require 'spec_helper' RSpec.describe PublicBodyCategory do - context 'when validating' do - it 'should require a title' do category = PublicBodyCategory.new expect(category).not_to be_valid @@ -56,11 +54,9 @@ expect(category.errors[:title].size).to eq(1) expect(translation.errors[:title].size).to eq(0) end - end describe '#save' do - it 'saves translations' do category = FactoryBot.build(:public_body_category) category.translations_attributes = { es: { locale: 'es', @@ -70,13 +66,10 @@ category.save! expect(PublicBodyCategory.find(category.id).translations.size).to eq(2) end - end describe '#translations_attributes=' do - context 'translation_attrs is a Hash' do - it 'does not persist translations' do category = FactoryBot.create(:public_body_category) category.translations_attributes = { es: { locale: 'es', @@ -153,14 +146,11 @@ expect(category.translations.size).to eq(2) end - end end - end RSpec.describe PublicBodyCategory::Translation do - it 'requires a locale' do translation = PublicBodyCategory::Translation.new translation.valid? @@ -186,28 +176,23 @@ end describe '#default_locale?' do - it 'returns true if the locale is the default locale' do translation = PublicBodyCategory::Translation.new(locale: "en") expect(translation.default_locale?).to be true end context 'when the default locale contains an underscore' do - it 'returns true if the locale is the default locale' do AlaveteliLocalization.set_locales('en_GB es', 'en_GB') translation = PublicBodyCategory::Translation.new(locale: "en_GB") expect(translation.default_locale?).to be true end - end it 'returns false if the locale is not the default locale' do translation = PublicBodyCategory::Translation.new(locale: "es") expect(translation.default_locale?).to be false end - end - end diff --git a/spec/models/public_body_change_request_spec.rb b/spec/models/public_body_change_request_spec.rb index 5975c974d9..c3663db12c 100644 --- a/spec/models/public_body_change_request_spec.rb +++ b/spec/models/public_body_change_request_spec.rb @@ -59,7 +59,6 @@ end RSpec.describe PublicBodyChangeRequest, 'when validating' do - it 'should not be valid without a public body name' do change_request = PublicBodyChangeRequest.new expect(change_request.valid?).to be false @@ -98,11 +97,9 @@ expect(change_request.valid?).to be false expect(change_request.errors[:public_body_email]).to eq(["The authority email doesn't look like a valid address"]) end - end RSpec.describe PublicBodyChangeRequest, 'get_user_name' do - it 'should return the user_name field if there is no user association' do change_request = PublicBodyChangeRequest.new(user_name: 'Test User') expect(change_request.get_user_name).to eq('Test User') @@ -113,12 +110,9 @@ change_request = PublicBodyChangeRequest.new(user: user) expect(change_request.get_user_name).to eq(user.name) end - end - RSpec.describe PublicBodyChangeRequest, 'get_user_email' do - it 'should return the user_email field if there is no user association' do change_request = PublicBodyChangeRequest.new(user_email: 'user@example.com') expect(change_request.get_user_email).to eq('user@example.com') @@ -129,7 +123,6 @@ change_request = PublicBodyChangeRequest.new(user: user) expect(change_request.get_user_email).to eq(user.email) end - end RSpec.describe PublicBodyChangeRequest, '.new_body_requests' do @@ -166,7 +159,6 @@ end RSpec.describe PublicBodyChangeRequest, 'get_public_body_name' do - it 'should return the public_body_name field if there is no public body association' do change_request = PublicBodyChangeRequest.new(public_body_name: 'Test Authority') expect(change_request.get_public_body_name).to eq('Test Authority') @@ -177,11 +169,9 @@ change_request = PublicBodyChangeRequest.new(public_body: public_body) expect(change_request.get_public_body_name).to eq(public_body.name) end - end RSpec.describe PublicBodyChangeRequest, 'when creating a comment for the associated public body' do - it 'should include requesting user, source_url and notes' do change_request = PublicBodyChangeRequest.new(user_name: 'Test User', user_email: 'test@example.com', @@ -190,13 +180,10 @@ expected = "Requested by: Test User (test@example.com)\nSource URL: http://www.example.com\nNotes: Some notes" expect(change_request.comment_for_public_body).to eq(expected) end - end RSpec.describe PublicBodyChangeRequest, '#request_subject' do - context 'requesting a new authority' do - it 'returns an appropriate subject line' do change_request = PublicBodyChangeRequest.new(public_body_name: 'Test') expect(change_request.request_subject). @@ -215,11 +202,9 @@ PublicBodyChangeRequest.new(public_body_name: "Test's") expect(change_request.request_subject.html_safe?).to eq(false) end - end context 'updating an existing authority' do - it 'returns an appropriate subject line' do public_body = FactoryBot.build(:public_body) change_request = PublicBodyChangeRequest.new(public_body: public_body) @@ -233,13 +218,10 @@ expect(change_request.request_subject). to eq('Update email address - Test\'s') end - end - end RSpec.describe PublicBodyChangeRequest, '#add_body_request?' do - it 'returns false if there is an associated public_body' do public_body = FactoryBot.build(:public_body) change_request = PublicBodyChangeRequest.new(public_body: public_body) @@ -250,11 +232,9 @@ change_request = PublicBodyChangeRequest.new(public_body_name: 'Test') expect(change_request.add_body_request?).to eq(true) end - end RSpec.describe PublicBodyChangeRequest, 'when creating a default subject for a response email' do - it 'should create an appropriate subject for a request to add a body' do change_request = PublicBodyChangeRequest.new(public_body_name: 'Test Body') expect(change_request.default_response_subject). @@ -267,5 +247,4 @@ expect(change_request.default_response_subject). to eq("Re: Update email address - #{public_body.name}") end - end diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb index 5044d412fd..8f6459717a 100644 --- a/spec/models/public_body_heading_spec.rb +++ b/spec/models/public_body_heading_spec.rb @@ -13,9 +13,7 @@ require 'spec_helper' RSpec.describe PublicBodyHeading do - context 'when validating' do - it 'should require a name' do heading = PublicBodyHeading.new expect(heading).not_to be_valid @@ -40,11 +38,9 @@ translation = heading.translations.build expect(heading).to_not be_valid end - end context 'when setting a display order' do - it 'should return 0 if there are no public body headings' do PublicBodyHeading.destroy_all expect(PublicBodyHeading.next_display_order).to eq(0) @@ -58,7 +54,6 @@ end describe :save do - it 'saves translations' do heading = FactoryBot.build(:public_body_heading) heading.translations_attributes = { es: { locale: 'es', @@ -67,13 +62,10 @@ heading.save! expect(PublicBodyHeading.find(heading.id).translations.size).to eq(2) end - end describe :translations_attributes= do - context 'translation_attrs is a Hash' do - it 'does not persist translations' do heading = FactoryBot.create(:public_body_heading) heading.translations_attributes = { es: { locale: 'es', @@ -149,7 +141,6 @@ end RSpec.describe PublicBodyHeading::Translation do - it 'requires a locale' do translation = PublicBodyHeading::Translation.new translation.valid? @@ -162,5 +153,4 @@ ) expect(translation).to be_valid end - end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 562cdc4eac..1ad829c811 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -171,7 +171,6 @@ end describe '.with_query' do - it 'should return authorities starting with a multibyte first letter' do authority = FactoryBot.create(:public_body, name: 'Åčçèñtéd Authority') department = FactoryBot.create(:public_body, name: 'Åčçèñtéd Department') @@ -193,7 +192,6 @@ public_bodies(:forlorn_public_body) ]) end - end describe '.cached_urls' do @@ -282,7 +280,6 @@ end describe '#name' do - it 'is invalid when nil' do subject = described_class.new(name: nil) subject.valid? @@ -301,11 +298,9 @@ subject.valid? expect(subject.errors[:name]).to eq(["Name is already taken"]) end - end describe '#short_name' do - it 'is invalid when not unique' do existing = FactoryBot.create(:public_body, short_name: 'xyz') subject = described_class.new(short_name: existing.short_name) @@ -318,11 +313,9 @@ subject.valid? expect(subject.errors[:short_name]).to be_empty end - end describe '#request_email' do - it 'is invalid when nil' do subject = described_class.new(request_email: nil) subject.valid? @@ -331,7 +324,6 @@ end context "when the email is set" do - subject(:public_body) do FactoryBot.build(:public_body, request_email: "request@example.com") @@ -347,11 +339,9 @@ and_return("tester@example.com") expect(public_body.request_email).to eq("tester@example.com") end - end context "when no email is set" do - subject(:public_body) do FactoryBot.build(:public_body, request_email: "") end @@ -366,7 +356,6 @@ and_return("tester@example.com") expect(public_body.request_email).to be_blank end - end it 'is invalid with an unrequestable email' do @@ -381,21 +370,17 @@ subject.valid? expect(subject.errors[:request_email]).to be_empty end - end describe '#version' do - it 'ignores manually set attributes' do subject = FactoryBot.build(:public_body, version: 21) subject.save! expect(subject.version).to eq(1) end - end describe '#url_name' do - it 'is invalid when nil' do subject = PublicBody.new(url_name: nil) subject.valid? @@ -426,7 +411,6 @@ end context 'short_name has not been set' do - it 'updates the url_name when name is changed' do subject = PublicBody.new subject.name = 'Some Authority' @@ -438,11 +422,9 @@ subject.name = '1234' expect(subject.url_name).to eq('body') end - end context 'short_name has been set' do - it 'does not update the url_name when name is changed' do subject = PublicBody.new(short_name: 'Test Name') subject.name = 'Some Authority' @@ -454,13 +436,10 @@ subject.short_name = 'Short Name' expect(subject.url_name).to eq('short_name') end - end - end describe '#first_letter' do - it 'is empty on initialization' do subject = FactoryBot.build(:public_body) expect(subject.first_letter).to be_nil @@ -504,11 +483,9 @@ expect(subject.first_letter).to eq('B') end end - end describe '#api_key' do - it 'is empty on initialization' do subject = FactoryBot.build(:public_body) expect(subject.api_key).to be_nil @@ -526,11 +503,9 @@ subject.save! expect(subject.api_key).to eq(existing) end - end describe '#last_edit_editor' do - it 'is invalid when nil' do subject = PublicBody.new(last_edit_editor: nil) subject.valid? @@ -557,11 +532,9 @@ subject.valid? expect(subject.errors[:last_edit_editor]).to be_empty end - end describe '#last_edit_comment' do - it 'is valid when nil' do subject = PublicBody.new(last_edit_comment: nil) subject.valid? @@ -572,11 +545,9 @@ subject = FactoryBot.create(:public_body, last_edit_comment: '') expect(subject.last_edit_comment).to be_nil end - end describe '#home_page' do - it 'is valid when nil' do subject = PublicBody.new(home_page: nil) subject.valid? @@ -587,7 +558,6 @@ subject = FactoryBot.create(:public_body, home_page: '') expect(subject.home_page).to be_nil end - end describe '#notes' do @@ -638,7 +608,6 @@ end describe '#has_notes?' do - subject { public_body.has_notes? } let(:public_body) { PublicBody.new } @@ -656,11 +625,9 @@ allow(public_body).to receive(:notes).and_return([double(:note)]) is_expected.to eq(true) end - end describe '#publication_scheme' do - it 'is valid when nil' do subject = PublicBody.new(publication_scheme: nil) subject.valid? @@ -671,11 +638,9 @@ subject = FactoryBot.create(:public_body, publication_scheme: '') expect(subject.publication_scheme).to be_nil end - end describe '#disclosure_log' do - it 'is valid when nil' do subject = PublicBody.new(disclosure_log: nil) subject.valid? @@ -686,13 +651,10 @@ subject = FactoryBot.create(:public_body, disclosure_log: '') expect(subject.disclosure_log).to be_nil end - end describe '#translations_attributes=' do - context 'translation_attrs is a Hash' do - it 'does not persist translations' do body = FactoryBot.create(:public_body) body.translations_attributes = { es: { locale: 'es', @@ -767,7 +729,6 @@ end describe '#set_api_key' do - it 'generates and sets an API key' do allow(SecureRandom).to receive(:base64).and_return('APIKEY') body = PublicBody.new @@ -781,11 +742,9 @@ body.set_api_key expect(body.api_key).to eq('EXISTING') end - end describe '#set_api_key!' do - it 'generates and sets an API key' do allow(SecureRandom).to receive(:base64).and_return('APIKEY') body = PublicBody.new @@ -799,7 +758,6 @@ body.set_api_key! expect(body.api_key).to eq('APIKEY') end - end describe '#expire_requests' do @@ -812,7 +770,6 @@ end describe '#short_or_long_name' do - it 'returns the short_name if it has been set' do public_body = PublicBody.new(name: 'Test Name', short_name: "Test") expect(public_body.short_or_long_name).to eq('Test') @@ -822,11 +779,9 @@ public_body = PublicBody.new(name: 'Test Name') expect(public_body.short_or_long_name).to eq('Test Name') end - end describe '#set_first_letter' do - it 'sets first_letter to the first letter of the name if the name is set' do public_body = PublicBody.new(name: 'Test Name') public_body.set_first_letter @@ -850,11 +805,9 @@ public_body.set_first_letter expect(public_body.first_letter).to eq('Å') end - end describe '#not_subject_to_law?' do - it 'returns true if tagged with "foi_no"' do public_body = FactoryBot.build(:public_body, tag_string: 'foi_no') @@ -872,11 +825,9 @@ public_body = FactoryBot.build(:public_body) expect(public_body.not_subject_to_law?).to eq true end - end describe ".internal_admin_body" do - before(:each) do InfoRequest.destroy_all PublicBody.destroy_all @@ -918,31 +869,26 @@ expect(found_iab).to eq(iab) end end - end describe '.localized_csv_field_name' do - it 'returns the field name if passed the default_locale' do expect(PublicBody.localized_csv_field_name(:en, "first_letter")). to eq("first_letter") end context 'the default_locale contains an underscore' do - it 'returns the field name if passed the default_locale' do AlaveteliLocalization.set_locales('en_GB es', 'en_GB') expect(PublicBody.localized_csv_field_name(:en_GB, "first_letter")). to eq("first_letter") end - end it 'returns appends the locale name if passed a non default locale' do expect(PublicBody.localized_csv_field_name(:es, "first_letter")). to eq("first_letter.es") end - end describe '.without_request_email' do @@ -973,7 +919,6 @@ end is_expected.to include(blank_body) end - end describe '.with_request_email' do @@ -989,7 +934,6 @@ it 'does not include bodies with an empty request email' do is_expected.to_not include(blank_body) end - end describe 'when generating json for the api' do @@ -1035,9 +979,7 @@ } }) end - end - end RSpec.describe PublicBody, " using tags" do @@ -1135,7 +1077,6 @@ end RSpec.describe PublicBody, "when finding_by_tags" do - before do @geraldine = public_bodies(:geraldine_public_body) @geraldine.tag_string = 'rabbit' @@ -1271,7 +1212,6 @@ def set_default_attributes(public_body) end RSpec.describe PublicBody, "when searching" do - it "should find by existing url name" do body = PublicBody.find_by_url_name_with_historic('dfh') expect(body.id).to eq(3) @@ -1367,7 +1307,6 @@ def set_default_attributes(public_body) public_body.reload expect { public_body.destroy }.to raise_error(ActiveRecord::InvalidForeignKey) end - end RSpec.describe PublicBody, " when loading CSV files" do @@ -1499,11 +1438,8 @@ def set_default_attributes(public_body) expect(PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search).to eq(%w[aTag fake]) end - context 'when the import tag is set' do - context 'with a new body' do - it 'appends the import tag when no tag_string is specified' do csv = <<-CSV.strip_heredoc #id,request_email,name,tag_string,home_page @@ -1555,11 +1491,9 @@ def set_default_attributes(public_body) expected = %w(first_tag imported second_tag) expect(PublicBody.find_by_name('Quango').tag_array_for_search).to eq(expected) end - end context 'an existing body without tags' do - before do @body = FactoryBot.create(:public_body, name: 'Existing Body') end @@ -1576,11 +1510,9 @@ def set_default_attributes(public_body) expected = %w(imported) expect(errors).to include("error: line 2: Name Name is already taken for authority 'Existing Body'") end - end context 'an existing body with tags' do - before do @body = FactoryBot.create(:public_body, tag_string: 'imported first_tag second_tag') end @@ -1609,15 +1541,11 @@ def set_default_attributes(public_body) expected = %w(first_tag imported new_tag) expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected) end - end - end context 'when the import tag is not set' do - context 'with a new body' do - it 'it is empty if no tag_string is set' do csv = <<-CSV.strip_heredoc #id,request_email,name,tag_string,home_page @@ -1669,11 +1597,9 @@ def set_default_attributes(public_body) expected = %w(first_tag) expect(PublicBody.find_by_name('Quango').tag_array_for_search).to eq(expected) end - end context 'with an existing body without tags' do - before do @body = FactoryBot.create(:public_body) end @@ -1729,11 +1655,9 @@ def set_default_attributes(public_body) expected = %w(new_tag) expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected) end - end describe 'with an existing body with tags' do - before do @body = FactoryBot.create(:public_body, tag_string: 'first_tag second_tag') end @@ -1763,9 +1687,7 @@ def set_default_attributes(public_body) expected = %w(first_tag new_tag) expect(PublicBody.find(@body.id).tag_array_for_search).to eq(expected) end - end - end it "should create bodies with names in multiple locales" do @@ -1815,7 +1737,6 @@ def set_default_attributes(public_body) end context 'when importing data from a CSV' do - before do InfoRequest.destroy_all PublicBody.destroy_all @@ -1853,7 +1774,6 @@ def set_default_attributes(public_body) locale ).to eq(:en_GB) end - end it "should handle active record validation errors" do @@ -2024,7 +1944,6 @@ def set_default_attributes(public_body) end describe '#site_administration?' do - it 'is true when the body has the site_administration tag' do p = FactoryBot.build(:public_body, tag_string: 'site_administration') expect(p.site_administration?).to be true @@ -2034,11 +1953,9 @@ def set_default_attributes(public_body) p = FactoryBot.build(:public_body) expect(p.site_administration?).to be false end - end describe '#has_request_email?' do - before do @body = PublicBody.new(request_email: 'test@example.com') end @@ -2064,7 +1981,6 @@ def set_default_attributes(public_body) end describe '#special_not_requestable_reason' do - before do @body = PublicBody.new end @@ -2083,7 +1999,6 @@ def set_default_attributes(public_body) expect(@body.special_not_requestable_reason?).to eq(false) end end - end RSpec.describe PublicBody, " when override all public body request emails set" do @@ -2167,11 +2082,9 @@ def set_default_attributes(public_body) hpb.tag_string = original_tag_string end end - end RSpec.describe PublicBody, 'when asked for popular bodies' do - it 'should return bodies correctly when passed the hyphenated version of the locale' do allow(AlaveteliConfiguration).to receive(:frontpage_publicbody_examples).and_return('') expect(PublicBody.popular_bodies('he-IL')).to eq([public_bodies(:humpadink_public_body)]) @@ -2181,11 +2094,9 @@ def set_default_attributes(public_body) allow(AlaveteliConfiguration).to receive(:frontpage_publicbody_examples).and_return('tgq') expect(PublicBody.popular_bodies('en')).to eq([public_bodies(:geraldine_public_body)]) end - end RSpec.describe PublicBody do - describe '.foi_applies' do subject { PublicBody.foi_applies } @@ -2199,7 +2110,6 @@ def set_default_attributes(public_body) it 'does not include bodies where FOI/EIR is not applicable' do is_expected.to_not include(not_apply_body) end - end describe '.not_defunct' do @@ -2215,11 +2125,9 @@ def set_default_attributes(public_body) it 'does not include defunct bodies' do is_expected.to_not include(defunct_body) end - end describe '#is_requestable?' do - before do @body = PublicBody.new(request_email: 'test@example.com') end @@ -2247,7 +2155,6 @@ def set_default_attributes(public_body) it 'should return true if the request email is an email address' do expect(@body.is_requestable?).to eq(true) end - end describe '.is_requestable' do @@ -2273,11 +2180,9 @@ def set_default_attributes(public_body) it 'does not include bodies where FOI/EIR is not applicable' do is_expected.to_not include(not_apply_body) end - end describe '#is_followupable?' do - before do @body = PublicBody.new(request_email: 'test@example.com') end @@ -2290,11 +2195,9 @@ def set_default_attributes(public_body) it 'should return true if the request email is an email address' do expect(@body.is_followupable?).to eq(true) end - end describe '#not_requestable_reason' do - before do @body = PublicBody.new(request_email: 'test@example.com') end @@ -2309,7 +2212,6 @@ def set_default_attributes(public_body) expect(@body.not_requestable_reason).to eq('not_apply') end - it 'should return "bad_contact" there is no request_email' do allow(@body).to receive(:has_request_email?).and_return false expect(@body.not_requestable_reason).to eq('bad_contact') @@ -2319,7 +2221,6 @@ def set_default_attributes(public_body) expected_error = "not_requestable_reason called with type that has no reason" expect { @body.not_requestable_reason }.to raise_error(expected_error) end - end describe '#update_counter_cache' do @@ -2445,7 +2346,6 @@ def set_default_attributes(public_body) end RSpec.describe PublicBody::Translation do - it 'requires a locale' do translation = PublicBody::Translation.new translation.valid? @@ -2458,38 +2358,30 @@ def set_default_attributes(public_body) ) expect(translation).to be_valid end - end RSpec.describe PublicBody::Version do let(:public_body) { FactoryBot.create(:public_body) } describe '#compare' do - describe 'when no block is given' do - describe 'when there is no other version' do - it 'returns an empty list' do current = public_body.versions.latest expect(current.compare(current.previous)).to eq([]) end - end describe 'when there are no significant changes' do - it 'returns an empty list' do public_body.last_edit_comment = 'Just tinkering' public_body.save! current = public_body.versions.latest expect(current.compare(current.previous)).to eq([]) end - end describe 'when there are significant changes' do - it 'returns a list of changes as hashes with keys :name, :from and :to' do public_body.request_email = 'new@example.com' @@ -2500,25 +2392,19 @@ def set_default_attributes(public_body) to: "new@example.com" } expect(current.compare(current.previous)).to eq([ expected ]) end - end - end describe 'when no block is given' do - describe 'when there is no other version' do - it 'does not yield' do current = public_body.versions.latest expect { |b| current.compare(current.previous, &b) }. not_to yield_control end - end describe 'when there are no significant changes' do - it 'returns an empty list' do public_body.last_edit_comment = 'Just tinkering' public_body.save! @@ -2526,11 +2412,9 @@ def set_default_attributes(public_body) expect { |b| current.compare(current.previous, &b) }. not_to yield_control end - end describe 'when there are significant changes' do - it 'returns a list of changes as hashes with keys :name, :from and :to' do public_body.request_email = 'new@example.com' @@ -2542,11 +2426,8 @@ def set_default_attributes(public_body) expect { |b| current.compare(current.previous, &b) }. to yield_with_args(expected) end - end - end - end describe '#editor' do diff --git a/spec/models/raw_email_spec.rb b/spec/models/raw_email_spec.rb index bcd0829eb8..057b18e855 100644 --- a/spec/models/raw_email_spec.rb +++ b/spec/models/raw_email_spec.rb @@ -11,7 +11,6 @@ require 'spec_helper' RSpec.describe RawEmail do - def roundtrip_data(raw_email, data) raw_email.data = data raw_email.save! @@ -131,7 +130,6 @@ def test_real(fixture_file, expected) allow(raw_email).to receive(:mail!).and_return(double('updated')) expect(raw_email.mail).to eq(initial) end - end describe '#mail!' do @@ -169,7 +167,6 @@ def test_real(fixture_file, expected) # version, _not_ the initial cache expect(raw_email.mail).to eq(updated) end - end describe '#data' do @@ -191,7 +188,6 @@ def test_real(fixture_file, expected) end describe '#data_as_text' do - it 'returns a utf-8 string with a valid encoding if the data is non-ascii and non-utf8' do raw_email = FactoryBot.create(:incoming_message).raw_email roundtrip_data(raw_email, "\xA0ccc") @@ -200,7 +196,6 @@ def test_real(fixture_file, expected) expect(data_as_text.encoding.to_s).to eq('UTF-8') expect(data_as_text.valid_encoding?).to be true end - end describe '#from_email_domain' do diff --git a/spec/models/request_classification_spec.rb b/spec/models/request_classification_spec.rb index dc47199167..04475a4730 100644 --- a/spec/models/request_classification_spec.rb +++ b/spec/models/request_classification_spec.rb @@ -13,9 +13,7 @@ require 'spec_helper' RSpec.describe RequestClassification do - describe '.league_table' do - before do @user_one = FactoryBot.create(:user) @user_two = FactoryBot.create(:user) @@ -48,7 +46,5 @@ expect(league_table.first.user_id).to eq(@user_two.id) expect(league_table.first.cnt).to eq(1) end - end - end diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 6ca880e350..ad81f8f82a 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -14,7 +14,6 @@ require 'spec_helper' RSpec.describe Role do - it 'validates the role name is in the allowed roles' do role = Role.new(name: 'test') role.valid? @@ -30,43 +29,32 @@ end describe '.admin_role' do - it 'returns role with name admin' do expect(Role.admin_role.name).to eq 'admin' end - end describe '.pro_role' do - it 'returns role with name pro' do expect(Role.pro_role.name).to eq 'pro' end - end describe '.grantable_roles' do - context 'when alaveteli_pro feature is disabled' do - it 'returns an array [:admin]' do expect(Role.grantable_roles).to match_array %i[admin] end - end context 'when alaveteli_pro feature is enabled', feature: :alaveteli_pro do - it 'returns an array [:admin, :pro, :pro_admin]' do expect(Role.grantable_roles).to match_array %i[pro admin pro_admin] end - end - end describe '.grants_and_revokes' do - it 'returns an array [:admin] when passed :admin' do expect(Role.grants_and_revokes(:admin)) .to eq([:admin]) @@ -81,11 +69,9 @@ it 'returns an empty array when passed :pro' do expect(Role.grants_and_revokes(:pro)).to eq([]) end - end describe '.requires' do - it 'returns an empty array when passed :admin' do expect(Role.requires(:admin)).to eq([]) end @@ -97,7 +83,5 @@ it 'returns an empty array when passed :pro' do expect(Role.requires(:pro)).to eq([]) end - end - end diff --git a/spec/models/spam_address_spec.rb b/spec/models/spam_address_spec.rb index fdc744b668..38f34d269e 100644 --- a/spec/models/spam_address_spec.rb +++ b/spec/models/spam_address_spec.rb @@ -15,7 +15,6 @@ it { is_expected.to strip_attribute(:email) } describe '.new' do - it 'requres an email address' do expect(SpamAddress.new).not_to be_valid expect(SpamAddress.new(email: 'spam@example.org')).to be_valid @@ -25,11 +24,9 @@ existing = FactoryBot.create(:spam_address) expect(SpamAddress.new(email: existing.email)).not_to be_valid end - end describe '.spam?' do - before(:each) do @spam_address = FactoryBot.create(:spam_address) end @@ -51,7 +48,6 @@ end describe 'when accepting an array of emails' do - it 'is spam if any of the emails are stored' do emails = ['genuine-email@example.com', @spam_address.email.swapcase] expect(SpamAddress.spam?(emails)).to be true @@ -61,9 +57,7 @@ emails = ['genuine-email@example.com', 'genuine-email@example.org'] expect(SpamAddress.spam?(emails)).to be false end - end - end describe '#save' do diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 8a70ca0426..010ba18f27 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -18,7 +18,6 @@ require 'spec_helper' RSpec.describe TrackThing, "when tracking changes" do - before do @track_thing = track_things(:track_fancy_dog_search) end diff --git a/spec/models/user/transaction_calculator_spec.rb b/spec/models/user/transaction_calculator_spec.rb index 390a43cf11..d7c06da27f 100644 --- a/spec/models/user/transaction_calculator_spec.rb +++ b/spec/models/user/transaction_calculator_spec.rb @@ -1,13 +1,11 @@ require 'spec_helper' RSpec.describe User::TransactionCalculator do - let(:user) { FactoryBot.create(:user) } subject { described_class.new(user) } describe '.new' do - it 'requires a User' do expect { described_class.new }.to raise_error(ArgumentError) end @@ -29,21 +27,16 @@ described_class.new(user, transaction_associations: list) }.to raise_error(NoMethodError) end - end describe '#user' do - it 'returns the User' do expect(subject.user).to eq(user) end - end describe '#total' do - context 'with no arguments' do - it 'sums the total transactions made by the user' do 3.times do FactoryBot.create(:comment, user: user) @@ -51,11 +44,9 @@ end expect(subject.total).to eq(6) end - end context 'with a Range argument' do - it 'sums the total transactions made by the user during the range' do travel_to(1.year.ago) do FactoryBot.create(:comment, user: user) @@ -71,11 +62,9 @@ expect(subject.total(10.days.ago..1.day.ago)).to eq(2) end - end context 'with a Symbol argument' do - it ':last_7_days sums the total transactions made by the user in the last 7 days' do travel_to(8.days.ago) do FactoryBot.create(:comment, user: user) @@ -140,11 +129,9 @@ expect { subject.total('invalid argument') }. to raise_error(ArgumentError, "Invalid argument `invalid argument'") end - end describe '#total_per_month' do - it 'returns a hash containing the total transactions grouped by month' do travel_to(Time.zone.parse('2016-01-05')) do FactoryBot.create(:comment, user: user) @@ -165,11 +152,9 @@ expect(subject.total_per_month). to eq({ '2016-01-01' => 3, '2016-03-01' => 1 }) end - end describe '#average_per_month' do - it 'returns the average transactions per month' do travel_to(Time.zone.parse('2016-01-01')) user = FactoryBot.create(:user) @@ -189,11 +174,9 @@ expect(subject.average_per_month).to eq(1.5) end end - end describe '#==' do - it 'returns true if the user and transactions are equal' do expect(described_class.new(user)).to eq(described_class.new(user)) end @@ -217,7 +200,5 @@ calc2 = described_class.new(user, transaction_associations: list2) expect(calc1).not_to eq(calc2) end - end - end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4015e312cb..79838268a5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -64,7 +64,6 @@ end RSpec.describe User, "banning the user" do - it 'does not change the URL name' do user = FactoryBot.create(:user, name: 'nasty user 123') user.update(ban_text: 'You are banned') @@ -81,7 +80,6 @@ user = FactoryBot.build(:user, name: 'nasty user', ban_text: 'banned') expect(user.name).to eq('nasty user (Account suspended)') end - end RSpec.describe User, "showing the name" do @@ -95,7 +93,6 @@ end describe 'if user has been banned' do - before do @user.ban_text = "Naughty user" end @@ -103,10 +100,7 @@ it 'should show an "Account suspended" suffix' do expect(@user.name).to eq('Some Name (Account suspended)') end - end - - end RSpec.describe User, 'password hashing algorithms' do @@ -145,7 +139,6 @@ def create_user(options = {}) it 'returns user in sha1 scope' do expect(User.sha1).to include user end - end context 'short password hashed with SHA1' do @@ -174,7 +167,6 @@ def create_user(options = {}) it 'returns user in sha1 scope' do expect(User.sha1).to include user end - end context 'password hashed with SHA1 and then bcrypt' do @@ -202,7 +194,6 @@ def create_user(options = {}) it 'does not return user in sha1 scope' do expect(User.sha1).to_not include user end - end context 'password hashed with bcrypt' do @@ -222,9 +213,7 @@ def create_user(options = {}) it 'does not return user in sha1 scope' do expect(User.sha1).to_not include user end - end - end RSpec.describe User, 'when saving' do @@ -365,10 +354,8 @@ def create_user(options = {}) expect(@user).not_to receive(:xapian_mark_needs_index) @user.save! end - end - RSpec.describe User, "when reindexing referencing models" do let(:user) { FactoryBot.create(:user) } let!(:comment) { FactoryBot.create(:comment, :with_event, user: user) } @@ -423,7 +410,6 @@ def create_user(options = {}) end RSpec.describe User, "when checking abilities" do - before do @user = users(:bob_smith_user) end @@ -435,7 +421,6 @@ def create_user(options = {}) it "should be able to file requests" do expect(@user.can_file_requests?).to be true end - end RSpec.describe User, 'previous names' do @@ -537,7 +522,6 @@ def create_user(options = {}) end RSpec.describe User, '#should_be_emailed?' do - context 'when confirmed and active' do let(:user) { FactoryBot.build(:user) } before { allow(user).to receive(:active?).and_return(true) } @@ -581,11 +565,9 @@ def create_user(options = {}) expect(user).to_not be_should_be_emailed end end - end RSpec.describe User, "when emails have bounced" do - it "should record bounces" do User.record_bounce_for_email("bob@localhost", "A bounce message") @@ -599,7 +581,6 @@ def create_user(options = {}) user = User.find_user_by_email("bob@localhost") expect(user.email_bounce_message).to eq("Invalid utf-8 –") end - end RSpec.describe User do @@ -695,11 +676,9 @@ def create_user(options = {}) expect(found_user.errors.size).to eq(0) expect(found_user).to eq(full_user) end - end describe '.stay_logged_in_on_redirect?' do - it 'is false if the user is nil' do expect(User.stay_logged_in_on_redirect?(nil)).to be_falsey end @@ -713,7 +692,6 @@ def create_user(options = {}) user = double(is_admin?: false) expect(User.stay_logged_in_on_redirect?(user)).to eq(false) end - end describe '#sign_ins' do @@ -754,7 +732,6 @@ def create_user(options = {}) end describe '#transactions' do - it 'returns a TransactionCalculator with the default transaction set' do user = User.new expect(user.transactions).to eq(User::TransactionCalculator.new(user)) @@ -767,21 +744,17 @@ def create_user(options = {}) new(user, transaction_associations: [:comments, :info_requests]) expect(user.transactions(:comments, :info_requests)).to eq(calculator) end - end describe '#password=' do - it 'creates a hashed password when the password is set' do expect(subject.hashed_password).to be_nil subject.password = "a test password" expect(subject.hashed_password).not_to be_nil end - end describe '#destroy' do - let(:user) { FactoryBot.create(:user) } it 'destroys any associated info_requests' do @@ -848,7 +821,6 @@ def create_user(options = {}) expect(RequestClassification.where(id: request_classification.id)) .to be_empty end - end describe '#expire_requests' do @@ -878,9 +850,7 @@ def create_user(options = {}) end describe '#valid?' do - context 'with require_otp' do - it 'has no effect when otp is disabled' do user = FactoryBot.build(:user) user.enable_otp @@ -933,24 +903,19 @@ def create_user(options = {}) user.valid? expect(user.otp_counter).to eq(counter + 1) end - end context 'with otp disabled' do - it 'is valid with any otp' do user = FactoryBot.build(:user) user.disable_otp user.entered_otp_code = 'invalid' expect(user.valid?).to eq(true) end - end - end describe '#otp_enabled' do - it 'defaults to false' do user = User.new expect(user.otp_enabled).to eq(false) @@ -966,11 +931,9 @@ def create_user(options = {}) user.otp_enabled = true expect(user.otp_enabled).to eq(true) end - end describe '#otp_enabled?' do - it 'requires an otp_secret_key to be enabled' do attrs = { otp_enabled: true, otp_secret_key: nil, @@ -1002,11 +965,9 @@ def create_user(options = {}) user = User.new(attrs) expect(user.otp_enabled?).to eq(true) end - end describe '#enable_otp' do - it 'resets the otp_counter' do user = User.new(otp_counter: 200) user.enable_otp @@ -1029,11 +990,9 @@ def create_user(options = {}) user = User.new expect(user.enable_otp).to eq(true) end - end describe '#disable_otp' do - it 'sets otp_enabled to false' do user = User.new(otp_enabled: true) user.disable_otp @@ -1051,11 +1010,9 @@ def create_user(options = {}) user = User.new expect(user.disable_otp).to eq(true) end - end describe '#require_otp?' do - it 'is false by default' do user = User.new expect(user.require_otp?).to eq(false) @@ -1065,11 +1022,9 @@ def create_user(options = {}) user = User.new(require_otp: true) expect(user.require_otp?).to eq(true) end - end describe '#require_otp=' do - it 'assigns true for a truthy value' do user = User.new user.require_otp = 'yes' @@ -1081,11 +1036,9 @@ def create_user(options = {}) user.require_otp = nil expect(user.require_otp?).to eq(false) end - end describe '#otp_counter' do - it 'defaults to 1' do user = User.new expect(user.otp_counter).to eq(1) @@ -1101,11 +1054,9 @@ def create_user(options = {}) user.otp_counter = 200 expect(user.otp_counter).to eq(200) end - end describe '#otp_secret_key' do - it 'can be set on initialization' do key = User.otp_random_secret user = User.new(otp_secret_key: key) @@ -1118,30 +1069,24 @@ def create_user(options = {}) user.otp_secret_key = key expect(user.otp_secret_key).to eq(key) end - end describe '#entered_otp_code' do - it 'gets the virtual attribue for use in validation' do user = User.new(entered_otp_code: '123456') expect(user.entered_otp_code).to eq('123456') end - end describe '#entered_otp_code=' do - it 'sets the virtual attribue for use in validation' do user = User.new user.entered_otp_code = '123456' expect(user.entered_otp_code).to eq('123456') end - end describe '#banned?' do - it 'is banned if the user has ban_text' do user = FactoryBot.build(:user, ban_text: 'banned') expect(user).to be_banned @@ -1151,7 +1096,6 @@ def create_user(options = {}) user = FactoryBot.build(:user, ban_text: '') expect(user).to_not be_banned end - end describe '#close_and_anonymise' do @@ -1241,7 +1185,6 @@ def create_user(options = {}) user.closed_at = nil expect(user).to_not be_closed end - end describe '#erase' do @@ -1424,25 +1367,21 @@ def create_user(options = {}) end describe '.closed' do - it 'should not return users with closed_at timestamp' do active_user = FactoryBot.create(:user) user = FactoryBot.create(:user, closed_at: Time.zone.now) expect(User.closed).to_not include(active_user) expect(User.closed).to include(user) end - end describe '.not_closed' do - it 'should return users with closed_at timestamp' do active_user = FactoryBot.create(:user) user = FactoryBot.create(:user, closed_at: Time.zone.now) expect(User.not_closed).to include(active_user) expect(User.not_closed).to_not include(user) end - end describe '#active?' do @@ -1463,7 +1402,6 @@ def create_user(options = {}) allow(user).to receive(:closed?).and_return(true) expect(user).to_not be_active end - end describe '#suspended?' do @@ -1484,7 +1422,6 @@ def create_user(options = {}) allow(user).to receive(:closed?).and_return(true) expect(user).to be_suspended end - end describe '#prominence' do @@ -1517,7 +1454,6 @@ def create_user(options = {}) end describe '.active' do - it 'should not return banned users' do active_user = FactoryBot.create(:user) user = FactoryBot.create(:user, ban_text: 'banned') @@ -1531,33 +1467,27 @@ def create_user(options = {}) expect(User.active).to include(active_user) expect(User.active).to_not include(user) end - end describe '.banned' do - it 'should return banned users' do active_user = FactoryBot.create(:user) user = FactoryBot.create(:user, ban_text: 'banned') expect(User.banned).to_not include(active_user) expect(User.banned).to include(user) end - end describe '.not_banned' do - it 'should not return banned users' do active_user = FactoryBot.create(:user) user = FactoryBot.create(:user, ban_text: 'banned') expect(User.not_banned).to include(active_user) expect(User.not_banned).not_to include(user) end - end describe '#confirm' do - it 'confirms an unconfirmed user' do user = FactoryBot.build(:user, email_confirmed: false) user.confirm @@ -1581,11 +1511,9 @@ def create_user(options = {}) user.confirm(true) expect(user).to be_persisted end - end describe '#confirm!' do - it 'confirms an unconfirmed user' do user = FactoryBot.build(:user, email_confirmed: false) user.confirm! @@ -1608,11 +1536,9 @@ def create_user(options = {}) user = FactoryBot.build(:user, email: nil, email_confirmed: false) expect { user.confirm! }.to raise_error(ActiveRecord::RecordInvalid) end - end describe '.find_user_by_email' do - it 'finds a user by email case-insensitively' do user = FactoryBot.create(:user) expect(User.find_user_by_email(user.email.upcase)).to eq(user) @@ -1634,11 +1560,9 @@ def create_user(options = {}) user = FactoryBot.create(:user) expect(User.find_user_by_email(" #{user.email} ")).to eq(user) end - end describe '#about_me_already_exists?' do - it 'is true if the about_me text already exists for another user' do FactoryBot.create(:user, about_me: '123') user = FactoryBot.build(:user, about_me: '123') @@ -1662,11 +1586,9 @@ def create_user(options = {}) user = FactoryBot.create(:user, about_me: '123') expect(user.about_me_already_exists?).to eq(false) end - end describe '#indexed_by_search?' do - it 'is false if the user is unconfirmed' do user = User.new(email_confirmed: false, ban_text: '') expect(user.indexed_by_search?).to eq(false) @@ -1681,11 +1603,9 @@ def create_user(options = {}) user = User.new(email_confirmed: true, ban_text: '') expect(user.indexed_by_search?).to eq(true) end - end describe '#can_admin_roles' do - it 'returns an array including the admin and roles for an admin user' do admin_user = FactoryBot.create(:admin_user) expect(admin_user.can_admin_roles).to eq([:admin]) @@ -1700,7 +1620,6 @@ def create_user(options = {}) pro_user = FactoryBot.create(:pro_user) expect(pro_user.can_admin_roles).to eq([]) end - end describe '#can_admin_role?' do @@ -2010,49 +1929,39 @@ def create_user(options = {}) end describe 'role callbacks' do - let(:user) { FactoryBot.build(:user) } context 'adding unknown role' do - it 'enables user role features' do features = double(:features) allow(user).to receive(:features).and_return(features) expect(features).to receive(:assign_role_features) user.add_role(:unknown) end - end context 'adding pro role' do - it 'enables user role features' do features = double(:features) allow(user).to receive(:features).and_return(features) expect(features).to receive(:assign_role_features) user.add_role(:pro) end - end context 'with pro pricing enabled', feature: :pro_pricing do - it 'creates pro account when pro role added' do expect { user.add_role :pro }.to change(user, :pro_account). from(nil).to(ProAccount) end - end context 'without pro pricing enabled' do - it 'does not create pro account when pro role is added' do expect { user.add_role :pro }.to_not change(user, :pro_account). from(nil) end - end - end describe 'update callbacks' do @@ -2070,7 +1979,6 @@ def create_user(options = {}) user.run_callbacks :update end end - end describe '#show_profile_photo?' do diff --git a/spec/models/widget_vote_spec.rb b/spec/models/widget_vote_spec.rb index faa2f6da65..7b22ce8b65 100644 --- a/spec/models/widget_vote_spec.rb +++ b/spec/models/widget_vote_spec.rb @@ -13,9 +13,7 @@ require 'spec_helper' RSpec.describe WidgetVote do - describe '.new' do - it 'requires an info request' do widget_vote = WidgetVote.new expect(widget_vote).not_to be_valid @@ -48,7 +46,5 @@ second_request_vote = second_info_request.widget_votes.build(cookie: 'x' * 20) expect(second_request_vote).to be_valid end - end - end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 3c46c33e9c..0db3a04921 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe User, " when indexing users with Xapian" do - before(:each) do load_raw_emails_data update_xapian_index @@ -62,11 +61,9 @@ xapian_object = ActsAsXapian::Search.new([PublicBody], "lonely", limit: 100) expect(xapian_object.results).to eq([]) end - end RSpec.describe PublicBody, " when indexing requests by body they are to" do - include ActiveJob::TestHelper before(:each) do @@ -430,7 +427,6 @@ end RSpec.describe InfoRequestEvent, " when faced with a race condition during xapian_mark_needs_index" do - before(:each) do load_raw_emails_data update_xapian_index @@ -442,5 +438,4 @@ ir.reindex_request_events end end - end diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb index ec53a15850..5a54d232d0 100644 --- a/spec/script/handle-mail-replies_spec.rb +++ b/spec/script/handle-mail-replies_spec.rb @@ -12,9 +12,7 @@ def mail_reply_test(email_filename) end RSpec.describe "When filtering" do - describe "when not in test mode" do - it "should not fail handling a bounce mail" do xc = ExternalCommand.new("script/handle-mail-replies", { stdin_string: load_file_fixture("track-response-exim-bounce.email") diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb index 420542f8bc..c76a11d973 100644 --- a/spec/script/mailin_spec.rb +++ b/spec/script/mailin_spec.rb @@ -3,7 +3,6 @@ def mailin_test(email_filename) Dir.chdir Rails.root do - mail = load_file_fixture(email_filename) ir = info_requests(:other_request) mail.gsub!('EMAIL_TO', ir.incoming_email) @@ -15,7 +14,6 @@ def mailin_test(email_filename) end RSpec.describe "When importing mail into the application" do - # Turn off transactional fixtures for this suite - incoming message is imported # outside the transaction via ExternalCommand, so needs to be destroyed outside the # transaction @@ -33,5 +31,4 @@ def mailin_test(email_filename) incoming_message = ir.incoming_messages[0] incoming_message.destroy end - end diff --git a/spec/support/email_helpers.rb b/spec/support/email_helpers.rb index 9028e5335b..9f7eab508c 100644 --- a/spec/support/email_helpers.rb +++ b/spec/support/email_helpers.rb @@ -36,7 +36,6 @@ def load_mail_server_logs(log) else raise "Unexpected MTA type: #{ mta_log_type }" end - end def gsub_addresses(content, **kargs) diff --git a/spec/support/shared_examples_for_activity_list_items.rb b/spec/support/shared_examples_for_activity_list_items.rb index da90875c2e..0b844b3680 100644 --- a/spec/support/shared_examples_for_activity_list_items.rb +++ b/spec/support/shared_examples_for_activity_list_items.rb @@ -1,19 +1,13 @@ shared_examples_for "an ActivityList::Item with standard #call_to_action" do - describe '#call_to_action' do - it 'returns the text "View"' do expect(activity.call_to_action).to eq('View') end - end - end shared_examples_for "an ActivityList::Item with standard #description_urls" do - describe '#description_urls' do - it 'returns a hash of :public_body_name and :info_request_title' do expected_urls = { public_body_name: { text: event.info_request.public_body.name, url: public_body_path(event.info_request.public_body) }, diff --git a/spec/support/shared_examples_for_network_errors_during_send.rb b/spec/support/shared_examples_for_network_errors_during_send.rb index 19b4f5d763..d30e6f704c 100644 --- a/spec/support/shared_examples_for_network_errors_during_send.rb +++ b/spec/support/shared_examples_for_network_errors_during_send.rb @@ -1,7 +1,5 @@ shared_examples_for 'NetworkSendErrors' do - describe 'handles a network error during message sending' do - before do allow_any_instance_of(ActionMailer::MessageDelivery). to receive(:deliver_now). @@ -36,7 +34,5 @@ it 'ensures that the outgoing message status is set to "failed"' do expect(outgoing_message.status).to eq 'failed' end - end - end diff --git a/spec/support/shared_examples_for_phase_counts.rb b/spec/support/shared_examples_for_phase_counts.rb index eec435f287..09626166f2 100644 --- a/spec/support/shared_examples_for_phase_counts.rb +++ b/spec/support/shared_examples_for_phase_counts.rb @@ -1,5 +1,4 @@ shared_examples_for "PhaseCounts" do - let(:model) { described_class } let(:class_name) { model.to_s } let(:factory) { class_name.demodulize.underscore } @@ -24,7 +23,6 @@ end describe '#phase_counts' do - it 'returns a Hash' do expect(resource.phase_counts).to be_a(Hash) end @@ -62,7 +60,6 @@ it 'does not include draft requests in the not_drafts total' do expect(resource.phase_counts['not_drafts']).to eq 3 end - end context 'with expiring embargoes' do @@ -85,7 +82,6 @@ it 'does not double count the expiring embargo in the not_drafts total' do expect(resource.phase_counts['not_drafts']).to eq 4 end - end it 'caches the results' do @@ -97,11 +93,9 @@ resource.save! expect(resource.phase_counts['awaiting_response']).to eq(before) end - end describe '#phase_counts!' do - it 'resets the cache so the results are recalcuated' do before = resource.phase_counts!['awaiting_response'] summary = @@ -111,7 +105,5 @@ resource.save! expect(resource.phase_counts!['awaiting_response']).to eq(before + 1) end - end - end diff --git a/spec/support/shared_examples_for_viewing_requests.rb b/spec/support/shared_examples_for_viewing_requests.rb index bd76640831..cf55b7a21a 100644 --- a/spec/support/shared_examples_for_viewing_requests.rb +++ b/spec/support/shared_examples_for_viewing_requests.rb @@ -1,5 +1,4 @@ shared_examples_for 'allows the embargo to be lifted' do - it 'allows the user to publish a request' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -10,11 +9,9 @@ expect(page).to have_content(/Your requests? (is|are) now public!/) end end - end shared_examples_for 'allows annotations' do - it 'allows the user to add an annotation' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -28,11 +25,9 @@ expect(page).to have_content("Testing annotations") end end - end shared_examples_for 'allows followups' do - it 'allows the user to send a follow up' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) @@ -47,22 +42,18 @@ expect(page).to have_content("Testing follow ups") end end - end shared_examples_for 'prevents setting an embargo' do - it 'does not show the option to add an embargo' do using_pro_session(pro_user_session) do browse_pro_request(info_request.url_title) expect(page).not_to have_content "Keep private for" end end - end shared_examples_for 'a request with response' do - before do incoming_message = FactoryBot.create(:plain_incoming_message, info_request: info_request) @@ -130,5 +121,4 @@ check 'Change status' end end - end diff --git a/spec/validators/change_email_validator_spec.rb b/spec/validators/change_email_validator_spec.rb index 1b8ee578e0..b266a24db8 100644 --- a/spec/validators/change_email_validator_spec.rb +++ b/spec/validators/change_email_validator_spec.rb @@ -7,11 +7,9 @@ def validator_with_user_and_params(user, params = {}) end RSpec.describe ChangeEmailValidator do - let(:user) { FactoryBot.create(:user) } describe '#old_email' do - it 'must have an old email' do params = { old_email: nil, new_email: 'new@example.com', @@ -46,11 +44,9 @@ def validator_with_user_and_params(user, params = {}) msg = "Old email address isn't the same as the address of the account you are logged in with" expect(validator.errors[:old_email]).to include(msg) end - end describe '#new_email' do - it 'must have a new email' do params = { old_email: user.email, new_email: nil, @@ -72,11 +68,9 @@ def validator_with_user_and_params(user, params = {}) msg = "New email doesn't look like a valid address" expect(validator.errors[:new_email]).to include(msg) end - end describe '#password' do - it 'password_and_format_of_email validation fails when password is nil' do params = { old_email: user.email, new_email: 'new@example.com', @@ -117,7 +111,5 @@ def validator_with_user_and_params(user, params = {}) msg = 'Password is not correct' expect(validator.errors[:password]).to include(msg) end - end - end diff --git a/spec/validators/contact_validator_spec.rb b/spec/validators/contact_validator_spec.rb index 9e54db0f00..d4d6777fb7 100644 --- a/spec/validators/contact_validator_spec.rb +++ b/spec/validators/contact_validator_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' RSpec.describe ContactValidator do - describe '.new' do - let(:valid_params) do { name: "Vinny Vanilli", email: "vinny@localhost", @@ -50,7 +48,5 @@ validator.valid? expect(validator.errors[:message].size).to eq(1) end - end - end diff --git a/spec/validators/not_nil_validator_spec.rb b/spec/validators/not_nil_validator_spec.rb index c334b0ebea..e45e8e218a 100644 --- a/spec/validators/not_nil_validator_spec.rb +++ b/spec/validators/not_nil_validator_spec.rb @@ -19,7 +19,6 @@ class ValidatableCustomMessage end RSpec.describe NotNilValidator do - it 'is valid when the subject_attr is not blank' do subject = Validatable.new(subject_attr: 'xyz') expect(subject).to be_valid @@ -46,5 +45,4 @@ class ValidatableCustomMessage subject.valid? expect(subject.errors[:subject_attr]).to eq(['Custom message']) end - end diff --git a/spec/validators/reply_to_address_validator_spec.rb b/spec/validators/reply_to_address_validator_spec.rb index 0745c6194d..b794f266db 100644 --- a/spec/validators/reply_to_address_validator_spec.rb +++ b/spec/validators/reply_to_address_validator_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe ReplyToAddressValidator do - describe '.no_reply_regexp' do subject { described_class.no_reply_regexp } @@ -19,7 +18,6 @@ it { is_expected.to eq(/123/) } end - end describe '.invalid_reply_addresses' do @@ -39,7 +37,5 @@ it { is_expected.to eq(%w(a@example.com)) } end - end - end diff --git a/spec/views/admin_general/_announcement.html.erb_spec.rb b/spec/views/admin_general/_announcement.html.erb_spec.rb index 573481ef64..6af65bce2e 100644 --- a/spec/views/admin_general/_announcement.html.erb_spec.rb +++ b/spec/views/admin_general/_announcement.html.erb_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' RSpec.describe 'admin_general/_announcement' do - let(:announcement) do FactoryBot. create(:announcement, @@ -10,7 +9,6 @@ end describe 'displaying an announcement' do - it 'shows the announcement' do render template: 'admin_general/_announcement', locals: { announcement: announcement } @@ -23,7 +21,5 @@ locals: { announcement: announcement } expect(rendered).not_to include('