diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index cae647889..633655416 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,6 +1,7 @@
name: Build, Test and Optionally Deploy
-
-on: [push, pull_request, workflow_dispatch]
+on:
+ - push
+ - workflow_dispatch
# According to: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md
# Both Node and Yarn should be installed already
@@ -63,12 +64,17 @@ jobs:
yarn install --immutable
env:
NODE_ENV: test
- - name: Do Tests
+ - name: Run unit tests
run: |
- yarn build
- bundle exec rails test
- bundle exec rails test:system
-
+ bin/test --unit --no-fix
+ env:
+ POSTGRES_USER: postgres
+ POSTGRES_HOST: localhost
+ POSTGRES_PORT: 5432
+ PGPASSWORD: foobar
+ - name: Run system tests
+ run: |
+ bin/test --system --no-lint
env:
POSTGRES_USER: postgres
POSTGRES_HOST: localhost
diff --git a/.prettierignore b/.prettierignore
index e4ee9d1ba..5f73aaa12 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1,3 +1,7 @@
/app/assets/builds/
+/doc/**/*.html
+/doc/**/*.css
+/doc/**/*.js
/tmp/
/vendor/bundle/
+/.rubocop_todo.yml
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 000000000..132952f07
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,27 @@
+inherit_from: .rubocop_todo.yml
+
+require:
+ - rubocop-graphql
+ - rubocop-minitest
+ - rubocop-performance
+ - rubocop-rails
+ - rubocop-rake
+
+AllCops:
+ NewCops: enable
+
+GraphQL/FieldName:
+ Enabled: false
+
+GraphQL/ObjectDescription:
+ Enabled: false
+
+Rails/DynamicFindBy:
+ AllowedMethods:
+ - find_by_day
+ - find_by_request
+ - find_by_sql
+ - find_by_week
+
+Style/Documentation:
+ Enabled: false
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
new file mode 100644
index 000000000..ec0c3c286
--- /dev/null
+++ b/.rubocop_todo.yml
@@ -0,0 +1,850 @@
+# This configuration was generated by
+# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
+# on 2022-10-04 22:51:51 UTC using RuboCop version 1.30.1.
+# The point is for the user to remove these configuration records
+# one by one as the offenses are removed from the code base.
+# Note that changes in the inspected code, or installation of new
+# versions of RuboCop, may require this file to be generated again.
+
+# Offense count: 6
+GraphQL/ArgumentDescription:
+ Exclude:
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/graphql/types/query_type.rb'
+
+# Offense count: 4
+# Configuration parameters: MaxFields, Prefixes.
+# Prefixes: is, has, with, avg, min, max
+GraphQL/ExtractType:
+ Exclude:
+ - 'app/graphql/types/address_type.rb'
+ - 'app/graphql/types/article_type.rb'
+ - 'app/graphql/types/event_type.rb'
+ - 'app/graphql/types/neighbourhood_type.rb'
+
+# Offense count: 3
+# Configuration parameters: AllowedMethods.
+# AllowedMethods: enums
+Lint/ConstantDefinitionInBlock:
+ Exclude:
+ - 'lib/tasks/db.rake'
+
+# Offense count: 2
+# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
+Lint/DuplicateBranch:
+ Exclude:
+ - 'app/policies/tag_policy.rb'
+ - 'lib/tasks/db.rake'
+
+# Offense count: 2
+# Configuration parameters: AllowComments, AllowEmptyLambdas.
+Lint/EmptyBlock:
+ Exclude:
+ - 'db/seeds.rb'
+ - 'test/integration/graphql/article_query_type_test.rb'
+
+# Offense count: 2
+Lint/LiteralAsCondition:
+ Exclude:
+ - 'app/models/site.rb'
+ - 'lib/tasks/data.rake'
+
+# Offense count: 1
+# Configuration parameters: MaximumRangeSize.
+Lint/MissingCopEnableDirective:
+ Exclude:
+ - 'test/integration/admin/user_integration_test.rb'
+
+# Offense count: 5
+Lint/MissingSuper:
+ Exclude:
+ - 'app/jobs/calendar_importer/events/eventbrite_event.rb'
+ - 'app/jobs/calendar_importer/events/ics_event.rb'
+ - 'app/jobs/calendar_importer/events/manchester_uni_event.rb'
+ - 'app/jobs/calendar_importer/events/meetup_event.rb'
+ - 'app/policies/user_policy.rb'
+
+# Offense count: 1
+Lint/ShadowingOuterLocalVariable:
+ Exclude:
+ - 'app/jobs/calendar_importer/events/ics_event.rb'
+
+# Offense count: 1
+Lint/UnreachableCode:
+ Exclude:
+ - 'app/jobs/calendar_importer/events/meetup_event.rb'
+
+# Offense count: 1
+# Configuration parameters: AllowedPatterns, IgnoredPatterns.
+# AllowedPatterns: (?-mix:(exactly|at_least|at_most)\(\d+\)\.times)
+Lint/UnreachableLoop:
+ Exclude:
+ - 'lib/tasks/neighbourhoods.rake'
+
+# Offense count: 27
+Lint/UselessAssignment:
+ Exclude:
+ - 'app/jobs/calendar_importer/parsers/ics.rb'
+ - 'app/jobs/calendar_importer_job.rb'
+ - 'app/models/address.rb'
+ - 'app/models/calendar.rb'
+ - 'db/data/20180530123745_add_manchester_uni_feeds.rb'
+ - 'db/seeds_to_migrate.rb'
+ - 'test/integration/graphql/article_by_tag_query_test.rb'
+ - 'test/integration/graphql/articles_by_partner_tag_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/integration/news_integration_test.rb'
+ - 'test/jobs/calendar_importer/calendar_importer_test.rb'
+ - 'test/jobs/calendar_importer/event_resolver_strategy_test.rb'
+ - 'test/jobs/calendar_importer/events_import_test.rb'
+ - 'test/models/partner_site_scope_test.rb'
+ - 'test/models/site_test.rb'
+ - 'test/policies/partner_scope_test.rb'
+ - 'test/system/graphql/graphql_test.rb'
+
+# Offense count: 1
+# This cop supports unsafe autocorrection (--autocorrect-all).
+Lint/UselessMethodDefinition:
+ Exclude:
+ - 'app/graphql/place_cal_schema.rb'
+
+# Offense count: 2
+# Configuration parameters: CheckForMethodsWithNoSideEffects.
+Lint/Void:
+ Exclude:
+ - 'test/controllers/partners_controller_test.rb'
+ - 'test/models/site_test.rb'
+
+# Offense count: 38
+# Configuration parameters: IgnoredMethods, CountRepeatedAttributes, Max.
+Metrics/AbcSize:
+ Exclude:
+ - 'app/components/event/event_component.rb'
+ - 'app/controllers/admin/partners_controller.rb'
+ - 'app/controllers/admin/tags_controller.rb'
+ - 'app/controllers/admin/users_controller.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/concerns/map_markers.rb'
+ - 'app/controllers/events_controller.rb'
+ - 'app/controllers/partners_controller.rb'
+ - 'app/controllers/users/auth_common.rb'
+ - 'app/datatables/calendar_datatable.rb'
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/helpers/map_helper.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/jobs/calendar_importer/events/base.rb'
+ - 'app/jobs/calendar_importer_job.rb'
+ - 'app/models/concerns/html_render_cache.rb'
+ - 'app/models/partner.rb'
+ - 'app/policies/article_policy.rb'
+ - 'app/policies/calendar_policy.rb'
+ - 'config/initializers/icalendar_overrides.rb'
+ - 'db/migrate/20170726032024_add_devise_to_users.rb'
+ - 'db/migrate/20170726032515_create_initial_tables.rb'
+ - 'db/migrate/20191201002011_fix_invalid_partners.rb'
+ - 'db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb'
+ - 'db/migrate/20211118162518_remove_old_neighbourhood_properties.rb'
+ - 'db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb'
+ - 'db/migrate/20220105161548_fix_broken_datamodel.rb'
+ - 'test/controllers/admin/articles_controller_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/policies/article_policy_test.rb'
+
+# Offense count: 43
+# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, IgnoredMethods.
+# IgnoredMethods: refine
+Metrics/BlockLength:
+ Exclude:
+ - 'Guardfile'
+ - 'config/environments/development.rb'
+ - 'config/environments/production.rb'
+ - 'config/environments/staging.rb'
+ - 'config/initializers/simple_form_bootstrap.rb'
+ - 'db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb'
+ - 'lib/tasks/data.rake'
+ - 'lib/tasks/db.rake'
+ - 'lib/tasks/events.rake'
+ - 'lib/tasks/workers.rake'
+ - 'test/controllers/admin/partner_update_postcode_test.rb'
+ - 'test/controllers/concerns/map_markers_concern_test.rb'
+ - 'test/controllers/partners_controller_test.rb'
+ - 'test/factories/address.rb'
+ - 'test/factories/neighbourhood.rb'
+ - 'test/factories/partner.rb'
+ - 'test/factories/user.rb'
+ - 'test/integration/admin/partner_integration_test.rb'
+ - 'test/integration/event_site_integration_test.rb'
+ - 'test/integration/graphql/article_by_tag_query_test.rb'
+ - 'test/integration/graphql/article_query_type_test.rb'
+ - 'test/integration/graphql/articles_by_partner_tag_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/integration/partners_integration_test.rb'
+ - 'test/jobs/calendar_importer/event_resolver_test.rb'
+ - 'test/models/article_test.rb'
+ - 'test/models/partner_site_scope_test.rb'
+ - 'test/system/admin/site_test.rb'
+ - 'test/system/admin/user_test.rb'
+
+# Offense count: 21
+# Configuration parameters: CountComments, Max, CountAsOne.
+Metrics/ClassLength:
+ Exclude:
+ - 'app/controllers/admin/partners_controller.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/event.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/site.rb'
+ - 'test/controllers/admin/articles_controller_test.rb'
+ - 'test/controllers/admin/partners_controller_test.rb'
+ - 'test/controllers/admin/users_controller_test.rb'
+ - 'test/integration/admin/partner_integration_test.rb'
+ - 'test/integration/admin/sites_integration_test.rb'
+ - 'test/integration/admin/user_integration_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/jobs/calendar_importer/calendar_importer_test.rb'
+ - 'test/jobs/calendar_importer/event_resolver_test.rb'
+ - 'test/models/article_test.rb'
+ - 'test/models/events_test.rb'
+ - 'test/models/partner_site_scope_test.rb'
+ - 'test/models/partner_test.rb'
+
+# Offense count: 10
+# Configuration parameters: IgnoredMethods, Max.
+Metrics/CyclomaticComplexity:
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/concerns/map_markers.rb'
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/helpers/application_helper.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/models/site.rb'
+ - 'app/policies/tag_policy.rb'
+ - 'db/migrate/20191201002011_fix_invalid_partners.rb'
+ - 'db/migrate/20211118162518_remove_old_neighbourhood_properties.rb'
+
+# Offense count: 73
+# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, IgnoredMethods.
+Metrics/MethodLength:
+ Exclude:
+ - 'app/components/paginator/paginator_component.rb'
+ - 'app/controllers/admin/articles_controller.rb'
+ - 'app/controllers/admin/calendars_controller.rb'
+ - 'app/controllers/admin/neighbourhoods_controller.rb'
+ - 'app/controllers/admin/partners_controller.rb'
+ - 'app/controllers/admin/sites_controller.rb'
+ - 'app/controllers/admin/tags_controller.rb'
+ - 'app/controllers/admin/users_controller.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/concerns/map_markers.rb'
+ - 'app/controllers/events_controller.rb'
+ - 'app/controllers/graphql_controller.rb'
+ - 'app/controllers/news_controller.rb'
+ - 'app/controllers/partners_controller.rb'
+ - 'app/controllers/users/auth_common.rb'
+ - 'app/datatables/article_datatable.rb'
+ - 'app/datatables/calendar_datatable.rb'
+ - 'app/datatables/tag_datatable.rb'
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/graphql/types/query_type.rb'
+ - 'app/helpers/calendars_helper.rb'
+ - 'app/helpers/events_helper.rb'
+ - 'app/helpers/map_helper.rb'
+ - 'app/helpers/users_helper.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/jobs/calendar_importer/events/base.rb'
+ - 'app/jobs/calendar_importer/events/eventbrite_event.rb'
+ - 'app/jobs/calendar_importer_job.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/concerns/html_render_cache.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/site.rb'
+ - 'app/policies/partner_policy.rb'
+ - 'app/policies/user_policy.rb'
+ - 'db/data/20180530123745_add_manchester_uni_feeds.rb'
+ - 'db/data/20180625163935_add_places_partners.rb'
+ - 'db/migrate/20170726032024_add_devise_to_users.rb'
+ - 'db/migrate/20170726032515_create_initial_tables.rb'
+ - 'db/migrate/20170916030904_change_relations.rb'
+ - 'db/migrate/20170927112842_create_delayed_jobs.rb'
+ - 'db/migrate/20171128151240_create_friendly_id_slugs.rb'
+ - 'db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb'
+ - 'db/migrate/20191201002011_fix_invalid_partners.rb'
+ - 'db/migrate/20200107174516_add_more_info_to_neighbourhoods.rb'
+ - 'db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb'
+ - 'db/migrate/20211118162518_remove_old_neighbourhood_properties.rb'
+ - 'db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb'
+ - 'db/migrate/20220105161548_fix_broken_datamodel.rb'
+ - 'lib/tasks/data.rake'
+ - 'test/controllers/admin/articles_controller_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/jobs/calendar_importer/event_resolver_strategy_test.rb'
+ - 'test/policies/article_policy_test.rb'
+
+# Offense count: 9
+# Configuration parameters: IgnoredMethods, Max.
+Metrics/PerceivedComplexity:
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/concerns/map_markers.rb'
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/helpers/application_helper.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/models/site.rb'
+ - 'db/migrate/20191201002011_fix_invalid_partners.rb'
+ - 'db/migrate/20211118162518_remove_old_neighbourhood_properties.rb'
+
+# Offense count: 2
+Minitest/AssertRaisesCompoundBody:
+ Exclude:
+ - 'test/jobs/calendar_importer/calendar_importer_task_test.rb'
+ - 'test/models/partner_service_area_test.rb'
+
+# Offense count: 1
+Minitest/AssertWithExpectedArgument:
+ Exclude:
+ - 'test/test_helper.rb'
+
+# Offense count: 1
+Minitest/AssertionInLifecycleHook:
+ Exclude:
+ - 'test/policies/article_policy_test.rb'
+
+# Offense count: 80
+# Configuration parameters: Max.
+Minitest/MultipleAssertions:
+ Exclude:
+ - 'test/controllers/admin/tags_controller_test.rb'
+ - 'test/controllers/admin/users_controller_test.rb'
+ - 'test/controllers/concerns/map_markers_concern_test.rb'
+ - 'test/controllers/news_controller_test.rb'
+ - 'test/controllers/pages_controller_test.rb'
+ - 'test/integration/admin/articles_integration_test.rb'
+ - 'test/integration/admin/calendars_integration_test.rb'
+ - 'test/integration/admin/neighbourhood_integration_test.rb'
+ - 'test/integration/admin/partner_integration_test.rb'
+ - 'test/integration/admin/sites_integration_test.rb'
+ - 'test/integration/admin/tags_integration_test.rb'
+ - 'test/integration/admin/user_integration_test.rb'
+ - 'test/integration/collections_integration_test.rb'
+ - 'test/integration/devise_redirection_test.rb'
+ - 'test/integration/event_integration_test.rb'
+ - 'test/integration/events_integration_test.rb'
+ - 'test/integration/graphql/article_by_tag_query_test.rb'
+ - 'test/integration/graphql/article_query_type_test.rb'
+ - 'test/integration/graphql/articles_by_partner_tag_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/integration/partner_integration_test.rb'
+ - 'test/integration/partners_integration_test.rb'
+ - 'test/integration/sites_integration_test.rb'
+ - 'test/models/calendar_state_test.rb'
+ - 'test/models/calendar_test.rb'
+ - 'test/models/neighbourhoods_test.rb'
+ - 'test/models/partner_test.rb'
+ - 'test/models/user_test.rb'
+ - 'test/policies/article_policy_test.rb'
+ - 'test/policies/neighbourhoods_policy_test.rb'
+ - 'test/policies/partner_policy_test.rb'
+ - 'test/policies/tag_policy_test.rb'
+ - 'test/system/admin/article_test.rb'
+ - 'test/system/admin/calendar_test.rb'
+ - 'test/system/admin/partner_test.rb'
+ - 'test/system/admin/site_test.rb'
+ - 'test/system/admin/tag_test.rb'
+ - 'test/system/admin/user_test.rb'
+ - 'test/system/create_admin_users_test.rb'
+
+# Offense count: 7
+Naming/AccessorMethodName:
+ Exclude:
+ - 'app/datatables/article_datatable.rb'
+ - 'app/datatables/calendar_datatable.rb'
+ - 'app/datatables/neighbourhood_datatable.rb'
+ - 'app/datatables/partner_datatable.rb'
+ - 'app/datatables/site_datatable.rb'
+ - 'app/datatables/tag_datatable.rb'
+ - 'app/datatables/user_datatable.rb'
+
+# Offense count: 4
+# Configuration parameters: EnforcedStyleForLeadingUnderscores.
+# SupportedStylesForLeadingUnderscores: disallowed, required, optional
+Naming/MemoizedInstanceVariableName:
+ Exclude:
+ - 'app/controllers/admin/sites_controller.rb'
+ - 'app/models/concerns/html_render_cache.rb'
+ - 'test/models/partner_site_scope_test.rb'
+ - 'test/models/partner_site_with_tag_scope_test.rb'
+
+# Offense count: 2
+# Configuration parameters: EnforcedStyle, AllowedPatterns, IgnoredPatterns.
+# SupportedStyles: snake_case, camelCase
+Naming/MethodName:
+ Exclude:
+ - 'app/graphql/types/event_type.rb'
+
+# Offense count: 6
+# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
+# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
+Naming/MethodParameterName:
+ Exclude:
+ - 'app/components/paginator/paginator_component.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/graphql_controller.rb'
+ - 'app/jobs/calendar_importer_job.rb'
+ - 'app/models/address.rb'
+ - 'config/initializers/kramdown.rb'
+
+# Offense count: 9
+# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
+# NamePrefix: is_, has_, have_
+# ForbiddenPrefixes: is_, has_, have_
+# AllowedMethods: is_a?
+# MethodDefinitionMacros: define_method, define_singleton_method
+Naming/PredicateName:
+ Exclude:
+ - 'app/helpers/application_helper.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/jobs/calendar_importer/events/base.rb'
+ - 'app/jobs/calendar_importer/events/ics_event.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/partner.rb'
+ - 'app/uploaders/supporter_logo_uploader.rb'
+
+# Offense count: 26
+# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
+# SupportedStyles: snake_case, normalcase, non_integer
+# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
+Naming/VariableNumber:
+ Exclude:
+ - 'test/controllers/admin/partner_update_postcode_test.rb'
+ - 'test/factories/address.rb'
+ - 'test/helpers/calendars_helper_test.rb'
+ - 'test/integration/event_site_integration_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/models/article_test.rb'
+ - 'test/models/partner_site_scope_test.rb'
+ - 'test/models/partner_site_with_tag_scope_test.rb'
+ - 'test/policies/partner_scope_test.rb'
+
+# Offense count: 1
+# Configuration parameters: MinSize.
+Performance/CollectionLiteralInLoop:
+ Exclude:
+ - 'db/migrate/20191201002011_fix_invalid_partners.rb'
+
+# Offense count: 1
+Performance/FixedSize:
+ Exclude:
+ - 'app/models/address.rb'
+
+# Offense count: 21
+# Configuration parameters: Database, Include.
+# SupportedDatabases: mysql, postgresql
+# Include: db/migrate/*.rb
+Rails/BulkChangeTable:
+ Exclude:
+ - 'db/migrate/20171017160904_add_contact_to_places.rb'
+ - 'db/migrate/20180316122253_add_columns_to_admin_partners.rb'
+ - 'db/migrate/20180629174727_add_last_checksum_and_footer_to_calendar.rb'
+ - 'db/migrate/20180716040041_remove_type_and_address_from_calendar.rb'
+ - 'db/migrate/20180801041639_add_access_token_to_users_and_calendars.rb'
+ - 'db/migrate/20180827120116_add_devise_invitable.rb'
+ - 'db/migrate/20180926032437_change_calendar_columns.rb'
+ - 'db/migrate/20181009094523_merge_partners_places_tables.rb'
+ - 'db/migrate/20181010165919_add_calendar_contact_columns.rb'
+ - 'db/migrate/20181012041853_add_facebook_app_id_and_facebook_app_secret_to_users.rb'
+ - 'db/migrate/20181031134053_change_calendar_contact_details_to_type_string.rb'
+ - 'db/migrate/20181121141327_add_social_media_columns_to_partners.rb'
+ - 'db/migrate/20200107174516_add_more_info_to_neighbourhoods.rb'
+ - 'db/migrate/20220106150818_add_summary_description_to_partners.rb'
+ - 'db/migrate/20220516083725_add_importer_mode_to_calendar.rb'
+ - 'db/migrate/20220611154511_add_html_fields_to_models.rb'
+ - 'db/migrate/20220711161804_remove_facebook_fields.rb'
+ - 'db/migrate/20220720151156_remove_calendar_contact_info_fields.rb'
+
+# Offense count: 7
+# Configuration parameters: Include.
+# Include: db/migrate/*.rb
+Rails/CreateTableWithTimestamps:
+ Exclude:
+ - 'db/migrate/20170726032515_create_initial_tables.rb'
+ - 'db/migrate/20180530100533_create_data_migrations.seed_migration.rb'
+ - 'db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb'
+ - 'db/migrate/20181009162402_add_organisation_relationships_table.rb'
+
+# Offense count: 24
+# Configuration parameters: EnforcedStyle, AllowToTime.
+# SupportedStyles: strict, flexible
+Rails/Date:
+ Exclude:
+ - 'app/components/paginator/paginator_component.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/models/partner.rb'
+ - 'test/controllers/admin/calendars_controller_test.rb'
+ - 'test/controllers/partners_controller_test.rb'
+ - 'test/integration/event_site_integration_test.rb'
+ - 'test/integration/graphql/partners_integration_test.rb'
+ - 'test/jobs/calendar_importer/calendar_importer_task_test.rb'
+ - 'test/models/events_test.rb'
+
+# Offense count: 7
+# Configuration parameters: EnforcedStyle.
+# SupportedStyles: slashes, arguments
+Rails/FilePath:
+ Exclude:
+ - 'config/application.rb'
+ - 'config/environments/development.rb'
+ - 'config/initializers/assets.rb'
+ - 'lib/tasks/db.rake'
+ - 'test/test_helper.rb'
+
+# Offense count: 8
+# Configuration parameters: Include.
+# Include: app/models/**/*.rb
+Rails/HasAndBelongsToMany:
+ Exclude:
+ - 'app/models/collection.rb'
+ - 'app/models/event.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/site.rb'
+ - 'app/models/supporter.rb'
+ - 'app/models/user.rb'
+
+# Offense count: 6
+# Configuration parameters: Include.
+# Include: app/models/**/*.rb
+Rails/HasManyOrHasOneDependent:
+ Exclude:
+ - 'app/models/address.rb'
+ - 'app/models/online_address.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/user.rb'
+
+# Offense count: 7
+# Configuration parameters: Include.
+# Include: app/helpers/**/*.rb
+Rails/HelperInstanceVariable:
+ Exclude:
+ - 'app/helpers/events_helper.rb'
+ - 'app/helpers/partners_helper.rb'
+ - 'app/helpers/sites_helper.rb'
+
+# Offense count: 55
+Rails/I18nLocaleTexts:
+ Exclude:
+ - 'app/controllers/admin/articles_controller.rb'
+ - 'app/controllers/admin/calendars_controller.rb'
+ - 'app/controllers/admin/collections_controller.rb'
+ - 'app/controllers/admin/neighbourhoods_controller.rb'
+ - 'app/controllers/admin/partners_controller.rb'
+ - 'app/controllers/admin/sites_controller.rb'
+ - 'app/controllers/admin/supporters_controller.rb'
+ - 'app/controllers/admin/tags_controller.rb'
+ - 'app/controllers/admin/users_controller.rb'
+ - 'app/controllers/calendars_controller.rb'
+ - 'app/controllers/events_controller.rb'
+ - 'app/controllers/joins_controller.rb'
+ - 'app/mailers/join_mailer.rb'
+ - 'app/models/address.rb'
+ - 'app/models/article_partner.rb'
+ - 'app/models/article_tag.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/neighbourhoods_user.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/partner_tag.rb'
+ - 'app/models/sites_neighbourhood.rb'
+ - 'app/models/sites_supporter.rb'
+ - 'app/models/sites_tag.rb'
+ - 'app/models/tags_user.rb'
+ - 'app/models/user.rb'
+
+# Offense count: 1
+# Configuration parameters: IgnoreScopes, Include.
+# Include: app/models/**/*.rb
+Rails/InverseOf:
+ Exclude:
+ - 'app/models/user.rb'
+
+# Offense count: 5
+# Configuration parameters: Include.
+# Include: app/controllers/**/*.rb
+Rails/LexicallyScopedActionFilter:
+ Exclude:
+ - 'app/controllers/admin/neighbourhoods_controller.rb'
+ - 'app/controllers/admin/tags_controller.rb'
+ - 'app/controllers/collections_controller.rb'
+ - 'app/controllers/pages_controller.rb'
+ - 'app/controllers/sites_controller.rb'
+
+# Offense count: 3
+# Configuration parameters: Include.
+# Include: db/migrate/*.rb
+Rails/NotNullColumn:
+ Exclude:
+ - 'db/migrate/20181009162402_add_organisation_relationships_table.rb'
+
+# Offense count: 13
+# This cop supports unsafe autocorrection (--autocorrect-all).
+# Configuration parameters: Include.
+# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
+Rails/Output:
+ Exclude:
+ - 'app/jobs/calendar_importer_job.rb'
+ - 'db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb'
+ - 'db/migrate/20211118162518_remove_old_neighbourhood_properties.rb'
+ - 'db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb'
+
+# Offense count: 19
+Rails/OutputSafety:
+ Exclude:
+ - 'app/components/address/address_component.rb'
+ - 'app/components/hero/hero_component.rb'
+ - 'app/helpers/application_helper.rb'
+ - 'app/helpers/articles_helper.rb'
+ - 'app/helpers/calendars_helper.rb'
+ - 'app/helpers/events_helper.rb'
+ - 'app/helpers/map_helper.rb'
+ - 'app/helpers/partners_helper.rb'
+ - 'app/helpers/tags_helper.rb'
+ - 'app/helpers/users_helper.rb'
+ - 'app/models/partner.rb'
+
+# Offense count: 8
+# Configuration parameters: Include.
+# Include: db/**/*.rb
+Rails/ReversibleMigration:
+ Exclude:
+ - 'db/migrate/20180418132801_drop_sites_turfs_table.rb'
+ - 'db/migrate/20181031134053_change_calendar_contact_details_to_type_string.rb'
+ - 'db/migrate/20220225162314_add_id_to_partners_tags_and_places_tags.rb'
+
+# Offense count: 1
+# Configuration parameters: ForbiddenMethods, AllowedMethods.
+# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
+Rails/SkipsModelValidations:
+ Exclude:
+ - 'lib/tasks/fixes/users.rake'
+
+# Offense count: 22
+# This cop supports unsafe autocorrection (--autocorrect-all).
+# Configuration parameters: EnforcedStyle.
+# SupportedStyles: strict, flexible
+Rails/TimeZone:
+ Exclude:
+ - 'app/components/event/event_component.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/graphql/types/query_type.rb'
+ - 'app/jobs/calendar_importer/events/meetup_event.rb'
+ - 'app/jobs/calendar_importer/events/ticketsolve_event.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/event.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/site.rb'
+ - 'lib/tasks/db.rake'
+ - 'test/controllers/events_controller_test.rb'
+ - 'test/controllers/partners_controller_test.rb'
+ - 'test/integration/graphql/event_integration_test.rb'
+ - 'test/models/events_test.rb'
+
+# Offense count: 4
+Rails/TransactionExitStatement:
+ Exclude:
+ - 'app/models/calendar.rb'
+
+# Offense count: 9
+# Configuration parameters: Include.
+# Include: app/models/**/*.rb
+Rails/UniqueValidationWithoutIndex:
+ Exclude:
+ - 'app/models/article_tag.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/neighbourhoods_user.rb'
+ - 'app/models/partner.rb'
+ - 'app/models/partner_tag.rb'
+ - 'app/models/sites_neighbourhood.rb'
+ - 'app/models/sites_supporter.rb'
+ - 'app/models/tag.rb'
+ - 'app/models/tags_user.rb'
+
+# Offense count: 1
+# Configuration parameters: Environments.
+# Environments: development, test, production
+Rails/UnknownEnv:
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+
+# Offense count: 4
+# This cop supports unsafe autocorrection (--autocorrect-all).
+Rails/WhereEquals:
+ Exclude:
+ - 'app/models/article.rb'
+ - 'app/models/event.rb'
+ - 'app/models/partner.rb'
+
+# Offense count: 1
+# This cop supports unsafe autocorrection (--autocorrect-all).
+# Configuration parameters: EnforcedStyle.
+# SupportedStyles: exists, where
+Rails/WhereExists:
+ Exclude:
+ - 'app/policies/application_policy.rb'
+
+# Offense count: 4
+# This cop supports safe autocorrection (--autocorrect).
+Rake/Desc:
+ Exclude:
+ - 'lib/tasks/events.rake'
+ - 'lib/tasks/fixes/users.rake'
+
+# Offense count: 8
+Rake/MethodDefinitionInTask:
+ Exclude:
+ - 'lib/tasks/data.rake'
+ - 'lib/tasks/db.rake'
+ - 'lib/tasks/events.rake'
+
+# Offense count: 34
+# This cop supports unsafe autocorrection (--autocorrect-all).
+# Configuration parameters: EnforcedStyle.
+# SupportedStyles: nested, compact
+Style/ClassAndModuleChildren:
+ Exclude:
+ - 'app/controllers/users/confirmations_controller.rb'
+ - 'app/controllers/users/invitations_controller.rb'
+ - 'app/controllers/users/passwords_controller.rb'
+ - 'app/controllers/users/sessions_controller.rb'
+ - 'app/jobs/calendar_importer/calendar_importer.rb'
+ - 'app/jobs/calendar_importer/calendar_importer_task.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/jobs/calendar_importer/events/base.rb'
+ - 'app/jobs/calendar_importer/events/eventbrite_event.rb'
+ - 'app/jobs/calendar_importer/events/ics_event.rb'
+ - 'app/jobs/calendar_importer/events/manchester_uni_event.rb'
+ - 'app/jobs/calendar_importer/events/meetup_event.rb'
+ - 'app/jobs/calendar_importer/events/ticketsolve_event.rb'
+ - 'app/jobs/calendar_importer/parsers/base.rb'
+ - 'app/jobs/calendar_importer/parsers/eventbrite.rb'
+ - 'app/jobs/calendar_importer/parsers/ics.rb'
+ - 'app/jobs/calendar_importer/parsers/manchester_uni.rb'
+ - 'app/jobs/calendar_importer/parsers/meetup.rb'
+ - 'app/jobs/calendar_importer/parsers/ticketsolve.rb'
+ - 'app/jobs/calendar_importer/parsers/xml.rb'
+ - 'test/controllers/admin/articles_controller_test.rb'
+ - 'test/controllers/admin/calendars_controller_test.rb'
+ - 'test/controllers/admin/collections_controller_test.rb'
+ - 'test/controllers/admin/neighbourhoods_controller_test.rb'
+ - 'test/controllers/admin/partners_controller_test.rb'
+ - 'test/controllers/admin/sites_controller_test.rb'
+ - 'test/controllers/admin/supporter_controller_test.rb'
+ - 'test/controllers/admin/tags_controller_test.rb'
+ - 'test/controllers/admin/users_controller_test.rb'
+ - 'test/controllers/concerns/map_markers_concern_test.rb'
+ - 'test/integration/admin/articles_integration_test.rb'
+ - 'test/integration/admin/calendars_integration_test.rb'
+ - 'test/integration/admin/tags_integration_test.rb'
+ - 'test/jobs/calendar_importer/calendar_importer_test.rb'
+
+# Offense count: 1
+# This cop supports unsafe autocorrection (--autocorrect-all).
+Style/CollectionCompact:
+ Exclude:
+ - 'app/helpers/map_helper.rb'
+
+# Offense count: 1
+Style/CombinableLoops:
+ Exclude:
+ - 'db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb'
+
+# Offense count: 2
+# This cop supports unsafe autocorrection (--autocorrect-all).
+Style/CommentedKeyword:
+ Exclude:
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/jobs/calendar_importer/events/base.rb'
+
+# Offense count: 2
+# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods.
+# SupportedStyles: annotated, template, unannotated
+Style/FormatStringToken:
+ EnforcedStyle: unannotated
+
+# Offense count: 2
+# This cop supports unsafe autocorrection (--autocorrect-all).
+Style/GlobalStdStream:
+ Exclude:
+ - 'config/environments/production.rb'
+ - 'config/environments/staging.rb'
+
+# Offense count: 10
+# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
+Style/GuardClause:
+ Exclude:
+ - 'app/controllers/users/auth_common.rb'
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/jobs/calendar_importer/event_resolver.rb'
+ - 'app/jobs/calendar_importer/events/meetup_event.rb'
+ - 'app/models/partner.rb'
+ - 'db/migrate/20191031170146_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb'
+ - 'lib/tasks/data.rake'
+
+# Offense count: 1
+# Configuration parameters: MinBranchesCount.
+Style/HashLikeCase:
+ Exclude:
+ - 'lib/tasks/db.rake'
+
+# Offense count: 1
+Style/MixinUsage:
+ Exclude:
+ - 'test/test_helper.rb'
+
+# Offense count: 4
+# Configuration parameters: AllowedMethods.
+# AllowedMethods: respond_to_missing?
+Style/OptionalBooleanParameter:
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/controllers/concerns/map_markers.rb'
+ - 'app/helpers/application_helper.rb'
+ - 'app/jobs/calendar_importer_job.rb'
+
+# Offense count: 43
+# This cop supports safe autocorrection (--autocorrect).
+# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
+# URISchemes: http, https
+Layout/LineLength:
+ Exclude:
+ - 'app/controllers/application_controller.rb'
+ - 'app/graphql/types/event_queries.rb'
+ - 'app/graphql/types/event_type.rb'
+ - 'app/graphql/types/neighbourhood_type.rb'
+ - 'app/helpers/calendars_helper.rb'
+ - 'app/jobs/calendar_importer/events/ics_event.rb'
+ - 'app/models/address.rb'
+ - 'app/models/calendar.rb'
+ - 'app/models/concerns/validation.rb'
+ - 'app/models/partner.rb'
+ - 'config/initializers/devise.rb'
+ - 'config/initializers/simple_form.rb'
+ - 'config/initializers/simple_form_bootstrap.rb'
+ - 'db/data/20180625163935_add_places_partners.rb'
+ - 'db/data/20180625172033_add_sites.rb'
+ - 'db/migrate/20170927112842_create_delayed_jobs.rb'
+ - 'db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb'
+ - 'db/migrate/20181009094523_merge_partners_places_tables.rb'
+ - 'db/seeds_to_migrate.rb'
+ - 'lib/tasks/db.rake'
+ - 'lib/tasks/events.rake'
+ - 'lib/tasks/neighbourhoods.rake'
+ - 'test/factories/articles.rb'
+ - 'test/integration/home_integration_test.rb'
+ - 'test/jobs/calendar_importer/calendar_importer_test.rb'
+ - 'test/jobs/calendar_importer/event_resolver_strategy_test.rb'
+ - 'test/system/admin/site_test.rb'
diff --git a/Gemfile b/Gemfile
index a2732d4f9..0a1f61519 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,10 +9,10 @@ git_source(:github) do |repo_name|
end
# Core
+gem 'minitest-rails'
gem 'pg'
gem 'puma', '~> 5'
gem 'rails', '~> 6.1.6.1'
-gem 'minitest-rails'
# Frontend
gem 'coffee-rails', '~> 5.0'
@@ -21,8 +21,8 @@ gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'jsbundling-rails'
gem 'sass-rails', '~> 6.0'
-gem 'turbo-rails'
gem 'stimulus-rails'
+gem 'turbo-rails'
# Backend
gem 'ancestry'
@@ -31,10 +31,10 @@ gem 'ancestry'
gem 'ajax-datatables-rails'
# Calendar
+gem 'eventbrite_sdk'
gem 'httparty'
gem 'icalendar'
gem 'icalendar-recurrence'
-gem 'eventbrite_sdk'
# Uploads
gem 'carrierwave'
@@ -102,21 +102,26 @@ group :development do
gem 'awesome_print'
gem 'better_errors'
gem 'binding_of_caller'
+ gem 'graphiql-rails'
gem 'guard'
gem 'guard-livereload', '~> 2.5', require: false
gem 'guard-minitest'
gem 'letter_opener'
gem 'rails-erd'
- gem 'rubocop-rails'
+ gem 'rubocop-graphql', require: false
+ gem 'rubocop-minitest', require: false
+ gem 'rubocop-performance', require: false
+ gem 'rubocop-rails', require: false
+ gem 'rubocop-rake', require: false
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console', '>= 3.3.0'
gem 'yard'
- gem 'graphiql-rails'
end
group :test do
gem 'capybara-select-2', '~> 0.5.1'
+ gem 'graphql-client'
gem 'json_matchers'
gem 'minitest-rails-capybara'
gem 'minitest-reporters'
@@ -125,7 +130,6 @@ group :test do
# gem 'simplecov', require: false
gem 'vcr'
gem 'webmock'
- gem 'graphql-client'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
diff --git a/Gemfile.lock b/Gemfile.lock
index 7925485c3..e8a7a2ac0 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -430,10 +430,19 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0)
parser (>= 3.1.1.0)
+ rubocop-graphql (0.15.0)
+ rubocop (>= 0.87, < 2)
+ rubocop-minitest (0.22.1)
+ rubocop (>= 0.90, < 2.0)
+ rubocop-performance (1.15.0)
+ rubocop (>= 1.7.0, < 2.0)
+ rubocop-ast (>= 0.4.0)
rubocop-rails (2.14.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
+ rubocop-rake (0.6.0)
+ rubocop (~> 1.0)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
@@ -594,7 +603,11 @@ DEPENDENCIES
rails_autolink
redis (~> 4.0)
rollbar
+ rubocop-graphql
+ rubocop-minitest
+ rubocop-performance
rubocop-rails
+ rubocop-rake
sass-rails (~> 6.0)
seed_migration
select2-rails
diff --git a/Guardfile b/Guardfile
index 3906c03ae..6fb607898 100644
--- a/Guardfile
+++ b/Guardfile
@@ -17,9 +17,9 @@
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
-guard :minitest, spring: 'bin/rails test', env: { 'NO_COVERAGE': 'true' } do
+guard :minitest, spring: 'bin/rails test', env: { NO_COVERAGE: 'true' } do
# with Minitest::Unit
- watch(%r{^test/(.*)\/?(.*)\_test.rb$})
+ watch(%r{^test/(.*)/?(.*)_test.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
@@ -30,7 +30,6 @@ guard :minitest, spring: 'bin/rails test', env: { 'NO_COVERAGE': 'true' } do
end
guard 'livereload', grace_period: 1 do
-
extensions = {
css: :css,
scss: :css,
diff --git a/README.md b/README.md
index 5c75eab0a..de86d5137 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ To run PlaceCal locally you will need:
- [yarn](https://classic.yarnpkg.com/en/docs/install)
- ImageMagick for image manipulation
- [Graphviz](https://voormedia.github.io/rails-erd/install.html) for documentation diagrams
-- Chrome/Chromium for system tests
+- Chrome/Chromium for system tests along with a matching version of [Chromedriver](https://chromedriver.chromium.org/)
## Quickstart
@@ -89,23 +89,21 @@ Amongst other things, this will create an admin user for you:
## Testing
-PlaceCal tests are written in minitest. Before running the tests please ensure your dev environment has all of the migrations run, and ensure you have loaded the schema into the test database by running:
+PlaceCal tests are written in minitest.
-```sh
-bin/rails db:test:prepare
-```
+Before running the tests please make sure your development environment is up to date (you can run `bin/update` to quickly do that).
-The following commands are used for running tests:
+You can run the tests with:
```sh
-bin/rails test # To run all of the unit tests
-bin/rails test:system # To run all of the system tests (Invokes a headless browser)
-bin/rails test:all # To run both the unit tests and the system tests at once
+bin/test # To run all tests
+bin/test --unit # To only run unit tests
+bin/test --system # To only run system tests
```
-Please note that when running unit tests, system tests are **not** run, this is because they can take a while to run and are quite resource intensive. To perform more advanced usage like executing only a specific test or test file, see the documentation [here](https://guides.rubyonrails.org/testing.html)
+Note that the system tests can take a while to run and are quite resource-intensive. To perform more advanced usage like executing only a specific test or test file, see the [Rails documentation on testing](https://guides.rubyonrails.org/testing.html).
-When pushing to a branch on github all tests are run (unit and system). This is configured [here](.github/workflows/test.yml). You are not allowed to merge a branch (onto main or production) without a passing test suite.
+Note also that the test suite will also run all formatters and linters for you in autocorrect mode.
## Formatting
@@ -117,8 +115,20 @@ If you do want to run it manually, you can:
bin/yarn run format
```
+It's also run for you by the test runner.
+
Note that we use tabs over spaces because [tabs are more accessible to people using braille displays](https://twitter.com/Rich_Harris/status/1541761871585464323).
+## Linting
+
+We use Rubocop to lint our Ruby code. Because of the time it can take to run, this is a manual step:
+
+```sh
+bin/bundle exec rubocop --autocorrect
+```
+
+It's also run for you by the test runner.
+
## Contributing
We welcome new contributors but strongly recommend you have a chat with us in [Geeks for Social Change's Discord server](http://discord.gfsc.studio) and say hi before you do. We will be happy to onboard you properly before you get stuck in.
diff --git a/app/components/contact_details/contact_details_component.rb b/app/components/contact_details/contact_details_component.rb
index 7fcfe0db8..115fbcc42 100644
--- a/app/components/contact_details/contact_details_component.rb
+++ b/app/components/contact_details/contact_details_component.rb
@@ -25,6 +25,6 @@ def strip_url(target_url)
target_url.gsub('http://', '')
.gsub('https://', '')
.gsub('www.', '')
- .gsub(/\/$/, '')
+ .gsub(%r{/$}, '')
end
end
diff --git a/app/components/dashboard_card/dashboard_card_component.rb b/app/components/dashboard_card/dashboard_card_component.rb
index ffa4b770c..6e8f7cc29 100644
--- a/app/components/dashboard_card/dashboard_card_component.rb
+++ b/app/components/dashboard_card/dashboard_card_component.rb
@@ -9,8 +9,6 @@ class DashboardCardComponent < MountainView::Presenter
property :last_updated, default: false
def description
- if properties[:description]
- properties[:description].truncate(200)
- end
+ properties[:description]&.truncate(200)
end
end
diff --git a/app/components/event/event_component.rb b/app/components/event/event_component.rb
index dbcae4e36..4a5baaf91 100644
--- a/app/components/event/event_component.rb
+++ b/app/components/event/event_component.rb
@@ -7,17 +7,13 @@ class EventComponent < MountainView::Presenter
include ActionView::Helpers::TextHelper
include ActionView::Helpers::DateHelper
- def id
- event.id
- end
+ delegate :id, to: :event
- def place
- event.place
- end
+ delegate :place, to: :event
def time
if event.dtend
- fmt_time(event.dtstart) + ' – ' + fmt_time(event.dtend)
+ "#{fmt_time(event.dtstart)} – #{fmt_time(event.dtend)}"
else
fmt_time(event.dtstart)
end
@@ -54,13 +50,9 @@ def date
end
end
- def summary
- event.summary
- end
+ delegate :summary, to: :event
- def description
- event.description
- end
+ delegate :description, to: :event
def page?
context == :page
diff --git a/app/components/hero_image/hero_image_component.rb b/app/components/hero_image/hero_image_component.rb
index 5dda0356d..36c75c616 100644
--- a/app/components/hero_image/hero_image_component.rb
+++ b/app/components/hero_image/hero_image_component.rb
@@ -2,7 +2,8 @@
# app/components/hero_image/hero_image_component.rb
class HeroImageComponent < MountainView::Presenter
- property :title, default: 'PlaceCal is a community events calendar where you can find everything near you, all in one place.'
+ property :title,
+ default: 'PlaceCal is a community events calendar where you can find everything near you, all in one place.'
properties :image_path, :image_credit
def title
@@ -10,7 +11,8 @@ def title
end
def image_credit
- return false unless properties[:image_credit].present?
+ return false if properties[:image_credit].blank?
+
"Image credit: #{properties[:image_credit]}"
end
diff --git a/app/components/navigation/navigation_component.rb b/app/components/navigation/navigation_component.rb
index d1b3e8dd4..e123171fc 100644
--- a/app/components/navigation/navigation_component.rb
+++ b/app/components/navigation/navigation_component.rb
@@ -2,7 +2,6 @@
# app/components/navigation/navigation_component.rb
class NavigationComponent < MountainView::Presenter
-
property :navigation
# property :site
@@ -14,5 +13,4 @@ class NavigationComponent < MountainView::Presenter
# def site_logo
# site.logo
# end
-
end
diff --git a/app/components/paginator/paginator_component.rb b/app/components/paginator/paginator_component.rb
index 397f4e61f..68e0f1132 100644
--- a/app/components/paginator/paginator_component.rb
+++ b/app/components/paginator/paginator_component.rb
@@ -17,7 +17,7 @@ def paginator # rubocop:disable Metrics/AbcSize
css: 'paginator__arrow paginator__arrow--back js-back' }
# Create in-between links according to steps requested
(0..steps).each do |i|
- day = pointer + period * i
+ day = pointer + (period * i)
css = active?(day) ? 'active js-button' : 'js-button'
pages << { text: format_date(day),
link: create_event_url(day),
@@ -99,7 +99,7 @@ def todayify(date)
end
# Format the button for a week of events
- def weekify(date) # rubocop:disable Metrics/MethodLength
+ def weekify(date)
today = Date.today
end_date = date + period - 1.day
date_fmt = if date.month == end_date.month
@@ -127,7 +127,7 @@ def url_suffix
str << 'period=week' if period == 1.week
str << "sort=#{sort}" if sort
str << "repeating=#{repeating}" if repeating
- '?' + str.join('&') if str.any?
+ "?#{str.join('&')}" if str.any?
end
# Icon for back arrow
diff --git a/app/components/place_partner_preview/place_partner_preview_component.rb b/app/components/place_partner_preview/place_partner_preview_component.rb
index 49a9d5fc1..c90455554 100644
--- a/app/components/place_partner_preview/place_partner_preview_component.rb
+++ b/app/components/place_partner_preview/place_partner_preview_component.rb
@@ -5,9 +5,7 @@ class PlacePartnerPreviewComponent < MountainView::Presenter
properties :primary_neighbourhood, :previewee, :show_neighbourhoods,
:badge_zoom_level, :service_areas
- def name
- previewee.name
- end
+ delegate :name, to: :previewee
def link
previewee
@@ -35,7 +33,7 @@ def primary_neighbourhood?
end
def show_service_area?
- service_areas.count > 0
+ service_areas.count.positive?
end
def service_area_name
diff --git a/app/components/profile/profile_component.rb b/app/components/profile/profile_component.rb
index 0291f3c4c..e2ab6a18e 100644
--- a/app/components/profile/profile_component.rb
+++ b/app/components/profile/profile_component.rb
@@ -10,10 +10,9 @@ def name
def phone
# Bloody empty string strikes again
return false unless user.phone&.length&.positive?
+
user.phone
end
- def email
- user.email
- end
+ delegate :email, to: :user
end
diff --git a/app/constraints/sites.rb b/app/constraints/sites.rb
index 2c87df024..2f0f98216 100644
--- a/app/constraints/sites.rb
+++ b/app/constraints/sites.rb
@@ -4,6 +4,7 @@ module Sites
class Local
def self.matches?(request)
return false if request.subdomain == Site::ADMIN_SUBDOMAIN
+
site = Site.find_by_request request
site&.local_site?
end
diff --git a/app/controllers/admin/articles_controller.rb b/app/controllers/admin/articles_controller.rb
index b6782cdd6..34a390246 100644
--- a/app/controllers/admin/articles_controller.rb
+++ b/app/controllers/admin/articles_controller.rb
@@ -10,13 +10,13 @@ def index
respond_to do |format|
format.html
- format.json {
+ format.json do
render json: ArticleDatatable.new(
params,
view_context: view_context,
articles: @articles
)
- }
+ end
end
end
diff --git a/app/controllers/admin/calendars_controller.rb b/app/controllers/admin/calendars_controller.rb
index 54f71315f..7208ee845 100644
--- a/app/controllers/admin/calendars_controller.rb
+++ b/app/controllers/admin/calendars_controller.rb
@@ -11,13 +11,13 @@ def index
respond_to do |format|
format.html
- format.json {
+ format.json do
render json: CalendarDatatable.new(
params,
view_context: view_context,
calendars: @calendars
)
- }
+ end
end
end
diff --git a/app/controllers/admin/jobs_controller.rb b/app/controllers/admin/jobs_controller.rb
index 9dd3fe8f1..bd4f49530 100644
--- a/app/controllers/admin/jobs_controller.rb
+++ b/app/controllers/admin/jobs_controller.rb
@@ -6,8 +6,8 @@ class JobsController < Admin::ApplicationController
def index
@job_count = ActiveRecord::Base
- .connection.execute("select count(*) from delayed_jobs")
- .first["count"]
+ .connection.execute('select count(*) from delayed_jobs')
+ .first['count']
@calendar_counts = Calendar.group(:calendar_state).count
end
diff --git a/app/controllers/admin/partners_controller.rb b/app/controllers/admin/partners_controller.rb
index 842a1ca79..ff777d46e 100644
--- a/app/controllers/admin/partners_controller.rb
+++ b/app/controllers/admin/partners_controller.rb
@@ -13,11 +13,11 @@ def index
respond_to do |format|
format.html
- format.json {
+ format.json do
render json: PartnerDatatable.new(params,
view_context: view_context,
partners: @partners)
- }
+ end
end
end
@@ -113,14 +113,14 @@ def setup
def set_service_area_map_ids
# maps neighbourhood ID to service_area ID
- if @partner
- @service_area_id_map = @partner
- .service_areas.select(:id, :neighbourhood_id)
- .map { |sa| { sa.neighbourhood_id => sa.id } }
- .reduce({}, :merge)
- else
- @service_area_id_map = {}
- end
+ @service_area_id_map = if @partner
+ @partner
+ .service_areas.select(:id, :neighbourhood_id)
+ .map { |sa| { sa.neighbourhood_id => sa.id } }
+ .reduce({}, :merge)
+ else
+ {}
+ end
end
def set_neighbourhoods
diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb
index d426f2cf7..72c95dc07 100644
--- a/app/controllers/admin/tags_controller.rb
+++ b/app/controllers/admin/tags_controller.rb
@@ -10,13 +10,13 @@ def index
respond_to do |format|
format.html
- format.json {
+ format.json do
render json: TagDatatable.new(
params,
view_context: view_context,
tags: @tags
)
- }
+ end
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 9a85ec75f..22adb0699 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -90,9 +90,7 @@ def current_site
@current_site = Site.find_by_request(request)
- if @current_site.nil? && !response.redirect?
- redirect_to( root_url( :subdomain => false ) )
- end
+ redirect_to(root_url(subdomain: false)) if @current_site.nil? && !response.redirect?
@current_site
end
@@ -101,7 +99,6 @@ def set_primary_neighbourhood
@primary_neighbourhood = current_site&.primary_neighbourhood
end
-
# Create a calendar from array of events
def create_calendar(events, title = false)
cal = Icalendar::Calendar.new
@@ -140,9 +137,11 @@ def default_update(obj, obj_params)
def authenticate_by_ip
# Is whitelist mode enabled?
return unless ENV['WHITELIST_MODE']
+
# Whitelisted ips are stored as comma separated values in the dokku config
whitelist = ENV['WHITELISTED_IPS'].split(',')
return if whitelist.include?(request.remote_ip)
+
redirect_to 'https://google.com'
end
@@ -174,7 +173,7 @@ def redirect_from_default_site
def set_navigation
return @navigation if @navigation
- return if self.class == MountainView::StyleguideController
+ return if instance_of?(MountainView::StyleguideController)
@navigation = if default_site?
default_site_navigation
@@ -183,15 +182,15 @@ def set_navigation
end
end
-
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: %i[first_name last_name email password password_confirmation])
- devise_parameter_sanitizer.permit(:account_update, keys: %i[first_name last_name email password password_confirmation current_password])
+ devise_parameter_sanitizer.permit(:account_update,
+ keys: %i[first_name last_name email password password_confirmation
+ current_password])
end
-
def storable_location?
(request.subdomain == Site::ADMIN_SUBDOMAIN) && request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
end
@@ -224,7 +223,7 @@ def sub_site_navigation
# ['Places', places_path],
['Partners', partners_path]
]
- items << ['News', news_index_path] if article_count > 0
+ items << ['News', news_index_path] if article_count.positive?
items
end
end
diff --git a/app/controllers/concerns/load_utilities.rb b/app/controllers/concerns/load_utilities.rb
index 865ce7f7e..06d369dfb 100644
--- a/app/controllers/concerns/load_utilities.rb
+++ b/app/controllers/concerns/load_utilities.rb
@@ -6,10 +6,10 @@ module LoadUtilities
included do
def set_tags
@tags = if current_user&.role&.root?
- Tag.all
- else
- current_user&.tags
- end
+ Tag.all
+ else
+ current_user&.tags
+ end
end
end
end
diff --git a/app/controllers/concerns/map_markers.rb b/app/controllers/concerns/map_markers.rb
index d4acd0b1b..c3bab9ef2 100644
--- a/app/controllers/concerns/map_markers.rb
+++ b/app/controllers/concerns/map_markers.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module MapMarkers
extend ActiveSupport::Concern
@@ -12,8 +14,7 @@ module MapMarkers
# returns:
# Array of Hashes to be consumed by the JS map front end
#
- def get_map_markers(locations, addresses_only=false)
-
+ def get_map_markers(locations, addresses_only = false)
# Events
locations = locations.map do |loc|
next loc unless loc.is_a?(Event)
@@ -28,9 +29,9 @@ def get_map_markers(locations, addresses_only=false)
# reject partner with no resolvable address
next if loc.address.nil? || loc.address.latitude.blank?
- if addresses_only
+ if addresses_only && loc.service_areas.count.positive?
# reject partner if they have any service areas?
- next if loc.service_areas.count > 0
+ next
end
{
@@ -44,6 +45,7 @@ def get_map_markers(locations, addresses_only=false)
# Addresses
locations = locations.map do |loc|
next loc unless loc.is_a?(Address)
+
{
lat: loc.latitude,
lon: loc.longitude
@@ -52,5 +54,4 @@ def get_map_markers(locations, addresses_only=false)
locations.keep_if { |loc| loc.is_a?(Hash) }
end
-
end
diff --git a/app/controllers/graphql_controller.rb b/app/controllers/graphql_controller.rb
index 659a53f85..11217c247 100644
--- a/app/controllers/graphql_controller.rb
+++ b/app/controllers/graphql_controller.rb
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
+
class GraphqlController < ApplicationController
-
skip_before_action :verify_authenticity_token
# If accessing from outside this domain, nullify the session
@@ -19,6 +20,7 @@ def execute
render json: result
rescue StandardError => e
raise e unless Rails.env.development?
+
handle_error_in_development(e)
end
@@ -48,6 +50,6 @@ def handle_error_in_development(e)
logger.error e.message
logger.error e.backtrace.join("\n")
- render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
+ render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: :internal_server_error
end
end
diff --git a/app/controllers/joins_controller.rb b/app/controllers/joins_controller.rb
index af7284b37..281f315f1 100644
--- a/app/controllers/joins_controller.rb
+++ b/app/controllers/joins_controller.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
class JoinsController < ApplicationController
before_action :set_site
def new
- @join = Join.new
+ @join = Join.new
end
def create
@@ -11,9 +13,9 @@ def create
if @join.submit
redirect_to join_path, notice: "Thank you for your interest in PlaceCal. We'll be in touch with you shortly."
else
- flash[:error] = "Please fill out the required fields below"
- render :new
- end
+ flash[:error] = 'Please fill out the required fields below'
+ render :new
+ end
end
private
diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 738c49b54..0c1923483 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -9,24 +9,23 @@ class NewsController < ApplicationController
def index
@offset = params[:offset].to_i
- @offset = 0 if @offset < 0
+ @offset = 0 if @offset.negative?
@next_offset = @offset + ARTICLES_PER_PAGE
@article_count = Article
- .for_site(@site)
- .published
- .count
+ .for_site(@site)
+ .published
+ .count
@articles = Article
- .for_site(@site)
- .published
- .by_publish_date
- .offset(@offset)
- .limit(ARTICLES_PER_PAGE)
+ .for_site(@site)
+ .published
+ .by_publish_date
+ .offset(@offset)
+ .limit(ARTICLES_PER_PAGE)
end
- def show
- end
+ def show; end
private
diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb
index bdc36f88d..2b40b61fb 100644
--- a/app/controllers/partners_controller.rb
+++ b/app/controllers/partners_controller.rb
@@ -3,8 +3,8 @@
class PartnersController < ApplicationController
include MapMarkers
- before_action :set_partner, only: [:show, :embed]
- before_action :set_day, only: [:show, :embed]
+ before_action :set_partner, only: %i[show embed]
+ before_action :set_day, only: %i[show embed]
before_action :set_primary_neighbourhood, only: [:index]
before_action :set_site
before_action :set_title, only: %i[index show]
@@ -82,9 +82,9 @@ def embed
def no_upcoming_events_reason(partner)
if partner.calendars.none?
- "This partner does not list events on PlaceCal."
+ 'This partner does not list events on PlaceCal.'
else
- "This partner has no upcoming events."
+ 'This partner has no upcoming events.'
end
end
diff --git a/app/controllers/users/auth_common.rb b/app/controllers/users/auth_common.rb
index c66d7c7f8..b43778996 100644
--- a/app/controllers/users/auth_common.rb
+++ b/app/controllers/users/auth_common.rb
@@ -2,7 +2,6 @@
module Users
module AuthCommon
-
def self.included(klass)
klass.before_action :devise_check_on_root_site
klass.after_action :patch_flash
@@ -18,7 +17,7 @@ def self.included(klass)
#
def devise_check_on_root_site
return if current_user.present?
- return if not request.subdomain.present?
+ return if request.subdomain.blank?
redirect_to url_for(subdomain: nil)
end
@@ -54,7 +53,7 @@ def patch_flash
#
# == Returns
# URL of admin site with correct path and subdomain
- def after_sign_in_path_for(resource_or_scope)
+ def after_sign_in_path_for(_resource_or_scope)
route_for(
:root,
subdomain: Site::ADMIN_SUBDOMAIN
@@ -68,7 +67,7 @@ def after_sign_in_path_for(resource_or_scope)
#
# == Returns
# full url with domain to take user to
- def after_accept_path_for(resource_or_scope)
+ def after_accept_path_for(_resource_or_scope)
route_for(
:root,
subdomain: Site::ADMIN_SUBDOMAIN
@@ -82,12 +81,11 @@ def after_accept_path_for(resource_or_scope)
#
# == Returns
# full url with domain to take user to
- def after_sign_out_path_for(resource_or_scope)
+ def after_sign_out_path_for(_resource_or_scope)
route_for(
:root,
subdomain: nil
)
end
end
-
end
diff --git a/app/datatables/article_datatable.rb b/app/datatables/article_datatable.rb
index 0919de76e..4c4f70171 100644
--- a/app/datatables/article_datatable.rb
+++ b/app/datatables/article_datatable.rb
@@ -1,5 +1,6 @@
-class ArticleDatatable < Datatable
+# frozen_string_literal: true
+class ArticleDatatable < Datatable
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
diff --git a/app/datatables/datatable.rb b/app/datatables/datatable.rb
index eab299fb5..5ccfb24f4 100644
--- a/app/datatables/datatable.rb
+++ b/app/datatables/datatable.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Datatable < AjaxDatatablesRails::ActiveRecord
extend Forwardable
diff --git a/app/datatables/neighbourhood_datatable.rb b/app/datatables/neighbourhood_datatable.rb
index 9533b6161..468cc7406 100644
--- a/app/datatables/neighbourhood_datatable.rb
+++ b/app/datatables/neighbourhood_datatable.rb
@@ -1,26 +1,28 @@
+# frozen_string_literal: true
+
class NeighbourhoodDatatable < Datatable
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
@view_columns ||= {
- id: { source: 'Neighbourhood.id', cond: :eq },
- name: { source: 'Neighbourhood.name' },
- unit_name: { source: 'Neighbourhood.unit_name' },
- unit_code_key: { source: 'Neighbourhood.unit_code_key' },
+ id: { source: 'Neighbourhood.id', cond: :eq },
+ name: { source: 'Neighbourhood.name' },
+ unit_name: { source: 'Neighbourhood.unit_name' },
+ unit_code_key: { source: 'Neighbourhood.unit_code_key' },
unit_code_value: { source: 'Neighbourhood.unit_code_value' },
- parent_name: { source: 'Neighbourhood.parent_name' },
+ parent_name: { source: 'Neighbourhood.parent_name' }
}
end
def data
records.map do |record|
{
- id: link_to(record.id, edit_admin_neighbourhood_path(record)),
- name: record.name,
- unit_name: record.unit_name,
- unit_code_key: record.unit_code_key,
+ id: link_to(record.id, edit_admin_neighbourhood_path(record)),
+ name: record.name,
+ unit_name: record.unit_name,
+ unit_code_key: record.unit_code_key,
unit_code_value: record.unit_code_value,
- parent_name: record.parent_name,
+ parent_name: record.parent_name
}
end
end
diff --git a/app/datatables/partner_datatable.rb b/app/datatables/partner_datatable.rb
index 5c638b138..19c11b099 100644
--- a/app/datatables/partner_datatable.rb
+++ b/app/datatables/partner_datatable.rb
@@ -1,23 +1,25 @@
+# frozen_string_literal: true
+
class PartnerDatatable < Datatable
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
@view_columns ||= {
- id: { source: 'Partner.id', cond: :eq },
- name: { source: 'Partner.name', cond: :like },
- slug: { source: 'Partner.slug' },
- address: { source: 'Partner.address', searchable: false },
- updated_at: { source: 'Partner.updated_at' },
+ id: { source: 'Partner.id', cond: :eq },
+ name: { source: 'Partner.name', cond: :like },
+ slug: { source: 'Partner.slug' },
+ address: { source: 'Partner.address', searchable: false },
+ updated_at: { source: 'Partner.updated_at' }
}
end
def data
records.map do |record|
{
- id: link_to(record.id, edit_admin_partner_path(record)),
- name: link_to(record.name, edit_admin_partner_path(record)),
- slug: link_to(record.slug, edit_admin_partner_path(record)),
- address: record.address,
+ id: link_to(record.id, edit_admin_partner_path(record)),
+ name: link_to(record.name, edit_admin_partner_path(record)),
+ slug: link_to(record.slug, edit_admin_partner_path(record)),
+ address: record.address,
updated_at: record.updated_at
}
end
diff --git a/app/datatables/site_datatable.rb b/app/datatables/site_datatable.rb
index 3be1dee56..92cbc2598 100644
--- a/app/datatables/site_datatable.rb
+++ b/app/datatables/site_datatable.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class SiteDatatable < Datatable
def view_columns
# Declare strings in this format: ModelName.column_name
diff --git a/app/datatables/tag_datatable.rb b/app/datatables/tag_datatable.rb
index 233ff7ba8..ea37775bd 100644
--- a/app/datatables/tag_datatable.rb
+++ b/app/datatables/tag_datatable.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class TagDatatable < Datatable
def view_columns
# Declare strings in this format: ModelName.column_name
diff --git a/app/datatables/user_datatable.rb b/app/datatables/user_datatable.rb
index ef99bdb07..8073e3695 100644
--- a/app/datatables/user_datatable.rb
+++ b/app/datatables/user_datatable.rb
@@ -1,26 +1,28 @@
+# frozen_string_literal: true
+
class UserDatatable < Datatable
def view_columns
# Declare strings in this format: ModelName.column_name
# or in aliased_join_table.column_name format
@view_columns ||= {
- id: { source: 'User.id', cond: :eq },
- first_name: { source: 'User.first_name' },
- last_name: { source: 'User.last_name' },
+ id: { source: 'User.id', cond: :eq },
+ first_name: { source: 'User.first_name' },
+ last_name: { source: 'User.last_name' },
admin_roles: { source: 'User.admin_roles', searchable: false, orderable: false },
- email: { source: 'User.email' },
- updated_at: { source: 'User.updated_at' }
+ email: { source: 'User.email' },
+ updated_at: { source: 'User.updated_at' }
}
end
def data
records.map do |record|
{
- id: link_to(record.id, edit_admin_user_path(record)),
- first_name: link_to(record.first_name, edit_admin_user_path(record)),
- last_name: link_to(record.last_name, edit_admin_user_path(record)),
+ id: link_to(record.id, edit_admin_user_path(record)),
+ first_name: link_to(record.first_name, edit_admin_user_path(record)),
+ last_name: link_to(record.last_name, edit_admin_user_path(record)),
admin_roles: record.admin_roles,
- email: record.email,
- updated_at: record.updated_at
+ email: record.email,
+ updated_at: record.updated_at
}
end
end
diff --git a/app/graphql/mutations/base_mutation.rb b/app/graphql/mutations/base_mutation.rb
index 0749ec031..0ff6c4eec 100644
--- a/app/graphql/mutations/base_mutation.rb
+++ b/app/graphql/mutations/base_mutation.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
argument_class Types::BaseArgument
diff --git a/app/graphql/place_cal_schema.rb b/app/graphql/place_cal_schema.rb
index 9ea9c2ac4..63565796f 100644
--- a/app/graphql/place_cal_schema.rb
+++ b/app/graphql/place_cal_schema.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class PlaceCalSchema < GraphQL::Schema
# mutation(Types::MutationType)
@@ -18,7 +20,7 @@ def self.type_error(err, context)
end
# Union and Interface Resolution
- def self.resolve_type(abstract_type, obj, ctx)
+ def self.resolve_type(_abstract_type, _obj, _ctx)
# TODO: Implement this method
# to return the correct GraphQL object type for `obj`
raise(GraphQL::RequiredImplementationMissingError)
@@ -27,24 +29,24 @@ def self.resolve_type(abstract_type, obj, ctx)
# Relay-style Object Identification:
# Return a string UUID for `object`
- def self.id_from_object(object, type_definition, query_ctx)
+ def self.id_from_object(object, type_definition, _query_ctx)
# For example, use Rails' GlobalID library (https://github.com/rails/globalid):
object_id = object.to_global_id.to_s
# Remove this redundant prefix to make IDs shorter:
- object_id = object_id.sub("gid://#{GlobalID.app}/", "")
+ object_id = object_id.sub("gid://#{GlobalID.app}/", '')
encoded_id = Base64.urlsafe_encode64(object_id)
# Remove the "=" padding
- encoded_id = encoded_id.sub(/=+/, "")
+ encoded_id = encoded_id.sub(/=+/, '')
# Add a type hint
type_hint = type_definition.graphql_name.first
"#{type_hint}_#{encoded_id}"
end
# Given a string UUID, find the object
- def self.object_from_id(encoded_id_with_hint, query_ctx)
+ def self.object_from_id(encoded_id_with_hint, _query_ctx)
# For example, use Rails' GlobalID library (https://github.com/rails/globalid):
# Split off the type hint
- _type_hint, encoded_id = encoded_id_with_hint.split("_", 2)
+ _type_hint, encoded_id = encoded_id_with_hint.split('_', 2)
# Decode the ID
id = Base64.urlsafe_decode64(encoded_id)
# Rebuild it for Rails then find the object:
diff --git a/app/graphql/types/article_type.rb b/app/graphql/types/article_type.rb
index 4563ab720..026bd6586 100644
--- a/app/graphql/types/article_type.rb
+++ b/app/graphql/types/article_type.rb
@@ -51,7 +51,7 @@ class ArticleType < Types::BaseObject
# author: person, from user
def image
- return nil unless object.article_image_url.present?
+ return nil if object.article_image_url.blank?
url = URI::HTTP.build(Rails.application.default_url_options)
url.scheme = Rails.application.default_url_options[:protocol]
diff --git a/app/graphql/types/base_argument.rb b/app/graphql/types/base_argument.rb
index c1bfdabbf..2e2278c5a 100644
--- a/app/graphql/types/base_argument.rb
+++ b/app/graphql/types/base_argument.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseArgument < GraphQL::Schema::Argument
end
diff --git a/app/graphql/types/base_connection.rb b/app/graphql/types/base_connection.rb
index df16c1713..366c69e8a 100644
--- a/app/graphql/types/base_connection.rb
+++ b/app/graphql/types/base_connection.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseConnection < Types::BaseObject
# add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
diff --git a/app/graphql/types/base_edge.rb b/app/graphql/types/base_edge.rb
index e3c4bf723..e0d2f79c0 100644
--- a/app/graphql/types/base_edge.rb
+++ b/app/graphql/types/base_edge.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseEdge < Types::BaseObject
# add `node` and `cursor` fields, as well as `node_type(...)` override
diff --git a/app/graphql/types/base_enum.rb b/app/graphql/types/base_enum.rb
index b45a845f7..cf43fea45 100644
--- a/app/graphql/types/base_enum.rb
+++ b/app/graphql/types/base_enum.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseEnum < GraphQL::Schema::Enum
end
diff --git a/app/graphql/types/base_field.rb b/app/graphql/types/base_field.rb
index 7142ef7dd..611eb0560 100644
--- a/app/graphql/types/base_field.rb
+++ b/app/graphql/types/base_field.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseField < GraphQL::Schema::Field
argument_class Types::BaseArgument
diff --git a/app/graphql/types/base_input_object.rb b/app/graphql/types/base_input_object.rb
index c97c47963..279511321 100644
--- a/app/graphql/types/base_input_object.rb
+++ b/app/graphql/types/base_input_object.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseInputObject < GraphQL::Schema::InputObject
argument_class Types::BaseArgument
diff --git a/app/graphql/types/base_interface.rb b/app/graphql/types/base_interface.rb
index a330aef26..188993871 100644
--- a/app/graphql/types/base_interface.rb
+++ b/app/graphql/types/base_interface.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
module BaseInterface
include GraphQL::Schema::Interface
diff --git a/app/graphql/types/base_object.rb b/app/graphql/types/base_object.rb
index ed6a321f1..487af2f58 100644
--- a/app/graphql/types/base_object.rb
+++ b/app/graphql/types/base_object.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseObject < GraphQL::Schema::Object
edge_type_class(Types::BaseEdge)
diff --git a/app/graphql/types/base_scalar.rb b/app/graphql/types/base_scalar.rb
index c0aa38be2..719bc808f 100644
--- a/app/graphql/types/base_scalar.rb
+++ b/app/graphql/types/base_scalar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseScalar < GraphQL::Schema::Scalar
end
diff --git a/app/graphql/types/base_union.rb b/app/graphql/types/base_union.rb
index d6dd3acb1..959416963 100644
--- a/app/graphql/types/base_union.rb
+++ b/app/graphql/types/base_union.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class BaseUnion < GraphQL::Schema::Union
edge_type_class(Types::BaseEdge)
diff --git a/app/graphql/types/contact_type.rb b/app/graphql/types/contact_type.rb
index e10d6bef2..857d33269 100644
--- a/app/graphql/types/contact_type.rb
+++ b/app/graphql/types/contact_type.rb
@@ -1,23 +1,22 @@
+# frozen_string_literal: true
+
module Types
class ContactType < Types::BaseObject
-
description 'Contact information for a person or venue'
- field :name, String,
- null: false,
- method: :public_name,
- description: 'Name of contact'
+ field :name, String,
+ null: false,
+ method: :public_name,
+ description: 'Name of contact'
- field :email, String,
- null: false,
- method: :public_email,
- description: 'Email address of contact'
+ field :email, String,
+ null: false,
+ method: :public_email,
+ description: 'Email address of contact'
field :telephone, String,
- null: false,
- method: :public_phone,
- description: 'Telephone number of contact'
-
+ null: false,
+ method: :public_phone,
+ description: 'Telephone number of contact'
end
end
-
diff --git a/app/graphql/types/event_queries.rb b/app/graphql/types/event_queries.rb
index f67ab93cd..ce5f22d13 100644
--- a/app/graphql/types/event_queries.rb
+++ b/app/graphql/types/event_queries.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
module EventQueries
def self.included(klass)
@@ -47,12 +49,12 @@ def events_by_filter(**args)
if args[:from_date].present?
if args[:from_date] =~ /^\s*(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})/
from_date = DateTime.new(
- $1.to_i, # year
- $2.to_i, # month
- $3.to_i, # day
- $4.to_i, # hour
- $5.to_i, # minute
- 0, # seconds
+ Regexp.last_match(1).to_i, # year
+ Regexp.last_match(2).to_i, # month
+ Regexp.last_match(3).to_i, # day
+ Regexp.last_match(4).to_i, # hour
+ Regexp.last_match(5).to_i, # minute
+ 0 # seconds
)
else
raise GraphQL::ExecutionError, "fromDate not in 'YYYY-MM-DD HH:MM' format"
@@ -64,12 +66,12 @@ def events_by_filter(**args)
if args[:to_date].present?
if args[:to_date] =~ /^\s*(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})/
to_date = DateTime.new(
- $1.to_i, # year
- $2.to_i, # month
- $3.to_i, # day
- $4.to_i, # hour
- $5.to_i, # minute
- 0, # seconds
+ Regexp.last_match(1).to_i, # year
+ Regexp.last_match(2).to_i, # month
+ Regexp.last_match(3).to_i, # day
+ Regexp.last_match(4).to_i, # hour
+ Regexp.last_match(5).to_i, # minute
+ 0 # seconds
)
raise GraphQL::ExecutionError, 'toDate is before fromDate' if to_date <= from_date
diff --git a/app/graphql/types/event_type.rb b/app/graphql/types/event_type.rb
index b901abfe1..704f535cc 100644
--- a/app/graphql/types/event_type.rb
+++ b/app/graphql/types/event_type.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
class EventType < Types::BaseObject
description 'An event represents a date in time that a partner operates their service, meetup, workout or class etc'
diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb
index 28516a597..6737f73f6 100644
--- a/app/graphql/types/mutation_type.rb
+++ b/app/graphql/types/mutation_type.rb
@@ -1,10 +1,12 @@
+# frozen_string_literal: true
+
module Types
class MutationType < Types::BaseObject
# TODO: remove me
field :test_field, String, null: false,
- description: "An example field added by the generator"
+ description: 'An example field added by the generator'
def test_field
- "Hello World"
+ 'Hello World'
end
end
end
diff --git a/app/graphql/types/neighbourhood_type.rb b/app/graphql/types/neighbourhood_type.rb
index 1b5f0ac8a..83009dd0c 100644
--- a/app/graphql/types/neighbourhood_type.rb
+++ b/app/graphql/types/neighbourhood_type.rb
@@ -1,28 +1,27 @@
+# frozen_string_literal: true
+
module Types
class NeighbourhoodType < Types::BaseObject
-
description 'A political divison, for example as established by the UK Boundary Authority. Can be on a number of scales from local to national'
# field :id, ID, null: false
- field :name, String,
- null: false,
- description: 'The common name for this region'
+ field :name, String,
+ null: false,
+ description: 'The common name for this region'
field :abbreviated_name, String,
- description: 'Abbreviated version of name or just the name if this is not set'
+ description: 'Abbreviated version of name or just the name if this is not set'
field :unit, String,
- description: 'Size of neighbourhood: country -> region -> county -> district -> ward'
+ description: 'Size of neighbourhood: country -> region -> county -> district -> ward'
field :unit_name, String,
- description: 'Official name of this neighbourhood'
+ description: 'Official name of this neighbourhood'
field :unit_code_key, String,
- description: 'Official key for this neighbourhood'
+ description: 'Official key for this neighbourhood'
field :unit_code_value, String,
- description: 'Official value (ID) of this neighbourhood'
-
+ description: 'Official value (ID) of this neighbourhood'
end
end
-
diff --git a/app/graphql/types/node_type.rb b/app/graphql/types/node_type.rb
index 8daea8406..c71ec3ee6 100644
--- a/app/graphql/types/node_type.rb
+++ b/app/graphql/types/node_type.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Types
module NodeType
include Types::BaseInterface
diff --git a/app/graphql/types/opening_hours_type.rb b/app/graphql/types/opening_hours_type.rb
index 13ed1f085..7559f6c1a 100644
--- a/app/graphql/types/opening_hours_type.rb
+++ b/app/graphql/types/opening_hours_type.rb
@@ -1,19 +1,21 @@
+# frozen_string_literal: true
+
module Types
class OpeningHoursType < Types::BaseObject
description 'A period of time that this partner is open for'
field :day_of_week, String,
- description: 'Monday, Tuesday, Wednesday etc'
+ description: 'Monday, Tuesday, Wednesday etc'
field :opens, String,
- description: 'Hour at which business commences'
+ description: 'Hour at which business commences'
field :closes, String,
- description: 'Hour at which business ceaces'
+ description: 'Hour at which business ceaces'
def day_of_week
- object['dayOfWeek'].scan(/\/([^\/]*)$/)
- $1
+ object['dayOfWeek'].scan(%r{/([^/]*)$})
+ Regexp.last_match(1)
end
end
end
diff --git a/app/graphql/types/partner_type.rb b/app/graphql/types/partner_type.rb
index fe1ffc7b8..77201a698 100644
--- a/app/graphql/types/partner_type.rb
+++ b/app/graphql/types/partner_type.rb
@@ -65,7 +65,7 @@ def articles
end
def logo
- return nil unless object.logo_url.present?
+ return nil if object.logo_url.blank?
url = URI::HTTP.build(Rails.application.default_url_options)
url.scheme = Rails.application.default_url_options[:protocol]
diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb
index 569017ff7..7f4dcd5fb 100644
--- a/app/graphql/types/query_type.rb
+++ b/app/graphql/types/query_type.rb
@@ -1,10 +1,11 @@
+# frozen_string_literal: true
+
module Types
ID = GraphQL::Types::ID
module PartnerQueries
def self.included(klass)
-
- klass.field :partner, PartnerType do
+ klass.field :partner, PartnerType do
description 'Retrieve one Partner based on specific ID'
argument :id, ID
end
@@ -24,7 +25,7 @@ def partner(id:)
Partner.find(id)
end
- def partner_connection(**args)
+ def partner_connection(**_args)
Partner.all
end
@@ -35,9 +36,9 @@ def partners_by_tag(tag_id:)
module ArticleQueries
def self.included(klass)
- #klass.field :all_articles, [ArticleType] do
+ # klass.field :all_articles, [ArticleType] do
# description 'Return news articles from all sites for all partners'
- #end
+ # end
klass.field :article_connection, Types::ArticleType.connection_type do
description \
@@ -55,7 +56,7 @@ def self.included(klass)
end
end
- def article_connection(**args)
+ def article_connection(**_args)
Article.global_newsfeed
end
@@ -85,7 +86,7 @@ def site(id:)
Site.find(id)
end
- def site_connection(**args)
+ def site_connection(**_args)
Site.all
end
end
@@ -93,8 +94,8 @@ def site_connection(**args)
module MiscQueries
def self.included(klass)
klass.field :ping, String,
- null: false,
- description: "Ping server, returns a happy message and a timestamp"
+ null: false,
+ description: 'Ping server, returns a happy message and a timestamp'
end
def ping
@@ -103,7 +104,6 @@ def ping
end
class QueryType < Types::BaseObject
-
description "The base query schema for all of PlaceCal's GraphQL queries"
# Add `node(id: ID!) and `nodes(ids: [ID!]!)`
diff --git a/app/graphql/types/site_type.rb b/app/graphql/types/site_type.rb
index 9709f6e31..32a694f1f 100644
--- a/app/graphql/types/site_type.rb
+++ b/app/graphql/types/site_type.rb
@@ -1,29 +1,28 @@
+# frozen_string_literal: true
+
module Types
class SiteType < Types::BaseObject
-
description 'Sites represent a collection of neighbourhoods or service areas'
- field :id, ID,
- null: false,
- description: 'Internal reference ID'
+ field :id, ID,
+ null: false,
+ description: 'Internal reference ID'
field :name, String,
- null: false,
- description: 'Full name of site'
+ null: false,
+ description: 'Full name of site'
- field :slug, String,
- null: false,
- description: 'Short unique URL friendly version of name'
+ field :slug, String,
+ null: false,
+ description: 'Short unique URL friendly version of name'
field :domain, String,
- description: 'The public URL that this site can be found on PlaceCal'
+ description: 'The public URL that this site can be found on PlaceCal'
field :description, String,
- description: 'Longer description of site'
+ description: 'Longer description of site'
field :neighbourhoods, [NeighbourhoodType],
- description: 'The neighbourhoods that this site encompasses'
-
+ description: 'The neighbourhoods that this site encompasses'
end
end
-
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b7c9d17a9..db11e2a67 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
class StrongParametersFormBuilder < SimpleForm::FormBuilder
def input(attribute_name, options = {}, &block)
disabled = self.options[:disabled]
display_filter = self.options[:display_only]&.collect { |attr| attr.is_a?(Hash) ? attr.keys : attr }&.flatten
- if disabled && disabled.include?(attribute_name)
+ if disabled&.include?(attribute_name)
options[:disabled] = true
super
elsif display_filter
@@ -32,7 +33,7 @@ def admin_nav_link(name, path, icon = false)
end
def filtered_form_for(object, options = {}, &block)
- simple_form_for(object, options.merge(:builder => StrongParametersFormBuilder), &block)
+ simple_form_for(object, options.merge(builder: StrongParametersFormBuilder), &block)
end
def has_any_global_admin_links?
@@ -44,8 +45,8 @@ def has_any_global_admin_links?
def image_uploader_hint(uploader_field)
return if uploader_field.nil?
- sprintf(
- "Supported file formats: %s. Max file size: %s",
+ format(
+ 'Supported file formats: %s. Max file size: %s',
uploader_field.extension_allowlist.to_sentence,
number_to_human_size(uploader_field.size_range.max)
)
diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb
index 1a3d6da87..3a08da976 100644
--- a/app/helpers/articles_helper.rb
+++ b/app/helpers/articles_helper.rb
@@ -7,9 +7,9 @@ def options_for_partners
end
def article_partner_links(article)
- article.partners.map { |partner|
+ article.partners.map do |partner|
link_to(partner.name, partner_path(partner))
- }.join(' | ').html_safe
+ end.join(' | ').html_safe
end
def article_summary_text(article)
diff --git a/app/helpers/calendars_helper.rb b/app/helpers/calendars_helper.rb
index b12fad6b0..640be3b22 100644
--- a/app/helpers/calendars_helper.rb
+++ b/app/helpers/calendars_helper.rb
@@ -3,11 +3,11 @@
module CalendarsHelper
def options_for_organiser
org_opts = policy_scope(Partner)
- .order(:name)
- .collect { |opt| [ opt.name, opt.id ] }
+ .order(:name)
+ .collect { |opt| [opt.name, opt.id] }
- #[{ name: '', id: ''}] + org_opts
- [[ '(No Partner)', '', { disabled: true }]] + org_opts
+ # [{ name: '', id: ''}] + org_opts
+ [['(No Partner)', '', { disabled: true }]] + org_opts
end
def options_for_location
@@ -20,8 +20,8 @@ def options_for_importer
CalendarImporter::CalendarImporter::PARSERS
.dup
.keep_if { |parser| parser::PUBLIC }
- .map { |parser| [ parser::NAME, parser::KEY ] }
- .prepend([ '(Auto detect)', 'auto' ])
+ .map { |parser| [parser::NAME, parser::KEY] }
+ .prepend(['(Auto detect)', 'auto'])
end
def summarize_dates(dates)
diff --git a/app/helpers/map_helper.rb b/app/helpers/map_helper.rb
index 5672ba0ff..86a844e04 100644
--- a/app/helpers/map_helper.rb
+++ b/app/helpers/map_helper.rb
@@ -1,6 +1,6 @@
+# frozen_string_literal: true
module MapHelper
-
def args_for_map(map_points, site, style_mode, compact_mode)
data_for_markers = map_points.dup.reject(&:nil?).map do |mrkr|
{}.tap do |pin|
@@ -25,14 +25,14 @@ def args_for_map(map_points, site, style_mode, compact_mode)
def map_style_class(points, style_mode, compact_mode)
out = []
- case style_mode
- when :single
- out << 'map--single'
- when :multi
- out << 'map--multiple'
- else
- out << ((points.length > 1) ? 'map--multiple' : 'map--single')
- end
+ out << case style_mode
+ when :single
+ 'map--single'
+ when :multi
+ 'map--multiple'
+ else
+ (points.length > 1 ? 'map--multiple' : 'map--single')
+ end
out << 'map--compact' if compact_mode
out
end
@@ -42,15 +42,15 @@ def center(marker_data)
return marker_data.first[:position] if marker_data.length == 1
[
- marker_data.map { |p| p[:position][0] }.sum / marker_data.length,
- marker_data.map { |p| p[:position][1] }.sum / marker_data.length
+ marker_data.sum { |p| p[:position][0] } / marker_data.length,
+ marker_data.sum { |p| p[:position][1] } / marker_data.length
]
end
def api_token
return '' if Rails.env.test?
- token = ENV['MAPBOX_TOKEN']
+ token = ENV.fetch('MAPBOX_TOKEN', nil)
return token if token
raise 'MAPBOX_TOKEN is missing from ENV, please see .env.example'
@@ -69,4 +69,3 @@ def tileset_for_site_url(site)
"https://api.mapbox.com/styles/v1/placecal/#{tileset}/tiles/256/{z}/{x}/{y}@2x?access_token=#{api_token}"
end
end
-
diff --git a/app/jobs/calendar_importer/calendar_importer.rb b/app/jobs/calendar_importer/calendar_importer.rb
index 95f1f2355..f17fffe85 100644
--- a/app/jobs/calendar_importer/calendar_importer.rb
+++ b/app/jobs/calendar_importer/calendar_importer.rb
@@ -35,13 +35,13 @@ def parser
# This ensures that self.parser is set during calendar_importer_task
def validate_feed!
raise InaccessibleFeed, "The URL could not be reached for calendar #{@calendar.name}" unless url_accessible?
- raise UnsupportedFeed, 'The provided URL is not supported' unless parser.present?
+ raise UnsupportedFeed, 'The provided URL is not supported' if parser.blank?
end
def url_accessible?
response = HTTParty.get(@calendar.source, follow_redirects: true)
response.code == 200
- rescue
+ rescue StandardError
false
end
end
diff --git a/app/jobs/calendar_importer/calendar_importer_task.rb b/app/jobs/calendar_importer/calendar_importer_task.rb
index 3262427a1..89f61bb69 100644
--- a/app/jobs/calendar_importer/calendar_importer_task.rb
+++ b/app/jobs/calendar_importer/calendar_importer_task.rb
@@ -30,7 +30,6 @@ def run
calendar.flag_complete_import_job! notices, calendar_source.checksum, parser::KEY
end
-
private
def notices
@@ -73,7 +72,6 @@ def process_event(parsed_event)
active_event_uids << parsed_event.uid
parsed_event.save_all_occurences
-
rescue CalendarImporter::EventResolver::Problem => e
notices << e.message
end
diff --git a/app/jobs/calendar_importer/event_resolver.rb b/app/jobs/calendar_importer/event_resolver.rb
index 6efafb4bb..be0f87a98 100644
--- a/app/jobs/calendar_importer/event_resolver.rb
+++ b/app/jobs/calendar_importer/event_resolver.rb
@@ -57,7 +57,7 @@ def determine_location_for_strategy
'online_only' => :online_only_strategy
}
- if strategies.keys.include?(calendar.strategy)
+ if strategies.key?(calendar.strategy)
strategy = strategies[calendar.strategy]
place, address = method(strategy).call(calendar.place)
else
@@ -97,13 +97,13 @@ def event_strategy(place, address: nil)
# if the address failed to save
# Both of these will cause the event to fail validation with "No place or address could be created/found (etc)"
- else # no location
- raise Problem, WARNING2_MSG if place.present?
- # No longer an error if place is not present -- see #1198
- # Passthrough here
- end
+ elsif place.present?
+ raise Problem, WARNING2_MSG
+ end # no location
+ # No longer an error if place is not present -- see #1198
+ # Passthrough here
- return place, address
+ [place, address]
end
def event_override_strategy(place, address: nil)
@@ -120,19 +120,17 @@ def event_override_strategy(place, address: nil)
# NOTE: place is possibly unset here - fuzzy_find_by_location can be nil
# NOTE: address is possibly unset here - place might be nil or Address.search can return nil
# In either case we will just drop this event on the floor
- else # no location
- if place.present?
- # place = 'calendar.place'
- # address = 'calendar.place.address'
- # place = calendar.place
- address = place.address
-
- else # no place, no location
- raise Problem, WARNING1_MSG
- end
+ elsif place.present? # no location
+ address = place.address
+ # place = 'calendar.place'
+ # address = 'calendar.place.address'
+ # place = calendar.place
+
+ else # no place, no location
+ raise Problem, WARNING1_MSG
end
- return place, address
+ [place, address]
end
def place_strategy(_place, _address: nil)
@@ -148,7 +146,7 @@ def place_strategy(_place, _address: nil)
raise Problem, message if calendar.place.nil?
- return calendar.place, calendar.place.address
+ [calendar.place, calendar.place.address]
# NOTE: calendar.place can be nil, in which case this event will be dropped on the floor
# (Likely what is happening with Velociposse?)
@@ -169,27 +167,25 @@ def room_number_strategy(place, address: nil)
raise Problem, 'N/A'
end
- else # no location
- if place.present?
- # place = 'calendar.place'
- # address = 'calendar.place.address'
- # xx place = calendar.place.address
- address = place.address
+ elsif place.present? # no location
+ address = place.address
+ # place = 'calendar.place'
+ # address = 'calendar.place.address'
+ # xx place = calendar.place.address
- else # no place, no location
- raise Problem, 'N/A'
- end
+ else # no place, no location
+ raise Problem, 'N/A'
end
- return place, address
+ [place, address]
end
def no_location_strategy(_place, _address: nil)
- return nil, nil
+ [nil, nil]
end
def online_only_strategy(_place, _address: nil)
- return nil, nil
+ [nil, nil]
end
def save_all_occurences
@@ -238,8 +234,8 @@ def event_location_components
regexp = Regexp.new(regex_string, Regexp::IGNORECASE)
@event_location_components = (data.location || '')
- .split(', ')
- .map { |component| component.gsub(regexp, '').strip }
- .reject(&:blank?)
+ .split(', ')
+ .map { |component| component.gsub(regexp, '').strip }
+ .compact_blank
end
end
diff --git a/app/jobs/calendar_importer/events/base.rb b/app/jobs/calendar_importer/events/base.rb
index 3f8409864..0e69532a2 100644
--- a/app/jobs/calendar_importer/events/base.rb
+++ b/app/jobs/calendar_importer/events/base.rb
@@ -2,7 +2,7 @@
module CalendarImporter::Events
class Base
- ALLOWED_TAGS = %w[p a strong b em i ul ol li blockquote h3 h4 h5 h6 br]
+ ALLOWED_TAGS = %w[p a strong b em i ul ol li blockquote h3 h4 h5 h6 br].freeze
Dates = Struct.new(:start_time, :end_time, :status)
@@ -21,7 +21,7 @@ def rrule
def sanitize_invalid_char(input)
# input = I18n.transliterate(input)
- input.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '')
+ input.encode('utf-8', invalid: :replace, undef: :replace, replace: '')
end
# Convert h1 and h2 to h3
@@ -35,15 +35,15 @@ def html_sanitize(input)
input_mode = 'markdown'
doc = Nokogiri::HTML.fragment(clean_text)
- if doc.css('*').length > 0
+ if doc.css('*').length.positive?
input_mode = 'html'
# looks like HTML to us
- #if doc.errors.any? # this could be useful?
+ # if doc.errors.any? # this could be useful?
# puts 'errors found:'
# puts doc.errors
# return ''
- #end
+ # end
doc.css('h1', 'h2').each { |header| header.name = 'h3' }
@@ -60,17 +60,16 @@ def html_sanitize(input)
end
def attributes
- { uid: uid&.strip,
- summary: sanitize_invalid_char(summary),
- description: html_sanitize(description),
+ { uid: uid&.strip,
+ summary: sanitize_invalid_char(summary),
+ description: html_sanitize(description),
raw_location_from_source: location&.strip,
- rrule: rrule,
- place_id: place_id,
- address_id: address_id,
- partner_id: partner_id,
- publisher_url: publisher_url,
- online_address_id: online_address_id
- }
+ rrule: rrule,
+ place_id: place_id,
+ address_id: address_id,
+ partner_id: partner_id,
+ publisher_url: publisher_url,
+ online_address_id: online_address_id }
end
def footer; end
@@ -78,7 +77,7 @@ def footer; end
def publisher_url; end
def has_location?
- !location.blank?
+ location.present?
end
def recurring_event?
@@ -87,7 +86,9 @@ def recurring_event?
def postcode
postal = location.match(Address::POSTCODE_REGEX).try(:[], 0)
- postal = /M[1-9]{2}(?:\s)?(?:[1-9])?/.match(location).try(:[], 0) if postal.blank? # check for instances of M14 or M15 4 or whatever madness they've come up with
+ if postal.blank?
+ postal = /M[1-9]{2}(?:\s)?(?:[1-9])?/.match(location).try(:[], 0)
+ end # check for instances of M14 or M15 4 or whatever madness they've come up with
# TODO? Remove? This will currently do nothing because postcodes.io only
# works on postcodes and we have established that a postcode does not
@@ -110,12 +111,12 @@ def ip_class
end
def private?
- ip_class&.casecmp('private')&.zero? || (description&.include?('#placecal-ignore'))
+ ip_class&.casecmp('private')&.zero? || description&.include?('#placecal-ignore')
end
def online_event?
# TODO: Put in default here
- return nil
+ nil
end
end
end
diff --git a/app/jobs/calendar_importer/events/eventbrite_event.rb b/app/jobs/calendar_importer/events/eventbrite_event.rb
index e717a83e7..8e3b7d40f 100644
--- a/app/jobs/calendar_importer/events/eventbrite_event.rb
+++ b/app/jobs/calendar_importer/events/eventbrite_event.rb
@@ -39,7 +39,7 @@ def location
address['city'],
address['region'],
address['postal_code']
- ].reject(&:blank?).join(', ')
+ ].compact_blank.join(', ')
else
place['name']
end
diff --git a/app/jobs/calendar_importer/events/ics_event.rb b/app/jobs/calendar_importer/events/ics_event.rb
index 74fcbfa21..a398148f6 100644
--- a/app/jobs/calendar_importer/events/ics_event.rb
+++ b/app/jobs/calendar_importer/events/ics_event.rb
@@ -25,7 +25,7 @@ def description
text = @event.description
text = text.join(' ') if text.is_a?(Icalendar::Values::Array)
- text.to_s #.gsub(/\A(\n)+\z/, '').strip
+ text.to_s # .gsub(/\A(\n)+\z/, '').strip
end
def location
@@ -69,7 +69,7 @@ def online_event?
def have_direct_url_to_stream?(link)
# Oh my god why is ruby's iteration stuff so annoying
# also TODO: find a different name than "value"
- domain = event_link_types.keys.find(proc { nil }) { |domain| link.include?(domain) }
+ domain = event_link_types.keys.find(proc {}) { |domain| link.include?(domain) }
return event_link_types[domain][:type] if domain
@@ -79,18 +79,18 @@ def have_direct_url_to_stream?(link)
end
def find_event_link
- link_regexes = event_link_types.values.map { |v| v[:regex] }
+ link_regexes = event_link_types.values.pluck(:regex)
regex = Regexp.union link_regexes
regex.match description
end
def event_link_types
- http = %r{(http(s)?://)?} # - https:// or http:// or nothing
- alphanum = %r{[A-Za-z0-9]+} # - alphanumeric strings
- subdomain = %r{(#{alphanum}\.)?} # - matches the www. or us04web in the zoom link
- suffix = %r{[^\s<"]+} # - matches until we see a whitespace character,
- # an angle bracket, or a quote (thanks html)
+ http = %r{(http(s)?://)?} # - https:// or http:// or nothing
+ alphanum = /[A-Za-z0-9]+/ # - alphanumeric strings
+ subdomain = /(#{alphanum}\.)?/ # - matches the www. or us04web in the zoom link
+ suffix = /[^\s<"]+/ # - matches until we see a whitespace character,
+ # an angle bracket, or a quote (thanks html)
# We deal with the following strings:
# meet.jit.si/foobarbaz
@@ -102,10 +102,10 @@ def event_link_types
#
(event url)
{
- 'meet.jit.si' => { regex: %r{#{http}#{subdomain}meet.jit.si/#{suffix}}, type: 'direct' },
+ 'meet.jit.si' => { regex: %r{#{http}#{subdomain}meet.jit.si/#{suffix}}, type: 'direct' },
'meet.google.com' => { regex: %r{#{http}#{subdomain}meet.google.com/#{suffix}}, type: 'direct' },
- 'zoom.us' => { regex: %r{#{http}#{subdomain}zoom.us/j/#{suffix}}, type: 'direct' },
- 'facebook.com' => { regex: %r{#{http}#{subdomain}facebook.com/events/#{suffix}}, type: 'indirect' }
+ 'zoom.us' => { regex: %r{#{http}#{subdomain}zoom.us/j/#{suffix}}, type: 'direct' },
+ 'facebook.com' => { regex: %r{#{http}#{subdomain}facebook.com/events/#{suffix}}, type: 'indirect' }
}
end
end
diff --git a/app/jobs/calendar_importer/events/manchester_uni_event.rb b/app/jobs/calendar_importer/events/manchester_uni_event.rb
index e5fa93641..b04e3cfb1 100644
--- a/app/jobs/calendar_importer/events/manchester_uni_event.rb
+++ b/app/jobs/calendar_importer/events/manchester_uni_event.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module CalendarImporter::Events
class ManchesterUniEvent < Base
def initialize(event)
@@ -23,7 +25,7 @@ def dtstart
time = @event.at_xpath('./ns:times[@type="local"] //ns:start //ns:time')
DateTime.parse([date, time].join(', '))
rescue StandardError
- nil
+ nil
end
def dtend
@@ -31,7 +33,7 @@ def dtend
time = @event.at_xpath('./ns:times[@type="local"] //ns:end //ns:time')
DateTime.parse([date, time].join(', '))
rescue StandardError
- nil
+ nil
end
def recurring_event?
diff --git a/app/jobs/calendar_importer/events/meetup_event.rb b/app/jobs/calendar_importer/events/meetup_event.rb
index 8b9edf7f0..bafe43b17 100644
--- a/app/jobs/calendar_importer/events/meetup_event.rb
+++ b/app/jobs/calendar_importer/events/meetup_event.rb
@@ -36,7 +36,7 @@ def location
venue['city'],
venue['localized_country_name'],
venue['name'] # postcode?
- ].map(&:to_s).map(&:strip).reject(&:blank?).join(', ')
+ ].map(&:to_s).map(&:strip).compact_blank.join(', ')
end
end
diff --git a/app/jobs/calendar_importer/events/ticketsolve_event.rb b/app/jobs/calendar_importer/events/ticketsolve_event.rb
index 848f92e9b..d2b1aae3e 100644
--- a/app/jobs/calendar_importer/events/ticketsolve_event.rb
+++ b/app/jobs/calendar_importer/events/ticketsolve_event.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module CalendarImporter::Events
class TicketsolveEvent < Base
def uid
diff --git a/app/jobs/calendar_importer/parsers/base.rb b/app/jobs/calendar_importer/parsers/base.rb
index 1ab009e26..ae3a254d8 100644
--- a/app/jobs/calendar_importer/parsers/base.rb
+++ b/app/jobs/calendar_importer/parsers/base.rb
@@ -30,9 +30,7 @@ def calendar_to_events
data = download_calendar
checksum = digest(data)
- if !@force_import && (@calendar.last_checksum == checksum)
- return Output.new([], checksum)
- end
+ return Output.new([], checksum) if !@force_import && (@calendar.last_checksum == checksum)
Output.new(import_events_from(data), checksum)
end
diff --git a/app/jobs/calendar_importer/parsers/eventbrite.rb b/app/jobs/calendar_importer/parsers/eventbrite.rb
index 2fe17fd6c..acb038a7a 100644
--- a/app/jobs/calendar_importer/parsers/eventbrite.rb
+++ b/app/jobs/calendar_importer/parsers/eventbrite.rb
@@ -8,10 +8,10 @@ module CalendarImporter::Parsers
class Eventbrite < Base
NAME = 'Eventbrite'
KEY = 'eventbrite'
- DOMAINS = %w[www.eventbrite.com www.eventbrite.co.uk]
+ DOMAINS = %w[www.eventbrite.com www.eventbrite.co.uk].freeze
def self.whitelist_pattern
- /^https:\/\/www.eventbrite\.(com|co.uk)\/o\/[A-Za-z0-9-]+/
+ %r{^https://www.eventbrite\.(com|co.uk)/o/[A-Za-z0-9-]+}
end
def organizer_id
@@ -20,7 +20,7 @@ def organizer_id
end
def download_calendar
- EventbriteSDK.token = ENV['EVENTBRITE_TOKEN']
+ EventbriteSDK.token = ENV.fetch('EVENTBRITE_TOKEN', nil)
@events = []
results = EventbriteSDK::Organizer.retrieve(id: organizer_id).events.with_expansion(:venue).page(1)
diff --git a/app/jobs/calendar_importer/parsers/ics.rb b/app/jobs/calendar_importer/parsers/ics.rb
index 3482e0542..e00dde45f 100644
--- a/app/jobs/calendar_importer/parsers/ics.rb
+++ b/app/jobs/calendar_importer/parsers/ics.rb
@@ -15,7 +15,7 @@ class Ics < Base
outlook.live.com
ics.teamup.com
webcal://
- ]
+ ].freeze
def self.whitelist_pattern
whitelists = {
@@ -60,9 +60,8 @@ def digest(data)
def parse_remote_calendars(data)
Icalendar::Calendar.parse data
-
rescue StandardError => e
- # FIXME this should set an error flag that is checked by the importer and
+ # FIXME: this should set an error flag that is checked by the importer and
# logged to the calendar
[]
end
diff --git a/app/jobs/calendar_importer/parsers/manchester_uni.rb b/app/jobs/calendar_importer/parsers/manchester_uni.rb
index 545583d18..c1e32e5a2 100644
--- a/app/jobs/calendar_importer/parsers/manchester_uni.rb
+++ b/app/jobs/calendar_importer/parsers/manchester_uni.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# In order for a parser to be recognized, it must be added
# to the PARSERS constant list in app/models/calendar_parser.rb.
# Parent parser classes should not be added.
@@ -6,10 +8,10 @@ module CalendarImporter::Parsers
class ManchesterUni < Xml
PUBLIC = false
NAME = 'Manchester University'
- DOMAINS = %w[events.manchester.ac.uk]
+ DOMAINS = %w[events.manchester.ac.uk].freeze
def self.whitelist_pattern
- /^http(s)?:\/\/events.manchester.ac.uk\/f3vf\/calendar\/.*/
+ %r{^http(s)?://events.manchester.ac.uk/f3vf/calendar/.*}
end
def import_events_from(data)
@@ -21,6 +23,5 @@ def import_events_from(data)
events
end
-
end
end
diff --git a/app/jobs/calendar_importer/parsers/meetup.rb b/app/jobs/calendar_importer/parsers/meetup.rb
index ae4f92131..05b77cc08 100644
--- a/app/jobs/calendar_importer/parsers/meetup.rb
+++ b/app/jobs/calendar_importer/parsers/meetup.rb
@@ -8,15 +8,15 @@ module CalendarImporter::Parsers
class Meetup < Base
NAME = 'Meetup'
KEY = 'meetup'
- DOMAINS = %w[www.meetup.com]
+ DOMAINS = %w[www.meetup.com].freeze
def self.whitelist_pattern
- /^https:\/\/www\.meetup\.com\/[^\/]*\/?$/
+ %r{^https://www\.meetup\.com/[^/]*/?$}
end
def download_calendar
- user_name = (@url =~ /^https:\/\/www\.meetup\.com\/([^\/]*)\/?$/) && $1
- return [] unless user_name.present?
+ user_name = (@url =~ %r{^https://www\.meetup\.com/([^/]*)/?$}) && Regexp.last_match(1)
+ return [] if user_name.blank?
api_url = "https://api.meetup.com/#{user_name}/events"
response = HTTParty.get(api_url).body
diff --git a/app/jobs/calendar_importer/parsers/ticketsolve.rb b/app/jobs/calendar_importer/parsers/ticketsolve.rb
index 10fd6dcc3..33abaea65 100644
--- a/app/jobs/calendar_importer/parsers/ticketsolve.rb
+++ b/app/jobs/calendar_importer/parsers/ticketsolve.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# In order for a parser to be recognized, it must be added
# to the PARSERS constant list in app/models/calendar_parser.rb.
# Parent parser classes should not be added.
@@ -6,7 +8,7 @@ module CalendarImporter::Parsers
class Ticketsolve < Xml
NAME = 'Ticket Solve'
KEY = 'ticket-solve'
- DOMAINS = %w[*.ticketsolve.com]
+ DOMAINS = %w[*.ticketsolve.com].freeze
def self.whitelist_pattern
%r{^https?://([^.]*).ticketsolve.com/?}
@@ -21,6 +23,5 @@ def import_events_from(data)
@events
end
-
end
end
diff --git a/app/jobs/calendar_importer_job.rb b/app/jobs/calendar_importer_job.rb
index 41a38bfd0..1293ed9a3 100644
--- a/app/jobs/calendar_importer_job.rb
+++ b/app/jobs/calendar_importer_job.rb
@@ -1,17 +1,20 @@
+# frozen_string_literal: true
+
class CalendarImporterJob < ApplicationJob
queue_as :default
rescue_from CalendarImporter::CalendarImporter::UnsupportedFeed do |exception|
- report_error exception, "Calendar URL is not supported"
+ report_error exception, 'Calendar URL is not supported'
end
rescue_from CalendarImporter::CalendarImporter::InaccessibleFeed do |exception|
- report_error exception, "Calendar URL is not accessible"
+ report_error exception, 'Calendar URL is not accessible'
end
rescue_from ActiveRecord::ActiveRecordError do |exception|
- raise exception if Rails.env != 'production' && @silence_db_exceptions == false
- report_error exception, "Internal database error"
+ raise exception if !Rails.env.production? && @silence_db_exceptions == false
+
+ report_error exception, 'Internal database error'
end
def calendar
@@ -21,8 +24,7 @@ def calendar
# Imports all events from a given calendar
# @param calendar_id [int] The ID of the Calendar object to import from
# @param from_date [Date] The Date from which to import from
- def perform(calendar_id, from_date, force_import, silence_db_exceptions=false)
-
+ def perform(calendar_id, from_date, force_import, silence_db_exceptions = false)
Calendar.record_timestamps = false
@silence_db_exceptions = silence_db_exceptions
@@ -32,7 +34,7 @@ def perform(calendar_id, from_date, force_import, silence_db_exceptions=false)
print "Importing events for calendar #{calendar.name} (ID #{calendar.id})"
print " for place #{calendar.place.name} (ID #{calendar.place.id})" if calendar.place
- print " is forced" if force_import
+ print ' is forced' if force_import
print "\n"
# calendar.import_events(from)
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index 921a4fb86..16de3da18 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
+
class ApplicationMailer < ActionMailer::Base
default from: 'no-reply@placecal.org'
layout 'mailer'
end
-
diff --git a/app/mailers/join_mailer.rb b/app/mailers/join_mailer.rb
index 26050a0fb..3d61560ce 100644
--- a/app/mailers/join_mailer.rb
+++ b/app/mailers/join_mailer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class JoinMailer < ApplicationMailer
def join_us(join)
@join = join
diff --git a/app/models/address.rb b/app/models/address.rb
index c156973cd..48098bf9c 100644
--- a/app/models/address.rb
+++ b/app/models/address.rb
@@ -2,8 +2,7 @@
# app/models/address.rb
class Address < ApplicationRecord
-
- POSTCODE_REGEX = /\s*((GIR\s*0AA)|((([A-PR-UWYZ][0-9]{1,2})|(([A-PR-UWYZ][A-HK-Y][0-9]{1,2})|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))\s*[0-9][ABD-HJLNP-UW-Z]{2}))\s*/i
+ POSTCODE_REGEX = /\s*((GIR\s*0AA)|((([A-PR-UWYZ][0-9]{1,2})|(([A-PR-UWYZ][A-HK-Y][0-9]{1,2})|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))\s*[0-9][ABD-HJLNP-UW-Z]{2}))\s*/i.freeze
validates :street_address, :postcode, :country_code, presence: true
validates :postcode, format: { with: POSTCODE_REGEX, message: 'is invalid' }
@@ -40,27 +39,24 @@ def first_address_line
# Needed for schema.org outputs as streetAddress
def full_street_address
- [ street_address,
- street_address2,
- street_address3
- ].reject(&:blank?).join(', ')
+ [street_address,
+ street_address2,
+ street_address3].compact_blank.join(', ')
end
def other_address_lines
- [ street_address2,
- street_address3,
- city,
- postcode
- ].reject(&:blank?)
+ [street_address2,
+ street_address3,
+ city,
+ postcode].compact_blank
end
def all_address_lines
- [ street_address,
- street_address2,
- street_address3,
- city,
- postcode
- ].reject(&:blank?)
+ [street_address,
+ street_address2,
+ street_address3,
+ city,
+ postcode].compact_blank
end
def last_line_of_address
@@ -125,10 +121,10 @@ def build_from_components(components, postcode)
return if components.blank?
address = Address.new(
- street_address: components[0]&.strip,
+ street_address: components[0]&.strip,
street_address2: components[1]&.strip,
street_address3: components[2]&.strip,
- postcode: postcode
+ postcode: postcode
)
address if address.save
end
@@ -139,6 +135,7 @@ def build_from_components(components, postcode)
# before the final three characters.
def standardised_postcode(pc)
return unless pc
+
pc.gsub(/\s+/, '').strip.upcase.insert(-4, ' ')
end
end
diff --git a/app/models/article.rb b/app/models/article.rb
index c208f7d18..97ea58604 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -29,8 +29,8 @@ class Article < ApplicationRecord
scope :with_partner_tag, lambda { |tag_id|
joins('left outer join article_partners on articles.id=article_partners.article_id')
- .joins('left outer join partner_tags on article_partners.partner_id = partner_tags.partner_id')
- .where('partner_tags.tag_id = ?', tag_id)
+ .joins('left outer join partner_tags on article_partners.partner_id = partner_tags.partner_id')
+ .where('partner_tags.tag_id = ?', tag_id)
}
scope :with_tags, lambda { |tag_ids|
@@ -38,7 +38,6 @@ class Article < ApplicationRecord
}
scope :for_site, lambda { |site|
-
# this is a bit complicated but necessary
# the main problem to overcome is that we want articles by tag OR location
# (emphasis on OR).
@@ -75,9 +74,9 @@ class Article < ApplicationRecord
if site_neighbourhood_ids.any?
# TODO: service areas?
scope = scope
- .joins('LEFT OUTER JOIN article_partners ON articles.id=article_partners.article_id')
- .joins('LEFT OUTER JOIN partners ON article_partners.partner_id = partners.id')
- .joins('LEFT OUTER JOIN addresses ON partners.address_id = addresses.id')
+ .joins('LEFT OUTER JOIN article_partners ON articles.id=article_partners.article_id')
+ .joins('LEFT OUTER JOIN partners ON article_partners.partner_id = partners.id')
+ .joins('LEFT OUTER JOIN addresses ON partners.address_id = addresses.id')
where_fragments << 'addresses.neighbourhood_id IN (?)'
where_params << site_neighbourhood_ids
end
@@ -85,20 +84,20 @@ class Article < ApplicationRecord
# articles by tag
if site_tag_ids.any?
scope = scope
- .joins(' LEFT OUTER JOIN article_tags ON articles.id=article_tags.article_id')
+ .joins(' LEFT OUTER JOIN article_tags ON articles.id=article_tags.article_id')
where_fragments << 'article_tags.tag_id IN (?)'
where_params << site_tag_ids
end
# combine conditions with params to extend the scope
scope = scope
- .where("(#{where_fragments.join(' OR ')})", *where_params)
+ .where("(#{where_fragments.join(' OR ')})", *where_params)
scope.distinct('articles.id')
}
def update_published_at
- self.published_at = self.is_draft ? nil : DateTime.now
+ self.published_at = is_draft ? nil : DateTime.now
end
# This retrieves the author's name for use in the GQL output
@@ -114,6 +113,6 @@ def highres_image
end
def slug_candidates
- [ %i[title id] ]
+ [%i[title id]]
end
end
diff --git a/app/models/article_partner.rb b/app/models/article_partner.rb
index c7e483fef..48af9be66 100644
--- a/app/models/article_partner.rb
+++ b/app/models/article_partner.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ArticlePartner < ApplicationRecord
belongs_to :article
belongs_to :partner
diff --git a/app/models/article_tag.rb b/app/models/article_tag.rb
index f4603e9a5..96ab77757 100644
--- a/app/models/article_tag.rb
+++ b/app/models/article_tag.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ArticleTag < ApplicationRecord
belongs_to :article
belongs_to :tag
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index e9fa7930a..5d7c9e49e 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
# app/models/calendar.rb
class Calendar < ApplicationRecord
include ActionView::Helpers::DateHelper
include Validation
extend Enumerize
- CALENDAR_REGEX = /\A(?:(?:(https?|webcal)):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
+ CALENDAR_REGEX = %r{\A(?:(?:(https?|webcal))://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:/[^\s]*)?\z}i.freeze
self.inheritance_column = nil
@@ -45,7 +46,6 @@ class Calendar < ApplicationRecord
scope :where_idle, -> { where(calendar_state: :idle) }
scope :where_errored, -> { where(calendar_state: :error) }
-
# We need a default location for some strategies
def requires_default_location?
%i[place room_number event_override].include? strategy.to_sym
@@ -55,10 +55,10 @@ def requires_default_location?
# This uses PaperTrail to get historical records of the Event models, including deletes
# It does this to show a "event added" / "event removed" thing
def recent_activity
- versions = PaperTrail::Version.with_item_keys('Event', self.event_ids).where('created_at >= ?', 2.weeks.ago)
+ versions = PaperTrail::Version.with_item_keys('Event', event_ids).where('created_at >= ?', 2.weeks.ago)
versions = versions.or(PaperTrail::Version.destroys
.where("item_type = 'Event' AND object @> ? AND created_at >= ?",
- { calendar_id: self.id }.to_json, 2.weeks.ago))
+ { calendar_id: id }.to_json, 2.weeks.ago))
versions = versions.order(created_at: :desc).group_by { |version| version.created_at.to_date }
end
@@ -71,11 +71,11 @@ def events_this_week
# Who should be contacted about this calendar?
def contact_information
if public_contact_email
- [ public_contact_email, public_contact_name ]
+ [public_contact_email, public_contact_name]
elsif partner&.public_email
- [ partner.public_email, partner.public_name ]
+ [partner.public_email, partner.public_name]
elsif place&.public_email
- [ place.public_email, place.public_name ]
+ [place.public_email, place.public_name]
else
false
end
@@ -99,7 +99,6 @@ def source_supported
# The calendar importer will raise an exception if the source
# URL has a problem
CalendarImporter::CalendarImporter.new(self)
-
rescue CalendarImporter::CalendarImporter::InaccessibleFeed, CalendarImporter::CalendarImporter::UnsupportedFeed => e
flag_error_import_job! e.to_s
end
@@ -122,7 +121,7 @@ def queue_for_import!(force_import, from_date)
update! calendar_state: :in_queue
- CalendarImporterJob.perform_later self.id, from_date, force_import
+ CalendarImporterJob.perform_later id, from_date, force_import
end
end
@@ -132,6 +131,7 @@ def queue_for_import!(force_import, from_date)
def flag_start_import_job!
transaction do
return unless calendar_state.in_queue?
+
update! calendar_state: :in_worker
end
end
diff --git a/app/models/concerns/html_render_cache.rb b/app/models/concerns/html_render_cache.rb
index f112c5106..09d5f8041 100644
--- a/app/models/concerns/html_render_cache.rb
+++ b/app/models/concerns/html_render_cache.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module HtmlRenderCache
extend ActiveSupport::Concern
@@ -27,17 +28,17 @@ def render_html_fields
if changed.include?(field_name.to_s)
value = changes[field_name.to_s][1]
html = Kramdown::Document.new(value).to_html
- write_attribute cache_name, html
+ self[cache_name] = html
next
end
# puts attributes.to_json
- if @force_html_generation
- value = attributes[field_name.to_s].to_s
- html = Kramdown::Document.new(value).to_html
- write_attribute cache_name, html
- end
+ next unless @force_html_generation
+
+ value = attributes[field_name.to_s].to_s
+ html = Kramdown::Document.new(value).to_html
+ self[cache_name] = html
end
end
end
diff --git a/app/models/concerns/validation.rb b/app/models/concerns/validation.rb
index e9121faf5..b4b1ebab9 100644
--- a/app/models/concerns/validation.rb
+++ b/app/models/concerns/validation.rb
@@ -1,11 +1,13 @@
+# frozen_string_literal: true
+
module Validation
- URL_REGEX = /\A(?:(?:https?):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
+ URL_REGEX = %r{\A(?:(?:https?)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:/[^\s]*)?\z}i.freeze
- TWITTER_REGEX = /\A@?(\w){1,15}\z/
+ TWITTER_REGEX = /\A@?(\w){1,15}\z/.freeze
- FACEBOOK_REGEX = /\A(\w){1,50}\z/
+ FACEBOOK_REGEX = /\A(\w){1,50}\z/.freeze
- UK_NUMBER_REGEX = /\A(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?\z/
+ UK_NUMBER_REGEX = /\A(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?\z/.freeze
- EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
+ EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i.freeze
end
diff --git a/app/models/event.rb b/app/models/event.rb
index 42ddd2c5b..70201a034 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -86,7 +86,7 @@ class Event < ApplicationRecord
scope :sort_by_summary, -> { order(summary: :asc).order(:dtstart) }
scope :sort_by_time, -> { order(dtstart: :asc).order(summary: :asc) }
- scope :without_matching_times, ->(start_times, end_times) {
+ scope :without_matching_times, lambda { |start_times, end_times|
where.not(dtstart: start_times).or(where.not(dtend: end_times))
}
@@ -110,7 +110,7 @@ def sanitize_rrule
def time
if dtend
- dtstart.strftime('%H:%M') + ' – ' + dtend.strftime('%H:%M')
+ "#{dtstart.strftime('%H:%M')} – #{dtend.strftime('%H:%M')}"
else
dtstart.strftime('%H:%M')
end
@@ -166,10 +166,10 @@ def require_location
return if %w[event no_location online_only].include?(calendar&.strategy)
# If we have an online address we don't need a physical one
- return if self.online_address_id.present?
+ return if online_address_id.present?
# If the address exists then the error doesn't apply
- return unless self.address_id.blank?
+ return if address_id.present?
errors.add(:base, 'No place or address could be created or found for ' \
"the event location: #{raw_location_from_source}")
diff --git a/app/models/join.rb b/app/models/join.rb
index ca49e6a88..70186cc27 100644
--- a/app/models/join.rb
+++ b/app/models/join.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Join
include ActiveModel::Model
@@ -9,10 +11,9 @@ class Join
def submit
if valid?
JoinMailer.join_us(self).deliver
- return true
+ true
else
- return false
+ false
end
end
end
-
diff --git a/app/models/neighbourhood.rb b/app/models/neighbourhood.rb
index 9bb88456b..c4a7dd5f3 100644
--- a/app/models/neighbourhood.rb
+++ b/app/models/neighbourhood.rb
@@ -10,9 +10,9 @@ class Neighbourhood < ApplicationRecord
has_many :service_areas, dependent: :destroy
has_many :service_area_partners,
- through: :service_areas,
- source: :partner,
- class_name: 'Partner'
+ through: :service_areas,
+ source: :partner,
+ class_name: 'Partner'
# validates :name, presence: true
validates :unit_code_value,
@@ -27,7 +27,7 @@ def shortname
elsif name.present?
name
else
- "[not set]"
+ '[not set]'
end
end
@@ -57,7 +57,7 @@ def fullname
# == Returns
# A string of the name
def abbreviated_name
- name_abbr.present? ? name_abbr : name
+ name_abbr.presence || name
end
# normalize abbreviated names (usually coming from calendar
@@ -72,7 +72,7 @@ def abbreviated_name
def name_abbr=(value)
value = value.to_s.strip
- self['name_abbr'] = value.present? ? value : nil
+ self['name_abbr'] = value.presence
end
def to_s
diff --git a/app/models/organisation_relationship.rb b/app/models/organisation_relationship.rb
index aff6d1a51..a1e34667b 100644
--- a/app/models/organisation_relationship.rb
+++ b/app/models/organisation_relationship.rb
@@ -4,6 +4,7 @@ class OrganisationRelationship < ApplicationRecord
self.table_name = 'organisation_relationships'
belongs_to :subject, class_name: 'Partner'
- extend Enumerize; enumerize :verb, in: %i[manages]
+ extend Enumerize
+ enumerize :verb, in: %i[manages]
belongs_to :object, class_name: 'Partner'
end
diff --git a/app/models/partner.rb b/app/models/partner.rb
index d61a7f3c7..af99ef814 100644
--- a/app/models/partner.rb
+++ b/app/models/partner.rb
@@ -23,9 +23,9 @@ class Partner < ApplicationRecord
has_many :service_areas, dependent: :destroy
has_many :service_area_neighbourhoods,
- through: :service_areas,
- source: :neighbourhood,
- class_name: 'Neighbourhood'
+ through: :service_areas,
+ source: :neighbourhood,
+ class_name: 'Neighbourhood'
validates_associated :service_areas
@@ -65,7 +65,7 @@ class Partner < ApplicationRecord
}
validates :summary,
presence: {
- if: ->(p) { !p.description.blank? },
+ if: ->(p) { p.description.present? },
message: 'cannot have a description without a summary'
}
validates :url,
@@ -127,8 +127,8 @@ class Partner < ApplicationRecord
site_tag_ids = site.tags.map(&:id)
if site_tag_ids.any?
query = query
- .left_joins(:partner_tags)
- .where("partner_tags.tag_id in (?)", site_tag_ids)
+ .left_joins(:partner_tags)
+ .where('partner_tags.tag_id in (?)', site_tag_ids)
end
# now look for addresses and service areas
@@ -141,7 +141,8 @@ class Partner < ApplicationRecord
.left_joins(:address, :service_areas)
.where(
'(service_areas.neighbourhood_id in (:neighbourhood_ids) OR addresses.neighbourhood_id in (:neighbourhood_ids))',
- neighbourhood_ids: site_neighbourhood_ids)
+ neighbourhood_ids: site_neighbourhood_ids
+ )
.distinct
}
@@ -149,11 +150,11 @@ class Partner < ApplicationRecord
return none if tag.nil?
query = Partner
- .select('"partners".*, LOWER("partners"."name") as sortable_name')
+ .select('"partners".*, LOWER("partners"."name") as sortable_name')
query = query
- .left_joins(:partner_tags)
- .where(partner_tags: { tag: tag })
+ .left_joins(:partner_tags)
+ .where(partner_tags: { tag: tag })
# now look for addresses and service areas
site_neighbourhood_ids = site.owned_neighbourhoods.map(&:id)
@@ -167,7 +168,8 @@ class Partner < ApplicationRecord
.left_joins(:address, :service_areas)
.where(
'(service_areas.neighbourhood_id in (:neighbourhood_ids) OR addresses.neighbourhood_id in (:neighbourhood_ids))',
- neighbourhood_ids: site_neighbourhood_ids)
+ neighbourhood_ids: site_neighbourhood_ids
+ )
.distinct
.order('sortable_name')
}
@@ -176,15 +178,15 @@ class Partner < ApplicationRecord
#
# @param tags [Array] A list of tags
# @return [ActiveRecord::Relation]
- scope :with_tags, ->(tag_ids) {
+ scope :with_tags, lambda { |tag_ids|
left_joins(:partner_tags)
- .where("partner_tags.tag_id in (?)", tag_ids)
+ .where('partner_tags.tag_id in (?)', tag_ids)
}
# only select partners that have addresses
- scope :with_address, -> do
- where('address_id is not null')
- end
+ scope :with_address, lambda {
+ where.not(address_id: nil)
+ }
# Get all Partners that have hosted an event in the last month or will host
# an event in the future
@@ -192,16 +194,16 @@ class Partner < ApplicationRecord
# TODO? This might be an incredibly inefficient query. If so, add a column
# to the Partner table, e.g. place_latest_dtstart, which can be updated on
# import.
- scope :event_hosts, -> do
+ scope :event_hosts, lambda {
joins('JOIN events ON events.place_id = partners.id')
.where('events.dtstart > ?', Date.today - 30).distinct
- end
+ }
# Get all Partners that manage at least one other Partner.
- scope :managers, -> do
+ scope :managers, lambda {
joins('JOIN organisation_relationships o_r on o_r.subject_id = partners.id')
.where(o_r: { verb: :manages }).distinct
- end
+ }
delegate :neighbourhood_id, to: :address, allow_nil: true
@@ -211,9 +213,9 @@ def twitter_handle=(handle)
def address_attributes=(value)
addr = Address
- .where('lower(street_address) = ?', value[:street_address]&.downcase&.strip)
- .where(postcode: value[:postcode]&.upcase&.strip)
- .first
+ .where('lower(street_address) = ?', value[:street_address]&.downcase&.strip)
+ .where(postcode: value[:postcode]&.upcase&.strip)
+ .first
if addr.present?
self.address = addr
@@ -245,7 +247,7 @@ def should_generate_new_friendly_id?
end
def has_service_areas?
- service_areas.count > 0
+ service_areas.count.positive?
end
def permalink
@@ -276,7 +278,7 @@ def opening_times_data
end
def human_readable_opening_times
- return [] if !opening_times || opening_times.length == 0
+ return [] if !opening_times || opening_times.length.zero?
JSON.parse(opening_times).map do |s|
d = s['dayOfWeek'].split('/').last
@@ -286,7 +288,6 @@ def human_readable_opening_times
#{o} – #{c}
).html_safe
end
-
rescue JSON::ParserError
[]
end
@@ -323,7 +324,7 @@ def self.fuzzy_find_by_location(components)
def check_ward_access
return if accessed_by_user.nil? || accessed_by_user.root?
- return unless address.present?
+ return if address.blank?
unless accessed_by_user.assigned_to_postcode?(address&.postcode)
errors.add :base, 'Partners cannot have an address outside of your ward.'
diff --git a/app/models/service_area.rb b/app/models/service_area.rb
index e5d1d8fbd..627e799bd 100644
--- a/app/models/service_area.rb
+++ b/app/models/service_area.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
class ServiceArea < ApplicationRecord
belongs_to :neighbourhood
belongs_to :partner
- validates_uniqueness_of :partner, scope: :neighbourhood
+ validates :partner, uniqueness: { scope: :neighbourhood }
end
diff --git a/app/models/site.rb b/app/models/site.rb
index 511e280c5..be9563740 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -10,10 +10,14 @@ class Site < ApplicationRecord
friendly_id :name, use: :slugged
has_one :sites_neighbourhood, dependent: :destroy
- has_one :primary_neighbourhood, -> { where(sites_neighbourhoods: { relation_type: 'Primary' }) }, source: :neighbourhood, through: :sites_neighbourhood
+ has_one :primary_neighbourhood, lambda {
+ where(sites_neighbourhoods: { relation_type: 'Primary' })
+ }, source: :neighbourhood, through: :sites_neighbourhood
has_many :sites_neighbourhoods, dependent: :destroy
- has_many :secondary_neighbourhoods, -> { where(sites_neighbourhoods: { relation_type: 'Secondary' }) }, source: :neighbourhood, through: :sites_neighbourhoods
+ has_many :secondary_neighbourhoods, lambda {
+ where(sites_neighbourhoods: { relation_type: 'Secondary' })
+ }, source: :neighbourhood, through: :sites_neighbourhoods
has_many :neighbourhoods, through: :sites_neighbourhoods
@@ -25,7 +29,9 @@ class Site < ApplicationRecord
belongs_to :site_admin, class_name: 'User', optional: true
accepts_nested_attributes_for :sites_neighbourhood
- accepts_nested_attributes_for :sites_neighbourhoods, reject_if: ->(c) { c[:neighbourhood_id].blank? }, allow_destroy: true
+ accepts_nested_attributes_for :sites_neighbourhoods, reject_if: lambda { |c|
+ c[:neighbourhood_id].blank?
+ }, allow_destroy: true
validates :name, :slug, :domain, presence: true
validates :place_name unless :default_site?
@@ -68,7 +74,7 @@ def default_site?
# ASSUMPTION: All valid sites, other than the default site, are local sites.
def local_site?
- not default_site?
+ !default_site?
end
# Should we show the neighbourhood lozenge out on this site?
diff --git a/app/models/sites_supporter.rb b/app/models/sites_supporter.rb
index 032ae6cb6..cd6ec2f61 100644
--- a/app/models/sites_supporter.rb
+++ b/app/models/sites_supporter.rb
@@ -4,7 +4,7 @@
class SitesSupporter < ApplicationRecord
belongs_to :supporter
belongs_to :site
- validates_uniqueness_of :supporter_id,
- scope: :site_id,
- message: 'Supporters can not be assigned more than once to a site'
+ validates :supporter_id,
+ uniqueness: { scope: :site_id,
+ message: 'Supporters can not be assigned more than once to a site' }
end
diff --git a/app/models/supporter.rb b/app/models/supporter.rb
index 53ad63870..e4c3adaef 100644
--- a/app/models/supporter.rb
+++ b/app/models/supporter.rb
@@ -4,7 +4,7 @@
class Supporter < ApplicationRecord
has_and_belongs_to_many :sites
- validates_presence_of :name
+ validates :name, presence: true
default_scope { order(:weight) }
scope :global, -> { where(is_global: true) }
diff --git a/app/models/user.rb b/app/models/user.rb
index 426eb03e1..4ac3e75c6 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -40,12 +40,12 @@ class User < ApplicationRecord
# General use throughout the site
def full_name
- [first_name, last_name].reject(&:blank?).join(' ')
+ [first_name, last_name].compact_blank.join(' ')
end
# Shows in admin interfaces
def admin_name
- name = [last_name&.upcase, first_name].reject(&:blank?).join(', ')
+ name = [last_name&.upcase, first_name].compact_blank.join(', ')
"#{name} <#{email}>".strip
end
diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb
index bc4dfb227..ef74098ab 100644
--- a/app/policies/calendar_policy.rb
+++ b/app/policies/calendar_policy.rb
@@ -20,6 +20,7 @@ def edit?
def update?
return true if user.root?
return true if user.partner_admin? && user.partner_ids.include?(record.partner_id)
+
# return true if user.neighbourhood_admin? && user.neighbourhoods.include?(record.address.neighbourhood)
index?
end
@@ -44,7 +45,7 @@ def resolve
Calendar.left_outer_joins(partner: :address, place: :address)
.where(addresses: { neighbourhood_id: user.owned_neighbourhood_ids })
.or(Calendar.left_outer_joins(partner: :address, place: :address)
- .where("partner_id IN (:partner_id) OR place_id IN (:partner_id)", partner_id: user.partner_ids))
+ .where('partner_id IN (:partner_id) OR place_id IN (:partner_id)', partner_id: user.partner_ids))
.distinct
end
end
diff --git a/app/policies/partner_policy.rb b/app/policies/partner_policy.rb
index d0eb54cc6..08a4bea89 100644
--- a/app/policies/partner_policy.rb
+++ b/app/policies/partner_policy.rb
@@ -42,15 +42,15 @@ def setup?
end
def permitted_attributes
- attrs = [ :name, :image, :summary, :description, :accessibility_info,
- :public_name, :public_email, :public_phone,
- :partner_name, :partner_email, :partner_phone,
- :address_id, :url, :facebook_link, :twitter_handle,
- :opening_times,
- calendars_attributes: %i[id name source strategy place_id partner_id _destroy],
- address_attributes: %i[id street_address street_address2 street_address3 city postcode],
- service_areas_attributes: %i[id neighbourhood_id _destroy],
- tag_ids: [] ]
+ attrs = [:name, :image, :summary, :description, :accessibility_info,
+ :public_name, :public_email, :public_phone,
+ :partner_name, :partner_email, :partner_phone,
+ :address_id, :url, :facebook_link, :twitter_handle,
+ :opening_times,
+ { calendars_attributes: %i[id name source strategy place_id partner_id _destroy],
+ address_attributes: %i[id street_address street_address2 street_address3 city postcode],
+ service_areas_attributes: %i[id neighbourhood_id _destroy],
+ tag_ids: [] }]
attrs << :slug if user.root?
attrs
@@ -64,7 +64,7 @@ def resolve
else
user_neighbourhood_ids = user.owned_neighbourhood_ids
- clause = <<-SQL
+ clause = <<-SQL.squish
partners_users.user_id = ?
OR addresses.neighbourhood_id IN (?)
OR service_areas.neighbourhood_id IN (?)
diff --git a/app/policies/tag_policy.rb b/app/policies/tag_policy.rb
index 15a7f9543..3151daa5b 100644
--- a/app/policies/tag_policy.rb
+++ b/app/policies/tag_policy.rb
@@ -26,7 +26,6 @@ def update?
# If the user is a tag admin and has been assigned this tag
return true if user.tag_admin? && user.tags.include?(@record)
-
# NB: We literally can't filter by partners added because otherwise itll wipe existing partners
#
# If the user is a partner admin and the tag is generally available for use
diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb
index 8439e61bc..55b272724 100644
--- a/app/uploaders/avatar_uploader.rb
+++ b/app/uploaders/avatar_uploader.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AvatarUploader < DefaultUploader
# Process files as they are uploaded:
process resize_to_fit: [1200, 1200]
diff --git a/app/uploaders/default_uploader.rb b/app/uploaders/default_uploader.rb
index d4297e34a..753e55875 100644
--- a/app/uploaders/default_uploader.rb
+++ b/app/uploaders/default_uploader.rb
@@ -11,6 +11,6 @@ def store_dir
# remember to change this in nginx.conf.d/increase_upload_size.conf
def size_range
- 1.byte..10.megabytes
+ (1.byte)..(10.megabytes)
end
end
diff --git a/bin/setup b/bin/setup
index 0cc3e3170..4a59a9d3f 100755
--- a/bin/setup
+++ b/bin/setup
@@ -19,9 +19,7 @@ FileUtils.chdir APP_ROOT do
system! 'bin/yarn install'
puts "\n== Copying sample files =="
- unless File.exist?('.env')
- FileUtils.cp '.env.example', '.env'
- end
+ FileUtils.cp '.env.example', '.env' unless File.exist?('.env')
puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
diff --git a/bin/test b/bin/test
new file mode 100755
index 000000000..d42ada52e
--- /dev/null
+++ b/bin/test
@@ -0,0 +1,70 @@
+#!/usr/bin/env ruby
+require 'fileutils'
+
+# path to your application root.
+APP_ROOT = File.expand_path('..', __dir__)
+
+@options = {}
+
+def process_argv(option)
+ case option
+ when "-h"
+ when "--help"
+ puts "Run the tests."
+ puts " -u, --unit Run unit tests"
+ puts " -s, --system Run system tests"
+ puts " --no-lint Disable linters and formatters"
+ puts " --no-fix Lint and format without autocorrection"
+ exit
+ when "-u"
+ when "--unit"
+ @options[:unit_only] = true
+ when "-s"
+ when "--system"
+ @options[:system_only] = true
+ when "--no-lint"
+ @options[:without_lint] = true
+ when "--no-fix"
+ @options[:without_fix] = true
+ end
+end
+
+ARGV.each { |option| process_argv(option) }
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+FileUtils.chdir APP_ROOT do
+ # This script is a way to run the tests and linters.
+ # Add necessary test steps to this file.
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:test:prepare'
+
+ puts "\n== Building assets =="
+ system! 'bin/yarn run build'
+
+ if @options[:unit_only]
+ puts "\n== Running unit tests =="
+ system! 'bin/rails test'
+ elsif @options[:system_only]
+ puts "\n== Running system tests =="
+ system! 'bin/rails test:system'
+ else
+ puts "\n== Running all tests =="
+ system! 'bin/rails test:all'
+ end
+
+ unless @options[:without_lint]
+ if @options[:without_fix]
+ puts "\n== Running formatters and linters =="
+ system! 'bin/yarn run format:check'
+ system! 'bin/bundle exec rubocop'
+ else
+ puts "\n== Running formatters and linters (in autocorrect mode) =="
+ system! 'bin/yarn run format'
+ system! 'bin/bundle exec rubocop --autocorrect'
+ end
+ end
+end
diff --git a/bin/yarn b/bin/yarn
index a6eb079f1..948629b57 100755
--- a/bin/yarn
+++ b/bin/yarn
@@ -1,11 +1,9 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
- begin
- exec "yarnpkg", *ARGV
- rescue Errno::ENOENT
- $stderr.puts "Yarn executable was not detected in the system."
- $stderr.puts "Download Yarn at https://classic.yarnpkg.com/en/docs/install"
- exit 1
- end
+ exec 'yarnpkg', *ARGV
+rescue Errno::ENOENT
+ warn 'Yarn executable was not detected in the system.'
+ warn 'Download Yarn at https://classic.yarnpkg.com/en/docs/install'
+ exit 1
end
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 8af810221..e15420d01 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -87,7 +87,7 @@
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
- if ENV["RAILS_LOG_TO_STDOUT"].present?
+ if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
@@ -124,8 +124,8 @@
address: 'smtp.mailersend.net',
port: 587,
domain: host,
- user_name: ENV['MAILERSEND_USERNAME'],
- password: ENV['MAILERSEND_PASSWORD'],
+ user_name: ENV.fetch('MAILERSEND_USERNAME', nil),
+ password: ENV.fetch('MAILERSEND_PASSWORD', nil),
authentication: :login,
enable_starttls_auto: true
}
diff --git a/config/environments/staging.rb b/config/environments/staging.rb
index d008bea37..71528db3e 100644
--- a/config/environments/staging.rb
+++ b/config/environments/staging.rb
@@ -69,8 +69,8 @@
address: 'smtp.mailersend.net',
port: 587,
domain: host,
- user_name: ENV['MAILERSEND_USERNAME'],
- password: ENV['MAILERSEND_PASSWORD'],
+ user_name: ENV.fetch('MAILERSEND_USERNAME', nil),
+ password: ENV.fetch('MAILERSEND_PASSWORD', nil),
authentication: :login,
enable_starttls_auto: true
}
diff --git a/config/environments/test.rb b/config/environments/test.rb
index c3d59c5e6..85b4c6da0 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
index 89d2efab2..f4556db39 100644
--- a/config/initializers/application_controller_renderer.rb
+++ b/config/initializers/application_controller_renderer.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index 330082e28..6fd0f6b0b 100644
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
index 59385cdf3..d0f0d3b5d 100644
--- a/config/initializers/backtrace_silencers.rb
+++ b/config/initializers/backtrace_silencers.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb
index 41c43016f..98230c980 100644
--- a/config/initializers/content_security_policy.rb
+++ b/config/initializers/content_security_policy.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy
diff --git a/config/initializers/icalendar_overrides.rb b/config/initializers/icalendar_overrides.rb
index 81a8960ef..59c25d931 100644
--- a/config/initializers/icalendar_overrides.rb
+++ b/config/initializers/icalendar_overrides.rb
@@ -2,9 +2,9 @@
Icalendar::Recurrence::Schedule.class_eval do
def timezone
- #Timezone is missing or incorrectly set.
- #Check to see if custom properties contains invalid tzid property (ex. Mossley Community Center calendar)
- #and verify it matches default timezone (Europe/London)
+ # Timezone is missing or incorrectly set.
+ # Check to see if custom properties contains invalid tzid property (ex. Mossley Community Center calendar)
+ # and verify it matches default timezone (Europe/London)
return Time.zone.name if event.tzid.blank? || (event.parent.custom_properties['tzid']&.first == Time.zone.name)
ActiveSupport::TimeZone[event.tzid].present? ? event.tzid : Time.zone.name
diff --git a/config/initializers/markdown_handler.rb b/config/initializers/markdown_handler.rb
index dbb9fcbb4..df7f0f462 100644
--- a/config/initializers/markdown_handler.rb
+++ b/config/initializers/markdown_handler.rb
@@ -6,7 +6,7 @@ def self.erb
@erb ||= ActionView::Template.registered_template_handler(:erb)
end
- def self.call(template, source)
+ def self.call(template, _source)
compiled_source = erb.call(template)
"Kramdown::Document.new(begin;#{compiled_source};end, auto_ids: false).to_html.html_safe"
end
diff --git a/config/initializers/new_framework_defaults_6_0.rb b/config/initializers/new_framework_defaults_6_0.rb
index 92240ef5f..a48d4eb00 100644
--- a/config/initializers/new_framework_defaults_6_0.rb
+++ b/config/initializers/new_framework_defaults_6_0.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 6.0 upgrade.
diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb
index 62b5d97b3..4065c0896 100644
--- a/config/initializers/rollbar.rb
+++ b/config/initializers/rollbar.rb
@@ -4,7 +4,7 @@
# Without configuration, Rollbar is enabled in all environments.
# To disable in specific environments, set config.enabled=false.
- config.access_token = ENV['ROLLBAR_ACCESS_TOKEN']
+ config.access_token = ENV.fetch('ROLLBAR_ACCESS_TOKEN', nil)
# Here we'll disable in 'test':
config.enabled = false if Rails.env.development? || Rails.env.test?
@@ -58,7 +58,7 @@
config.exception_level_filters.merge!('ActionController::RoutingError' => lambda do |error|
error.message =~ %r{No route matches \[[A-Z]+\] "/(.+)"}
case Regexp.last_match(1).split('/').first.to_s.downcase
- when *%w[old gate.php wp-includes mifs vendor epa]
+ when 'old', 'gate.php', 'wp-includes', 'mifs', 'vendor', 'epa'
'ignore'
else
'warning'
diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb
index 2c5270384..10c83e731 100644
--- a/config/initializers/simple_form.rb
+++ b/config/initializers/simple_form.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
#
# Uncomment this and change the path if necessary to include your own
# components.
@@ -14,7 +15,7 @@
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, class: :input,
- hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
+ hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb
index 0178fd53c..9e79d8116 100644
--- a/config/initializers/simple_form_bootstrap.rb
+++ b/config/initializers/simple_form_bootstrap.rb
@@ -21,7 +21,7 @@
config.boolean_label_class = 'form-check-label'
# How the label text should be generated altogether with the required text.
- config.label_text = lambda { |label, required, explicit_label| "#{label} #{required}" }
+ config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" }
# Define the way to render check boxes / radio buttons with labels.
config.boolean_style = :inline
@@ -45,11 +45,11 @@
config.input_field_error_class = 'is-invalid'
config.input_field_valid_class = 'is-valid'
-
# vertical forms
#
# vertical default_wrapper
- config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@@ -64,7 +64,8 @@
end
# vertical input for boolean
- config.wrappers :vertical_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
@@ -76,7 +77,8 @@
end
# vertical input for radio buttons and check boxes
- config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group',
+ error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -88,7 +90,8 @@
end
# vertical input for inline radio buttons and check boxes
- config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'fieldset',
+ class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -100,7 +103,8 @@
end
# vertical file input
- config.wrappers :vertical_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@@ -113,7 +117,8 @@
end
# vertical multi select
- config.wrappers :vertical_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'form-control-label'
@@ -125,7 +130,8 @@
end
# vertical range input
- config.wrappers :vertical_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :vertical_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :readonly
@@ -136,11 +142,11 @@
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
end
-
# horizontal forms
#
# horizontal default_wrapper
- config.wrappers :horizontal_form, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_form, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@@ -157,7 +163,8 @@
end
# horizontal input for boolean
- config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper tag: 'label', class: 'col-sm-3' do |ba|
@@ -174,7 +181,8 @@
end
# horizontal input for radio buttons and check boxes
- config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', tag: 'div', class: 'form-group row',
+ error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'col-sm-3 form-control-label'
@@ -186,7 +194,8 @@
end
# horizontal input for inline radio buttons and check boxes
- config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'div',
+ class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'col-sm-3 form-control-label'
@@ -198,7 +207,8 @@
end
# horizontal file input
- config.wrappers :horizontal_file, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_file, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@@ -213,7 +223,8 @@
end
# horizontal multi select
- config.wrappers :horizontal_multi_select, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_multi_select, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'col-sm-3 control-label'
@@ -227,7 +238,8 @@
end
# horizontal range input
- config.wrappers :horizontal_range, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :horizontal_range, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :readonly
@@ -240,7 +252,6 @@
end
end
-
# inline forms
#
# inline default_wrapper
@@ -260,7 +271,8 @@
end
# inline input for boolean
- config.wrappers :inline_boolean, tag: 'span', class: 'form-check flex-wrap justify-content-start mr-sm-2', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :inline_boolean, tag: 'span', class: 'form-check flex-wrap justify-content-start mr-sm-2',
+ error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
@@ -269,11 +281,11 @@
b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
end
-
# bootstrap custom forms
#
# custom input for boolean
- config.wrappers :custom_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox' do |bb|
@@ -284,7 +296,8 @@
end
end
- config.wrappers :custom_boolean_switch, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_boolean_switch, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox-switch' do |bb|
@@ -296,7 +309,8 @@
end
# custom input for radio buttons and check boxes
- config.wrappers :custom_collection, item_wrapper_class: 'custom-control', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_collection, item_wrapper_class: 'custom-control', tag: 'fieldset', class: 'form-group',
+ error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -308,7 +322,8 @@
end
# custom input for inline radio buttons and check boxes
- config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline',
+ tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -320,7 +335,8 @@
end
# custom file input
- config.wrappers :custom_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@@ -336,7 +352,8 @@
end
# custom multi select
- config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'form-control-label'
@@ -348,7 +365,8 @@
end
# custom range input
- config.wrappers :custom_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :custom_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :readonly
@@ -359,7 +377,6 @@
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
end
-
# Input Group - custom component
# see example app and config at https://github.com/rafaelfranca/simple_form-bootstrap
# config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
@@ -380,11 +397,11 @@
# b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
# end
-
# Floating Labels form
#
# floating labels default_wrapper
- config.wrappers :floating_labels_form, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :floating_labels_form, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@@ -399,7 +416,8 @@
end
# custom multi select
- config.wrappers :floating_labels_select, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
+ config.wrappers :floating_labels_select, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid',
+ valid_class: 'form-group-valid' do |b|
b.use :html5
b.optional :readonly
b.use :input, class: 'custom-select custom-select-lg', error_class: 'is-invalid', valid_class: 'is-valid'
@@ -408,21 +426,20 @@
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
end
-
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :vertical_form
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
config.wrapper_mappings = {
- boolean: :vertical_boolean,
- check_boxes: :vertical_collection,
- date: :vertical_multi_select,
- datetime: :vertical_multi_select,
- file: :vertical_file,
+ boolean: :vertical_boolean,
+ check_boxes: :vertical_collection,
+ date: :vertical_multi_select,
+ datetime: :vertical_multi_select,
+ file: :vertical_file,
radio_buttons: :vertical_collection,
- range: :vertical_range,
- time: :vertical_multi_select
+ range: :vertical_range,
+ time: :vertical_multi_select
}
# enable custom form wrappers
diff --git a/config/puma.rb b/config/puma.rb
index bca244eff..e338e4623 100644
--- a/config/puma.rb
+++ b/config/puma.rb
@@ -1,20 +1,22 @@
+# frozen_string_literal: true
+
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
-max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
-min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
+max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
+min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
-port ENV.fetch("PORT") { 3000 }
+port ENV.fetch('PORT', 3000)
# Specifies the `environment` that Puma will run in.
#
-environment ENV.fetch("RAILS_ENV") { "development" }
+environment ENV.fetch('RAILS_ENV', 'development')
# Specifies the `pidfile` that Puma will use.
# pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
diff --git a/config/routes.rb b/config/routes.rb
index 38da97b78..ada233989 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -35,7 +35,7 @@
resources :neighbourhoods
resources :partners do
collection do
- match :setup, via: [:get, :post]
+ match :setup, via: %i[get post]
end
end
resources :tags
@@ -58,9 +58,9 @@
root 'pages#home'
- ymd = { year: /\d{4}/,
+ ymd = { year: /\d{4}/,
month: /\d{1,2}/,
- day: /\d{1,2}/ }
+ day: /\d{1,2}/ }
# Events
resources :events, only: %i[index show]
@@ -99,7 +99,5 @@
post '/api/v1/graphql', to: 'graphql#execute'
- if Rails.env.development?
- mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: "/api/v1/graphql"
- end
+ mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/api/v1/graphql' if Rails.env.development?
end
diff --git a/config/spring.rb b/config/spring.rb
index db5bf1307..93cd0ff8c 100644
--- a/config/spring.rb
+++ b/config/spring.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
Spring.watch(
- ".ruby-version",
- ".rbenv-vars",
- "tmp/restart.txt",
- "tmp/caching-dev.txt"
+ '.ruby-version',
+ '.rbenv-vars',
+ 'tmp/restart.txt',
+ 'tmp/caching-dev.txt'
)
diff --git a/db/data/20180530123745_add_manchester_uni_feeds.rb b/db/data/20180530123745_add_manchester_uni_feeds.rb
index 8bda45d14..926e6ab8f 100644
--- a/db/data/20180530123745_add_manchester_uni_feeds.rb
+++ b/db/data/20180530123745_add_manchester_uni_feeds.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddManchesterUniFeeds < SeedMigration::Migration
def up
partner = Partner.create!(name: 'Manchester University')
@@ -12,79 +14,70 @@ def down
def places(partner_id)
[
- {
- name: 'Manchester Museum',
- calendars_attributes: [
- { name: 'Manchester Museum',
- source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:manchester_museum/view:list/p:q_details/calml.xml',
- strategy: 'place',
- type: 'manchesteru',
- partner_id: partner_id
- }
- ],
- address_attributes:
- { street_address: 'The University of Manchester',
- street_address2: 'Oxford Road',
- city: 'Manchester',
- postcode: 'M13 9PL',
- country_code: 'UK'
- }
-
- },
- {
- name: 'The Whitworth',
- calendars_attributes: [
- { name: 'The Whitworth',
- source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:whitworth/view:list/p:q_details/calml.xml',
- strategy: 'place',
- type: 'manchesteru',
- partner_id: partner_id
- }
- ],
- address_attributes:
+ {
+ name: 'Manchester Museum',
+ calendars_attributes: [
+ { name: 'Manchester Museum',
+ source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:manchester_museum/view:list/p:q_details/calml.xml',
+ strategy: 'place',
+ type: 'manchesteru',
+ partner_id: partner_id }
+ ],
+ address_attributes:
{ street_address: 'The University of Manchester',
street_address2: 'Oxford Road',
city: 'Manchester',
- postcode: 'M15 6ER',
- country_code: 'UK'
- }
- },
- {
- name: 'Martin Harris Centre',
- calendars_attributes: [
- { name: 'Martin Harris Centre',
- source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:martin_harris_centre/view:list/p:q_details/calml.xml',
- strategy: 'place',
- type: 'manchesteru',
- partner_id: partner_id
- }
- ],
- address_attributes:
- { street_address: 'The University of Manchester',
- street_address2: 'Bridgeford Street, off Oxford Road',
- city: 'Manchester',
postcode: 'M13 9PL',
- country_code: 'UK'
- }
- },
- {
- name: 'John Rylands Library',
- calendars_attributes: [
- { name: 'John Rylands Library',
- source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:john_rylands_library/view:list/p:q_details/calml.xml',
- strategy: 'place',
- type: 'manchesteru',
- partner_id: partner_id
- }
- ],
- address_attributes:
- { street_address: '150 Deansgate',
- city: 'Manchester',
- postcode: 'M3 3EH',
- country_code: 'UK'
- }
- }
- ]
+ country_code: 'UK' }
+ },
+ {
+ name: 'The Whitworth',
+ calendars_attributes: [
+ { name: 'The Whitworth',
+ source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:whitworth/view:list/p:q_details/calml.xml',
+ strategy: 'place',
+ type: 'manchesteru',
+ partner_id: partner_id }
+ ],
+ address_attributes:
+ { street_address: 'The University of Manchester',
+ street_address2: 'Oxford Road',
+ city: 'Manchester',
+ postcode: 'M15 6ER',
+ country_code: 'UK' }
+ },
+ {
+ name: 'Martin Harris Centre',
+ calendars_attributes: [
+ { name: 'Martin Harris Centre',
+ source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:martin_harris_centre/view:list/p:q_details/calml.xml',
+ strategy: 'place',
+ type: 'manchesteru',
+ partner_id: partner_id }
+ ],
+ address_attributes:
+ { street_address: 'The University of Manchester',
+ street_address2: 'Bridgeford Street, off Oxford Road',
+ city: 'Manchester',
+ postcode: 'M13 9PL',
+ country_code: 'UK' }
+ },
+ {
+ name: 'John Rylands Library',
+ calendars_attributes: [
+ { name: 'John Rylands Library',
+ source: 'http://events.manchester.ac.uk/f3vf/calendar/tag:john_rylands_library/view:list/p:q_details/calml.xml',
+ strategy: 'place',
+ type: 'manchesteru',
+ partner_id: partner_id }
+ ],
+ address_attributes:
+ { street_address: '150 Deansgate',
+ city: 'Manchester',
+ postcode: 'M3 3EH',
+ country_code: 'UK' }
+ }
+ ]
end
end
diff --git a/db/data/20180625163935_add_places_partners.rb b/db/data/20180625163935_add_places_partners.rb
index d8c3cc0fd..fa995ff00 100644
--- a/db/data/20180625163935_add_places_partners.rb
+++ b/db/data/20180625163935_add_places_partners.rb
@@ -1,53 +1,60 @@
+# frozen_string_literal: true
+
class AddPlacesPartners < SeedMigration::Migration
def up
# Hulme Garden Centre
hcgc_address = Address.create(street_address: '28 Old Birley Street', city: 'Manchester', postcode: 'M15 5RG')
hcgc = Partner.create(
- name: "Hulme Community Garden Centre",
+ name: 'Hulme Community Garden Centre',
address: hcgc_address,
- public_email: "info@hulmegardencentre.org.uk",
- short_description: "A garden centre with a difference that makes a difference!
-
- Hulme Community Garden Centre is a unique community led inner-city horticultural project and charity. Our mission is to bring the local community together through gardening.
-
- As a not-for-profit organisation we provide low-cost plants to the local community but we are foremost a volunteer and education hub promoting horticultural and sustainability issues to schools, colleges, the local community and wider public."
- )
- hcgc.places << Place.create(
- name: 'Hulme Community Garden Centre',
- short_description: 'A garden centre with a difference that makes a difference!',
- address: hcgc_address
- )
- # Zion Centre
- blc = Partner.create(
- name: "Big Life Centres",
- short_description: "Big Life Centres enables people to live their best lives. It does this by developing health and well being centres that deliver holistic services to improve the quality of life for people living in disadvantaged areas. It enables people to make choices for themselves.
-
- Big Life Centres offer:
-
- * A place in the community – high quality, welcoming, helpful
- * Improving access to health and wellbeing services for all residents
- * Supporting people and providing opportunities for them to achieve their goals and aspirations
- * Offering tenants a high quality, competitive service with added value linked to our shared values
- * Improving health and wellbeing outcomes"
- )
- blc.places << Place.create(
- name: 'Zion Community Resource Centre',
- phone: '0161 226 5412',
- url: 'https://www.thebiglifegroup.com/big-life-centres/zion-centre/',
- address: Address.create(street_address: '339 Stretford Road', city: 'Manchester', postcode: 'M154ZY')
- )
- blc.places << Place.create(
- name: 'Kath Locke Centre',
- phone: '0161 455 0211',
- short_description: "The Kath Locke Centre combines the best in conventional NHS healthcare alongside complementary therapies to offer a complete approach to health and well-being.",
- url: 'https://www.thebiglifegroup.com/big-life-centres/kath-locke-centre/',
- address: Address.create(street_address: '123 Moss Lane East', city: 'Manchester', postcode: 'M155DD')
- )
+ public_email: 'info@hulmegardencentre.org.uk',
+ short_description: <<~DESC
+ A garden centre with a difference that makes a difference!
+
+ Hulme Community Garden Centre is a unique community led inner-city horticultural project and charity. Our mission is to bring the local community together through gardening.
+
+ As a not-for-profit organisation we provide low-cost plants to the local community but we are foremost a volunteer and education hub promoting horticultural and sustainability issues to schools, colleges, the local community and wider public.
+ DESC
+ )
+ hcgc.places << Place.create(
+ name: 'Hulme Community Garden Centre',
+ short_description: 'A garden centre with a difference that makes a difference!',
+ address: hcgc_address
+ )
+ # Zion Centre
+ blc = Partner.create(
+ name: 'Big Life Centres',
+ short_description: <<~DESC
+ Big Life Centres enables people to live their best lives. It does this by developing health and well being centres that deliver holistic services to improve the quality of life for people living in disadvantaged areas. It enables people to make choices for themselves.
+
+ Big Life Centres offer:
+
+ * A place in the community – high quality, welcoming, helpful
+ * Improving access to health and wellbeing services for all residents
+ * Supporting people and providing opportunities for them to achieve their goals and aspirations
+ * Offering tenants a high quality, competitive service with added value linked to our shared values
+ * Improving health and wellbeing outcomes
+ DESC
+ )
+ blc.places << Place.create(
+ name: 'Zion Community Resource Centre',
+ phone: '0161 226 5412',
+ url: 'https://www.thebiglifegroup.com/big-life-centres/zion-centre/',
+ address: Address.create(street_address: '339 Stretford Road', city: 'Manchester', postcode: 'M154ZY')
+ )
+ blc.places << Place.create(
+ name: 'Kath Locke Centre',
+ phone: '0161 455 0211',
+
+ short_description: 'The Kath Locke Centre combines the best in conventional NHS healthcare alongside complementary therapies to offer a complete approach to health and well-being.',
+
+ url: 'https://www.thebiglifegroup.com/big-life-centres/kath-locke-centre/',
+ address: Address.create(street_address: '123 Moss Lane East', city: 'Manchester', postcode: 'M155DD')
+ )
end
def down
# Prob don't need this
# ["Hulme Community Garden Centre"].each { |p| Partner.where(name: p).destroy_all }
end
-
end
diff --git a/db/data/20180625171116_add_root_user.rb b/db/data/20180625171116_add_root_user.rb
index 09e936dc3..8e3a8312c 100644
--- a/db/data/20180625171116_add_root_user.rb
+++ b/db/data/20180625171116_add_root_user.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddRootUser < SeedMigration::Migration
def up
User.create(
diff --git a/db/data/20180625172033_add_sites.rb b/db/data/20180625172033_add_sites.rb
index 43ab3ef3c..715cbcce5 100644
--- a/db/data/20180625172033_add_sites.rb
+++ b/db/data/20180625172033_add_sites.rb
@@ -31,7 +31,8 @@ def records # rubocop:disable Metrics/MethodLength
footer_logo: 'hulme-footer.svg',
hero_image: 'hulme-hero.jpg',
hero_image_credit: 'Jane Samuels',
- supporters: Supporter.where(name: ['Age Friendly Hulme and Moss Side', 'Buzz', 'People First Wellbeing Service'])
+ supporters: Supporter.where(name: ['Age Friendly Hulme and Moss Side', 'Buzz',
+ 'People First Wellbeing Service'])
},
{
name: 'Moss Side',
@@ -43,7 +44,8 @@ def records # rubocop:disable Metrics/MethodLength
footer_logo: 'hulme-footer.svg',
hero_image: 'moss-side-hero.jpg',
hero_image_credit: 'Jane Samuels',
- supporters: Supporter.where(name: ['Age Friendly Hulme and Moss Side', 'Buzz', 'People First Wellbeing Service'])
+ supporters: Supporter.where(name: ['Age Friendly Hulme and Moss Side', 'Buzz',
+ 'People First Wellbeing Service'])
},
{
name: 'Rusholme',
diff --git a/db/migrate/20170916030904_change_relations.rb b/db/migrate/20170916030904_change_relations.rb
index 736af585f..637d6afc7 100644
--- a/db/migrate/20170916030904_change_relations.rb
+++ b/db/migrate/20170916030904_change_relations.rb
@@ -7,9 +7,12 @@ def change
t.references :partner, foreign_key: true
end
- add_column :events, :partner_id, :integer, index: true
- add_column :calendars, :address_id, :integer, index: true
- add_column :events, :address_id, :integer, index: true
+ add_column :events, :partner_id, :integer
+ add_index :events, :partner_id
+ add_column :calendars, :address_id, :integer
+ add_index :calendars, :address_id
+ add_column :events, :address_id, :integer
+ add_index :events, :address_id
add_foreign_key :events, :partners
add_foreign_key :calendars, :addresses
diff --git a/db/migrate/20171015232730_remove_deleted_at_from_events.rb b/db/migrate/20171015232730_remove_deleted_at_from_events.rb
index 7357d9575..bf7edce43 100644
--- a/db/migrate/20171015232730_remove_deleted_at_from_events.rb
+++ b/db/migrate/20171015232730_remove_deleted_at_from_events.rb
@@ -7,6 +7,7 @@ def up
end
def down
- add_column :events, :deleted_at, :datetime, index: true
+ add_column :events, :deleted_at, :datetime
+ add_index :events, :deleted_at
end
end
diff --git a/db/migrate/20180518110917_add_user_to_site.rb b/db/migrate/20180518110917_add_user_to_site.rb
index c545cf5bf..84cc692de 100644
--- a/db/migrate/20180518110917_add_user_to_site.rb
+++ b/db/migrate/20180518110917_add_user_to_site.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddUserToSite < ActiveRecord::Migration[5.1]
def change
add_reference :sites, :site_admin, foreign_key: { to_table: :users }
diff --git a/db/migrate/20180525130733_add_logo_to_sites.rb b/db/migrate/20180525130733_add_logo_to_sites.rb
index b803b9da4..ad10aa096 100644
--- a/db/migrate/20180525130733_add_logo_to_sites.rb
+++ b/db/migrate/20180525130733_add_logo_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddLogoToSites < ActiveRecord::Migration[5.1]
def change
add_column :sites, :logo, :string
diff --git a/db/migrate/20180525140208_add_hero_image_to_sites.rb b/db/migrate/20180525140208_add_hero_image_to_sites.rb
index 0e5736cb4..8d4b08bd4 100644
--- a/db/migrate/20180525140208_add_hero_image_to_sites.rb
+++ b/db/migrate/20180525140208_add_hero_image_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddHeroImageToSites < ActiveRecord::Migration[5.1]
def change
add_column :sites, :hero_image, :string
diff --git a/db/migrate/20180525144755_add_hero_image_credit_to_site.rb b/db/migrate/20180525144755_add_hero_image_credit_to_site.rb
index 3cd8b7e10..fcf548517 100644
--- a/db/migrate/20180525144755_add_hero_image_credit_to_site.rb
+++ b/db/migrate/20180525144755_add_hero_image_credit_to_site.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddHeroImageCreditToSite < ActiveRecord::Migration[5.1]
def change
add_column :sites, :hero_image_credit, :string
diff --git a/db/migrate/20180525190230_add_footer_logo_to_sites.rb b/db/migrate/20180525190230_add_footer_logo_to_sites.rb
index 1a9c0564f..60cec8bb0 100644
--- a/db/migrate/20180525190230_add_footer_logo_to_sites.rb
+++ b/db/migrate/20180525190230_add_footer_logo_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddFooterLogoToSites < ActiveRecord::Migration[5.1]
def change
add_column :sites, :footer_logo, :string
diff --git a/db/migrate/20180528112309_add_internet_access_turf.rb b/db/migrate/20180528112309_add_internet_access_turf.rb
index 8b9b43b5b..1530c9b00 100644
--- a/db/migrate/20180528112309_add_internet_access_turf.rb
+++ b/db/migrate/20180528112309_add_internet_access_turf.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddInternetAccessTurf < ActiveRecord::Migration[5.1]
def change
# Turf.create(name: 'Internet Access',
diff --git a/db/migrate/20180528161308_add_url_to_partners.rb b/db/migrate/20180528161308_add_url_to_partners.rb
index cb2286993..50416c0a8 100644
--- a/db/migrate/20180528161308_add_url_to_partners.rb
+++ b/db/migrate/20180528161308_add_url_to_partners.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddUrlToPartners < ActiveRecord::Migration[5.1]
def change
add_column :partners, :url, :string
diff --git a/db/migrate/20180528164945_create_supporters.rb b/db/migrate/20180528164945_create_supporters.rb
index 9f6ce3daa..105d67b63 100644
--- a/db/migrate/20180528164945_create_supporters.rb
+++ b/db/migrate/20180528164945_create_supporters.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateSupporters < ActiveRecord::Migration[5.1]
def change
create_table :supporters do |t|
diff --git a/db/migrate/20180528165204_create_join_table_sites_supporters.rb b/db/migrate/20180528165204_create_join_table_sites_supporters.rb
index 4ad850e98..1e513d366 100644
--- a/db/migrate/20180528165204_create_join_table_sites_supporters.rb
+++ b/db/migrate/20180528165204_create_join_table_sites_supporters.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
class CreateJoinTableSitesSupporters < ActiveRecord::Migration[5.1]
def change
create_join_table :sites, :supporters do |t|
- t.index [:site_id, :supporter_id]
- t.index [:supporter_id, :site_id]
+ t.index %i[site_id supporter_id]
+ t.index %i[supporter_id site_id]
end
end
end
diff --git a/db/migrate/20180530093323_add_global_to_supporters.rb b/db/migrate/20180530093323_add_global_to_supporters.rb
index ada190a2b..4adc8a663 100644
--- a/db/migrate/20180530093323_add_global_to_supporters.rb
+++ b/db/migrate/20180530093323_add_global_to_supporters.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddGlobalToSupporters < ActiveRecord::Migration[5.1]
def change
add_column :supporters, :is_global, :boolean, default: false
diff --git a/db/migrate/20180530100533_create_data_migrations.seed_migration.rb b/db/migrate/20180530100533_create_data_migrations.seed_migration.rb
index 919500c4f..2a34bc7f2 100644
--- a/db/migrate/20180530100533_create_data_migrations.seed_migration.rb
+++ b/db/migrate/20180530100533_create_data_migrations.seed_migration.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This migration comes from seed_migration (originally 20140310150145)
class CreateDataMigrations < ActiveRecord::Migration[4.2]
def up
diff --git a/db/migrate/20180625172806_add_supporter_data.rb b/db/migrate/20180625172806_add_supporter_data.rb
index fdcfe458d..26654630a 100644
--- a/db/migrate/20180625172806_add_supporter_data.rb
+++ b/db/migrate/20180625172806_add_supporter_data.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddSupporterData < ActiveRecord::Migration[5.1]
def up
records.each do |r|
diff --git a/db/migrate/20180629174727_add_last_checksum_and_footer_to_calendar.rb b/db/migrate/20180629174727_add_last_checksum_and_footer_to_calendar.rb
index a010a6431..5d3ada637 100644
--- a/db/migrate/20180629174727_add_last_checksum_and_footer_to_calendar.rb
+++ b/db/migrate/20180629174727_add_last_checksum_and_footer_to_calendar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddLastChecksumAndFooterToCalendar < ActiveRecord::Migration[5.1]
def change
add_column :calendars, :last_checksum, :string
diff --git a/db/migrate/20180716040041_remove_type_and_address_from_calendar.rb b/db/migrate/20180716040041_remove_type_and_address_from_calendar.rb
index d54154195..863e592dd 100644
--- a/db/migrate/20180716040041_remove_type_and_address_from_calendar.rb
+++ b/db/migrate/20180716040041_remove_type_and_address_from_calendar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RemoveTypeAndAddressFromCalendar < ActiveRecord::Migration[5.1]
def change
remove_column :calendars, :type, :string
diff --git a/db/migrate/20180720112624_add_critical_error_to_calendar.rb b/db/migrate/20180720112624_add_critical_error_to_calendar.rb
index 7e06aa956..3a521f257 100644
--- a/db/migrate/20180720112624_add_critical_error_to_calendar.rb
+++ b/db/migrate/20180720112624_add_critical_error_to_calendar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddCriticalErrorToCalendar < ActiveRecord::Migration[5.1]
def change
add_column :calendars, :critical_error, :text
diff --git a/db/migrate/20180801041639_add_access_token_to_users_and_calendars.rb b/db/migrate/20180801041639_add_access_token_to_users_and_calendars.rb
index ac990d501..ea149d701 100644
--- a/db/migrate/20180801041639_add_access_token_to_users_and_calendars.rb
+++ b/db/migrate/20180801041639_add_access_token_to_users_and_calendars.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddAccessTokenToUsersAndCalendars < ActiveRecord::Migration[5.1]
def change
add_column :users, :access_token, :string
diff --git a/db/migrate/20180827120116_add_devise_invitable.rb b/db/migrate/20180827120116_add_devise_invitable.rb
index 3343855e9..36795ef68 100644
--- a/db/migrate/20180827120116_add_devise_invitable.rb
+++ b/db/migrate/20180827120116_add_devise_invitable.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddDeviseInvitable < ActiveRecord::Migration[5.1]
def change
add_column :users, :invitation_token, :string
@@ -7,11 +9,11 @@ def change
add_column :users, :invitation_limit, :integer
add_column :users, :invited_by_id, :integer
add_column :users, :invited_by_type, :string
- add_index :users, :invitation_token, :unique => true
+ add_index :users, :invitation_token, unique: true
# Allow null encrypted_password
change_column_null :users, :encrypted_password, :string, true
# Allow null password_salt (add it if you are using Devise's encryptable module)
- #change_column_null :users, :password_salt, :string, true
+ # change_column_null :users, :password_salt, :string, true
end
end
diff --git a/db/migrate/20180905123823_add_admin_ward_to_addresses.rb b/db/migrate/20180905123823_add_admin_ward_to_addresses.rb
index 82b55ab6d..3c0e9d2cf 100644
--- a/db/migrate/20180905123823_add_admin_ward_to_addresses.rb
+++ b/db/migrate/20180905123823_add_admin_ward_to_addresses.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddAdminWardToAddresses < ActiveRecord::Migration[5.1]
def change
add_column :addresses, :admin_ward, :string
diff --git a/db/migrate/20180910134410_add_neighbourhood_turf_to_address.rb b/db/migrate/20180910134410_add_neighbourhood_turf_to_address.rb
index bc106a898..ca63a9764 100644
--- a/db/migrate/20180910134410_add_neighbourhood_turf_to_address.rb
+++ b/db/migrate/20180910134410_add_neighbourhood_turf_to_address.rb
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
class AddNeighbourhoodTurfToAddress < ActiveRecord::Migration[5.1]
def change
- add_reference :addresses, :neighbourhood_turf, foreign_key: {to_table: :turfs}
+ add_reference :addresses, :neighbourhood_turf, foreign_key: { to_table: :turfs }
end
end
diff --git a/db/migrate/20180910143528_remove_admin_ward_from_addresses.rb b/db/migrate/20180910143528_remove_admin_ward_from_addresses.rb
index 87cac41a1..c7f016fe7 100644
--- a/db/migrate/20180910143528_remove_admin_ward_from_addresses.rb
+++ b/db/migrate/20180910143528_remove_admin_ward_from_addresses.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RemoveAdminWardFromAddresses < ActiveRecord::Migration[5.1]
def change
remove_column :addresses, :admin_ward, :string
diff --git a/db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb b/db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb
index 877ac85e5..c21369fba 100644
--- a/db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb
+++ b/db/migrate/20180919111400_split_turfs_into_neighbourhoods_and_turfs.rb
@@ -1,42 +1,44 @@
+# frozen_string_literal: true
+
class SplitTurfsIntoNeighbourhoodsAndTurfs < ActiveRecord::Migration[5.1]
def up
- #1 Create and populate neighbourhoods table
+ # 1 Create and populate neighbourhoods table
create_table :neighbourhoods do |t|
t.string :name
end
execute("insert into neighbourhoods ( id, name ) select id, name from turfs where turfs.turf_type = 'neighbourhood';")
- #2 Change addresses to point at neighbourhoods rather than turfs
+ # 2 Change addresses to point at neighbourhoods rather than turfs
remove_foreign_key :addresses, column: :neighbourhood_turf_id
rename_column :addresses, :neighbourhood_turf_id, :neighbourhood_id
add_foreign_key :addresses, :neighbourhoods, column: :neighbourhood_id
- #3 Rename sites_turfs
+ # 3 Rename sites_turfs
rename_table :sites_turfs, :sites_neighbourhoods
rename_column :sites_neighbourhoods, :turf_id, :neighbourhood_id
- #4 Delete redundant data and structure from turfs
+ # 4 Delete redundant data and structure from turfs
execute("delete from turfs where turf_type = 'neighbourhood';")
remove_column :turfs, :turf_type, :string
end
def down
- #4
+ # 4
add_column :turfs, :turf_type, :string
execute("update turfs set turf_type = 'interest';")
- # Note: Does not create slugs for neighbourhood turfs!
+ # NOTE: Does not create slugs for neighbourhood turfs!
execute("insert into turfs ( id, name, turf_type, created_at, updated_at ) select id, name, 'neighbourhood', now(), now() from neighbourhoods;")
- #3
+ # 3
rename_table :sites_neighbourhoods, :sites_turfs
rename_column :sites_turfs, :neighbourhood_id, :turf_id
- #2
+ # 2
remove_foreign_key :addresses, :neighbourhoods
rename_column :addresses, :neighbourhood_id, :neighbourhood_turf_id
add_foreign_key :addresses, :turfs, column: :neighbourhood_turf_id
- #3
+ # 3
drop_table :neighbourhoods
end
end
diff --git a/db/migrate/20180926032437_change_calendar_columns.rb b/db/migrate/20180926032437_change_calendar_columns.rb
index c98b545c8..1c0241d11 100644
--- a/db/migrate/20180926032437_change_calendar_columns.rb
+++ b/db/migrate/20180926032437_change_calendar_columns.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ChangeCalendarColumns < ActiveRecord::Migration[5.1]
def change
remove_column :calendars, :footer, :text
diff --git a/db/migrate/20181001150453_add_default_site.rb b/db/migrate/20181001150453_add_default_site.rb
index e6510f981..719b0a051 100644
--- a/db/migrate/20181001150453_add_default_site.rb
+++ b/db/migrate/20181001150453_add_default_site.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
class AddDefaultSite < ActiveRecord::Migration[5.1]
def up
execute(
-%(insert into sites
+ %(insert into sites
(name, domain, slug, created_at, updated_at)
values
('Default site (no subdomain)', 'placecal.org', 'default-site', now(), now()) ;)
@@ -10,9 +12,9 @@ def up
def down
execute(
-%(delete from sites_neighbourhoods where site_id =
+ %(delete from sites_neighbourhoods where site_id =
(select id from sites where slug = 'default-site');)
)
- execute( "delete from sites where slug = 'default-site';" )
+ execute("delete from sites where slug = 'default-site';")
end
end
diff --git a/db/migrate/20181005091853_add_avatar_to_users.rb b/db/migrate/20181005091853_add_avatar_to_users.rb
index efc120b14..5cc9014a9 100644
--- a/db/migrate/20181005091853_add_avatar_to_users.rb
+++ b/db/migrate/20181005091853_add_avatar_to_users.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddAvatarToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :avatar, :string
diff --git a/db/migrate/20181009094523_merge_partners_places_tables.rb b/db/migrate/20181009094523_merge_partners_places_tables.rb
index d8b5f88db..d2cb02aa7 100644
--- a/db/migrate/20181009094523_merge_partners_places_tables.rb
+++ b/db/migrate/20181009094523_merge_partners_places_tables.rb
@@ -1,9 +1,9 @@
-class MergePartnersPlacesTables < ActiveRecord::Migration[5.1]
+# frozen_string_literal: true
+class MergePartnersPlacesTables < ActiveRecord::Migration[5.1]
# NOTE: No data deletion happens in this migration. The only destructive edits
# are dropping of indexes in order to make other changes possible.
def up
-
# 1) add relevant places columns to partners and rename other where appropriate
change_table :partners do |t|
t.jsonb :opening_times
@@ -59,17 +59,15 @@ def up
add_foreign_key :events, :partners, column: :place_id
end
-
def down
-
- #4)
- execute("UPDATE events SET place_id = null;")
+ # 4)
+ execute('UPDATE events SET place_id = null;')
remove_foreign_key :events, column: :place_id
add_foreign_key :events, :places
- #3)
- execute("UPDATE calendars SET place_id = null;")
+ # 3)
+ execute('UPDATE calendars SET place_id = null;')
remove_foreign_key :calendars, column: :place_id
add_foreign_key :calendars, :places
diff --git a/db/migrate/20181009162402_add_organisation_relationships_table.rb b/db/migrate/20181009162402_add_organisation_relationships_table.rb
index d9e1d13f3..2544a199b 100644
--- a/db/migrate/20181009162402_add_organisation_relationships_table.rb
+++ b/db/migrate/20181009162402_add_organisation_relationships_table.rb
@@ -1,5 +1,6 @@
-class AddOrganisationRelationshipsTable < ActiveRecord::Migration[5.1]
+# frozen_string_literal: true
+class AddOrganisationRelationshipsTable < ActiveRecord::Migration[5.1]
def change
create_table :organisation_relationships
add_reference :organisation_relationships, :subject, null: false
@@ -7,7 +8,7 @@ def change
add_column :organisation_relationships, :verb, :string, null: false
add_reference :organisation_relationships, :object, null: false
add_foreign_key :organisation_relationships, :partners, column: :object_id
- add_index :organisation_relationships, [:subject_id, :verb, :object_id], unique: true, name: :unique_organisation_relationship_row
+ add_index :organisation_relationships, %i[subject_id verb object_id], unique: true,
+ name: :unique_organisation_relationship_row
end
-
end
diff --git a/db/migrate/20181010165919_add_calendar_contact_columns.rb b/db/migrate/20181010165919_add_calendar_contact_columns.rb
index 8eae4e6a4..5d9e08956 100644
--- a/db/migrate/20181010165919_add_calendar_contact_columns.rb
+++ b/db/migrate/20181010165919_add_calendar_contact_columns.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddCalendarContactColumns < ActiveRecord::Migration[5.1]
def change
# NOTE: Not copying any data over from partners. Staging server had no
@@ -11,5 +13,4 @@ def change
t.text :public_contact_phone
end
end
-
end
diff --git a/db/migrate/20181012041853_add_facebook_app_id_and_facebook_app_secret_to_users.rb b/db/migrate/20181012041853_add_facebook_app_id_and_facebook_app_secret_to_users.rb
index 998a5fda7..8d288d464 100644
--- a/db/migrate/20181012041853_add_facebook_app_id_and_facebook_app_secret_to_users.rb
+++ b/db/migrate/20181012041853_add_facebook_app_id_and_facebook_app_secret_to_users.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddFacebookAppIdAndFacebookAppSecretToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :facebook_app_id, :text
diff --git a/db/migrate/20181031134053_change_calendar_contact_details_to_type_string.rb b/db/migrate/20181031134053_change_calendar_contact_details_to_type_string.rb
index 26dd3bd86..be93d8c71 100644
--- a/db/migrate/20181031134053_change_calendar_contact_details_to_type_string.rb
+++ b/db/migrate/20181031134053_change_calendar_contact_details_to_type_string.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ChangeCalendarContactDetailsToTypeString < ActiveRecord::Migration[5.1]
def change
change_column :calendars, :partnership_contact_name, :string
diff --git a/db/migrate/20181121122228_rename_events_location_column.rb b/db/migrate/20181121122228_rename_events_location_column.rb
index 46aeade05..299230836 100644
--- a/db/migrate/20181121122228_rename_events_location_column.rb
+++ b/db/migrate/20181121122228_rename_events_location_column.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RenameEventsLocationColumn < ActiveRecord::Migration[5.1]
def change
rename_column :events, :location, :raw_location_from_source
diff --git a/db/migrate/20181121141327_add_social_media_columns_to_partners.rb b/db/migrate/20181121141327_add_social_media_columns_to_partners.rb
index f99f4309c..c6500ccb0 100644
--- a/db/migrate/20181121141327_add_social_media_columns_to_partners.rb
+++ b/db/migrate/20181121141327_add_social_media_columns_to_partners.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddSocialMediaColumnsToPartners < ActiveRecord::Migration[5.1]
def change
add_column :partners, :twitter_handle, :string
diff --git a/db/migrate/20181126174530_add_route_to_collections.rb b/db/migrate/20181126174530_add_route_to_collections.rb
index b1d87a1c9..3ef8ffdda 100644
--- a/db/migrate/20181126174530_add_route_to_collections.rb
+++ b/db/migrate/20181126174530_add_route_to_collections.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddRouteToCollections < ActiveRecord::Migration[5.1]
def change
add_column :collections, :route, :string
diff --git a/db/migrate/20181127132710_add_tagline_to_sites.rb b/db/migrate/20181127132710_add_tagline_to_sites.rb
index 8f4fac8cf..24893384b 100644
--- a/db/migrate/20181127132710_add_tagline_to_sites.rb
+++ b/db/migrate/20181127132710_add_tagline_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddTaglineToSites < ActiveRecord::Migration[5.1]
def change
add_column :sites, :tagline, :string, default: 'The Community Calendar'
diff --git a/db/migrate/20190605132649_add_placename_to_site.rb b/db/migrate/20190605132649_add_placename_to_site.rb
index 3a6e12908..6d1a31b48 100644
--- a/db/migrate/20190605132649_add_placename_to_site.rb
+++ b/db/migrate/20190605132649_add_placename_to_site.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddPlacenameToSite < ActiveRecord::Migration[5.1]
def change
add_column :sites, :place_name, :string
diff --git a/db/migrate/20191031170146_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb b/db/migrate/20191031170146_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb
index ff5d72c7e..7818547c4 100644
--- a/db/migrate/20191031170146_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb
+++ b/db/migrate/20191031170146_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This migration comes from active_storage (originally 20180723000244)
class AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId < ActiveRecord::Migration[6.0]
def up
diff --git a/db/migrate/20191201002011_fix_invalid_partners.rb b/db/migrate/20191201002011_fix_invalid_partners.rb
index cca3be9c7..ebda7c12f 100644
--- a/db/migrate/20191201002011_fix_invalid_partners.rb
+++ b/db/migrate/20191201002011_fix_invalid_partners.rb
@@ -1,25 +1,27 @@
+# frozen_string_literal: true
+
class FixInvalidPartners < ActiveRecord::Migration[6.0]
def up
- invalid_partners= Partner.all.reject(&:valid?)
+ invalid_partners = Partner.all.reject(&:valid?)
invalid_partners.each do |partner|
partner.valid?
invalid_fields = partner.errors.messages
- invalid_fields.each do |field, error|
- if field == :partner_phone || field == :public_phone
+ invalid_fields.each do |field, _error|
+ if %i[partner_phone public_phone].include?(field)
partner.public_phone = partner.public_phone&.strip
partner.partner_phone = partner.partner_phone&.strip
elsif field == :twitter_handle
- partner.twitter_handle = partner.twitter_handle.gsub('@', '').strip
+ partner.twitter_handle = partner.twitter_handle.delete('@').strip
elsif field == :facebook_link
- facebook_link = partner.facebook_link.scan(/(?:https?:\/\/)?(?:www.)?facebook.com\/(?:pg\/)?(\w*)\/?/)
+ facebook_link = partner.facebook_link.scan(%r{(?:https?://)?(?:www.)?facebook.com/(?:pg/)?(\w*)/?})
partner.facebook_link = facebook_link.flatten[0]&.strip
elsif field == :url
- if partner.url.starts_with?('www')
- partner.url = ('https://' + partner.url)&.strip
- else
- partner.url = ('https://www.' + partner.url)&.strip
- end
+ partner.url = if partner.url.starts_with?('www')
+ "https://#{partner.url}"&.strip
+ else
+ "https://www.#{partner.url}"&.strip
+ end
end
end
diff --git a/db/migrate/20191210165905_create_neighbourhoods_users.rb b/db/migrate/20191210165905_create_neighbourhoods_users.rb
index fb4e8e010..b1b903340 100644
--- a/db/migrate/20191210165905_create_neighbourhoods_users.rb
+++ b/db/migrate/20191210165905_create_neighbourhoods_users.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateNeighbourhoodsUsers < ActiveRecord::Migration[6.0]
def change
create_table :neighbourhoods_users do |t|
diff --git a/db/migrate/20191219122747_rename_turfs_to_tags.rb b/db/migrate/20191219122747_rename_turfs_to_tags.rb
index 43ec2ac41..b5c32318a 100644
--- a/db/migrate/20191219122747_rename_turfs_to_tags.rb
+++ b/db/migrate/20191219122747_rename_turfs_to_tags.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RenameTurfsToTags < ActiveRecord::Migration[6.0]
def change
rename_table :turfs, :tags
diff --git a/db/migrate/20200107153812_add_theme_to_sites.rb b/db/migrate/20200107153812_add_theme_to_sites.rb
index 1df10b0d5..b4f819ce2 100644
--- a/db/migrate/20200107153812_add_theme_to_sites.rb
+++ b/db/migrate/20200107153812_add_theme_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddThemeToSites < ActiveRecord::Migration[6.0]
def change
add_column :sites, :theme, :string
diff --git a/db/migrate/20200107165257_update_site_themes.rb b/db/migrate/20200107165257_update_site_themes.rb
index e3d0df74f..e65526d4f 100644
--- a/db/migrate/20200107165257_update_site_themes.rb
+++ b/db/migrate/20200107165257_update_site_themes.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class UpdateSiteThemes < ActiveRecord::Migration[6.0]
def change
set_theme 'hulme', :pink
@@ -9,6 +11,6 @@ def change
def set_theme(slug, colour)
site = Site.find_by(slug: slug)
- site.update(theme: colour) if site
+ site&.update(theme: colour)
end
end
diff --git a/db/migrate/20200107174516_add_more_info_to_neighbourhoods.rb b/db/migrate/20200107174516_add_more_info_to_neighbourhoods.rb
index 6d7c44139..2ce5a3a83 100644
--- a/db/migrate/20200107174516_add_more_info_to_neighbourhoods.rb
+++ b/db/migrate/20200107174516_add_more_info_to_neighbourhoods.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddMoreInfoToNeighbourhoods < ActiveRecord::Migration[6.0]
def change
add_column :neighbourhoods, :name_abbr, :string
diff --git a/db/migrate/20200312155023_add_publish_to_sites.rb b/db/migrate/20200312155023_add_publish_to_sites.rb
index bf86d98df..d86949878 100644
--- a/db/migrate/20200312155023_add_publish_to_sites.rb
+++ b/db/migrate/20200312155023_add_publish_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddPublishToSites < ActiveRecord::Migration[6.0]
def change
add_column :sites, :is_published, :boolean, default: false
diff --git a/db/migrate/20211117104415_add_ancestry_to_neighbourhoods.rb b/db/migrate/20211117104415_add_ancestry_to_neighbourhoods.rb
index 4543a4732..e880dcb74 100644
--- a/db/migrate/20211117104415_add_ancestry_to_neighbourhoods.rb
+++ b/db/migrate/20211117104415_add_ancestry_to_neighbourhoods.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddAncestryToNeighbourhoods < ActiveRecord::Migration[6.0]
def change
add_column :neighbourhoods, :ancestry, :string
diff --git a/db/migrate/20211118145348_add_unit_columns_to_tables.rb b/db/migrate/20211118145348_add_unit_columns_to_tables.rb
index 89e8b55a8..4e2131614 100644
--- a/db/migrate/20211118145348_add_unit_columns_to_tables.rb
+++ b/db/migrate/20211118145348_add_unit_columns_to_tables.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddUnitColumnsToTables < ActiveRecord::Migration[6.0]
def change
change_table(:neighbourhoods, bulk: true) do |n|
diff --git a/db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb b/db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb
index eecf4dcc7..e76682e78 100644
--- a/db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb
+++ b/db/migrate/20211118145604_alter_structure_of_neighbourhoods.rb
@@ -1,99 +1,92 @@
+# frozen_string_literal: true
+
class AlterStructureOfNeighbourhoods < ActiveRecord::Migration[6.0]
def up
errors = []
Neighbourhood.find_each do |ward|
- begin
- next if ward.unit != 'ward'
+ next if ward.unit != 'ward'
- puts "Processing ward #{ward.id}, #{ward.name}"
+ puts "Processing ward #{ward.id}, #{ward.name}"
- # Nice variables
- # Often we do not actually have name / code data for the county or region nodes.
- # The values .ward, .district, .county, .region are all more accurate than that code data
- district_name = ward.district
- county_name = ward.county
- region_name = ward.region
+ # Nice variables
+ # Often we do not actually have name / code data for the county or region nodes.
+ # The values .ward, .district, .county, .region are all more accurate than that code data
+ district_name = ward.district
+ county_name = ward.county
+ region_name = ward.region
- # Fill ward with default values
- ward.unit_code_value = ward.WD19CD
- ward.unit_name = ward.name
+ # Fill ward with default values
+ ward.unit_code_value = ward.WD19CD
+ ward.unit_name = ward.name
- # Find/Create district and county neighbourhoods
- district_node = Neighbourhood.find_or_create_by!(
- { name: district_name,
- unit: 'district',
- unit_code_key: 'LAD19CD',
- unit_code_value: ward.LAD19CD,
- unit_name: district_name }
- )
- county_node = Neighbourhood.find_or_create_by!(
- { name: county_name,
- unit: 'county',
- unit_code_key: 'CTY19CD',
- unit_code_value: ward.CTY19CD,
- unit_name: county_name }
- )
- region_node = Neighbourhood.find_or_create_by!(
- { name: region_name,
- unit: 'region',
- unit_code_key: 'RGN19CD',
- unit_code_value: ward.RGN19CD,
- unit_name: region_name }
- )
+ # Find/Create district and county neighbourhoods
+ district_node = Neighbourhood.find_or_create_by!(
+ { name: district_name,
+ unit: 'district',
+ unit_code_key: 'LAD19CD',
+ unit_code_value: ward.LAD19CD,
+ unit_name: district_name }
+ )
+ county_node = Neighbourhood.find_or_create_by!(
+ { name: county_name,
+ unit: 'county',
+ unit_code_key: 'CTY19CD',
+ unit_code_value: ward.CTY19CD,
+ unit_name: county_name }
+ )
+ region_node = Neighbourhood.find_or_create_by!(
+ { name: region_name,
+ unit: 'region',
+ unit_code_key: 'RGN19CD',
+ unit_code_value: ward.RGN19CD,
+ unit_name: region_name }
+ )
- # Make the ward a child of the district
- ward.parent = district_node
+ # Make the ward a child of the district
+ ward.parent = district_node
- # Make the district a child of the county, if it isn't already
- district_node.parent = county_node unless
- county_node.children.include? district_node
+ # Make the district a child of the county, if it isn't already
+ district_node.parent = county_node unless
+ county_node.children.include? district_node
- county_node.parent = region_node unless
- region_node.children.include? county_node
+ county_node.parent = region_node unless
+ region_node.children.include? county_node
- # Save save save!!!
- ward.save!
- district_node.save!
- county_node.save!
- region_node.save!
- rescue => e
- errors << { error: e.message,
- trace: e.backtrace_locations,
- id: ward.id,
- name: ward.name }
- next
- end
+ # Save save save!!!
+ ward.save!
+ district_node.save!
+ county_node.save!
+ region_node.save!
+ rescue StandardError => e
+ errors << { error: e.message,
+ trace: e.backtrace_locations,
+ id: ward.id,
+ name: ward.name }
+ next
end
return unless errors.any?
- File.open('20211118145604_alter_structure_of_neighbourhoods.errors.txt', 'w') do |f|
- f.write errors
- end
+ File.write('20211118145604_alter_structure_of_neighbourhoods.errors.txt', errors)
end
def down
puts 'WARNING: Downgrade path has NOT been verified and should be manually verified first.'
errors = []
Neighbourhood.find_each do |ward|
- begin
- next if ward.unit == 'ward'
-
- puts "Destroying non-ward item of type #{ward.unit} with name #{ward.name}"
- ward.destroy!
- rescue => e
- errors << { error: e.message,
- trace: e.backtrace_locations,
- id: ward.id,
- name: ward.name }
- end
+ next if ward.unit == 'ward'
+ puts "Destroying non-ward item of type #{ward.unit} with name #{ward.name}"
+ ward.destroy!
+ rescue StandardError => e
+ errors << { error: e.message,
+ trace: e.backtrace_locations,
+ id: ward.id,
+ name: ward.name }
end
return unless errors.any?
- File.open('20211118145604_alter_structure_of_neighbourhoods.errors.txt', 'w') do |f|
- f.write errors
- end
+ File.write('20211118145604_alter_structure_of_neighbourhoods.errors.txt', errors)
end
end
diff --git a/db/migrate/20211118162518_remove_old_neighbourhood_properties.rb b/db/migrate/20211118162518_remove_old_neighbourhood_properties.rb
index 4dc0bd4b2..8373acf44 100644
--- a/db/migrate/20211118162518_remove_old_neighbourhood_properties.rb
+++ b/db/migrate/20211118162518_remove_old_neighbourhood_properties.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RemoveOldNeighbourhoodProperties < ActiveRecord::Migration[6.0]
def up
change_table :neighbourhoods, bulk: true do |t|
@@ -35,41 +37,37 @@ def down
end
Neighbourhood.find_each do |ward|
- begin
- next if ward.unit != 'ward'
+ next if ward.unit != 'ward'
- puts "Filling ward #{ward.name} with parental information"
+ puts "Filling ward #{ward.name} with parental information"
- ward.ward = ward.name
- ward.WD19CD = ward.unit_code_value
- ward.WD19NM = ward.unit_name
- if ward.parent
- ward.district = ward.parent.name if ward.parent
- ward.LAD19CD = ward.parent.unit_code_value
- ward.LAD19NM = ward.parent.name
- end
- if ward.parent.parent
- ward.county = ward.parent.parent.name if ward.parent.parent
- ward.CTY19CD = ward.parent.parent.unit_code_value
- ward.CTY19NM = ward.parent.parent.name
- end
- if ward.parent.parent.parent
- ward.region = ward.parent.parent.parent.name if ward.parent.parent.parent
- ward.RGN19CD = ward.parent.parent.parent.unit_code_value
- ward.RGN19NM = ward.parent.parent.parent.name
- end
- rescue => e
- errors << { error: e.message,
- trace: e.backtrace_locations,
- id: ward.id,
- name: ward.name }
+ ward.ward = ward.name
+ ward.WD19CD = ward.unit_code_value
+ ward.WD19NM = ward.unit_name
+ if ward.parent
+ ward.district = ward.parent.name if ward.parent
+ ward.LAD19CD = ward.parent.unit_code_value
+ ward.LAD19NM = ward.parent.name
+ end
+ if ward.parent.parent
+ ward.county = ward.parent.parent.name if ward.parent.parent
+ ward.CTY19CD = ward.parent.parent.unit_code_value
+ ward.CTY19NM = ward.parent.parent.name
end
+ if ward.parent.parent.parent
+ ward.region = ward.parent.parent.parent.name if ward.parent.parent.parent
+ ward.RGN19CD = ward.parent.parent.parent.unit_code_value
+ ward.RGN19NM = ward.parent.parent.parent.name
+ end
+ rescue StandardError => e
+ errors << { error: e.message,
+ trace: e.backtrace_locations,
+ id: ward.id,
+ name: ward.name }
end
return unless errors.any?
- File.open('20211118162518_remove_old_neighbourhood_properties.errors.txt', 'w') do |f|
- f.write errors
- end
+ File.write('20211118162518_remove_old_neighbourhood_properties.errors.txt', errors)
end
end
diff --git a/db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb b/db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb
index 5a7e8fa27..8f51cd908 100644
--- a/db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb
+++ b/db/migrate/20211203153422_correct_datamodel_by_importing_neighbourhoods_json.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CorrectDatamodelByImportingNeighbourhoodsJson < ActiveRecord::Migration[6.1]
# This code is hecking UGLY
def create_unit(json_unit, parent_neighbourhood, parent_unit)
@@ -58,7 +60,7 @@ def up
puts "Processing country #{country['properties']['name']}..."
create_unit(country, nil, nil)
end
- rescue => e
+ rescue StandardError => e
errors << { error: e.message,
trace: e.backtrace_locations }
end
@@ -66,8 +68,6 @@ def up
# Recover from Errors
return unless errors.any?
- File.open('20211118145604_alter_structure_of_neighbourhoods.errors.txt', 'w') do |f|
- f.write errors
- end
+ File.write('20211118145604_alter_structure_of_neighbourhoods.errors.txt', errors)
end
end
diff --git a/db/migrate/20220105161548_fix_broken_datamodel.rb b/db/migrate/20220105161548_fix_broken_datamodel.rb
index 43c91a136..3f40f4474 100644
--- a/db/migrate/20220105161548_fix_broken_datamodel.rb
+++ b/db/migrate/20220105161548_fix_broken_datamodel.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class FixBrokenDatamodel < ActiveRecord::Migration[6.1]
# This code is hecking UGLY
def create_unit(json_unit, parent_neighbourhood, parent_unit)
@@ -38,6 +40,7 @@ def up
# Remove all wards that have ancestry data or are a country (countries lack ancestry data)
Neighbourhood.find_each do |ward|
next unless !ward.ancestry.nil? || ward.unit == 'country'
+
ward.destroy!
end
@@ -50,7 +53,7 @@ def up
json_data.each_value do |country|
create_unit(country, nil, nil)
end
- rescue => e
+ rescue StandardError => e
errors << { error: e.message,
trace: e.backtrace_locations }
end
@@ -58,8 +61,6 @@ def up
# Recover from Errors
return unless errors.any?
- File.open('20220105161548_fix_broken_datamodel.errors', 'w') do |f|
- f.write errors
- end
+ File.write('20220105161548_fix_broken_datamodel.errors', errors)
end
end
diff --git a/db/migrate/20220106150818_add_summary_description_to_partners.rb b/db/migrate/20220106150818_add_summary_description_to_partners.rb
index 95c46f3f6..3bfb81939 100644
--- a/db/migrate/20220106150818_add_summary_description_to_partners.rb
+++ b/db/migrate/20220106150818_add_summary_description_to_partners.rb
@@ -1,12 +1,14 @@
+# frozen_string_literal: true
+
class AddSummaryDescriptionToPartners < ActiveRecord::Migration[6.1]
def up
add_column :partners, :summary, :string
add_column :partners, :description, :text
Partner.find_each do |partner|
- next unless !partner.short_description.nil?
+ next if partner.short_description.nil?
- summary, *description = partner.short_description.split(/\r\n\r\n/)
+ summary, *description = partner.short_description.split("\r\n\r\n")
partner.summary = summary
partner.description = description.join("\r\n\r\n")
partner.save(validate: false)
diff --git a/db/migrate/20220124170103_create_service_areas.rb b/db/migrate/20220124170103_create_service_areas.rb
index 1b10ac590..0cedfd123 100644
--- a/db/migrate/20220124170103_create_service_areas.rb
+++ b/db/migrate/20220124170103_create_service_areas.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateServiceAreas < ActiveRecord::Migration[6.1]
def change
create_table :service_areas do |t|
diff --git a/db/migrate/20220125175817_add_parent_name_field_to_neighbourhoods.rb b/db/migrate/20220125175817_add_parent_name_field_to_neighbourhoods.rb
index 5cfbde6f1..1574c0300 100644
--- a/db/migrate/20220125175817_add_parent_name_field_to_neighbourhoods.rb
+++ b/db/migrate/20220125175817_add_parent_name_field_to_neighbourhoods.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddParentNameFieldToNeighbourhoods < ActiveRecord::Migration[6.1]
def change
add_column :neighbourhoods, :parent_name, :string
diff --git a/db/migrate/20220210165818_add_badge_zoom_level_to_sites.rb b/db/migrate/20220210165818_add_badge_zoom_level_to_sites.rb
index 5fef5a0cb..ee58ac7c7 100644
--- a/db/migrate/20220210165818_add_badge_zoom_level_to_sites.rb
+++ b/db/migrate/20220210165818_add_badge_zoom_level_to_sites.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddBadgeZoomLevelToSites < ActiveRecord::Migration[6.1]
def change
add_column :sites, :badge_zoom_level, :string
diff --git a/db/migrate/20220217050106_add_edit_permission_to_tags.rb b/db/migrate/20220217050106_add_edit_permission_to_tags.rb
index 0cd2e9be0..f5972e210 100644
--- a/db/migrate/20220217050106_add_edit_permission_to_tags.rb
+++ b/db/migrate/20220217050106_add_edit_permission_to_tags.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddEditPermissionToTags < ActiveRecord::Migration[6.1]
def change
add_column :tags, :edit_permission, :string
diff --git a/db/migrate/20220217120103_create_articles.rb b/db/migrate/20220217120103_create_articles.rb
index c01ee29b8..6888921cd 100644
--- a/db/migrate/20220217120103_create_articles.rb
+++ b/db/migrate/20220217120103_create_articles.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateArticles < ActiveRecord::Migration[6.1]
def change
create_table :articles do |t|
@@ -5,7 +7,7 @@ def change
t.text :body
t.date :published_at
t.boolean :is_draft, default: true
-
+
t.timestamps
end
end
diff --git a/db/migrate/20220218131749_create_article_partners.rb b/db/migrate/20220218131749_create_article_partners.rb
index 8a51dd3cd..331593917 100644
--- a/db/migrate/20220218131749_create_article_partners.rb
+++ b/db/migrate/20220218131749_create_article_partners.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateArticlePartners < ActiveRecord::Migration[6.1]
def change
create_table :article_partners do |t|
diff --git a/db/migrate/20220221063323_add_id_to_tags_users.rb b/db/migrate/20220221063323_add_id_to_tags_users.rb
index ca5540e96..4607efea4 100644
--- a/db/migrate/20220221063323_add_id_to_tags_users.rb
+++ b/db/migrate/20220221063323_add_id_to_tags_users.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddIdToTagsUsers < ActiveRecord::Migration[6.1]
def change
add_column :tags_users, :id, :primary_key
diff --git a/db/migrate/20220225162314_add_id_to_partners_tags_and_places_tags.rb b/db/migrate/20220225162314_add_id_to_partners_tags_and_places_tags.rb
index f3f6648ff..47dea7c8b 100644
--- a/db/migrate/20220225162314_add_id_to_partners_tags_and_places_tags.rb
+++ b/db/migrate/20220225162314_add_id_to_partners_tags_and_places_tags.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddIdToPartnersTagsAndPlacesTags < ActiveRecord::Migration[6.1]
def change
rename_table :partners_tags, :partner_tags
diff --git a/db/migrate/20220310125155_add_sites_tags.rb b/db/migrate/20220310125155_add_sites_tags.rb
index 4b788f231..c436566ba 100644
--- a/db/migrate/20220310125155_add_sites_tags.rb
+++ b/db/migrate/20220310125155_add_sites_tags.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddSitesTags < ActiveRecord::Migration[6.1]
def change
create_table :sites_tags do |t|
diff --git a/db/migrate/20220329140520_fix_address_and_neighbourhood_fields.rb b/db/migrate/20220329140520_fix_address_and_neighbourhood_fields.rb
index c1aced770..7eb2574ea 100644
--- a/db/migrate/20220329140520_fix_address_and_neighbourhood_fields.rb
+++ b/db/migrate/20220329140520_fix_address_and_neighbourhood_fields.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class FixAddressAndNeighbourhoodFields < ActiveRecord::Migration[6.1]
def change
# removed code as this type of fix is better performed elsewhere
diff --git a/db/migrate/20220330160817_add_author_to_article.rb b/db/migrate/20220330160817_add_author_to_article.rb
index 758abd331..183587a9c 100644
--- a/db/migrate/20220330160817_add_author_to_article.rb
+++ b/db/migrate/20220330160817_add_author_to_article.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddAuthorToArticle < ActiveRecord::Migration[6.1]
def change
add_reference :articles, :author, foreign_key: { to_table: :users }
diff --git a/db/migrate/20220405102801_add_article_header_to_articles.rb b/db/migrate/20220405102801_add_article_header_to_articles.rb
index 3690705b9..1c5c3e27c 100644
--- a/db/migrate/20220405102801_add_article_header_to_articles.rb
+++ b/db/migrate/20220405102801_add_article_header_to_articles.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddArticleHeaderToArticles < ActiveRecord::Migration[6.1]
def change
add_column :articles, :article_image, :string
diff --git a/db/migrate/20220406135448_create_article_tags.rb b/db/migrate/20220406135448_create_article_tags.rb
index 13b2e7d19..2eee748f5 100644
--- a/db/migrate/20220406135448_create_article_tags.rb
+++ b/db/migrate/20220406135448_create_article_tags.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateArticleTags < ActiveRecord::Migration[6.1]
def change
create_table :article_tags do |t|
diff --git a/db/migrate/20220427131452_add_notices_count_to_calendar.rb b/db/migrate/20220427131452_add_notices_count_to_calendar.rb
index 32f8035c0..b6874a537 100644
--- a/db/migrate/20220427131452_add_notices_count_to_calendar.rb
+++ b/db/migrate/20220427131452_add_notices_count_to_calendar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddNoticesCountToCalendar < ActiveRecord::Migration[6.1]
def change
add_column :calendars, :notice_count, :integer
diff --git a/db/migrate/20220510134827_add_state_to_calendar.rb b/db/migrate/20220510134827_add_state_to_calendar.rb
index 4e68897c3..cecb2bb69 100644
--- a/db/migrate/20220510134827_add_state_to_calendar.rb
+++ b/db/migrate/20220510134827_add_state_to_calendar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddStateToCalendar < ActiveRecord::Migration[6.1]
def change
add_column :calendars, :calendar_state, :string, default: 'idle'
diff --git a/db/migrate/20220512135923_add_publisher_url_to_events.rb b/db/migrate/20220512135923_add_publisher_url_to_events.rb
index 24dde4b7e..216135724 100644
--- a/db/migrate/20220512135923_add_publisher_url_to_events.rb
+++ b/db/migrate/20220512135923_add_publisher_url_to_events.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddPublisherUrlToEvents < ActiveRecord::Migration[6.1]
def change
add_column :events, :publisher_url, :string
diff --git a/db/migrate/20220512144807_create_online_addresses.rb b/db/migrate/20220512144807_create_online_addresses.rb
index e213e1a78..1dd7ba991 100644
--- a/db/migrate/20220512144807_create_online_addresses.rb
+++ b/db/migrate/20220512144807_create_online_addresses.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateOnlineAddresses < ActiveRecord::Migration[6.1]
def change
create_table :online_addresses do |t|
diff --git a/db/migrate/20220516083725_add_importer_mode_to_calendar.rb b/db/migrate/20220516083725_add_importer_mode_to_calendar.rb
index 513659c1a..b6300e275 100644
--- a/db/migrate/20220516083725_add_importer_mode_to_calendar.rb
+++ b/db/migrate/20220516083725_add_importer_mode_to_calendar.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddImporterModeToCalendar < ActiveRecord::Migration[6.1]
def change
add_column :calendars, :importer_mode, :string, default: 'auto'
diff --git a/db/migrate/20220524160826_add_link_type_to_online_address.rb b/db/migrate/20220524160826_add_link_type_to_online_address.rb
index 11d5aaa10..8eb2ca825 100644
--- a/db/migrate/20220524160826_add_link_type_to_online_address.rb
+++ b/db/migrate/20220524160826_add_link_type_to_online_address.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddLinkTypeToOnlineAddress < ActiveRecord::Migration[6.1]
def change
add_column :online_addresses, :link_type, :string
diff --git a/db/migrate/20220601153635_add_slug_to_articles.rb b/db/migrate/20220601153635_add_slug_to_articles.rb
index e57a47af9..9f0fa67ed 100644
--- a/db/migrate/20220601153635_add_slug_to_articles.rb
+++ b/db/migrate/20220601153635_add_slug_to_articles.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddSlugToArticles < ActiveRecord::Migration[6.1]
def change
add_column :articles, :slug, :string
diff --git a/db/migrate/20220607161025_add_system_flag_to_tags.rb b/db/migrate/20220607161025_add_system_flag_to_tags.rb
index b1135060f..a2d4465e1 100644
--- a/db/migrate/20220607161025_add_system_flag_to_tags.rb
+++ b/db/migrate/20220607161025_add_system_flag_to_tags.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AddSystemFlagToTags < ActiveRecord::Migration[6.1]
def change
add_column :tags, :system_tag, :boolean, default: false
diff --git a/db/migrate/20220611154511_add_html_fields_to_models.rb b/db/migrate/20220611154511_add_html_fields_to_models.rb
index 3ecccf73a..901b6bac8 100644
--- a/db/migrate/20220611154511_add_html_fields_to_models.rb
+++ b/db/migrate/20220611154511_add_html_fields_to_models.rb
@@ -1,11 +1,13 @@
+# frozen_string_literal: true
+
class AddHtmlFieldsToModels < ActiveRecord::Migration[6.1]
def change
- add_column :articles, :body_html, :string
- add_column :events, :description_html, :string
- add_column :events, :summary_html, :string
- add_column :partners, :description_html, :string
- add_column :partners, :summary_html, :string
+ add_column :articles, :body_html, :string
+ add_column :events, :description_html, :string
+ add_column :events, :summary_html, :string
+ add_column :partners, :description_html, :string
+ add_column :partners, :summary_html, :string
add_column :partners, :accessibility_info_html, :string
- add_column :sites, :description_html, :string
+ add_column :sites, :description_html, :string
end
end
diff --git a/db/migrate/20220711161804_remove_facebook_fields.rb b/db/migrate/20220711161804_remove_facebook_fields.rb
index 6468c2114..3ad675680 100644
--- a/db/migrate/20220711161804_remove_facebook_fields.rb
+++ b/db/migrate/20220711161804_remove_facebook_fields.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RemoveFacebookFields < ActiveRecord::Migration[6.1]
def change
remove_column :users, :facebook_app_id, :text
diff --git a/db/migrate/20220720151156_remove_calendar_contact_info_fields.rb b/db/migrate/20220720151156_remove_calendar_contact_info_fields.rb
index 2d90a1841..302d05df8 100644
--- a/db/migrate/20220720151156_remove_calendar_contact_info_fields.rb
+++ b/db/migrate/20220720151156_remove_calendar_contact_info_fields.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RemoveCalendarContactInfoFields < ActiveRecord::Migration[6.1]
def change
remove_column :calendars, :partnership_contact_name, :string
diff --git a/db/schema.rb b/db/schema.rb
index e34188150..cbd9804a3 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,418 +10,419 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2022_07_20_151156) do
-
+ActiveRecord::Schema.define(version: 20_220_720_151_156) do
# These are extensions that must be enabled in order to support this database
- enable_extension "plpgsql"
-
- create_table "addresses", id: :serial, force: :cascade do |t|
- t.string "street_address"
- t.string "street_address2"
- t.string "street_address3"
- t.string "city"
- t.string "postcode"
- t.string "country_code", default: "UK"
- t.float "latitude"
- t.float "longitude"
- t.bigint "neighbourhood_id"
- t.index ["neighbourhood_id"], name: "index_addresses_on_neighbourhood_id"
+ enable_extension 'plpgsql'
+
+ create_table 'addresses', id: :serial, force: :cascade do |t|
+ t.string 'street_address'
+ t.string 'street_address2'
+ t.string 'street_address3'
+ t.string 'city'
+ t.string 'postcode'
+ t.string 'country_code', default: 'UK'
+ t.float 'latitude'
+ t.float 'longitude'
+ t.bigint 'neighbourhood_id'
+ t.index ['neighbourhood_id'], name: 'index_addresses_on_neighbourhood_id'
end
- create_table "article_partners", force: :cascade do |t|
- t.bigint "article_id"
- t.bigint "partner_id"
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["article_id", "partner_id"], name: "index_article_partners_on_article_id_and_partner_id", unique: true
- t.index ["article_id"], name: "index_article_partners_on_article_id"
- t.index ["partner_id"], name: "index_article_partners_on_partner_id"
+ create_table 'article_partners', force: :cascade do |t|
+ t.bigint 'article_id'
+ t.bigint 'partner_id'
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.index %w[article_id partner_id], name: 'index_article_partners_on_article_id_and_partner_id', unique: true
+ t.index ['article_id'], name: 'index_article_partners_on_article_id'
+ t.index ['partner_id'], name: 'index_article_partners_on_partner_id'
end
- create_table "article_tags", force: :cascade do |t|
- t.bigint "article_id"
- t.bigint "tag_id"
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["article_id"], name: "index_article_tags_on_article_id"
- t.index ["tag_id"], name: "index_article_tags_on_tag_id"
+ create_table 'article_tags', force: :cascade do |t|
+ t.bigint 'article_id'
+ t.bigint 'tag_id'
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.index ['article_id'], name: 'index_article_tags_on_article_id'
+ t.index ['tag_id'], name: 'index_article_tags_on_tag_id'
end
- create_table "articles", force: :cascade do |t|
- t.text "title"
- t.text "body"
- t.date "published_at"
- t.boolean "is_draft", default: true
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.bigint "author_id"
- t.string "article_image"
- t.string "slug"
- t.string "body_html"
- t.index ["author_id"], name: "index_articles_on_author_id"
- t.index ["slug"], name: "index_articles_on_slug", unique: true
+ create_table 'articles', force: :cascade do |t|
+ t.text 'title'
+ t.text 'body'
+ t.date 'published_at'
+ t.boolean 'is_draft', default: true
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.bigint 'author_id'
+ t.string 'article_image'
+ t.string 'slug'
+ t.string 'body_html'
+ t.index ['author_id'], name: 'index_articles_on_author_id'
+ t.index ['slug'], name: 'index_articles_on_slug', unique: true
end
- create_table "calendars", id: :serial, force: :cascade do |t|
- t.string "name"
- t.string "source"
- t.jsonb "notices"
- t.datetime "last_import_at"
- t.integer "partner_id"
- t.integer "place_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "strategy"
- t.string "last_checksum"
- t.text "critical_error"
- t.string "page_access_token"
- t.boolean "is_working", default: true, null: false
- t.string "public_contact_name"
- t.string "public_contact_email"
- t.string "public_contact_phone"
- t.integer "notice_count"
- t.string "source_type", default: ""
- t.string "calendar_state", default: "idle"
- t.string "importer_mode", default: "auto"
- t.string "importer_used"
- t.index ["partner_id"], name: "index_calendars_on_partner_id"
- t.index ["place_id"], name: "index_calendars_on_place_id"
+ create_table 'calendars', id: :serial, force: :cascade do |t|
+ t.string 'name'
+ t.string 'source'
+ t.jsonb 'notices'
+ t.datetime 'last_import_at'
+ t.integer 'partner_id'
+ t.integer 'place_id'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.string 'strategy'
+ t.string 'last_checksum'
+ t.text 'critical_error'
+ t.string 'page_access_token'
+ t.boolean 'is_working', default: true, null: false
+ t.string 'public_contact_name'
+ t.string 'public_contact_email'
+ t.string 'public_contact_phone'
+ t.integer 'notice_count'
+ t.string 'source_type', default: ''
+ t.string 'calendar_state', default: 'idle'
+ t.string 'importer_mode', default: 'auto'
+ t.string 'importer_used'
+ t.index ['partner_id'], name: 'index_calendars_on_partner_id'
+ t.index ['place_id'], name: 'index_calendars_on_place_id'
end
- create_table "collections", force: :cascade do |t|
- t.string "name"
- t.text "description"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "image"
- t.string "route"
+ create_table 'collections', force: :cascade do |t|
+ t.string 'name'
+ t.text 'description'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.string 'image'
+ t.string 'route'
end
- create_table "collections_events", id: false, force: :cascade do |t|
- t.bigint "collection_id", null: false
- t.bigint "event_id", null: false
- t.index ["collection_id", "event_id"], name: "index_collections_events_on_collection_id_and_event_id"
- t.index ["event_id", "collection_id"], name: "index_collections_events_on_event_id_and_collection_id"
+ create_table 'collections_events', id: false, force: :cascade do |t|
+ t.bigint 'collection_id', null: false
+ t.bigint 'event_id', null: false
+ t.index %w[collection_id event_id], name: 'index_collections_events_on_collection_id_and_event_id'
+ t.index %w[event_id collection_id], name: 'index_collections_events_on_event_id_and_collection_id'
end
- create_table "delayed_jobs", force: :cascade do |t|
- t.integer "priority", default: 0, null: false
- t.integer "attempts", default: 0, null: false
- t.text "handler", null: false
- t.text "last_error"
- t.datetime "run_at"
- t.datetime "locked_at"
- t.datetime "failed_at"
- t.string "locked_by"
- t.string "queue"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.index ["priority", "run_at"], name: "delayed_jobs_priority"
+ create_table 'delayed_jobs', force: :cascade do |t|
+ t.integer 'priority', default: 0, null: false
+ t.integer 'attempts', default: 0, null: false
+ t.text 'handler', null: false
+ t.text 'last_error'
+ t.datetime 'run_at'
+ t.datetime 'locked_at'
+ t.datetime 'failed_at'
+ t.string 'locked_by'
+ t.string 'queue'
+ t.datetime 'created_at'
+ t.datetime 'updated_at'
+ t.index %w[priority run_at], name: 'delayed_jobs_priority'
end
- create_table "events", id: :serial, force: :cascade do |t|
- t.integer "place_id"
- t.integer "calendar_id"
- t.string "uid"
- t.text "summary"
- t.text "description"
- t.text "raw_location_from_source"
- t.jsonb "rrule"
- t.jsonb "notices"
- t.boolean "is_active", default: true, null: false
- t.datetime "dtstart"
- t.datetime "dtend"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.integer "partner_id"
- t.integer "address_id"
- t.string "are_spaces_available"
- t.text "footer"
- t.string "publisher_url"
- t.bigint "online_address_id"
- t.string "description_html"
- t.string "summary_html"
- t.index ["calendar_id"], name: "index_events_on_calendar_id"
- t.index ["online_address_id"], name: "index_events_on_online_address_id"
- t.index ["place_id"], name: "index_events_on_place_id"
+ create_table 'events', id: :serial, force: :cascade do |t|
+ t.integer 'place_id'
+ t.integer 'calendar_id'
+ t.string 'uid'
+ t.text 'summary'
+ t.text 'description'
+ t.text 'raw_location_from_source'
+ t.jsonb 'rrule'
+ t.jsonb 'notices'
+ t.boolean 'is_active', default: true, null: false
+ t.datetime 'dtstart'
+ t.datetime 'dtend'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.integer 'partner_id'
+ t.integer 'address_id'
+ t.string 'are_spaces_available'
+ t.text 'footer'
+ t.string 'publisher_url'
+ t.bigint 'online_address_id'
+ t.string 'description_html'
+ t.string 'summary_html'
+ t.index ['calendar_id'], name: 'index_events_on_calendar_id'
+ t.index ['online_address_id'], name: 'index_events_on_online_address_id'
+ t.index ['place_id'], name: 'index_events_on_place_id'
end
- create_table "friendly_id_slugs", force: :cascade do |t|
- t.string "slug", null: false
- t.integer "sluggable_id", null: false
- t.string "sluggable_type", limit: 50
- t.string "scope"
- t.datetime "created_at"
- t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
- t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
- t.index ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id"
- t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type"
+ create_table 'friendly_id_slugs', force: :cascade do |t|
+ t.string 'slug', null: false
+ t.integer 'sluggable_id', null: false
+ t.string 'sluggable_type', limit: 50
+ t.string 'scope'
+ t.datetime 'created_at'
+ t.index %w[slug sluggable_type scope], name: 'index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope',
+ unique: true
+ t.index %w[slug sluggable_type], name: 'index_friendly_id_slugs_on_slug_and_sluggable_type'
+ t.index ['sluggable_id'], name: 'index_friendly_id_slugs_on_sluggable_id'
+ t.index ['sluggable_type'], name: 'index_friendly_id_slugs_on_sluggable_type'
end
- create_table "neighbourhoods", force: :cascade do |t|
- t.string "name"
- t.string "name_abbr"
- t.string "ancestry"
- t.string "unit", default: "ward"
- t.string "unit_code_key", default: "WD19CD"
- t.string "unit_code_value"
- t.string "unit_name"
- t.string "parent_name"
- t.index ["ancestry"], name: "index_neighbourhoods_on_ancestry"
+ create_table 'neighbourhoods', force: :cascade do |t|
+ t.string 'name'
+ t.string 'name_abbr'
+ t.string 'ancestry'
+ t.string 'unit', default: 'ward'
+ t.string 'unit_code_key', default: 'WD19CD'
+ t.string 'unit_code_value'
+ t.string 'unit_name'
+ t.string 'parent_name'
+ t.index ['ancestry'], name: 'index_neighbourhoods_on_ancestry'
end
- create_table "neighbourhoods_users", force: :cascade do |t|
- t.bigint "neighbourhood_id"
- t.bigint "user_id"
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["neighbourhood_id"], name: "index_neighbourhoods_users_on_neighbourhood_id"
- t.index ["user_id"], name: "index_neighbourhoods_users_on_user_id"
+ create_table 'neighbourhoods_users', force: :cascade do |t|
+ t.bigint 'neighbourhood_id'
+ t.bigint 'user_id'
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.index ['neighbourhood_id'], name: 'index_neighbourhoods_users_on_neighbourhood_id'
+ t.index ['user_id'], name: 'index_neighbourhoods_users_on_user_id'
end
- create_table "online_addresses", force: :cascade do |t|
- t.string "url"
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.string "link_type"
+ create_table 'online_addresses', force: :cascade do |t|
+ t.string 'url'
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.string 'link_type'
end
- create_table "organisation_relationships", force: :cascade do |t|
- t.bigint "subject_id", null: false
- t.string "verb", null: false
- t.bigint "object_id", null: false
- t.index ["object_id"], name: "index_organisation_relationships_on_object_id"
- t.index ["subject_id", "verb", "object_id"], name: "unique_organisation_relationship_row", unique: true
- t.index ["subject_id"], name: "index_organisation_relationships_on_subject_id"
+ create_table 'organisation_relationships', force: :cascade do |t|
+ t.bigint 'subject_id', null: false
+ t.string 'verb', null: false
+ t.bigint 'object_id', null: false
+ t.index ['object_id'], name: 'index_organisation_relationships_on_object_id'
+ t.index %w[subject_id verb object_id], name: 'unique_organisation_relationship_row', unique: true
+ t.index ['subject_id'], name: 'index_organisation_relationships_on_subject_id'
end
- create_table "partner_tags", force: :cascade do |t|
- t.bigint "partner_id", null: false
- t.bigint "tag_id", null: false
- t.index ["partner_id", "tag_id"], name: "index_partner_tags_on_partner_id_and_tag_id"
- t.index ["tag_id", "partner_id"], name: "index_partner_tags_on_tag_id_and_partner_id"
+ create_table 'partner_tags', force: :cascade do |t|
+ t.bigint 'partner_id', null: false
+ t.bigint 'tag_id', null: false
+ t.index %w[partner_id tag_id], name: 'index_partner_tags_on_partner_id_and_tag_id'
+ t.index %w[tag_id partner_id], name: 'index_partner_tags_on_tag_id_and_partner_id'
end
- create_table "partners", id: :serial, force: :cascade do |t|
- t.string "name"
- t.string "image"
- t.string "public_phone"
- t.string "public_email"
- t.string "admin_name"
- t.string "admin_email"
- t.integer "address_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.boolean "is_a_place"
- t.string "slug"
- t.string "partner_email"
- t.string "partner_name"
- t.string "partner_phone"
- t.string "calendar_email"
- t.string "calendar_phone"
- t.string "calendar_name"
- t.string "public_name"
- t.string "url"
- t.jsonb "opening_times"
- t.text "booking_info"
- t.text "accessibility_info"
- t.string "twitter_handle"
- t.string "summary"
- t.text "description"
- t.string "facebook_link"
- t.string "description_html"
- t.string "summary_html"
- t.string "accessibility_info_html"
- t.index ["address_id"], name: "index_partners_on_address_id"
- t.index ["slug"], name: "index_partners_on_slug", unique: true
+ create_table 'partners', id: :serial, force: :cascade do |t|
+ t.string 'name'
+ t.string 'image'
+ t.string 'public_phone'
+ t.string 'public_email'
+ t.string 'admin_name'
+ t.string 'admin_email'
+ t.integer 'address_id'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.boolean 'is_a_place'
+ t.string 'slug'
+ t.string 'partner_email'
+ t.string 'partner_name'
+ t.string 'partner_phone'
+ t.string 'calendar_email'
+ t.string 'calendar_phone'
+ t.string 'calendar_name'
+ t.string 'public_name'
+ t.string 'url'
+ t.jsonb 'opening_times'
+ t.text 'booking_info'
+ t.text 'accessibility_info'
+ t.string 'twitter_handle'
+ t.string 'summary'
+ t.text 'description'
+ t.string 'facebook_link'
+ t.string 'description_html'
+ t.string 'summary_html'
+ t.string 'accessibility_info_html'
+ t.index ['address_id'], name: 'index_partners_on_address_id'
+ t.index ['slug'], name: 'index_partners_on_slug', unique: true
end
- create_table "partners_places", id: :serial, force: :cascade do |t|
- t.integer "partner_id"
- t.integer "place_id"
- t.index ["partner_id"], name: "index_partners_places_on_partner_id"
- t.index ["place_id"], name: "index_partners_places_on_place_id"
+ create_table 'partners_places', id: :serial, force: :cascade do |t|
+ t.integer 'partner_id'
+ t.integer 'place_id'
+ t.index ['partner_id'], name: 'index_partners_places_on_partner_id'
+ t.index ['place_id'], name: 'index_partners_places_on_place_id'
end
- create_table "partners_users", id: :serial, force: :cascade do |t|
- t.integer "partner_id"
- t.integer "user_id"
- t.index ["partner_id"], name: "index_partners_users_on_partner_id"
- t.index ["user_id"], name: "index_partners_users_on_user_id"
+ create_table 'partners_users', id: :serial, force: :cascade do |t|
+ t.integer 'partner_id'
+ t.integer 'user_id'
+ t.index ['partner_id'], name: 'index_partners_users_on_partner_id'
+ t.index ['user_id'], name: 'index_partners_users_on_user_id'
end
- create_table "places", id: :serial, force: :cascade do |t|
- t.string "name"
- t.string "status"
- t.string "logo"
- t.string "phone"
- t.jsonb "opening_times"
- t.text "short_description"
- t.text "booking_info"
- t.text "accessibility_info"
- t.integer "address_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "email"
- t.string "url"
- t.string "slug"
- t.index ["address_id"], name: "index_places_on_address_id"
- t.index ["slug"], name: "index_places_on_slug", unique: true
+ create_table 'places', id: :serial, force: :cascade do |t|
+ t.string 'name'
+ t.string 'status'
+ t.string 'logo'
+ t.string 'phone'
+ t.jsonb 'opening_times'
+ t.text 'short_description'
+ t.text 'booking_info'
+ t.text 'accessibility_info'
+ t.integer 'address_id'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.string 'email'
+ t.string 'url'
+ t.string 'slug'
+ t.index ['address_id'], name: 'index_places_on_address_id'
+ t.index ['slug'], name: 'index_places_on_slug', unique: true
end
- create_table "seed_migration_data_migrations", id: :serial, force: :cascade do |t|
- t.string "version"
- t.integer "runtime"
- t.datetime "migrated_on"
+ create_table 'seed_migration_data_migrations', id: :serial, force: :cascade do |t|
+ t.string 'version'
+ t.integer 'runtime'
+ t.datetime 'migrated_on'
end
- create_table "service_areas", force: :cascade do |t|
- t.bigint "neighbourhood_id"
- t.bigint "partner_id"
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["neighbourhood_id", "partner_id"], name: "index_service_areas_on_neighbourhood_id_and_partner_id", unique: true
- t.index ["neighbourhood_id"], name: "index_service_areas_on_neighbourhood_id"
- t.index ["partner_id"], name: "index_service_areas_on_partner_id"
+ create_table 'service_areas', force: :cascade do |t|
+ t.bigint 'neighbourhood_id'
+ t.bigint 'partner_id'
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.index %w[neighbourhood_id partner_id], name: 'index_service_areas_on_neighbourhood_id_and_partner_id',
+ unique: true
+ t.index ['neighbourhood_id'], name: 'index_service_areas_on_neighbourhood_id'
+ t.index ['partner_id'], name: 'index_service_areas_on_partner_id'
end
- create_table "sites", force: :cascade do |t|
- t.string "name"
- t.string "slug"
- t.string "domain"
- t.text "description"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.bigint "site_admin_id"
- t.string "logo"
- t.string "hero_image"
- t.string "hero_image_credit"
- t.string "footer_logo"
- t.string "tagline", default: "The Community Calendar"
- t.string "place_name"
- t.string "theme"
- t.boolean "is_published", default: false
- t.string "badge_zoom_level"
- t.string "description_html"
- t.index ["site_admin_id"], name: "index_sites_on_site_admin_id"
+ create_table 'sites', force: :cascade do |t|
+ t.string 'name'
+ t.string 'slug'
+ t.string 'domain'
+ t.text 'description'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.bigint 'site_admin_id'
+ t.string 'logo'
+ t.string 'hero_image'
+ t.string 'hero_image_credit'
+ t.string 'footer_logo'
+ t.string 'tagline', default: 'The Community Calendar'
+ t.string 'place_name'
+ t.string 'theme'
+ t.boolean 'is_published', default: false
+ t.string 'badge_zoom_level'
+ t.string 'description_html'
+ t.index ['site_admin_id'], name: 'index_sites_on_site_admin_id'
end
- create_table "sites_neighbourhoods", force: :cascade do |t|
- t.integer "neighbourhood_id"
- t.integer "site_id"
- t.string "relation_type"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ create_table 'sites_neighbourhoods', force: :cascade do |t|
+ t.integer 'neighbourhood_id'
+ t.integer 'site_id'
+ t.string 'relation_type'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
end
- create_table "sites_supporters", id: false, force: :cascade do |t|
- t.bigint "site_id", null: false
- t.bigint "supporter_id", null: false
- t.index ["site_id", "supporter_id"], name: "index_sites_supporters_on_site_id_and_supporter_id"
- t.index ["supporter_id", "site_id"], name: "index_sites_supporters_on_supporter_id_and_site_id"
+ create_table 'sites_supporters', id: false, force: :cascade do |t|
+ t.bigint 'site_id', null: false
+ t.bigint 'supporter_id', null: false
+ t.index %w[site_id supporter_id], name: 'index_sites_supporters_on_site_id_and_supporter_id'
+ t.index %w[supporter_id site_id], name: 'index_sites_supporters_on_supporter_id_and_site_id'
end
- create_table "sites_tags", force: :cascade do |t|
- t.bigint "site_id"
- t.bigint "tag_id"
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["site_id", "tag_id"], name: "index_sites_tags_on_site_id_and_tag_id", unique: true
- t.index ["site_id"], name: "index_sites_tags_on_site_id"
- t.index ["tag_id"], name: "index_sites_tags_on_tag_id"
+ create_table 'sites_tags', force: :cascade do |t|
+ t.bigint 'site_id'
+ t.bigint 'tag_id'
+ t.datetime 'created_at', precision: 6, null: false
+ t.datetime 'updated_at', precision: 6, null: false
+ t.index %w[site_id tag_id], name: 'index_sites_tags_on_site_id_and_tag_id', unique: true
+ t.index ['site_id'], name: 'index_sites_tags_on_site_id'
+ t.index ['tag_id'], name: 'index_sites_tags_on_tag_id'
end
- create_table "supporters", force: :cascade do |t|
- t.string "name"
- t.string "url"
- t.string "logo"
- t.string "description"
- t.integer "weight"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.boolean "is_global", default: false
+ create_table 'supporters', force: :cascade do |t|
+ t.string 'name'
+ t.string 'url'
+ t.string 'logo'
+ t.string 'description'
+ t.integer 'weight'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.boolean 'is_global', default: false
end
- create_table "tags", force: :cascade do |t|
- t.string "name"
- t.string "slug"
- t.text "description"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "edit_permission"
- t.boolean "system_tag", default: false
+ create_table 'tags', force: :cascade do |t|
+ t.string 'name'
+ t.string 'slug'
+ t.text 'description'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.string 'edit_permission'
+ t.boolean 'system_tag', default: false
end
- create_table "tags_users", force: :cascade do |t|
- t.bigint "tag_id", null: false
- t.bigint "user_id", null: false
- t.index ["tag_id", "user_id"], name: "index_tags_users_on_tag_id_and_user_id"
- t.index ["user_id", "tag_id"], name: "index_tags_users_on_user_id_and_tag_id"
+ create_table 'tags_users', force: :cascade do |t|
+ t.bigint 'tag_id', null: false
+ t.bigint 'user_id', null: false
+ t.index %w[tag_id user_id], name: 'index_tags_users_on_tag_id_and_user_id'
+ t.index %w[user_id tag_id], name: 'index_tags_users_on_user_id_and_tag_id'
end
- create_table "users", id: :serial, force: :cascade do |t|
- t.string "first_name"
- t.string "last_name"
- t.string "role"
- t.string "phone"
- t.string "email", default: "", null: false
- t.string "encrypted_password", default: ""
- t.string "reset_password_token"
- t.datetime "reset_password_sent_at"
- t.datetime "remember_created_at"
- t.integer "sign_in_count", default: 0, null: false
- t.datetime "current_sign_in_at"
- t.datetime "last_sign_in_at"
- t.inet "current_sign_in_ip"
- t.inet "last_sign_in_ip"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "access_token"
- t.string "access_token_expires_at"
- t.string "invitation_token"
- t.datetime "invitation_created_at"
- t.datetime "invitation_sent_at"
- t.datetime "invitation_accepted_at"
- t.integer "invitation_limit"
- t.integer "invited_by_id"
- t.string "invited_by_type"
- t.string "avatar"
- t.index ["email"], name: "index_users_on_email", unique: true
- t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
- t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
+ create_table 'users', id: :serial, force: :cascade do |t|
+ t.string 'first_name'
+ t.string 'last_name'
+ t.string 'role'
+ t.string 'phone'
+ t.string 'email', default: '', null: false
+ t.string 'encrypted_password', default: ''
+ t.string 'reset_password_token'
+ t.datetime 'reset_password_sent_at'
+ t.datetime 'remember_created_at'
+ t.integer 'sign_in_count', default: 0, null: false
+ t.datetime 'current_sign_in_at'
+ t.datetime 'last_sign_in_at'
+ t.inet 'current_sign_in_ip'
+ t.inet 'last_sign_in_ip'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.string 'access_token'
+ t.string 'access_token_expires_at'
+ t.string 'invitation_token'
+ t.datetime 'invitation_created_at'
+ t.datetime 'invitation_sent_at'
+ t.datetime 'invitation_accepted_at'
+ t.integer 'invitation_limit'
+ t.integer 'invited_by_id'
+ t.string 'invited_by_type'
+ t.string 'avatar'
+ t.index ['email'], name: 'index_users_on_email', unique: true
+ t.index ['invitation_token'], name: 'index_users_on_invitation_token', unique: true
+ t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
end
- create_table "versions", force: :cascade do |t|
- t.string "item_type", null: false
- t.integer "item_id", null: false
- t.string "event", null: false
- t.string "whodunnit"
- t.jsonb "object"
- t.jsonb "object_changes"
- t.datetime "created_at"
- t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
+ create_table 'versions', force: :cascade do |t|
+ t.string 'item_type', null: false
+ t.integer 'item_id', null: false
+ t.string 'event', null: false
+ t.string 'whodunnit'
+ t.jsonb 'object'
+ t.jsonb 'object_changes'
+ t.datetime 'created_at'
+ t.index %w[item_type item_id], name: 'index_versions_on_item_type_and_item_id'
end
- add_foreign_key "addresses", "neighbourhoods"
- add_foreign_key "articles", "users", column: "author_id"
- add_foreign_key "calendars", "partners"
- add_foreign_key "calendars", "partners", column: "place_id"
- add_foreign_key "events", "addresses"
- add_foreign_key "events", "calendars"
- add_foreign_key "events", "online_addresses"
- add_foreign_key "events", "partners"
- add_foreign_key "events", "partners", column: "place_id"
- add_foreign_key "organisation_relationships", "partners", column: "object_id"
- add_foreign_key "organisation_relationships", "partners", column: "subject_id"
- add_foreign_key "partners", "addresses"
- add_foreign_key "partners_places", "partners"
- add_foreign_key "partners_places", "places"
- add_foreign_key "partners_users", "partners"
- add_foreign_key "partners_users", "users"
- add_foreign_key "places", "addresses"
- add_foreign_key "service_areas", "neighbourhoods"
- add_foreign_key "service_areas", "partners"
- add_foreign_key "sites", "users", column: "site_admin_id"
- add_foreign_key "sites_tags", "sites"
- add_foreign_key "sites_tags", "tags"
+ add_foreign_key 'addresses', 'neighbourhoods'
+ add_foreign_key 'articles', 'users', column: 'author_id'
+ add_foreign_key 'calendars', 'partners'
+ add_foreign_key 'calendars', 'partners', column: 'place_id'
+ add_foreign_key 'events', 'addresses'
+ add_foreign_key 'events', 'calendars'
+ add_foreign_key 'events', 'online_addresses'
+ add_foreign_key 'events', 'partners'
+ add_foreign_key 'events', 'partners', column: 'place_id'
+ add_foreign_key 'organisation_relationships', 'partners', column: 'object_id'
+ add_foreign_key 'organisation_relationships', 'partners', column: 'subject_id'
+ add_foreign_key 'partners', 'addresses'
+ add_foreign_key 'partners_places', 'partners'
+ add_foreign_key 'partners_places', 'places'
+ add_foreign_key 'partners_users', 'partners'
+ add_foreign_key 'partners_users', 'users'
+ add_foreign_key 'places', 'addresses'
+ add_foreign_key 'service_areas', 'neighbourhoods'
+ add_foreign_key 'service_areas', 'partners'
+ add_foreign_key 'sites', 'users', column: 'site_admin_id'
+ add_foreign_key 'sites_tags', 'sites'
+ add_foreign_key 'sites_tags', 'tags'
end
diff --git a/db/seeds.rb b/db/seeds.rb
index 23e447b91..e2e1822f8 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -1,4 +1,5 @@
-# encoding: UTF-8
+# frozen_string_literal: true
+
# This file is auto-generated from the current content of the database. Instead
# of editing this file, please use the migrations feature of Seed Migration to
# incrementally modify your database, and then regenerate this seed file.
@@ -13,4 +14,4 @@
ActiveRecord::Base.transaction do
end
-SeedMigration::Migrator.bootstrap(20180625172033)
+SeedMigration::Migrator.bootstrap(20_180_625_172_033)
diff --git a/db/seeds_to_migrate.rb b/db/seeds_to_migrate.rb
index 05d6f9f9e..636842ce1 100644
--- a/db/seeds_to_migrate.rb
+++ b/db/seeds_to_migrate.rb
@@ -62,7 +62,6 @@
# Hulme & Moss Side Age Friendly Events
hulme_moss = Partner.create(name: 'Hulme & Moss Side Age Friendly Events')
-
Turf.where(name: 'Hulme',
slug: 'hulme',
turf_type: 'neighbourhood',
diff --git a/lib/tasks/addresses.rake b/lib/tasks/addresses.rake
index e275af130..ce972bccc 100644
--- a/lib/tasks/addresses.rake
+++ b/lib/tasks/addresses.rake
@@ -1,7 +1,8 @@
-namespace :addresses do
+# frozen_string_literal: true
+namespace :addresses do
# TODO: Refactor these two tasks to use a lower level task
- desc "Geocode all addresses in order to identify neighbourhood tags"
+ desc 'Geocode all addresses in order to identify neighbourhood tags'
task update_all_neighbourhood_tags: :environment do
$stdout.puts "Regeocoding #{Address.count} Addresses:"
num = 1
@@ -9,35 +10,35 @@ namespace :addresses do
$stdout.puts "#{num}: #{a.street_address}, #{a.postcode}"
a.geocode_with_ward
a.save
- num+=1
+ num += 1
end
end
- desc "Geocode addresses that do not have a neighbourhood tag"
+ desc 'Geocode addresses that do not have a neighbourhood tag'
task set_missing_neighbourhood_tags: :environment do
- $stdout.puts "Geocoding #{Address.where( neighbourhood_tag: nil ).count} Addresses:"
+ $stdout.puts "Geocoding #{Address.where(neighbourhood_tag: nil).count} Addresses:"
num = 1
- Address.where( neighbourhood_tag: nil ).each do |a|
+ Address.where(neighbourhood_tag: nil).each do |a|
$stdout.puts "#{num}: #{a.street_address}, #{a.postcode}"
a.geocode_with_ward
a.save
- num+=1
+ num += 1
end
end
end
# TODO? Move this to events.rake ? events.rake contains namespace :import
namespace :events do
- desc "Set Event#address from Event#place.address for Events that do not have an Address"
+ desc 'Set Event#address from Event#place.address for Events that do not have an Address'
task set_missing_addresses_from_place: :environment do
- events = Event.where( address_id: nil ).where.not( place_id: nil )
+ events = Event.where(address_id: nil).where.not(place_id: nil)
$stdout.puts "Updating #{events.count} Events:"
num = 1
events.each do |e|
$stdout.puts "#{num}: #{e.summary}, #{e.place.name}"
e.place = e.place
e.save
- num+=1
+ num += 1
end
end
end
diff --git a/lib/tasks/auto_generate_diagram.rake b/lib/tasks/auto_generate_diagram.rake
index 1df069625..48df78352 100644
--- a/lib/tasks/auto_generate_diagram.rake
+++ b/lib/tasks/auto_generate_diagram.rake
@@ -1,6 +1,6 @@
+# frozen_string_literal: true
+
# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
-if Rails.env.development?
- RailsERD.load_tasks
-end
+RailsERD.load_tasks if Rails.env.development?
diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake
index c41684675..eb0ef7e41 100644
--- a/lib/tasks/data.rake
+++ b/lib/tasks/data.rake
@@ -1,10 +1,8 @@
# frozen_string_literal: true
namespace :data do
-
desc 'Fix fields that need to be rendered to HTML'
- task :render_html_fields => :environment do
-
+ task render_html_fields: :environment do
PaperTrail.enabled = false
@bad_count = 0
@@ -16,9 +14,8 @@ namespace :data do
fix_model Site
fix_model Partner
-
fix_model Event do |event|
- next if event.description_html.to_s.length > 0
+ next if event.description_html.to_s.length.positive?
description_text = Kramdown::Document.new(event.description.to_s, input: 'html').to_kramdown.strip
event.description = description_text
@@ -46,10 +43,8 @@ namespace :data do
saved = record.save
end
- @bad_count += 1 if !saved
+ @bad_count += 1 unless saved
end
end
end
-
end
-
diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake
index c1667f26c..d1f7b6cf6 100644
--- a/lib/tasks/db.rake
+++ b/lib/tasks/db.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Original source: https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# Merged with: https://gist.github.com/kofronpi/37130f5ed670465b1fe2d170f754f8c6
#
@@ -29,16 +31,17 @@
#
# Original source: https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# Merged with: https://gist.github.com/kofronpi/37130f5ed670465b1fe2d170f754f8c6
+require 'English'
namespace :db do
desc 'Dumps the database to backups'
task dump: :environment do
- dump_fmt = ensure_format(ENV['format'])
+ dump_fmt = ensure_format(ENV.fetch('format', nil))
dump_sfx = suffix_for_format(dump_fmt)
backup_dir = backup_directory(Rails.env, create: true)
full_path = nil
cmd = nil
- with_config do |app, host, db, user|
+ with_config do |_app, host, db, user|
full_path = "#{backup_dir}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{db}.#{dump_sfx}"
cmd = "pg_dump -F #{dump_fmt} -v -O -o -U '#{user}' -h '#{host}' -d '#{db}' -f '#{full_path}'"
end
@@ -53,16 +56,16 @@ namespace :db do
namespace :dump do
desc 'Dumps a specific table to backups'
task table: :environment do
- table_name = ENV['table']
+ table_name = ENV.fetch('table', nil)
if table_name.present?
- dump_fmt = ensure_format(ENV['format'])
+ dump_fmt = ensure_format(ENV.fetch('format', nil))
dump_sfx = suffix_for_format(dump_fmt)
backup_dir = backup_directory(Rails.env, create: true)
full_path = nil
cmd = nil
- with_config do |app, host, db, user|
+ with_config do |_app, host, db, user|
full_path = "#{backup_dir}/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{db}.#{table_name.parameterize.underscore}.#{dump_sfx}"
cmd = "pg_dump -F #{dump_fmt} -v -O -o -U '#{user}' -h '#{host}' -d '#{db}' -t '#{table_name}' -f '#{full_path}'"
end
@@ -81,19 +84,19 @@ namespace :db do
desc 'Show the existing database backups'
task dumps: :environment do
backup_dir = backup_directory
- puts "#{backup_dir}"
+ puts backup_dir.to_s
system "/bin/ls -ltR #{backup_dir}"
end
desc 'Restores the database from a backup using PATTERN'
task restore: :environment do
- pattern = ENV['pattern']
+ pattern = ENV.fetch('pattern', nil)
if pattern.present?
file = nil
cmd = nil
- with_config do |app, host, db, user|
+ with_config do |_app, host, db, user|
backup_dir = backup_directory
files = Dir.glob("#{backup_dir}/**/*#{pattern}*")
@@ -114,15 +117,15 @@ namespace :db do
end
else
puts "Too many files match the pattern '#{pattern}':"
- puts ' ' + files.join("\n ")
+ puts " #{files.join("\n ")}"
puts ''
- puts "Try a more specific pattern"
+ puts 'Try a more specific pattern'
puts ''
end
end
unless cmd.nil?
- Rake::Task["db:drop"].invoke
- Rake::Task["db:create"].invoke
+ Rake::Task['db:drop'].invoke
+ Rake::Task['db:create'].invoke
puts cmd
system cmd
puts ''
@@ -141,95 +144,73 @@ namespace :db do
DB_DUMP_SSH_URL = 'DB_DUMP_SSH_URL'
DB_DUMP_STAGING_SSH_URL = 'DB_DUMP_STAGING_SSH_URL'
- desc "Synchronize staging with the production database in one fell swoop"
+ desc 'Synchronize staging with the production database in one fell swoop'
task sync_prod_staging: :environment do
+ prod_ssh_url = ENV.fetch(DB_DUMP_SSH_URL, 'root@placecal.org -p 666')
- prod_ssh_url = if ENV[DB_DUMP_SSH_URL]
- ENV[DB_DUMP_SSH_URL]
- else
- 'root@placecal.org -p 666'
- end
+ ssh_url = ENV.fetch(DB_DUMP_STAGING_SSH_URL, 'root@placecal-staging.org -p 666')
- ssh_url = if ENV[DB_DUMP_STAGING_SSH_URL]
- ENV[DB_DUMP_STAGING_SSH_URL]
- else
- 'root@placecal-staging.org -p 666'
- end
-
- $stdout.puts "Backing up staging db (May take a while.) ..."
+ $stdout.puts 'Backing up staging db (May take a while.) ...'
puts `ssh #{ssh_url} dokku postgres:export placecal-db > $(date -Im)_placecal-staging.sql`
- $stdout.puts "Replicating production db to staging db (May take a while.) ..."
+ $stdout.puts 'Replicating production db to staging db (May take a while.) ...'
puts `ssh #{prod_ssh_url} dokku postgres:export placecal-db2 | ssh #{ssh_url} dokku postgres:import placecal-db`
- if $?.success?
- $stdout.puts "Replicated production to staging (you might have to run rails db:migrate in dokku?)"
+ if $CHILD_STATUS.success?
+ $stdout.puts 'Replicated production to staging (you might have to run rails db:migrate in dokku?)'
else
- $stderr.puts "Failed to replicate production to staging!"
+ warn 'Failed to replicate production to staging!'
end
end
- desc "Download production DB dump"
+ desc 'Download production DB dump'
task dump_production: :environment do
+ filename = ENV.fetch(DB_DUMP_ENV_KEY) { "#{Rails.root}/dump/production_#{Time.now.to_i}.sql" }
- filename = if ENV[DB_DUMP_ENV_KEY]
- ENV[DB_DUMP_ENV_KEY]
- else
- "#{Rails.root}/dump/production_#{Time.now.to_i}.sql"
- end
-
- ssh_url = if ENV[DB_DUMP_SSH_URL]
- ENV[DB_DUMP_SSH_URL]
- else
- "root@placecal.org -p 666"
- end
+ ssh_url = ENV.fetch(DB_DUMP_SSH_URL, 'root@placecal.org -p 666')
$stdout.puts "Downloading production db to #{filename} (May take a while.) ..."
puts `ssh #{ssh_url} dokku postgres:export placecal-db2 > #{filename}`
- if $?.success?
+ if $CHILD_STATUS.success?
$stdout.puts "Downloaded production db to #{filename}"
ENV[DB_DUMP_ENV_KEY] = filename
else
- $stderr.puts "Failed to download DB dump!"
+ warn 'Failed to download DB dump!'
end
end
desc "Restore db dump file #{DB_DUMP_ENV_KEY}= to local dev DB"
task restore_local: :environment do
- filename = ENV[DB_DUMP_ENV_KEY]
- raise "Could not find #{filename} file!" if ! File.exist? filename
+ filename = ENV.fetch(DB_DUMP_ENV_KEY, nil)
+ raise "Could not find #{filename} file!" unless File.exist? filename
$stdout.puts "Restoring DB dump file #{filename} to local dev DB. (May take a while.) ..."
puts `dropdb placecal_dev && createdb placecal_dev && pg_restore -d placecal_dev #{filename}`
- if $?.success?
- $stdout.puts "... done."
+ if $CHILD_STATUS.success?
+ $stdout.puts '... done.'
else
- $stderr.puts "Failed to restore DB dump to local dev DB!"
- $stderr.puts "Please manually check to see whether local DB dev still exists."
+ warn 'Failed to restore DB dump to local dev DB!'
+ warn 'Please manually check to see whether local DB dev still exists.'
exit
end
end
desc "Restore db dump file #{DB_DUMP_ENV_KEY}= to staging server DB"
task restore_staging: :environment do
- filename = ENV[DB_DUMP_ENV_KEY]
- ssh_url = if ENV[DB_DUMP_STAGING_SSH_URL]
- ENV[DB_DUMP_STAGING_SSH_URL]
- else
- "root@placecal-staging.org -p 666"
- end
- raise "Could not find #{filename} file!" if ! File.exist? filename
+ filename = ENV.fetch(DB_DUMP_ENV_KEY, nil)
+ ssh_url = ENV.fetch(DB_DUMP_STAGING_SSH_URL, 'root@placecal-staging.org -p 666')
+ raise "Could not find #{filename} file!" unless File.exist? filename
$stdout.puts "Restoring DB dump file #{filename} to staging server DB. (May take a while.) ..."
puts `< #{filename} ssh #{ssh_url} dokku postgres:import placecal-staging-db`
- if $?.success?
- $stdout.puts "... done."
+ if $CHILD_STATUS.success?
+ $stdout.puts '... done.'
else
- $stderr.puts "Failed to restore DB dump to staging server DB!"
- $stderr.puts "Please manually check to see whether staging server DB still exists."
+ warn 'Failed to restore DB dump to staging server DB!'
+ warn 'Please manually check to see whether staging server DB still exists.'
exit
end
end
- desc "Download production DB dump and optionally use it to restore_on_local=1 and/or restore_on_staging=1"
+ desc 'Download production DB dump and optionally use it to restore_on_local=1 and/or restore_on_staging=1'
task dump_production_and_restore_other: :dump_production do
$stdout.puts "restore_on_local = #{ENV['restore_on_local']}" if ENV['restore_on_local']
$stdout.puts "restore_on_staging = #{ENV['restore_on_staging']}" if ENV['restore_on_staging']
@@ -237,11 +218,11 @@ namespace :db do
Rake::Task['db:restore_staging'].execute if ENV['restore_on_staging']
end
- desc "SCP uploads from production to local server"
+ desc 'SCP uploads from production to local server'
task get_files: :environment do
- $stdout.puts "Getting files..."
+ $stdout.puts 'Getting files...'
`scp -r root@placecal.org:/var/lib/dokku/data/storage/placecal/public/ ./`
- $stdout.puts "... done."
+ $stdout.puts '... done.'
end
private
@@ -264,7 +245,6 @@ namespace :db do
when 'p' then 'sql'
when 't' then 'tar'
when 'd' then 'dir'
- else nil
end
end
@@ -274,14 +254,13 @@ namespace :db do
when /\.sql$/ then 'p'
when /\.dir$/ then 'd'
when /\.tar$/ then 't'
- else nil
end
end
def backup_directory(suffix = nil, create: false)
backup_dir = File.join(*[Rails.root, 'db/backups', suffix].compact)
- if create and not Dir.exists?(backup_dir)
+ if create && !Dir.exist?(backup_dir)
puts "Creating #{backup_dir} .."
FileUtils.mkdir_p(backup_dir)
end
diff --git a/lib/tasks/events.rake b/lib/tasks/events.rake
index 29a7a2717..caa58be9a 100644
--- a/lib/tasks/events.rake
+++ b/lib/tasks/events.rake
@@ -3,7 +3,6 @@
namespace :import do
desc 'scan for calendars to send to the importer worker'
task :scan_for_calendars_needing_import, %i[force_import from] => [:environment] do |_t, args|
-
force_import = to_boolean(args[:force_import])
from = to_date(args[:from])
@@ -46,11 +45,11 @@ namespace :import do
calendar.update calendar_state: :in_queue
CalendarImporterJob.perform_now calendar.id, from, force_import, silence_db_exceptions
- #rescue StandardError => e
- # puts "\n"
- # puts "#{e.class}: bad thing: #{e}"
- # puts e.backtrace
- # puts '-' * 20
+ # rescue StandardError => e
+ # puts "\n"
+ # puts "#{e.class}: bad thing: #{e}"
+ # puts e.backtrace
+ # puts '-' * 20
end
end
@@ -91,7 +90,10 @@ namespace :import do
task refresh_online_addresses: :environment do
# Clean out all OnlineAddress entities
- Event.where.not(online_address_id: nil).map { |e| e.online_address_id = nil; e.save! }
+ Event.where.not(online_address_id: nil).map do |e|
+ e.online_address_id = nil
+ e.save!
+ end
OnlineAddress.delete_all
# TODO: For all ICS calendars, check their events and refresh their online event data
@@ -106,6 +108,7 @@ namespace :import do
def to_date(value)
return Date.current.beginning_of_day if value.blank?
+
Date.parse value
end
end
diff --git a/lib/tasks/neighbourhoods.rake b/lib/tasks/neighbourhoods.rake
index 2093135dd..60b237513 100644
--- a/lib/tasks/neighbourhoods.rake
+++ b/lib/tasks/neighbourhoods.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This rake task creates the database migration needed to add ward info
# Data: https://geoportal.statistics.gov.uk/datasets/ward-to-local-authority-district-to-county-to-region-to-country-december-2018-lookup-in-united-kingdom-
diff --git a/lib/tasks/recreate_images.rake b/lib/tasks/recreate_images.rake
index a2c685923..bf891af7e 100644
--- a/lib/tasks/recreate_images.rake
+++ b/lib/tasks/recreate_images.rake
@@ -1,5 +1,6 @@
-namespace :recreate_images do
+# frozen_string_literal: true
+namespace :recreate_images do
desc 'Recreate Site hero image'
task site: :environment do
Site.find_each { |s| s.hero_image.recreate_versions! }
diff --git a/lib/tasks/yard.rake b/lib/tasks/yard.rake
index 49ce19b96..da3c6a59a 100644
--- a/lib/tasks/yard.rake
+++ b/lib/tasks/yard.rake
@@ -2,7 +2,7 @@
# lib/tasks/yard.rake
desc 'Generate code documentation with YARD'
-task yard: [] do
+task :yard do # rubocop:disable Rails/RakeEnvironment
YARD::Rake::YardocTask.new do |t|
t.files = %w[lib/**/*.rb app/**/*.rb - doc/adr/*.md INSTALL.md README.md]
# t.options = %w[-r]
diff --git a/package.json b/package.json
index e1d70d35d..08b49b132 100644
--- a/package.json
+++ b/package.json
@@ -40,6 +40,7 @@
"build": "node esbuild.config.js",
"build:css": "sass ./app/assets/stylesheets/application.sass ./app/assets/builds/application.css --no-source-map --load-path=node_modules",
"format": "prettier --write .",
+ "format:check": "prettier --check .",
"prepare": "husky install"
},
"lint-staged": {
diff --git a/test/controllers/admin/calendars_controller_test.rb b/test/controllers/admin/calendars_controller_test.rb
index ab5826915..4b33a6091 100644
--- a/test/controllers/admin/calendars_controller_test.rb
+++ b/test/controllers/admin/calendars_controller_test.rb
@@ -48,9 +48,9 @@ class Admin::CalendarControllerTest < ActionDispatch::IntegrationTest
partner = create(:partner)
assert_difference('Calendar.count') do
post admin_calendars_url,
- params: { calendar: attributes_for(:calendar,
- place_id: place.id,
- partner_id: partner.id) }
+ params: { calendar: attributes_for(:calendar,
+ place_id: place.id,
+ partner_id: partner.id) }
end
assert_redirected_to edit_admin_calendar_path(assigns[:calendar])
assert_not flash.empty?
diff --git a/test/controllers/admin/partner_update_postcode_test.rb b/test/controllers/admin/partner_update_postcode_test.rb
index cd11a9f39..e5ef42c0b 100644
--- a/test/controllers/admin/partner_update_postcode_test.rb
+++ b/test/controllers/admin/partner_update_postcode_test.rb
@@ -3,15 +3,13 @@
require 'test_helper'
class PartnerUpdatePostcodeTest < ActionDispatch::IntegrationTest
-
setup do
Neighbourhood.destroy_all
-
+
@neighbourhood_admin = create(:user)
end
test 'can change postcode of partner' do
-
neighbourhood_1 = Neighbourhood.create!( # 'M15 5DD'
name: 'Neighbourhood 1',
name_abbr: '',
@@ -30,11 +28,9 @@ class PartnerUpdatePostcodeTest < ActionDispatch::IntegrationTest
unit_name: 'Ashton Hurst'
)
-
@neighbourhood_admin.neighbourhoods << neighbourhood_1
@neighbourhood_admin.neighbourhoods << neighbourhood_2
-
@partner = Partner.new(name: 'A new partner')
@partner.address = Address.create!(
street_address: '123 Street',
@@ -46,19 +42,19 @@ class PartnerUpdatePostcodeTest < ActionDispatch::IntegrationTest
sign_in @neighbourhood_admin
update_args = {
- partner: {
+ partner: {
name: @partner.name,
address_attributes: {
street_address: @partner.address.street_address,
postcode: 'OL6 8BH'
- }
- }
+ }
+ }
}
patch admin_partner_url(@partner), params: update_args
assert_redirected_to edit_admin_partner_url(@partner)
@partner.reload
- assert @partner.address.postcode == 'OL6 8BH'
+ assert_equal('OL6 8BH', @partner.address.postcode)
end
end
diff --git a/test/controllers/admin/tags_controller_test.rb b/test/controllers/admin/tags_controller_test.rb
index cc3b5c0ba..353c99d02 100644
--- a/test/controllers/admin/tags_controller_test.rb
+++ b/test/controllers/admin/tags_controller_test.rb
@@ -96,7 +96,7 @@ def test_update_partner_admin
def test_update_tag_admin
# Tag admins
# can only edit tags that are public, or they have had assigned to them
- assert @tag_admin.tags.include?(@assigned_root_tag) # For prosperity
+ assert_includes @tag_admin.tags, @assigned_root_tag # For prosperity
assert allows_access(@tag_admin, @public_tag, :update)
assert allows_access(@tag_admin, @assigned_root_tag, :update)
# They may not edit unassigned tags >:(
diff --git a/test/controllers/admin/users_controller_test.rb b/test/controllers/admin/users_controller_test.rb
index 65a5cfcda..c27444116 100644
--- a/test/controllers/admin/users_controller_test.rb
+++ b/test/controllers/admin/users_controller_test.rb
@@ -15,21 +15,21 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
end
# Profile
- test "root: can access profile" do
+ test 'root: can access profile' do
sign_in @root
get admin_profile_path
assert_response :success
end
- test "neighbourhood_admin: can access profile" do
+ test 'neighbourhood_admin: can access profile' do
sign_in @neighbourhood_admin
get admin_profile_path
assert_response :success
end
- test "citizen: can access profile" do
+ test 'citizen: can access profile' do
sign_in @citizen
get admin_profile_path
@@ -37,11 +37,11 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
end
# Update Profile
- test "user can update their profile" do
+ test 'user can update their profile' do
sign_in @root
patch update_profile_admin_user_path(@root),
- params: { user: { first_name: 'Bob' }}
+ params: { user: { first_name: 'Bob' } }
assert_redirected_to admin_profile_url
assert_equal 'Bob', @root.reload.first_name
@@ -53,7 +53,7 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
sign_in @root
patch update_profile_admin_user_path(user),
- params: { user: { first_name: 'Name' }}
+ params: { user: { first_name: 'Name' } }
assert_redirected_to admin_profile_url
assert_equal 'Test', user.reload.first_name
@@ -171,7 +171,7 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
assert_not_equal 'Bob', @citizen.first_name
assert_not_equal 'Smith', @citizen.last_name
assert_equal [@partner.id], @citizen.partner_ids
- assert_equal [], @citizen.neighbourhood_ids
+ assert_empty @citizen.neighbourhood_ids
end
# Delete User
diff --git a/test/controllers/concerns/map_markers_concern_test.rb b/test/controllers/concerns/map_markers_concern_test.rb
index d9d86c9df..dfe88ab7e 100644
--- a/test/controllers/concerns/map_markers_concern_test.rb
+++ b/test/controllers/concerns/map_markers_concern_test.rb
@@ -3,8 +3,7 @@
require 'test_helper'
class ActiveSupport::TestCase
-
- def self.context(description)
+ def self.context(_description)
yield
end
end
@@ -18,13 +17,13 @@ def controller
@controller ||= FakeController.new
end
- context "get_map_markers" do
- test "returns empty array if empty input" do
+ context 'get_map_markers' do
+ test 'returns empty array if empty input' do
markers = controller.get_map_markers([])
assert_empty markers
end
- test "returns payload for partners" do
+ test 'returns payload for partners' do
partners = create_list(:partner, 10)
output = controller.get_map_markers(partners)
assert_equal 10, output.length
@@ -36,7 +35,7 @@ def controller
assert_field entry, :id
end
- test "returns payload for addresses" do
+ test 'returns payload for addresses' do
addresses = create_list(:address, 10)
output = controller.get_map_markers(addresses)
assert_equal 10, output.length
@@ -46,7 +45,7 @@ def controller
assert_field entry, :lon
end
- test "skips partners with no service areas when flagged" do
+ test 'skips partners with no service areas when flagged' do
neighbourhood = neighbourhoods(:one)
# no service areas
@@ -64,13 +63,10 @@ def controller
assert_equal 5, output.length
end
- test "cam turn events into markers" do
+ test 'cam turn events into markers' do
events = create_list(:event, 10)
output = controller.get_map_markers(events)
assert_equal 10, output.length
-
end
-
end
-
end
diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb
index 2b160726a..84c0477da 100644
--- a/test/controllers/events_controller_test.rb
+++ b/test/controllers/events_controller_test.rb
@@ -49,11 +49,11 @@ class EventsControllerTest < ActionDispatch::IntegrationTest
get from_site_slug(@site, events_path)
assert_response :success
- assert_select "ol.events li", 2
+ assert_select 'ol.events li', 2
end
test 'should get index with invalid subdomain' do
- get url_for controller: :events, subdomain: "notaknownsubdomain"
+ get url_for controller: :events, subdomain: 'notaknownsubdomain'
assert_response :redirect
end
@@ -87,6 +87,6 @@ class EventsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
events = assigns(:events).values.first
- assert events.length == 5
+ assert_equal(5, events.length)
end
end
diff --git a/test/controllers/news_controller_test.rb b/test/controllers/news_controller_test.rb
index a1379c70e..1307c9232 100644
--- a/test/controllers/news_controller_test.rb
+++ b/test/controllers/news_controller_test.rb
@@ -10,10 +10,11 @@ class NewsControllerTest < ActionDispatch::IntegrationTest
@partner = create(:partner, address: create(:address, neighbourhood: @neighbourhood))
@articles = (0...5).map do |n|
@partner.articles.create!(
- title: "#{n} Article",
- is_draft: false,
- body: 'Some text about this news piece',
- author: @author)
+ title: "#{n} Article",
+ is_draft: false,
+ body: 'Some text about this news piece',
+ author: @author
+ )
end
@site = create(:site)
@@ -23,7 +24,7 @@ class NewsControllerTest < ActionDispatch::IntegrationTest
test 'should get index subdomain' do
get news_index_url(subdomain: @site.domain)
assert_response :success
- assert_select ".articles__article-card", 5
+ assert_select '.articles__article-card', 5
# counts
# assert_select 'p', { text: 'Found 5 articles.' }
@@ -39,7 +40,8 @@ class NewsControllerTest < ActionDispatch::IntegrationTest
title: "#{n} Article, again",
is_draft: false,
body: 'Some text about this news piece',
- author: @author)
+ author: @author
+ )
end
@epoch = Date.new(2000, 1, 31)
@@ -51,7 +53,7 @@ class NewsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
# this is capped
- assert_select ".articles__article-card", NewsController::ARTICLES_PER_PAGE
+ assert_select '.articles__article-card', NewsController::ARTICLES_PER_PAGE
# counts
# assert_select 'p', { text: 'Found 30 articles.' }
@@ -62,22 +64,21 @@ class NewsControllerTest < ActionDispatch::IntegrationTest
get news_index_url(subdomain: @site.domain, offset: 20)
- assert_select ".articles__article-card", 10 # only ten left
+ assert_select '.articles__article-card', 10 # only ten left
# pagination
# assert_select 'p', { text: 'No more news items' }
assert_select 'p', { count: 0, text: 'Older news items' }
end
-
- #test 'should get index with configured subdomain' do
+ # test 'should get index with configured subdomain' do
# get url_for controller: :news, subdomain: @site.slug
# assert_response :success
# assert_select "ol.events li", 5
- #end
+ # end
test 'should get index with invalid subdomain' do
- get url_for controller: :news, subdomain: "notaknownsubdomain"
+ get url_for controller: :news, subdomain: 'notaknownsubdomain'
assert_response :redirect
end
diff --git a/test/controllers/partners_controller_test.rb b/test/controllers/partners_controller_test.rb
index c65f07460..a507b9876 100644
--- a/test/controllers/partners_controller_test.rb
+++ b/test/controllers/partners_controller_test.rb
@@ -25,8 +25,14 @@ class PartnersControllerTest < ActionDispatch::IntegrationTest
# NOTE: Uhhh, what does this do? - Alexandria, 2022-05-31
@partners.each do |for_nbd|
o_r = OrganisationRelationship.new
- o_r.subject = for_nbd[0]; o_r.verb = :manages; o_r.object = for_nbd[1]; o_r.save
- e = build(:event); e.dtstart = Date.today; e.place = for_nbd[2]; e.save
+ o_r.subject = for_nbd[0]
+ o_r.verb = :manages
+ o_r.object = for_nbd[1]
+ o_r.save
+ e = build(:event)
+ e.dtstart = Date.today
+ e.place = for_nbd[2]
+ e.save
for_nbd
end
@@ -42,7 +48,7 @@ class PartnersControllerTest < ActionDispatch::IntegrationTest
end
test 'should get index without subdomain' do
- get url_for controller: "partners", subdomain: false
+ get url_for controller: 'partners', subdomain: false
assert_response :redirect
end
@@ -56,7 +62,7 @@ class PartnersControllerTest < ActionDispatch::IntegrationTest
get from_site_slug(@site, partners_path)
assert_response :success
- assert_select "ul.partners li", 3
+ assert_select 'ul.partners li', 3
end
# test 'should get places_index with configured subdomain' do
@@ -66,7 +72,7 @@ class PartnersControllerTest < ActionDispatch::IntegrationTest
# end
test 'should redirect from index with unknown subdomain' do
- get url_for controller: "partners", subdomain: "notaknownsubdomain"
+ get url_for controller: 'partners', subdomain: 'notaknownsubdomain'
assert_response :redirect
end
@@ -101,6 +107,6 @@ class PartnersControllerTest < ActionDispatch::IntegrationTest
get from_site_slug(@site, partner_path(partner))
events = assigns(:events).values.first
- assert events.length == 3
+ assert_equal(3, events.length)
end
end
diff --git a/test/factories/article_partners.rb b/test/factories/article_partners.rb
index 073cd8a16..491b33d13 100644
--- a/test/factories/article_partners.rb
+++ b/test/factories/article_partners.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
FactoryBot.define do
factory :article_partner do
article
diff --git a/test/factories/articles.rb b/test/factories/articles.rb
index c76cfc468..40c6357fa 100644
--- a/test/factories/articles.rb
+++ b/test/factories/articles.rb
@@ -3,7 +3,9 @@
FactoryBot.define do
factory :article do
title { 'No D&D session this week!' }
- body { "We regret to inform you that this week's D&D session has been cancelled, the DM's dog has eaten a key NPC's character sheet, bad Fido! We'll be back in a fortnight!" }
+ body do
+ "We regret to inform you that this week's D&D session has been cancelled, the DM's dog has eaten a key NPC's character sheet, bad Fido! We'll be back in a fortnight!"
+ end
published_at { '2022-02-16' }
is_draft { false }
diff --git a/test/factories/calendar.rb b/test/factories/calendar.rb
index a569bdd7b..d0c8af01f 100644
--- a/test/factories/calendar.rb
+++ b/test/factories/calendar.rb
@@ -6,11 +6,11 @@
"Zion Centre #{n}"
end
sequence :source do |n|
- "https://outlook.office365.com/owa/calendar/#{n}/calendar.ics"
- end
+ "https://outlook.office365.com/owa/calendar/#{n}/calendar.ics"
+ end
public_contact_name { 'Public Calendar Name' }
- public_contact_email { 'public@communitygroup.com'}
+ public_contact_email { 'public@communitygroup.com' }
public_contact_phone { '0161 0000000' }
partner
diff --git a/test/factories/online_addresses.rb b/test/factories/online_addresses.rb
index aabf7de1a..02608b8d7 100644
--- a/test/factories/online_addresses.rb
+++ b/test/factories/online_addresses.rb
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
FactoryBot.define do
factory :online_address do
- url { "MyString" }
+ url { 'MyString' }
end
end
diff --git a/test/factories/partner.rb b/test/factories/partner.rb
index d29754122..ef2ed46c4 100644
--- a/test/factories/partner.rb
+++ b/test/factories/partner.rb
@@ -47,39 +47,39 @@
end
end
- opening_times {
+ opening_times do
'[ { "@type": "OpeningHoursSpecification",'\
- ' "closes": "20:00:00",'\
- ' "dayOfWeek": "http://schema.org/Monday",'\
- ' "opens": "09:00:00"'\
- ' },'\
- ' { "@type": "OpeningHoursSpecification",'\
- ' "closes": "17:00:00",'\
- ' "dayOfWeek": "http://schema.org/Tuesday",'\
- ' "opens": "09:00:00"'\
- ' },'\
- ' { "@type": "OpeningHoursSpecification",'\
- ' "closes": "17:00:00",'\
- ' "dayOfWeek": "http://schema.org/Wednesday",'\
- ' "opens": "09:00:00"'\
- ' },'\
- ' { "@type": "OpeningHoursSpecification",'\
- ' "closes": "17:00:00",'\
- ' "dayOfWeek": "http://schema.org/Thursday",'\
- ' "opens": "09:00:00"'\
- ' },'\
- ' { "@type": "OpeningHoursSpecification",'\
- ' "closes": "17:00:00",'\
- ' "dayOfWeek": "http://schema.org/Friday",'\
- ' "opens": "09:00:00"'\
- ' },'\
- ' { "@type": "OpeningHoursSpecification",'\
- ' "closes": "13:00:00",'\
- ' "dayOfWeek": "http://schema.org/Saturday",'\
- ' "opens": "09:00:00"'\
- ' }'\
- ']'
- }
+ ' "closes": "20:00:00",'\
+ ' "dayOfWeek": "http://schema.org/Monday",'\
+ ' "opens": "09:00:00"'\
+ ' },'\
+ ' { "@type": "OpeningHoursSpecification",'\
+ ' "closes": "17:00:00",'\
+ ' "dayOfWeek": "http://schema.org/Tuesday",'\
+ ' "opens": "09:00:00"'\
+ ' },'\
+ ' { "@type": "OpeningHoursSpecification",'\
+ ' "closes": "17:00:00",'\
+ ' "dayOfWeek": "http://schema.org/Wednesday",'\
+ ' "opens": "09:00:00"'\
+ ' },'\
+ ' { "@type": "OpeningHoursSpecification",'\
+ ' "closes": "17:00:00",'\
+ ' "dayOfWeek": "http://schema.org/Thursday",'\
+ ' "opens": "09:00:00"'\
+ ' },'\
+ ' { "@type": "OpeningHoursSpecification",'\
+ ' "closes": "17:00:00",'\
+ ' "dayOfWeek": "http://schema.org/Friday",'\
+ ' "opens": "09:00:00"'\
+ ' },'\
+ ' { "@type": "OpeningHoursSpecification",'\
+ ' "closes": "13:00:00",'\
+ ' "dayOfWeek": "http://schema.org/Saturday",'\
+ ' "opens": "09:00:00"'\
+ ' }'\
+ ']'
+ end
factory :place do
sequence(:name) do |n|
@@ -90,5 +90,4 @@
public_email { 'contact@venue.org' }
end
end
-
end
diff --git a/test/factories/service_areas.rb b/test/factories/service_areas.rb
index 6a858c56e..e3cc4cfdc 100644
--- a/test/factories/service_areas.rb
+++ b/test/factories/service_areas.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
FactoryBot.define do
factory :ashton_service_area, class: 'ServiceArea' do
association :neighbourhood, factory: :ashton_neighbourhood
diff --git a/test/factories/tag.rb b/test/factories/tag.rb
index bd5fba204..2dcf98dac 100644
--- a/test/factories/tag.rb
+++ b/test/factories/tag.rb
@@ -17,6 +17,5 @@
factory :system_tag do
system_tag { true }
end
-
end
end
diff --git a/test/helpers/calendars_helper_test.rb b/test/helpers/calendars_helper_test.rb
index 3fec11f2e..aba36d788 100644
--- a/test/helpers/calendars_helper_test.rb
+++ b/test/helpers/calendars_helper_test.rb
@@ -14,21 +14,20 @@ class CalendarsHelperTest < ActionView::TestCase
@partner_3 = create(:partner)
end
- test "options_for_location only shows partners with addresses" do
+ test 'options_for_location only shows partners with addresses' do
# FIXME: there is a bug in ActionView where it gets itself into an
# infinite call loop and StackOverflows
- #sign_in @root
+ # sign_in @root
- #begin
+ # begin
# locations = options_for_location
- #rescue SystemStackError => e
+ # rescue SystemStackError => e
# puts e.backtrace
# raise e
- #end
+ # end
# assert_equal 4, locations.length, "Should see 4 options"
end
-
end
diff --git a/test/helpers/partners_helper_test.rb b/test/helpers/partners_helper_test.rb
index 18f243845..b3c6158af 100644
--- a/test/helpers/partners_helper_test.rb
+++ b/test/helpers/partners_helper_test.rb
@@ -14,30 +14,30 @@ class PartnersHelperTest < ActionView::TestCase
# testing partner_service_area_text
- test "shows only one text correctly" do
+ test 'shows only one text correctly' do
@partner.service_areas.create neighbourhood: @hoods[0]
output = partner_service_area_text(@partner)
- assert output == 'alpha'
+ assert_equal('alpha', output)
end
- test "shows two texts correctly" do
+ test 'shows two texts correctly' do
@partner.service_areas.create neighbourhood: @hoods[0]
@partner.service_areas.create neighbourhood: @hoods[1]
output = partner_service_area_text(@partner)
- assert output == 'alpha and beta'
+ assert_equal('alpha and beta', output)
end
- test "shows N texts correctly" do
+ test 'shows N texts correctly' do
@partner.service_areas.create neighbourhood: @hoods[0]
@partner.service_areas.create neighbourhood: @hoods[1]
@partner.service_areas.create neighbourhood: @hoods[2]
output = partner_service_area_text(@partner)
- assert output == 'alpha, beta and cappa'
+ assert_equal('alpha, beta and cappa', output)
end
end
diff --git a/test/integration/admin/articles_integration_test.rb b/test/integration/admin/articles_integration_test.rb
index 82d6a2d7b..550cb6f11 100644
--- a/test/integration/admin/articles_integration_test.rb
+++ b/test/integration/admin/articles_integration_test.rb
@@ -63,20 +63,20 @@ class Admin::ArticlesTest < ActionDispatch::IntegrationTest
title: 'a new article',
body: 'alpha beta cappa delta epsilon foxtrot etc',
author_id: @root.id,
- article_image: fixture_file_upload("bad-cat-picture.bmp")
+ article_image: fixture_file_upload('bad-cat-picture.bmp')
}
post admin_articles_path, params: { article: new_article_params }
assert_not response.redirect?
- assert_select "h6", text: "1 error prohibited this Article from being saved"
+ assert_select 'h6', text: '1 error prohibited this Article from being saved'
# top of page form error box
assert_select '#form-errors li',
- text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png"
+ text: 'Article image You are not allowed to upload "bmp" files, allowed types: svg, jpg, jpeg, png'
assert_select 'form .article_article_image .invalid-feedback',
- text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png"
+ text: 'Article image You are not allowed to upload "bmp" files, allowed types: svg, jpg, jpeg, png'
end
test 'update article image upload problem feedback' do
@@ -88,20 +88,19 @@ class Admin::ArticlesTest < ActionDispatch::IntegrationTest
title: article.title,
body: article.body,
author_id: article.author_id,
- article_image: fixture_file_upload("bad-cat-picture.bmp")
+ article_image: fixture_file_upload('bad-cat-picture.bmp')
}
put admin_article_path(article), params: { article: article_params }
assert_not response.successful?
- assert_select "h6", text: "1 error prohibited this Article from being saved"
+ assert_select 'h6', text: '1 error prohibited this Article from being saved'
# top of page form error box
assert_select '#form-errors li',
- text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png"
+ text: 'Article image You are not allowed to upload "bmp" files, allowed types: svg, jpg, jpeg, png'
assert_select 'form .article_article_image .invalid-feedback',
- text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png"
+ text: 'Article image You are not allowed to upload "bmp" files, allowed types: svg, jpg, jpeg, png'
end
-
end
diff --git a/test/integration/admin/calendars_integration_test.rb b/test/integration/admin/calendars_integration_test.rb
index 5570b1b8b..a497e17fd 100644
--- a/test/integration/admin/calendars_integration_test.rb
+++ b/test/integration/admin/calendars_integration_test.rb
@@ -17,26 +17,26 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
host! 'admin.lvh.me'
end
- test "root user : can get index" do
+ test 'root user : can get index' do
sign_in @root
get admin_calendars_path
- assert_select 'title', text: "Calendars | PlaceCal Admin"
+ assert_select 'title', text: 'Calendars | PlaceCal Admin'
assert_select 'tbody tr', count: 1
end
- test "neighbourhood admin : can get index" do
+ test 'neighbourhood admin : can get index' do
sign_in @root
get admin_calendars_path
assert_select 'tbody tr', count: 1
end
# GET new
- test "root : can get new" do
+ test 'root : can get new' do
sign_in @root
get new_admin_calendar_path
- assert_select 'title', text: "New Calendar | PlaceCal Admin"
+ assert_select 'title', text: 'New Calendar | PlaceCal Admin'
assert_select 'select#calendar_partner_id' do
assert_select 'option', count: 3
@@ -48,7 +48,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
end
# GET new
- test "root : can get new with preselected partner" do
+ test 'root : can get new with preselected partner' do
@root.partners << @partner
sign_in @root
@@ -57,12 +57,11 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
assert_select 'option[selected="selected"]', @partner.name
end
- test "neighbourhood_admin : can get new" do
+ test 'neighbourhood_admin : can get new' do
sign_in @neighbourhood_admin
get new_admin_calendar_path
-
assert_select 'select#calendar_partner_id' do
assert_select 'option', count: 2
end
@@ -70,7 +69,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
assert_select 'option', @partner.name, count: 1
end
- test "partner_admin : can get new" do
+ test 'partner_admin : can get new' do
sign_in @partner_admin
get new_admin_calendar_path
@@ -83,7 +82,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
end
# GET edit
- test "root : can get edit" do
+ test 'root : can get edit' do
sign_in @root
get edit_admin_calendar_path(@calendar)
@@ -96,7 +95,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
assert_select 'option', @partner_two.name, count: 1
end
- test "neighbourhood_admin : can get edit" do
+ test 'neighbourhood_admin : can get edit' do
sign_in @neighbourhood_admin
get edit_admin_calendar_path(@calendar)
@@ -108,7 +107,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
assert_select 'option', @partner.name, count: 1
end
- test "partner_admin : can get edit" do
+ test 'partner_admin : can get edit' do
sign_in @partner_admin
get edit_admin_calendar_path(@calendar)
@@ -120,7 +119,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
assert_select 'option', @partner.name, count: 1
end
- test "partner : can see which importer is selected" do
+ test 'partner : can see which importer is selected' do
@calendar.update! importer_mode: 'ical'
sign_in @partner_admin
@@ -129,7 +128,7 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
assert_select 'option[value="ical"][selected="selected"]', nil, count: 1
end
- test "partner : can change importer" do
+ test 'partner : can change importer' do
sign_in @partner_admin
params = { calendar: @calendar.attributes }
@@ -140,5 +139,4 @@ class Admin::CalendarsTest < ActionDispatch::IntegrationTest
@calendar.reload
assert_equal 'eventbrite', @calendar.importer_mode
end
-
end
diff --git a/test/integration/admin/home_integration_test.rb b/test/integration/admin/home_integration_test.rb
index 469bccc48..19b33aec0 100644
--- a/test/integration/admin/home_integration_test.rb
+++ b/test/integration/admin/home_integration_test.rb
@@ -12,25 +12,24 @@ class AdminHomeIntegrationTest < ActionDispatch::IntegrationTest
test "Admin home page can't be accessed without a login" do
@default_site = create_default_site
- get "http://admin.lvh.me"
- assert_redirected_to "http://admin.lvh.me/users/sign_in"
+ get 'http://admin.lvh.me'
+ assert_redirected_to 'http://admin.lvh.me/users/sign_in'
end
- test "Admin can access page when logged in" do
+ test 'Admin can access page when logged in' do
sign_in @admin
- get "http://admin.lvh.me"
+ get 'http://admin.lvh.me'
assert_response :success
- assert_select 'title', text: "Dashboard | PlaceCal Admin"
+ assert_select 'title', text: 'Dashboard | PlaceCal Admin'
end
test "Blank citizen gets a 'no content' warning" do
sign_in @citizen
- get "http://admin.lvh.me"
+ get 'http://admin.lvh.me'
assert_response :success
- assert_select 'title', text: "Dashboard | PlaceCal Admin"
- assert_select 'h1', text: "Missing Permissions"
+ assert_select 'title', text: 'Dashboard | PlaceCal Admin'
+ assert_select 'h1', text: 'Missing Permissions'
end
-
end
diff --git a/test/integration/admin/neighbourhood_integration_test.rb b/test/integration/admin/neighbourhood_integration_test.rb
index 76c496b5a..7ac67f54f 100644
--- a/test/integration/admin/neighbourhood_integration_test.rb
+++ b/test/integration/admin/neighbourhood_integration_test.rb
@@ -19,26 +19,26 @@ class AdminNeighbourhoodIntegrationTest < ActionDispatch::IntegrationTest
@number_of_neighbourhoods = 15
@neighbourhoods << @neighbourhood
- get "http://admin.lvh.me"
+ get 'http://admin.lvh.me'
end
- test "Index shows correct neighbourhoods for root" do
+ test 'Index shows correct neighbourhoods for root' do
sign_in(@root)
get admin_neighbourhoods_path
# See all neighbourhoods
- assert_select 'title', text: "Neighbourhoods | PlaceCal Admin"
+ assert_select 'title', text: 'Neighbourhoods | PlaceCal Admin'
assert_select 'tbody tr', count: @number_of_neighbourhoods
end
- test "Index shows correct neighbourhoods for neighbourhood admin" do
+ test 'Index shows correct neighbourhoods for neighbourhood admin' do
sign_in(@neighbourhood_admin)
get admin_neighbourhoods_path
# See just the neighbourhood they admin
assert_select 'tbody tr', count: 1
end
- test "Edit form has correct fields for root" do
+ test 'Edit form has correct fields for root' do
sign_in @root
get edit_admin_neighbourhood_path(@neighbourhood)
assert_response :success
@@ -55,7 +55,7 @@ class AdminNeighbourhoodIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'a', 'Destroy'
end
- test "Edit form has correct fields for neighbourhood admin" do
+ test 'Edit form has correct fields for neighbourhood admin' do
sign_in @neighbourhood_admin
get edit_admin_neighbourhood_path(@neighbourhood)
assert_response :success
diff --git a/test/integration/admin/partner_integration_test.rb b/test/integration/admin/partner_integration_test.rb
index 6b7c87fe9..3e93d1ba9 100644
--- a/test/integration/admin/partner_integration_test.rb
+++ b/test/integration/admin/partner_integration_test.rb
@@ -123,7 +123,7 @@ class PartnerIntegrationTest < ActionDispatch::IntegrationTest
street_address: @partner.address.street_address,
postcode: @partner.address.postcode
},
- image: fixture_file_upload("bad-cat-picture.bmp")
+ image: fixture_file_upload('bad-cat-picture.bmp')
}
sign_in @admin
@@ -131,9 +131,11 @@ class PartnerIntegrationTest < ActionDispatch::IntegrationTest
assert_not response.redirect?
- assert_select "h6", text: "1 error prohibited this Partner from being saved"
- assert_select '#form-errors li', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png"
- assert_select 'form .partner_image .invalid-feedback', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png"
+ assert_select 'h6', text: '1 error prohibited this Partner from being saved'
+ assert_select '#form-errors li',
+ text: 'Image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, gif, png'
+ assert_select 'form .partner_image .invalid-feedback',
+ text: 'Image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, gif, png'
end
test 'Partner update form gives feedback on bad image selection' do
@@ -143,7 +145,7 @@ class PartnerIntegrationTest < ActionDispatch::IntegrationTest
street_address: @partner.address.street_address,
postcode: @partner.address.postcode
},
- image: fixture_file_upload("bad-cat-picture.bmp")
+ image: fixture_file_upload('bad-cat-picture.bmp')
}
sign_in @admin
@@ -151,53 +153,52 @@ class PartnerIntegrationTest < ActionDispatch::IntegrationTest
assert_not response.redirect?
- assert_select "h6", text: "1 error prohibited this Partner from being saved"
- assert_select '#form-errors li', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png"
- assert_select 'form .partner_image .invalid-feedback', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png"
+ assert_select 'h6', text: '1 error prohibited this Partner from being saved'
+ assert_select '#form-errors li',
+ text: 'Image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, gif, png'
+ assert_select 'form .partner_image .invalid-feedback',
+ text: 'Image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, gif, png'
end
-
end
# Capybara feature test that doesn't work and i have no time to fix
-=begin
-class PartnerAddressUpdatesTest < ActionDispatch::IntegrationTest # Capybara::Rails::TestCase
-
- include Devise::Test::IntegrationHelpers
- include Capybara::DSL
- include Capybara::Minitest::Assertions
-
- setup do
- @admin = create(:root)
- @site = FactoryBot.create(:site, slug: 'default-site')
- @partner = create(:partner)
- # @admin = create(:root)
- host! 'admin.lvh.me'
- end
-
- test 'can change postcode of partner' do
- sign_in @admin
-
- visit '/'
-
- click_link 'Partners'
- click_link @partner.title
-
- fill_in 'Postcode', with: 'OL6 8BH'
-
-
- #update_args = @partner_two.as_json
- #update_args['partner']['address']['postcode'] =
- #patch admin_partner_url(@partner_two), params: update_args
- click_button 'Update'
- assert_redirected_to admin_partners_url
-
- click @partner.title
-
- puts 'is this runing?'
- assert_have_selector 'input[name="partner_postcode"]'
-
- #@partner_two.reload
- #assert @partner_two.address.postcode == 'OL6 8BH'
- end
-end
-=end
+# class PartnerAddressUpdatesTest < ActionDispatch::IntegrationTest # Capybara::Rails::TestCase
+#
+# include Devise::Test::IntegrationHelpers
+# include Capybara::DSL
+# include Capybara::Minitest::Assertions
+#
+# setup do
+# @admin = create(:root)
+# @site = FactoryBot.create(:site, slug: 'default-site')
+# @partner = create(:partner)
+# # @admin = create(:root)
+# host! 'admin.lvh.me'
+# end
+#
+# test 'can change postcode of partner' do
+# sign_in @admin
+#
+# visit '/'
+#
+# click_link 'Partners'
+# click_link @partner.title
+#
+# fill_in 'Postcode', with: 'OL6 8BH'
+#
+#
+# #update_args = @partner_two.as_json
+# #update_args['partner']['address']['postcode'] =
+# #patch admin_partner_url(@partner_two), params: update_args
+# click_button 'Update'
+# assert_redirected_to admin_partners_url
+#
+# click @partner.title
+#
+# puts 'is this runing?'
+# assert_have_selector 'input[name="partner_postcode"]'
+#
+# #@partner_two.reload
+# #assert @partner_two.address.postcode == 'OL6 8BH'
+# end
+# end
diff --git a/test/integration/admin/sites_integration_test.rb b/test/integration/admin/sites_integration_test.rb
index 2eb9f938e..2bd987243 100644
--- a/test/integration/admin/sites_integration_test.rb
+++ b/test/integration/admin/sites_integration_test.rb
@@ -67,7 +67,7 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
cocoon_select_template = assert_select('.add_fields').first['data-association-insertion-template']
neighbourhoods_shown = cocoon_select_template.scan(/(option value=)/).size
- assert neighbourhoods_shown == @number_of_neighbourhoods
+ assert_equal neighbourhoods_shown, @number_of_neighbourhoods
end
test 'site admin users see appropriate fields' do
@@ -94,7 +94,7 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
# See just neighbourhoods they admin
cocoon_select_template = assert_select('.add_fields').first['data-association-insertion-template']
neighbourhoods_shown = cocoon_select_template.scan(/(option value=)/).size
- assert neighbourhoods_shown == 2
+ assert_equal(2, neighbourhoods_shown)
end
test 'site tags show up' do
@@ -118,24 +118,29 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
name: 'a new site',
domain: 'a-domain',
slug: 'a-slug',
- logo: fixture_file_upload("bad-cat-picture.bmp"),
- footer_logo: fixture_file_upload("bad-cat-picture.bmp"),
- hero_image: fixture_file_upload("bad-cat-picture.bmp"),
+ logo: fixture_file_upload('bad-cat-picture.bmp'),
+ footer_logo: fixture_file_upload('bad-cat-picture.bmp'),
+ hero_image: fixture_file_upload('bad-cat-picture.bmp')
}
post admin_sites_path, params: { site: new_site_params }
assert_not response.successful?
- assert_select "h6", text: "3 errors prohibited this Site from being saved"
+ assert_select 'h6', text: '3 errors prohibited this Site from being saved'
# top of page form error box
- assert_select '#form-errors li', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select '#form-errors li', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select '#form-errors li', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
-
- assert_select 'form .site_logo .invalid-feedback', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select 'form .site_footer_logo .invalid-feedback', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select 'form .site_hero_image .invalid-feedback', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select '#form-errors li', text: 'Logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select '#form-errors li',
+ text: 'Footer logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select '#form-errors li',
+ text: 'Hero image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, png'
+
+ assert_select 'form .site_logo .invalid-feedback',
+ text: 'Logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select 'form .site_footer_logo .invalid-feedback',
+ text: 'Footer logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select 'form .site_hero_image .invalid-feedback',
+ text: 'Hero image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, png'
end
test 'update site image upload problem feedback' do
@@ -145,23 +150,28 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
name: 'a new site',
domain: 'a-domain',
slug: 'a-slug',
- logo: fixture_file_upload("bad-cat-picture.bmp"),
- footer_logo: fixture_file_upload("bad-cat-picture.bmp"),
- hero_image: fixture_file_upload("bad-cat-picture.bmp"),
+ logo: fixture_file_upload('bad-cat-picture.bmp'),
+ footer_logo: fixture_file_upload('bad-cat-picture.bmp'),
+ hero_image: fixture_file_upload('bad-cat-picture.bmp')
}
put admin_site_path(@site), params: { site: site_params }
assert_not response.successful?
- assert_select "h6", text: "3 errors prohibited this Site from being saved"
+ assert_select 'h6', text: '3 errors prohibited this Site from being saved'
# top of page form error box
- assert_select '#form-errors li', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select '#form-errors li', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select '#form-errors li', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
-
- assert_select 'form .site_logo .invalid-feedback', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select 'form .site_footer_logo .invalid-feedback', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png"
- assert_select 'form .site_hero_image .invalid-feedback', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select '#form-errors li', text: 'Logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select '#form-errors li',
+ text: 'Footer logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select '#form-errors li',
+ text: 'Hero image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, png'
+
+ assert_select 'form .site_logo .invalid-feedback',
+ text: 'Logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select 'form .site_footer_logo .invalid-feedback',
+ text: 'Footer logo You are not allowed to upload "bmp" files, allowed types: svg, png'
+ assert_select 'form .site_hero_image .invalid-feedback',
+ text: 'Hero image You are not allowed to upload "bmp" files, allowed types: jpg, jpeg, png'
end
end
diff --git a/test/integration/admin/tags_integration_test.rb b/test/integration/admin/tags_integration_test.rb
index 7242d554e..530f4d87a 100644
--- a/test/integration/admin/tags_integration_test.rb
+++ b/test/integration/admin/tags_integration_test.rb
@@ -58,7 +58,6 @@ class Admin::TagsTest < ActionDispatch::IntegrationTest
test 'root users can make a tag a system tag' do
log_in_with @root.email
-
# toggle on
visit edit_admin_tag_url(@tag)
check 'System tag'
@@ -85,7 +84,7 @@ def assert_has_flash(type, message)
assert_css ".flashes .alert-#{type}", text: message
end
- def log_in_with(email, password='password')
+ def log_in_with(email, password = 'password')
# NOTE: make sure you have a default site set up in DB
visit 'http://lvh.me/users/sign_in'
fill_in 'Email', with: email
diff --git a/test/integration/admin/user_integration_test.rb b/test/integration/admin/user_integration_test.rb
index 1f8eb5029..da48d77f7 100644
--- a/test/integration/admin/user_integration_test.rb
+++ b/test/integration/admin/user_integration_test.rb
@@ -35,7 +35,6 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'h1', text: "Users"
end
-
test "root : can get new user" do
sign_in @root
@@ -128,7 +127,6 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'h3', 'Role', count: 0
end
-
test "Edit form has correct fields for root" do
sign_in @root
get edit_admin_user_path(@citizen)
@@ -167,7 +165,7 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
test "shows partner select list" do
sign_in @root
- 5.times do |i|
+ 5.times do |_i|
FactoryBot.create(:partner, users: [@root])
end
@@ -179,7 +177,7 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
test "new user has preselected partner when ID provided" do
sign_in @root
- 5.times do |i|
+ 5.times do |_i|
FactoryBot.create(:partner, users: [@root])
end
@@ -243,7 +241,7 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
new_user_params = {
email: 'user@example.com',
role: 'root',
- avatar: fixture_file_upload("bad-cat-picture.bmp"),
+ avatar: fixture_file_upload("bad-cat-picture.bmp")
}
post admin_users_path, params: { user: new_user_params }
@@ -252,9 +250,11 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
assert_select "h6", text: "1 error prohibited this User from being saved"
# top of page form error box
- assert_select '#form-errors li', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select '#form-errors li',
+ text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
- assert_select 'form .user_avatar .invalid-feedback', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select 'form .user_avatar .invalid-feedback',
+ text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
end
test 'update user avatar upload problem feedback' do
@@ -263,7 +263,7 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
user_params = {
email: @root.email,
role: @root.role,
- avatar: fixture_file_upload("bad-cat-picture.bmp"),
+ avatar: fixture_file_upload("bad-cat-picture.bmp")
}
put admin_user_path(@root), params: { user: user_params }
@@ -272,9 +272,11 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
assert_select "h6", text: "1 error prohibited this User from being saved"
# top of page form error box
- assert_select '#form-errors li', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select '#form-errors li',
+ text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
- assert_select 'form .user_avatar .invalid-feedback', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select 'form .user_avatar .invalid-feedback',
+ text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
end
test 'update profile avatar upload problem feedback' do
@@ -282,7 +284,7 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
user_params = {
email: @root.email,
- avatar: fixture_file_upload("bad-cat-picture.bmp"),
+ avatar: fixture_file_upload("bad-cat-picture.bmp")
}
patch update_profile_admin_user_path(@root), params: { user: user_params }
@@ -291,9 +293,10 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
assert_select "h6", text: "1 error prohibited this User from being saved"
# top of page form error box
- assert_select '#form-errors li', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select '#form-errors li',
+ text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
- assert_select 'form .user_avatar .invalid-feedback', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
+ assert_select 'form .user_avatar .invalid-feedback',
+ text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png"
end
-
end
diff --git a/test/integration/devise_redirection_test.rb b/test/integration/devise_redirection_test.rb
index 8818cfd49..fb50e7e9c 100644
--- a/test/integration/devise_redirection_test.rb
+++ b/test/integration/devise_redirection_test.rb
@@ -1,7 +1,8 @@
+# frozen_string_literal: true
+
require 'test_helper'
class DeviseRedirectTest < ActionDispatch::IntegrationTest
-
include Capybara::DSL
include Capybara::Minitest::Assertions
include EmailHelper
@@ -30,8 +31,9 @@ class DeviseRedirectTest < ActionDispatch::IntegrationTest
click_button 'Send me reset password instructions'
# has redirected to log in page with flash
- assert_selector '.alert-success', text: 'You will receive an email with instructions on how to reset your password in a few minutes.'
- assert_equal 'http://lvh.me/users/sign_in', current_url
+ assert_selector '.alert-success',
+ text: 'You will receive an email with instructions on how to reset your password in a few minutes.'
+ assert_equal 'http://lvh.me/users/sign_in', current_url
# now pick up the reset email and extract the link
email = last_email_delivered
@@ -48,7 +50,7 @@ class DeviseRedirectTest < ActionDispatch::IntegrationTest
# we are now logged in
assert_selector '.alert-success', text: 'Your password has been changed successfully. You are now signed in.'
- assert_equal 'http://admin.lvh.me:3000/', current_url
+ assert_equal 'http://admin.lvh.me:3000/', current_url
end
test 'invitation to set password' do
@@ -90,8 +92,7 @@ class DeviseRedirectTest < ActionDispatch::IntegrationTest
click_button 'Set password'
# user should be logged in
- assert_equal 'http://admin.lvh.me:3000/', current_url
+ assert_equal 'http://admin.lvh.me:3000/', current_url
assert_selector '.alert-success', text: 'Your password was set successfully. You are now signed in'
end
end
-
diff --git a/test/integration/event_integration_test.rb b/test/integration/event_integration_test.rb
index aaf85de2d..b12da130a 100644
--- a/test/integration/event_integration_test.rb
+++ b/test/integration/event_integration_test.rb
@@ -32,7 +32,8 @@ class EventIntegrationTest < ActionDispatch::IntegrationTest
get from_site_slug(@neighbourhood_site, event_path(@event))
get "http://#{@neighbourhood_site.slug}.lvh.me/events/#{@event.id}"
assert_response :success
- assert_select 'title', count: 1, text: "#{@event.summary}, #{@event.date}, #{@event.time} | #{@neighbourhood_site.name}"
+ assert_select 'title', count: 1,
+ text: "#{@event.summary}, #{@event.date}, #{@event.time} | #{@neighbourhood_site.name}"
assert_select 'div.hero h4', text: "Neighbourhood's Community Calendar"
assert_select 'div.hero h1', text: @event.summary
assert_select 'div.event__detail', count: 4
diff --git a/test/integration/event_site_integration_test.rb b/test/integration/event_site_integration_test.rb
index ae60fb67d..409bbf2e4 100644
--- a/test/integration/event_site_integration_test.rb
+++ b/test/integration/event_site_integration_test.rb
@@ -29,23 +29,23 @@ class EventForSiteScopeTest < ActiveSupport::TestCase
)
end
- test "returns a regular set of events" do
+ test 'returns a regular set of events' do
found = Event.for_site(@site)
count = found.count
- assert count == 2
+ assert_equal(2, count)
end
- test "does not return events outside of address or service area" do
+ test 'does not return events outside of address or service area' do
other_site_neighbourhood = neighbourhoods(:two)
other_site = create(:site)
other_site.neighbourhoods << other_site_neighbourhood
found = Event.for_site(other_site)
count = found.count
- assert count == 0
+ assert_equal(0, count)
end
- test "also returns events with partners that have service areas in the site scope" do
+ test 'also returns events with partners that have service areas in the site scope' do
other_site_neighbourhood = neighbourhoods(:two)
other_site = create(:site)
other_site.neighbourhoods << other_site_neighbourhood
@@ -54,13 +54,11 @@ class EventForSiteScopeTest < ActiveSupport::TestCase
found = Event.for_site(other_site)
count = found.count
- assert count == 2
+ assert_equal(2, count)
end
-
end
-class EventsBySiteTagTest < ActionDispatch::IntegrationTest
-
+class EventsBySiteTagTest < ActionDispatch::IntegrationTest
test 'filtering events by partner tag' do
Neighbourhood.destroy_all
@@ -76,7 +74,7 @@ class EventsBySiteTagTest < ActionDispatch::IntegrationTest
tag = Tag.create!(
name: 'Tag',
slug: 'tag',
- description: 'A tag about a thing',
+ description: 'A tag about a thing'
)
tag_site = Site.create!(
@@ -93,7 +91,7 @@ class EventsBySiteTagTest < ActionDispatch::IntegrationTest
street_address: '123 Street',
postcode: 'M15 5DD'
)
- assert address.neighbourhood == neighbourhood
+ assert_equal address.neighbourhood, neighbourhood
partner_with_tag = Partner.create!(
name: 'Partner with tag',
@@ -113,7 +111,7 @@ class EventsBySiteTagTest < ActionDispatch::IntegrationTest
Event.create!(
partner: partner_with_tag,
summary: "Event with tagged partner #{n}",
- dtstart: DateTime.now + 1.hours,
+ dtstart: DateTime.now + 1.hour,
dtend: DateTime.now + 2.hours,
address: address
)
@@ -124,7 +122,7 @@ class EventsBySiteTagTest < ActionDispatch::IntegrationTest
Event.create!(
partner: partner_without_tag,
summary: "Event without tagged partner #{n}",
- dtstart: DateTime.now + 1.hours,
+ dtstart: DateTime.now + 1.hour,
dtend: DateTime.now + 2.hours,
address: address
)
@@ -136,4 +134,3 @@ class EventsBySiteTagTest < ActionDispatch::IntegrationTest
assert_select 'ol.events li .event', count: 2
end
end
-
diff --git a/test/integration/events_integration_test.rb b/test/integration/events_integration_test.rb
index 4673385d6..4f695ad22 100644
--- a/test/integration/events_integration_test.rb
+++ b/test/integration/events_integration_test.rb
@@ -28,7 +28,6 @@ class EventsIntegrationTest < ActionDispatch::IntegrationTest
end
@neighbourhood_site.neighbourhoods << @neighbourhood2
-
# Make a ward, add events to that ward
@ward = create(:neighbourhood)
@regional_ward_events = create_list :event, 5, dtstart: date + 1.hour
diff --git a/test/integration/graphql/article_by_tag_query_test.rb b/test/integration/graphql/article_by_tag_query_test.rb
index d57ebce0d..4ad8de6ef 100644
--- a/test/integration/graphql/article_by_tag_query_test.rb
+++ b/test/integration/graphql/article_by_tag_query_test.rb
@@ -7,7 +7,7 @@ class ArticlesByTagTest < ActionDispatch::IntegrationTest
user = create(:user)
not_published_article = Article.create!(
- title: "Not published article",
+ title: 'Not published article',
body: 'article body text',
author: user
)
@@ -15,7 +15,7 @@ class ArticlesByTagTest < ActionDispatch::IntegrationTest
epoch = DateTime.now.beginning_of_day
not_tagged_article = Article.create!(
- title: "Not tagged article",
+ title: 'Not tagged article',
body: 'article body text',
author: user,
is_draft: false,
@@ -30,7 +30,6 @@ class ArticlesByTagTest < ActionDispatch::IntegrationTest
body: 'article body text',
author: user,
is_draft: false
-
)
article.update! published_at: epoch + (n + 1).days
@@ -49,7 +48,7 @@ class ArticlesByTagTest < ActionDispatch::IntegrationTest
GRAPHQL
result = PlaceCalSchema.execute(query_string)
- refute result.key?('errors'), 'errors are present'
+ assert_not result.key?('errors'), 'errors are present'
data = result['data']
assert data.key?('articlesByTag')
@@ -58,7 +57,7 @@ class ArticlesByTagTest < ActionDispatch::IntegrationTest
assert_equal 3, articles.length, 'expected to only find articles that are published and tagged correctly'
# newest to oldest
- expected_titles = [ 2, 1, 0 ].map { |index| live_tagged_articles[index].title }
+ expected_titles = [2, 1, 0].map { |index| live_tagged_articles[index].title }
found_titles = articles.map { |article| article['name'] }
assert_equal expected_titles, found_titles
end
diff --git a/test/integration/graphql/article_query_type_test.rb b/test/integration/graphql/article_query_type_test.rb
index e7c03d645..5b28ef414 100644
--- a/test/integration/graphql/article_query_type_test.rb
+++ b/test/integration/graphql/article_query_type_test.rb
@@ -17,7 +17,7 @@ class ArticleIndexTest < ActionDispatch::IntegrationTest
author: @user,
is_draft: false,
published_at: DateTime.now,
- partners: @partners,
+ partners: @partners
)
end
@@ -55,7 +55,7 @@ class ArticleIndexTest < ActionDispatch::IntegrationTest
assert data.key?('articleConnection'), 'result is missing key `allArticles`'
edges = data['articleConnection']['edges']
- assert_equal edges.length, 5
+ assert_equal(5, edges.length)
# Strip the 'node' object container off so we don't have to deal with that
nodes = edges.map { |edge| edge['node'] }
@@ -63,7 +63,7 @@ class ArticleIndexTest < ActionDispatch::IntegrationTest
nodes.each do |gql_article|
assert_field gql_article, 'name', 'Article title is nil?'
- refute_nil article = Article.find_by(title: gql_article['name']), 'Returned article that doesn\'t exist?'
+ assert_not_nil article = Article.find_by(title: gql_article['name']), 'Returned article that doesn\'t exist?'
assert_field_equals gql_article, 'headline', value: article.title
assert_field_equals gql_article, 'author', value: article.author_name
diff --git a/test/integration/graphql/articles_by_partner_tag_test.rb b/test/integration/graphql/articles_by_partner_tag_test.rb
index d365f23d5..bbee1825c 100644
--- a/test/integration/graphql/articles_by_partner_tag_test.rb
+++ b/test/integration/graphql/articles_by_partner_tag_test.rb
@@ -7,7 +7,7 @@ class ArticlesByPartnerTagTest < ActionDispatch::IntegrationTest
user = create(:user)
not_published_article = Article.create!(
- title: "Not published article",
+ title: 'Not published article',
body: 'article body text',
author: user
)
@@ -15,7 +15,7 @@ class ArticlesByPartnerTagTest < ActionDispatch::IntegrationTest
epoch = DateTime.now.beginning_of_day
not_tagged_article = Article.create!(
- title: "Not tagged article",
+ title: 'Not tagged article',
body: 'article body text',
author: user,
is_draft: false,
@@ -32,7 +32,6 @@ class ArticlesByPartnerTagTest < ActionDispatch::IntegrationTest
body: 'article body text',
author: user,
is_draft: false
-
)
article.update! published_at: epoch + (n + 1).days
@@ -51,7 +50,7 @@ class ArticlesByPartnerTagTest < ActionDispatch::IntegrationTest
GRAPHQL
result = PlaceCalSchema.execute(query_string)
- refute result.key?('errors'), 'errors are present'
+ assert_not result.key?('errors'), 'errors are present'
data = result['data']
assert data.key?('articlesByPartnerTag')
@@ -60,7 +59,7 @@ class ArticlesByPartnerTagTest < ActionDispatch::IntegrationTest
assert_equal 5, articles.length, 'expected to only find articles that are published and tagged correctly'
# newest to oldest
- expected_titles = [ 4, 3, 2, 1, 0 ].map { |index| live_tagged_articles[index].title }
+ expected_titles = [4, 3, 2, 1, 0].map { |index| live_tagged_articles[index].title }
found_titles = articles.map { |article| article['name'] }
assert_equal expected_titles, found_titles
end
diff --git a/test/integration/graphql/event_integration_test.rb b/test/integration/graphql/event_integration_test.rb
index 6264ea805..b63e4673a 100644
--- a/test/integration/graphql/event_integration_test.rb
+++ b/test/integration/graphql/event_integration_test.rb
@@ -46,14 +46,14 @@ class GraphQLEventTest < ActionDispatch::IntegrationTest
connection = assert_field data, 'eventConnection'
edges = assert_field connection, 'edges'
- assert_equal edges.length, 5
+ assert_equal(5, edges.length)
# TODO: Actually test that the events we are getting back are the ones we want
end
test 'can show specific event' do
event = @partner.events.create!(
dtstart: Time.now,
- summary: "An event summary",
+ summary: 'An event summary',
description: 'Longer text covering the event in more detail',
address: @address
)
@@ -112,11 +112,11 @@ def build_time_events(now_time)
description: 'Longer text covering the event in more detail',
address: @address
)
- time += 1.days
+ time += 1.day
end
# events in the near future
- time = now_time + 1.days
+ time = now_time + 1.day
5.times do
@partner.events.create!(
dtstart: time,
@@ -124,7 +124,7 @@ def build_time_events(now_time)
description: 'Longer text covering the event in more detail',
address: @address
)
- time += 1.days
+ time += 1.day
end
# events in the far future
@@ -132,11 +132,11 @@ def build_time_events(now_time)
5.times do
@partner.events.create!(
dtstart: time,
- summary: "future: An event summary",
+ summary: 'future: An event summary',
description: 'Longer text covering the event in more detail',
address: @address
)
- time += 1.days
+ time += 1.day
end
end
@@ -159,10 +159,10 @@ def build_time_events(now_time)
refute_field result, 'errors'
data = result['data']
- assert data.has_key?('eventsByFilter'), 'Data structure does not contain event key'
+ assert data.key?('eventsByFilter'), 'Data structure does not contain event key'
events = data['eventsByFilter']
- assert_equal events.length, 10, 'was expecting only events in the future'
+ assert_equal(10, events.length, 'was expecting only events in the future')
# TODO: Actually test that the events we are getting back are the ones we want
end
end
@@ -186,10 +186,10 @@ def build_time_events(now_time)
refute_field result, 'errors'
data = result['data']
- assert data.has_key?('eventsByFilter'), 'Data structure does not contain event key'
+ assert data.key?('eventsByFilter'), 'Data structure does not contain event key'
events = data['eventsByFilter']
- assert_equal events.length, 15, 'was expecting to see all events'
+ assert_equal(15, events.length, 'was expecting to see all events')
# TODO: Actually test that the events we are getting back are the ones we want
end
end
@@ -213,10 +213,10 @@ def build_time_events(now_time)
refute_field result, 'errors'
data = result['data']
- assert data.has_key?('eventsByFilter'), 'Data structure does not contain event key'
+ assert data.key?('eventsByFilter'), 'Data structure does not contain event key'
events = data['eventsByFilter']
- assert_equal events.length, 5, 'was expecting to see only some future events'
+ assert_equal(5, events.length, 'was expecting to see only some future events')
# TODO: Actually test that the events we are getting back are the ones we want
end
end
@@ -226,8 +226,8 @@ def build_time_events(now_time)
test 'can scope to neighbourhood (via partner address)' do
3.times do
@partner.events.create!(
- dtstart: DateTime.now + 1.hours,
- summary: "partner 1: An event summary",
+ dtstart: DateTime.now + 1.hour,
+ summary: 'partner 1: An event summary',
description: 'Longer text covering the event in more detail',
address: @address
)
@@ -238,8 +238,8 @@ def build_time_events(now_time)
5.times do
other_partner.events.create!(
- dtstart: DateTime.now + 1.hours,
- summary: "partner 2: An event summary",
+ dtstart: DateTime.now + 1.hour,
+ summary: 'partner 2: An event summary',
description: 'Longer text covering the event in more detail',
address: other_address
)
@@ -258,10 +258,10 @@ def build_time_events(now_time)
refute_field result, 'errors'
data = result['data']
- assert data.has_key?('eventsByFilter'), 'Data structure does not contain event key'
+ assert data.key?('eventsByFilter'), 'Data structure does not contain event key'
events = data['eventsByFilter']
- assert_equal events.length, 5, 'was expecting to see only events from other_partner'
+ assert_equal(5, events.length, 'was expecting to see only events from other_partner')
# TODO: Actually test that the events we are getting back are the ones we want
end
@@ -274,8 +274,8 @@ def build_time_events(now_time)
5.times do
@partner.events.create!(
- dtstart: DateTime.now + 1.hours,
- summary: "partner in good neighbourhood: An event summary",
+ dtstart: DateTime.now + 1.hour,
+ summary: 'partner in good neighbourhood: An event summary',
description: 'Longer text covering the event in more detail',
address: @address
)
@@ -287,8 +287,8 @@ def build_time_events(now_time)
3.times do
other_partner.events.create!(
- dtstart: DateTime.now + 1.hours,
- summary: "partner in bad neighbourhood: An event summary",
+ dtstart: DateTime.now + 1.hour,
+ summary: 'partner in bad neighbourhood: An event summary',
description: 'Longer text covering the event in more detail',
address: create(:bare_address_2)
)
@@ -307,23 +307,23 @@ def build_time_events(now_time)
refute_field result, 'errors'
data = result['data']
- assert data.has_key?('eventsByFilter'), 'Data structure does not contain event key'
+ assert data.key?('eventsByFilter'), 'Data structure does not contain event key'
events = data['eventsByFilter']
- assert_equal events.length, 5, 'was expecting to see only events within neighbourhood_good service area'
+ assert_equal(5, events.length, 'was expecting to see only events within neighbourhood_good service area')
# TODO: Actually test that the events we are getting back are the ones we want
end
# in cases where we have eventConnection { edges { node { ... } } }
def map_edges_to_ids(edges)
# [{ 'node': { 'id': 23, etc } }, ...] => { '23': { 'id': 23, etc }, ... }
- edges.map { |edge| [edge['node']['id'].to_i, edge['node']] }.to_h
+ edges.to_h { |edge| [edge['node']['id'].to_i, edge['node']] }
end
# in cases where we have eventsByFilter { ... }
def map_results_to_ids(events)
# [{ 'id': 23, etc }, ...] => { '23': { 'id': 23, etc }, ... }
- events.map { |event| [event['id'].to_i, event] }.to_h
+ events.index_by { |event| event['id'].to_i }
end
# this should mainly be tested elsewhere
@@ -398,7 +398,7 @@ def map_results_to_ids(events)
connection = assert_field data, 'eventConnection'
edges = assert_field connection, 'edges'
- assert_equal edges.length, 1
+ assert_equal(1, edges.length)
data_event = assert_field edges.first, 'node'
assert_field_equals data_event, 'id', value: event.id.to_s
@@ -418,7 +418,10 @@ def map_results_to_ids(events)
# splice the lists so we get a reasonable number of events, this also replaces? the `events` list :)
# stuff off rubocop this is perfectly fine
- events.zip(online_addresses).each { |event, oa| event.online_address = oa; event.save! }
+ events.zip(online_addresses).each do |event, oa|
+ event.online_address = oa
+ event.save!
+ end
query_string = <<-GRAPHQL
query {
diff --git a/test/integration/graphql/partners_integration_test.rb b/test/integration/graphql/partners_integration_test.rb
index ea3d44816..a0d19d63f 100644
--- a/test/integration/graphql/partners_integration_test.rb
+++ b/test/integration/graphql/partners_integration_test.rb
@@ -28,7 +28,7 @@ class GraphQLPartnerTest < ActionDispatch::IntegrationTest
connection = assert_field data, 'partnerConnection'
edges = assert_field connection, 'edges'
- assert_equal edges.length, 5
+ assert_equal(5, edges.length)
# Validate that we are in-fact returning the partner's data, too
edges.lazy.zip(partner_list).each do |edge, partner|
@@ -92,7 +92,7 @@ def check_opening_hours(data, opening_hours)
expected_day = opening_hours.first
assert_kind_of Array, data, 'openingHours should be an array'
- assert data.length == 6 # from factory
+ assert_equal(6, data.length) # from factory
first_day = data.first
expected_day_of_week = expected_day['dayOfWeek'] =~ %r{/([^/]*)$} && Regexp.last_match(1)
@@ -104,7 +104,7 @@ def check_opening_hours(data, opening_hours)
def check_areas_served(data, service_areas)
assert_kind_of Array, data, 'areasServed should be an array'
- assert data.length == service_areas.count
+ assert_equal data.length, service_areas.count
wanted_area = service_areas.first
service_area = data.first
@@ -253,7 +253,7 @@ def check_basic_fields(data, partner)
partner_data = data['partner']
article_data = partner_data['articles']
- assert article_data.length == 1, 'Should only see the one article published by this partenr'
+ assert_equal(1, article_data.length, 'Should only see the one article published by this partenr')
end
test 'finding partners by tag' do
@@ -275,7 +275,7 @@ def check_basic_fields(data, partner)
data = result['data']
partner_data = data['partnersByTag']
- assert partner_data.length == 1, 'expecting to see a tag on this partner'
+ assert_equal(1, partner_data.length, 'expecting to see a tag on this partner')
end
test 'returns null properly if openning times are missing' do
@@ -333,7 +333,7 @@ def check_basic_fields(data, partner)
connection = assert_field data, 'partnerConnection'
edges = assert_field connection, 'edges'
- assert_equal edges.length, 1
+ assert_equal(1, edges.length)
data_partner = assert_field edges.first, 'node'
assert_field_equals data_partner, 'id', value: partner.id.to_s
diff --git a/test/integration/graphql/ping_integration_test.rb b/test/integration/graphql/ping_integration_test.rb
index 1c39858fe..dc1a44abc 100644
--- a/test/integration/graphql/ping_integration_test.rb
+++ b/test/integration/graphql/ping_integration_test.rb
@@ -12,7 +12,7 @@ class GraphQLPingTest < ActionDispatch::IntegrationTest
result = PlaceCalSchema.execute(query_string)
data = result['data']
- assert data.has_key?('ping')
+ assert data.key?('ping')
assert data['ping'] =~ /^Hello World! The time is \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/
end
diff --git a/test/integration/graphql/site_integration_test.rb b/test/integration/graphql/site_integration_test.rb
index cb24de7ba..8e7030cea 100644
--- a/test/integration/graphql/site_integration_test.rb
+++ b/test/integration/graphql/site_integration_test.rb
@@ -24,13 +24,13 @@ class GraphQLSitesTest < ActionDispatch::IntegrationTest
result = PlaceCalSchema.execute(query_string)
data = result['data']
- assert data.has_key?('siteConnection'), 'result is missing key `siteConnection`'
+ assert data.key?('siteConnection'), 'result is missing key `siteConnection`'
connection = data['siteConnection']
- assert connection.has_key?('edges')
+ assert connection.key?('edges')
edges = connection['edges']
- assert edges.length == 5
+ assert_equal(5, edges.length)
end
test 'can show specific site' do
@@ -48,10 +48,9 @@ class GraphQLSitesTest < ActionDispatch::IntegrationTest
result = PlaceCalSchema.execute(query_string)
data = result['data']
- assert data.has_key?('site')
+ assert data.key?('site')
data_site = data['site']
- assert data_site['name'] == site.name
-
+ assert_equal data_site['name'], site.name
end
end
diff --git a/test/integration/home_integration_test.rb b/test/integration/home_integration_test.rb
index 2f325518a..dd3257c12 100644
--- a/test/integration/home_integration_test.rb
+++ b/test/integration/home_integration_test.rb
@@ -5,7 +5,7 @@
class HomeIntegrationTest < ActionDispatch::IntegrationTest
test 'home page for default site has correct title' do
@default_site = create_default_site
- get "http://lvh.me"
+ get 'http://lvh.me'
assert_response :success
assert_select 'title', count: 1, text: 'PlaceCal | The Community Calendar'
assert_select 'h1', count: 1, text: 'The Community Calendar'
@@ -15,7 +15,8 @@ class HomeIntegrationTest < ActionDispatch::IntegrationTest
@neighbourhood_site = create(:site_local)
get "http://#{@neighbourhood_site.slug}.lvh.me"
assert_response :success
- assert_select 'title', count: 1, text: "#{@neighbourhood_site.name}"
- assert_select 'h1', count: 1, text: 'PlaceCal is a community events calendar where you can find everything near you, all in one place.'
+ assert_select 'title', count: 1, text: @neighbourhood_site.name.to_s
+ assert_select 'h1', count: 1,
+ text: 'PlaceCal is a community events calendar where you can find everything near you, all in one place.'
end
end
diff --git a/test/integration/news_integration_test.rb b/test/integration/news_integration_test.rb
index 2200abd21..10cce494f 100644
--- a/test/integration/news_integration_test.rb
+++ b/test/integration/news_integration_test.rb
@@ -17,7 +17,7 @@ class NewsIntegrationTest < ActionDispatch::IntegrationTest
partner = create(:partner, address: @address)
article = Article.create!(
- title: "Article from Partner",
+ title: 'Article from Partner',
is_draft: false,
body: 'lorem ipsum dorem ditsum',
author: @author
@@ -91,4 +91,3 @@ class NewsIntegrationTest < ActionDispatch::IntegrationTest
assert_select '.article__author', count: 0
end
end
-
diff --git a/test/integration/partner_integration_test.rb b/test/integration/partner_integration_test.rb
index c63f5bc3b..cf13ba5df 100644
--- a/test/integration/partner_integration_test.rb
+++ b/test/integration/partner_integration_test.rb
@@ -45,7 +45,7 @@ class PartnerIntegrationTest < ActionDispatch::IntegrationTest
end
test 'has accessibility text' do
- @partner.accessibility_info = "This is some accessibility informtation"
+ @partner.accessibility_info = 'This is some accessibility informtation'
@partner.save!
get from_site_slug(@default_site, partner_path(@partner))
diff --git a/test/integration/sites_integration_test.rb b/test/integration/sites_integration_test.rb
index e62f76199..42df494fa 100644
--- a/test/integration/sites_integration_test.rb
+++ b/test/integration/sites_integration_test.rb
@@ -28,7 +28,8 @@ class SitesIntegrationTest < ActionDispatch::IntegrationTest
test 'basic page content shows up' do
get 'http://hulme.lvh.me'
- assert_select 'h1', 'PlaceCal is a community events calendar where you can find everything near you, all in one place.'
+ assert_select 'h1',
+ 'PlaceCal is a community events calendar where you can find everything near you, all in one place.'
assert_select 'h2', "PlaceCal is working to make #{@site.place_name} a better connected neighbourhood."
assert_select 'p', @site.description
assert_select 'strong', @site_admin.full_name
diff --git a/test/integration/users_log_in_go_to_admin_site_test.rb b/test/integration/users_log_in_go_to_admin_site_test.rb
index d83872741..3223c5eb7 100644
--- a/test/integration/users_log_in_go_to_admin_site_test.rb
+++ b/test/integration/users_log_in_go_to_admin_site_test.rb
@@ -3,5 +3,4 @@
require 'test_helper'
class UsersLogInGoToAdminSiteTest < ActionDispatch::IntegrationTest
-
end
diff --git a/test/integration/users_login_on_site_test.rb b/test/integration/users_login_on_site_test.rb
index e717b4655..d739be322 100644
--- a/test/integration/users_login_on_site_test.rb
+++ b/test/integration/users_login_on_site_test.rb
@@ -1,10 +1,8 @@
-
# frozen_string_literal: true
require 'test_helper'
class UsersLoginOnSiteTest < ActionDispatch::IntegrationTest
-
setup do
create_default_site
end
diff --git a/test/jobs/calendar_importer/calendar_importer_task_test.rb b/test/jobs/calendar_importer/calendar_importer_task_test.rb
index bcdf99a36..21c63f1b5 100644
--- a/test/jobs/calendar_importer/calendar_importer_task_test.rb
+++ b/test/jobs/calendar_importer/calendar_importer_task_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
class CalendarImporterTaskTest < ActiveSupport::TestCase
@@ -21,14 +23,13 @@ class CalendarImporterTaskTest < ActiveSupport::TestCase
end
test 'rejects unknown sources by default' do
-
VCR.use_cassette('Uknown Teamup Feed', allow_playback_repeats: true) do
# set up the calendar with faulty data that we know will trip up
# the validations. we are testing the importer, not the model
calendar = create(
:calendar,
name: 'Unknown source calendar',
- source: 'https://not-a-real-calendar-provider.com/feed/ksq8ayp7mw5mhb193x/5941140.ics',
+ source: 'https://not-a-real-calendar-provider.com/feed/ksq8ayp7mw5mhb193x/5941140.ics'
)
calendar.update calendar_state: 'in_worker'
@@ -63,5 +64,4 @@ class CalendarImporterTaskTest < ActiveSupport::TestCase
assert_equal 'ical', calendar.importer_used
end
end
-
end
diff --git a/test/jobs/calendar_importer/calendar_importer_test.rb b/test/jobs/calendar_importer/calendar_importer_test.rb
index 7527d943d..5bd606b00 100644
--- a/test/jobs/calendar_importer/calendar_importer_test.rb
+++ b/test/jobs/calendar_importer/calendar_importer_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
# TODO: Assertations are wrong way around - should be (expected, actual)
@@ -15,9 +17,9 @@ class CalendarImporter::CalendarImporterTest < ActiveSupport::TestCase
first_event = events.first
last_event = events.last
- assert_equal events.count, 2
- assert_equal first_event.summary, 'Age Friendly Community Soup'
- assert_equal last_event.summary, 'YellowBird Age Friendly Drop-in'
+ assert_equal(2, events.count)
+ assert_equal('Age Friendly Community Soup', first_event.summary)
+ assert_equal('YellowBird Age Friendly Drop-in', last_event.summary)
end
end
@@ -88,9 +90,9 @@ class CalendarImporter::CalendarImporterTest < ActiveSupport::TestCase
first_event = events.first
last_event = events.last
- assert_equal events.count, 3
- assert_equal first_event.summary, 'Technical tours of the Martin Harris Centre for Music and Drama'
- assert_equal last_event.summary, 'KIDNAP@20: The Art of Incarceration'
+ assert_equal(3, events.count)
+ assert_equal('Technical tours of the Martin Harris Centre for Music and Drama', first_event.summary)
+ assert_equal('KIDNAP@20: The Art of Incarceration', last_event.summary)
end
end
@@ -106,9 +108,9 @@ class CalendarImporter::CalendarImporterTest < ActiveSupport::TestCase
first_event = events.first
last_event = events.last
- assert_equal events.count, 38
- assert_equal first_event.summary, 'Inuk'
- assert_equal last_event.summary, 'ZYP: Unusual Theatre in Unusual Spaces'
+ assert_equal(38, events.count)
+ assert_equal('Inuk', first_event.summary)
+ assert_equal('ZYP: Unusual Theatre in Unusual Spaces', last_event.summary)
end
end
@@ -152,7 +154,6 @@ class CalendarImporter::CalendarImporterTest < ActiveSupport::TestCase
url = 'https://z-arts.ticketsolve.com/shows.xml'
checksum = 'd1a94a9869af91d0548a1faf0ded91d7'
-
VCR.use_cassette('Z-Arts Calendar', allow_playback_repeats: true) do
calendar = create(:calendar, name: 'Z-Arts', last_checksum: checksum, source: url)
diff --git a/test/jobs/calendar_importer/event_base_html_sanitize_test.rb b/test/jobs/calendar_importer/event_base_html_sanitize_test.rb
index b42c17f7b..1bf18de6d 100644
--- a/test/jobs/calendar_importer/event_base_html_sanitize_test.rb
+++ b/test/jobs/calendar_importer/event_base_html_sanitize_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
class EventBaseHtmlSanitizeTest < ActiveSupport::TestCase
@@ -34,16 +36,16 @@ class EventBaseHtmlSanitizeTest < ActiveSupport::TestCase
event = EventBase.new(nil)
output = event.html_sanitize(input)
- expected_output = <<-MARKDOWN
-### A title!
+ expected_output = <<~MARKDOWN
+ ### A title!
-This is input
+ This is input
-Another Paragraph
+ Another Paragraph
-* One
-* Two
-* Three
+ * One
+ * Two
+ * Three
MARKDOWN
assert_equal expected_output.strip, output
@@ -72,45 +74,40 @@ class EventBaseHtmlSanitizeTest < ActiveSupport::TestCase
'',
'Another Paragraph',
'',
- 'Things',
+ 'Things'
].join("\n")
assert_equal expected_output.strip, output
end
test 'given markdown input nothing is changed on output' do
- input = <<-MARKDOWN
-### A title!
+ input = <<~MARKDOWN.strip
+ ### A title!
-This is input
+ This is input
-Another Paragraph
+ Another Paragraph
-* One
-* Two
-* Three
+ * One
+ * Two
+ * Three
MARKDOWN
- input.strip!
-
event = EventBase.new(nil)
output = event.html_sanitize(input)
assert_equal input, output
end
-
-# test 'cleans out non utf-8 input' do
-# # pulled from https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
-# input = '��This is a �����bad string�����'
-#
-# event = EventBase.new(nil)
-# output = event.html_sanitize(input)
-#
-# expected_output = 'This is a bad string'
-#
-# assert_equal expected_output, output
-# end
-
+ # test 'cleans out non utf-8 input' do
+ # # pulled from https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
+ # input = '��This is a �����bad string�����'
+ #
+ # event = EventBase.new(nil)
+ # output = event.html_sanitize(input)
+ #
+ # expected_output = 'This is a bad string'
+ #
+ # assert_equal expected_output, output
+ # end
end
-
diff --git a/test/jobs/calendar_importer/event_resolver_strategy_test.rb b/test/jobs/calendar_importer/event_resolver_strategy_test.rb
index cfbce150e..52703111b 100644
--- a/test/jobs/calendar_importer/event_resolver_strategy_test.rb
+++ b/test/jobs/calendar_importer/event_resolver_strategy_test.rb
@@ -1,36 +1,36 @@
-require 'test_helper'
-
-=begin
-
-- If event location is set and calendar strategy is 'event' or 'override', that location should be used instead of the partner's place
-- if event strategy is place, then it continues to work correctly
-- if event strategy is override and location is not set, it continues to work correctly
-
-1.
- event strategy
- overide strategy
- event source location is present
- address = source.location
-
-2.
- place strategy
- address = source.location
+# frozen_string_literal: true
-3.
- override strategy
- address = partner.location
-
-note:
-
-event locations can either
- be addresses like '123 Street, place, city, postcode'
- or places like 'The Science Museum'
- or hybrids like 'Goldsmiths university, 123 street, place, etc'
- or rooms like 'Room 250, Goldsmiths university, 123 street, place, etc'
- (or URLs like 'https://zoom.com/igfjgjybviutkhy')
- or missing
+require 'test_helper'
-=end
+#
+# - If event location is set and calendar strategy is 'event' or 'override', that location should be used instead of the partner's place
+# - if event strategy is place, then it continues to work correctly
+# - if event strategy is override and location is not set, it continues to work correctly
+#
+# 1.
+# event strategy
+# overide strategy
+# event source location is present
+# address = source.location
+#
+# 2.
+# place strategy
+# address = source.location
+#
+# 3.
+# override strategy
+# address = partner.location
+#
+# note:
+#
+# event locations can either
+# be addresses like '123 Street, place, city, postcode'
+# or places like 'The Science Museum'
+# or hybrids like 'Goldsmiths university, 123 street, place, etc'
+# or rooms like 'Room 250, Goldsmiths university, 123 street, place, etc'
+# (or URLs like 'https://zoom.com/igfjgjybviutkhy')
+# or missing
+#
class EventResolverStrategyTest < ActiveSupport::TestCase
FakeEvent = Struct.new(
@@ -54,7 +54,8 @@ def setup
@end_date = Date.new(1990, 1, 2)
@address = create(:address, street_address: '123 alpha', neighbourhood: @neighbourhood, postcode: 'M15 5DD')
- @other_address = create(:address, street_address: '456 beta', neighbourhood: @other_neighbourhood, postcode: 'OL6 8BH')
+ @other_address = create(:address, street_address: '456 beta', neighbourhood: @other_neighbourhood,
+ postcode: 'OL6 8BH')
@address_partner = create(:partner, name: 'Address Partner', address: @address)
@other_address_partner = create(:partner, name: 'Other Address Partner', address: @other_address)
@@ -158,14 +159,13 @@ def test_override_strategy_works_with_no_data_location
place, address = resolver.event_override_strategy(calendar.place)
end
- #puts "address_partner=#{@address_partner.to_json}"
- #puts "place=#{place.to_json}"
- #puts "address=#{address.to_json}"
+ # puts "address_partner=#{@address_partner.to_json}"
+ # puts "place=#{place.to_json}"
+ # puts "address=#{address.to_json}"
# FIXME
# these come from the calendar
- #assert_equal place, @address_partner
- #assert_equal address, @address_partner.address
+ # assert_equal place, @address_partner
+ # assert_equal address, @address_partner.address
end
end
-
diff --git a/test/jobs/calendar_importer/event_resolver_test.rb b/test/jobs/calendar_importer/event_resolver_test.rb
index 086728a81..659c7966a 100644
--- a/test/jobs/calendar_importer/event_resolver_test.rb
+++ b/test/jobs/calendar_importer/event_resolver_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
class EventsResolverTest < ActiveSupport::TestCase
@@ -57,18 +59,18 @@ class EventsResolverTest < ActiveSupport::TestCase
@fake_eventbrite_event = FakeEventbriteEvent.new(
id: '111111111111',
- name: { 'text': 'A summary' },
- description: { 'text': 'A description' },
+ name: { text: 'A summary' },
+ description: { text: 'A description' },
venue: nil,
- start: { 'local': @start_date.iso8601 },
- 'end': { 'local': @end_date.iso8601 },
+ start: { local: @start_date.iso8601 },
+ end: { local: @end_date.iso8601 },
online_event: true
)
@fake_meetup_event = FakeMeetupEvent.new(
id: '111111111',
- name: { 'text': 'A summary' },
- description: { 'text': 'This is a meetup description!
' },
+ name: { text: 'A summary' },
+ description: { text: 'This is a meetup description!
' },
venue: nil,
time: @start_date.to_i,
utc_offset: (@end_date.to_i - @start_date.to_i),
@@ -120,7 +122,7 @@ class EventsResolverTest < ActiveSupport::TestCase
resolver = CalendarImporter::EventResolver.new(ics_event_data, calendar, [], @start_date)
resolver.determine_online_location
- assert resolver.data.online_address_id.present?
+ assert_predicate resolver.data.online_address_id, :present?
online_address = OnlineAddress.find(resolver.data.online_address_id)
assert_equal online_address.url, @fake_ics_event['custom_properties']['x_google_conference'].first
@@ -136,7 +138,7 @@ class EventsResolverTest < ActiveSupport::TestCase
resolver = CalendarImporter::EventResolver.new(ics_event_data, calendar, [], @start_date)
resolver.determine_online_location
- assert resolver.data.online_address_id.present?
+ assert_predicate resolver.data.online_address_id, :present?
online_address = OnlineAddress.find(resolver.data.online_address_id)
assert_equal online_address.url, jitsi_link
@@ -152,7 +154,7 @@ class EventsResolverTest < ActiveSupport::TestCase
resolver = CalendarImporter::EventResolver.new(ics_event_data, calendar, [], @start_date)
resolver.determine_online_location
- assert resolver.data.online_address_id.present?
+ assert_predicate resolver.data.online_address_id, :present?
online_address = OnlineAddress.find(resolver.data.online_address_id)
assert_equal online_address.url, meet_link
@@ -168,7 +170,7 @@ class EventsResolverTest < ActiveSupport::TestCase
resolver = CalendarImporter::EventResolver.new(ics_event_data, calendar, [], @start_date)
resolver.determine_online_location
- assert resolver.data.online_address_id.present?
+ assert_predicate resolver.data.online_address_id, :present?
online_address = OnlineAddress.find(resolver.data.online_address_id)
assert_equal online_address.url, zoom_link
@@ -184,7 +186,7 @@ class EventsResolverTest < ActiveSupport::TestCase
resolver = CalendarImporter::EventResolver.new(event_data, calendar, [], @start_date)
resolver.determine_online_location
- assert resolver.data.online_address_id.present?
+ assert_predicate resolver.data.online_address_id, :present?
online_address = OnlineAddress.find(resolver.data.online_address_id)
assert_equal online_address.url, eventbrite_link
@@ -200,7 +202,7 @@ class EventsResolverTest < ActiveSupport::TestCase
resolver = CalendarImporter::EventResolver.new(event_data, calendar, [], @start_date)
resolver.determine_online_location
- assert resolver.data.online_address_id.present?
+ assert_predicate resolver.data.online_address_id, :present?
online_address = OnlineAddress.find(resolver.data.online_address_id)
assert_equal online_address.url, meetup_link
diff --git a/test/jobs/calendar_importer/events_import_test.rb b/test/jobs/calendar_importer/events_import_test.rb
index cde42b6a9..9bc1a8b58 100644
--- a/test/jobs/calendar_importer/events_import_test.rb
+++ b/test/jobs/calendar_importer/events_import_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
class EventsImportTest < ActiveSupport::TestCase
diff --git a/test/mailers/join_mailer_test.rb b/test/mailers/join_mailer_test.rb
index e440fbece..e6c084003 100644
--- a/test/mailers/join_mailer_test.rb
+++ b/test/mailers/join_mailer_test.rb
@@ -1,4 +1,6 @@
-require "test_helper"
+# frozen_string_literal: true
+
+require 'test_helper'
describe JoinMailer do
# it "does a thing" do
diff --git a/test/mailers/previews/join_mailer_preview.rb b/test/mailers/previews/join_mailer_preview.rb
index 50640ffe2..4426934c5 100644
--- a/test/mailers/previews/join_mailer_preview.rb
+++ b/test/mailers/previews/join_mailer_preview.rb
@@ -1,4 +1,5 @@
+# frozen_string_literal: true
+
# Preview all emails at http://localhost:3000/rails/mailers/contact_mailer
class JoinMailerPreview < ActionMailer::Preview
-
end
diff --git a/test/models/address_test.rb b/test/models/address_test.rb
index d3a67f14f..fcf560e26 100644
--- a/test/models/address_test.rb
+++ b/test/models/address_test.rb
@@ -21,7 +21,7 @@ class AddressTest < ActiveSupport::TestCase
)
address.save!
- assert address.postcode == expected_output
+ assert_equal address.postcode, expected_output
end
end
end
diff --git a/test/models/article_partner_test.rb b/test/models/article_partner_test.rb
index b42ae5cac..0f750c65c 100644
--- a/test/models/article_partner_test.rb
+++ b/test/models/article_partner_test.rb
@@ -1,4 +1,6 @@
-require "test_helper"
+# frozen_string_literal: true
+
+require 'test_helper'
class ArticlePartnerTest < ActiveSupport::TestCase
setup do
@@ -8,6 +10,6 @@ class ArticlePartnerTest < ActiveSupport::TestCase
test 'create article for partner' do
@partner.articles << @article
- assert_equal @partner.articles.count, 1
+ assert_equal(1, @partner.articles.count)
end
-end
\ No newline at end of file
+end
diff --git a/test/models/article_test.rb b/test/models/article_test.rb
index 48150066a..7fd5a3b79 100644
--- a/test/models/article_test.rb
+++ b/test/models/article_test.rb
@@ -10,21 +10,21 @@ class ArticleTest < ActiveSupport::TestCase
end
test 'article should be valid' do
- assert @article.valid?
+ assert_predicate @article, :valid?
end
test 'title should be present' do
@article.title = ''
- refute @article.valid?
+ assert_not_predicate @article, :valid?
end
test 'body should be present' do
@article.body = ''
- refute @article.valid?
+ assert_not_predicate @article, :valid?
end
test 'published_at updates correctly when is_draft is set' do
- assert @article_draft.published_at.nil?
+ assert_nil @article_draft.published_at
@article_draft.is_draft = false
assert @article_draft.save!
@@ -40,7 +40,7 @@ class ArticleTest < ActiveSupport::TestCase
4.times do |n|
Article.create!(
title: "Article title no. #{n}",
- body: "lorem ipsum ...",
+ body: 'lorem ipsum ...',
author: user
)
end
@@ -49,7 +49,7 @@ class ArticleTest < ActiveSupport::TestCase
2.times do |n|
article = Article.create!(
title: "Article title no. #{n}",
- body: "lorem ipsum ...",
+ body: 'lorem ipsum ...',
author: user
)
article.tags << tag
@@ -69,7 +69,7 @@ class ArticleTest < ActiveSupport::TestCase
3.times do |n|
Article.create!(
title: "Article title no. #{n}",
- body: "lorem ipsum ...",
+ body: 'lorem ipsum ...',
author: user
)
end
@@ -78,7 +78,7 @@ class ArticleTest < ActiveSupport::TestCase
5.times do |n|
article = Article.create!(
title: "Article title no. #{n}",
- body: "lorem ipsum ...",
+ body: 'lorem ipsum ...',
author: user
)
article.partners << partner
@@ -203,6 +203,6 @@ class ArticleTest < ActiveSupport::TestCase
art = create(:article)
art.body = 'A body of text about something'
art.save!
- assert art.body_html.present?
+ assert_predicate art.body_html, :present?
end
end
diff --git a/test/models/calendar_state_test.rb b/test/models/calendar_state_test.rb
index f27ae4519..c449626f3 100644
--- a/test/models/calendar_state_test.rb
+++ b/test/models/calendar_state_test.rb
@@ -9,7 +9,7 @@ class CalendarStateTest < ActiveSupport::TestCase
# idle
test 'is idle by default' do
- assert Calendar.new.calendar_state.idle?
+ assert_predicate Calendar.new.calendar_state, :idle?
end
# queueing
@@ -17,7 +17,7 @@ class CalendarStateTest < ActiveSupport::TestCase
assert_enqueued_jobs 0
calendar = create(:calendar)
calendar.queue_for_import! false, Date.new(2000, 1, 1)
- assert calendar.calendar_state.in_queue?
+ assert_predicate calendar.calendar_state, :in_queue?
assert_enqueued_jobs 1
end
@@ -27,38 +27,38 @@ class CalendarStateTest < ActiveSupport::TestCase
calendar.queue_for_import! false, Date.new(2000, 1, 1)
# this has not changed
- assert calendar.calendar_state.in_queue?
+ assert_predicate calendar.calendar_state, :in_queue?
# not in queue
assert_enqueued_jobs 0
end
- test "can move into working state" do
+ test 'can move into working state' do
VCR.use_cassette(:import_test_calendar) do
calendar = create(:calendar, calendar_state: :in_queue, source: SOURCE_URL)
calendar.flag_start_import_job!
- assert calendar.calendar_state.in_worker?
+ assert_predicate calendar.calendar_state, :in_worker?
end
end
# in worker
- test "can move into idle state" do
+ test 'can move into idle state' do
VCR.use_cassette(:import_test_calendar) do
calendar = create(:calendar, calendar_state: :in_worker, source: SOURCE_URL)
calendar.flag_complete_import_job! [], 0, 'ical'
- assert calendar.calendar_state.idle?
+ assert_predicate calendar.calendar_state, :idle?
# are we close enough?
# deal with weird database encoding serialisations
assert_in_delta Time.now.to_i, calendar.last_import_at.to_i, 24.hours
end
end
- test "can move into error state" do
+ test 'can move into error state' do
VCR.use_cassette(:import_test_calendar) do
bad_message = 'A description of the error'
calendar = create(:calendar, calendar_state: :in_worker, source: SOURCE_URL)
calendar.flag_error_import_job! bad_message
- assert calendar.calendar_state.error?
+ assert_predicate calendar.calendar_state, :error?
assert_equal bad_message, calendar.critical_error
end
end
@@ -80,25 +80,25 @@ class CalendarStateTest < ActiveSupport::TestCase
# set some invalid state
calendar.name = nil
- assert (calendar.valid? == false), 'Calendar should be invalid'
+ assert_predicate calendar, :invalid?, 'Calendar should be invalid'
+ # assert_equal (calendar.valid?, false), 'Calendar should be invalid'
# flag bad thing
calendar.flag_error_import_job! bad_message
# check the calendar is back to how it was
assert_equal name, calendar.name
- assert calendar.valid?, 'Calendar should be valid now'
+ assert_predicate calendar, :valid?, 'Calendar should be valid now'
# check the error was saved to calendar
- assert calendar.calendar_state.error?
+ assert_predicate calendar.calendar_state, :error?
assert_equal bad_message, calendar.critical_error
end
end
# error'd
- test "can be tested for" do
+ test 'can be tested for' do
calendar = create(:calendar, calendar_state: :error)
- assert calendar.calendar_state.error?
+ assert_predicate calendar.calendar_state, :error?
end
-
end
diff --git a/test/models/calendar_test.rb b/test/models/calendar_test.rb
index ee40e215d..8a4785628 100644
--- a/test/models/calendar_test.rb
+++ b/test/models/calendar_test.rb
@@ -10,50 +10,47 @@ class CalendarTest < ActiveSupport::TestCase
test 'has required fields' do
# Must have a name and source URL
- refute @calendar.valid?
- @calendar.name = "A name for the calendar"
- refute @calendar.valid?
- @calendar.source = "https://my-calendar.com"
- refute @calendar.valid?
+ assert_not_predicate @calendar, :valid?
+ @calendar.name = 'A name for the calendar'
+ assert_not_predicate @calendar, :valid?
+ @calendar.source = 'https://my-calendar.com'
+ assert_not_predicate @calendar, :valid?
@calendar.partner = create(:partner)
- refute @calendar.valid?
+ assert_not_predicate @calendar, :valid?
@calendar.place = create(:partner)
- assert @calendar.valid?
+ assert_predicate @calendar, :valid?
@calendar.save
# Sources must be unique
@existing_calendar = create(:calendar)
- @existing_calendar.update(source: "https://my-calendar.com")
- refute @existing_calendar.valid?
- assert_equal ["calendar source already in use"], @existing_calendar.errors[:source]
+ @existing_calendar.update(source: 'https://my-calendar.com')
+ assert_not_predicate @existing_calendar, :valid?
+ assert_equal ['calendar source already in use'], @existing_calendar.errors[:source]
end
test 'gets a contact for each calendar' do
@calendar = create(:calendar)
- assert @calendar.valid?
+ assert_predicate @calendar, :valid?
# If calendar contact listed, show that
- assert_equal [ @calendar.public_contact_email,
- @calendar.public_contact_name
- ], @calendar.contact_information
+ assert_equal [@calendar.public_contact_email,
+ @calendar.public_contact_name], @calendar.contact_information
# Otherwise, show the partner public contact if possible
@calendar.update(public_contact_email: nil)
- assert_equal [ @calendar.partner.public_email,
- @calendar.partner.public_name
- ], @calendar.contact_information
+ assert_equal [@calendar.partner.public_email,
+ @calendar.partner.public_name], @calendar.contact_information
# Otherwise, show the default location contact if possible
@calendar.partner.update(public_email: nil)
- assert_equal [ @calendar.place.public_email,
- @calendar.place.public_name
- ], @calendar.contact_information
+ assert_equal [@calendar.place.public_email,
+ @calendar.place.public_name], @calendar.contact_information
# Otherwise, return false
@calendar.place.update(public_email: nil)
- assert_equal false, @calendar.contact_information
+ assert_not @calendar.contact_information
end
- test "notices get counted when saved" do
- messages = [
- "alpha",
- "beta",
- "cappa"
+ test 'notices get counted when saved' do
+ messages = %w[
+ alpha
+ beta
+ cappa
]
calendar = build(:calendar)
@@ -61,14 +58,13 @@ class CalendarTest < ActiveSupport::TestCase
calendar.save!
assert_equal 3, calendar.notice_count
-
end
- test "notices are not counted if notices have not changed value" do
- messages = [
- "alpha",
- "beta",
- "cappa"
+ test 'notices are not counted if notices have not changed value' do
+ messages = %w[
+ alpha
+ beta
+ cappa
]
calendar = create(:calendar, notices: messages)
diff --git a/test/models/events_test.rb b/test/models/events_test.rb
index 8d410fc04..4db31e85c 100644
--- a/test/models/events_test.rb
+++ b/test/models/events_test.rb
@@ -25,7 +25,7 @@ class EventTest < ActiveSupport::TestCase
**@event_data }
assert Event.new(event_hash).save
- refute Event.new(event_hash).valid?
+ assert_not_predicate Event.new(event_hash), :valid?
assert_raises ActiveRecord::RecordInvalid do
Event.new(event_hash).save!
@@ -38,7 +38,7 @@ class EventTest < ActiveSupport::TestCase
assert a.save
b = Event.new(summary: 'foonlys get together :,)', **event_hash)
- assert b.valid?
+ assert_predicate b, :valid?
end
test 'can create two events with the same summary and calendar but diff start' do
@@ -46,8 +46,8 @@ class EventTest < ActiveSupport::TestCase
a = Event.new(dtstart: DateTime.now - 1.hour, **event_hash)
assert a.save
- b = Event.new(dtstart: DateTime.now - 3.hour, **event_hash)
- assert b.valid?
+ b = Event.new(dtstart: DateTime.now - 3.hours, **event_hash)
+ assert_predicate b, :valid?
end
test 'can create two events with the same summary and dtstart but diff calendar' do
@@ -56,7 +56,7 @@ class EventTest < ActiveSupport::TestCase
assert a.save
b = Event.new(calendar: create(:calendar), **event_hash)
- assert b.valid?
+ assert_predicate b, :valid?
end
test 'has blank location with no addresses at all' do
@@ -105,7 +105,7 @@ class EventTest < ActiveSupport::TestCase
events = Event.all.find_by_day(Date.today)
- assert_equal events.length, 1
+ assert_equal(1, events.length)
assert_equal events.first.dtstart, todays_event.dtstart
end
@@ -123,7 +123,7 @@ class EventTest < ActiveSupport::TestCase
events = Event.all.find_by_day(Date.today)
- assert_equal events.length, 1
+ assert_equal(1, events.length)
assert_equal events.first.dtstart, todays_event.dtstart
end
@@ -140,7 +140,7 @@ class EventTest < ActiveSupport::TestCase
events = Event.all.find_by_day(Date.today)
- assert_equal events.length, 1
+ assert_equal(1, events.length)
assert_equal events.first.dtstart, tomorrows_event.dtstart
end
end
diff --git a/test/models/neighbourhoods_test.rb b/test/models/neighbourhoods_test.rb
index dbb9116a9..15ac6e567 100644
--- a/test/models/neighbourhoods_test.rb
+++ b/test/models/neighbourhoods_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
class NeighbourhoodsAncestryTest < ActiveSupport::TestCase
@@ -13,35 +15,34 @@ class NeighbourhoodsAncestryTest < ActiveSupport::TestCase
assert @neighbourhood.district
assert @neighbourhood.country
- assert @ashton_neighbourhood.district.name == 'Tameside'
- assert @ashton_neighbourhood.district.unit == 'district'
+ assert_equal('Tameside', @ashton_neighbourhood.district.name)
+ assert_equal('district', @ashton_neighbourhood.district.unit)
- assert @ashton_neighbourhood.county.name == 'Greater Manchester'
- assert @ashton_neighbourhood.county.unit == 'county'
+ assert_equal('Greater Manchester', @ashton_neighbourhood.county.name)
+ assert_equal('county', @ashton_neighbourhood.county.unit)
- assert @ashton_neighbourhood.region.name == 'North West'
- assert @ashton_neighbourhood.region.unit == 'region'
+ assert_equal('North West', @ashton_neighbourhood.region.name)
+ assert_equal('region', @ashton_neighbourhood.region.unit)
- assert @ashton_neighbourhood.country.name == 'England'
- assert @ashton_neighbourhood.country.unit == 'country'
+ assert_equal('England', @ashton_neighbourhood.country.name)
+ assert_equal('country', @ashton_neighbourhood.country.unit)
end
test 'uses name if name_abbr is missing' do
# missing altogether
hood = Neighbourhood.new(name: 'neighbourhood')
- assert hood.abbreviated_name == 'neighbourhood'
+ assert_equal('neighbourhood', hood.abbreviated_name)
# is empty string
hood = Neighbourhood.new(name: 'neighbourhood', name_abbr: '')
- assert hood.abbreviated_name == 'neighbourhood'
+ assert_equal('neighbourhood', hood.abbreviated_name)
# is a blank string
hood = Neighbourhood.new(name: 'neighbourhood', name_abbr: ' ')
- assert hood.abbreviated_name == 'neighbourhood'
+ assert_equal('neighbourhood', hood.abbreviated_name)
# is fine with a value
hood = Neighbourhood.new(name: 'neighbourhood', name_abbr: 'hood')
- assert hood.abbreviated_name == 'hood'
+ assert_equal('hood', hood.abbreviated_name)
end
-
end
diff --git a/test/models/partner_address_or_service_area_permission_test.rb b/test/models/partner_address_or_service_area_permission_test.rb
index b47010a4a..a90c944ee 100644
--- a/test/models/partner_address_or_service_area_permission_test.rb
+++ b/test/models/partner_address_or_service_area_permission_test.rb
@@ -5,32 +5,32 @@
class PartnerAddressOrServiceAreaPermissionsTest < ActiveSupport::TestCase
setup do
@user = create(:user)
- @user_neighbourhood = neighbourhoods(:one)
-
+ @user_neighbourhood = neighbourhoods(:one)
+
@user.neighbourhoods << @user_neighbourhood
@new_partner = build(
- :partner,
+ :partner,
address: nil,
accessed_by_user: @user
)
end
- test "valid if address is in user ward" do
+ test 'valid if address is in user ward' do
@new_partner.address = create(:address, neighbourhood: @user_neighbourhood)
@new_partner.save!
- assert @new_partner.valid?
+ assert_predicate @new_partner, :valid?
end
- test "verify: with service area in user neighbourhoods" do
+ test 'verify: with service area in user neighbourhoods' do
@new_partner.service_area_neighbourhoods << @user_neighbourhood
@new_partner.save!
- assert @new_partner.valid?
+ assert_predicate @new_partner, :valid?
end
- test "verify: with service area contained within users neighbourhood subtrees" do
+ test 'verify: with service area contained within users neighbourhood subtrees' do
child_neighbourhood = create(:neighbourhood)
parent_neighbourhood = child_neighbourhood.parent
@@ -39,7 +39,7 @@ class PartnerAddressOrServiceAreaPermissionsTest < ActiveSupport::TestCase
@new_partner.service_area_neighbourhoods << child_neighbourhood
@new_partner.save!
- assert @new_partner.valid?
+ assert_predicate @new_partner, :valid?
end
test "with a service area not in user's ward set" do
@@ -48,6 +48,6 @@ class PartnerAddressOrServiceAreaPermissionsTest < ActiveSupport::TestCase
@new_partner.service_area_neighbourhoods << @user_neighbourhood
@new_partner.service_area_neighbourhoods << other_neighbourhood
- assert @new_partner.valid? == false, 'Users cannot create service areas outside of their neighbourhoods'
+ assert_not_predicate(@new_partner, :valid?, 'Users cannot create service areas outside of their neighbourhoods')
end
end
diff --git a/test/models/partner_address_or_service_area_presence_test.rb b/test/models/partner_address_or_service_area_presence_test.rb
index 6df034d26..73dd7c854 100644
--- a/test/models/partner_address_or_service_area_presence_test.rb
+++ b/test/models/partner_address_or_service_area_presence_test.rb
@@ -3,7 +3,6 @@
require 'test_helper'
class PartnerAddressOrServiceAreaPresenceTest < ActiveSupport::TestCase
-
setup do
@user = create(:root)
@neighbourhood = neighbourhoods(:one)
@@ -16,21 +15,20 @@ class PartnerAddressOrServiceAreaPresenceTest < ActiveSupport::TestCase
)
end
- test "is invalid if both service area and address not present" do
-
+ test 'is invalid if both service area and address not present' do
@new_partner.validate
- assert @new_partner.valid? == false, 'Partner should be invalid'
-
+ assert_not_predicate(@new_partner, :valid?, 'Partner should be invalid')
+
base_errors = @new_partner.errors[:base]
- assert base_errors.length > 0
+ assert_predicate base_errors.length, :positive?
end
test 'is valid with service_area set' do
@new_partner.service_areas.build neighbourhood: @neighbourhood
@new_partner.validate
- assert @new_partner.valid? == true, 'Partner should be valid'
+ assert_predicate(@new_partner, :valid?, 'Partner should be valid')
end
test 'is valid with address set' do
@@ -39,7 +37,7 @@ class PartnerAddressOrServiceAreaPresenceTest < ActiveSupport::TestCase
@new_partner.address = address
@new_partner.save!
- assert @new_partner.valid? == true, 'Partner should be valid'
+ assert_predicate(@new_partner, :valid?, 'Partner should be valid')
end
test 'is valid with both service_area and address set' do
@@ -49,6 +47,6 @@ class PartnerAddressOrServiceAreaPresenceTest < ActiveSupport::TestCase
@new_partner.service_areas.build neighbourhood: @neighbourhood
@new_partner.validate
- assert @new_partner.valid? == true, 'Partner should valid'
+ assert_predicate(@new_partner, :valid?, 'Partner should valid')
end
end
diff --git a/test/models/partner_service_area_test.rb b/test/models/partner_service_area_test.rb
index 819b4d86b..48846b4bd 100644
--- a/test/models/partner_service_area_test.rb
+++ b/test/models/partner_service_area_test.rb
@@ -15,13 +15,13 @@ class PartnerServiceAreaTest < ActiveSupport::TestCase
@partner.address = create(:address, neighbourhood: @neighbourhood)
@partner.save!
- assert @partner.valid?, 'Partner (without service_area) is not valid'
+ assert_predicate @partner, :valid?, 'Partner (without service_area) is not valid'
end
test 'is valid when set, can be accessed' do
model = build(:ashton_service_area_partner)
model.save!
- assert model.valid?
+ assert_predicate model, :valid?
service_areas = model.service_areas
assert_equal 1, service_areas.count
@@ -32,7 +32,7 @@ class PartnerServiceAreaTest < ActiveSupport::TestCase
@partner.service_area_neighbourhoods << @neighbourhood
@partner.save!
- assert @partner.valid?, 'Partner (with service_area) is not valid'
+ assert_predicate @partner, :valid?, 'Partner (with service_area) is not valid'
neighbourhood_count = @partner.service_area_neighbourhoods.count
assert_equal 1, neighbourhood_count, 'count neighbourhoods'
@@ -42,7 +42,7 @@ class PartnerServiceAreaTest < ActiveSupport::TestCase
@partner.address = create(:address, neighbourhood: @neighbourhood)
@partner.save!
- assert_raises ActiveRecord::RecordInvalid do
+ assert_raises ActiveRecord::RecordInvalid do
@partner.service_areas.create!(neighbourhood: @neighbourhood)
@partner.service_areas.create!(neighbourhood: @neighbourhood)
end
@@ -58,7 +58,7 @@ class PartnerServiceAreaTest < ActiveSupport::TestCase
@partner.service_areas.create! neighbourhood: other_neighbourhood
neighbourhoods = @partner.service_area_neighbourhoods.order('neighbourhoods.name').all
- assert neighbourhoods.count == 2, 'Failed to count neighbourhoods'
+ assert_equal(2, neighbourhoods.count, 'Failed to count neighbourhoods')
n1 = neighbourhoods[0]
assert_equal 'Ashton Hurst', n1.name
@@ -71,7 +71,7 @@ class PartnerServiceAreaTest < ActiveSupport::TestCase
@partner.service_areas.build neighbourhood: create(:moss_side_neighbourhood)
@partner.validate
- assert @partner.valid? == false, 'Partner should not be valid'
+ assert_not_predicate(@partner, :valid?, 'Partner should not be valid')
end
test 'can be set by root users' do
@@ -82,7 +82,7 @@ class PartnerServiceAreaTest < ActiveSupport::TestCase
@partner.service_area_neighbourhoods << other_neighbourhood
@partner.save!
- assert @partner.valid?, 'Partner (with service_area) should be valid'
+ assert_predicate @partner, :valid?, 'Partner (with service_area) should be valid'
neighbourhood_count = @partner.service_area_neighbourhoods.count
assert_equal 1, neighbourhood_count, 'count neighbourhoods'
diff --git a/test/models/partner_site_scope_test.rb b/test/models/partner_site_scope_test.rb
index 20c489121..239aa49bd 100644
--- a/test/models/partner_site_scope_test.rb
+++ b/test/models/partner_site_scope_test.rb
@@ -3,7 +3,6 @@
require 'test_helper'
class PartnerSiteScopeTest < ActiveSupport::TestCase
-
# this verifies that partner#for_site is behaving
# NOTE: these MUST match up with the geocoder response
@@ -39,12 +38,12 @@ def address_one
Neighbourhood.destroy_all
end
- test "empty site returns nothing" do
+ test 'empty site returns nothing' do
output = Partner.for_site(site)
- assert output.empty?, 'site should be empty'
+ assert_empty output, 'site should be empty'
end
- test "can find partners in site with address" do
+ test 'can find partners in site with address' do
neighbourhood = geocodable_neighbourhood_one
site.neighbourhoods << neighbourhood
@@ -54,7 +53,7 @@ def address_one
assert_equal 5, output.count # number of partners with addresses in site
end
- test "can find partners in site with service areas (without duplicates)" do
+ test 'can find partners in site with service areas (without duplicates)' do
neighbourhood_a = create(:bare_neighbourhood)
site.neighbourhoods << neighbourhood_a
@@ -73,7 +72,7 @@ def address_one
assert_equal 5, output.count
end
- test "can find partners by address and service_area" do
+ test 'can find partners by address and service_area' do
neighbourhood_a = create(:bare_neighbourhood)
site.neighbourhoods << neighbourhood_a
@@ -92,7 +91,7 @@ def address_one
assert_equal 2, output.count
end
- test "ignores partners on other sites" do
+ test 'ignores partners on other sites' do
neighbourhood_a = create(:bare_neighbourhood)
site.neighbourhoods << neighbourhood_a
@@ -135,7 +134,7 @@ def address_one
assert_equal 10, output.count
end
- test "only finds partners with tags if site has tags" do
+ test 'only finds partners with tags if site has tags' do
neighbourhood = geocodable_neighbourhood_one
tag = create(:tag)
other_tag = create(:tag)
diff --git a/test/models/partner_site_with_tag_scope_test.rb b/test/models/partner_site_with_tag_scope_test.rb
index a8e25f04d..3a8959225 100644
--- a/test/models/partner_site_with_tag_scope_test.rb
+++ b/test/models/partner_site_with_tag_scope_test.rb
@@ -1,10 +1,8 @@
-
# frozen_string_literal: true
require 'test_helper'
class PartnerSiteWithTagScopeTest < ActiveSupport::TestCase
-
# this verifies that partner#for_site is behaving
# NOTE: these MUST match up with the geocoder response
@@ -40,13 +38,13 @@ def address_one
Neighbourhood.destroy_all
end
- test "empty site/tag returns nothing" do
+ test 'empty site/tag returns nothing' do
tag = nil
output = Partner.for_site_with_tag(site, tag)
- assert output.empty?, 'site should be empty'
+ assert_empty output, 'site should be empty'
end
- test "finds partners with tag" do
+ test 'finds partners with tag' do
tag = create(:tag)
other_tag = create(:tag)
@@ -72,5 +70,4 @@ def address_one
output = Partner.for_site_with_tag(site, tag)
assert_equal 4, output.all.length
end
-
end
diff --git a/test/models/partner_test.rb b/test/models/partner_test.rb
index 366aeab5b..8b617c440 100644
--- a/test/models/partner_test.rb
+++ b/test/models/partner_test.rb
@@ -12,7 +12,7 @@ class PartnerTest < ActiveSupport::TestCase
test 'updates user roles when saved' do
@new_partner.users << @user
@new_partner.save
- assert @user.partner_admin?
+ assert_predicate @user, :partner_admin?
end
test 'can change postcode of partner' do
@@ -21,15 +21,15 @@ class PartnerTest < ActiveSupport::TestCase
new_postcode = 'OL6 8BH'
new_params = {
address_attributes: {
- 'street_address': @new_address.street_address,
- 'postcode': new_postcode
+ street_address: @new_address.street_address,
+ postcode: new_postcode
}
}
@new_partner.update! new_params
@new_partner.reload
- assert @new_partner.address.postcode == new_postcode
+ assert_equal @new_partner.address.postcode, new_postcode
end
test 'it recycles addresses if it can' do
@@ -38,14 +38,14 @@ class PartnerTest < ActiveSupport::TestCase
other_partner = build(:partner, address: nil, accessed_by_user: @user)
other_params = {
address_attributes: {
- 'street_address': @new_address.street_address,
- 'postcode': @new_address.postcode
+ street_address: @new_address.street_address,
+ postcode: @new_address.postcode
}
}
other_partner.update! other_params
other_partner.reload
- assert @new_partner.address_id == other_partner.address_id, 'should have same address ID'
+ assert_equal @new_partner.address_id, other_partner.address_id, 'should have same address ID'
end
test 'validate name length' do
@@ -66,12 +66,12 @@ class PartnerTest < ActiveSupport::TestCase
test 'validate no summary or description' do
@new_partner.update(name: 'Test Partner', summary: '', description: '')
- assert @new_partner.errors.empty?
+ assert_empty @new_partner.errors
end
test 'validate summary without description' do
@new_partner.update(name: 'Test Partner', summary: 'This is a test partner used for testing :)', description: '')
- assert @new_partner.errors.empty?, 'Should be able to submit a summary'
+ assert_empty @new_partner.errors, 'Should be able to submit a summary'
end
test 'validate description without summary' do
@@ -86,17 +86,16 @@ class PartnerTest < ActiveSupport::TestCase
end
test 'validate description and summary' do
-
@new_partner.update(name: 'Test Partner',
- summary: 'This is a test summary wheee :)',
- description: 'This is a test new_partner used for testing :)')
- assert @new_partner.errors.empty?, 'Should be able to submit a summary and description'
+ summary: 'This is a test summary wheee :)',
+ description: 'This is a test new_partner used for testing :)')
+ assert_empty @new_partner.errors, 'Should be able to submit a summary and description'
end
test 'validate summary length' do
# We can submit a 200 character summary
@new_partner.update(name: 'Test Partner', summary: ''.ljust(200, 'a'))
- assert @new_partner.errors.empty?, '200 character summary should be valid'
+ assert_empty @new_partner.errors, '200 character summary should be valid'
# But not a 201 character summary
@new_partner.update(name: 'Test Partner', summary: ''.ljust(201, 'a'))
@@ -108,15 +107,15 @@ class PartnerTest < ActiveSupport::TestCase
@new_partner.update(url: 'htp://bad-domain.co')
assert_equal ['is invalid'], @new_partner.errors[:url], 'Partner must have a valid url'
@new_partner.update(url: 'https://good-domain.com')
- refute @new_partner.errors.key?(:url), 'Valid URL not saved'
+ assert_not @new_partner.errors.key?(:url), 'Valid URL not saved'
end
test 'validate twitter' do
# Twitter must be valid
@new_partner.update(twitter_handle: '@asdf')
- refute @new_partner.errors.key?(:twitter_handle), 'Valid twitter not saved'
+ assert_not @new_partner.errors.key?(:twitter_handle), 'Valid twitter not saved'
@new_partner.update(twitter_handle: 'asdf')
- refute @new_partner.errors.key?(:twitter_handle), 'Valid twitter not saved'
+ assert_not @new_partner.errors.key?(:twitter_handle), 'Valid twitter not saved'
@new_partner.update(twitter_handle: 'https://twitter.com/asdf')
assert @new_partner.errors.key?(:twitter_handle), 'Should be account name not full URL'
@new_partner.update(twitter_handle: 'asd£$%dsa')
@@ -130,14 +129,14 @@ class PartnerTest < ActiveSupport::TestCase
@new_partner.update(facebook_link: 'Group-Name')
assert @new_partner.errors.key?(:facebook_link), 'invalid Facebook page name saved'
@new_partner.update(facebook_link: 'GroupName')
- refute @new_partner.errors.key?(:facebook_link), 'Valid page name not saved'
+ assert_not @new_partner.errors.key?(:facebook_link), 'Valid page name not saved'
end
test 'deals with badly formatted opening times' do
partner = build(:partner)
partner.opening_times = '{{ $data.openingHoursSpecifications }}'
- assert_equal [], partner.human_readable_opening_times
+ assert_empty partner.human_readable_opening_times
end
test 'opening_times can be unset' do
@@ -150,7 +149,7 @@ class PartnerTest < ActiveSupport::TestCase
opening_times_payload = [
{ opens: '', closes: '' },
{ opens: '', closes: '' },
- { opens: '', closes: '' },
+ { opens: '', closes: '' }
].to_json
p = Partner.new(opening_times: opening_times_payload)
diff --git a/test/models/service_area_test.rb b/test/models/service_area_test.rb
index a54724c55..ae8c9748b 100644
--- a/test/models/service_area_test.rb
+++ b/test/models/service_area_test.rb
@@ -1,4 +1,6 @@
-require "test_helper"
+# frozen_string_literal: true
+
+require 'test_helper'
describe ServiceArea do
# it "does a thing" do
diff --git a/test/models/site_test.rb b/test/models/site_test.rb
index 4e676bd10..7f8b26fb9 100644
--- a/test/models/site_test.rb
+++ b/test/models/site_test.rb
@@ -7,7 +7,7 @@ class SiteTest < ActiveSupport::TestCase
@site = create(:site)
end
- test "gets correct stylesheet link" do
+ test 'gets correct stylesheet link' do
assert_equal 'themes/pink', @site.stylesheet_link
@site.theme = :custom
@site.slug = 'my-town'
@@ -18,7 +18,6 @@ class SiteTest < ActiveSupport::TestCase
end
class SitePartnerTest < ActiveSupport::TestCase
-
test 'can find sites by partner' do
address_neighbourhood = FactoryBot.create(:neighbourhood)
service_area_neighbourhood = FactoryBot.create(:rusholme_neighbourhood)
@@ -44,7 +43,6 @@ class SitePartnerTest < ActiveSupport::TestCase
found = Site.sites_that_contain_partner(partner).order(:id)
- assert found == [address_site, service_area_site, tag_site]
+ assert_equal found, [address_site, service_area_site, tag_site]
end
end
-
diff --git a/test/models/supporter_test.rb b/test/models/supporter_test.rb
index 8956b5953..9365137e2 100644
--- a/test/models/supporter_test.rb
+++ b/test/models/supporter_test.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
class SupporterTest < ActiveSupport::TestCase
diff --git a/test/models/tag_test.rb b/test/models/tag_test.rb
index 48c4028f9..a67f40f7b 100644
--- a/test/models/tag_test.rb
+++ b/test/models/tag_test.rb
@@ -12,14 +12,14 @@ class TagTest < ActiveSupport::TestCase
test 'updates user roles when saved' do
@tag.users << @user
@tag.save
- assert @user.tag_admin?
+ assert_predicate @user, :tag_admin?
end
test 'updates partners tags when saved' do
@tag.partners << @partner
@tag.save
- assert @tag.partners.length > 0
+ assert_predicate @tag.partners.length, :positive?
end
test 'system_tags cannot modify name or slug' do
@@ -27,9 +27,9 @@ class TagTest < ActiveSupport::TestCase
@tag.name = 'This is a new name'
@tag.slug = 'a-new-tag-slug'
- refute @tag.validate
+ assert_not @tag.validate
- assert @tag.errors.has_key?(:name)
- assert @tag.errors.has_key?(:slug)
+ assert @tag.errors.key?(:name)
+ assert @tag.errors.key?(:slug)
end
end
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
index c0456a025..db173d278 100644
--- a/test/models/user_test.rb
+++ b/test/models/user_test.rb
@@ -10,19 +10,19 @@ class UserTest < ActiveSupport::TestCase
test 'owned neighbourhoods returns all descendants' do
# Does the admin only own one region neighbourhood?
- assert @neighbourhood_region_admin.neighbourhoods.length == 1
- assert @neighbourhood_region_admin.neighbourhoods.first.unit == 'region'
+ assert_equal(1, @neighbourhood_region_admin.neighbourhoods.length)
+ assert_equal('region', @neighbourhood_region_admin.neighbourhoods.first.unit)
# Does it return the region, the districts, and the wards?
# We have five counties with one district each, all parenting one ward, plus the region
# (See: factories/user.rb - neighbourhood_region_admin)
owned_length = 1 + (5 * 3)
- assert @neighbourhood_region_admin.owned_neighbourhoods.to_a.length == owned_length
+ assert_equal @neighbourhood_region_admin.owned_neighbourhoods.to_a.length, owned_length
# does it actually return both the districts and the wards?
- assert @neighbourhood_region_admin.owned_neighbourhoods.find_all { |u| u.unit == 'county' }.length == 5
- assert @neighbourhood_region_admin.owned_neighbourhoods.find_all { |u| u.unit == 'district' }.length == 5
- assert @neighbourhood_region_admin.owned_neighbourhoods.find_all { |u| u.unit == 'ward' }.length == 5
+ assert_equal(5, @neighbourhood_region_admin.owned_neighbourhoods.count { |u| u.unit == 'county' })
+ assert_equal(5, @neighbourhood_region_admin.owned_neighbourhoods.count { |u| u.unit == 'district' })
+ assert_equal(5, @neighbourhood_region_admin.owned_neighbourhoods.count { |u| u.unit == 'ward' })
end
test 'can edit neighourhoods' do
@@ -30,12 +30,12 @@ class UserTest < ActiveSupport::TestCase
owned_neighbourhoods = @neighbourhood_region_admin.owned_neighbourhoods
- county = owned_neighbourhoods.find_all { |u| u.unit == 'county' }.first
- district = owned_neighbourhoods.find_all { |u| u.unit == 'district' }.first
- ward = owned_neighbourhoods.find_all { |u| u.unit == 'ward' }.first
+ county = owned_neighbourhoods.find { |u| u.unit == 'county' }
+ district = owned_neighbourhoods.find { |u| u.unit == 'district' }
+ ward = owned_neighbourhoods.find { |u| u.unit == 'ward' }
# We do not have permissions to edit the country!
- assert (@neighbourhood_region_admin.can_alter_neighbourhood_by_id? region.parent.id) == false
+ assert_not((@neighbourhood_region_admin.can_alter_neighbourhood_by_id? region.parent.id))
# We should have permissions to edit a county, district, or ward neighbourhood
assert @neighbourhood_region_admin.can_alter_neighbourhood_by_id?(county.id)
@@ -55,16 +55,16 @@ class UserTest < ActiveSupport::TestCase
# Does this person manage at least one partner?
@user.partners << create(:partner)
@user.save
- assert @user.partner_admin?
+ assert_predicate @user, :partner_admin?
# Does this person manage at least one tag?
@user.tags << create(:tag)
@user.save
- assert @user.tag_admin?
+ assert_predicate @user, :tag_admin?
# Is this person a root? If they are, they're also a secretary
@user.update(role: :root)
- assert @user.root?
+ assert_predicate @user, :root?
end
test 'full name method gives sensible responses' do
@@ -87,13 +87,12 @@ class UserTest < ActiveSupport::TestCase
test 'without skip_password_validation' do
user = User.new(email: 'test@test.com', role: 'citizen')
- assert_equal false, user.valid?
+ assert_not_predicate user, :valid?
end
test 'with skip_password_valiation' do
user = User.new(email: 'test@test.com', role: 'citizen')
user.skip_password_validation = true
- assert_equal true, user.valid?
-
+ assert_predicate user, :valid?
end
end
diff --git a/test/policies/article_policy_test.rb b/test/policies/article_policy_test.rb
index 29db94980..7ef518360 100644
--- a/test/policies/article_policy_test.rb
+++ b/test/policies/article_policy_test.rb
@@ -16,7 +16,7 @@ def setup
partner.address.save!
end
# Double check that it's been looped together properly
- assert @neighbourhood_admin.owned_neighbourhood_ids.include?(@partner.address.neighbourhood.id)
+ assert_includes @neighbourhood_admin.owned_neighbourhood_ids, @partner.address.neighbourhood.id
@partner_admin = create(:partner_admin) do |user|
user.partners << @partner
diff --git a/test/policies/neighbourhoods_policy_test.rb b/test/policies/neighbourhoods_policy_test.rb
index a3990dcaf..6cd8b50e8 100644
--- a/test/policies/neighbourhoods_policy_test.rb
+++ b/test/policies/neighbourhoods_policy_test.rb
@@ -11,7 +11,7 @@ class NeighbourhoodPolicyTest < ActiveSupport::TestCase
end
def test_scope
- assert_equal(permitted_records(@citizen, Neighbourhood), [])
+ assert_empty(permitted_records(@citizen, Neighbourhood))
assert_equal(permitted_records(@neighbourhood_admin, Neighbourhood), @neighbourhood_admin.neighbourhoods)
# Enforcing ordering is annoying, just compare the length, let the user test ensure that owned_neighbourhoods works
assert_equal(permitted_records(@neighbourhood_region_admin, Neighbourhood).length,
diff --git a/test/policies/partner_policy_test.rb b/test/policies/partner_policy_test.rb
index 48192da89..407ca3f59 100644
--- a/test/policies/partner_policy_test.rb
+++ b/test/policies/partner_policy_test.rb
@@ -7,7 +7,7 @@ class PartnerPolicyTest < ActiveSupport::TestCase
# Make some user accounts
# -----------------------
@citizen = create(:citizen)
-
+
@correct_partner_admin = create(:partner_admin)
@wrong_partner_admin = create(:partner_admin)
@@ -24,7 +24,7 @@ class PartnerPolicyTest < ActiveSupport::TestCase
## Set up partner we want to test for and make sure it's in the right regions
# ---------------------------------------------------------------------------
-
+
@partner = @correct_partner_admin.partners.first
@correct_ward_admin.neighbourhoods << @partner.address.neighbourhood
@correct_district_admin.neighbourhoods << @partner.address.neighbourhood.district
@@ -38,7 +38,7 @@ class PartnerPolicyTest < ActiveSupport::TestCase
# puts "B: Partner address ward parental ID: #{parent.id}; Child ID: #{@partner.address.neighbourhood.id}"
# is_childed = parent.children.map(&:subtree).flatten.include?(@partner.address.neighbourhood)
# puts "B: Partner address ward parent contains ward: #{is_childed}"
-
+
# @multi_admin = create(:neighbourhood_admin)
# @multi_admin.neighbourhoods << @partner.address.neighbourhood
@@ -47,7 +47,7 @@ class PartnerPolicyTest < ActiveSupport::TestCase
end
# Everyone except guess can view list
- def test_index
+ def test_index
assert denies_access(@citizen, Partner, :index)
assert allows_access(@root, Partner, :index)
@@ -137,10 +137,9 @@ def test_update_with_partner_permissions
# denies user with no partners
assert denies_access(user, partner, :update)
-
+
# can update partners user has access to
user.partners << partner
assert allows_access(user, partner, :update)
end
end
-
diff --git a/test/policies/partner_scope_test.rb b/test/policies/partner_scope_test.rb
index 7f27f5ffd..94f9c6f6c 100644
--- a/test/policies/partner_scope_test.rb
+++ b/test/policies/partner_scope_test.rb
@@ -8,11 +8,11 @@ class PartnerScopeTest < ActiveSupport::TestCase
@basic_partner = create(:partner)
end
- test "returns nothing" do
- assert permitted_records(@normal_user, Partner) == []
+ test 'returns nothing' do
+ assert_empty(permitted_records(@normal_user, Partner))
end
- test "scope on ownership" do # test_scope_for_ownership
+ test 'scope on ownership' do # test_scope_for_ownership
# user doesn't own this
other_neighbourhood = neighbourhoods(:two)
not_user_address = create(:address, neighbourhood: other_neighbourhood)
@@ -28,11 +28,10 @@ class PartnerScopeTest < ActiveSupport::TestCase
# now we should see all the partners the user owns
found_partners = permitted_records(@normal_user, Partner)
- assert found_partners.count == 3
+ assert_equal(3, found_partners.count)
end
- test "scope on address" do # test_scope_for_address
-
+ test 'scope on address' do # test_scope_for_address
# give the user a neighbourhood to admin
neighbourhood = neighbourhoods(:one)
@normal_user.neighbourhoods << neighbourhood
@@ -47,10 +46,10 @@ class PartnerScopeTest < ActiveSupport::TestCase
# now we should get all the partners in this users neighbourhoods
found_partners = permitted_records(@normal_user, Partner)
- assert found_partners.count == 4
+ assert_equal(4, found_partners.count)
end
- test "scope on service areas" do # test_scope_for_service_areas
+ test 'scope on service areas' do # test_scope_for_service_areas
# give the user a neighbourhood to admin
neighbourhood = neighbourhoods(:one)
@normal_user.neighbourhoods << neighbourhood
@@ -67,7 +66,6 @@ class PartnerScopeTest < ActiveSupport::TestCase
# we should be able to see all the partners with service areas
# in the users' neighbourhoods
found_partners = permitted_records(@normal_user, Partner)
- assert found_partners.count == 5
+ assert_equal(5, found_partners.count)
end
end
-
diff --git a/test/support/email_helper.rb b/test/support/email_helper.rb
index 55007115b..2bf3b6bcf 100644
--- a/test/support/email_helper.rb
+++ b/test/support/email_helper.rb
@@ -1,5 +1,6 @@
-module EmailHelper
+# frozen_string_literal: true
+module EmailHelper
# get the last email sent by ActionMailer
#
# Returns
@@ -25,6 +26,6 @@ def extract_link_from(email)
body_text = html_body.decoded
end
- body_text =~ %r{ 'M15 5DD',
'quality' => 1,
'eastings' => 383_417,
- 'northings' => 395_997,
+ 'northings' => 395_997,
'country' => 'England',
'nhs_ha' => 'North West',
'longitude' => -2.251226,
@@ -86,8 +87,8 @@
{
'postcode' => 'M16 7BA',
'quality' => 1,
- 'eastings' => 383321,
- 'northings' => 395843,
+ 'eastings' => 383_321,
+ 'northings' => 395_843,
'country' => 'England',
'nhs_ha' => 'North West',
'longitude' => -2.252664,
diff --git a/test/system/admin/partner_test.rb b/test/system/admin/partner_test.rb
index 9b34d7c26..12ad4ac57 100644
--- a/test/system/admin/partner_test.rb
+++ b/test/system/admin/partner_test.rb
@@ -12,8 +12,8 @@ class AdminPartnerTest < ApplicationSystemTestCase
@partner = create :ashton_partner
@tag = create :tag
@tag_pub = create :tag_public
- @neighbourhood_one = neighbourhoods[1].to_s.gsub('w', 'W')
- @neighbourhood_two = neighbourhoods[2].to_s.gsub('w', 'W')
+ @neighbourhood_one = neighbourhoods[1].to_s.tr('w', 'W')
+ @neighbourhood_two = neighbourhoods[2].to_s.tr('w', 'W')
# logging in as root user
visit '/users/sign_in'
@@ -83,12 +83,12 @@ class AdminPartnerTest < ApplicationSystemTestCase
# check it's in the list
assert all(:css, '.list-group-item')[-1].text.starts_with?('Sunday all day')
# check it's added to the text area
- assert data.include?(new_time)
+ assert_includes data, new_time
# remove the event
all(:css, '.list-group-item')[-1].click_button('Remove')
data = find('[data-opening-times-target="textarea"]', visible: :hidden).value
# check time is removed from the text area
- assert !data.include?(new_time)
+ assert_not_includes data, new_time
end
end
diff --git a/test/system/admin/site_test.rb b/test/system/admin/site_test.rb
index cda1e3f19..7e91fcfc7 100644
--- a/test/system/admin/site_test.rb
+++ b/test/system/admin/site_test.rb
@@ -13,8 +13,8 @@ class AdminSiteTest < ApplicationSystemTestCase
@tag_pub = create :tag_public
@site = create :site
- @neighbourhood_one = neighbourhoods[1].to_s.gsub('w', 'W')
- @neighbourhood_two = neighbourhoods[2].to_s.gsub('w', 'W')
+ @neighbourhood_one = neighbourhoods[1].to_s.tr('w', 'W')
+ @neighbourhood_two = neighbourhoods[2].to_s.tr('w', 'W')
@sites_neighbourhood = create(:sites_neighbourhood,
site: @site,
@@ -80,7 +80,7 @@ class AdminSiteTest < ApplicationSystemTestCase
click_link @site.name
await_select2
service_areas = all_cocoon_select2_nodes 'sites_neighbourhoods'
- msg = '@site should only have a primary neighbourhood, if this fails either this is now rendering where it should\'t or another neighborhood has been added at setup and the test should be adjusted'
- assert service_areas.length.zero?, msg
+ msg = '@site should only have a primary neighbourhood, if this fails either this is now rendering where it should\'t or another neighborhood has been added at setup and the test should be adjusted'
+ assert_predicate service_areas.length, :zero?, msg
end
end
diff --git a/test/system/admin/user_test.rb b/test/system/admin/user_test.rb
index 036cf73f7..8b48b1fad 100644
--- a/test/system/admin/user_test.rb
+++ b/test/system/admin/user_test.rb
@@ -17,9 +17,9 @@ class AdminUserTest < ApplicationSystemTestCase
@tag = create :tag
@tag_pub = create :tag_public
-
- @neighbourhood_one = neighbourhoods[1].to_s.gsub('w', 'W')
- @neighbourhood_two = neighbourhoods[2].to_s.gsub('w', 'W')
+
+ @neighbourhood_one = neighbourhoods[1].to_s.tr('w', 'W')
+ @neighbourhood_two = neighbourhoods[2].to_s.tr('w', 'W')
# logging in as root user
visit '/users/sign_in'
diff --git a/test/system/application_system_test_case.rb b/test/system/application_system_test_case.rb
index cb4a6b456..3f2b4993d 100644
--- a/test/system/application_system_test_case.rb
+++ b/test/system/application_system_test_case.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'system_test_helper'
# For system tests so we can test our JS frontend is working
@@ -6,4 +8,3 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
Capybara.server = :puma, { Silent: true }
Selenium::WebDriver.logger.ignore(:browser_options)
end
-
diff --git a/test/system/collections_test.rb b/test/system/collections_test.rb
index 943ce4e97..45232f817 100644
--- a/test/system/collections_test.rb
+++ b/test/system/collections_test.rb
@@ -1,11 +1,12 @@
+# frozen_string_literal: true
## frozen_string_literal: true
#
-#require 'application_system_test_case'
+# require 'application_system_test_case'
#
-#class CollectionsTest < ApplicationSystemTestCase
+# class CollectionsTest < ApplicationSystemTestCase
# # test "visiting the index" do
# # visit collections_url
# #
# # assert_selector "h1", text: "Collection"
# # end
-#end
+# end
diff --git a/test/system/create_admin_users_test.rb b/test/system/create_admin_users_test.rb
index ddfce6c6a..05213462a 100644
--- a/test/system/create_admin_users_test.rb
+++ b/test/system/create_admin_users_test.rb
@@ -1,4 +1,6 @@
-require_relative "./application_system_test_case"
+# frozen_string_literal: true
+
+require_relative './application_system_test_case'
class CreateAdminUsersTest < ApplicationSystemTestCase
setup do
@@ -12,8 +14,7 @@ class CreateAdminUsersTest < ApplicationSystemTestCase
app_routes.default_url_options[:protocol] = 'http'
end
- test "visiting the index" do
-
+ test 'visiting the index' do
# set up
given_a_root_user_exists
given_the_default_site_exists
@@ -79,6 +80,6 @@ def last_email_delivered
def extract_invitation_link_from(email)
body = email.body.parts.first.body.raw_source
- body =~ /^(https?:\/\/.*)$/ && $1
+ body =~ %r{^(https?://.*)$} && Regexp.last_match(1)
end
end
diff --git a/test/system/graphql/graphql_test.rb b/test/system/graphql/graphql_test.rb
index 696c30e9e..590dc5ab2 100644
--- a/test/system/graphql/graphql_test.rb
+++ b/test/system/graphql/graphql_test.rb
@@ -1,29 +1,28 @@
-require_relative "../application_system_test_case"
-
-=begin
-
-This is basically a stand alone script that pokes the GraphQL endpoint
-running on the server through a network connection (just as how users
-will use the endpoint on staging/production). It does not use any
-internal code like /test/integration/graphql/*
-
-We could be being overly paranoid here but it may become useful for
-catching the kind of bugs that only show up on a real network
-connection.
-
-NOTE: we are mainly interested in testing the endpoints that
-the Trans Dimension elm app uses.
-=end
+# frozen_string_literal: true
+
+require_relative '../application_system_test_case'
+
+#
+# This is basically a stand alone script that pokes the GraphQL endpoint
+# running on the server through a network connection (just as how users
+# will use the endpoint on staging/production). It does not use any
+# internal code like /test/integration/graphql/*
+#
+# We could be being overly paranoid here but it may become useful for
+# catching the kind of bugs that only show up on a real network
+# connection.
+#
+# NOTE: we are mainly interested in testing the endpoints that
+# the Trans Dimension elm app uses.
require 'graphql/client'
require 'graphql/client/http'
-
module PlaceCalApi
extend self
PING_QUERY_STRING =
- "query { ping }"
+ 'query { ping }'
ARTICLE_CONNECTION_QUERY_STRING = <<-QUERY
query { articleConnection { edges {
@@ -51,9 +50,8 @@ module PlaceCalApi
} }
QUERY
-
def configure(default_url_options)
- @url = URI::HTTP::build(default_url_options)
+ @url = URI::HTTP.build(default_url_options)
@url.path = '/api/v1/graphql'
@http = GraphQL::Client::HTTP.new(@url.to_s)
@@ -77,18 +75,18 @@ def do_article_connection_query
end
def do_partners_by_tag_query(tag_id)
- @client.query PartnersByTagQuery, variables: { 'tagId': tag_id }
+ @client.query PartnersByTagQuery, variables: { tagId: tag_id }
end
private
def define_constant(name, value)
return if const_defined?(name)
+
const_set name, value
end
end
-
class GraphQLTest < ApplicationSystemTestCase
# This tests a number of small (critical) bits of the GraphQL
# system so its name is bit generic
@@ -111,11 +109,11 @@ class GraphQLTest < ApplicationSystemTestCase
PlaceCalApi.configure app_routes.default_url_options
end
- test "ping works" do
+ test 'ping works' do
result = PlaceCalApi.do_ping_query
- assert result.errors.empty?
+ assert_empty result.errors
assert result.data.ping =~ /^Hello World! The time is \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/,
- 'missing PING data response'
+ 'missing PING data response'
end
test 'news article connection with image url' do
@@ -145,4 +143,3 @@ class GraphQLTest < ApplicationSystemTestCase
assert url =~ %r{\Ahttps://#{@server.host}:#{@server.port}/}, 'partner logo is not full URL'
end
end
-
diff --git a/test/system_test_helper.rb b/test/system_test_helper.rb
index 87c03ac75..087541d02 100644
--- a/test/system_test_helper.rb
+++ b/test/system_test_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'test_helper'
Capybara.app_host = 'http://lvh.me'
@@ -14,10 +16,10 @@
)
Capybara::Selenium::Driver.new app,
- browser: :chrome,
- desired_capabilities: capabilities
+ browser: :chrome,
+ desired_capabilities: capabilities
end
-#Dir.glob(File.join(Rails.root, 'test/system/**/*.rb')) do |path|
+# Dir.glob(File.join(Rails.root, 'test/system/**/*.rb')) do |path|
# require path
-#end
+# end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index ae0f9c10d..317eaa2e1 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -21,10 +21,10 @@
JsonMatchers.schema_root = 'test/support/api/schemas'
include JsonMatchers::Minitest::Assertions
-require "capybara/rails"
-require "capybara/minitest"
+require 'capybara/rails'
+require 'capybara/minitest'
-Dir.glob(File.join(Rails.root, 'test/support/**/*.rb')) do |path|
+Dir.glob(File.join(Rails.root, 'test/support/**/*.rb')).sort.each do |path|
require path
end
@@ -114,7 +114,6 @@ def create_default_site
create(:site, slug: 'default-site')
end
-
# Some helpers for working with JS and Capybara
def click_sidebar(href)
@@ -159,7 +158,7 @@ def assert_select2_multiple(options_array, node)
# If we are left with nothing then the options and stored data match
within :xpath, node.path do
assert_selector '.select2-selection__choice', count: options_array.length
- rendered = find(:css, '.select2-selection__rendered').text.gsub('×', '').gsub("\n", '')
+ rendered = find(:css, '.select2-selection__rendered').text.delete('×').delete("\n")
options_array.each do |opt|
rendered = rendered.gsub(opt, '')
end
@@ -202,7 +201,7 @@ def assert_field(obj, key, message = nil)
def refute_field(obj, key, message = nil)
message ||= "Field '#{key}' exists in: #{obj}"
- refute obj.key?(key), message # obj.key? returns false if an item is nil, ergo...
+ assert_not obj.key?(key), message # obj.key? returns false if an item is nil, ergo...
obj[key]
end