From 04f518e6cc7ba2b69da37eef8b48c0bcc9a4d83c Mon Sep 17 00:00:00 2001 From: David Wessman Date: Sun, 17 Oct 2021 14:24:08 +0200 Subject: [PATCH 1/4] Adds standard formatter and linter --- .standard.yml | 1 + Gemfile | 1 + Gemfile.lock | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 .standard.yml diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 000000000..c406f5cf5 --- /dev/null +++ b/.standard.yml @@ -0,0 +1 @@ +ruby_version: 2.5.0 diff --git a/Gemfile b/Gemfile index fcbedb2ee..40040fa82 100644 --- a/Gemfile +++ b/Gemfile @@ -87,6 +87,7 @@ group :development do gem 'bullet' gem 'foreman' gem 'onesky-rails' + gem 'standard', '~> 1.4' gem 'web-console' end diff --git a/Gemfile.lock b/Gemfile.lock index 2176ce5f2..f29532438 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,6 +98,7 @@ GEM sshkit (>= 1.6.1, != 1.7.0) ansi (1.5.0) arel (8.0.0) + ast (2.4.2) autoprefixer-rails (9.4.9) execjs bcrypt (3.1.13) @@ -280,8 +281,11 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) + parallel (1.21.0) paranoia (2.4.1) activerecord (>= 4.0, < 5.3) + parser (3.0.2.0) + ast (~> 2.4.1) pdf-core (0.6.1) pg (0.21.0) poltergeist (1.18.1) @@ -340,6 +344,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) rake (12.3.3) rb-fsevent (0.10.3) rb-inotify (0.10.0) @@ -349,6 +354,7 @@ GEM redcarpet (3.4.0) redis (3.3.5) ref (2.0.0) + regexp_parser (2.1.1) request_store (1.4.1) rack (>= 1.4) responders (3.0.0) @@ -358,6 +364,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) netrc (~> 0.7) + rexml (3.2.5) roadie (3.3.0) css_parser (~> 1.4) nokogiri (~> 1.5) @@ -398,6 +405,21 @@ GEM rspec-support (3.7.1) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) + rubocop (1.22.3) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.12.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.12.0) + parser (>= 3.0.1.1) + rubocop-performance (1.11.5) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + ruby-progressbar (1.11.0) ruby_dep (1.5.0) rufus-scheduler (3.4.2) et-orbi (~> 1.0) @@ -445,6 +467,9 @@ GEM sshkit (1.19.1) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) + standard (1.4.0) + rubocop (= 1.22.3) + rubocop-performance (= 1.11.5) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) therubyracer (0.12.3) @@ -464,6 +489,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.2) + unicode-display_width (2.1.0) uniform_notifier (1.11.0) warden (1.2.8) rack (>= 2.0.6) @@ -554,6 +580,7 @@ DEPENDENCIES sidekiq-unique-jobs simple_form sitemap_generator + standard (~> 1.4) therubyracer turbolinks uglifier From bd42d4292a68282217e8dd50358d7f3738eee50c Mon Sep 17 00:00:00 2001 From: David Wessman Date: Sun, 17 Oct 2021 14:29:18 +0200 Subject: [PATCH 2/4] Run standard on all files --- Capfile | 26 +- Gemfile | 162 ++-- Rakefile | 2 +- app/channels/application_cable/connection.rb | 4 +- app/channels/groups_channel.rb | 16 +- .../admin/access_users_controller.rb | 2 +- .../adventure_mission_groups_controller.rb | 34 +- .../admin/adventure_missions_controller.rb | 12 +- .../admin/adventures_controller.rb | 16 +- app/controllers/admin/albums_controller.rb | 10 +- .../admin/blog_posts_controller.rb | 14 +- app/controllers/admin/cafe_controller.rb | 4 +- .../admin/cafe_shifts_controller.rb | 6 +- .../admin/cafe_workers_controller.rb | 13 +- app/controllers/admin/contacts_controller.rb | 2 +- app/controllers/admin/councils_controller.rb | 2 +- app/controllers/admin/documents_controller.rb | 8 +- app/controllers/admin/doors_controller.rb | 2 +- app/controllers/admin/elections_controller.rb | 18 +- .../admin/event_signups_controller.rb | 16 +- app/controllers/admin/events_controller.rb | 20 +- app/controllers/admin/groups_controller.rb | 8 +- app/controllers/admin/images_controller.rb | 4 +- .../admin/introductions_controller.rb | 2 +- app/controllers/admin/keys_controller.rb | 6 +- .../admin/mail_aliases_controller.rb | 27 +- app/controllers/admin/meetings_controller.rb | 16 +- app/controllers/admin/menus_controller.rb | 10 +- app/controllers/admin/messages_controller.rb | 10 +- app/controllers/admin/news_controller.rb | 12 +- .../admin/page_elements_controller.rb | 8 +- app/controllers/admin/pages_controller.rb | 2 +- .../admin/permissions_controller.rb | 1 - app/controllers/admin/posts_controller.rb | 28 +- app/controllers/admin/rents_controller.rb | 8 +- app/controllers/admin/songs_controller.rb | 2 +- app/controllers/admin/tools_controller.rb | 2 +- .../admin/work_posts_controller.rb | 20 +- .../adventure_mission_groups_controller.rb | 12 +- .../adventure_missions_controller.rb | 2 +- app/controllers/adventures_controller.rb | 4 +- .../api/achievements_controller.rb | 2 +- .../adventure_mission_groups_controller.rb | 4 +- .../api/adventure_missions_controller.rb | 28 +- app/controllers/api/adventures_controller.rb | 16 +- app/controllers/api/base_controller.rb | 2 +- app/controllers/api/cafe_controller.rb | 4 +- app/controllers/api/contacts_controller.rb | 2 +- app/controllers/api/event_users_controller.rb | 6 +- app/controllers/api/events_controller.rb | 8 +- .../api/fredmanskies_controller.rb | 4 +- app/controllers/api/gallery_controller.rb | 2 +- app/controllers/api/groups_controller.rb | 4 +- app/controllers/api/messages_controller.rb | 8 +- .../api/notifications_controller.rb | 10 +- .../api/push_devices_controller.rb | 4 +- app/controllers/api/songs_controller.rb | 10 +- app/controllers/api/start_controller.rb | 8 +- app/controllers/api/users_controller.rb | 10 +- app/controllers/application_controller.rb | 32 +- app/controllers/cafe_controller.rb | 12 +- app/controllers/cafe_shifts_controller.rb | 6 +- app/controllers/cafe_workers_controller.rb | 19 +- app/controllers/calendars_controller.rb | 4 +- app/controllers/concerns/alerts.rb | 18 +- .../concerns/controller_authorization.rb | 4 +- app/controllers/contacts_controller.rb | 16 +- app/controllers/documents_controller.rb | 16 +- .../elections/candidates_controller.rb | 7 +- .../elections/nominations_controller.rb | 3 +- app/controllers/elections_controller.rb | 22 +- app/controllers/gallery/albums_controller.rb | 2 +- app/controllers/groups_controller.rb | 4 +- app/controllers/introductions_controller.rb | 18 +- app/controllers/meetings_controller.rb | 4 +- app/controllers/messages_controller.rb | 14 +- app/controllers/notifications_controller.rb | 6 +- app/controllers/pages_controller.rb | 15 +- app/controllers/posts_controller.rb | 3 +- app/controllers/proposals_controller.rb | 2 +- app/controllers/registrations_controller.rb | 2 +- app/controllers/rents_controller.rb | 6 +- app/controllers/short_links_controller.rb | 3 +- app/controllers/songs_controller.rb | 2 +- app/controllers/static_pages_controller.rb | 2 +- app/controllers/users_controller.rb | 18 +- app/helpers/admin/event_signups_helper.rb | 58 +- app/helpers/admin/pages_helper.rb | 4 +- app/helpers/adventure_helper.rb | 2 +- app/helpers/application_helper.rb | 22 +- app/helpers/blog_posts_helper.rb | 14 +- app/helpers/cafe_helper.rb | 23 +- app/helpers/categories_helper.rb | 22 +- app/helpers/contact_helper.rb | 8 +- app/helpers/documents_helper.rb | 3 +- app/helpers/election_helper.rb | 22 +- app/helpers/election_mailer_helper.rb | 2 +- app/helpers/email_helper.rb | 8 +- app/helpers/event_helper.rb | 76 +- app/helpers/group_helper.rb | 42 +- app/helpers/introduction_helper.rb | 4 +- app/helpers/link_helper.rb | 2 +- app/helpers/markdown_helper.rb | 24 +- app/helpers/meeting_helper.rb | 12 +- app/helpers/meeting_mailer_helper.rb | 8 +- app/helpers/menu_helper.rb | 10 +- app/helpers/message_helper.rb | 16 +- app/helpers/meta_tags_helper.rb | 12 +- app/helpers/news_helper.rb | 4 +- app/helpers/notification_helper.rb | 27 +- app/helpers/post_helper.rb | 26 +- app/helpers/rent_mailer_helper.rb | 10 +- app/helpers/time_helper.rb | 3 +- app/helpers/tool_helper.rb | 10 +- app/helpers/users_helper.rb | 10 +- app/helpers/work_post_helper.rb | 8 +- app/inputs/date_picker_input.rb | 18 +- app/inputs/datetime_picker_input.rb | 8 +- app/inputs/pagedown_input.rb | 2 +- app/inputs/time_picker_input.rb | 4 +- app/mailers/application_mailer.rb | 6 +- app/mailers/cafe_mailer.rb | 6 +- app/mailers/contact_mailer.rb | 4 +- app/mailers/election_mailer.rb | 6 +- app/mailers/meeting_mailer.rb | 18 +- app/mailers/notification_mailer.rb | 4 +- app/mailers/rent_mailer.rb | 14 +- app/mailers/tool_renting_mailer.rb | 6 +- app/models/ability.rb | 6 +- app/models/access.rb | 2 +- app/models/adventures/adventure.rb | 12 +- app/models/adventures/adventure_mission.rb | 4 +- .../adventures/adventure_mission_group.rb | 4 +- app/models/album.rb | 14 +- app/models/blog_post.rb | 10 +- app/models/cafes/cafe_shift.rb | 12 +- app/models/cafes/cafe_worker.rb | 10 +- app/models/cafes/cafe_worker_council.rb | 2 +- app/models/candidate.rb | 10 +- app/models/cars/car_ban.rb | 2 +- app/models/cars/rent.rb | 18 +- app/models/categorization.rb | 8 +- app/models/category.rb | 30 +- app/models/concerns/categorizable.rb | 2 +- app/models/connected_list.rb | 2 +- app/models/constant.rb | 2 +- app/models/contacts/contact.rb | 6 +- app/models/council.rb | 2 +- app/models/document.rb | 12 +- app/models/elections/election.rb | 14 +- app/models/elections/election_post.rb | 2 +- app/models/events/event.rb | 34 +- app/models/events/event_signup.rb | 32 +- app/models/events/event_user.rb | 20 +- app/models/faq.rb | 10 +- app/models/fredmansky/fredmansky_data.rb | 10 +- app/models/groups/group.rb | 16 +- app/models/groups/group_message.rb | 4 +- app/models/groups/group_user.rb | 24 +- app/models/image.rb | 2 +- app/models/introduction.rb | 16 +- app/models/keys/key.rb | 12 +- app/models/mail_alias.rb | 44 +- app/models/main_menu.rb | 2 +- app/models/meeting.rb | 26 +- app/models/menu.rb | 2 +- app/models/messages/message.rb | 6 +- app/models/messages/message_data.rb | 6 +- app/models/messages/message_token.rb | 4 +- app/models/news.rb | 10 +- app/models/nomination.rb | 10 +- app/models/notifications/notification.rb | 8 +- app/models/notifications/notification_data.rb | 48 +- app/models/pages/page.rb | 18 +- app/models/pages/page_element.rb | 6 +- app/models/permissions/permission.rb | 2 +- app/models/posts/post.rb | 22 +- app/models/posts/post_user.rb | 4 +- app/models/push_device.rb | 4 +- app/models/recurring_meeting.rb | 2 +- app/models/short_link.rb | 14 +- app/models/song.rb | 2 +- app/models/tools/tool.rb | 4 +- app/models/tools/tool_renting.rb | 4 +- app/models/user.rb | 38 +- app/models/work_post.rb | 14 +- app/query_objects/adventure_queries.rb | 10 +- app/query_objects/album_queries.rb | 8 +- app/query_objects/cafe_queries.rb | 62 +- app/renderers/message_renderer.rb | 2 +- .../api/adventure_mission_serializer.rb | 2 +- app/serializers/api/adventure_serializer.rb | 10 +- app/serializers/api/contacts_serializer.rb | 4 +- app/serializers/api/event_serializer.rb | 2 +- .../api/notification_serializer.rb | 2 +- app/serializers/api/song_serializer.rb | 1 - app/serializers/event_serializer.rb | 4 +- app/serializers/message_serializer.rb | 4 +- app/services/adventure_mission_service.rb | 24 +- app/services/adventure_service.rb | 2 +- app/services/album_service.rb | 2 +- app/services/cafe_service.rb | 61 +- app/services/calendar_json.rb | 42 +- app/services/calendar_service.rb | 18 +- app/services/export_csv.rb | 20 +- app/services/meeting_service.rb | 40 +- app/services/notification_service.rb | 2 +- app/services/post_user_service.rb | 2 +- app/services/push_service.rb | 14 +- app/services/rent_service.rb | 114 ++- app/services/tool_renting_service.rb | 2 +- app/uploaders/base_image_uploader.rb | 2 +- app/uploaders/document_uploader.rb | 2 +- app/uploaders/image_uploader.rb | 2 +- app/uploaders/watermarker.rb | 8 +- app/validators/contact_message_validator.rb | 2 +- app/validators/rent_validator.rb | 16 +- app/view_objects/cafe_competition.rb | 14 +- app/view_objects/document_view.rb | 2 +- app/view_objects/election_view.rb | 14 +- app/view_objects/start_page.rb | 2 +- app/view_objects/work_portal.rb | 28 +- .../event_signup_closing_reminder_worker.rb | 2 +- .../event_signup_open_reminder_worker.rb | 2 +- app/workers/event_signup_position_worker.rb | 2 +- app/workers/event_signup_reminder_worker.rb | 2 +- config.ru | 2 +- config/application.rb | 21 +- config/boot.rb | 4 +- config/deploy.rb | 30 +- config/deploy/dev.rb | 12 +- config/deploy/production.rb | 14 +- config/deploy/staging.rb | 10 +- config/environment.rb | 2 +- config/environments/development.rb | 17 +- config/environments/production.rb | 18 +- config/environments/staging.rb | 18 +- config/environments/test.rb | 8 +- config/initializers/action_cable_config.rb | 8 +- config/initializers/assets.rb | 6 +- config/initializers/devise.rb | 9 +- config/initializers/devise_token_auth.rb | 4 +- .../initializers/filter_parameter_logging.rb | 2 +- config/initializers/mime_types.rb | 2 +- config/initializers/new_framework_defaults.rb | 2 +- config/initializers/paperclip_defaults.rb | 6 +- .../initializers/ranged_datetime_wrapper.rb | 12 +- config/initializers/rollbar.rb | 8 +- config/initializers/rpush.rb | 9 +- config/initializers/session_store.rb | 2 +- config/initializers/sidekiq.rb | 4 +- config/initializers/simple_form.rb | 20 +- config/initializers/simple_form_bootstrap.rb | 112 +-- config/initializers/wice_grid_config.rb | 33 +- config/puma.rb | 2 +- config/routes.rb | 84 +- config/sitemap.rb | 2 +- config/spring.rb | 4 +- db/migrate/20160831154400_init_schema.rb | 761 +++++++++--------- ...0160904223300_change_event_signup_index.rb | 4 +- ...20160922115838_add_use_case_to_category.rb | 2 +- ...23132346_add_translations_to_categories.rb | 2 +- db/migrate/20160923170248_squasher_clean.rb | 2 +- db/migrate/20170123191137_add_meetings.rb | 2 +- ...0227195000_add_translations_to_election.rb | 4 +- db/migrate/20170621104453_add_rpush.rb | 134 ++- .../20170621104454_rpush_2_0_0_updates.rb | 14 +- .../20170621104456_rpush_2_6_0_updates.rb | 1 - .../20170621104457_rpush_2_7_0_updates.rb | 1 - ...20170823124500_add_translations_to_post.rb | 2 +- ...70823132130_add_translations_to_council.rb | 2 +- db/migrate/20180220003700_migrate_cafe.rb | 2 +- .../20180402140721_rpush_3_0_0_updates.rb | 2 +- ..._add_translations_to_adventure_missions.rb | 2 +- ..._constraint_to_adventure_mission_groups.rb | 8 +- ...01800_swap_song_category_to_association.rb | 6 +- db/seeds.rb | 74 +- lib/constraints/sidekiq.rb | 2 +- lib/route_prefixes.rb | 8 +- lib/tasks/event_signup_data.rake | 42 +- lib/tasks/introduction_events.rake | 22 +- lib/tasks/permissions.rake | 74 +- lib/tasks/promote_admin.rake | 16 +- lib/tasks/tests_data.rake | 202 ++--- old/import_old_albums.rb | 67 +- .../admin/albums_controller_spec.rb | 88 +- .../admin/blog_posts_controller_spec.rb | 64 +- .../controllers/admin/cafe_controller_spec.rb | 10 +- .../admin/cafe_shifts_controller_spec.rb | 106 +-- .../admin/cafe_workers_controller_spec.rb | 64 +- .../admin/categories_controller_spec.rb | 58 +- .../admin/constants_controller_spec.rb | 12 +- .../admin/contacts_controller_spec.rb | 66 +- .../admin/councils_controller_spec.rb | 66 +- .../admin/documents_controller_spec.rb | 58 +- .../admin/doors_controller_spec.rb | 64 +- .../admin/elections_controller_spec.rb | 16 +- .../admin/event_signups_controller_spec.rb | 14 +- .../admin/events_controller_spec.rb | 66 +- .../controllers/admin/faqs_controller_spec.rb | 66 +- .../admin/groups_controller_spec.rb | 54 +- .../admin/introductions_controller_spec.rb | 64 +- .../admin/mail_aliases_controller_spec.rb | 24 +- .../admin/menus_controller_spec.rb | 70 +- .../controllers/admin/news_controller_spec.rb | 34 +- .../admin/page_elements_controller_spec.rb | 76 +- .../admin/pages_controller_spec.rb | 82 +- .../admin/permissions_controller_spec.rb | 40 +- .../admin/posts_controller_spec.rb | 78 +- .../admin/rents_controller_spec.rb | 52 +- .../admin/short_links_controller_spec.rb | 28 +- .../admin/tool_rentings_controller_spec.rb | 42 +- .../admin/tools_controller_spec.rb | 70 +- .../admin/users_controller_spec.rb | 2 +- .../admin/work_posts_controller_spec.rb | 70 +- .../controllers/blog_posts_controller_spec.rb | 42 +- spec/controllers/cafe_controller_spec.rb | 24 +- .../cafe_shifts_controller_spec.rb | 26 +- .../cafe_workers_controller_spec.rb | 62 +- spec/controllers/calendar_controller_spec.rb | 76 +- spec/controllers/concerns/alerts_spec.rb | 38 +- .../concerns/controller_authorization_spec.rb | 10 +- .../concerns/instance_authorization_spec.rb | 42 +- spec/controllers/contacts_controller_spec.rb | 42 +- spec/controllers/councils_controller_spec.rb | 25 +- spec/controllers/documents_controller_spec.rb | 18 +- .../elections/candidates_controller_spec.rb | 36 +- .../elections/nominations_controller_spec.rb | 36 +- spec/controllers/elections_controller_spec.rb | 10 +- .../event_users_controller_spec.rb | 56 +- spec/controllers/faqs_controller_spec.rb | 28 +- .../gallery/albums_controller_spec.rb | 12 +- .../gallery/gallery_controller_spec.rb | 22 +- spec/controllers/groups_controller_spec.rb | 10 +- .../introductions_controller_spec.rb | 94 +-- spec/controllers/meetings_controller_spec.rb | 88 +- spec/controllers/news_controller_spec.rb | 6 +- .../notfications_controller_spec.rb | 16 +- spec/controllers/pages_controller_spec.rb | 20 +- spec/controllers/posts_controller_spec.rb | 24 +- spec/controllers/proposals_controller_spec.rb | 11 +- spec/controllers/rents_controller_spec.rb | 72 +- .../short_links_controller_spec.rb | 28 +- .../static_pages_controller_spec.rb | 22 +- spec/controllers/tools_controller_spec.rb | 12 +- spec/controllers/users_controller_spec.rb | 60 +- .../controllers/work_posts_controller_spec.rb | 22 +- spec/factories/albums.rb | 1 - spec/factories/cafe_shifts.rb | 3 +- spec/factories/constants.rb | 1 - spec/factories/contact_messages.rb | 5 +- spec/factories/contacts.rb | 3 +- spec/factories/councils.rb | 1 - spec/factories/documents.rb | 5 +- spec/factories/event_signups.rb | 2 +- spec/factories/faq.rb | 3 +- spec/factories/images.rb | 3 +- spec/factories/mail_aliases.rb | 7 +- spec/factories/news.rb | 3 +- spec/factories/notifications.rb | 2 +- spec/factories/page_elements.rb | 1 - spec/factories/page_images.rb | 2 +- spec/factories/pages.rb | 1 - spec/factories/permissions.rb | 6 +- spec/factories/posts.rb | 1 - spec/factories/rents.rb | 10 +- spec/factories/shared.rb | 6 +- spec/factories/short_links.rb | 5 +- spec/factories/tool_rentings.rb | 2 +- spec/factories/tools.rb | 2 +- spec/factories/users.rb | 16 +- spec/factories/work_posts.rb | 11 +- spec/features/admin/visit_spec.rb | 6 +- spec/features/cafe_shift_spec.rb | 14 +- spec/features/contacts_spec.rb | 22 +- spec/features/election/candidate_spec.rb | 16 +- spec/features/election/election_spec.rb | 22 +- spec/features/election/nomination_spec.rb | 20 +- spec/features/groups_spec.rb | 24 +- spec/features/introductions_spec.rb | 16 +- spec/features/messages_spec.rb | 8 +- spec/features/pages_spec.rb | 12 +- spec/features/user/account_spec.rb | 48 +- spec/features/user/confirm_account_spec.rb | 8 +- spec/features/user/log_in_spec.rb | 56 +- spec/features/user/reset_password_spec.rb | 8 +- spec/features/user/sign_up_spec.rb | 20 +- spec/features/visit_spec.rb | 6 +- spec/features/visitor_visit_spec.rb | 6 +- spec/helpers/contact_helper_spec.rb | 24 +- spec/helpers/election_mailer_helper_spec.rb | 22 +- spec/helpers/event_helper_spec.rb | 40 +- spec/helpers/markdown_helper_spec.rb | 38 +- spec/helpers/posts_helper_spec.rb | 20 +- spec/helpers/time_helper_spec.rb | 76 +- spec/lib/tasks/promote_admin_spec.rb | 8 +- spec/mailers/application_mailer_spec.rb | 10 +- spec/mailers/contact_mailer_spec.rb | 34 +- spec/mailers/election_mailer_spec.rb | 66 +- spec/mailers/meeting_mailer_spec.rb | 38 +- spec/mailers/rent_mailer_spec.rb | 84 +- spec/models/ability_spec.rb | 140 ++-- spec/models/access_spec.rb | 8 +- spec/models/album_spec.rb | 6 +- spec/models/blog_post_spec.rb | 12 +- spec/models/cafe_shift_spec.rb | 24 +- spec/models/cafe_worker_spec.rb | 8 +- spec/models/candidate_spec.rb | 20 +- spec/models/category_spec.rb | 28 +- spec/models/constant_spec.rb | 14 +- spec/models/contact_spec.rb | 2 +- spec/models/document_spec.rb | 10 +- spec/models/door_spec.rb | 4 +- spec/models/election_post_spec.rb | 6 +- spec/models/election_spec.rb | 76 +- spec/models/event_signup_spec.rb | 34 +- spec/models/event_spec.rb | 40 +- spec/models/event_user_spec.rb | 32 +- spec/models/image_spec.rb | 12 +- spec/models/introduction_spec.rb | 12 +- spec/models/mail_alias_spec.rb | 74 +- spec/models/meeting_spec.rb | 34 +- spec/models/message_spec.rb | 26 +- spec/models/news_spec.rb | 4 +- spec/models/nomination_spec.rb | 18 +- spec/models/notification_spec.rb | 4 +- spec/models/page_element_spec.rb | 24 +- spec/models/page_image_spec.rb | 12 +- spec/models/page_spec.rb | 54 +- spec/models/permission_post_spec.rb | 2 +- spec/models/permission_spec.rb | 2 +- spec/models/post_spec.rb | 18 +- spec/models/post_user_spec.rb | 16 +- spec/models/rent_spec.rb | 98 +-- spec/models/short_link_spec.rb | 42 +- spec/models/tool_renting_spec.rb | 16 +- spec/models/tool_spec.rb | 17 +- spec/models/user_spec.rb | 54 +- spec/query_objects/cafe_queries_spec.rb | 32 +- spec/rails_helper.rb | 18 +- spec/requests/api/authorization_spec.rb | 68 +- spec/services/cafe_service_spec.rb | 10 +- spec/services/calendar_service_spec.rb | 54 +- spec/services/election_service_spec.rb | 24 +- spec/services/page_service_spec.rb | 8 +- spec/services/post_user_service_spec.rb | 2 +- spec/services/rent_service_spec.rb | 50 +- spec/spec_helper.rb | 2 +- spec/support/cancan_matchers.rb | 34 +- spec/support/capybara.rb | 6 +- spec/support/database_cleaner.rb | 2 +- spec/support/factory_girl.rb | 2 +- spec/support/feature_macros.rb | 2 +- spec/support/shared_context/rake.rb | 10 +- spec/support/simplecov.rb | 6 +- spec/uploaders/document_uploader_spec.rb | 12 +- spec/uploaders/image_uploader_spec.rb | 14 +- .../contact_message_validator_spec.rb | 28 +- spec/view_objects/cafe_competition_spec.rb | 24 +- spec/view_objects/start_page_spec.rb | 40 +- spec/view_objects/work_portal_spec.rb | 86 +- 461 files changed, 4882 insertions(+), 4941 deletions(-) diff --git a/Capfile b/Capfile index aa5605bbf..eb2d32315 100644 --- a/Capfile +++ b/Capfile @@ -1,23 +1,23 @@ # Load DSL and Setup Up Stages -require 'capistrano/setup' +require "capistrano/setup" # Includes default deployment tasks -require 'capistrano/deploy' +require "capistrano/deploy" -require 'capistrano/rbenv' +require "capistrano/rbenv" set :rbenv_type, :user # or :system, depends on your rbenv setup # Do not forget to update in .ruby-version, circle.yml and Gemfile -set :rbenv_ruby, '2.5.0' +set :rbenv_ruby, "2.5.0" -require 'capistrano/bundler' -require 'capistrano/rails/assets' -require 'capistrano/rails/migrations' -require 'capistrano/passenger' -require 'capistrano/sitemap_generator' -require 'rollbar/capistrano3' -require 'capistrano/scm/git' - install_plugin Capistrano::SCM::Git +require "capistrano/bundler" +require "capistrano/rails/assets" +require "capistrano/rails/migrations" +require "capistrano/passenger" +require "capistrano/sitemap_generator" +require "rollbar/capistrano3" +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. -Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } +Dir.glob("lib/capistrano/tasks/*.cap").each { |r| import r } diff --git a/Gemfile b/Gemfile index 40040fa82..3476d3679 100644 --- a/Gemfile +++ b/Gemfile @@ -1,100 +1,100 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Do not forget to update in .ruby-version, Capfile and circle.yml -ruby '2.5.0' +ruby "2.5.0" -gem 'rails', '5.1.6.2' +gem "rails", "5.1.6.2" -gem 'active_model_serializers', '~> 0.10.0' -gem 'bcrypt_pbkdf', '~> 1.1.0.rc1' -gem 'bootstrap-sass' -gem 'bootstrap-datepicker-rails' -gem 'cancancan' -gem 'carrierwave', '~> 0.11.2' -gem 'carrierwave_backgrounder', git: 'https://github.com/lardawge/carrierwave_backgrounder' -gem 'cookies_eu' -gem 'datetimepicker-rails', git: 'https://github.com/zpaulovics/datetimepicker-rails', - branch: 'master', +gem "active_model_serializers", "~> 0.10.0" +gem "bcrypt_pbkdf", "~> 1.1.0.rc1" +gem "bootstrap-sass" +gem "bootstrap-datepicker-rails" +gem "cancancan" +gem "carrierwave", "~> 0.11.2" +gem "carrierwave_backgrounder", git: "https://github.com/lardawge/carrierwave_backgrounder" +gem "cookies_eu" +gem "datetimepicker-rails", git: "https://github.com/zpaulovics/datetimepicker-rails", + branch: "master", submodules: true -gem 'devise', '~> 4.7.1' -gem 'devise_token_auth', '~> 1.1.3' -gem 'ed25519', '~> 1.2', '>= 1.2.4' -gem 'ejs' -gem 'font-awesome-sass', '~> 5.6.1' -gem 'fotoramajs' -gem 'fullcalendar-rails' -gem 'globalize', git: 'https://github.com/globalize/globalize' # For rails 5.1 support -gem 'activemodel-serializers-xml' -gem 'globalize-accessors' -gem 'icalendar' -gem 'jquery-rails' -gem 'jquery-turbolinks' -gem 'jquery-ui-rails' -gem 'kaminari' -gem 'meta-tags' -gem 'mail', '>= 2.6.6.rc1' -gem 'mini_magick' -gem 'momentjs-rails' -gem 'nokogiri', '>=1.7' -gem 'pg' -gem 'paperclip', '>= 5.2.0' -gem 'pagedown-bootstrap-rails' -gem 'paranoia' -gem 'prawn-rails' -gem 'recaptcha', require: 'recaptcha/rails' -gem 'redcarpet' -gem 'redis', '< 4' -gem 'roadie-rails', '~> 1.3' -gem 'rollbar' -gem 'rpush' -gem 'routing-filter', '~> 0.6.2' -gem 'sassc-rails' -gem 'select2-rails' -gem 'sidekiq' -gem 'sidekiq-cron' -gem 'sidekiq-unique-jobs' -gem 'simple_form' -gem 'sitemap_generator' -gem 'turbolinks' -gem 'uglifier' -gem 'wice_grid', git: 'https://github.com/navro/wice_grid', branch: 'rails51' +gem "devise", "~> 4.7.1" +gem "devise_token_auth", "~> 1.1.3" +gem "ed25519", "~> 1.2", ">= 1.2.4" +gem "ejs" +gem "font-awesome-sass", "~> 5.6.1" +gem "fotoramajs" +gem "fullcalendar-rails" +gem "globalize", git: "https://github.com/globalize/globalize" # For rails 5.1 support +gem "activemodel-serializers-xml" +gem "globalize-accessors" +gem "icalendar" +gem "jquery-rails" +gem "jquery-turbolinks" +gem "jquery-ui-rails" +gem "kaminari" +gem "meta-tags" +gem "mail", ">= 2.6.6.rc1" +gem "mini_magick" +gem "momentjs-rails" +gem "nokogiri", ">=1.7" +gem "pg" +gem "paperclip", ">= 5.2.0" +gem "pagedown-bootstrap-rails" +gem "paranoia" +gem "prawn-rails" +gem "recaptcha", require: "recaptcha/rails" +gem "redcarpet" +gem "redis", "< 4" +gem "roadie-rails", "~> 1.3" +gem "rollbar" +gem "rpush" +gem "routing-filter", "~> 0.6.2" +gem "sassc-rails" +gem "select2-rails" +gem "sidekiq" +gem "sidekiq-cron" +gem "sidekiq-unique-jobs" +gem "simple_form" +gem "sitemap_generator" +gem "turbolinks" +gem "uglifier" +gem "wice_grid", git: "https://github.com/navro/wice_grid", branch: "rails51" # To have a working JVM on server group :staging, :production do - gem 'therubyracer', platform: :ruby + gem "therubyracer", platform: :ruby end group :development, :test do - gem 'better_errors', git: 'https://github.com/charliesome/better_errors' # For rails 5 support - gem 'capistrano', require: false + gem "better_errors", git: "https://github.com/charliesome/better_errors" # For rails 5 support + gem "capistrano", require: false # Need 1.1.3 to load sprockets manifest file - gem 'capistrano-rails', require: false - gem 'capistrano-rbenv', require: false - gem 'capistrano-passenger', '>= 0.2.1', require: false - gem 'capybara' - gem 'factory_bot_rails' - gem 'dotenv-rails' - gem 'listen' - gem 'poltergeist' - gem 'pry-byebug' - gem 'pry-rails' - gem 'puma' - gem 'rspec-example_steps' - gem 'rspec-rails' + gem "capistrano-rails", require: false + gem "capistrano-rbenv", require: false + gem "capistrano-passenger", ">= 0.2.1", require: false + gem "capybara" + gem "factory_bot_rails" + gem "dotenv-rails" + gem "listen" + gem "poltergeist" + gem "pry-byebug" + gem "pry-rails" + gem "puma" + gem "rspec-example_steps" + gem "rspec-rails" end group :development do - gem 'bullet' - gem 'foreman' - gem 'onesky-rails' - gem 'standard', '~> 1.4' - gem 'web-console' + gem "bullet" + gem "foreman" + gem "onesky-rails" + gem "standard", "~> 1.4" + gem "web-console" end group :test do - gem 'codeclimate-test-reporter', require: false - gem 'database_cleaner' - gem 'shoulda-matchers', require: false - gem 'rails-controller-testing' - gem 'rspec_junit_formatter' + gem "codeclimate-test-reporter", require: false + gem "database_cleaner" + gem "shoulda-matchers", require: false + gem "rails-controller-testing" + gem "rspec_junit_formatter" end diff --git a/Rakefile b/Rakefile index 2aad0099a..43f52ba4d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require File.expand_path("../config/application", __FILE__) Fsek::Application.load_tasks diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index c8b804baf..fd93042f4 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -4,7 +4,7 @@ class Connection < ActionCable::Connection::Base def connect self.current_user = find_verified_user - logger.add_tags 'ActionCable', current_user.email + logger.add_tags "ActionCable", current_user.email end def ability @@ -14,7 +14,7 @@ def ability protected def find_verified_user - cookie_user = env['warden'].user + cookie_user = env["warden"].user token = request.params[:token] if cookie_user.present? diff --git a/app/channels/groups_channel.rb b/app/channels/groups_channel.rb index f6d8b579a..9ba283234 100644 --- a/app/channels/groups_channel.rb +++ b/app/channels/groups_channel.rb @@ -1,37 +1,37 @@ class GroupsChannel < ApplicationCable::Channel def subscribed - group = Group.find(params['group_id']) + group = Group.find(params["group_id"]) if ability.can?(:show, group) - stream_from "groups_#{params['group_id']}_channel" + stream_from "groups_#{params["group_id"]}_channel" ConnectedList.add(current_user.id, group.id) end end def unsubscribed - ConnectedList.remove(current_user.id, params['group_id']) + ConnectedList.remove(current_user.id, params["group_id"]) end def send_message(data) - group = Group.find(data['group_id']) + group = Group.find(data["group_id"]) return unless ability.can?(:show, group) && !group.info? - params = { content: data['content'] } + params = {content: data["content"]} MessageService.create_message(params, [group], current_user) end def destroy_message(data) - message = Message.find(data['message_id']) + message = Message.find(data["message_id"]) return unless ability.can?(:destroy, message) MessageService.destroy_message(message) end def update_message(data) - message = Message.find(data['message_id']) + message = Message.find(data["message_id"]) return unless ability.can?(:update, message) - message.update!(content: data['content']) + message.update!(content: data["content"]) MessageService.broadcast_update(message) end end diff --git a/app/controllers/admin/access_users_controller.rb b/app/controllers/admin/access_users_controller.rb index 9f0f97133..2b3756a45 100644 --- a/app/controllers/admin/access_users_controller.rb +++ b/app/controllers/admin/access_users_controller.rb @@ -23,7 +23,7 @@ def update redirect_to(admin_access_users_path, notice: alert_update(AccessUser)) else redirect_to(edit_admin_access_user_path(@access_user), - notice: alert_danger(@access_user.errors.full_messages)) + notice: alert_danger(@access_user.errors.full_messages)) end end diff --git a/app/controllers/admin/adventure_mission_groups_controller.rb b/app/controllers/admin/adventure_mission_groups_controller.rb index 244bcfdcc..da3a82a9c 100644 --- a/app/controllers/admin/adventure_mission_groups_controller.rb +++ b/app/controllers/admin/adventure_mission_groups_controller.rb @@ -1,17 +1,17 @@ class Admin::AdventureMissionGroupsController < Admin::BaseController load_permissions_and_authorize_resource - load_and_authorize_resource :adventure, :except => [:update] - load_and_authorize_resource :group, :only => [:index] + load_and_authorize_resource :adventure, except: [:update] + load_and_authorize_resource :group, only: [:index] def index adventure_mission_groups_pending = @adventure.adventure_mission_groups.where(pending: true) adventure_mission_groups_accepted = @adventure.adventure_mission_groups.where(pending: false) @grid_pending = initialize_grid(adventure_mission_groups_pending, - include: [:group, :adventure_mission], - per_page: 30) + include: [:group, :adventure_mission], + per_page: 30) @grid_accepted = initialize_grid(adventure_mission_groups_accepted, - include: [:group, :adventure_mission], - per_page: 30) + include: [:group, :adventure_mission], + per_page: 30) end def edit @@ -21,27 +21,27 @@ def edit def update # No validation here since there are admins doing this @adventure_mission_group.points = adventure_mission_group_params[:points] - if adventure_mission_group_params[:pending].nil? - @adventure_mission_group.pending = false + @adventure_mission_group.pending = if adventure_mission_group_params[:pending].nil? + false else - @adventure_mission_group.pending = adventure_mission_group_params[:pending] + adventure_mission_group_params[:pending] end if @adventure_mission_group.save(validate: false) redirect_to admin_group_adventures_path(group_id: @adventure_mission_group.group.id), - notice: alert_success(t('.success')) + notice: alert_success(t(".success")) else redirect_to edit_admin_adventure_mission_group_path(group: @group), - alert: alert_errors(@adventure_mission_group.errors.full_messages) + alert: alert_errors(@adventure_mission_group.errors.full_messages) end end def destroy @group = @adventure_mission_group.group if @adventure_mission_group.destroy - redirect_to admin_group_adventures_path(@group), notice: alert_success(t('.success')) + redirect_to admin_group_adventures_path(@group), notice: alert_success(t(".success")) else redirect_to edit_admin_group_adventure_mission_group_path(@group, @adventure_mission_group), - alert: alert_errors(@adventure_mission_group.errors.full_messages) + alert: alert_errors(@adventure_mission_group.errors.full_messages) end end @@ -49,10 +49,10 @@ def accept @adventure_mission_group = AdventureMissionGroup.find(params[:adventure_mission_group_id]) if @adventure_mission_group.update_attribute(:pending, false) redirect_to admin_adventure_adventure_mission_groups_path(@adventure), - notice: alert_success(t('.success')) + notice: alert_success(t(".success")) else redirect_to admin_adventure_adventure_mission_groups_path(@adventure), - alert: alert_danger(t('.fail')) + alert: alert_danger(t(".fail")) end end @@ -60,10 +60,10 @@ def decline @adventure_mission_group = AdventureMissionGroup.find(params[:adventure_mission_group_id]) if @adventure_mission_group.update_attribute(:pending, true) redirect_to admin_adventure_adventure_mission_groups_path(@adventure), - notice: alert_success(t('.success')) + notice: alert_success(t(".success")) else redirect_to admin_adventure_adventure_mission_groups_path(@adventure), - alert: alert_danger(t('.fail')) + alert: alert_danger(t(".fail")) end end diff --git a/app/controllers/admin/adventure_missions_controller.rb b/app/controllers/admin/adventure_missions_controller.rb index 4bc6556e2..82d1c545f 100644 --- a/app/controllers/admin/adventure_missions_controller.rb +++ b/app/controllers/admin/adventure_missions_controller.rb @@ -4,7 +4,7 @@ class Admin::AdventureMissionsController < Admin::BaseController load_and_authorize_resource :adventure_mission, through: :adventure def index - @grid = initialize_grid(@adventure_missions, locale: :sv, order: 'adventure_missions.index') + @grid = initialize_grid(@adventure_missions, locale: :sv, order: "adventure_missions.index") end def new @@ -27,8 +27,8 @@ def create def update if @adventure_mission.update(adventure_mission_params) AdventureMissionService.shift_index_on_update(@adventure, - @adventure_mission.index, - adventure_mission_params[:index].to_i) + @adventure_mission.index, + adventure_mission_params[:index].to_i) redirect_to admin_adventure_adventure_missions_path(@adventure), notice: alert_update(AdventureMission) else render :edit, status: 422 @@ -41,7 +41,7 @@ def destroy redirect_to admin_adventure_adventure_missions_path(@adventure), notice: alert_destroy(AdventureMission) else redirect_to edit_admin_adventure_adventure_mission_path(@adventure, @adventure_mission), - alert: alert_errors(@adventure_mission.errors.full_messages) + alert: alert_errors(@adventure_mission.errors.full_messages) end end @@ -53,7 +53,7 @@ def edit def adventure_mission_params params.require(:adventure_mission).permit(:title_sv, :title_en, :description_sv, - :description_en, :max_points, :variable_points, - :index, :locked, :require_acceptance) + :description_en, :max_points, :variable_points, + :index, :locked, :require_acceptance) end end diff --git a/app/controllers/admin/adventures_controller.rb b/app/controllers/admin/adventures_controller.rb index 56a918653..5c73d5c60 100644 --- a/app/controllers/admin/adventures_controller.rb +++ b/app/controllers/admin/adventures_controller.rb @@ -27,25 +27,25 @@ def update redirect_to(admin_adventures_path, notice: alert_update(Adventure)) else redirect_to edit_admin_adventure_path(@adventure), - alert: alert_errors(@adventure.errors.full_messages) + alert: alert_errors(@adventure.errors.full_messages) end end def lock @adventure = Adventure.find(params[:adventure_id]) if @adventure.adventure_missions.update_all(locked: true) - redirect_to admin_adventure_adventure_missions_path, notice: alert_success(t('.success')) + redirect_to admin_adventure_adventure_missions_path, notice: alert_success(t(".success")) else - redirect_to admin_adventure_adventure_missions_path, alert: alert_danger(t('.fail')) + redirect_to admin_adventure_adventure_missions_path, alert: alert_danger(t(".fail")) end end def unlock @adventure = Adventure.find(params[:adventure_id]) if @adventure.adventure_missions.update_all(locked: false) - redirect_to admin_adventure_adventure_missions_path, notice: alert_success(t('.success')) + redirect_to admin_adventure_adventure_missions_path, notice: alert_success(t(".success")) else - redirect_to admin_adventure_adventure_missions_path, notice: alert_danger(t('.fail')) + redirect_to admin_adventure_adventure_missions_path, notice: alert_danger(t(".fail")) end end @@ -54,7 +54,7 @@ def destroy redirect_to(admin_adventures_path, notice: alert_destroy(Adventure)) else redirect_to edit_admin_adventure_path(@adventure), - alert: alert_errors(@adventure.errors.full_messages) + alert: alert_errors(@adventure.errors.full_messages) end end @@ -71,7 +71,7 @@ def set_adventures def adventure_params params.require(:adventure).permit(:title_sv, :title_en, :content_sv, :content_en, - :max_points, :start_date, :end_date, - :video, :publish_results, :introduction_id) + :max_points, :start_date, :end_date, + :video, :publish_results, :introduction_id) end end diff --git a/app/controllers/admin/albums_controller.rb b/app/controllers/admin/albums_controller.rb index fb9fc3633..00b94dcd9 100644 --- a/app/controllers/admin/albums_controller.rb +++ b/app/controllers/admin/albums_controller.rb @@ -32,7 +32,7 @@ def update service = AlbumService.new if @album.update(album_params) && service.upload_images(@album) redirect_to(admin_album_path(@album), - notice: %(#{alert_update(Album)} #{I18n.t('model.album.uploaded')}: #{service.uploaded})) + notice: %(#{alert_update(Album)} #{I18n.t("model.album.uploaded")}: #{service.uploaded})) else render :show, status: 422 end @@ -43,15 +43,15 @@ def destroy_images album.images.destroy_all redirect_to(admin_album_path(album), - notice: alert_destroy(Image)) + notice: alert_destroy(Image)) end private def album_params params.require(:album).permit(:title_sv, :title_en, :description_sv, :description_en, - :location, :start_date, :end_date, - :photographer_user, :photographer_name, - image_upload: []) + :location, :start_date, :end_date, + :photographer_user, :photographer_name, + image_upload: []) end end diff --git a/app/controllers/admin/blog_posts_controller.rb b/app/controllers/admin/blog_posts_controller.rb index f6c4de317..c4f49a1e3 100644 --- a/app/controllers/admin/blog_posts_controller.rb +++ b/app/controllers/admin/blog_posts_controller.rb @@ -3,9 +3,9 @@ class Admin::BlogPostsController < Admin::BaseController def index @post_grid = initialize_grid(BlogPost, - include: :user, - locale: :sv, - order: :created_at) + include: :user, + locale: :sv, + order: :created_at) end def new @@ -41,9 +41,9 @@ def destroy def blog_post_params params.require(:blog_post).permit(:title_sv, :title_en, - :content_sv, :content_en, - :preamble_sv, :preamble_en, - :cover_image, :remove_cover_image, - category_ids: []) + :content_sv, :content_en, + :preamble_sv, :preamble_en, + :cover_image, :remove_cover_image, + category_ids: []) end end diff --git a/app/controllers/admin/cafe_controller.rb b/app/controllers/admin/cafe_controller.rb index 989d17ffd..592650728 100644 --- a/app/controllers/admin/cafe_controller.rb +++ b/app/controllers/admin/cafe_controller.rb @@ -4,8 +4,8 @@ class Admin::CafeController < Admin::BaseController def index @cafe_shift_grid = initialize_grid(CafeShift, - include: :user, order: :start, - conditions: ['start >= ?', cafe_date]) + include: :user, order: :start, + conditions: ["start >= ?", cafe_date]) end def overview diff --git a/app/controllers/admin/cafe_shifts_controller.rb b/app/controllers/admin/cafe_shifts_controller.rb index 6644ecf92..119d63cf5 100644 --- a/app/controllers/admin/cafe_shifts_controller.rb +++ b/app/controllers/admin/cafe_shifts_controller.rb @@ -6,8 +6,8 @@ def show cafe_shift = CafeShift.find(params[:id]) cafe_shift.cafe_worker || cafe_shift.build_cafe_worker @cafe_view = CafeViewObject.new(users: User.by_firstname, - councils: Council.by_title, - shift: cafe_shift) + councils: Council.by_title, + shift: cafe_shift) end def edit @@ -55,7 +55,7 @@ def setup_create if CafeService.setup(@cafe_shift) redirect_to(admin_cafe_shifts_path, notice: alert_create(CafeShift)) else - flash[:alert] = I18n.t('model.cafe_shift.setup_error') + flash[:alert] = I18n.t("model.cafe_shift.setup_error") render :setup, status: 422 end end diff --git a/app/controllers/admin/cafe_workers_controller.rb b/app/controllers/admin/cafe_workers_controller.rb index f59d9a114..677fa9da8 100644 --- a/app/controllers/admin/cafe_workers_controller.rb +++ b/app/controllers/admin/cafe_workers_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class Admin::CafeWorkersController < Admin::BaseController load_permissions_and_authorize_resource load_and_authorize_resource :cafe_shift, parent: true @@ -8,8 +7,8 @@ def new cafe_shift.cafe_worker || cafe_shift.build_cafe_worker @cafe_view = CafeViewObject.new(users: User.by_firstname.confirmed, - councils: Council.by_title, - shift: cafe_shift) + councils: Council.by_title, + shift: cafe_shift) end def create @@ -17,8 +16,8 @@ def create cafe_shift.build_cafe_worker(cafe_worker_params) @cafe_view = CafeViewObject.new(users: User.by_firstname.confirmed, - councils: Council.by_title, - shift: cafe_shift) + councils: Council.by_title, + shift: cafe_shift) if cafe_shift.cafe_worker.save redirect_to(admin_cafe_shift_path(@cafe_shift), notice: alert_create(CafeWorker)) else @@ -30,8 +29,8 @@ def update cafe_shift = CafeShift.find(params[:cafe_shift_id]) cafe_worker = CafeWorker.find(params[:id]) @cafe_view = CafeViewObject.new(users: User.by_firstname.confirmed, - councils: Council.by_title, - shift: cafe_shift) + councils: Council.by_title, + shift: cafe_shift) if cafe_worker.update(cafe_worker_params) redirect_to(admin_cafe_shift_path(cafe_shift), notice: alert_update(CafeWorker)) else diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index 4e6fbfac8..1a1e4fb6c 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -45,6 +45,6 @@ def destroy def contact_params params.require(:contact).permit(:name_sv, :name_en, :email, :phone, :public, :avatar, - :text_sv, :text_en, :post_id, :slug, :remove_avatar) + :text_sv, :text_en, :post_id, :slug, :remove_avatar) end end diff --git a/app/controllers/admin/councils_controller.rb b/app/controllers/admin/councils_controller.rb index fc5e7439c..397dc93f2 100644 --- a/app/controllers/admin/councils_controller.rb +++ b/app/controllers/admin/councils_controller.rb @@ -3,7 +3,7 @@ class Admin::CouncilsController < Admin::BaseController load_permissions_and_authorize_resource find_by: :url def index - @council_grid = initialize_grid(Council, locale: :sv, order: 'council_translations.title') + @council_grid = initialize_grid(Council, locale: :sv, order: "council_translations.title") end def new diff --git a/app/controllers/admin/documents_controller.rb b/app/controllers/admin/documents_controller.rb index c578dfe33..034a19016 100644 --- a/app/controllers/admin/documents_controller.rb +++ b/app/controllers/admin/documents_controller.rb @@ -3,13 +3,13 @@ class Admin::DocumentsController < Admin::BaseController def index documents = filter_documents(Document.all, params[:category]) - grid = initialize_grid(documents, order: 'documents.updated_at', - order_direction: 'desc', + grid = initialize_grid(documents, order: "documents.updated_at", + order_direction: "desc", include: :user) @documents = DocumentView.new(grid: grid, - categories: Document.categories, - current_category: params[:category]) + categories: Document.categories, + current_category: params[:category]) end def edit diff --git a/app/controllers/admin/doors_controller.rb b/app/controllers/admin/doors_controller.rb index 44e6bea42..487d7bdc2 100644 --- a/app/controllers/admin/doors_controller.rb +++ b/app/controllers/admin/doors_controller.rb @@ -38,7 +38,7 @@ def destroy def accesses @doors = Door.by_title @door = Door.includes(:posts).find(params[:id]) - @access_grid = initialize_grid(@door.users, order: 'student_id') + @access_grid = initialize_grid(@door.users, order: "student_id") end def post diff --git a/app/controllers/admin/elections_controller.rb b/app/controllers/admin/elections_controller.rb index ebea31cc7..f278f654c 100644 --- a/app/controllers/admin/elections_controller.rb +++ b/app/controllers/admin/elections_controller.rb @@ -44,24 +44,24 @@ def destroy def nominations @nominations_grid = initialize_grid(@election.nominations, - name: 'nominations', - include: [post: :translations]) + name: "nominations", + include: [post: :translations]) end def candidates @candidates_grid = initialize_grid(@election.candidates, - name: 'candidates', - include: [:user, post: :translations, council: :translations], - custom_order: { 'posts.id' => 'post_translations.title' }) + name: "candidates", + include: [:user, post: :translations, council: :translations], + custom_order: {"posts.id" => "post_translations.title"}) end private def election_params params.require(:election).permit(:title_sv, :title_en, :description_sv, :description_en, - :open, :close_general, :close_all, - :url, :visible, :mail_link, :board_mail_link, - :nominate_mail, :candidate_mail, :semester, - :candidate_mail_star, extra_post_ids: []) + :open, :close_general, :close_all, + :url, :visible, :mail_link, :board_mail_link, + :nominate_mail, :candidate_mail, :semester, + :candidate_mail_star, extra_post_ids: []) end end diff --git a/app/controllers/admin/event_signups_controller.rb b/app/controllers/admin/event_signups_controller.rb index 0b1264c0e..89b29fc28 100644 --- a/app/controllers/admin/event_signups_controller.rb +++ b/app/controllers/admin/event_signups_controller.rb @@ -23,8 +23,8 @@ def update def show @event_signup = @event.signup @event_signup ||= @event.build_event_signup(opens: Time.zone.now, - closes: @event.starts_at, - for_members: false) + closes: @event.starts_at, + for_members: false) set_grids end @@ -36,14 +36,14 @@ def destroy def export respond_to do |format| format.csv do - if params[:list] == 'reserves' + if params[:list] == "reserves" set_reserves send_data(ExportCSV.event_users(@reserves, @event_signup), - filename: "reserver_till_#{@event.to_s.parameterize}.csv") + filename: "reserver_till_#{@event.to_s.parameterize}.csv") else set_attending send_data(ExportCSV.event_users(@attending, @event_signup), - filename: "anmalda_till_#{@event.to_s.parameterize}.csv") + filename: "anmalda_till_#{@event.to_s.parameterize}.csv") end end end @@ -53,9 +53,9 @@ def export def event_signup_params params.require(:event_signup).permit(:for_members, :closes, :slots, :question_sv, :question_en, - :notification_message_sv, :notification_message_en, - :novice, :mentor, :member, :custom, :custom_name, :opens, - group_types: []) + :notification_message_sv, :notification_message_en, + :novice, :mentor, :member, :custom, :custom_name, :opens, + group_types: []) end def set_tab diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 532767d85..0f00201b0 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -4,10 +4,10 @@ class Admin::EventsController < Admin::BaseController def index @event_grid = initialize_grid(Event, - include: :event_signup, - locale: :sv, - order: :starts_at, - order_direction: :desc) + include: :event_signup, + locale: :sv, + order: :starts_at, + order_direction: :desc) end def new @@ -47,12 +47,12 @@ def destroy def event_params params.require(:event).permit(:title_sv, :title_en, :description_sv, :description_en, - :short_sv, :short_en, - :location_sv, :location_en, :starts_at, :ends_at, - :all_day, :image, :remove_image, - :drink, :food, :cash, :price, :contact_id, - :council_id, :dot, dress_code: [], - category_ids: []) + :short_sv, :short_en, + :location_sv, :location_en, :starts_at, :ends_at, + :all_day, :image, :remove_image, + :drink, :food, :cash, :price, :contact_id, + :council_id, :dot, dress_code: [], + category_ids: []) end def set_tab diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 927c42f02..ddb5a1a68 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -4,8 +4,8 @@ class Admin::GroupsController < Admin::BaseController def index set_groups @grid = initialize_grid(@groups, - include: :introduction, - order: 'introductions.start') + include: :introduction, + order: "introductions.start") end def new @@ -45,8 +45,8 @@ def adventures @group = Group.find(params[:group_id]) @adventure_mission_groups = AdventureMissionGroup.where(group: @group, pending: false) @grid = initialize_grid(@adventure_mission_groups, - include: :adventure_mission, - order: 'adventure_mission_groups.updated_at') + include: :adventure_mission, + order: "adventure_mission_groups.updated_at") end private diff --git a/app/controllers/admin/images_controller.rb b/app/controllers/admin/images_controller.rb index e762d24a1..d4582927b 100644 --- a/app/controllers/admin/images_controller.rb +++ b/app/controllers/admin/images_controller.rb @@ -5,7 +5,7 @@ class Admin::ImagesController < Admin::BaseController def download if @image.file - send_file(@image.file.path, filename: @image.filename, type: 'image/jpg', + send_file(@image.file.path, filename: @image.filename, type: "image/jpg", x_sendfile: true) end end @@ -15,7 +15,7 @@ def reprocess if @image.save redirect_to(admin_album_image_path(@album, @image)) else - render(:show, notice: I18n.t('model.image.cannot_save_reprocess')) + render(:show, notice: I18n.t("model.image.cannot_save_reprocess")) end end diff --git a/app/controllers/admin/introductions_controller.rb b/app/controllers/admin/introductions_controller.rb index a6e75657e..9c852df0a 100644 --- a/app/controllers/admin/introductions_controller.rb +++ b/app/controllers/admin/introductions_controller.rb @@ -42,6 +42,6 @@ def destroy def introduction_params params.require(:introduction).permit(:title_sv, :title_en, :description_sv, :description_en, - :start, :stop, :slug, :current) + :start, :stop, :slug, :current) end end diff --git a/app/controllers/admin/keys_controller.rb b/app/controllers/admin/keys_controller.rb index 79b0936ba..cdec921c6 100644 --- a/app/controllers/admin/keys_controller.rb +++ b/app/controllers/admin/keys_controller.rb @@ -2,8 +2,8 @@ class Admin::KeysController < Admin::BaseController load_permissions_and_authorize_resource def index - @keys = initialize_grid(Key.all, order: 'name', order_direction: 'asc') - @key_users = initialize_grid(KeyUser.all, order_direction: 'asc') + @keys = initialize_grid(Key.all, order: "name", order_direction: "asc") + @key_users = initialize_grid(KeyUser.all, order_direction: "asc") end def new @@ -19,7 +19,7 @@ def create if @key.save redirect_to admin_keys_path else - render 'new' + render "new" end end diff --git a/app/controllers/admin/mail_aliases_controller.rb b/app/controllers/admin/mail_aliases_controller.rb index 8c9d6d594..12522f007 100644 --- a/app/controllers/admin/mail_aliases_controller.rb +++ b/app/controllers/admin/mail_aliases_controller.rb @@ -5,43 +5,44 @@ def index end def search - if params[:q] - @aliases = MailAlias.fulltext_search(params[:q]) + @aliases = if params[:q] + MailAlias.fulltext_search(params[:q]) else - @aliases = MailAlias.none + MailAlias.none end - render :json => { :mail_aliases => process_list(@aliases) } + render json: {mail_aliases: process_list(@aliases)} end def update begin # If targets is [] it will become nil over HTTP so handle it here. @aliases = MailAlias.insert_aliases! mail_alias_params[:username], - mail_alias_params[:domain], - mail_alias_params[:targets] || [] + mail_alias_params[:domain], + mail_alias_params[:targets] || [] rescue ActiveRecord::RecordInvalid => ex - render :nothing => true, :status => :unprocessable_entity + render nothing: true, status: :unprocessable_entity return end - render :json => { :mail_aliases => process_list(@aliases) } + render json: {mail_aliases: process_list(@aliases)} end private + def mail_alias_params params.require(:mail_alias).permit( - [ :username, :domain, :targets => []] + [:username, :domain, targets: []] ) end def process_list lst # Do the processing here in ruby where we have functioning hashmaps etc. table = lst.group_by(&:address) - return table.keys.sort.map do |k| - { :username => table[k].first.username, - :domain => table[k].first.domain, - :targets => table[k].map(&:target).sort } + table.keys.sort.map do |k| + {username: table[k].first.username, + domain: table[k].first.domain, + targets: table[k].map(&:target).sort} end end end diff --git a/app/controllers/admin/meetings_controller.rb b/app/controllers/admin/meetings_controller.rb index c8e962a15..8118dcb70 100644 --- a/app/controllers/admin/meetings_controller.rb +++ b/app/controllers/admin/meetings_controller.rb @@ -18,7 +18,7 @@ def create if meeting_params[:occurrences].to_i > 0 @first_meeting = MeetingService.create_recurring_meeting(meeting_params) if !@first_meeting.nil? - redirect_to edit_admin_meeting_path(@first_meeting, edit_type: 'all'), notice: alert_create(RecurringMeeting) + redirect_to edit_admin_meeting_path(@first_meeting, edit_type: "all"), notice: alert_create(RecurringMeeting) else render :new, status: 422 end @@ -39,24 +39,24 @@ def update @meeting.is_admin = true edit_type = params[:meeting][:edit_type] - if edit_type == 'one' + if edit_type == "one" if MeetingService.update_meeting(@meeting, meeting_params) MeetingMailer.update_email(@meeting, current_user).deliver_now unless @meeting.by_admin redirect_to edit_admin_meeting_path(@meeting), notice: alert_update(Meeting) else render :edit, status: 422 end - elsif edit_type == 'all' + elsif edit_type == "all" @updated_meeting = MeetingService.update_all_recurring_meeting(@meeting, meeting_params) if !@updated_meeting.nil? - redirect_to edit_admin_meeting_path(@updated_meeting, edit_type: 'all'), notice: alert_update(RecurringMeeting) + redirect_to edit_admin_meeting_path(@updated_meeting, edit_type: "all"), notice: alert_update(RecurringMeeting) else render :edit, status: 422 end - elsif edit_type == 'after' + elsif edit_type == "after" @updated_meeting = MeetingService.update_after_recurring_meeting(@meeting, meeting_params) if !@updated_meeting.nil? - redirect_to edit_admin_meeting_path(@updated_meeting, edit_type: 'after'), notice: alert_update(RecurringMeeting) + redirect_to edit_admin_meeting_path(@updated_meeting, edit_type: "after"), notice: alert_update(RecurringMeeting) else render :edit, status: 422 end @@ -75,7 +75,7 @@ def destroy def meeting_params params.require(:meeting).permit(:start_date, :end_date, :title, :purpose, :room, - :comment, :council_id, :user_id, :status, :every, - :occurrences) + :comment, :council_id, :user_id, :status, :every, + :occurrences) end end diff --git a/app/controllers/admin/menus_controller.rb b/app/controllers/admin/menus_controller.rb index 65c1203cd..7b040b36c 100644 --- a/app/controllers/admin/menus_controller.rb +++ b/app/controllers/admin/menus_controller.rb @@ -3,10 +3,10 @@ class Admin::MenusController < Admin::BaseController def index @menus_grid = initialize_grid(Menu, - include: [main_menu: :translations], - locale: :sv, - order: 'menus.main_menu_id', - order_direction: 'asc') + include: [main_menu: :translations], + locale: :sv, + order: "menus.main_menu_id", + order_direction: "asc") end def new @@ -49,6 +49,6 @@ def destroy def menu_params params.require(:menu).permit(:main_menu_id, :index, :link, :column, - :name_sv, :name_en, :visible, :turbolinks, :blank_p, :header) + :name_sv, :name_en, :visible, :turbolinks, :blank_p, :header) end end diff --git a/app/controllers/admin/messages_controller.rb b/app/controllers/admin/messages_controller.rb index f8e6b617b..02ad21aef 100644 --- a/app/controllers/admin/messages_controller.rb +++ b/app/controllers/admin/messages_controller.rb @@ -48,12 +48,12 @@ def destroy end def download_image - if params[:size] == 'original' - send_file @message.image.url, disposition: 'inline' - elsif params[:size] == 'large' - send_file @message.image.large.url, disposition: 'inline' + if params[:size] == "original" + send_file @message.image.url, disposition: "inline" + elsif params[:size] == "large" + send_file @message.image.large.url, disposition: "inline" else - send_file @message.image.thumb.url, disposition: 'inline' + send_file @message.image.thumb.url, disposition: "inline" end end diff --git a/app/controllers/admin/news_controller.rb b/app/controllers/admin/news_controller.rb index beb54ebe2..3aeffd69c 100644 --- a/app/controllers/admin/news_controller.rb +++ b/app/controllers/admin/news_controller.rb @@ -3,10 +3,10 @@ class Admin::NewsController < Admin::BaseController def index @news_grid = initialize_grid(News, - include: :user, - order: 'news.created_at', - locale: 'sv', - order_direction: :desc) + include: :user, + order: "news.created_at", + locale: "sv", + order_direction: :desc) end def new @@ -47,7 +47,7 @@ def destroy def news_params params.require(:news).permit(:title_sv, :title_en, :content_sv, :content_en, - :image, :pinned_from, :pinned_to, - :remove_image, category_ids: []) + :image, :pinned_from, :pinned_to, + :remove_image, category_ids: []) end end diff --git a/app/controllers/admin/page_elements_controller.rb b/app/controllers/admin/page_elements_controller.rb index fd417f90e..6810053aa 100644 --- a/app/controllers/admin/page_elements_controller.rb +++ b/app/controllers/admin/page_elements_controller.rb @@ -24,7 +24,7 @@ def create @page_element = page.page_elements.build(page_element_params) if @page_element.save redirect_to(edit_admin_page_page_element_path(page, @page_element), - notice: alert_create(PageElement)) + notice: alert_create(PageElement)) else render :new, status: 422 end @@ -36,7 +36,7 @@ def update if @page_element.update(page_element_params) redirect_to(edit_admin_page_page_element_path(page, @page_element), - notice: alert_update(PageElement)) + notice: alert_update(PageElement)) else render :edit, status: 422 end @@ -53,7 +53,7 @@ def destroy def page_element_params params.require(:page_element).permit(:index, :sidebar, :visible, :text_sv, - :text_en, :headline_sv, :headline_en, - :element_type, :page_image_id) + :text_en, :headline_sv, :headline_en, + :element_type, :page_image_id) end end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index a32204795..88337d74b 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -50,6 +50,6 @@ def destroy_image def page_params params.require(:page).permit(:url, :visible, :title_sv, :title_en, - :public, :namespace, image_upload: []) + :public, :namespace, image_upload: []) end end diff --git a/app/controllers/admin/permissions_controller.rb b/app/controllers/admin/permissions_controller.rb index 6b78a88c4..a04181b79 100644 --- a/app/controllers/admin/permissions_controller.rb +++ b/app/controllers/admin/permissions_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class Admin::PermissionsController < Admin::BaseController load_permissions_and_authorize_resource load_and_authorize_resource :post diff --git a/app/controllers/admin/posts_controller.rb b/app/controllers/admin/posts_controller.rb index 1f93c629f..0a338aee0 100644 --- a/app/controllers/admin/posts_controller.rb +++ b/app/controllers/admin/posts_controller.rb @@ -5,15 +5,15 @@ class Admin::PostsController < Admin::BaseController def add_user council = Council.find_by_url!(params[:council_id]) @post_view = PostView.new(council: council, - post_user: PostUser.new(post_user_params), - users: User.by_firstname) + post_user: PostUser.new(post_user_params), + users: User.by_firstname) @post_view = set_grids(@post_view) if PostUserService.create(@post_view.post_user) redirect_to(admin_council_posts_path(@post_view.council), - notice: I18n.t('model.post.added', - u: @post_view.post_user.user, - p: @post_view.post_user.post)) + notice: I18n.t("model.post.added", + u: @post_view.post_user.user, + p: @post_view.post_user.post)) else render :index end @@ -21,7 +21,7 @@ def add_user def remove_user post_user = PostUser.find(params[:post_user_id]) - @status = I18n.t('model.post.user_removed', u: post_user.user, p: post_user.post) + @status = I18n.t("model.post.user_removed", u: post_user.user, p: post_user.post) @id = params[:post_user_id] @state = post_user.destroy @@ -30,8 +30,8 @@ def remove_user def index council = Council.find_by_url!(params[:council_id]) @post_view = PostView.new(council: council, post_user: PostUser.new, users: User.by_firstname) - @post_view.post_grid = initialize_grid(council.posts, name: 'posts', locale: :sv) - @post_view.post_user_grid = initialize_grid(council.post_users, include: [:post, :user], name: 'post_users') + @post_view.post_grid = initialize_grid(council.posts, name: "posts", locale: :sv) + @post_view.post_user_grid = initialize_grid(council.post_users, include: [:post, :user], name: "post_users") end def new @@ -59,7 +59,7 @@ def update if @post.update(post_params) redirect_to(edit_admin_council_post_path(@council, @post), - notice: alert_update(Post)) + notice: alert_update(Post)) else render :edit, status: 422 end @@ -76,18 +76,18 @@ def destroy private def set_grids(post_view) - post_view.post_grid = initialize_grid(post_view.council.posts, name: 'posts', locale: :sv) + post_view.post_grid = initialize_grid(post_view.council.posts, name: "posts", locale: :sv) post_view.post_user_grid = initialize_grid(post_view.council.post_users, - include: [:post, :user], - name: 'post_users') + include: [:post, :user], + name: "post_users") post_view end def post_params params.require(:post).permit(:title_sv, :title_en, :limit, :rec_limit, - :description_sv, :description_en, :elected_by, - :semester, :board, :car_rent, :council_id) + :description_sv, :description_en, :elected_by, + :semester, :board, :car_rent, :council_id) end def post_user_params diff --git a/app/controllers/admin/rents_controller.rb b/app/controllers/admin/rents_controller.rb index 5ad477b8c..f716d443f 100644 --- a/app/controllers/admin/rents_controller.rb +++ b/app/controllers/admin/rents_controller.rb @@ -4,8 +4,8 @@ class Admin::RentsController < Admin::BaseController def index @rents = Rent.from_date(Time.zone.now.beginning_of_day).includes(:user) - @rent_grid = initialize_grid(@rents, order: 'rents.d_from', order_direction: :asc) - @faqs = Faq.where(answer: '').where(category: 'Bil') + @rent_grid = initialize_grid(@rents, order: "rents.d_from", order_direction: :asc) + @faqs = Faq.where(answer: "").where(category: "Bil") end def show @@ -48,7 +48,7 @@ def prepare def rent_params params.require(:rent).permit(:d_from, :d_til, :user_id, - :purpose, :disclaimer, :council_id, - :comment, :status, :aktiv, :service) + :purpose, :disclaimer, :council_id, + :comment, :status, :aktiv, :service) end end diff --git a/app/controllers/admin/songs_controller.rb b/app/controllers/admin/songs_controller.rb index e52e37c8a..620b52489 100644 --- a/app/controllers/admin/songs_controller.rb +++ b/app/controllers/admin/songs_controller.rb @@ -6,7 +6,7 @@ def new end def index - @songs = initialize_grid(Song.all, order: 'title', order_direction: 'asc') + @songs = initialize_grid(Song.all, order: "title", order_direction: "asc") end def edit diff --git a/app/controllers/admin/tools_controller.rb b/app/controllers/admin/tools_controller.rb index e7c187f2d..6db69bc96 100644 --- a/app/controllers/admin/tools_controller.rb +++ b/app/controllers/admin/tools_controller.rb @@ -43,7 +43,7 @@ def destroy if tool.destroy redirect_to admin_tools_path, notice: alert_destroy(Tool) else - redirect_to admin_tools_path, notice: alert_danger(t('model.tool.could_not_destroy')) + redirect_to admin_tools_path, notice: alert_danger(t("model.tool.could_not_destroy")) end end diff --git a/app/controllers/admin/work_posts_controller.rb b/app/controllers/admin/work_posts_controller.rb index 97123bd1d..926e8f3cc 100644 --- a/app/controllers/admin/work_posts_controller.rb +++ b/app/controllers/admin/work_posts_controller.rb @@ -3,16 +3,16 @@ class Admin::WorkPostsController < Admin::BaseController load_permissions_and_authorize_resource def index - if params[:all].present? - posts = WorkPost.all + posts = if params[:all].present? + WorkPost.all else - posts = WorkPost.by_deadline + WorkPost.by_deadline end @work_portal = WorkPortal.new(grid: initialize_grid(posts, - include: :user, - order: 'updated_at', - order_direction: 'desc')) + include: :user, + order: "updated_at", + order_direction: "desc")) end def new @@ -29,7 +29,7 @@ def create if @work_portal.current_post.save redirect_to(edit_admin_work_post_path(@work_portal.current_post), - notice: alert_create(WorkPost)) + notice: alert_create(WorkPost)) else render :new, status: 422 end @@ -41,7 +41,7 @@ def update if @work_portal.current_post.update(work_post_params) redirect_to(edit_admin_work_post_path(@work_portal.current_post), - notice: alert_update(WorkPost)) + notice: alert_update(WorkPost)) else render :edit, status: 422 end @@ -58,7 +58,7 @@ def destroy def work_post_params params.require(:work_post).permit(:title, :description, :company, :deadline, - :field, :target_group, :visible, :publish, - :image, :remove_image, :link, :kind) + :field, :target_group, :visible, :publish, + :image, :remove_image, :link, :kind) end end diff --git a/app/controllers/adventure_mission_groups_controller.rb b/app/controllers/adventure_mission_groups_controller.rb index e0228c9fa..df5605f0d 100644 --- a/app/controllers/adventure_mission_groups_controller.rb +++ b/app/controllers/adventure_mission_groups_controller.rb @@ -15,10 +15,10 @@ def create @adventure_mission_group.pending = true if @adventure_mission.require_acceptance? if @adventure_mission_group.save - redirect_to adventure_mission_path(@adventure_mission), notice: alert_success(t('.success')) + redirect_to adventure_mission_path(@adventure_mission), notice: alert_success(t(".success")) else redirect_to new_adventure_mission_group_path(adventure_mission: @adventure_mission), - alert: alert_errors(@adventure_mission_group.errors.full_messages) + alert: alert_errors(@adventure_mission_group.errors.full_messages) end end @@ -29,10 +29,10 @@ def edit def update @adventure_mission = AdventureMission.find(adventure_mission_group_params[:adventure_mission_id]) if @adventure_mission_group.update(adventure_mission_group_params) - redirect_to adventure_mission_path(@adventure_mission), notice: alert_success(t('.success')) + redirect_to adventure_mission_path(@adventure_mission), notice: alert_success(t(".success")) else redirect_to edit_adventure_mission_group_path(@adventure_mission_group), - alert: alert_errors(@adventure_mission_group.errors.full_messages) + alert: alert_errors(@adventure_mission_group.errors.full_messages) end end @@ -40,10 +40,10 @@ def destroy @adventure_mission = @adventure_mission_group.adventure_mission if @adventure_mission_group.destroy - redirect_to adventure_mission_path(@adventure_mission), notice: alert_danger(t('.success')) + redirect_to adventure_mission_path(@adventure_mission), notice: alert_danger(t(".success")) else redirect_to adventure_mission_path(@adventure_mission), - alert: alert_errors(@adventure_mission_group.errors.full_messages) + alert: alert_errors(@adventure_mission_group.errors.full_messages) end end diff --git a/app/controllers/adventure_missions_controller.rb b/app/controllers/adventure_missions_controller.rb index bad98df83..26d3799fb 100644 --- a/app/controllers/adventure_missions_controller.rb +++ b/app/controllers/adventure_missions_controller.rb @@ -5,7 +5,7 @@ def show @group = current_user.groups.regular.last if @group.blank? - redirect_to adventures_path, alert: t('.no_group') + redirect_to adventures_path, alert: t(".no_group") else @adventure_mission_group = @group.adventure_mission_groups.find_by(adventure_mission: @adventure_mission) end diff --git a/app/controllers/adventures_controller.rb b/app/controllers/adventures_controller.rb index a5cc5c512..6e4494a90 100644 --- a/app/controllers/adventures_controller.rb +++ b/app/controllers/adventures_controller.rb @@ -5,7 +5,7 @@ class AdventuresController < ApplicationController def index @adventure = @introduction.adventures.published.first - redirect_to root_path, notice: t('.no_adventure') and return if @adventure.nil? + redirect_to root_path, notice: t(".no_adventure") and return if @adventure.nil? if @adventure.adventure_missions.present? set_mission_variables(@adventure) @@ -43,7 +43,7 @@ def set_mission_variables(adventure) am.points = am.points(@group) end - @grid = initialize_grid(@adventure_missions, locale: :sv, order: 'adventure_missions.index') + @grid = initialize_grid(@adventure_missions, locale: :sv, order: "adventure_missions.index") end private diff --git a/app/controllers/api/achievements_controller.rb b/app/controllers/api/achievements_controller.rb index a89aa4e7c..7e7964258 100644 --- a/app/controllers/api/achievements_controller.rb +++ b/app/controllers/api/achievements_controller.rb @@ -5,4 +5,4 @@ def index @achievement_users = current_user.achievement_users render json: @achievement_users end -end \ No newline at end of file +end diff --git a/app/controllers/api/adventure_mission_groups_controller.rb b/app/controllers/api/adventure_mission_groups_controller.rb index a95bc7966..93560c0c2 100644 --- a/app/controllers/api/adventure_mission_groups_controller.rb +++ b/app/controllers/api/adventure_mission_groups_controller.rb @@ -2,8 +2,8 @@ class Api::AdventureMissionGroupsController < Api::BaseController load_permissions_and_authorize_resource def index - @groups = AdventureQueries.highscore_list + @groups = AdventureQueries.highscore_list - render json: @groups, each_serializer: Api::AdventureMissionGroupSerializer::Index, root: 'groups' + render json: @groups, each_serializer: Api::AdventureMissionGroupSerializer::Index, root: "groups" end end diff --git a/app/controllers/api/adventure_missions_controller.rb b/app/controllers/api/adventure_missions_controller.rb index ef88fe88f..7f4da1dda 100644 --- a/app/controllers/api/adventure_missions_controller.rb +++ b/app/controllers/api/adventure_missions_controller.rb @@ -10,30 +10,30 @@ def finish_adventure_mission points = params[:points].to_i if adventure_mission.locked? - render json: { error: 'Too late, the mission is locked..' }, status: 422 and return + render json: {error: "Too late, the mission is locked.."}, status: 422 and return elsif points > adventure_mission.max_points - render json: { error: "You can't get more than max points which is: #{adventure_mission.max_points}" }, - status: 422 and return + render json: {error: "You can't get more than max points which is: #{adventure_mission.max_points}"}, + status: 422 and return elsif points.zero? - render json: { error: 'You can\'t get 0 points' }, status: 422 and return + render json: {error: "You can't get 0 points"}, status: 422 and return end # Doing both server and database auth to stop as soon as possible if group.adventure_mission_groups.pluck(:adventure_mission_id).include?(adventure_mission.id) - render json: { error: 'You can only finish a mission once' }, status: 422 and return + render json: {error: "You can only finish a mission once"}, status: 422 and return end # here is currently serving the exact same purpose as adventure_mission_group = AdventureMissionGroup.new(adventure_mission: adventure_mission, - group: group, - points: points, - finished: Time.now, - pending: adventure_mission.require_acceptance?) + group: group, + points: points, + finished: Time.now, + pending: adventure_mission.require_acceptance?) if adventure_mission_group.save render json: :ok, status: 200 else - render json: { error: adventure_mission_group.errors.full_messages }, status: 500 + render json: {error: adventure_mission_group.errors.full_messages}, status: 500 end end @@ -41,14 +41,14 @@ def reset_adventure_mission adventure_mission = AdventureMission.find(params[:adventure_mission_id]) if adventure_mission.locked? - render json: { error: 'You can\'t reset a locked mission' }, status: 422 and return + render json: {error: "You can't reset a locked mission"}, status: 422 and return end # fetch group from current_user so one can't specify other groups group = current_user.groups.regular.last unless group.adventure_mission_groups.pluck(:adventure_mission_id).include?(adventure_mission.id) - render json: { error: 'You have not finished this mission yet' }, status: 422 and return + render json: {error: "You have not finished this mission yet"}, status: 422 and return end adventure_mission_group = group.adventure_mission_groups.where(adventure_mission: adventure_mission).first @@ -56,13 +56,13 @@ def reset_adventure_mission if adventure_mission_group.destroy! render json: :ok, status: 200 else - render json: { error: adventure_mission_group.errors.full_messages }, status: 500 + render json: {error: adventure_mission_group.errors.full_messages}, status: 500 end end private def notify_not_unique - render json: { error: 'You can only finish a mission once' }, status: 422 + render json: {error: "You can only finish a mission once"}, status: 422 end end diff --git a/app/controllers/api/adventures_controller.rb b/app/controllers/api/adventures_controller.rb index 854806ae7..64408f7c0 100644 --- a/app/controllers/api/adventures_controller.rb +++ b/app/controllers/api/adventures_controller.rb @@ -4,11 +4,11 @@ class Api::AdventuresController < Api::BaseController def index if @introduction.nil? - render json: { error: 'No introduction exists' } and return + render json: {error: "No introduction exists"} and return elsif current_user.groups.regular.last.nil? - render json: { error: 'No group exists' } and return + render json: {error: "No group exists"} and return elsif @introduction.adventures.published_asc.empty? - render json: { error: 'No adventures avaliable' } and return + render json: {error: "No adventures avaliable"} and return end @adventures = @introduction.adventures.published_asc @@ -16,11 +16,11 @@ def index # Also passing current_user to the serializer scope because it doesn't # seem to be passed automatically @serializable_adventures = ActiveModelSerializers::SerializableResource.new(@adventures, - {each_serializer: Api::AdventureSerializer::Index, scope: { 'current_user': current_user}}) - render json: { group_name: current_user.groups.regular.last.name, - is_mentor: current_user.mentor?, - total_group_points: current_user.groups.regular.last.total_published_adventure_points, - adventures: @serializable_adventures } + {each_serializer: Api::AdventureSerializer::Index, scope: {current_user: current_user}}) + render json: {group_name: current_user.groups.regular.last.name, + is_mentor: current_user.mentor?, + total_group_points: current_user.groups.regular.last.total_published_adventure_points, + adventures: @serializable_adventures} end private diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 8c8912c8f..ccc1b9a20 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -7,6 +7,6 @@ class Api::BaseController < ApplicationController include DeviseTokenAuth::Concerns::SetUserByToken rescue_from CanCan::AccessDenied do - render(json: { success: false, errors: ["Invalid login credentials"] }, status: 401) + render(json: {success: false, errors: ["Invalid login credentials"]}, status: 401) end end diff --git a/app/controllers/api/cafe_controller.rb b/app/controllers/api/cafe_controller.rb index 9876e69f0..1a84a0e1b 100644 --- a/app/controllers/api/cafe_controller.rb +++ b/app/controllers/api/cafe_controller.rb @@ -21,7 +21,7 @@ def create if cafe_worker.save render json: {}, status: :ok else - render json: { errors: cafe_worker.errors.full_messages }, status: 422 + render json: {errors: cafe_worker.errors.full_messages}, status: 422 end end @@ -31,7 +31,7 @@ def destroy if cafe_user&.destroy render json: {}, status: :ok else - render json: { errors: 'Failed to destroy' }, status: 422 + render json: {errors: "Failed to destroy"}, status: 422 end end diff --git a/app/controllers/api/contacts_controller.rb b/app/controllers/api/contacts_controller.rb index 01d26b916..1af10b8bc 100644 --- a/app/controllers/api/contacts_controller.rb +++ b/app/controllers/api/contacts_controller.rb @@ -26,7 +26,7 @@ def mail if @contact.send_email render json: {}, status: :ok else - render json: { errors: @contact.errors.full_messages }, status: 422 + render json: {errors: @contact.errors.full_messages}, status: 422 end end diff --git a/app/controllers/api/event_users_controller.rb b/app/controllers/api/event_users_controller.rb index 61c1b4aa6..fb6a960bd 100644 --- a/app/controllers/api/event_users_controller.rb +++ b/app/controllers/api/event_users_controller.rb @@ -10,7 +10,7 @@ def create if @event_user.save render json: @event_user else - render json: { errors: @event_user.errors.full_messages }, status: 422 + render json: {errors: @event_user.errors.full_messages}, status: 422 end end @@ -21,10 +21,10 @@ def destroy if @event_user.destroy render json: {}, status: :ok else - render json: { errors: @event_user.errors.full_messages }, status: 500 + render json: {errors: @event_user.errors.full_messages}, status: 500 end else - render json: { errors: ['Signup is not open'], status: 422 } + render json: {errors: ["Signup is not open"], status: 422} end end diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index 55dfb802e..064a13828 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -6,7 +6,7 @@ def index authorize!(:index, :api_event) @events = Event.includes(:translations).between(params[:start], params[:end]).by_start - render json: @events, namespace: '' # Use the same serializer as for the web calendar + render json: @events, namespace: "" # Use the same serializer as for the web calendar end def matrix @@ -14,7 +14,7 @@ def matrix @introduction = Introduction.current if @introduction.nil? - render json: { error: 'No introduction exists' } and return + render json: {error: "No introduction exists"} and return end start = @introduction.start @@ -23,7 +23,7 @@ def matrix @events = Event.includes(:translations).between(start, stop).by_start @events = group_events(@events) - render json: @events, namespace: '' + render json: @events, namespace: "" end def scroll @@ -36,7 +36,7 @@ def scroll @events = (@events.to_a + last_day.to_a).uniq end - render json: @events, namespace: '' + render json: @events, namespace: "" end def show diff --git a/app/controllers/api/fredmanskies_controller.rb b/app/controllers/api/fredmanskies_controller.rb index e67067410..3356ea3a4 100644 --- a/app/controllers/api/fredmanskies_controller.rb +++ b/app/controllers/api/fredmanskies_controller.rb @@ -7,7 +7,7 @@ def create enabled: true }, status: :ok else - render json: { errors: 'You can not join Fredmans' }, status: 422 + render json: {errors: "You can not join Fredmans"}, status: 422 end end @@ -19,7 +19,7 @@ def destroy enabled: false }, status: :ok else - render json: { errors: 'You can not leave Fredmans' }, status: 422 + render json: {errors: "You can not leave Fredmans"}, status: 422 end end diff --git a/app/controllers/api/gallery_controller.rb b/app/controllers/api/gallery_controller.rb index 36ec62584..cb4999380 100644 --- a/app/controllers/api/gallery_controller.rb +++ b/app/controllers/api/gallery_controller.rb @@ -2,7 +2,7 @@ class Api::GalleryController < Api::BaseController load_permissions_then_authorize_resource class: false def index - @year = params[:year] || Album.include_for_gallery.order('start_date').last.start_date.year + @year = params[:year] || Album.include_for_gallery.order("start_date").last.start_date.year @albums = Album.include_for_gallery.gallery(Time.zone.local(@year, 3)) diff --git a/app/controllers/api/groups_controller.rb b/app/controllers/api/groups_controller.rb index bd516fc8d..d96da00b3 100644 --- a/app/controllers/api/groups_controller.rb +++ b/app/controllers/api/groups_controller.rb @@ -3,7 +3,7 @@ class Api::GroupsController < Api::BaseController def index render json: @groups, - scope: current_user, - include: ['messages', 'messages.user', 'group_user'] + scope: current_user, + include: ["messages", "messages.user", "group_user"] end end diff --git a/app/controllers/api/messages_controller.rb b/app/controllers/api/messages_controller.rb index 7ce41a72f..57463840f 100644 --- a/app/controllers/api/messages_controller.rb +++ b/app/controllers/api/messages_controller.rb @@ -8,9 +8,9 @@ def index reset_counter unless params.has_key?(:page) render json: @messages, - scope: @group.id, - meta: pagination_meta(@messages), - namespace: '' + scope: @group.id, + meta: pagination_meta(@messages), + namespace: "" end def create @@ -19,7 +19,7 @@ def create end def edit - render json: { content: @message.content } + render json: {content: @message.content} end def new_token diff --git a/app/controllers/api/notifications_controller.rb b/app/controllers/api/notifications_controller.rb index e147e46aa..064972cf8 100644 --- a/app/controllers/api/notifications_controller.rb +++ b/app/controllers/api/notifications_controller.rb @@ -7,7 +7,7 @@ def index end def unread - render json: { unread: current_user.notifications_count } + render json: {unread: current_user.notifications_count} end # This method is not really needed but removing it @@ -17,9 +17,9 @@ def look if @notification&.update(seen: true) current_user.reload - render json: { unread: current_user.notifications_count }, status: :ok + render json: {unread: current_user.notifications_count}, status: :ok else - render json: { errors: 'Failed to mark notification as read' }, status: 422 + render json: {errors: "Failed to mark notification as read"}, status: 422 end end @@ -28,7 +28,7 @@ def look_all current_user.update!(notifications_count: 0) render json: {}, status: :ok else - render json: { errors: 'Failed to mark all notifications as read' }, status: 422 + render json: {errors: "Failed to mark all notifications as read"}, status: 422 end end @@ -39,7 +39,7 @@ def visit current_user.reload render json: {}, status: :ok else - render json: { errors: 'Failed to mark notification as visited' }, status: 422 + render json: {errors: "Failed to mark notification as visited"}, status: 422 end end diff --git a/app/controllers/api/push_devices_controller.rb b/app/controllers/api/push_devices_controller.rb index 5918d41e6..aa63ef122 100644 --- a/app/controllers/api/push_devices_controller.rb +++ b/app/controllers/api/push_devices_controller.rb @@ -7,7 +7,7 @@ def create if @push_device render json: {}, status: :ok else - render json: { errors: 'Failed to create push device' }, status: 422 + render json: {errors: "Failed to create push device"}, status: 422 end end @@ -17,7 +17,7 @@ def destroy if @push_device && @push_device.destroy render json: {}, status: :ok else - render json: { errors: 'Failed to destroy push device' }, status: 422 + render json: {errors: "Failed to destroy push device"}, status: 422 end end diff --git a/app/controllers/api/songs_controller.rb b/app/controllers/api/songs_controller.rb index 168ac373d..da059fe6a 100644 --- a/app/controllers/api/songs_controller.rb +++ b/app/controllers/api/songs_controller.rb @@ -4,19 +4,19 @@ class Api::SongsController < Api::BaseController def index @songs = Song.order(title: :asc) render json: @songs, - each_serializer: Api::SongSerializer::Index # Returns id, title and author + each_serializer: Api::SongSerializer::Index # Returns id, title and author end -def show + def show @song = Song.find(params[:id]) Song.increment_counter(:visits, @song) render json: @song, - serializer: Api::SongSerializer::Show # Returns all relevant fields + serializer: Api::SongSerializer::Show # Returns all relevant fields end def chants - @chants = SongCategory.where(slug: 'chants').take.songs.order(author: :asc) + @chants = SongCategory.where(slug: "chants").take.songs.order(author: :asc) render json: @chants, - each_serializer: Api::SongSerializer::Index # Returns id, title and author + each_serializer: Api::SongSerializer::Index # Returns id, title and author end end diff --git a/app/controllers/api/start_controller.rb b/app/controllers/api/start_controller.rb index 688a85b1a..48c0a98f5 100644 --- a/app/controllers/api/start_controller.rb +++ b/app/controllers/api/start_controller.rb @@ -6,15 +6,15 @@ def index @unpinned = News.for_feed.unpinned.page(1).per(5) @events = Event.includes(:translations).stream - render json: { pinned: serialize(@pinned), - unpinned: serialize(@unpinned, meta: pagination_meta(@unpinned)), - events: serialize(@events, namespace: '') } + render json: {pinned: serialize(@pinned), + unpinned: serialize(@unpinned, meta: pagination_meta(@unpinned)), + events: serialize(@events, namespace: "")} end private def serialize(collection, namespace: :Api, meta: nil) - options = { meta: meta, namespace: namespace } + options = {meta: meta, namespace: namespace} ActiveModelSerializers::SerializableResource.new(collection, options) end end diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index c13359894..95ea34be2 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -7,7 +7,7 @@ def update if @user.update(user_params) render json: {}, status: :ok else - render json: { errors: @user.errors.full_messages }, status: 422 + render json: {errors: @user.errors.full_messages}, status: 422 end end @@ -19,9 +19,9 @@ def accept_terms def user_params params.require(:user).permit(:firstname, :lastname, :program, :start_year, - :avatar, :student_id, :phone, :display_phone, - :remove_avatar, :food_custom, :notify_messages, - :notify_event_users, :notify_event_closing, - :notify_event_open, food_preferences: []) + :avatar, :student_id, :phone, :display_phone, + :remove_avatar, :food_custom, :notify_messages, + :notify_event_users, :notify_event_closing, + :notify_event_open, food_preferences: []) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 26d9c31b4..d32240fab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base before_action :verify_terms_version, if: -> { !request.get? } helper_method :alert_update, :alert_create, :alert_destroy, - :can_administrate?, :authorize_admin! + :can_administrate?, :authorize_admin! include Alerts include InstanceAuthorization @@ -22,32 +22,32 @@ class ApplicationController < ActionController::Base end rescue_from ActiveRecord::RecordInvalid do |ex| - flash[:alert] = ex.record.errors.full_messages.join '; ' + flash[:alert] = ex.record.errors.full_messages.join "; " render referring_action, status: :unprocessable_entity end rescue_from ActiveRecord::RecordNotFound do # translate record not found -> HTTP 404 - fail ActionController::RoutingError.new 'not found' + fail ActionController::RoutingError.new "not found" end protected def prepare_meta_tags(options = {}) - site_name = I18n.t('global.title') - description = options[:description] || I18n.t('global.description') - image = options[:image] || view_context.image_url('sektionsmarke.png') + site_name = I18n.t("global.title") + description = options[:description] || I18n.t("global.description") + image = options[:image] || view_context.image_url("sektionsmarke.png") current_url = request.url defaults = { - site: site_name, - image: image, + site: site_name, + image: image, description: description, - keywords: I18n.t('global.keywords'), + keywords: I18n.t("global.keywords"), twitter: { site_name: site_name, - site: '@fsektionen', - card: 'summary', + site: "@fsektionen", + card: "summary", description: description, image: image }, @@ -56,7 +56,7 @@ def prepare_meta_tags(options = {}) site_name: site_name, image: image, description: description, - type: 'website', + type: "website", locale: I18n.locale.to_s } } @@ -68,9 +68,9 @@ def prepare_meta_tags(options = {}) def configure_permitted_devise_parameters devise_parameter_sanitizer.permit(:sign_in, keys: [:email, :password, :remember_me]) devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname, :lastname, :email, - :password, :password_confirmation]) + :password, :password_confirmation]) devise_parameter_sanitizer.permit(:account_update, keys: [:password, :current_password, - :password_confirmation]) + :password_confirmation]) end def set_locale @@ -95,7 +95,7 @@ def recache_menu # Ignore session cookies when we want to sign in with devise token auth! def devise_token_controller - params[:controller].split('/')[0] == 'devise_token_auth' + params[:controller].split("/")[0] == "devise_token_auth" end # Adds pagination meta data (from kaminari) to a serializer @@ -115,7 +115,7 @@ def pagination_meta(collection) # Get requests are handled in `applications.html` def verify_terms_version if current_user.present? && current_user.terms_version != Versions.get(:terms) - unless controller_name == 'users' || devise_controller? + unless controller_name == "users" || devise_controller? redirect_to root_path end end diff --git a/app/controllers/cafe_controller.rb b/app/controllers/cafe_controller.rb index 4fd022053..e9474f61d 100644 --- a/app/controllers/cafe_controller.rb +++ b/app/controllers/cafe_controller.rb @@ -11,10 +11,10 @@ def competition lp_current = CafeShift.order(start: :desc).first.try(:lp) || 1 lp = params[:lp] || lp_current - if can_administrate?(:edit, CafeShift) - amount = params[:amount] || 10 + amount = if can_administrate?(:edit, CafeShift) + params[:amount] || 10 else - amount = 10 + 10 end @competition = CafeCompetition.new(lp: lp, year: competition_year, amount: amount) @@ -23,10 +23,10 @@ def competition def ladybug authorize_admin!(:ladybug, :cafe) - if date = ladybug_date - @date = Time.zone.parse(date) + @date = if date = ladybug_date + Time.zone.parse(date) else - @date = Time.zone.now + Time.zone.now end @cafe_shifts = CafeQueries.for_day(@date) diff --git a/app/controllers/cafe_shifts_controller.rb b/app/controllers/cafe_shifts_controller.rb index 6d8ec2045..26817f93d 100644 --- a/app/controllers/cafe_shifts_controller.rb +++ b/app/controllers/cafe_shifts_controller.rb @@ -6,11 +6,11 @@ def show cafe_shift = CafeShift.find(params[:id]) cafe_shift.cafe_worker || cafe_shift.build_cafe_worker @cafe_view = CafeViewObject.new(shift: cafe_shift, - councils: Council.by_title) + councils: Council.by_title) end def feed - render json: CafeQueries.between(params[:start], params[:end]). - as_json(user: current_user) + render json: CafeQueries.between(params[:start], params[:end]) + .as_json(user: current_user) end end diff --git a/app/controllers/cafe_workers_controller.rb b/app/controllers/cafe_workers_controller.rb index 1891bf9e7..1ae3d839d 100644 --- a/app/controllers/cafe_workers_controller.rb +++ b/app/controllers/cafe_workers_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class CafeWorkersController < ApplicationController load_permissions_and_authorize_resource load_and_authorize_resource :cafe_shift, parent: true @@ -7,21 +6,21 @@ def new cafe_shift = CafeShift.find(params[:cafe_shift_id]) cafe_shift.cafe_worker || cafe_shift.build_cafe_worker @cafe_view = CafeViewObject.new(shift: cafe_shift, - councils: Council.by_title) - render template: '/cafe_shifts/show' + councils: Council.by_title) + render template: "/cafe_shifts/show" end def create cafe_shift = CafeShift.find(params[:cafe_shift_id]) cafe_shift.build_cafe_worker(cafe_worker_params) @cafe_view = CafeViewObject.new(shift: cafe_shift, - councils: Council.by_title) + councils: Council.by_title) if cafe_shift.cafe_worker.save redirect_to(cafe_shift_path(cafe_shift), - notice: I18n.t('model.cafe_worker.created')) + notice: I18n.t("model.cafe_worker.created")) else - render template: '/cafe_shifts/show', status: 422 + render template: "/cafe_shifts/show", status: 422 end end @@ -29,12 +28,12 @@ def update cafe_shift = CafeShift.find(params[:cafe_shift_id]) cafe_worker = CafeWorker.find(params[:id]) @cafe_view = CafeViewObject.new(shift: cafe_shift, - councils: Council.by_title) + councils: Council.by_title) if cafe_worker.update(cafe_worker_params) redirect_to(cafe_shift_path(cafe_shift), - notice: I18n.t('model.cafe_worker.updated')) + notice: I18n.t("model.cafe_worker.updated")) else - render template: '/cafe_shifts/show', status: 422 + render template: "/cafe_shifts/show", status: 422 end end @@ -45,7 +44,7 @@ def destroy if cafe_worker.destroy CafeMailer.destroy_email(user, cafe_shift).deliver_now redirect_to(cafe_shift_path(cafe_shift), - notice: I18n.t('model.cafe_worker.destroyed')) + notice: I18n.t("model.cafe_worker.destroyed")) else redirect_to(cafe_shift_path(cafe_shift)) end diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index b20ad939d..9f54a8f76 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -15,8 +15,8 @@ def index end def export - events = Event.by_locale(locale: I18n.locale). - after_date(after_date) + events = Event.by_locale(locale: I18n.locale) + .after_date(after_date) calendar = CalendarService.export(events, locale: locale) respond_to do |format| diff --git a/app/controllers/concerns/alerts.rb b/app/controllers/concerns/alerts.rb index c679124ba..b184a69da 100644 --- a/app/controllers/concerns/alerts.rb +++ b/app/controllers/concerns/alerts.rb @@ -7,29 +7,29 @@ def model_name(model) end def alert_update(resource) - { text: %(#{model_name(resource)} #{I18n.t('global_controller.success_update')}.), - type: 'success' } + {text: %(#{model_name(resource)} #{I18n.t("global_controller.success_update")}.), + type: "success"} end def alert_create(resource) - { text: %(#{model_name(resource)} #{I18n.t('global_controller.success_create')}.), - type: 'success' } + {text: %(#{model_name(resource)} #{I18n.t("global_controller.success_create")}.), + type: "success"} end def alert_destroy(resource) - { text: %(#{model_name(resource)} #{I18n.t('global_controller.success_destroy')}.), - type: 'danger' } + {text: %(#{model_name(resource)} #{I18n.t("global_controller.success_destroy")}.), + type: "danger"} end def alert_errors(errors) - { errors: errors, type: 'errors' } + {errors: errors, type: "errors"} end def alert_success(message) - { text: message, type: 'success' } + {text: message, type: "success"} end def alert_danger(message) - { text: message, type: 'danger' } + {text: message, type: "danger"} end end diff --git a/app/controllers/concerns/controller_authorization.rb b/app/controllers/concerns/controller_authorization.rb index c39c1bac0..9e062569d 100644 --- a/app/controllers/concerns/controller_authorization.rb +++ b/app/controllers/concerns/controller_authorization.rb @@ -1,7 +1,9 @@ # Module for controller authorzation methods module ControllerAuthorization def permission - name.gsub('Controller', '').singularize.split('::').last.constantize.name rescue nil + name.gsub("Controller", "").singularize.split("::").last.constantize.name + rescue + nil end # Enables authentication and diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 9b053ab22..ff4f58d0b 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -5,12 +5,12 @@ class ContactsController < ApplicationController def index # @contacts initially set by Cancancan @councils = {} - @councils['Styrelsen'] = [] - @councils['Övriga'] = [] + @councils["Styrelsen"] = [] + @councils["Övriga"] = [] @contacts = @contacts.includes(:post).sort_by(&:to_s) @contacts.each do |contact| if contact.post.nil? - @councils['Övriga'].push(contact) + @councils["Övriga"].push(contact) else @councils[contact.post.council.title] = [] if @councils[contact.post.council.title].nil? @@ -25,9 +25,9 @@ def index # Hacky shit to move 'Ovriga' to last # This whole thing should have a proper sort method # But too much effort for too little gain for me atm - misc = @councils['Övriga'] - @councils = @councils.except('Övriga') - @councils['Övriga'] = misc + misc = @councils["Övriga"] + @councils = @councils.except("Övriga") + @councils["Övriga"] = misc end def show @@ -39,9 +39,9 @@ def mail @contact = Contact.find(params[:id]) @contact.message ||= ContactMessage.new(message_params) if verify_recaptcha(model: @contact, attribute: :recaptcha) && @contact.send_email - redirect_to contact_path(@contact), notice: t('model.contact.message_sent') + redirect_to contact_path(@contact), notice: t("model.contact.message_sent") else - flash[:alert] = t('model.contact.something_wrong') + flash[:alert] = t("model.contact.something_wrong") render :show, status: 422 end end diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index b75e347d5..e9d70f767 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -4,20 +4,20 @@ class DocumentsController < ApplicationController def index documents = set_documents(params[:category]) - grid = initialize_grid(documents, order: 'documents.updated_at', - order_direction: 'desc') + grid = initialize_grid(documents, order: "documents.updated_at", + order_direction: "desc") @documents = DocumentView.new(grid: grid, - categories: Document.categories, - current_category: params[:category]) + categories: Document.categories, + current_category: params[:category]) end def show document = Document.find(params[:id]) send_file(document.pdf.path, - filename: document.pdf_file_name, - type: 'application/pdf', - disposition: 'inline', - x_sendfile: true) + filename: document.pdf_file_name, + type: "application/pdf", + disposition: "inline", + x_sendfile: true) end private diff --git a/app/controllers/elections/candidates_controller.rb b/app/controllers/elections/candidates_controller.rb index a185a7ccc..85bfd8a7c 100644 --- a/app/controllers/elections/candidates_controller.rb +++ b/app/controllers/elections/candidates_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class Elections::CandidatesController < ApplicationController load_permissions_and_authorize_resource before_action :set_election @@ -27,7 +26,7 @@ def create if ElectionService.create_candidate(@election_view.candidate, current_user) redirect_to candidates_path, - notice: alert_create(Candidate) + notice: alert_create(Candidate) else render :new, status: 422 end @@ -39,7 +38,7 @@ def destroy redirect_to candidates_path, notice: alert_destroy(Candidate) else redirect_to candidates_path, - notice: %(#{model_name(Candidate)} #{t('model.candidate.not_allowed_to_destroy')}.) + notice: %(#{model_name(Candidate)} #{t("model.candidate.not_allowed_to_destroy")}.) end end @@ -48,7 +47,7 @@ def destroy def set_election @election = Election.current if @election.nil? - render '/elections/no_election', status: 404 + render "/elections/no_election", status: 404 else @election end diff --git a/app/controllers/elections/nominations_controller.rb b/app/controllers/elections/nominations_controller.rb index 114c1e2fb..7f7218129 100644 --- a/app/controllers/elections/nominations_controller.rb +++ b/app/controllers/elections/nominations_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class Elections::NominationsController < ApplicationController load_permissions_and_authorize_resource before_action :set_election @@ -27,7 +26,7 @@ def create def set_election @election = Election.current if @election.nil? - render '/elections/no_election', status: 404 + render "/elections/no_election", status: 404 else @election end diff --git a/app/controllers/elections_controller.rb b/app/controllers/elections_controller.rb index cbbc4146c..48979241d 100644 --- a/app/controllers/elections_controller.rb +++ b/app/controllers/elections_controller.rb @@ -7,23 +7,23 @@ def index if election.present? @election_view = ElectionView.new(election) @election_view.grid = initialize_grid(election.current_posts, - name: :main, - per_page: 70, - locale: I18n.locale, - include: [council: :translations], - order: 'post_translations.title') + name: :main, + per_page: 70, + locale: I18n.locale, + include: [council: :translations], + order: "post_translations.title") @count = election.post_count if election.after_posts.any? @election_view.rest_grid = initialize_grid(election.after_posts, - name: :rest, - per_page: 70, - locale: I18n.locale, - include: [council: :translations], - order: 'post_translations.title') + name: :rest, + per_page: 70, + locale: I18n.locale, + include: [council: :translations], + order: "post_translations.title") end else - render '/elections/no_election' + render "/elections/no_election" end end end diff --git a/app/controllers/gallery/albums_controller.rb b/app/controllers/gallery/albums_controller.rb index 128e6083e..2db0192f4 100644 --- a/app/controllers/gallery/albums_controller.rb +++ b/app/controllers/gallery/albums_controller.rb @@ -4,7 +4,7 @@ class Gallery::AlbumsController < ApplicationController def show @album = Album.include_for_gallery.includes(:photographers).find(params[:id]) - @policy = Document.find_by(slug: 'gallery_policy') + @policy = Document.find_by(slug: "gallery_policy") @start = params.fetch(:start, 0).to_i end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index d3ce5cd9b..e210b8524 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -5,8 +5,8 @@ def index @introduction = Introduction.find_by(id: params[:introduction_id]) || Introduction.current @introductions = Introduction.all_except(@introduction) @grid = initialize_grid(Group.regular.where(introduction: @introduction), - include: :users, - order: 'number') + include: :users, + order: "number") end def show diff --git a/app/controllers/introductions_controller.rb b/app/controllers/introductions_controller.rb index 232deb407..1f0bdbef4 100644 --- a/app/controllers/introductions_controller.rb +++ b/app/controllers/introductions_controller.rb @@ -4,11 +4,11 @@ class IntroductionsController < ApplicationController def index @news = News.for_feed.slug(:nollning).limit(5) - @contact = Contact.find_by(slug: 'foset') + @contact = Contact.find_by(slug: "foset") end def dance - @constant = Constant.find_by_name('nollning-video') + @constant = Constant.find_by_name("nollning-video") end def show @@ -31,9 +31,9 @@ def dynamic_matrix cookie = cookies[:hide_matrix] if param.present? && param != cookie - cookies[:hide_matrix] = { value: param, expires_in: 20.days.from_now } - flash[:notice] = I18n.t('model.introduction.matrix.hidden') if param == 'true' - flash[:notice] ||= I18n.t('model.introduction.matrix.shown') + cookies[:hide_matrix] = {value: param, expires_in: 20.days.from_now} + flash[:notice] = I18n.t("model.introduction.matrix.hidden") if param == "true" + flash[:notice] ||= I18n.t("model.introduction.matrix.shown") end end @@ -59,10 +59,8 @@ def set_introduction end def date - begin - Date.strptime(%({#{params[:date]}}), '{%Y-%m-%d}') - rescue - Date.today - end + Date.strptime(%({#{params[:date]}}), "{%Y-%m-%d}") + rescue + Date.today end end diff --git a/app/controllers/meetings_controller.rb b/app/controllers/meetings_controller.rb index 7cdc4c940..79b6c9de0 100644 --- a/app/controllers/meetings_controller.rb +++ b/app/controllers/meetings_controller.rb @@ -55,11 +55,11 @@ def destroy def meeting_params params.require(:meeting).permit(:start_date, :end_date, :title, :purpose, - :room, :council_id) + :room, :council_id) end def load_room - @room = params.fetch(:room, 'sk') + @room = params.fetch(:room, "sk") end def set_room diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 9c2fc5ef2..e4f0ee82e 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -10,17 +10,17 @@ def index reset_counter unless params.has_key?(:page) render json: @messages, - scope: @group.id, - meta: pagination_meta(@messages) + scope: @group.id, + meta: pagination_meta(@messages) end def download_image - if params[:size] == 'original' - send_file @message.image.url, disposition: 'inline' - elsif params[:size] == 'large' - send_file @message.image.large.url, disposition: 'inline' + if params[:size] == "original" + send_file @message.image.url, disposition: "inline" + elsif params[:size] == "large" + send_file @message.image.large.url, disposition: "inline" else - send_file @message.image.thumb.url, disposition: 'inline' + send_file @message.image.thumb.url, disposition: "inline" end end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 4f80b02ed..acb73f0ba 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -8,9 +8,9 @@ def index def look_all if current_user.notifications.not_seen.update_all(seen: true) current_user.update!(notifications_count: 0) - render json: { unread: current_user.notifications_count }, status: :ok + render json: {unread: current_user.notifications_count}, status: :ok else - render json: { errors: 'Failed to mark all notifications as read' }, status: 422 + render json: {errors: "Failed to mark all notifications as read"}, status: 422 end end @@ -21,7 +21,7 @@ def visit current_user.reload render json: {}, status: :ok else - render json: { errors: 'Failed to visit notification' }, status: 422 + render json: {errors: "Failed to visit notification"}, status: 422 end end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 2731c2716..128b44d91 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class PagesController < ApplicationController load_permissions_and_authorize_resource find_by: :url @@ -10,14 +9,14 @@ def show def set_page if current_user.try(:member?) - Page.includes(:page_elements). - visible. - find_by!(url: params[:id]) + Page.includes(:page_elements) + .visible + .find_by!(url: params[:id]) else - Page.includes(:page_elements). - visible. - publik. - find_by!(url: params[:id]) + Page.includes(:page_elements) + .visible + .publik + .find_by!(url: params[:id]) end end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d782e4754..8b767ff78 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 class PostsController < ApplicationController load_permissions_and_authorize_resource before_action :set_election @@ -20,7 +19,7 @@ def modal def set_election @election = Election.current if @election.nil? - render '/elections/no_election', status: 404 + render "/elections/no_election", status: 404 else @election end diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index a6a96ca74..eacea2f94 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -1,7 +1,7 @@ class ProposalsController < ApplicationController def form @proposal = Proposal.new - @proposal.points = [''] + @proposal.points = [""] end def generate diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index e72945cb4..2626d9032 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -3,7 +3,7 @@ def create if !verify_recaptcha build_resource(sign_up_params) resource.valid? - resource.errors.add(:recaptcha, t('model.user.recaptcha_error')) + resource.errors.add(:recaptcha, t("model.user.recaptcha_error")) clean_up_passwords(resource) respond_with_navigational(resource) { render :new } else diff --git a/app/controllers/rents_controller.rb b/app/controllers/rents_controller.rb index c645eb0d9..29aa2df38 100644 --- a/app/controllers/rents_controller.rb +++ b/app/controllers/rents_controller.rb @@ -5,7 +5,7 @@ class RentsController < ApplicationController def index respond_to do |format| format.html do - @faqs = Faq.answered.category('Bil') + @faqs = Faq.answered.category("Bil") end format.json do @@ -53,10 +53,10 @@ def overview def rent_params params.require(:rent).permit(:d_from, :d_til, :purpose, - :council_id, :user_id, :terms) + :council_id, :user_id, :terms) end def load_terms - @terms = Document.find_by(slug: 'rental-terms') + @terms = Document.find_by(slug: "rental-terms") end end diff --git a/app/controllers/short_links_controller.rb b/app/controllers/short_links_controller.rb index 0d0342679..64309beaa 100644 --- a/app/controllers/short_links_controller.rb +++ b/app/controllers/short_links_controller.rb @@ -1,11 +1,10 @@ class ShortLinksController < ApplicationController - def go redirect_to ShortLink.lookup(params[:link]).target, status: 301 end def check - if ShortLink.where('link = ?', params[:link]).exists? + if ShortLink.where("link = ?", params[:link]).exists? head :no_content else head :not_found diff --git a/app/controllers/songs_controller.rb b/app/controllers/songs_controller.rb index 4493a28a4..44d547c0b 100644 --- a/app/controllers/songs_controller.rb +++ b/app/controllers/songs_controller.rb @@ -2,7 +2,7 @@ class SongsController < ApplicationController load_permissions_and_authorize_resource def index - @songs = initialize_grid(Song.all, order: 'title', order_direction: 'asc') + @songs = initialize_grid(Song.all, order: "title", order_direction: "asc") end def show diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 3db95135f..21428d558 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -18,7 +18,7 @@ def influence end def robots - render :robots, content_type: 'text/plain' + render :robots, content_type: "text/plain" end def privacy diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 88d55366a..f69314751 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,10 +22,10 @@ def update def update_account @tab = :account if current_user.update_with_password(account_params) - flash[:notice] = t('model.user.account_updated') + flash[:notice] = t("model.user.account_updated") render :edit, status: 200 else - flash[:alert] = t('model.user.password_required') + flash[:alert] = t("model.user.password_required") render :edit, status: 422 end end @@ -33,28 +33,28 @@ def update_account def update_password @tab = :password if current_user.update_with_password(password_params) - flash[:notice] = t('model.user.password_updated') + flash[:notice] = t("model.user.password_updated") bypass_sign_in(current_user) render :edit, status: 200 else - flash[:alert] = t('model.user.password_required') + flash[:alert] = t("model.user.password_required") render :edit, status: 422 end end def accept_terms current_user.update!(terms_version: Versions.get(:terms)) - redirect_to root_path, notice: t('model.user.terms_accepted') + redirect_to root_path, notice: t("model.user.terms_accepted") end private def user_params params.require(:user).permit(:firstname, :lastname, :program, :start_year, - :avatar, :student_id, :phone, :display_phone, - :remove_avatar, :food_custom, :notify_messages, - :notify_event_users, :notify_event_closing, - :notify_event_open, food_preferences: []) + :avatar, :student_id, :phone, :display_phone, + :remove_avatar, :food_custom, :notify_messages, + :notify_event_users, :notify_event_closing, + :notify_event_open, food_preferences: []) end def account_params diff --git a/app/helpers/admin/event_signups_helper.rb b/app/helpers/admin/event_signups_helper.rb index 48a1b6214..38efb3c8c 100644 --- a/app/helpers/admin/event_signups_helper.rb +++ b/app/helpers/admin/event_signups_helper.rb @@ -2,36 +2,36 @@ module Admin::EventSignupsHelper def food_preferences_button(parameters, event) if parameters.present? && event.try(:food?) if show_food_preferences(parameters) - link_to(t('.hide_food_preferences'), allowed_params.merge(food: false, tab: :attendees), - class: 'btn secondary') + link_to(t(".hide_food_preferences"), allowed_params.merge(food: false, tab: :attendees), + class: "btn secondary") else - link_to(t('.show_food_preferences'), allowed_params.merge(food: true, tab: :attendees), - class: 'btn secondary') + link_to(t(".show_food_preferences"), allowed_params.merge(food: true, tab: :attendees), + class: "btn secondary") end end end def answers_button(parameters, event) if parameters.present? && - event.present? && - event.signup.present? && - event.signup.question.present? + event.present? && + event.signup.present? && + event.signup.question.present? if show_answers(parameters) - link_to(t('.hide_answer'), allowed_params.merge(answer: false, tab: :attendees), - class: 'btn secondary') + link_to(t(".hide_answer"), allowed_params.merge(answer: false, tab: :attendees), + class: "btn secondary") else - link_to(t('.show_answer'), allowed_params.merge(answer: true, tab: :attendees), - class: 'btn secondary') + link_to(t(".show_answer"), allowed_params.merge(answer: true, tab: :attendees), + class: "btn secondary") end end end def show_answers(parameters) - parameters.fetch(:answer, 'false') == 'true' + parameters.fetch(:answer, "false") == "true" end def show_food_preferences(parameters) - parameters.fetch(:food, 'false') == 'true' + parameters.fetch(:food, "false") == "true" end def event_signup_reminders_sent?(signup) @@ -39,34 +39,34 @@ def event_signup_reminders_sent?(signup) content = [] if signup.sent_position.present? - content << content_tag(:span, class: 'position-reminder') do - safe_join([icon('fas', 'bell'), - I18n.t('model.event_signup.position_reminder_was_sent', - date: localize(signup.sent_position))]) + content << content_tag(:span, class: "position-reminder") do + safe_join([icon("fas", "bell"), + I18n.t("model.event_signup.position_reminder_was_sent", + date: localize(signup.sent_position))]) end end if signup.sent_reminder.present? - content << content_tag(:span, class: 'event-reminder') do - safe_join([icon('fas', 'bell'), - I18n.t('model.event_signup.reminder_was_sent', - date: localize(signup.sent_reminder))]) + content << content_tag(:span, class: "event-reminder") do + safe_join([icon("fas", "bell"), + I18n.t("model.event_signup.reminder_was_sent", + date: localize(signup.sent_reminder))]) end end if signup.sent_closing.present? - content << content_tag(:span, class: 'event-reminder') do - safe_join([icon('fas', 'bell'), - I18n.t('model.event_signup.closing_was_sent', - date: localize(signup.sent_closing))]) + content << content_tag(:span, class: "event-reminder") do + safe_join([icon("fas", "bell"), + I18n.t("model.event_signup.closing_was_sent", + date: localize(signup.sent_closing))]) end end if signup.sent_open.present? - content << content_tag(:span, class: 'event-reminder') do - safe_join([icon('fas', 'bell'), - I18n.t('model.event_signup.open_was_sent', - date: localize(signup.sent_open))]) + content << content_tag(:span, class: "event-reminder") do + safe_join([icon("fas", "bell"), + I18n.t("model.event_signup.open_was_sent", + date: localize(signup.sent_open))]) end end diff --git a/app/helpers/admin/pages_helper.rb b/app/helpers/admin/pages_helper.rb index 374bac385..23e7dd491 100644 --- a/app/helpers/admin/pages_helper.rb +++ b/app/helpers/admin/pages_helper.rb @@ -1,6 +1,6 @@ module Admin::PagesHelper def page_element_types - [[t('model.page_element.text'), PageElement::TEXT], - [t('model.page_element.image'), PageElement::IMAGE]] + [[t("model.page_element.text"), PageElement::TEXT], + [t("model.page_element.image"), PageElement::IMAGE]] end end diff --git a/app/helpers/adventure_helper.rb b/app/helpers/adventure_helper.rb index 3ed697ce4..ce83169a8 100644 --- a/app/helpers/adventure_helper.rb +++ b/app/helpers/adventure_helper.rb @@ -1,5 +1,5 @@ module AdventureHelper def adventure_info(adventure) - "#{date_range(adventure.start_date, adventure.end_date)}" + date_range(adventure.start_date, adventure.end_date).to_s end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0aa367fae..4d8ba3087 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,9 +1,9 @@ module ApplicationHelper def yes_no(value) if value - I18n.t('global.yes') + I18n.t("global.yes") else - I18n.t('global.no') + I18n.t("global.no") end end @@ -21,29 +21,29 @@ def models_name(model) def form_group &block html = Nokogiri::HTML.fragment(capture(&block)) - html.xpath('input|textarea').each do |e| - if e['class'] - e['class'] += ' form-control ' + html.xpath("input|textarea").each do |e| + if e["class"] + e["class"] += " form-control " else - e['class'] = 'form-control ' + e["class"] = "form-control " end end - content_tag :div, raw(html.to_html), class: 'form-group' + content_tag :div, raw(html.to_html), class: "form-group" end def responsive_video(url) if url.present? - content_tag(:div, class: 'responsive-video') do - content_tag(:iframe, '', src: url, frameborder: 0) + content_tag(:div, class: "responsive-video") do + content_tag(:iframe, "", src: url, frameborder: 0) end end end def active_list_group(first, second) if first == second - 'list-group-item active' + "list-group-item active" else - 'list-group-item' + "list-group-item" end end end diff --git a/app/helpers/blog_posts_helper.rb b/app/helpers/blog_posts_helper.rb index 3b6762456..e1b1dde57 100644 --- a/app/helpers/blog_posts_helper.rb +++ b/app/helpers/blog_posts_helper.rb @@ -1,7 +1,7 @@ module BlogPostsHelper def blog_post_dropdown_button(collection:, current:) content = safe_join([category_button(current), blog_posts_collection(collection)]) - content_tag(:div, content, class: 'dropdown') + content_tag(:div, content, class: "dropdown") end def blog_posts_collection(collection) @@ -19,12 +19,12 @@ def blog_post_category_link(category) def blog_post_translated?(blog_post) unless blog_post.is_translated?(I18n.locale) - content_tag(:div, class: 'alert alert-info') do + content_tag(:div, class: "alert alert-info") do content = [] - content << content_tag(:button, icon('fas', 'times'), - type: 'button', class: 'close', - data: { dismiss: 'alert' }) - content << I18n.t('model.blog_post.not_translated') + content << content_tag(:button, icon("fas", "times"), + type: "button", class: "close", + data: {dismiss: "alert"}) + content << I18n.t("model.blog_post.not_translated") safe_join(content) end end @@ -43,7 +43,7 @@ def blog_title(blog_post, meta: false, link: false) end def blog_cover_image(url) - content_tag(:div, '', class: 'cover-image', + content_tag(:div, "", class: "cover-image", style: "background: url('#{url}') no-repeat center center; background-size: contain;") end end diff --git a/app/helpers/cafe_helper.rb b/app/helpers/cafe_helper.rb index d8148d3c7..fe558f5e6 100644 --- a/app/helpers/cafe_helper.rb +++ b/app/helpers/cafe_helper.rb @@ -2,8 +2,8 @@ module CafeHelper def cafe_worker_form(shift:, current_user: nil, councils: []) if shift.worker?(current_user) || !shift.user.present? content_tag(:tr) do - content_tag(:td, colspan: '2') do - render('cafe_workers/form', cafe_shift: shift, + content_tag(:td, colspan: "2") do + render("cafe_workers/form", cafe_shift: shift, councils: councils) end end @@ -17,23 +17,24 @@ def cafe_worker_form(shift:, current_user: nil, councils: []) def cafe_worker_working_thumbs(worker, user:) if user == worker.user && worker.persisted? - content_tag(:span, class: 'cafe working') do - safe_join([icon('far', 'thumbs-up'), ' ', - I18n.t('helper.cafe.worker.you_are_working')]) + content_tag(:span, class: "cafe working") do + safe_join([icon("far", "thumbs-up"), " ", + I18n.t("helper.cafe.worker.you_are_working")]) end end end def cafe_worker_edit_user(worker) if worker.present? && - worker.errors[:user].include?(I18n.t('model.user.attributes_missing')) - link_to(I18n.t('model.user.edit_information'), - edit_own_user_path, - class: 'btn danger small', - target: :blank_p) + worker.errors[:user].include?(I18n.t("model.user.attributes_missing")) + link_to(I18n.t("model.user.edit_information"), + edit_own_user_path, + class: "btn danger small", + target: :blank_p) end end + def pass_collection - [['2 timmar', 2], ['3 timmar', 3], ['1 timme', 1]] + [["2 timmar", 2], ["3 timmar", 3], ["1 timme", 1]] end end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index 53b59b2c2..40c0ef8a3 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -1,25 +1,25 @@ module CategoriesHelper def category_button(current) - content = safe_join([category_button_text(current), ' ', - content_tag(:span, '', class: 'caret')]) - content_tag(:button, content, class: 'btn primary dropdown-toggle', - id: 'category_dropdown', type: 'button', - data: { toggle: 'dropdown' }, - aria: { haspopup: 'true', expanded: 'true' }) + content = safe_join([category_button_text(current), " ", + content_tag(:span, "", class: "caret")]) + content_tag(:button, content, class: "btn primary dropdown-toggle", + id: "category_dropdown", type: "button", + data: {toggle: "dropdown"}, + aria: {haspopup: "true", expanded: "true"}) end def category_collection(categories, index_path) - categories = categories.unshift(content_tag(:li, link_to(t('helper.categories.all'), - index_path))) - content_tag(:ul, safe_join(categories), class: 'dropdown-menu', - aria: { labelled_by: 'category_dropdown' }) + categories = categories.unshift(content_tag(:li, link_to(t("helper.categories.all"), + index_path))) + content_tag(:ul, safe_join(categories), class: "dropdown-menu", + aria: {labelled_by: "category_dropdown"}) end def category_button_text(category) if category.present? category else - I18n.t('helper.categories.title') + I18n.t("helper.categories.title") end end diff --git a/app/helpers/contact_helper.rb b/app/helpers/contact_helper.rb index 8e7c84c39..04c3f2890 100644 --- a/app/helpers/contact_helper.rb +++ b/app/helpers/contact_helper.rb @@ -1,7 +1,7 @@ module ContactHelper def contact_link(contact) if contact.present? - text = safe_join([icon('fas', 'envelope'), ' ', contact.full_string]) + text = safe_join([icon("fas", "envelope"), " ", contact.full_string]) link_to(text, contact_path(contact)) end end @@ -17,11 +17,11 @@ def number_from_slug(slug:) def contact_image(contact) if contact.avatar.present? - image_tag(contact.avatar.large.url, class: 'img-responsive') + image_tag(contact.avatar.large.url, class: "img-responsive") elsif contact_single_user(contact) - image_tag(contact.post.users.first.large_avatar, class: 'img-responsive') + image_tag(contact.post.users.first.large_avatar, class: "img-responsive") else - image_tag('missing_thumb.png', class: 'img-responsive') + image_tag("missing_thumb.png", class: "img-responsive") end end diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index 60727d1f0..e54232fd9 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -4,10 +4,9 @@ module DocumentsHelper # Uses category button from CategoriesHelper to render the whole button def document_dropdown_button(collection:, current:) content = safe_join([category_button(current), document_collection(collection)]) - content_tag(:div, content, class: 'dropdown') + content_tag(:div, content, class: "dropdown") end - # Returns the collection of links fomr the CategoriesHelper.category_collection # Uses the index path to add a button for clearing query def document_collection(collection) diff --git a/app/helpers/election_helper.rb b/app/helpers/election_helper.rb index 6ac3773ef..885810e57 100644 --- a/app/helpers/election_helper.rb +++ b/app/helpers/election_helper.rb @@ -3,18 +3,18 @@ def election_meta_description(election) if election.description.present? markdown_plain(election.description) else - t('.description') + t(".description") end end def candidate_and_nominate_buttons(post) if post.present? - candidate = link_to(I18n.t('helper.election.new_candidate'), - new_candidate_path(post: post.id.to_s), - class: 'btn primary') - nomination = link_to(I18n.t('helper.election.new_nomination'), - new_nominations_path(post: post.id.to_s), - class: 'btn primary') + candidate = link_to(I18n.t("helper.election.new_candidate"), + new_candidate_path(post: post.id.to_s), + class: "btn primary") + nomination = link_to(I18n.t("helper.election.new_nomination"), + new_nominations_path(post: post.id.to_s), + class: "btn primary") safe_join([candidate, nomination]) end end @@ -22,11 +22,11 @@ def candidate_and_nominate_buttons(post) def election_post_link(post) if post.present? title = content_tag(:span, post.title) - show = link_to(post_path(post), target: :blank, class: 'links') do - icon('fas', 'external-link-alt') + show = link_to(post_path(post), target: :blank, class: "links") do + icon("fas", "external-link-alt") end - modal = link_to(modal_post_path(post), remote: true, class: 'links') do - icon('far', 'object-group') + modal = link_to(modal_post_path(post), remote: true, class: "links") do + icon("far", "object-group") end safe_join([show, modal, title]) end diff --git a/app/helpers/election_mailer_helper.rb b/app/helpers/election_mailer_helper.rb index 4b9f52b6c..7929b13bd 100644 --- a/app/helpers/election_mailer_helper.rb +++ b/app/helpers/election_mailer_helper.rb @@ -12,7 +12,7 @@ def candidate_mail_link(candidate) def candidate_mail_link_html(candidate) text = candidate_mail_link(candidate) if text.present? - link_to(t('model.candidate.book_interview'), text, class: 'btn primary') + link_to(t("model.candidate.book_interview"), text, class: "btn primary") end end end diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb index a74c7303d..e6a0cb5b7 100644 --- a/app/helpers/email_helper.rb +++ b/app/helpers/email_helper.rb @@ -1,19 +1,19 @@ module EmailHelper def inline_css(asset_path) - if %w(development test).include?(Rails.env.to_s) + if %w[development test].include?(Rails.env.to_s) file = Rails.application.assets.find_asset(asset_path) file.source if file.present? else file = find_css_asset(asset_path) - File.read(File.join(Rails.root, 'public', 'assets', file)) if file.present? + File.read(File.join(Rails.root, "public", "assets", file)) if file.present? end end def find_css_asset(asset_path) # Find precompiled asset in production and staging file = Rails.application.assets_manifest.assets[asset_path] - file ||= Rails.application.assets_manifest. - assets["#{File.basename(asset_path, File.extname(asset_path))}.css"] + file ||= Rails.application.assets_manifest + .assets["#{File.basename(asset_path, File.extname(asset_path))}.css"] file end end diff --git a/app/helpers/event_helper.rb b/app/helpers/event_helper.rb index d449e90b1..19656b5dd 100644 --- a/app/helpers/event_helper.rb +++ b/app/helpers/event_helper.rb @@ -1,63 +1,63 @@ module EventHelper def event_stream_date(event) if event.present? - I18n.l(event.starts_at, format: ' %H:%M') + I18n.l(event.starts_at, format: " %H:%M") end end def event_attendees(event) content = [] content << content_tag(:li) do - safe_join([icon('fas', 'user'), " #{I18n.t('model.event.attending')}: #{EventUser.attending_count(event)}"]) + safe_join([icon("fas", "user"), " #{I18n.t("model.event.attending")}: #{EventUser.attending_count(event)}"]) end content << content_tag(:li) do - safe_join([icon('fas', 'users'), " #{EventSignup.human_attribute_name(:slots)}: #{event.signup.slots}"]) + safe_join([icon("fas", "users"), " #{EventSignup.human_attribute_name(:slots)}: #{event.signup.slots}"]) end reserves = EventUser.reserve_count(event) if reserves > 0 content << content_tag(:li) do - safe_join([icon('fas', 'user-times'), " #{I18n.t('model.event.reserves')}: #{reserves}"]) + safe_join([icon("fas", "user-times"), " #{I18n.t("model.event.reserves")}: #{reserves}"]) end end content << content_tag(:li) do - safe_join([icon('fas', 'calendar-check'), - " #{EventSignup.human_attribute_name(:opens)}: #{l(event.signup.opens, format: :short)}"]) + safe_join([icon("fas", "calendar-check"), + " #{EventSignup.human_attribute_name(:opens)}: #{l(event.signup.opens, format: :short)}"]) end content << content_tag(:li) do - safe_join([icon('fas', 'calendar-times'), - " #{EventSignup.human_attribute_name(:closes)}: #{l(event.signup.closes, format: :short)}"]) + safe_join([icon("fas", "calendar-times"), + " #{EventSignup.human_attribute_name(:closes)}: #{l(event.signup.closes, format: :short)}"]) end - content_tag(:span, content_tag(:ul, safe_join(content)), class: 'event info') + content_tag(:span, content_tag(:ul, safe_join(content)), class: "event info") end def event_reg_status(event_signup, event_user) if event_user.persisted? persisted_event_user_status(event_signup, event_user) else - event_status_span('not-attending lg', 'fas', 'exclamation-circle', t('.not_attending')) + event_status_span("not-attending lg", "fas", "exclamation-circle", t(".not_attending")) end end def persisted_event_user_status(event_signup, event_user) if event_signup.closed? if event_user.reserve? - event_status_span('reserve lg', 'fas', 'exclamation-circle', t('.reserve')) + event_status_span("reserve lg", "fas", "exclamation-circle", t(".reserve")) else - event_status_span('attending lg', 'fas', 'check-circle', t('.attending')) + event_status_span("attending lg", "fas", "check-circle", t(".attending")) end else - event_status_span('registered lg', 'fas', 'question-circle', t('.registered')) + event_status_span("registered lg", "fas", "question-circle", t(".registered")) end end def event_status_span(status, icon_prefix, icon, text) content_tag(:span, class: "event #{status}") do - icon(icon_prefix, icon) + ' ' + text + icon(icon_prefix, icon) + " " + text end end @@ -65,13 +65,13 @@ def event_reg_logged_in_or_member(event, user) content = [] if event.try(:signup) if user.nil? - content << I18n.t('helper.event.need_to_sign_in') + content << I18n.t("helper.event.need_to_sign_in") elsif !user.member? && event.signup.for_members - content << I18n.t('helper.event.membership_required') + content << I18n.t("helper.event.membership_required") content << contact_from_slug(slug: :spindelman) end - content_tag(:span, safe_join(content), class: 'event not-registered') if content.any? + content_tag(:span, safe_join(content), class: "event not-registered") if content.any? end end @@ -79,7 +79,7 @@ def event_user_type(event_signup, type) if type == EventSignup::CUSTOM event_signup.custom_name elsif type.blank? - I18n.t('model.event_signup.user_types.other') + I18n.t("model.event_signup.user_types.other") else I18n.t("model.event_signup.user_types.#{type}") end @@ -89,7 +89,7 @@ def event_user_types(event_signup, user, include_other: true) types = map_event_user_types(event_signup, event_signup.selectable_types(user)) if include_other - types << [t('model.event_signup.user_types.other'), ''] + types << [t("model.event_signup.user_types.other"), ""] end types @@ -107,19 +107,19 @@ def map_event_user_types(event_signup, types) def event_user_groups(event_signup, user) groups = user.groups.merge(event_signup.selectable_groups).pluck(:name, :id) - groups << ['', nil] + groups << ["", nil] end def dress_codes(event) - event.dress_code.join(I18n.t('helper.event.or')) + event.dress_code.join(I18n.t("helper.event.or")) end def dress_code_collection - [I18n.t('model.event.dress_codes.overall'), - I18n.t('model.event.dress_codes.theme'), - I18n.t('model.event.dress_codes.formal'), - I18n.t('model.event.dress_codes.dark_suit'), - I18n.t('model.event.dress_codes.white_tie')] + [I18n.t("model.event.dress_codes.overall"), + I18n.t("model.event.dress_codes.theme"), + I18n.t("model.event.dress_codes.formal"), + I18n.t("model.event.dress_codes.dark_suit"), + I18n.t("model.event.dress_codes.white_tie")] end def group_str(event_user) @@ -129,20 +129,20 @@ def group_str(event_user) def event_signup_status(event) if event.signup.present? if event.signup.open? - content_tag(:span, icon('far', 'dot-circle'), - class: 'open', - 'data-toggle': 'tooltip', - title: I18n.t('helper.event.signup_open')) + content_tag(:span, icon("far", "dot-circle"), + class: "open", + 'data-toggle': "tooltip", + title: I18n.t("helper.event.signup_open")) elsif event.signup.closed? - content_tag(:span, icon('far', 'dot-circle'), - class: 'closed', - 'data-toggle': 'tooltip', - title: I18n.t('helper.event.signup_closed')) + content_tag(:span, icon("far", "dot-circle"), + class: "closed", + 'data-toggle': "tooltip", + title: I18n.t("helper.event.signup_closed")) else - content_tag(:spab, icon('far', 'dot-circle'), - class: 'future', - 'data-toggle': 'tooltip', - title: I18n.t('helper.event.signup_future')) + content_tag(:spab, icon("far", "dot-circle"), + class: "future", + 'data-toggle': "tooltip", + title: I18n.t("helper.event.signup_future")) end end end diff --git a/app/helpers/group_helper.rb b/app/helpers/group_helper.rb index 95e61a2e8..34c667ba9 100644 --- a/app/helpers/group_helper.rb +++ b/app/helpers/group_helper.rb @@ -1,20 +1,20 @@ module GroupHelper def group_user_name(group_user) - group_user.fadder ? safe_join([group_user.user, ' ', icon('fas', 'graduation-cap')]) : group_user.user + group_user.fadder ? safe_join([group_user.user, " ", icon("fas", "graduation-cap")]) : group_user.user end def group_user_state_link(group, group_user) if group.present? && group_user.present? if group_user.fadder - link_to(I18n.t('helper.group.set_nolla'), - set_not_fadder_admin_group_group_user_path(group, group_user), - method: :patch, - remote: true) + link_to(I18n.t("helper.group.set_nolla"), + set_not_fadder_admin_group_group_user_path(group, group_user), + method: :patch, + remote: true) else - link_to(I18n.t('helper.group.set_fadder'), - set_fadder_admin_group_group_user_path(group, group_user), - method: :patch, - remote: true) + link_to(I18n.t("helper.group.set_fadder"), + set_fadder_admin_group_group_user_path(group, group_user), + method: :patch, + remote: true) end end end @@ -22,7 +22,7 @@ def group_user_state_link(group, group_user) def group_title(group) if group.present? if group.regular? - t('helper.group.regular_title') + ' ' + group.number.to_s + ': ' + group.to_s + t("helper.group.regular_title") + " " + group.number.to_s + ": " + group.to_s else group.to_s end @@ -32,27 +32,27 @@ def group_title(group) def group_type_str(group) if group.present? if group.regular? - Group.human_attribute_name('regular') + Group.human_attribute_name("regular") elsif group.mission? - Group.human_attribute_name('mission') + Group.human_attribute_name("mission") elsif group.info? - Group.human_attribute_name('info') + Group.human_attribute_name("info") else - Group.human_attribute_name('other') + Group.human_attribute_name("other") end end end def group_type_event_collection - [[Group.human_attribute_name('regular'), Group::REGULAR], - [Group.human_attribute_name('mission'), Group::MISSION], - [Group.human_attribute_name('other'), Group::OTHER]] + [[Group.human_attribute_name("regular"), Group::REGULAR], + [Group.human_attribute_name("mission"), Group::MISSION], + [Group.human_attribute_name("other"), Group::OTHER]] end def group_type_collection - [[Group.human_attribute_name('regular'), Group::REGULAR], - [Group.human_attribute_name('mission'), Group::MISSION], - [Group.human_attribute_name('info'), Group::INFO], - [Group.human_attribute_name('other'), Group::OTHER]] + [[Group.human_attribute_name("regular"), Group::REGULAR], + [Group.human_attribute_name("mission"), Group::MISSION], + [Group.human_attribute_name("info"), Group::INFO], + [Group.human_attribute_name("other"), Group::OTHER]] end end diff --git a/app/helpers/introduction_helper.rb b/app/helpers/introduction_helper.rb index de3e0e1d0..047f73827 100644 --- a/app/helpers/introduction_helper.rb +++ b/app/helpers/introduction_helper.rb @@ -1,8 +1,8 @@ module IntroductionHelper def display_matrix_class(cookies) hide = cookies.fetch(:hide_matrix, false) - if hide == 'true' - 'hide-matrix' + if hide == "true" + "hide-matrix" end end end diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index af929a5e1..9f1ab3940 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -1,7 +1,7 @@ module LinkHelper def link(obj, options = {}) if obj.nil? - content_tag :i, '[missing]' + content_tag :i, "[missing]" elsif obj.is_a?(ActiveRecord::Base) && obj.respond_to?(:name) link_to obj.name, obj, options elsif obj.respond_to? :model_name diff --git a/app/helpers/markdown_helper.rb b/app/helpers/markdown_helper.rb index 0b927976b..7df4f482e 100644 --- a/app/helpers/markdown_helper.rb +++ b/app/helpers/markdown_helper.rb @@ -1,5 +1,5 @@ module MarkdownHelper - require 'redcarpet/render_strip' + require "redcarpet/render_strip" def markdown(text) MarkdownHelper.markdown(text) @@ -24,7 +24,7 @@ def self.markdown_plain(text) def self.markdown_renderer options = { hard_wrap: true, - link_attributes: { rel: 'nofollow', 'data-turbolinks': 'false' } + link_attributes: {rel: "nofollow", 'data-turbolinks': "false"} } extensions = { autolink: true, fenced_code_blocks: true, highlight: true, @@ -33,23 +33,23 @@ def self.markdown_renderer } Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(options), - extensions) + extensions) end def self.plain_renderer Redcarpet::Markdown.new(Redcarpet::Render::StripDown, - no_intra_emphasis: true, - fenced_code_blocks: true, - autolink: true, - tables: true, - underline: true, - highlight: true) + no_intra_emphasis: true, + fenced_code_blocks: true, + autolink: true, + tables: true, + underline: true, + highlight: true) end def self.api_renderer options = { hard_wrap: true, - link_attributes: { class: 'external', target: '_system' } + link_attributes: {class: "external", target: "_system"} } extensions = { autolink: true, fenced_code_blocks: true, highlight: true, @@ -58,12 +58,12 @@ def self.api_renderer } Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(options), - extensions) + extensions) end def self.sanitize(input) return unless input.present? ActionView::Base.new.sanitize(input.html_safe, - attributes: %w(href data-turbolinks rel class target)) + attributes: %w[href data-turbolinks rel class target]) end end diff --git a/app/helpers/meeting_helper.rb b/app/helpers/meeting_helper.rb index 02c125438..0144d4ed6 100644 --- a/app/helpers/meeting_helper.rb +++ b/app/helpers/meeting_helper.rb @@ -1,14 +1,14 @@ module MeetingHelper def room_collection - [[Meeting.human_attribute_name('sk'), :sk], - [Meeting.human_attribute_name('alumni'), :alumni], - [Meeting.human_attribute_name('sister_kent'), :sister_kent]] + [[Meeting.human_attribute_name("sk"), :sk], + [Meeting.human_attribute_name("alumni"), :alumni], + [Meeting.human_attribute_name("sister_kent"), :sister_kent]] end def meeting_status_collection - [[Meeting.human_attribute_name('confirmed'), :confirmed], - [Meeting.human_attribute_name('unconfirmed'), :unconfirmed], - [Meeting.human_attribute_name('denied'), :denied]] + [[Meeting.human_attribute_name("confirmed"), :confirmed], + [Meeting.human_attribute_name("unconfirmed"), :unconfirmed], + [Meeting.human_attribute_name("denied"), :denied]] end def meeting_str(meeting) diff --git a/app/helpers/meeting_mailer_helper.rb b/app/helpers/meeting_mailer_helper.rb index b4ed184f8..c45f3ace1 100644 --- a/app/helpers/meeting_mailer_helper.rb +++ b/app/helpers/meeting_mailer_helper.rb @@ -1,10 +1,10 @@ module MeetingMailerHelper def email_subject(meeting, status: t("model.meeting.#{meeting.status}")) if meeting.present? - I18n.t('meeting_mailer.mailer.subject', - date: meeting_times(meeting), - room: Meeting.human_attribute_name(meeting.room), - status: status) + I18n.t("meeting_mailer.mailer.subject", + date: meeting_times(meeting), + room: Meeting.human_attribute_name(meeting.room), + status: status) end end end diff --git a/app/helpers/menu_helper.rb b/app/helpers/menu_helper.rb index 530a44588..da2f47af0 100644 --- a/app/helpers/menu_helper.rb +++ b/app/helpers/menu_helper.rb @@ -1,6 +1,6 @@ # Helps creating menu links module MenuHelper - def menu_dropdown_render(menus, cls: '') + def menu_dropdown_render(menus, cls: "") content_tag(:ul, class: cls) do content = [] menus.each do |m| @@ -12,7 +12,7 @@ def menu_dropdown_render(menus, cls: '') def menu_locale_link(link, locale) if link.present? && locale.present? - if !link.start_with?('http', 'https') && locale.to_s == 'en' + if !link.start_with?("http", "https") && locale.to_s == "en" "/en#{link}" else link @@ -22,19 +22,19 @@ def menu_locale_link(link, locale) def menu_link(menu, locale) link_to(menu_content(menu), menu_locale_link(menu.link, locale), - menu_options(menu.blank_p, menu.turbolinks)) + menu_options(menu.blank_p, menu.turbolinks)) end def menu_content(menu) content = [menu.to_s] - content << icon('fas', 'external-link-alt') if menu.blank_p + content << icon("fas", "external-link-alt") if menu.blank_p safe_join(content) end def menu_options(blank, turbolinks) options = {} options[:target] = :blank if blank - options['data-turbolinks'] = turbolinks.to_s + options["data-turbolinks"] = turbolinks.to_s options end diff --git a/app/helpers/message_helper.rb b/app/helpers/message_helper.rb index 9bd0a3602..a32723da5 100644 --- a/app/helpers/message_helper.rb +++ b/app/helpers/message_helper.rb @@ -11,7 +11,7 @@ module MessageHelper space_after_headers: true }.freeze - API_OPTIONS = { link_attributes: { class: 'external', target: '_system' } }.freeze + API_OPTIONS = {link_attributes: {class: "external", target: "_system"}}.freeze def self.markdown(text) MarkdownHelper.sanitize(renderer.render(text)) if text.present? @@ -35,21 +35,21 @@ def admin_message_image_url(message) def message_destroy_link(message) link_to(admin_message_path(message), - method: :delete, - class: '', - data: { confirm: t('helper.message.destroy_message') }) do - icon('fas', 'trash') + method: :delete, + class: "", + data: {confirm: t("helper.message.destroy_message")}) do + icon("fas", "trash") end end def message_edit_link(message) - link_to(edit_admin_message_path(message), class: '') do - icon('fas', 'pencil-alt') + link_to(edit_admin_message_path(message), class: "") do + icon("fas", "pencil-alt") end end def message_receivers(message) - tag(:br) + t('helper.message.to') + message.group_names + tag(:br) + t("helper.message.to") + message.group_names end def message_form_params(edit, message) diff --git a/app/helpers/meta_tags_helper.rb b/app/helpers/meta_tags_helper.rb index 2b5a4b24a..b427871ee 100644 --- a/app/helpers/meta_tags_helper.rb +++ b/app/helpers/meta_tags_helper.rb @@ -3,8 +3,8 @@ def description(text) if text.present? tag_text = truncate(text, length: 155) set_meta_tags(description: tag_text, - twitter: { description: tag_text }, - og: { description: tag_text }) + twitter: {description: tag_text}, + og: {description: tag_text}) end text end @@ -12,8 +12,8 @@ def description(text) def title(text) if text.present? set_meta_tags(title: text, - twitter: { title: text }, - og: { title: text }) + twitter: {title: text}, + og: {title: text}) end text end @@ -22,8 +22,8 @@ def meta_image(image) if image.present? url = image_url(image) set_meta_tags(image: url, - twitter: { image: url }, - og: { image: url }) + twitter: {image: url}, + og: {image: url}) end image end diff --git a/app/helpers/news_helper.rb b/app/helpers/news_helper.rb index 58875f6a6..d2cc7912a 100644 --- a/app/helpers/news_helper.rb +++ b/app/helpers/news_helper.rb @@ -5,7 +5,7 @@ def news_user(news) if news.present? && news.user.present? content_tag(:span, class: :link) do link_to(news.user, target: :blank) do - icon('fas', 'user') + ' ' + news.user + icon("fas", "user") + " " + news.user end end end @@ -13,7 +13,7 @@ def news_user(news) def news_dropdown_button(collection:, current:) content = safe_join([category_button(current), news_collection(collection)]) - content_tag(:div, content, class: 'dropdown') + content_tag(:div, content, class: "dropdown") end def news_collection(collection) diff --git a/app/helpers/notification_helper.rb b/app/helpers/notification_helper.rb index 119e8f0e8..73fc1b724 100644 --- a/app/helpers/notification_helper.rb +++ b/app/helpers/notification_helper.rb @@ -1,30 +1,27 @@ module NotificationHelper def notification_context(notification, data) - content_tag(:div, markdown(data.body), class: 'body') + content_tag(:div, markdown(data.body), class: "body") end - def notification_icon(notification) - icon = '' - if notification.notifyable_type == 'EventUser' - if notification.mode == 'position' - icon = icon('fas', 'check') + def notification_icon(notification) + icon = "" + if notification.notifyable_type == "EventUser" + if notification.mode == "position" + icon("fas", "check") else - icon = icon('fas', 'glass-cheers') + icon("fas", "glass-cheers") end + elsif notification.mode == "closing" + icon("fas", "user-clock") else - if notification.mode == 'closing' - icon = icon('fas', 'user-clock') - else - icon = icon('fas', 'user-plus') - end + icon("fas", "user-plus") end - icon end def notification_created_at(time) - content_tag(:span, class: 'notification-time') do + content_tag(:span, class: "notification-time") do content = [] - content << icon('far', 'calendar-alt') + content << icon("far", "calendar-alt") content << localize(time) safe_join(content) end diff --git a/app/helpers/post_helper.rb b/app/helpers/post_helper.rb index 2462ecfe4..25c6cca89 100644 --- a/app/helpers/post_helper.rb +++ b/app/helpers/post_helper.rb @@ -2,7 +2,7 @@ module PostHelper def print_post_limit(post) if post.present? if post.rec_limit == 0 && post.limit == 0 || post.rec_limit > post.limit - '*' + "*" elsif post.rec_limit == post.limit && post.rec_limit > 0 %(#{post.limit} (x)) elsif post.limit > 0 && post.rec_limit == 0 @@ -15,7 +15,7 @@ def print_post_limit(post) def post_tab_header(posts) if posts.present? - content_tag(:ul, class: 'nav nav-tabs') do + content_tag(:ul, class: "nav nav-tabs") do content = [] content << post_tab_link(posts.first, first: true) posts.offset(1).each do |post| @@ -39,11 +39,11 @@ def post_tab(posts) def post_tab_element(post, first: false) if first - content_tag(:div, id: dom_id(post), class: 'tab-pane fade in active') do + content_tag(:div, id: dom_id(post), class: "tab-pane fade in active") do safe_join([post_tab_description(post), post_tab_users(post)]) end else - content_tag(:div, id: dom_id(post), class: 'tab-pane fade in') do + content_tag(:div, id: dom_id(post), class: "tab-pane fade in") do safe_join([post_tab_description(post), post_tab_users(post)]) end end @@ -53,11 +53,11 @@ def post_tab_link(post, first: false) if post.present? if first content_tag(:li, class: :active) do - link_to(post, %(##{dom_id(post)}), data: { toggle: :tab }) + link_to(post, %(##{dom_id(post)}), data: {toggle: :tab}) end else content_tag(:li) do - link_to(post, %(##{dom_id(post)}), data: { toggle: :tab }) + link_to(post, %(##{dom_id(post)}), data: {toggle: :tab}) end end end @@ -65,7 +65,7 @@ def post_tab_link(post, first: false) def post_tab_description(post) if post.present? - content_tag(:div, class: 'col-sm-8') do + content_tag(:div, class: "col-sm-8") do content = [] content << content_tag(:div, class: :headline) do content_tag(:h4) do @@ -80,22 +80,22 @@ def post_tab_description(post) def post_tab_users(post) if post.present? - content_tag(:div, class: 'col-sm-4') do + content_tag(:div, class: "col-sm-4") do content = [] content << content_tag(:div, class: :headline) do content_tag(:h4) do - t('helper.post.who_currently') + t("helper.post.who_currently") end end - if post.title == 'Överfös' - names = ['Överfös Natalia'] + if post.title == "Överfös" + names = ["Överfös Natalia"] names.each do |e| content << content_tag(:li) do e end end - elsif post.title == 'Cofös' - names = ['Cofös Eliot', 'Cofös Gustav', 'Cofös Klara', 'Cofös Axel'] + elsif post.title == "Cofös" + names = ["Cofös Eliot", "Cofös Gustav", "Cofös Klara", "Cofös Axel"] names.each do |e| content << content_tag(:li) do e diff --git a/app/helpers/rent_mailer_helper.rb b/app/helpers/rent_mailer_helper.rb index 5d2f5b50d..f07726fba 100644 --- a/app/helpers/rent_mailer_helper.rb +++ b/app/helpers/rent_mailer_helper.rb @@ -1,18 +1,18 @@ module RentMailerHelper def email_subject(rent, status: t("model.rent.#{rent.status}")) if rent.present? - I18n.t('rent_mailer.mailer.subject', - date: rent.p_time, - status: status) + I18n.t("rent_mailer.mailer.subject", + date: rent.p_time, + status: status) end end def active_email_subject(rent) if rent.present? if rent.aktiv - email_subject(rent, status: I18n.t('rent_mailer.active_email.marked_active')) + email_subject(rent, status: I18n.t("rent_mailer.active_email.marked_active")) else - email_subject(rent, status: I18n.t('rent_mailer.active_email.marked_inactive')) + email_subject(rent, status: I18n.t("rent_mailer.active_email.marked_inactive")) end end end diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb index 896dbcbed..7e1301ecb 100644 --- a/app/helpers/time_helper.rb +++ b/app/helpers/time_helper.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 module TimeHelper # Expecting two dates def date_range(from_date, until_date, format: :default) @@ -60,7 +59,7 @@ def localized(date, options = {}) if date.present? I18n.l(date, options) else - icon('fas', 'cogs') + icon("fas", "cogs") end end diff --git a/app/helpers/tool_helper.rb b/app/helpers/tool_helper.rb index 9f82665d5..6f2cf82f3 100644 --- a/app/helpers/tool_helper.rb +++ b/app/helpers/tool_helper.rb @@ -2,9 +2,9 @@ module ToolHelper def tool_link(tool, path) if tool.present? content = [] - content << content_tag(:h4, tool.title, class: 'list-group-item-heading') - content << content_tag(:span, tool.free.to_s + '/' + tool.total.to_s, class: 'badge') - content << content_tag(:p, tool.description, class: 'list-group-item-text') + content << content_tag(:h4, tool.title, class: "list-group-item-heading") + content << content_tag(:span, tool.free.to_s + "/" + tool.total.to_s, class: "badge") + content << content_tag(:p, tool.description, class: "list-group-item-text") make_link(tool, path, content) end @@ -13,9 +13,9 @@ def tool_link(tool, path) private def make_link(tool, path, content) - class_str = ['list-group-item', 'list-group-item-tools'] + class_str = ["list-group-item", "list-group-item-tools"] if tool.free.zero? - class_str << ' list-group-item-danger' + class_str << " list-group-item-danger" end link_to path, class: class_str do diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 83cabada8..26eed4395 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -4,16 +4,16 @@ def display_phone?(user:, current_user:) end def user_program_collection - [[I18n.t('model.user.program.physics'), User::PHYSICS], - [I18n.t('model.user.program.math'), User::MATH], - [I18n.t('model.user.program.nano'), User::NANO], - [I18n.t('model.user.program.other'), User::OTHER]] + [[I18n.t("model.user.program.physics"), User::PHYSICS], + [I18n.t("model.user.program.math"), User::MATH], + [I18n.t("model.user.program.nano"), User::NANO], + [I18n.t("model.user.program.other"), User::OTHER]] end def food_preferences_str(user) ary = user.food_preferences.delete_if(&:blank?).map { |f| I18n.t("model.user.food_prefs.#{f}") } ary << user.food_custom if user.food_custom.present? - ary.join(', ') + ary.join(", ") end def food_prefs_collection(user) diff --git a/app/helpers/work_post_helper.rb b/app/helpers/work_post_helper.rb index 8f1213464..9adcdcd0b 100644 --- a/app/helpers/work_post_helper.rb +++ b/app/helpers/work_post_helper.rb @@ -2,24 +2,24 @@ module WorkPostHelper def work_post_link(work_post) if work_post.present? && work_post.link.present? link_to(work_post.link, work_post.link, - class: 'btn primary small link') + class: "btn primary small link") end end def work_post_info_title(title, value) content = safe_join([work_post_title(title), work_post_value(value)]) - content_tag(:span, content, class: 'info') + content_tag(:span, content, class: "info") end def work_post_title(title) if title.present? - content_tag(:span, title, class: 'title') + content_tag(:span, title, class: "title") end end def work_post_value(value) if value.present? - content_tag(:span, value, class: 'value') + content_tag(:span, value, class: "value") end end end diff --git a/app/inputs/date_picker_input.rb b/app/inputs/date_picker_input.rb index 45b6a1505..be70c8c90 100644 --- a/app/inputs/date_picker_input.rb +++ b/app/inputs/date_picker_input.rb @@ -3,28 +3,28 @@ def input(wrapper_options) set_html_options set_value_html_option - template.content_tag :div, class: 'input-group date datetimepicker' do + template.content_tag :div, class: "input-group date datetimepicker" do input = super(wrapper_options) # leave StringInput do the real rendering input + input_button end end def input_html_classes - super.push '' # 'form-control' + super.push "" # 'form-control' end private def input_button - template.content_tag :span, class: 'input-group-btn' do - template.content_tag :button, class: 'btn btn-default', type: 'button' do - template.content_tag :span, '', class: 'fa fa-calendar' + template.content_tag :span, class: "input-group-btn" do + template.content_tag :button, class: "btn btn-default", type: "button" do + template.content_tag :span, "", class: "fa fa-calendar" end end end def set_html_options - input_html_options[:type] = 'text' + input_html_options[:type] = "text" input_html_options[:data] ||= {} input_html_options[:data].merge!(date_options: date_options) end @@ -39,15 +39,15 @@ def value end def display_pattern - I18n.t('datepicker.dformat', default: '%Y/%m/%d') + I18n.t("datepicker.dformat", default: "%Y/%m/%d") end def picker_pattern - I18n.t('datepicker.pformat', default: 'YYYY-MM-DD') + I18n.t("datepicker.pformat", default: "YYYY-MM-DD") end def date_view_header_format - I18n.t('dayViewHeaderFormat', default: 'MMMM YYYY') + I18n.t("dayViewHeaderFormat", default: "MMMM YYYY") end def date_options_base diff --git a/app/inputs/datetime_picker_input.rb b/app/inputs/datetime_picker_input.rb index d0d57629c..1b91305a0 100644 --- a/app/inputs/datetime_picker_input.rb +++ b/app/inputs/datetime_picker_input.rb @@ -2,12 +2,12 @@ class DatetimePickerInput < DatePickerInput private def display_pattern - I18n.t('datepicker.dformat', default: '%Y-%m-%d') + ' ' + - I18n.t('timepicker.dformat', default: '%R') + I18n.t("datepicker.dformat", default: "%Y-%m-%d") + " " + + I18n.t("timepicker.dformat", default: "%R") end def picker_pattern - I18n.t('datepicker.pformat', default: 'YYYY-MM-DD') + ' ' + - I18n.t('timepicker.pformat', default: 'HH:mm') + I18n.t("datepicker.pformat", default: "YYYY-MM-DD") + " " + + I18n.t("timepicker.pformat", default: "HH:mm") end end diff --git a/app/inputs/pagedown_input.rb b/app/inputs/pagedown_input.rb index e7fd0545b..ec7e6d6d6 100644 --- a/app/inputs/pagedown_input.rb +++ b/app/inputs/pagedown_input.rb @@ -15,7 +15,7 @@ def wmd_input @builder.text_area( attribute_name, input_html_options.merge( - class: 'wmd-input form-control', id: "wmd-input-#{attribute_name}" + class: "wmd-input form-control", id: "wmd-input-#{attribute_name}" ) ) end diff --git a/app/inputs/time_picker_input.rb b/app/inputs/time_picker_input.rb index 2f5c70bfc..ac535d859 100644 --- a/app/inputs/time_picker_input.rb +++ b/app/inputs/time_picker_input.rb @@ -2,11 +2,11 @@ class TimePickerInput < DatePickerInput private def display_pattern - I18n.t('timepicker.dformat', default: '%R') + I18n.t("timepicker.dformat", default: "%R") end def picker_pattern - I18n.t('timepicker.pformat', default: 'HH:mm') + I18n.t("timepicker.pformat", default: "HH:mm") end def date_options diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 67fbe8fc6..2eb939382 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,14 +1,14 @@ class ApplicationMailer < ActionMailer::Base include Roadie::Rails::Automatic helper EmailHelper - default(from: 'dirac@fsektionen.se') - layout('email') + default(from: "dirac@fsektionen.se") + layout("email") before_action(:set_message_id) private def set_message_id str = Time.zone.now.to_i.to_s - headers['Message-ID'] = "<#{Digest::SHA2.hexdigest(str)}@fsektionen.se>" + headers["Message-ID"] = "<#{Digest::SHA2.hexdigest(str)}@fsektionen.se>" end end diff --git a/app/mailers/cafe_mailer.rb b/app/mailers/cafe_mailer.rb index 2895bdca6..09bd81958 100644 --- a/app/mailers/cafe_mailer.rb +++ b/app/mailers/cafe_mailer.rb @@ -1,12 +1,12 @@ class CafeMailer < ApplicationMailer - default from: 'fsektionen.se ' + default from: "fsektionen.se " def destroy_email(user, cafe_shift) @user = user @cafe_shift = cafe_shift if @user.present? && @cafe_shift.present? - mail(to: 'cafe@fsektionen.se', - subject: 'Avhopp cafépass') + mail(to: "cafe@fsektionen.se", + subject: "Avhopp cafépass") end end end diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 64c5e2619..c25b7b592 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,12 +1,12 @@ class ContactMailer < ApplicationMailer - default from: 'Kontaktformulär ' + default from: "Kontaktformulär " def contact_email(contact) @contact = contact if @contact.present? recipient = "#{contact.name} <#{contact.email}>" sender = "#{contact.message.name} <#{contact.message.email}>" - subject = I18n.t('contact_mailer.subject', sender: contact.message.name) + subject = I18n.t("contact_mailer.subject", sender: contact.message.name) mail(subject: subject, to: recipient, cc: sender, reply_to: sender) end diff --git a/app/mailers/election_mailer.rb b/app/mailers/election_mailer.rb index 820520353..189f3b279 100644 --- a/app/mailers/election_mailer.rb +++ b/app/mailers/election_mailer.rb @@ -1,12 +1,12 @@ class ElectionMailer < ApplicationMailer helper MarkdownHelper, ElectionMailerHelper - default from: 'Valberedningen ' + default from: "Valberedningen " def nominate_email(nomination_id) @nomination = Nomination.find_by_id(nomination_id) if @nomination && @nomination.email.present? mail(to: @nomination.email, - subject: I18n.t('election_mailer.nominate_email.subject_nominated')) + subject: I18n.t("election_mailer.nominate_email.subject_nominated")) end end @@ -14,7 +14,7 @@ def candidate_email(candidate_id) @candidate = Candidate.find_by_id(candidate_id) if @candidate.present? && @candidate.user.email.present? mail(to: @candidate.user.print_email, - subject: I18n.t('election_mailer.candidate_email.subject_candidated')) + subject: I18n.t("election_mailer.candidate_email.subject_candidated")) end end end diff --git a/app/mailers/meeting_mailer.rb b/app/mailers/meeting_mailer.rb index 01a3a2428..f52a729eb 100644 --- a/app/mailers/meeting_mailer.rb +++ b/app/mailers/meeting_mailer.rb @@ -1,15 +1,17 @@ class MeetingMailer < ApplicationMailer - include MeetingMailerHelper, MeetingHelper, TimeHelper + include TimeHelper + include MeetingHelper + include MeetingMailerHelper add_template_helper MarkdownHelper - default from: %(#{I18n.t('meeting_mailer.mailer.executives')} ) + default from: %(#{I18n.t("meeting_mailer.mailer.executives")} ) def book_email(meeting) @meeting = meeting if @meeting.present? && @meeting.user.email.present? mail(to: @meeting.user.try(:print_email), - bcc: 'lokalbokning@fsektionen.se', - subject: email_subject(meeting), - sent_on: Time.zone.now) + bcc: "lokalbokning@fsektionen.se", + subject: email_subject(meeting), + sent_on: Time.zone.now) end end @@ -18,9 +20,9 @@ def update_email(meeting, user) @user = user if @meeting.present? && @meeting.user.email.present? mail(to: @meeting.user.try(:print_email), - bcc: 'lokalbokning@fsektionen.se', - subject: email_subject(meeting), - sent_on: Time.zone.now) + bcc: "lokalbokning@fsektionen.se", + subject: email_subject(meeting), + sent_on: Time.zone.now) end end end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 2e6e4e90d..a4d4e56b3 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,10 +1,10 @@ class NotificationMailer < ApplicationMailer - default from: 'F-sektionen ' + default from: "F-sektionen " helper :notification, :application, :markdown def notify(notification) @notification = notification - subject = I18n.t('notification_mailer.subject', notification: notification.to_s) + subject = I18n.t("notification_mailer.subject", notification: notification.to_s) mail(subject: subject, to: notification.user.print_email) end diff --git a/app/mailers/rent_mailer.rb b/app/mailers/rent_mailer.rb index ebea455a0..df4054051 100644 --- a/app/mailers/rent_mailer.rb +++ b/app/mailers/rent_mailer.rb @@ -1,13 +1,13 @@ class RentMailer < ApplicationMailer include RentMailerHelper - default from: %(#{I18n.t('rent_mailer.mailer.car_foreman')} ) + default from: %(#{I18n.t("rent_mailer.mailer.car_foreman")} ) def rent_email(rent) @rent = rent if @rent.present? && @rent.user.email.present? mail(to: @rent.user.try(:print_email), - subject: email_subject(rent), - sent_on: Time.zone.now) + subject: email_subject(rent), + sent_on: Time.zone.now) end end @@ -15,8 +15,8 @@ def status_email(rent) @rent = rent if @rent.present? && @rent.user.email.present? mail(to: @rent.user.try(:print_email), - subject: email_subject(@rent), - sent_on: Time.zone.now) + subject: email_subject(@rent), + sent_on: Time.zone.now) end end @@ -24,8 +24,8 @@ def active_email(rent) @rent = rent if @rent.present? && @rent.user.email.present? mail(to: @rent.user.print_email, - subject: active_email_subject(rent), - sent_on: Time.zone.now) + subject: active_email_subject(rent), + sent_on: Time.zone.now) end end end diff --git a/app/mailers/tool_renting_mailer.rb b/app/mailers/tool_renting_mailer.rb index 3c8af4227..deb9182e0 100644 --- a/app/mailers/tool_renting_mailer.rb +++ b/app/mailers/tool_renting_mailer.rb @@ -1,10 +1,10 @@ class ToolRentingMailer < ApplicationMailer def send_reminder_email(rent) - prylm = 'prylm@fsektionen.se' - fixare = 'fixare@fsektionen.se' + prylm = "prylm@fsektionen.se" + fixare = "fixare@fsektionen.se" @renter = User.find(rent.user_id) recipient = @renter.email.to_s - subject = 'Returdatum för verktygslån har passerat' + subject = "Returdatum för verktygslån har passerat" mail(to: recipient, from: prylm, bcc: [prylm, fixare], reply_to: prylm, subject: subject) end diff --git a/app/models/ability.rb b/app/models/ability.rb index 4127fdbb4..c82c24244 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -21,8 +21,8 @@ def initialize(user) can :index, :gallery can [:read, :archive, :matrix, :modal, :dance], Introduction can [:index, :about, :privacy, - :cookies_information, :company_about, - :company_offer, :robots, :influence], :static_pages + :cookies_information, :company_about, + :company_offer, :robots, :influence], :static_pages # Abilities all signed in users get if user.id.present? @@ -45,7 +45,7 @@ def initialize(user) can :read, Document, public: true can :index, Group - can :show, Group, users: { id: user.id } + can :show, Group, users: {id: user.id} can([:index, :show, :download_image], Message, Message.for_user(user)) do |message| message.with_group(user) diff --git a/app/models/access.rb b/app/models/access.rb index 9f93bfe3b..006445f25 100644 --- a/app/models/access.rb +++ b/app/models/access.rb @@ -3,5 +3,5 @@ class Access < ApplicationRecord belongs_to :post validates(:door, :post, presence: true) - validates(:door, uniqueness: { scope: :post }) + validates(:door, uniqueness: {scope: :post}) end diff --git a/app/models/adventures/adventure.rb b/app/models/adventures/adventure.rb index d828ddf9d..69bf0d9cd 100644 --- a/app/models/adventures/adventure.rb +++ b/app/models/adventures/adventure.rb @@ -14,8 +14,8 @@ class Adventure < ApplicationRecord validates :title_sv, :start_date, :end_date, :introduction_id, presence: true validate :date_validation - scope :published, -> { where('start_date <= ?', Time.zone.now).order(start_date: :desc) } - scope :published_asc, -> { where('start_date <= ?', Time.zone.now).order(start_date: :asc) } + scope :published, -> { where("start_date <= ?", Time.zone.now).order(start_date: :desc) } + scope :published_asc, -> { where("start_date <= ?", Time.zone.now).order(start_date: :asc) } scope :published_results, -> { where(publish_results: true) } @@ -27,13 +27,13 @@ def published? def week_number # Just making sure the dates don't extend into another week - (end_date - 3.days).strftime('%U').to_i + 1 + (end_date - 3.days).strftime("%U").to_i + 1 end def self.can_show?(user) User.joins(groups: :introduction) - .where('users.id': user.id, 'introductions.current': true, 'groups.group_type': 'regular') - .count > 0 + .where('users.id': user.id, 'introductions.current': true, 'groups.group_type': "regular") + .count > 0 end def to_s @@ -48,7 +48,7 @@ def schedule_locking def date_validation unless start_date.present? && end_date.present? && start_date < end_date - errors.add(:end_date, I18n.t('errors.messages.end_after_start')) + errors.add(:end_date, I18n.t("errors.messages.end_after_start")) end end end diff --git a/app/models/adventures/adventure_mission.rb b/app/models/adventures/adventure_mission.rb index 596484eba..09e5e98fe 100644 --- a/app/models/adventures/adventure_mission.rb +++ b/app/models/adventures/adventure_mission.rb @@ -9,8 +9,8 @@ class AdventureMission < ApplicationRecord attr_accessor :finished, :points validates :title_sv, presence: true - validates :index, numericality: { greater_than_or_equal: 0 }, presence: true - validates :max_points, numericality: { greater_than: 0 }, presence: true + validates :index, numericality: {greater_than_or_equal: 0}, presence: true + validates :max_points, numericality: {greater_than: 0}, presence: true validates :require_acceptance, null: false scope :by_group, ->(group) { where(group: group) } diff --git a/app/models/adventures/adventure_mission_group.rb b/app/models/adventures/adventure_mission_group.rb index b99a12cc1..fa835cc86 100644 --- a/app/models/adventures/adventure_mission_group.rb +++ b/app/models/adventures/adventure_mission_group.rb @@ -13,14 +13,14 @@ class AdventureMissionGroup < ApplicationRecord def point_validity unless points.present? && points > 0 && points <= adventure_mission.max_points - errors.add(:points, I18n.t('model.adventure_mission_group.invalid_points', max_points: adventure_mission.max_points)) + errors.add(:points, I18n.t("model.adventure_mission_group.invalid_points", max_points: adventure_mission.max_points)) throw :abort end end def not_locked if adventure_mission.locked? - errors.add(:locked, I18n.t('model.adventure_mission_group.locked')) + errors.add(:locked, I18n.t("model.adventure_mission_group.locked")) throw :abort end end diff --git a/app/models/album.rb b/app/models/album.rb index 7e58e963d..6f35189a0 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,25 +1,25 @@ class Album < ApplicationRecord translates(:title, :description) globalize_accessors(locales: [:en, :sv], - attributes: [:title, :description]) + attributes: [:title, :description]) has_many :images, dependent: :destroy, inverse_of: :album has_many :photographers, -> { distinct }, through: :images attr_accessor(:image_upload, :photographer_user, - :photographer_name) + :photographer_name) validates :title, :start_date, :description, presence: true scope :by_start, -> { order(start_date: :desc) } - scope :gallery, -> (date) { - by_start.where('start_date BETWEEN ? AND ?', - date.beginning_of_year, date.end_of_year) + scope :gallery, ->(date) { + by_start.where("start_date BETWEEN ? AND ?", + date.beginning_of_year, date.end_of_year) } scope :include_for_gallery, -> { includes(:images, :translations) } - scope :summer, -> { where('start_date > ?', User.summer) } + scope :summer, -> { where("start_date > ?", User.summer) } def self.unique_years - by_start.pluck('extract(year from start_date)::Integer').uniq + by_start.pluck("extract(year from start_date)::Integer").uniq end def self.locations diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index 928353b56..405f4ba25 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -4,17 +4,17 @@ class BlogPost < ApplicationRecord mount_uploader(:cover_image, CoverImageUploader) translates(:title, :preamble, :content, fallbacks_for_empty_translations: true) globalize_accessors(locales: [:en, :sv], - attributes: [:title, :preamble, :content]) + attributes: [:title, :preamble, :content]) paginates_per(5) belongs_to(:user, required: true) validates(:title, :content, presence: true) - validates(:preamble_sv, :preamble_en, length: { maximum: 160 }) + validates(:preamble_sv, :preamble_en, length: {maximum: 160}) scope :by_created, -> { order(created_at: :desc) } scope :include_for_index, -> { includes(:translations, :categories, :user) } - scope :other, -> (blog_post) { where.not(id: blog_post.id).limit(3) } + scope :other, ->(blog_post) { where.not(id: blog_post.id).limit(3) } def cover_image_thumb if cover_image.present? @@ -38,9 +38,9 @@ def to_s def is_translated?(locale) locale = locale.to_s - if locale == 'en' + if locale == "en" title_en.present? && content_en.present? - elsif locale == 'sv' + elsif locale == "sv" title_sv.present? && content_sv.present? end end diff --git a/app/models/cafes/cafe_shift.rb b/app/models/cafes/cafe_shift.rb index 9cc36abfe..5b56e9451 100644 --- a/app/models/cafes/cafe_shift.rb +++ b/app/models/cafes/cafe_shift.rb @@ -5,22 +5,22 @@ class CafeShift < ApplicationRecord # Validations validates :start, :pass, :lp, :lv, presence: true - validates :lp, inclusion: { in: 1..4 } - validates :pass, inclusion: { in: 1..3 } - validates :lv, inclusion: { in: 0..8 } + validates :lp, inclusion: {in: 1..4} + validates :pass, inclusion: {in: 1..3} + validates :lv, inclusion: {in: 0..8} # Scopes scope :all_start, -> { order(start: :asc) } scope :with_worker, -> { joins(:cafe_worker).includes(:cafe_worker) } - scope :without_worker, -> { where('id NOT IN (SELECT cafe_shift_id FROM cafe_workers)') } + scope :without_worker, -> { where("id NOT IN (SELECT cafe_shift_id FROM cafe_workers)") } attr_accessor :lv_first, :lv_last, :setup_mode def to_s if user.present? - %(#{user}) + user.to_s else - %(#{I18n.t('model.cafe_shift.is_free')}) + I18n.t("model.cafe_shift.is_free").to_s end end diff --git a/app/models/cafes/cafe_worker.rb b/app/models/cafes/cafe_worker.rb index b77611278..9bacc6c5d 100644 --- a/app/models/cafes/cafe_worker.rb +++ b/app/models/cafes/cafe_worker.rb @@ -11,19 +11,19 @@ class CafeWorker < ApplicationRecord def user_attributes? if user.present? && (user.email.blank? || user.phone.blank?) - errors.add(:user, I18n.t('model.user.attributes_missing')) + errors.add(:user, I18n.t("model.user.attributes_missing")) end end def multiple_shifts? if user.present? && cafe_shift.present? && !similar_shifts - errors.add(:user, I18n.t('model.cafe_worker.already_working_same_time')) + errors.add(:user, I18n.t("model.cafe_worker.already_working_same_time")) end end def similar_shifts - user.cafe_shifts. - where(start: cafe_shift.start). - where.not(id: cafe_shift.id).empty? + user.cafe_shifts + .where(start: cafe_shift.start) + .where.not(id: cafe_shift.id).empty? end end diff --git a/app/models/cafes/cafe_worker_council.rb b/app/models/cafes/cafe_worker_council.rb index 307d2fcec..9c3b0f932 100644 --- a/app/models/cafes/cafe_worker_council.rb +++ b/app/models/cafes/cafe_worker_council.rb @@ -3,5 +3,5 @@ class CafeWorkerCouncil < ApplicationRecord belongs_to :council validates :cafe_worker, :council, presence: true - validates :council_id, uniqueness: { scope: :cafe_worker } + validates :council_id, uniqueness: {scope: :cafe_worker} end diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 72bb873b6..4892dc1f3 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -4,11 +4,11 @@ class Candidate < ApplicationRecord belongs_to :post, required: true has_one :council, through: :post - validates :post, uniqueness: { scope: [:user, :election], - message: I18n.t('model.candidate.similar_candidate') } + validates :post, uniqueness: {scope: [:user, :election], + message: I18n.t("model.candidate.similar_candidate")} validate :user_attributes - validate :check_edit, if: Proc.new { |o| o.election.present? && o.post.present? } + validate :check_edit, if: proc { |o| o.election.present? && o.post.present? } def editable? if election.present? && post.present? @@ -28,13 +28,13 @@ def editable_until def user_attributes unless user.present? && user.has_attributes? - errors.add(:user, I18n.t('model.candidate.add_user_information')) + errors.add(:user, I18n.t("model.candidate.add_user_information")) end end def check_edit unless editable? - errors.add(:post, I18n.t('model.candidate.not_editable')) + errors.add(:post, I18n.t("model.candidate.not_editable")) end end end diff --git a/app/models/cars/car_ban.rb b/app/models/cars/car_ban.rb index 134e4e482..d050d5e15 100644 --- a/app/models/cars/car_ban.rb +++ b/app/models/cars/car_ban.rb @@ -1,6 +1,6 @@ class CarBan < ApplicationRecord belongs_to :user - belongs_to :creator, class_name: 'User', foreign_key: :creator_id + belongs_to :creator, class_name: "User", foreign_key: :creator_id validates :user, uniqueness: true validates :reason, presence: true diff --git a/app/models/cars/rent.rb b/app/models/cars/rent.rb index af15eb9aa..85a814fbf 100644 --- a/app/models/cars/rent.rb +++ b/app/models/cars/rent.rb @@ -8,10 +8,10 @@ class Rent < ApplicationRecord # Scopes scope :councils, -> { where.not(council_id: nil) } scope :active, -> { where(aktiv: true).where.not(status: :denied) } - scope :between, ->(from, to) { where('? >= d_from AND ? <= d_til', to, from) } + scope :between, ->(from, to) { where("? >= d_from AND ? <= d_til", to, from) } scope :date_overlap, ->(from, to, id) { between(from, to).where.not(id: id) } scope :ascending, -> { order(d_from: :asc) } - scope :from_date, ->(from) { where('d_from >= ?', from) } + scope :from_date, ->(from) { where("d_from >= ?", from) } attr_accessor :terms @@ -42,21 +42,21 @@ def duration # Methods for printing def print_status - str = '' + str = "" if service == true str += %(#{Rent.human_attribute_name(:service)} - ) elsif status.present? - str += I18n.t(%(model.rent.#{status})) + ' - ' + str += I18n.t(%(model.rent.#{status})) + " - " end - str += aktiv == true ? I18n.t('model.rent.active') : I18n.t('model.rent.inactive') + str += aktiv == true ? I18n.t("model.rent.active") : I18n.t("model.rent.inactive") str end def p_time - if (d_from.day == d_til.day) - %(#{I18n.l(d_from, format: '%H:%M')} - #{I18n.l(d_til, format: '%H:%M')}, #{I18n.l(d_from, format: '%d/%m')}) + if d_from.day == d_til.day + %(#{I18n.l(d_from, format: "%H:%M")} - #{I18n.l(d_til, format: "%H:%M")}, #{I18n.l(d_from, format: "%d/%m")}) else - %(#{I18n.l(d_from, format: '%H:%M %d/%m')} - #{I18n.l(d_til, format: '%H:%M %d/%m')}) + %(#{I18n.l(d_from, format: "%H:%M %d/%m")} - #{I18n.l(d_til, format: "%H:%M %d/%m")}) end end @@ -72,8 +72,6 @@ def p_path def overlap if d_from.present? && d_til.present? Rent.active.date_overlap(d_from, d_til, id) - else - nil end end diff --git a/app/models/categorization.rb b/app/models/categorization.rb index 6484d45aa..548a361c6 100644 --- a/app/models/categorization.rb +++ b/app/models/categorization.rb @@ -3,16 +3,16 @@ class Categorization < ApplicationRecord belongs_to :categorizable, polymorphic: true, touch: true validates :category, :categorizable, presence: true - validates :categorizable_id, uniqueness: { scope: [:category, - :categorizable_type], - message: I18n.t('model.category.already_added') } + validates :categorizable_id, uniqueness: {scope: [:category, + :categorizable_type], + message: I18n.t("model.category.already_added")} validate :use_case private def use_case if category.present? && !category.allowed_use_case?(categorizable_type) - errors.add(:categorizable, 'Not allowed use case') + errors.add(:categorizable, "Not allowed use case") end end end diff --git a/app/models/category.rb b/app/models/category.rb index 3b5c800bf..9011d04c6 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,29 +1,29 @@ class Category < ApplicationRecord - GENERAL = 'general'.freeze - USE_CASES = [GENERAL, 'BlogPost', 'Event', 'News'] + GENERAL = "general".freeze + USE_CASES = [GENERAL, "BlogPost", "Event", "News"] has_many :categorizations, dependent: :destroy translates(:title) globalize_accessors(locales: [:en, :sv], attributes: [:title]) validates :title, :slug, presence: true, uniqueness: true - validates :slug, format: { with: /\A[a-z0-9_-]+\z/, - allow_blank: true, - message: I18n.t('model.category.slug_format') } + validates :slug, format: {with: /\A[a-z0-9_-]+\z/, + allow_blank: true, + message: I18n.t("model.category.slug_format")} validate :use_cases - scope :by_type, -> (type) do - includes(:categorizations). - where(categorizations: { categorizable_type: type }) + scope :by_type, ->(type) do + includes(:categorizations) + .where(categorizations: {categorizable_type: type}) end scope :by_title, -> do - includes(:translations). - with_locales(I18n.available_locales). - order('category_translations.title ASC') + includes(:translations) + .with_locales(I18n.available_locales) + .order("category_translations.title ASC") end - scope :for_use_case, -> (use_case) do - where(use_case: [use_case, 'general']) + scope :for_use_case, ->(use_case) do + where(use_case: [use_case, "general"]) end def self.slugs @@ -31,7 +31,7 @@ def self.slugs end def to_s - title || id + title ||  id end def to_param @@ -48,7 +48,7 @@ def use_cases return if use_case == GENERAL if !USE_CASES.include?(use_case) - errors.add(:use_case, I18n.t('model.category.not_allowed_use_case')) + errors.add(:use_case, I18n.t("model.category.not_allowed_use_case")) end end end diff --git a/app/models/concerns/categorizable.rb b/app/models/concerns/categorizable.rb index e61eb56a3..a0c52876e 100644 --- a/app/models/concerns/categorizable.rb +++ b/app/models/concerns/categorizable.rb @@ -5,6 +5,6 @@ module Categorizable has_many :categorizations, as: :categorizable has_many :categories, through: :categorizations - scope :slug, ->(slug) { joins(:categories).where(categories: { slug: slug }) } + scope :slug, ->(slug) { joins(:categories).where(categories: {slug: slug}) } end end diff --git a/app/models/connected_list.rb b/app/models/connected_list.rb index 1333447a5..a6baa9d32 100644 --- a/app/models/connected_list.rb +++ b/app/models/connected_list.rb @@ -1,5 +1,5 @@ class ConnectedList - KEY_BASE = 'connected_to_group_'.freeze + KEY_BASE = "connected_to_group_".freeze def self.redis @redis ||= ::Redis.new(url: ActionCableConfig[:url]) diff --git a/app/models/constant.rb b/app/models/constant.rb index 4bc89995d..0057862a1 100644 --- a/app/models/constant.rb +++ b/app/models/constant.rb @@ -5,6 +5,6 @@ class Constant < ApplicationRecord def self.get(name) c = Constant.where(name: name).first - c && c.value || '' + c && c.value || "" end end diff --git a/app/models/contacts/contact.rb b/app/models/contacts/contact.rb index fc452a32d..236ff3f5d 100644 --- a/app/models/contacts/contact.rb +++ b/app/models/contacts/contact.rb @@ -1,7 +1,7 @@ class Contact < ApplicationRecord translates(:name, :text) globalize_accessors(locales: [:en, :sv], - attributes: [:name, :text]) + attributes: [:name, :text]) belongs_to :post has_many :users, through: :post @@ -9,8 +9,8 @@ class Contact < ApplicationRecord validates :name, presence: true, if: -> { post_id.nil? } validates :email, :text, presence: true - validates :email, uniqueness: true, format: { with: Devise::email_regexp } - validates :post_id, :slug, uniqueness: { allow_blank: true } + validates :email, uniqueness: true, format: {with: Devise.email_regexp} + validates :post_id, :slug, uniqueness: {allow_blank: true} attr_accessor :message diff --git a/app/models/council.rb b/app/models/council.rb index 3ec70a438..cddc9a453 100644 --- a/app/models/council.rb +++ b/app/models/council.rb @@ -37,7 +37,7 @@ def to_s end def to_param - (url.present?) ? url : id + url.present? ? url : id end def p_url diff --git a/app/models/document.rb b/app/models/document.rb index 63fe21770..e7adf5f9e 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -3,7 +3,7 @@ class Document < ApplicationRecord belongs_to :user validates :title, :category, presence: true - validates :slug, uniqueness: { allow_blank: true } + validates :slug, uniqueness: {allow_blank: true} mount_uploader :pdf, DocumentUploader, mount_on: :pdf_file_name @@ -13,13 +13,13 @@ class Document < ApplicationRecord scope :publik, -> { where(public: true) } def to_s - title || id + title ||  id end def self.categories - where.not(category: nil). - where.not(category: ''). - order(:category). - pluck(:category).uniq + where.not(category: nil) + .where.not(category: "") + .order(:category) + .pluck(:category).uniq end end diff --git a/app/models/elections/election.rb b/app/models/elections/election.rb index 32dcd585a..38d3f6c51 100644 --- a/app/models/elections/election.rb +++ b/app/models/elections/election.rb @@ -9,7 +9,7 @@ class Election < ApplicationRecord validates :url, uniqueness: true, presence: true, - format: { with: /\A[a-z0-9_-]+\z/ } + format: {with: /\A[a-z0-9_-]+\z/} validates :title, :open, :close_general, :close_all, :semester, presence: true @@ -33,13 +33,13 @@ def posts def state t = Time.zone.now if t < open - return :not_opened + :not_opened elsif t >= open && t < close_general - return :before_general + :before_general elsif t < close_all - return :after_general + :after_general else - return :closed + :closed end end @@ -95,11 +95,11 @@ def post_closing(post) end def post_count - candidates.joins(:post).group('posts.id').size.to_h + candidates.joins(:post).group("posts.id").size.to_h end def to_param - (url.present?) ? url : id + url.present? ? url : id end def to_s diff --git a/app/models/elections/election_post.rb b/app/models/elections/election_post.rb index cb9c8c617..7795f0783 100644 --- a/app/models/elections/election_post.rb +++ b/app/models/elections/election_post.rb @@ -2,5 +2,5 @@ class ElectionPost < ApplicationRecord belongs_to :election, required: true belongs_to :post, required: true - validates :post, uniqueness: { scope: :election } + validates :post, uniqueness: {scope: :election} end diff --git a/app/models/events/event.rb b/app/models/events/event.rb index 737cd8ea2..17bfd7b6d 100644 --- a/app/models/events/event.rb +++ b/app/models/events/event.rb @@ -3,10 +3,10 @@ class Event < ApplicationRecord include CarrierWave::Compatibility::Paperclip include Categorizable - TZID = 'Europe/Stockholm'.freeze - SINGLE = 'single'.freeze - DOUBLE = 'double'.freeze - WITHOUT = 'without'.freeze + TZID = "Europe/Stockholm".freeze + SINGLE = "single".freeze + DOUBLE = "double".freeze + WITHOUT = "without".freeze translates(:title, :description, :short, :location) globalize_accessors(locales: [:en, :sv], attributes: [:title, :description, :short, :location]) @@ -32,29 +32,29 @@ class Event < ApplicationRecord scope :by_start, -> { order(starts_at: :asc) } scope :calendar, -> { all } scope :translations, -> { includes(:translations) } - scope :from_date, -> (date) { between(date.beginning_of_day, date.end_of_day) } - scope :after_date, -> (date) { where('starts_at > :date', date: date || 2.weeks.ago) } - scope :between, -> (start, stop) do - where('(starts_at BETWEEN ? AND ?) OR (all_day IS TRUE AND ends_at BETWEEN ? AND ?)', - start, stop, start, stop) + scope :from_date, ->(date) { between(date.beginning_of_day, date.end_of_day) } + scope :after_date, ->(date) { where("starts_at > :date", date: date || 2.weeks.ago) } + scope :between, ->(start, stop) do + where("(starts_at BETWEEN ? AND ?) OR (all_day IS TRUE AND ends_at BETWEEN ? AND ?)", + start, stop, start, stop) end scope :stream, -> do between(Time.zone.now.beginning_of_day, 6.days.from_now.end_of_day).by_start.includes(:event_signup) end scope :starts_within, (lambda do |time| - where('starts_at BETWEEN :first AND :second', - first: Time.zone.now, - second: time.from_now) + where("starts_at BETWEEN :first AND :second", + first: Time.zone.now, + second: time.from_now) end) scope :not_reminded, -> { joins(:event_signup).merge(EventSignup.reminder_not_sent) } scope :by_locale, ->(locale: I18n.locale) do locale = locale.to_s - if locale == 'sv' + if locale == "sv" includes(:translations).all - elsif locale == 'en' - translation = Translation.where(locale: 'en').where.not(title: [nil, '']) + elsif locale == "en" + translation = Translation.where(locale: "en").where.not(title: [nil, ""]) includes(:translations).joins(:translations).merge(translation) else none @@ -62,11 +62,11 @@ class Event < ApplicationRecord end def self.locations_sv - Translation.where(locale: 'sv').select(:location).order(:location).distinct.pluck(:location) + Translation.where(locale: "sv").select(:location).order(:location).distinct.pluck(:location) end def self.locations_en - Translation.where(locale: 'en').select(:location).order(:location).distinct.pluck(:location) + Translation.where(locale: "en").select(:location).order(:location).distinct.pluck(:location) end def signup diff --git a/app/models/events/event_signup.rb b/app/models/events/event_signup.rb index 598ce1e39..f4fa6b124 100644 --- a/app/models/events/event_signup.rb +++ b/app/models/events/event_signup.rb @@ -1,8 +1,8 @@ class EventSignup < ApplicationRecord - NOVICE = 'novice'.freeze - MENTOR = 'mentor'.freeze - MEMBER = 'member'.freeze - CUSTOM = 'custom'.freeze + NOVICE = "novice".freeze + MENTOR = "mentor".freeze + MEMBER = "member".freeze + CUSTOM = "custom".freeze acts_as_paranoid belongs_to :event, required: true @@ -10,7 +10,7 @@ class EventSignup < ApplicationRecord has_many :notifications, as: :notifyable, dependent: :destroy validates(:opens, :closes, presence: true) - validates(:slots, presence: true, numericality: { greater_than: 0 }) + validates(:slots, presence: true, numericality: {greater_than: 0}) validates(:event, uniqueness: true) validate(:orders) @@ -22,13 +22,13 @@ class EventSignup < ApplicationRecord translates(:question, :notification_message) globalize_accessors(locales: [:en, :sv], - attributes: [:question, :notification_message]) + attributes: [:question, :notification_message]) scope :reminder_not_sent, -> { where(sent_reminder: nil) } scope :position_not_sent, -> { where(sent_position: nil) } scope :closing_not_sent, -> { where(sent_closing: nil) } scope :open_not_sent, -> { where(sent_open: nil) } - scope :closed, -> { where('closes < :current', current: Time.zone.now) } + scope :closed, -> { where("closes < :current", current: Time.zone.now) } serialize :group_types, Array @@ -36,10 +36,10 @@ class EventSignup < ApplicationRecord # Removes nil valued keys # Reverses to give the highest value first def order - { NOVICE => novice, - MENTOR => mentor, - MEMBER => member, - CUSTOM => custom }.compact.sort_by(&:last).to_h.keys.reverse + {NOVICE => novice, + MENTOR => mentor, + MEMBER => member, + CUSTOM => custom}.compact.sort_by(&:last).to_h.keys.reverse end def selectable_types(user) @@ -81,14 +81,14 @@ def orders val = val.compact unless val.uniq.length == val.length - errors.add(:novice, I18n.t('model.event_signup.same_priority')) - errors.add(:mentor, I18n.t('model.event_signup.same_priority')) - errors.add(:member, I18n.t('model.event_signup.same_priority')) - errors.add(:custom, I18n.t('model.event_signup.same_priority')) + errors.add(:novice, I18n.t("model.event_signup.same_priority")) + errors.add(:mentor, I18n.t("model.event_signup.same_priority")) + errors.add(:member, I18n.t("model.event_signup.same_priority")) + errors.add(:custom, I18n.t("model.event_signup.same_priority")) end if custom.present? && custom_name.blank? - errors.add(:custom_name, I18n.t('model.event_signup.custom_name_missing')) + errors.add(:custom_name, I18n.t("model.event_signup.custom_name_missing")) end end diff --git a/app/models/events/event_user.rb b/app/models/events/event_user.rb index a97e73ac3..fa1c5257e 100644 --- a/app/models/events/event_user.rb +++ b/app/models/events/event_user.rb @@ -66,38 +66,38 @@ def reserve? def reg_open if event_signup.present? && !event_signup.open? - errors.add(:event, I18n.t('model.event_signup.not_open')) + errors.add(:event, I18n.t("model.event_signup.not_open")) end end def membership if event_signup.present? && event_signup.for_members? && - user.present? && !user.member? - errors.add(:user, I18n.t('model.event_user.user_not_member')) + user.present? && !user.member? + errors.add(:user, I18n.t("model.event_user.user_not_member")) end end def user_types if user_type.present? && !event_signup.order.include?(user_type) - errors.add(:user_type, I18n.t('model.event_user.unavailable_type')) + errors.add(:user_type, I18n.t("model.event_user.unavailable_type")) end end def selected_type if (user_type == EventSignup::NOVICE && !user.novice?) || - (user_type == EventSignup::MENTOR && !user.mentor?) || - (user_type == EventSignup::MEMBER && !user.member?) - errors.add(:user_type, I18n.t('model.event_user.user_type_not_allowed')) + (user_type == EventSignup::MENTOR && !user.mentor?) || + (user_type == EventSignup::MEMBER && !user.member?) + errors.add(:user_type, I18n.t("model.event_user.user_type_not_allowed")) end end def groups if group.present? unless user.groups.include?(group) - errors.add(:group_id, I18n.t('model.event_user.not_in_group')) + errors.add(:group_id, I18n.t("model.event_user.not_in_group")) end unless event_signup.selectable_groups.include?(group) - errors.add(:group_id, I18n.t('model.event_user.unallowed_type')) + errors.add(:group_id, I18n.t("model.event_user.unallowed_type")) end end end @@ -105,7 +105,7 @@ def groups def uniqueness_validation if new_record? || user_id_changed? if EventUser.where(user: user, event: event).any? - errors.add(:user_id, I18n.t('model.event_user.already_registered')) + errors.add(:user_id, I18n.t("model.event_user.already_registered")) end end end diff --git a/app/models/faq.rb b/app/models/faq.rb index 0bfff6ade..a1cc72075 100644 --- a/app/models/faq.rb +++ b/app/models/faq.rb @@ -1,13 +1,13 @@ class Faq < ApplicationRecord validates :question, presence: true - scope :answered, -> { where.not(answer: nil).where.not(answer: '') } + scope :answered, -> { where.not(answer: nil).where.not(answer: "") } scope :category, ->(category) { where(category: category) } def self.categories - where.not(category: nil). - where.not(category: ''). - order(:category). - pluck(:category).uniq + where.not(category: nil) + .where.not(category: "") + .order(:category) + .pluck(:category).uniq end end diff --git a/app/models/fredmansky/fredmansky_data.rb b/app/models/fredmansky/fredmansky_data.rb index 35154bbd5..d8d53db44 100644 --- a/app/models/fredmansky/fredmansky_data.rb +++ b/app/models/fredmansky/fredmansky_data.rb @@ -1,16 +1,16 @@ class FredmanskyData - TITLE = 'Fredmans'.freeze - BODY = 'Fredmans! Fredmans! Fredmans! 🍺 🍻'.freeze + TITLE = "Fredmans".freeze + BODY = "Fredmans! Fredmans! Fredmans! 🍺 🍻".freeze def self.android_data - { title: TITLE, body: BODY, notId: 0 } + {title: TITLE, body: BODY, notId: 0} end def self.ios_notification - { title: TITLE, body: BODY } + {title: TITLE, body: BODY} end def self.ios_data - { notification_id: 0 } + {notification_id: 0} end end diff --git a/app/models/groups/group.rb b/app/models/groups/group.rb index 868cc5c67..3fd9293ae 100644 --- a/app/models/groups/group.rb +++ b/app/models/groups/group.rb @@ -9,15 +9,15 @@ class Group < ApplicationRecord has_many :messages, through: :group_messages has_many :adventure_mission_groups, dependent: :destroy - REGULAR = 'regular'.freeze - MISSION = 'mission'.freeze - INFO = 'info'.freeze - OTHER = 'other'.freeze + REGULAR = "regular".freeze + MISSION = "mission".freeze + INFO = "info".freeze + OTHER = "other".freeze validates :name, presence: true - validates :number, presence: true, numericality: { greater_than: 0 }, if: :regular? + validates :number, presence: true, numericality: {greater_than: 0}, if: :regular? validates :number, absence: true, unless: :regular? - validates :group_type, presence: true, inclusion: { in: [REGULAR, MISSION, INFO, OTHER] } + validates :group_type, presence: true, inclusion: {in: [REGULAR, MISSION, INFO, OTHER]} scope :regular, -> { where(group_type: REGULAR) } scope :missions, -> { where(group_type: MISSION) } @@ -46,14 +46,14 @@ def other? def to_s if introduction.present? - name + ' (' + introduction.year.to_s + ')' + name + " (" + introduction.year.to_s + ")" else name end end def total_published_adventure_points - adventure_mission_groups.where(pending: false).sum('points') + adventure_mission_groups.where(pending: false).sum("points") end def total_published_adventure_missions_accepted diff --git a/app/models/groups/group_message.rb b/app/models/groups/group_message.rb index 7f43eca20..739eefa27 100644 --- a/app/models/groups/group_message.rb +++ b/app/models/groups/group_message.rb @@ -4,14 +4,14 @@ class GroupMessage < ApplicationRecord belongs_to :group, required: true belongs_to :message, required: true - validates :group, uniqueness: { scope: :message } + validates :group, uniqueness: {scope: :message} validate :same_introduction private def same_introduction unless group.introduction == message.introduction - errors.add(:groups, I18n.t('model.message.group_introduction_error')) + errors.add(:groups, I18n.t("model.message.group_introduction_error")) end end end diff --git a/app/models/groups/group_user.rb b/app/models/groups/group_user.rb index d56a48c54..5e64c897f 100644 --- a/app/models/groups/group_user.rb +++ b/app/models/groups/group_user.rb @@ -3,25 +3,25 @@ class GroupUser < ApplicationRecord belongs_to :user, required: true belongs_to :group, required: true - validates :user, uniqueness: { scope: :group } + validates :user, uniqueness: {scope: :group} - scope :novices, -> (introduction: Introduction.current) do + scope :novices, ->(introduction: Introduction.current) do includes(:group).where(fadder: false, - groups: { - introduction_id: introduction, - group_type: [Group::REGULAR, Group::MISSION] - }) + groups: { + introduction_id: introduction, + group_type: [Group::REGULAR, Group::MISSION] + }) end - scope :mentors, -> (introduction: Introduction.current) do + scope :mentors, ->(introduction: Introduction.current) do includes(:group).where(fadder: true, - groups: { - introduction_id: introduction, - group_type: [Group::REGULAR, Group::MISSION] - }) + groups: { + introduction_id: introduction, + group_type: [Group::REGULAR, Group::MISSION] + }) end def to_partial_path - '/groups/group_user' + "/groups/group_user" end end diff --git a/app/models/image.rb b/app/models/image.rb index f7dd024e0..541abaadd 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -6,7 +6,7 @@ class Image < ApplicationRecord store_in_background :file, ImageWorker validates :file, :filename, presence: true - validates :filename, uniqueness: { scope: :album_id, message: '%{value} är redan uppladdad' } + validates :filename, uniqueness: {scope: :album_id, message: "%{value} är redan uppladdad"} scope :by_filename, -> { order(:filename) } diff --git a/app/models/introduction.rb b/app/models/introduction.rb index 4d7dbad2b..7524dee8d 100644 --- a/app/models/introduction.rb +++ b/app/models/introduction.rb @@ -3,7 +3,7 @@ class Introduction < ApplicationRecord acts_as_paranoid translates(:title, :description) globalize_accessors(locales: [:en, :sv], - attributes: [:title, :description]) + attributes: [:title, :description]) attr_reader :dates, :events_by_day, :dates_by_week @@ -16,7 +16,7 @@ class Introduction < ApplicationRecord validates :title, :start, :stop, :slug, presence: true validates :slug, uniqueness: true, presence: true, - format: { with: /\A[a-z0-9-]+\z/ } + format: {with: /\A[a-z0-9-]+\z/} validates :current, uniqueness: true, if: :current scope :all_except, (lambda do |introduction| @@ -28,14 +28,14 @@ def self.current Introduction.where(current: true).first end - def events(locale: 'sv') + def events(locale: "sv") Event.slug(:nollning) - .by_locale(locale: locale) - .between(start, stop) - .by_start + .by_locale(locale: locale) + .between(start, stop) + .by_start end - def events_by_day(locale: 'sv') + def events_by_day(locale: "sv") @events_by_day ||= events(locale: locale).group_by(&:day) end @@ -56,7 +56,7 @@ def year end def to_s - title + ' ' + year.to_s + title + " " + year.to_s end def week(date) diff --git a/app/models/keys/key.rb b/app/models/keys/key.rb index ab5362fdd..93c53fec6 100644 --- a/app/models/keys/key.rb +++ b/app/models/keys/key.rb @@ -1,7 +1,7 @@ class Key < ApplicationRecord validates :name, :description, presence: true - validates :total, numericality: { greater_than: 0, less_than_or_equal_to: 1000000 } - validates :free_count, numericality: { greater_than_or_equal_to: 0 } + validates :total, numericality: {greater_than: 0, less_than_or_equal_to: 1000000} + validates :free_count, numericality: {greater_than_or_equal_to: 0} has_many :key_users, dependent: :restrict_with_error has_many :users, through: :key_users @@ -17,10 +17,10 @@ def self.free def users renters = [] - self.key_users.each do |key_user| + key_users.each do |key_user| renters.push(key_user.user.to_s) end - renters.uniq.join(', ') + renters.uniq.join(", ") end def free_count @@ -28,10 +28,10 @@ def free_count end def to_s - %(#{name}) + name.to_s end def to_s_and_free - to_s + ' (Antal lediga: ' + free_count.to_s + ')' + to_s + " (Antal lediga: " + free_count.to_s + ")" end end diff --git a/app/models/mail_alias.rb b/app/models/mail_alias.rb index 3b09705b7..3a6ca6ba3 100644 --- a/app/models/mail_alias.rb +++ b/app/models/mail_alias.rb @@ -1,21 +1,21 @@ class MailAlias < ApplicationRecord - VALID_DOMAINS = [ 'fsektionen.se', - 'fsek.lth.se', - 'farad.nu' ] - - validates :username, :domain, :target, :presence => true - validates :username, :format => /\A[A-Za-z0-9_.+-]+\z/ - validates :username, :uniqueness => { :scope => [ :domain, :target ] } - validates :domain, :inclusion => VALID_DOMAINS - validates :target, :format => /\A[A-Za-z0-9_.+-]+@[A-Za-z0-9_.+-]+\z/ - - scope :fulltext_search, -> (str) do - (username, domain) = str.split('@', 2) + VALID_DOMAINS = ["fsektionen.se", + "fsek.lth.se", + "farad.nu"] + + validates :username, :domain, :target, presence: true + validates :username, format: /\A[A-Za-z0-9_.+-]+\z/ + validates :username, uniqueness: {scope: [:domain, :target]} + validates :domain, inclusion: VALID_DOMAINS + validates :target, format: /\A[A-Za-z0-9_.+-]+@[A-Za-z0-9_.+-]+\z/ + + scope :fulltext_search, ->(str) do + (username, domain) = str.split("@", 2) if domain.present? - return where('username = ? and domain = ?', - username, domain) + return where("username = ? and domain = ?", + username, domain) elsif username.present? - return where('username like ?', "%#{username}%") + return where("username like ?", "%#{username}%") else return all end @@ -23,8 +23,8 @@ class MailAlias < ApplicationRecord def self.insert_aliases! username, domain, targets # Update the alias to contain only those targets given. - self.transaction do - base_scope = MailAlias.where 'username = ? and domain = ?', username, domain + transaction do + base_scope = MailAlias.where "username = ? and domain = ?", username, domain if targets.empty? base_scope.delete_all # Not validated @@ -33,17 +33,17 @@ def self.insert_aliases! username, domain, targets # The queries below only work if targets != [] - to_remove = base_scope.where 'target not in (?)', targets + to_remove = base_scope.where "target not in (?)", targets to_remove.delete_all # Not validated - existing = base_scope.where 'target in (?)', targets - existing.update_all :updated_at => Time.zone.now # Not validated + existing = base_scope.where "target in (?)", targets + existing.update_all updated_at: Time.zone.now # Not validated existing_targets = existing.pluck(:target) - to_create = targets.reject{ |t| existing_targets.include? t } + to_create = targets.reject { |t| existing_targets.include? t } to_create.each do |t| - MailAlias.create! :username => username, :domain => domain, :target => t + MailAlias.create! username: username, domain: domain, target: t end return base_scope.reload diff --git a/app/models/main_menu.rb b/app/models/main_menu.rb index 34dc17cca..f33ae0d87 100644 --- a/app/models/main_menu.rb +++ b/app/models/main_menu.rb @@ -12,6 +12,6 @@ def to_s end def partial_path - mega ? '/main_menu/mega_menu' : '/main_menu/small_menu' + mega ? "/main_menu/mega_menu" : "/main_menu/small_menu" end end diff --git a/app/models/meeting.rb b/app/models/meeting.rb index 7250bf3bb..900793e4c 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -1,6 +1,6 @@ class Meeting < ApplicationRecord - enum status: { unconfirmed: 0, confirmed: 1, denied: 2 } - enum room: { sk: 0, alumni: 1, sister_kent: 2 } + enum status: {unconfirmed: 0, confirmed: 1, denied: 2} + enum room: {sk: 0, alumni: 1, sister_kent: 2} belongs_to :user, required: true belongs_to :council @@ -11,17 +11,17 @@ class Meeting < ApplicationRecord attr_accessor :occurrences validates :title, presence: true - validates :status, presence: true, inclusion: { in: ['unconfirmed'] }, unless: :is_admin - validates :status, presence: true, inclusion: { in: statuses.keys }, if: :is_admin - validates :room, presence: true, inclusion: { in: rooms.keys } + validates :status, presence: true, inclusion: {in: ["unconfirmed"]}, unless: :is_admin + validates :status, presence: true, inclusion: {in: statuses.keys}, if: :is_admin + validates :room, presence: true, inclusion: {in: rooms.keys} validate :date_validation, :overlap_validation validate :membership_validation, :council_validation, unless: :is_admin - scope :between, ->(from, to) { where('? > start_date AND ? < end_date', to, from) } + scope :between, ->(from, to) { where("? > start_date AND ? < end_date", to, from) } scope :date_overlap, ->(from, to, id) { between(from, to).where.not(id: id) } scope :for_room, ->(room) { where(room: rooms[room]) } - scope :from_date, ->(from) { where('start_date >= ?', from) } + scope :from_date, ->(from) { where("start_date >= ?", from) } def as_json(*) CalendarJSON.meeting(self) @@ -47,30 +47,30 @@ def to_s def membership_validation unless user.present? && user.member? - errors.add(:user, I18n.t('model.meeting.membership_needed')) + errors.add(:user, I18n.t("model.meeting.membership_needed")) end unless user.present? && user.has_attributes? - errors.add(:user, I18n.t('model.meeting.add_user_information')) + errors.add(:user, I18n.t("model.meeting.add_user_information")) end end def date_validation unless start_date.present? && end_date.present? && start_date < end_date - errors.add(:end_date, I18n.t('model.meeting.end_after_start')) + errors.add(:end_date, I18n.t("model.meeting.end_after_start")) end end def overlap_validation if confirmed? && Meeting.date_overlap(start_date, end_date, id).confirmed.for_room(room).any? - errors.add(:start_date, I18n.t('model.meeting.overlaps_confirmed')) - errors.add(:end_date, I18n.t('model.meeting.overlaps_confirmed')) + errors.add(:start_date, I18n.t("model.meeting.overlaps_confirmed")) + errors.add(:end_date, I18n.t("model.meeting.overlaps_confirmed")) end end def council_validation if council.present? && user.present? && !user.councils.include?(council) - errors.add(:council, I18n.t('model.meeting.council_error')) + errors.add(:council, I18n.t("model.meeting.council_error")) end end end diff --git a/app/models/menu.rb b/app/models/menu.rb index aa9f9184d..a6eac0c42 100644 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -15,7 +15,7 @@ def to_s def to_partial_path if header? - '/menus/menu_header' + "/menus/menu_header" else super end diff --git a/app/models/messages/message.rb b/app/models/messages/message.rb index 15fae4ff5..c8dd874e3 100644 --- a/app/models/messages/message.rb +++ b/app/models/messages/message.rb @@ -10,7 +10,7 @@ class Message < ApplicationRecord mount_uploader :image, MessageImageUploader paginates_per(30) - validates :groups, length: { minimum: 1, message: I18n.t('model.message.need_groups') } + validates :groups, length: {minimum: 1, message: I18n.t("model.message.need_groups")} validates :content, presence: true, if: -> { image.blank? } validate :in_group, unless: :by_admin @@ -34,7 +34,7 @@ def with_group(user) end def group_names - groups.pluck(:name).join(', '); + groups.pluck(:name).join(", ") end private @@ -45,7 +45,7 @@ def with_all_groups? def in_group unless user.nil? || with_all_groups? - errors.add(:groups, I18n.t('model.message.not_part_of_selected_groups')) + errors.add(:groups, I18n.t("model.message.not_part_of_selected_groups")) end end diff --git a/app/models/messages/message_data.rb b/app/models/messages/message_data.rb index e81a37b87..6701c17de 100644 --- a/app/models/messages/message_data.rb +++ b/app/models/messages/message_data.rb @@ -8,15 +8,15 @@ def initialize(message, group) end def android_data - { title: group.name, body: body, notId: -group.id, style: :inbox, group_id: group.id } + {title: group.name, body: body, notId: -group.id, style: :inbox, group_id: group.id} end def ios_notification - { title: group.name, body: body } + {title: group.name, body: body} end def ios_data # Use negative notification id to distinguish from `Notifications` - { notification_id: -message.id, group_id: group.id } + {notification_id: -message.id, group_id: group.id} end end diff --git a/app/models/messages/message_token.rb b/app/models/messages/message_token.rb index bdc253325..2500a9661 100644 --- a/app/models/messages/message_token.rb +++ b/app/models/messages/message_token.rb @@ -1,5 +1,5 @@ class MessageToken - KEY_BASE = 'message_token_'.freeze + KEY_BASE = "message_token_".freeze def self.redis @redis ||= ::Redis.new(url: ActionCableConfig[:url]) @@ -15,7 +15,7 @@ def self.add(user_id) expires = 30.seconds.from_now.to_i redis.expireat(KEY_BASE + token, expires) - data = { token: token, expires: expires } + data = {token: token, expires: expires} end # Finds the user_id for a token and removes the token diff --git a/app/models/news.rb b/app/models/news.rb index fd5bba60d..fc573564b 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -13,13 +13,13 @@ class News < ApplicationRecord # Scopes scope :for_feed, -> { includes(:translations, :categories, :user).order(created_at: :desc) } scope :pinned, -> do - where('pinned_from <= ? AND (pinned_to > ? OR pinned_to IS NULL)', - Time.zone.now, Time.zone.now) + where("pinned_from <= ? AND (pinned_to > ? OR pinned_to IS NULL)", + Time.zone.now, Time.zone.now) end scope :unpinned, -> do - where('pinned_from IS NULL OR pinned_from > ? OR pinned_to < ?', - Time.zone.now, Time.zone.now) + where("pinned_from IS NULL OR pinned_from > ? OR pinned_to < ?", + Time.zone.now, Time.zone.now) end def to_s @@ -42,7 +42,7 @@ def thumb def pinned_validation if pinned_from.present? && pinned_to.present? && pinned_to < pinned_from - errors.add(:pinned_to, t('model.news.pinned_dates_error')) + errors.add(:pinned_to, t("model.news.pinned_dates_error")) end end end diff --git a/app/models/nomination.rb b/app/models/nomination.rb index 11ba114b1..6b451ba93 100644 --- a/app/models/nomination.rb +++ b/app/models/nomination.rb @@ -3,20 +3,20 @@ class Nomination < ApplicationRecord belongs_to :post, required: true validates :name, :email, presence: true - validates :email, format: { with: /\A.+@.+\..+\z/i, - message: I18n.t('model.nomination.invalid_email') } - validate :valid_post, if: Proc.new { |o| o.election.present? && o.post.present? } + validates :email, format: {with: /\A.+@.+\..+\z/i, + message: I18n.t("model.nomination.invalid_email")} + validate :valid_post, if: proc { |o| o.election.present? && o.post.present? } def candidate_url Rails.application.routes.url_helpers.new_candidate_url(post: post, - host: PUBLIC_URL) + host: PUBLIC_URL) end private def valid_post unless election.searchable_posts.where(id: post.id).any? - errors.add(:post, I18n.t('model.nomination.not_valid_post')) + errors.add(:post, I18n.t("model.nomination.not_valid_post")) end end end diff --git a/app/models/notifications/notification.rb b/app/models/notifications/notification.rb index b044bd9e9..391e46325 100644 --- a/app/models/notifications/notification.rb +++ b/app/models/notifications/notification.rb @@ -1,6 +1,6 @@ class Notification < ApplicationRecord enum(event_users: [:reminder, :position], event_signup: [:closing, :open]) - ALLOWED = { 'EventUser' => event_users, 'EventSignup' => event_signups }.freeze + ALLOWED = {"EventUser" => event_users, "EventSignup" => event_signups}.freeze belongs_to :user, required: true, inverse_of: :notifications belongs_to :notifyable, polymorphic: true, required: true @@ -33,10 +33,10 @@ def valid_notifyable if allowed_class?(notifyable) unless allowed_mode?(notifyable, mode) - errors.add(:mode, I18n.t('model.notification.mode_not_allowed')) + errors.add(:mode, I18n.t("model.notification.mode_not_allowed")) end else - errors.add(:notifyable, I18n.t('model.notification.class_not_allowed')) + errors.add(:notifyable, I18n.t("model.notification.class_not_allowed")) end end @@ -53,7 +53,7 @@ def update_counter_cache end def send_push - if (notifyable_type == 'EventUser' && user.notify_event_users) || notifyable_type == 'EventSignup' + if (notifyable_type == "EventUser" && user.notify_event_users) || notifyable_type == "EventSignup" PushService.push(data, user) end end diff --git a/app/models/notifications/notification_data.rb b/app/models/notifications/notification_data.rb index 00d47830e..97258ba44 100644 --- a/app/models/notifications/notification_data.rb +++ b/app/models/notifications/notification_data.rb @@ -5,27 +5,27 @@ def initialize(notification) @notification = notification @notifyable = notification.notifyable - if @notification.notifyable_type == 'EventUser' + if @notification.notifyable_type == "EventUser" init_event_user - elsif @notification.notifyable_type == 'EventSignup' + elsif @notification.notifyable_type == "EventSignup" init_event_signup end end def for_serializer - { title: title, body: MarkdownHelper.markdown(body), extra: extra } + {title: title, body: MarkdownHelper.markdown(body), extra: extra} end def android_data - { title: title, body: MarkdownHelper.markdown_plain(body), notId: notification.id } + {title: title, body: MarkdownHelper.markdown_plain(body), notId: notification.id} end def ios_notification - { title: title, body: MarkdownHelper.markdown_plain(body) } + {title: title, body: MarkdownHelper.markdown_plain(body)} end def ios_data - { notification_id: notification.id } + {notification_id: notification.id} end private @@ -34,19 +34,19 @@ def init_event_user @title = @notifyable.event.title @link = @notifyable.event - if @notification.mode == 'position' + if @notification.mode == "position" init_position - elsif @notification.mode == 'reminder' + elsif @notification.mode == "reminder" init_reminder end end def init_position - @icon = 'hashtag' - if @notifyable.reserve? - @body = I18n.t('model.notification_data.reserve_position', event: @notifyable.event) + @icon = "hashtag" + @body = if @notifyable.reserve? + I18n.t("model.notification_data.reserve_position", event: @notifyable.event) else - @body = I18n.t('model.notification_data.attending', event: @notifyable.event) + I18n.t("model.notification_data.attending", event: @notifyable.event) end if @notifyable.event_signup.notification_message.present? @@ -55,21 +55,21 @@ def init_position end def init_reminder - @icon = 'calendar-alt' - @body = I18n.t('model.notification_data.remind_soon_starting', - event: @notifyable.event, - time: I18n.l(@notifyable.event.starts_at)) + @icon = "calendar-alt" + @body = I18n.t("model.notification_data.remind_soon_starting", + event: @notifyable.event, + time: I18n.l(@notifyable.event.starts_at)) end def init_event_signup - @icon = 'calendar-alt' - if @notification.mode == 'closing' - @body = I18n.t('model.notification_data.remind_signup_soon_closing', - event: @notifyable.event, - time: I18n.l(@notifyable.event.signup.closes)) - elsif @notification.mode == 'open' - @body = I18n.t('model.notification_data.remind_signup_open', - event: @notifyable.event) + @icon = "calendar-alt" + if @notification.mode == "closing" + @body = I18n.t("model.notification_data.remind_signup_soon_closing", + event: @notifyable.event, + time: I18n.l(@notifyable.event.signup.closes)) + elsif @notification.mode == "open" + @body = I18n.t("model.notification_data.remind_signup_open", + event: @notifyable.event) end end end diff --git a/app/models/pages/page.rb b/app/models/pages/page.rb index 988e0f119..71e44a062 100644 --- a/app/models/pages/page.rb +++ b/app/models/pages/page.rb @@ -8,24 +8,24 @@ class Page < ApplicationRecord validates :title, presence: true validates :url, uniqueness: true, presence: true, - format: { with: /\A[a-z0-9_-]+\z/ } - validates :namespace, format: { with: /\A[a-z0-9_-]+\z/, - allow_blank: true, - message: I18n.t('model.page.namespace_format') } + format: {with: /\A[a-z0-9_-]+\z/} + validates :namespace, format: {with: /\A[a-z0-9_-]+\z/, + allow_blank: true, + message: I18n.t("model.page.namespace_format")} translates(:title) globalize_accessors(locales: [:en, :sv], - attributes: [:title]) + attributes: [:title]) scope :publik, -> { where(public: true) } scope :visible, -> { where(visible: true) } attr_accessor :image_upload def self.namespaces - where.not(namespace: nil). - where.not(namespace: ''). - order(:namespace). - pluck(:namespace).uniq + where.not(namespace: nil) + .where.not(namespace: "") + .order(:namespace) + .pluck(:namespace).uniq end def main diff --git a/app/models/pages/page_element.rb b/app/models/pages/page_element.rb index 44513d084..df093e2df 100644 --- a/app/models/pages/page_element.rb +++ b/app/models/pages/page_element.rb @@ -1,13 +1,13 @@ class PageElement < ApplicationRecord - TEXT = 'text'.freeze - IMAGE = 'image'.freeze + TEXT = "text".freeze + IMAGE = "image".freeze belongs_to :page, required: true belongs_to :page_image belongs_to :contact translates(:text, :headline) globalize_accessors(locales: [:en, :sv], - attributes: [:text, :headline]) + attributes: [:text, :headline]) validates :element_type, presence: true validates :text, presence: true, if: :text_element? diff --git a/app/models/permissions/permission.rb b/app/models/permissions/permission.rb index e1e44d497..c733ed88d 100644 --- a/app/models/permissions/permission.rb +++ b/app/models/permissions/permission.rb @@ -1,5 +1,5 @@ class Permission < ApplicationRecord - CUSTOM = ['all', 'cafe'].freeze + CUSTOM = ["all", "cafe"].freeze has_many :posts, through: :permission_posts has_many :permission_posts validates :subject_class, :action, presence: true diff --git a/app/models/posts/post.rb b/app/models/posts/post.rb index e2c89291a..b44d69819 100644 --- a/app/models/posts/post.rb +++ b/app/models/posts/post.rb @@ -1,13 +1,13 @@ class Post < ApplicationRecord - AUTUMN = 'autumn'.freeze - SPRING = 'spring'.freeze - BOTH = 'both'.freeze - OTHER = 'other'.freeze + AUTUMN = "autumn".freeze + SPRING = "spring".freeze + BOTH = "both".freeze + OTHER = "other".freeze - BOARD = 'board'.freeze - EDUCATION = 'education'.freeze - GENERAL = 'general'.freeze - EXTRA = 'extra'.freeze + BOARD = "board".freeze + EDUCATION = "education".freeze + GENERAL = "general".freeze + EXTRA = "extra".freeze translates(:title, :description, fallbacks_for_empty_translations: true) globalize_accessors(locales: [:en, :sv], attributes: [:title, :description]) @@ -31,13 +31,13 @@ class Post < ApplicationRecord scope :general, -> { where(elected_by: GENERAL) } scope :not_general, -> { where.not(elected_by: GENERAL) } - scope :autumn, -> { where('semester = ? OR semester = ?', AUTUMN, BOTH) } - scope :spring, -> { where('semester = ? OR semester = ?', SPRING, BOTH) } + scope :autumn, -> { where("semester = ? OR semester = ?", AUTUMN, BOTH) } + scope :spring, -> { where("semester = ? OR semester = ?", SPRING, BOTH) } scope :both, -> { where(semester: BOTH) } # Validations validates(:title, :description, :limit, - :rec_limit, :elected_by, :semester, presence: true) + :rec_limit, :elected_by, :semester, presence: true) # Scopes scope :renters, -> { where(car_rent: true) } diff --git a/app/models/posts/post_user.rb b/app/models/posts/post_user.rb index f37e1e3a5..d7ae2be2c 100644 --- a/app/models/posts/post_user.rb +++ b/app/models/posts/post_user.rb @@ -4,8 +4,8 @@ class PostUser < ApplicationRecord has_one :council, through: :post validates :user_id, :post_id, presence: true - validates :user_id, uniqueness: { scope: :post_id, - message: I18n.t('model.post_user.already_have_post') } + validates :user_id, uniqueness: {scope: :post_id, + message: I18n.t("model.post_user.already_have_post")} scope :from_post, ->(id) { where(post_id: id) } def to_s diff --git a/app/models/push_device.rb b/app/models/push_device.rb index 9c01c4f8b..98448c7e5 100644 --- a/app/models/push_device.rb +++ b/app/models/push_device.rb @@ -1,9 +1,9 @@ class PushDevice < ApplicationRecord - enum system: { android: 0, ios: 1 } + enum system: {android: 0, ios: 1} belongs_to :user, required: true validates :system, presence: true - validates :token, presence: true, uniqueness: { scope: [:user_id] } + validates :token, presence: true, uniqueness: {scope: [:user_id]} def to_param token diff --git a/app/models/recurring_meeting.rb b/app/models/recurring_meeting.rb index 506cf94df..34f27921e 100644 --- a/app/models/recurring_meeting.rb +++ b/app/models/recurring_meeting.rb @@ -1,7 +1,7 @@ class RecurringMeeting < ApplicationRecord has_many :meetings, dependent: :destroy - validates :every, presence: true, numericality: { greater_than_or_equal_to: 1 } + validates :every, presence: true, numericality: {greater_than_or_equal_to: 1} def occurrences meetings.count diff --git a/app/models/short_link.rb b/app/models/short_link.rb index 02fb28da8..c54c69f9a 100644 --- a/app/models/short_link.rb +++ b/app/models/short_link.rb @@ -1,21 +1,21 @@ -require 'uri' +require "uri" class ShortLink < ApplicationRecord - validates :link, :target, :presence => true - validates :link, :uniqueness => true - validates :link, :format => /\A[a-z0-9_-]+\z/ - validates :link, :exclusion => { :in => RoutePrefixes::PREFIXES } + validates :link, :target, presence: true + validates :link, uniqueness: true + validates :link, format: /\A[a-z0-9_-]+\z/ + validates :link, exclusion: {in: RoutePrefixes::PREFIXES} validate -> do # target is a valid url begin # require u to be valid uri u = URI.parse target # require u to have at least two host components (google.com not google) - if u.host !~ /\./ + if !/\./.match?(u.host) fail URI::InvalidURIError end rescue URI::InvalidURIError - errors.add :target, I18n.t('model.short_link.invalid_url') + errors.add :target, I18n.t("model.short_link.invalid_url") end end diff --git a/app/models/song.rb b/app/models/song.rb index 30fbc42d5..4384ea5a6 100644 --- a/app/models/song.rb +++ b/app/models/song.rb @@ -8,7 +8,7 @@ def to_s def self.title_search(title) if title.present? - Song.where('title ILIKE ?', "%#{title}%").limit(10) + Song.where("title ILIKE ?", "%#{title}%").limit(10) end end diff --git a/app/models/tools/tool.rb b/app/models/tools/tool.rb index 5c6400a81..f4d4e7db6 100644 --- a/app/models/tools/tool.rb +++ b/app/models/tools/tool.rb @@ -2,7 +2,7 @@ class Tool < ApplicationRecord has_many :tool_rentings, dependent: :restrict_with_error validates :title, :total, presence: true - validates :total, numericality: { greater_than: 0 } + validates :total, numericality: {greater_than: 0} validate :total_greater_than_rented def free @@ -14,7 +14,7 @@ def free def total_greater_than_rented rented = tool_rentings.where(returned: false).size if total.present? && total < rented - errors.add(:total, I18n.t('model.tool.not_allowed_change_total')) + errors.add(:total, I18n.t("model.tool.not_allowed_change_total")) end end end diff --git a/app/models/tools/tool_renting.rb b/app/models/tools/tool_renting.rb index e4a372854..582dc68ae 100644 --- a/app/models/tools/tool_renting.rb +++ b/app/models/tools/tool_renting.rb @@ -9,13 +9,13 @@ class ToolRenting < ApplicationRecord def there_are_free_tools if !persisted? && tool.present? && tool.free == 0 - errors.add(:returned, I18n.t('model.tool_renting.no_more_tools')) + errors.add(:returned, I18n.t("model.tool_renting.no_more_tools")) end end def return_date_lesser_than_today if !persisted? && tool.present? && return_date < Date.today - errors.add(:returned, I18n.t('model.tool_renting.return_date_lesser_than_today')) + errors.add(:returned, I18n.t("model.tool_renting.return_date_lesser_than_today")) end end end diff --git a/app/models/user.rb b/app/models/user.rb index 972d47aab..555e8991b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,25 +1,25 @@ class User < ApplicationRecord # Must be on top! devise(:database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, - :confirmable) + :recoverable, :rememberable, :trackable, :validatable, + :confirmable) include DeviseTokenAuth::Concerns::User include CarrierWave::Compatibility::Paperclip - PHYSICS = 'Teknisk Fysik'.freeze - MATH = 'Teknisk Matematik'.freeze - NANO = 'Teknisk Nanovetenskap'.freeze - OTHER = 'Oklart'.freeze - FOOD_PREFS = ['vegetarian', 'vegan', 'pescetarian', 'milk', 'gluten'].freeze + PHYSICS = "Teknisk Fysik".freeze + MATH = "Teknisk Matematik".freeze + NANO = "Teknisk Nanovetenskap".freeze + OTHER = "Oklart".freeze + FOOD_PREFS = ["vegetarian", "vegan", "pescetarian", "milk", "gluten"].freeze validates :email, uniqueness: true - validates :email, format: { with: Devise::email_regexp } - validates :firstname, :lastname, presence: true, format: { with: /\A[\p{L}\p{M}*\-\p{Zs}]{2,}\z/ } + validates :email, format: {with: Devise.email_regexp} + validates :firstname, :lastname, presence: true, format: {with: /\A[\p{L}\p{M}*\-\p{Zs}]{2,}\z/} validates :password_confirmation, presence: true, on: :create validates :start_year, - numericality: { greater_than_or_equal_to: 1961, less_than_or_equal_to: Time.current.year }, - allow_nil: true + numericality: {greater_than_or_equal_to: 1961, less_than_or_equal_to: Time.current.year}, + allow_nil: true validate :food_validation # Associations @@ -48,8 +48,8 @@ class User < ApplicationRecord mount_uploader :avatar, AttachedImageUploader, mount_on: :avatar_file_name scope :by_firstname, -> { order(firstname: :asc) } - scope :members, -> { where('member_at < ?', Time.zone.now) } - scope :confirmed, -> { where('confirmed_at < ?', Time.zone.now) } + scope :members, -> { where("member_at < ?", Time.zone.now) } + scope :confirmed, -> { where("confirmed_at < ?", Time.zone.now) } serialize :food_preferences, Array @@ -84,11 +84,11 @@ def print_program end def program_year - str = '' - str = 'F' if program == PHYSICS - str = 'Pi' if program == MATH - str = 'N' if program == NANO - str += start_year.to_s.split(//).last(2).join if start_year.present? + str = "" + str = "F" if program == PHYSICS + str = "Pi" if program == MATH + str = "N" if program == NANO + str += start_year.to_s.split("").last(2).join if start_year.present? str end @@ -127,7 +127,7 @@ def mentor? def food_validation if food_preferences.present? unless (food_preferences - [""] - FOOD_PREFS).empty? - errors.add(:food_preferences, I18n.t('model.user.only_predefined_food_prefs')) + errors.add(:food_preferences, I18n.t("model.user.only_predefined_food_prefs")) end end end diff --git a/app/models/work_post.rb b/app/models/work_post.rb index f346d9e77..fac2a3d76 100644 --- a/app/models/work_post.rb +++ b/app/models/work_post.rb @@ -2,19 +2,19 @@ class WorkPost < ApplicationRecord belongs_to :user validates :title, :description, :company, - :kind, :target_group, :field, - presence: true + :kind, :target_group, :field, + presence: true mount_uploader :image, AttachedImageUploader scope :visible, -> { where(visible: true) } - scope :by_deadline, -> { where('deadline > ? OR deadline IS NULL', Time.zone.now) } - scope :by_published, -> { where('publish < ? OR publish IS NULL', Time.zone.now) } + scope :by_deadline, -> { where("deadline > ? OR deadline IS NULL", Time.zone.now) } + scope :by_published, -> { where("publish < ? OR publish IS NULL", Time.zone.now) } scope :published, -> { visible.by_deadline.by_published } - scope :target, -> (target) { where(target_group: target) } - scope :field, -> (field) { where(field: field) } - scope :kind, -> (kind) { where(kind: kind) } + scope :target, ->(target) { where(target_group: target) } + scope :field, ->(field) { where(field: field) } + scope :kind, ->(kind) { where(kind: kind) } def self.companies select(:company).order(:company).distinct.pluck(:company) diff --git a/app/query_objects/adventure_queries.rb b/app/query_objects/adventure_queries.rb index 40590773c..492f6610f 100644 --- a/app/query_objects/adventure_queries.rb +++ b/app/query_objects/adventure_queries.rb @@ -1,9 +1,9 @@ class AdventureQueries def self.highscore_list - AdventureMissionGroup.select('groups.name, sum(points) AS total_points, count(points) AS finished_missions') - .joins({group: :introduction}, {adventure_mission: :adventure}) - .where('introductions.current = true AND adventures.publish_results = true AND adventure_mission_groups.pending = false') - .group('groups.name') - .order('total_points DESC, finished_missions DESC, groups.name ASC') + AdventureMissionGroup.select("groups.name, sum(points) AS total_points, count(points) AS finished_missions") + .joins({group: :introduction}, {adventure_mission: :adventure}) + .where("introductions.current = true AND adventures.publish_results = true AND adventure_mission_groups.pending = false") + .group("groups.name") + .order("total_points DESC, finished_missions DESC, groups.name ASC") end end diff --git a/app/query_objects/album_queries.rb b/app/query_objects/album_queries.rb index 40dc98188..25eeeef1b 100644 --- a/app/query_objects/album_queries.rb +++ b/app/query_objects/album_queries.rb @@ -1,8 +1,8 @@ class AlbumQueries def self.photographer_names(album) - album.images.select('distinct on (images.photographer_id) photographer_id, '\ - 'images.id as iid, users.id as uid, users.firstname as firstname, '\ - ' users.lastname as lastname') - .joins('JOIN users on users.id = images.photographer_id') + album.images.select("distinct on (images.photographer_id) photographer_id, "\ + "images.id as iid, users.id as uid, users.firstname as firstname, "\ + " users.lastname as lastname") + .joins("JOIN users on users.id = images.photographer_id") end end diff --git a/app/query_objects/cafe_queries.rb b/app/query_objects/cafe_queries.rb index 3aff02b8f..696a285b1 100644 --- a/app/query_objects/cafe_queries.rb +++ b/app/query_objects/cafe_queries.rb @@ -10,31 +10,31 @@ def self.cafe_workers(lp, year) end def self.highscore_groups(lp, year) - (score_group(lp, year).group('group') + - score_council(lp, year).group('councils.id, title')). - sort_by { |g| -g[:score] } + (score_group(lp, year).group("group") + + score_council(lp, year).group("councils.id, title")) + .sort_by { |g| -g[:score] } end def self.highscore(lp, year, amount) - join_cafe_shifts(User.select('users.id, users.firstname, users.lastname, count(*) as score'). - joins(:cafe_shifts), lp, year). - group('users.id'). - order('score desc'). - limit(amount) + join_cafe_shifts(User.select("users.id, users.firstname, users.lastname, count(*) as score") + .joins(:cafe_shifts), lp, year) + .group("users.id") + .order("score desc") + .limit(amount) end # Currently only used from rails c def self.highscore_all(lp, year) - join_cafe_shifts(User.select('users.id, users.firstname, users.lastname, count(*) as score'). - joins(:cafe_shifts), lp, year). - group('users.id'). - order('score desc') + join_cafe_shifts(User.select("users.id, users.firstname, users.lastname, count(*) as score") + .joins(:cafe_shifts), lp, year) + .group("users.id") + .order("score desc") end def self.free_shifts(lp, year) - CafeShift.where(lp: lp). - where('start > ? and extract(year from start) = ?', Time.zone.now, year.year). - without_worker + CafeShift.where(lp: lp) + .where("start > ? and extract(year from start) = ?", Time.zone.now, year.year) + .without_worker end def self.for_day(day) @@ -42,15 +42,15 @@ def self.for_day(day) end def self.between(start, stop) - CafeShift.where('start BETWEEN ? AND ?', start, stop). - order(pass: :asc). - includes(:user) + CafeShift.where("start BETWEEN ? AND ?", start, stop) + .order(pass: :asc) + .includes(:user) end def self.between_by_start(start, stop) - CafeShift.where('start BETWEEN ? AND ?', start, stop). - order(start: :asc, pass: :asc). - includes(:user) + CafeShift.where("start BETWEEN ? AND ?", start, stop) + .order(start: :asc, pass: :asc) + .includes(:user) end # If past year, give end of year @@ -65,21 +65,21 @@ def self.year_or_today(year) # Join with cafe shifts in given study period(lp) and year def self.join_cafe_shifts(join, lp, year) - join.where(cafe_shifts: { lp: lp }). - where('cafe_shifts.start > ?', year.beginning_of_year). - where('cafe_shifts.start < ?', year_or_today(year)) + join.where(cafe_shifts: {lp: lp}) + .where("cafe_shifts.start > ?", year.beginning_of_year) + .where("cafe_shifts.start < ?", year_or_today(year)) end def self.score_group(lp, year) - join_cafe_shifts(CafeWorker.where(competition: true). - where.not(group: '').where.not(group: nil). - select('cafe_workers.group as title, count(*) as score'). - joins(:cafe_shift), lp, year) + join_cafe_shifts(CafeWorker.where(competition: true) + .where.not(group: "").where.not(group: nil) + .select("cafe_workers.group as title, count(*) as score") + .joins(:cafe_shift), lp, year) end def self.score_council(lp, year) - join_cafe_shifts(Council.select('count(*) as score').joins(:cafe_shifts), lp, year).joins(:translations). - where('council_translations.locale = ?', I18n.locale). - select('council_translations.title as title') + join_cafe_shifts(Council.select("count(*) as score").joins(:cafe_shifts), lp, year).joins(:translations) + .where("council_translations.locale = ?", I18n.locale) + .select("council_translations.title as title") end end diff --git a/app/renderers/message_renderer.rb b/app/renderers/message_renderer.rb index 9188298be..4acfb3c1b 100644 --- a/app/renderers/message_renderer.rb +++ b/app/renderers/message_renderer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class MessageRenderer < Redcarpet::Render::HTML - DEFAULT_OPTIONS = { hard_wrap: true, escape_html: true }.freeze + DEFAULT_OPTIONS = {hard_wrap: true, escape_html: true}.freeze def initialize(options) super(DEFAULT_OPTIONS.merge(options)) diff --git a/app/serializers/api/adventure_mission_serializer.rb b/app/serializers/api/adventure_mission_serializer.rb index bea26276d..e25879dd5 100644 --- a/app/serializers/api/adventure_mission_serializer.rb +++ b/app/serializers/api/adventure_mission_serializer.rb @@ -11,7 +11,7 @@ def accepted def pending @group = scope[:current_user].groups.regular.last - object.finished?(@group) and not object.accepted?(@group) + object.finished?(@group) and !object.accepted?(@group) end end end diff --git a/app/serializers/api/adventure_serializer.rb b/app/serializers/api/adventure_serializer.rb index 107784d52..57bb41837 100644 --- a/app/serializers/api/adventure_serializer.rb +++ b/app/serializers/api/adventure_serializer.rb @@ -1,15 +1,15 @@ class Api::AdventureSerializer < ActiveModel::Serializer class Api::AdventureSerializer::Index < ActiveModel::Serializer has_many :adventure_missions, - serializer: Api::AdventureMissionSerializer::Index, - scope: { - 'current_user': :current_user - } + serializer: Api::AdventureMissionSerializer::Index, + scope: { + current_user: :current_user + } attributes :title, :week_number, :video, :missions_accepted, :adventure_missions def adventure_missions - object.adventure_missions.order(index: 'asc') + object.adventure_missions.order(index: "asc") end def current_user diff --git a/app/serializers/api/contacts_serializer.rb b/app/serializers/api/contacts_serializer.rb index a8268d819..3e9a7a3a3 100644 --- a/app/serializers/api/contacts_serializer.rb +++ b/app/serializers/api/contacts_serializer.rb @@ -3,7 +3,7 @@ class Api::ContactsSerializer < ActiveModel::Serializer class Api::ContactsSerializer::Show < Api::ContactsSerializer attributes(:email, :name, :text, :avatar) - attribute(:users) { object.users.collect { |u| u.firstname + ' ' + u.lastname } } + attribute(:users) { object.users.collect { |u| u.firstname + " " + u.lastname } } def avatar if contact_single_user(object) @@ -16,7 +16,7 @@ def avatar class Api::ContactsSerializer::Index < Api::ContactsSerializer attributes(:id, :email, :name, :text, :avatar) - attribute(:users) { object.users.collect { |u| u.firstname + ' ' + u.lastname } } + attribute(:users) { object.users.collect { |u| u.firstname + " " + u.lastname } } def avatar if contact_single_user(object) diff --git a/app/serializers/api/event_serializer.rb b/app/serializers/api/event_serializer.rb index eabe8fa70..a2f2f807a 100644 --- a/app/serializers/api/event_serializer.rb +++ b/app/serializers/api/event_serializer.rb @@ -2,7 +2,7 @@ class Api::EventSerializer < ActiveModel::Serializer include EventHelper attributes(:id, :title, :description, :location, :starts_at, :ends_at, :all_day, :dot, :drink, - :food, :cash, :price, :dress_code, :can_signup, :event_user_count, :short, :user_types) + :food, :cash, :price, :dress_code, :can_signup, :event_user_count, :short, :user_types) belongs_to :contact has_one :event_signup diff --git a/app/serializers/api/notification_serializer.rb b/app/serializers/api/notification_serializer.rb index 3b04c52d7..164c0e4af 100644 --- a/app/serializers/api/notification_serializer.rb +++ b/app/serializers/api/notification_serializer.rb @@ -4,7 +4,7 @@ class Api::NotificationSerializer < ActiveModel::Serializer attribute(:event_id) def event_id - if object.notifyable_type == 'EventUser' || object.notifyable_type == 'EventSignup' + if object.notifyable_type == "EventUser" || object.notifyable_type == "EventSignup" object.notifyable.event.id end end diff --git a/app/serializers/api/song_serializer.rb b/app/serializers/api/song_serializer.rb index b4c197ee2..5c9c493dd 100644 --- a/app/serializers/api/song_serializer.rb +++ b/app/serializers/api/song_serializer.rb @@ -1,5 +1,4 @@ class Api::SongSerializer < ActiveModel::Serializer - class Api::SongSerializer::Index < ActiveModel::Serializer attributes(:id, :title, :author) end diff --git a/app/serializers/event_serializer.rb b/app/serializers/event_serializer.rb index 88980436f..e2b3d5e9e 100644 --- a/app/serializers/event_serializer.rb +++ b/app/serializers/event_serializer.rb @@ -1,13 +1,13 @@ class EventSerializer < ActiveModel::Serializer attributes(:id, :title, :start, :end) - attribute(:description) { object.description || '' } + attribute(:description) { object.description || "" } attribute(:location) attribute(:allday) { object.all_day? } attribute(:has_signup) { object.signup.present? } attribute(:signup_not_opened_yet) { object.signup.present? && object.signup.opens > Time.zone.now } attribute(:recurring) { false } attribute(:url) { Rails.application.routes.url_helpers.event_path(object.id) } - attribute(:textColor) { 'black' } + attribute(:textColor) { "black" } attribute(:dot) has_one :event_signup diff --git a/app/serializers/message_serializer.rb b/app/serializers/message_serializer.rb index 525538dac..767c7b857 100644 --- a/app/serializers/message_serializer.rb +++ b/app/serializers/message_serializer.rb @@ -4,11 +4,11 @@ class MessageSerializer < ActiveModel::Serializer attributes(:id, :by_admin, :updated_at, :image_url, :image_details) attribute(:text) { MessageHelper.markdown_api(object.content) } attribute(:day) { object.created_at.to_date } - attribute(:time) { object.created_at.strftime('%H:%M') } + attribute(:time) { object.created_at.strftime("%H:%M") } def updated_at if object.updated_at != object.created_at - I18n.t('model.message.updated_at', date: I18n.l(object.updated_at, format: :short)) + I18n.t("model.message.updated_at", date: I18n.l(object.updated_at, format: :short)) end end diff --git a/app/services/adventure_mission_service.rb b/app/services/adventure_mission_service.rb index 95220a13d..a44bcb4b2 100644 --- a/app/services/adventure_mission_service.rb +++ b/app/services/adventure_mission_service.rb @@ -2,35 +2,35 @@ class AdventureMissionService def self.shift_index_on_create(adventure, index) if adventure.adventure_missions.pluck(:index).include?(index) AdventureMission.where(adventure: adventure) - .order(index: 'desc') + .order(index: "desc") .limit(adventure.adventure_missions.count - index) - .update_all('index = index + 1') + .update_all("index = index + 1") end end def self.shift_index_on_destroy(adventure, index) if adventure.adventure_missions.pluck(:index).include?(index) AdventureMission.where(adventure: adventure) - .order(index: 'desc') + .order(index: "desc") .limit(adventure.adventure_missions.count - index) - .update_all('index = index - 1') + .update_all("index = index - 1") end end def self.shift_index_on_update(adventure, index_before, index_after) if adventure.adventure_missions.pluck(:index).include?(index_after) if index_before > index_after - AdventureMission.where(adventure: adventure, id: AdventureMission.order(index: 'desc') + AdventureMission.where(adventure: adventure, id: AdventureMission.order(index: "desc") .limit(adventure.adventure_missions.count - index_after)) - .order(index: 'asc') - .limit(index_before - index_after) - .update_all('index = index + 1') + .order(index: "asc") + .limit(index_before - index_after) + .update_all("index = index + 1") elsif index_before < index_after - AdventureMission.where(adventure: adventure, id: AdventureMission.order(index: 'desc') + AdventureMission.where(adventure: adventure, id: AdventureMission.order(index: "desc") .limit(adventure.adventure_missions.count - index_before - 1)) - .order(index: 'asc') - .limit(index_after - index_before) - .update_all('index = index - 1') + .order(index: "asc") + .limit(index_after - index_before) + .update_all("index = index - 1") end end end diff --git a/app/services/adventure_service.rb b/app/services/adventure_service.rb index 73f58d504..21b697288 100644 --- a/app/services/adventure_service.rb +++ b/app/services/adventure_service.rb @@ -24,7 +24,7 @@ def self.lock_adventure_missions(adventure, locked) end def self.adventure_active(adventure) - return adventure.start_date < Time.now && adventure.end_date > Time.now + adventure.start_date < Time.now && adventure.end_date > Time.now end def self.update_locking(old_adventure, new_adventure) diff --git a/app/services/album_service.rb b/app/services/album_service.rb index 8c959af3c..ce77bb903 100644 --- a/app/services/album_service.rb +++ b/app/services/album_service.rb @@ -12,7 +12,7 @@ def upload_images(album) if album.image_upload.present? album.image_upload.each do |img| new_img = album.images.new(file: img, photographer_id: album.photographer_user, - photographer_name: album.photographer_name) + photographer_name: album.photographer_name) if new_img.save @uploaded += 1 else diff --git a/app/services/cafe_service.rb b/app/services/cafe_service.rb index c02ff447c..70faf9a77 100644 --- a/app/services/cafe_service.rb +++ b/app/services/cafe_service.rb @@ -1,9 +1,8 @@ -# encoding: UTF-8 module CafeService def self.setup(shift) - if shift.setup_mode == 'week' + if shift.setup_mode == "week" setup_week(shift) - elsif shift.setup_mode == 'day' + elsif shift.setup_mode == "day" setup_day(shift) else false @@ -12,14 +11,14 @@ def self.setup(shift) def self.setup_week(shift) if shift.lv.present? && - shift.lv_last.present? && - shift.start.present? && - shift.lp.present? + shift.lv_last.present? && + shift.start.present? && + shift.lp.present? begin CafeShift.create!(generate(first_w: shift.lv, - last_w: shift.lv_last.to_i, - start: shift.start, - lp: shift.lp)) + last_w: shift.lv_last.to_i, + start: shift.start, + lp: shift.lp)) rescue return false end @@ -31,12 +30,12 @@ def self.setup_week(shift) def self.setup_day(shift) if shift.lv.present? && - shift.start.present? && - shift.lp.present? + shift.start.present? && + shift.lp.present? begin CafeShift.create!(generate_day(start: shift.start, - lp: shift.lp, - lv: shift.lv)) + lp: shift.lp, + lv: shift.lv)) rescue return false end @@ -49,10 +48,10 @@ def self.setup_day(shift) def self.generate(first_w:, last_w:, start:, lp:) shifts = [] (first_w..last_w).each do |lv| - (0..4).each do + 5.times do shifts += generate_day(start: start, - lp: lp, - lv: lv) + lp: lp, + lv: lv) start += 1.days end start += 2.days @@ -62,20 +61,20 @@ def self.generate(first_w:, last_w:, start:, lp:) def self.generate_day(start:, lp:, lv:) shifts = [] - shifts << { start: start, lp: lp, pass: 1, lv: lv } - shifts << { start: start, lp: lp, pass: 1, lv: lv } - shifts << { start: start + 2.hours, lp: lp, pass: 2, lv: lv } - shifts << { start: start + 2.hours, lp: lp, pass: 2, lv: lv } + shifts << {start: start, lp: lp, pass: 1, lv: lv} + shifts << {start: start, lp: lp, pass: 1, lv: lv} + shifts << {start: start + 2.hours, lp: lp, pass: 2, lv: lv} + shifts << {start: start + 2.hours, lp: lp, pass: 2, lv: lv} shifts end def self.group_cafe_shifts(date_start, date_end, shifts) - hash = Hash.new { - |h| h[:years] = Hash.new { - |h2, m| h2[m] = Hash.new { - |h3| h3[:months] = Hash.new { - |h4, a| h4[a] = Hash.new { - |h5| h5[:days] = {} + hash = Hash.new { |h| + h[:years] = Hash.new { |h2, m| + h2[m] = Hash.new { |h3| + h3[:months] = Hash.new { |h4, a| + h4[a] = Hash.new { |h5| + h5[:days] = {} } } } @@ -86,21 +85,19 @@ def self.group_cafe_shifts(date_start, date_end, shifts) end_day = Time.parse(date_end) while date <= end_day unless date.on_weekend? - hash[:years][date.year][:months][I18n.t('date.month_names')[date.month].capitalize][:days]["#{I18n.t('date.day_names')[date.wday].capitalize} - #{date.day}/#{date.month}"] = [] + hash[:years][date.year][:months][I18n.t("date.month_names")[date.month].capitalize][:days]["#{I18n.t("date.day_names")[date.wday].capitalize} - #{date.day}/#{date.month}"] = [] end date += 1.day end - shifts_by_ymd = shifts.each_with_object(hash) do |shift, h| + shifts.each_with_object(hash) do |shift, h| week_day = shift.start.wday # Returns the day of week (0-6, Sunday is zero) month = shift.start.month - day_name = I18n.t('date.day_names')[week_day].capitalize - month_name = I18n.t('date.month_names')[month].capitalize + day_name = I18n.t("date.day_names")[week_day].capitalize + month_name = I18n.t("date.month_names")[month].capitalize unless h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].nil? h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].push(Api::CafeShiftSerializer::Index.new(shift).as_json) end end - - shifts_by_ymd end end diff --git a/app/services/calendar_json.rb b/app/services/calendar_json.rb index 9268af1d3..af4b20dbd 100644 --- a/app/services/calendar_json.rb +++ b/app/services/calendar_json.rb @@ -6,8 +6,8 @@ def self.rent(rent) title: %(Service -\n #{rent.purpose}), start: rent.d_from.iso8601, end: rent.d_til.iso8601, - backgroundColor: 'black', - textColor: 'white' + backgroundColor: "black", + textColor: "white" } else { @@ -17,7 +17,7 @@ def self.rent(rent) end: rent.d_til.iso8601, url: rent.p_path, backgroundColor: rent_color(rent), - textColor: 'black' + textColor: "black" } end end @@ -29,9 +29,9 @@ def self.cafe(shift, user) start: shift.start.iso8601, end: shift.stop.iso8601, url: Rails.application.routes.url_helpers.cafe_shift_path(shift), - color: 'black', + color: "black", backgroundColor: cafe_color(shift, user), - textColor: 'black' + textColor: "black" } end @@ -42,7 +42,7 @@ def self.meeting(meeting) start: meeting.start_date.iso8601, end: meeting.end_date.iso8601, backgroundColor: meeting_color(meeting), - textColor: 'black', + textColor: "black", url: meeting.p_path } end @@ -51,35 +51,35 @@ def self.meeting(meeting) def self.cafe_color(shift, owner) if shift.cafe_worker.present? - owner ? 'green' : 'orange' + owner ? "green" : "orange" else - 'white' + "white" end end def self.rent_color(rent) if rent.aktiv case rent.status - when 'confirmed' - 'green' - when 'unconfirmed' - 'yellow' - when 'denied' - 'red' + when "confirmed" + "green" + when "unconfirmed" + "yellow" + when "denied" + "red" end else - 'red' + "red" end end def self.meeting_color(meeting) case meeting.status - when 'confirmed' - 'green' - when 'unconfirmed' - 'yellow' - when 'denied' - 'red' + when "confirmed" + "green" + when "unconfirmed" + "yellow" + when "denied" + "red" end end end diff --git a/app/services/calendar_service.rb b/app/services/calendar_service.rb index f14e2ee4b..0220eb7c5 100644 --- a/app/services/calendar_service.rb +++ b/app/services/calendar_service.rb @@ -1,8 +1,8 @@ module CalendarService - require 'icalendar/tzinfo' + require "icalendar/tzinfo" include MarkdownHelper - def self.export(events, locale: 'sv') + def self.export(events, locale: "sv") calendar = set_timezone(Icalendar::Calendar.new) if events.present? events.each do |e| @@ -21,13 +21,13 @@ def self.set_timezone(calendar) calendar end - def self.event(resource, locale: 'sv') + def self.event(resource, locale: "sv") ical_event = Icalendar::Event.new ical_event.uid = resource.id.to_json set_date(ical_event, resource) - if locale == 'en' + if locale == "en" ical_event.description = MarkdownHelper.markdown_plain(resource.description_en) ical_event.summary = resource.title_en else @@ -36,11 +36,11 @@ def self.event(resource, locale: 'sv') end ical_event.location = resource.location - ical_event.created = date_time(resource.created_at.utc, tzid: 'UTC') - ical_event.last_modified = date_time(resource.updated_at.utc, tzid: 'UTC') + ical_event.created = date_time(resource.created_at.utc, tzid: "UTC") + ical_event.last_modified = date_time(resource.updated_at.utc, tzid: "UTC") ical_event.url = Rails.application.routes.url_helpers.event_url(resource.id, - host: PUBLIC_URL) - ical_event.ip_class = 'PUBLIC' + host: PUBLIC_URL) + ical_event.ip_class = "PUBLIC" ical_event end @@ -60,6 +60,6 @@ def self.date(value) end def self.date_time(value, tzid: nil) - Icalendar::Values::DateTime.new(value, 'tzid' => tzid) + Icalendar::Values::DateTime.new(value, "tzid" => tzid) end end diff --git a/app/services/export_csv.rb b/app/services/export_csv.rb index 135574e22..61f7a1750 100644 --- a/app/services/export_csv.rb +++ b/app/services/export_csv.rb @@ -6,19 +6,19 @@ def self.event_users(attendees, signup) if attendees.present? && signup.present? CSV.generate(headers: true) do |csv| csv << [User.human_attribute_name(:name), - EventUser.human_attribute_name(:user_type), - EventUser.human_attribute_name(:group), - User.human_attribute_name(:food_preference), - EventUser.human_attribute_name(:answer), - User.human_attribute_name(:email)] + EventUser.human_attribute_name(:user_type), + EventUser.human_attribute_name(:group), + User.human_attribute_name(:food_preference), + EventUser.human_attribute_name(:answer), + User.human_attribute_name(:email)] attendees.each do |a| csv << [a.user, - event_user_type(signup, a.user_type), - group_str(a), - food_preferences_str(a.user), - a.answer, - a.user.email] + event_user_type(signup, a.user_type), + group_str(a), + food_preferences_str(a.user), + a.answer, + a.user.email] end end end diff --git a/app/services/meeting_service.rb b/app/services/meeting_service.rb index b161f048a..efbf5ef86 100644 --- a/app/services/meeting_service.rb +++ b/app/services/meeting_service.rb @@ -1,5 +1,5 @@ module MeetingService - def self.create_recurring_meeting(meeting_params, old_recurring=nil) + def self.create_recurring_meeting(meeting_params, old_recurring = nil) occurrences = meeting_params[:occurrences].to_i every = meeting_params[:every].to_i start_date = Time.parse(meeting_params[:start_date]) @@ -7,10 +7,10 @@ def self.create_recurring_meeting(meeting_params, old_recurring=nil) meetings = Array.new(occurrences) # Create meetings and add them to an array - for i in 0..occurrences - 1 + (0..occurrences - 1).each do |i| temp_params = meeting_params - new_start_date = (start_date + (i * every).day).strftime('%Y-%m-%d %H:%M:%S') - new_end_date = (end_date + (i * every).day).strftime('%Y-%m-%d %H:%M:%S') + new_start_date = (start_date + (i * every).day).strftime("%Y-%m-%d %H:%M:%S") + new_end_date = (end_date + (i * every).day).strftime("%Y-%m-%d %H:%M:%S") temp_params[:start_date] = new_start_date temp_params[:end_date] = new_end_date meeting = Meeting.new(temp_params) @@ -33,9 +33,9 @@ def self.create_recurring_meeting(meeting_params, old_recurring=nil) meeting.save! end end - return meetings[0] + meetings[0] rescue - return nil + nil end end @@ -55,8 +55,8 @@ def self.update_all_recurring_meeting(meeting, meeting_params) elsif every != recurring_meeting.every # Remove current recurring meeting including its meetings, and create a new recurring meeting meeting = Meeting.where(recurring_meeting_id: recurring_meeting.id)[0] - meeting_params[:start_date] = meeting.start_date.strftime('%Y-%m-%d %H:%M:%S') - meeting_params[:end_date] = meeting.end_date.strftime('%Y-%m-%d %H:%M:%S') + meeting_params[:start_date] = meeting.start_date.strftime("%Y-%m-%d %H:%M:%S") + meeting_params[:end_date] = meeting.end_date.strftime("%Y-%m-%d %H:%M:%S") create_recurring_meeting(meeting_params, recurring_meeting) else @@ -120,20 +120,20 @@ def self.update_meetings(meeting, meetings, meeting_params) end_date = Time.parse(meeting_params[:end_date]) # Update the time of all meetings if it has changed - if start_date.strftime('%H:%M:%S') != meeting.start_date.strftime('%H:%M:%S') || end_date.strftime('%H:%M:%S') != meeting.end_date.strftime('%H:%M:%S') + if start_date.strftime("%H:%M:%S") != meeting.start_date.strftime("%H:%M:%S") || end_date.strftime("%H:%M:%S") != meeting.end_date.strftime("%H:%M:%S") # Get time for start and end - start_time_hh = start_date.strftime('%H') - start_time_mm = start_date.strftime('%M') - end_time_hh = end_date.strftime('%H') - end_time_mm = end_date.strftime('%M') + start_time_hh = start_date.strftime("%H") + start_time_mm = start_date.strftime("%M") + end_time_hh = end_date.strftime("%H") + end_time_mm = end_date.strftime("%M") begin Meeting.transaction do meetings.each do |m| m.is_admin = true new_start_date = m.start_date new_end_date = m.end_date - m.start_date = new_start_date.change({ hour: start_time_hh, min: start_time_mm }) - m.end_date = new_end_date.change({ hour: end_time_hh, min: end_time_mm }) + m.start_date = new_start_date.change({hour: start_time_hh, min: start_time_mm}) + m.end_date = new_end_date.change({hour: end_time_hh, min: end_time_mm}) m.save! end end @@ -143,8 +143,8 @@ def self.update_meetings(meeting, meetings, meeting_params) end # Update only meeting information - meeting_params.delete('start_date') - meeting_params.delete('end_date') + meeting_params.delete("start_date") + meeting_params.delete("end_date") begin Meeting.transaction do meetings.each do |m| @@ -196,10 +196,10 @@ def self.occurrences_changed(meeting, meeting_params) start_date = meetings[-1].start_date end_date = meetings[-1].end_date new_meetings = Array.new(diff.abs) - for i in 1..diff.abs + (1..diff.abs).each do |i| temp_params = meeting_params - new_start_date = (start_date + (i * every).day).strftime('%Y-%m-%d %H:%M:%S') - new_end_date = (end_date + (i * every).day).strftime('%Y-%m-%d %H:%M:%S') + new_start_date = (start_date + (i * every).day).strftime("%Y-%m-%d %H:%M:%S") + new_end_date = (end_date + (i * every).day).strftime("%Y-%m-%d %H:%M:%S") temp_params[:start_date] = new_start_date temp_params[:end_date] = new_end_date m = Meeting.new(temp_params) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index ea2bd167e..11f488a9a 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -87,7 +87,7 @@ def self.destroy_for(event) # Updates the coutner caches def self.update_counters(users) - counts = Notification.joins(:user).merge(users).group('users.id').select('users.id, count(*) as score') + counts = Notification.joins(:user).merge(users).group("users.id").select("users.id, count(*) as score") counts.each do |c| User.update(c.id, notifications_count: c.score) end diff --git a/app/services/post_user_service.rb b/app/services/post_user_service.rb index a1f65e669..e456d09e9 100644 --- a/app/services/post_user_service.rb +++ b/app/services/post_user_service.rb @@ -3,7 +3,7 @@ def self.create(post_user) post_user.validate if post_user.post.try(:limited?) - post_user.errors.add(:post, I18n.t('service.post_user.limited')) + post_user.errors.add(:post, I18n.t("service.post_user.limited")) return false end diff --git a/app/services/push_service.rb b/app/services/push_service.rb index d566ef2f5..fd30af0e3 100644 --- a/app/services/push_service.rb +++ b/app/services/push_service.rb @@ -12,9 +12,9 @@ def self.push_android(data_object, app, users) # Firebase supports 1000 registration ids/notification clients.each_slice(1000) do |c| Rpush::Gcm::Notification.create!(app: app, - priority: :high, - data: data_object.android_data, - registration_ids: c) + priority: :high, + data: data_object.android_data, + registration_ids: c) end end @@ -25,10 +25,10 @@ def self.push_ios(data_object, app, users) # Firebase supports 1000 registration ids/notification clients.each_slice(1000) do |c| Rpush::Gcm::Notification.create!(app: app, - data: data_object.ios_data, - priority: :high, - notification: data_object.ios_notification, - registration_ids: c) + data: data_object.ios_data, + priority: :high, + notification: data_object.ios_notification, + registration_ids: c) end end diff --git a/app/services/rent_service.rb b/app/services/rent_service.rb index 12a2ecbef..f67943c37 100644 --- a/app/services/rent_service.rb +++ b/app/services/rent_service.rb @@ -1,87 +1,79 @@ module RentService def self.reservation(user, rent, terms) - begin - Rent.transaction do - rent.validate! - rent.user = user - rent.status = \ - if user.try(:member?) && comfortable_hours?(rent.d_from, rent.d_til) - :confirmed - else - :unconfirmed - end - if terms.present? && rent.terms != '1' - rent.errors.add(:terms, I18n.t('rent.validation.terms')) - false + Rent.transaction do + rent.validate! + rent.user = user + rent.status = \ + if user.try(:member?) && comfortable_hours?(rent.d_from, rent.d_til) + :confirmed else - rent.save! - if rent.council.present? - rent.overlap.each(&:overbook) - end - RentMailer.rent_email(rent).deliver_now - true + :unconfirmed end + if terms.present? && rent.terms != "1" + rent.errors.add(:terms, I18n.t("rent.validation.terms")) + false + else + rent.save! + if rent.council.present? + rent.overlap.each(&:overbook) + end + RentMailer.rent_email(rent).deliver_now + true end - rescue - false end + rescue + false end def self.update(params, user, rent) - begin - if rent.owner?(user) - d_from_datetime = DateTime.strptime(params[:d_from], '%Y-%m-%d %H:%M') - d_til_datetime = DateTime.strptime(params[:d_til], '%Y-%m-%d %H:%M') - rent.status = comfortable_hours?(d_from_datetime, d_til_datetime) ? :confirmed : :unconfirmed - rent.update!(params) - RentMailer.rent_email(rent).deliver_now if rent.status == 'unconfirmed' - true - else - rent.errors.add(I18n.t(:authorize), I18n.t('validation.unauthorized')) - false - end - rescue + if rent.owner?(user) + d_from_datetime = DateTime.strptime(params[:d_from], "%Y-%m-%d %H:%M") + d_til_datetime = DateTime.strptime(params[:d_til], "%Y-%m-%d %H:%M") + rent.status = comfortable_hours?(d_from_datetime, d_til_datetime) ? :confirmed : :unconfirmed + rent.update!(params) + RentMailer.rent_email(rent).deliver_now if rent.status == "unconfirmed" + true + else + rent.errors.add(I18n.t(:authorize), I18n.t("validation.unauthorized")) false end + rescue + false end def self.admin_reservation(rent) - begin - if RentValidator.new.base(rent) - rent.status = rent.user.member? ? :confirmed : :unconfirmed - rent.save!(validate: false) - RentMailer.rent_email(rent).deliver_now - true - else - false - end - rescue + if RentValidator.new.base(rent) + rent.status = rent.user.member? ? :confirmed : :unconfirmed + rent.save!(validate: false) + RentMailer.rent_email(rent).deliver_now + true + else false end + rescue + false end def self.administrate(rent, params) - begin - active = rent.aktiv - status = rent.status - rent.attributes = params - if RentValidator.new.base(rent) - rent.save!(validate: false) - if rent.aktiv != active - RentMailer.active_email(rent).deliver_now - end - if rent.status != status - RentMailer.status_email(rent).deliver_now - end - true - else - false + active = rent.aktiv + status = rent.status + rent.attributes = params + if RentValidator.new.base(rent) + rent.save!(validate: false) + if rent.aktiv != active + RentMailer.active_email(rent).deliver_now end - rescue + if rent.status != status + RentMailer.status_email(rent).deliver_now + end + true + else false end + rescue + false end - + def self.comfortable_hours?(d_from, d_til) valid_time?(d_from) && valid_time?(d_til) end diff --git a/app/services/tool_renting_service.rb b/app/services/tool_renting_service.rb index fc8620589..115d46321 100644 --- a/app/services/tool_renting_service.rb +++ b/app/services/tool_renting_service.rb @@ -9,7 +9,7 @@ def self.remove_reminder(rent) scheduled = Sidekiq::ScheduledSet.new.select scheduled.map do |job| - if job.klass == 'ToolRentingReminderWorker' + if job.klass == "ToolRentingReminderWorker" if job.args.include? rent.id job.delete end diff --git a/app/uploaders/base_image_uploader.rb b/app/uploaders/base_image_uploader.rb index 13c8957ff..9d6da2290 100644 --- a/app/uploaders/base_image_uploader.rb +++ b/app/uploaders/base_image_uploader.rb @@ -17,6 +17,6 @@ def md5 # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list - %w(jpg jpeg gif png) + %w[jpg jpeg gif png] end end diff --git a/app/uploaders/document_uploader.rb b/app/uploaders/document_uploader.rb index f3d21895d..b14d7ef53 100644 --- a/app/uploaders/document_uploader.rb +++ b/app/uploaders/document_uploader.rb @@ -6,6 +6,6 @@ def store_dir end def extension_white_list - %w(pdf) + %w[pdf] end end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 4077bfc8c..a5b37d0a0 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -35,7 +35,7 @@ def store_dir # Watermark should always be processed after thumbkit, ensuring that we always # have a valid image and we don't need to change the extension def watermark(options = {}) - cache_stored_file! if !cached? + cache_stored_file! unless cached? Watermarker.new(current_path).watermark!(options) end diff --git a/app/uploaders/watermarker.rb b/app/uploaders/watermarker.rb index 857d00fca..bd05cb9cd 100644 --- a/app/uploaders/watermarker.rb +++ b/app/uploaders/watermarker.rb @@ -1,4 +1,4 @@ -require 'mini_magick' +require "mini_magick" class Watermarker def initialize(original_path) @@ -10,16 +10,16 @@ def initialize(original_path) # Gravity options: None, Center, East, Forget, NorthEast, North, # NorthWest, SouthEast, South, SouthWest, West, Static def watermark!(options = {}) - watermark_path = Rails.root.join('app/assets/images/layout/watermark.png') + watermark_path = Rails.root.join("app/assets/images/layout/watermark.png") - options[:gravity] ||= 'SouthEast' + options[:gravity] ||= "SouthEast" image = MiniMagick::Image.open(@original_path) watermark = MiniMagick::Image.open(watermark_path) height = image[:height] * 0.20 watermark.resize(%(x#{height})) - result = image.composite(watermark, 'png') do |c| + result = image.composite(watermark, "png") do |c| c.gravity options[:gravity] c.geometry %(+#{height / 2}+#{height / 2}) end diff --git a/app/validators/contact_message_validator.rb b/app/validators/contact_message_validator.rb index 4622c83ff..bd6600b5f 100644 --- a/app/validators/contact_message_validator.rb +++ b/app/validators/contact_message_validator.rb @@ -23,7 +23,7 @@ def self.validate_email(message) state = false end - if !message.email.match(Devise::email_regexp) + if !message.email.match(Devise.email_regexp) message.errors.add(:email, :format) state = false end diff --git a/app/validators/rent_validator.rb b/app/validators/rent_validator.rb index c5dbd0212..f4ff09e81 100644 --- a/app/validators/rent_validator.rb +++ b/app/validators/rent_validator.rb @@ -2,32 +2,32 @@ class RentValidator < ActiveModel::Validator def validate(record) if base(record) if user_attributes(record) - record.errors.add(:user, I18n.t('model.rent.validation.add_user_information')) + record.errors.add(:user, I18n.t("model.rent.validation.add_user_information")) end if date_future(record) - record.errors.add(:d_from, I18n.t('model.rent.validation.future')) + record.errors.add(:d_from, I18n.t("model.rent.validation.future")) end if dates_ascending(record) - record.errors.add(:d_til, I18n.t('model.rent.validation.ascending')) + record.errors.add(:d_til, I18n.t("model.rent.validation.ascending")) end if duration(record) - record.errors.add(:d_from, I18n.t('model.rent.validation.duration')) - record.errors.add(:d_til, I18n.t('model.rent.validation.duration')) + record.errors.add(:d_from, I18n.t("model.rent.validation.duration")) + record.errors.add(:d_til, I18n.t("model.rent.validation.duration")) end if overlap(record) - record.errors.add(:d_from, I18n.t('model.rent.validation.overlap')) + record.errors.add(:d_from, I18n.t("model.rent.validation.overlap")) end if overlap_council(record) - record.errors.add(:d_from, I18n.t('model.rent.validation.overlap_council')) + record.errors.add(:d_from, I18n.t("model.rent.validation.overlap_council")) end if overlap_overbook(record) - record.errors.add(:d_from, I18n.t('model.rent.validation.overlap_overbook')) + record.errors.add(:d_from, I18n.t("model.rent.validation.overlap_overbook")) end end end diff --git a/app/view_objects/cafe_competition.rb b/app/view_objects/cafe_competition.rb index a8f3317cb..8e3cd9993 100644 --- a/app/view_objects/cafe_competition.rb +++ b/app/view_objects/cafe_competition.rb @@ -4,7 +4,7 @@ def initialize(lp:, year:, amount:) @cafe_workers = CafeQueries.cafe_workers(lp, year) @lp = lp @users = CafeQueries.working_users(lp, year) - @lps = ['1', '2', '3', '4'] - [lp] + @lps = ["1", "2", "3", "4"] - [lp] @year = year.year @amount = amount @free_shifts = CafeQueries.free_shifts(lp, year) @@ -20,9 +20,7 @@ def user_count users.count end - def highscore - @highscore - end + attr_reader :highscore def has_highscore? @highscore.exists? @@ -32,12 +30,10 @@ def has_highscore_group? @highscore_group.count > 0 end - def highscore_group - @highscore_group - end + attr_reader :highscore_group def study_periods - ['1', '2', '3', '4'] - [lp] + ["1", "2", "3", "4"] - [lp] end def years @@ -45,6 +41,6 @@ def years end def free_shifts - { count: @free_shifts.count, free: @free_shifts.first } + {count: @free_shifts.count, free: @free_shifts.first} end end diff --git a/app/view_objects/document_view.rb b/app/view_objects/document_view.rb index 44ac82d8a..9865b913f 100644 --- a/app/view_objects/document_view.rb +++ b/app/view_objects/document_view.rb @@ -1,7 +1,7 @@ class DocumentView attr_accessor :grid, :categories, :current_category - def initialize(grid:, categories:, current_category: '') + def initialize(grid:, categories:, current_category: "") @grid = grid @categories = categories @current_category = current_category diff --git a/app/view_objects/election_view.rb b/app/view_objects/election_view.rb index 7ccaa4313..e3788ac1c 100644 --- a/app/view_objects/election_view.rb +++ b/app/view_objects/election_view.rb @@ -10,28 +10,28 @@ def initialize(election, candidate: nil) def countdown_text case @election.state when :not_opened - I18n.t('election_view.opens_in') + I18n.t("election_view.opens_in") when :before_general, :after_general - I18n.t('election_view.closes_in') + I18n.t("election_view.closes_in") when :closed - I18n.t('election_view.already_closed') + I18n.t("election_view.already_closed") end end def posts_text case @election.state when :not_opened - I18n.t('election_view.posts_will_candidate') + I18n.t("election_view.posts_will_candidate") when :before_general, :after_general - I18n.t('election_view.posts_can_candidate') + I18n.t("election_view.posts_can_candidate") when :closed - I18n.t('election_view.posts_cannot_candidate') + I18n.t("election_view.posts_cannot_candidate") end end def rest_posts_text if @election.state == :after_general - I18n.t('election_view.posts_cannot_candidate') + I18n.t("election_view.posts_cannot_candidate") end end diff --git a/app/view_objects/start_page.rb b/app/view_objects/start_page.rb index 37d3b8fd9..48145456a 100644 --- a/app/view_objects/start_page.rb +++ b/app/view_objects/start_page.rb @@ -7,7 +7,7 @@ def initialize(member: false) @events = Event.by_locale(locale: I18n.locale).stream || [] election = Election.current - if(election.present? && election.state != :closed) + if election.present? && election.state != :closed @election_view = ElectionView.new(election) end end diff --git a/app/view_objects/work_portal.rb b/app/view_objects/work_portal.rb index 084b594c1..b4741f17d 100644 --- a/app/view_objects/work_portal.rb +++ b/app/view_objects/work_portal.rb @@ -1,7 +1,7 @@ class WorkPortal attr_reader(:current, :current_post, :work_posts, - :grid, :companies, :target_groups, - :fields, :kinds) + :grid, :companies, :target_groups, + :fields, :kinds) def initialize(current_post: nil, work_posts: [], grid: nil) @current = {} @@ -26,23 +26,23 @@ def current_and_filter(filtering_params) end def new_target_path(target) - Rails.application.routes.url_helpers. - work_posts_path(target: target, - field: @current[:field], - kind: @current[:kind]) + Rails.application.routes.url_helpers + .work_posts_path(target: target, + field: @current[:field], + kind: @current[:kind]) end def new_field_path(field) - Rails.application.routes.url_helpers. - work_posts_path(target: @current[:target], - field: field, - kind: @current[:kind]) + Rails.application.routes.url_helpers + .work_posts_path(target: @current[:target], + field: field, + kind: @current[:kind]) end def new_kind_path(kind) - Rails.application.routes.url_helpers. - work_posts_path(target: @current[:target], - field: @current[:field], - kind: kind) + Rails.application.routes.url_helpers + .work_posts_path(target: @current[:target], + field: @current[:field], + kind: kind) end end diff --git a/app/workers/event_signup_closing_reminder_worker.rb b/app/workers/event_signup_closing_reminder_worker.rb index 98f0aae93..9e06bce50 100644 --- a/app/workers/event_signup_closing_reminder_worker.rb +++ b/app/workers/event_signup_closing_reminder_worker.rb @@ -18,7 +18,7 @@ def notify(event_signup) attending_user_id = event_signup.event_users.pluck(:user_id) notify_users = User.where(notify_event_closing: true).where.not(id: attending_user_id) notify_users.each do |user| - NotificationService.event_signup(event_signup, 'closing', user) + NotificationService.event_signup(event_signup, "closing", user) end event_signup.update!(sent_closing: Time.zone.now) end diff --git a/app/workers/event_signup_open_reminder_worker.rb b/app/workers/event_signup_open_reminder_worker.rb index e5694f8ec..038e057a4 100644 --- a/app/workers/event_signup_open_reminder_worker.rb +++ b/app/workers/event_signup_open_reminder_worker.rb @@ -16,7 +16,7 @@ def notifyable(event_signup) def notify(event_signup) notify_users = User.where(notify_event_open: true) notify_users.each do |user| - NotificationService.event_signup(event_signup, 'open', user) + NotificationService.event_signup(event_signup, "open", user) end event_signup.update!(sent_open: Time.zone.now) end diff --git a/app/workers/event_signup_position_worker.rb b/app/workers/event_signup_position_worker.rb index 6c144285a..6c0276fa6 100644 --- a/app/workers/event_signup_position_worker.rb +++ b/app/workers/event_signup_position_worker.rb @@ -6,7 +6,7 @@ def perform(event_signup_id) event_signup = EventSignup.includes(:event_users).find(event_signup_id) if event_signup.sent_position.nil? && event_signup.closes <= Time.zone.now event_signup.event_users.each do |event_user| - NotificationService.event_user(event_user, 'position') + NotificationService.event_user(event_user, "position") end event_signup.update!(sent_position: Time.zone.now) diff --git a/app/workers/event_signup_reminder_worker.rb b/app/workers/event_signup_reminder_worker.rb index f3fb0447f..139e03a58 100644 --- a/app/workers/event_signup_reminder_worker.rb +++ b/app/workers/event_signup_reminder_worker.rb @@ -17,7 +17,7 @@ def notifyable(event_signup, time_until) def notify(event_signup) event_signup.event_users.attending(event_signup.event).each do |event_user| - NotificationService.event_user(event_user, 'reminder') + NotificationService.event_user(event_user, "reminder") end event_signup.update!(sent_reminder: Time.zone.now) diff --git a/config.ru b/config.ru index 5bc2a619e..193e5fed8 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path("../config/environment", __FILE__) run Rails.application diff --git a/config/application.rb b/config/application.rb index 0f171a5db..0d155eace 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,7 +1,6 @@ -# encoding: UTF-8 -require File.expand_path('../boot', __FILE__) +require File.expand_path("../boot", __FILE__) -require 'rails/all' +require "rails/all" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -20,26 +19,26 @@ class Application < Rails::Application # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] + config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")] config.i18n.default_locale = :sv config.i18n.fallbacks = true config.autoload_paths += Dir["#{config.root}/lib/**/"] config.autoload_paths += Dir["#{config.root}/app/mailers/concerns/**/"] - config.autoload_paths += Dir[Rails.root.join('app', 'models', '{*/}')] + config.autoload_paths += Dir[Rails.root.join("app", "models", "{*/}")] - config.time_zone = 'Stockholm' + config.time_zone = "Stockholm" config.filter_parameters += [:password, :password_confirmation, :message] # Set taken from # https://github.com/rails/rails-html-sanitizer/blob/master/lib/rails/html/sanitizer.rb#L107 - WHITE_HTML_TAGS = Set.new(%w(strong em b i p code pre tt samp kbd var sub - sup dfn cite big small address hr br div span - h1 h2 h3 h4 h5 h6 ul ol li dl dt dd abbr - acronym a img blockquote del ins table tr td th)) + WHITE_HTML_TAGS = Set.new(%w[strong em b i p code pre tt samp kbd var sub + sup dfn cite big small address hr br div span + h1 h2 h3 h4 h5 h6 ul ol li dl dt dd abbr + acronym a img blockquote del ins table tr td th]) config.action_view.sanitized_allowed_tags = WHITE_HTML_TAGS config.active_job.queue_adapter = :sidekiq - config.action_cable.mount_path = '/cable' + config.action_cable.mount_path = "/cable" config.active_record.belongs_to_required_by_default = false end diff --git a/config/boot.rb b/config/boot.rb index 6b750f00b..fb24cf2ed 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,3 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) -require 'bundler/setup' # Set up gems listed in the Gemfile. +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/config/deploy.rb b/config/deploy.rb index d50523b1d..fee0c7c62 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,10 +1,10 @@ # config valid only for Capistrano 3.11.0 -lock '3.11.0' +lock "3.11.0" -set :application, 'fsek' -set :repo_url, 'https://github.com/fsek/web.git' -set :stages, %w(staging production development) -set :rbenv_path, '$HOME/.rbenv' +set :application, "fsek" +set :repo_url, "https://github.com/fsek/web.git" +set :stages, %w[staging production development] +set :rbenv_path, "$HOME/.rbenv" set :user, :dirac @@ -12,22 +12,22 @@ set :bundle_binstubs, nil # Default value for :linked_files is [] -set :linked_files, %w(.rbenv-vars) +set :linked_files, %w[.rbenv-vars] # Default value for linked_dirs is [] -set :linked_dirs, %w(log tmp vendor/bundle public/system - public/uploads storage public/sitemaps) +set :linked_dirs, %w[log tmp vendor/bundle public/system + public/uploads storage public/sitemaps] # Rollbar -set :rollbar_token, ENV['ROLLBAR_TOKEN'] +set :rollbar_token, ENV["ROLLBAR_TOKEN"] set :rollbar_env, proc { fetch :stage } set :rollbar_role, proc { :app } set :pty, true -before 'deploy:started', 'sidekiq:quiet' -after 'deploy:publishing', 'sidekiq:stop' -after 'deploy:published', 'passenger:restart' -after 'deploy:published', 'sitemap:refresh' -after 'deploy:published', 'deploy:permissions:load' -after 'deploy:published', 'sidekiq:start' +before "deploy:started", "sidekiq:quiet" +after "deploy:publishing", "sidekiq:stop" +after "deploy:published", "passenger:restart" +after "deploy:published", "sitemap:refresh" +after "deploy:published", "deploy:permissions:load" +after "deploy:published", "sidekiq:start" diff --git a/config/deploy/dev.rb b/config/deploy/dev.rb index 126307d66..a3b21015a 100644 --- a/config/deploy/dev.rb +++ b/config/deploy/dev.rb @@ -6,12 +6,12 @@ # Don't declare `role :all`, it's a meta role set :stage, :development -set :branch, 'dev' -set :rails_env, 'development' +set :branch, "dev" +set :rails_env, "development" -role :app, %w{dirac@fsektionen.se} -role :web, %w{dirac@fsektionen.se} -role :deb, %w{dirac@fsektionen.se} +role :app, %w[dirac@fsektionen.se] +role :web, %w[dirac@fsektionen.se] +role :deb, %w[dirac@fsektionen.se] # Extended Server Syntax # ====================== @@ -19,7 +19,7 @@ # definition into the server list. The second argument # something that quacks like a hash can be used to set # extended properties on the server. -server 'fsektionen.se', user: 'dirac', roles: %w{web app db} +server "fsektionen.se", user: "dirac", roles: %w[web app db] set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}/#{fetch(:stage)}" set :tmp_dir, "/home/#{fetch(:user)}/tmp/#{fetch(:stage)}" diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 7118ad121..82fc54506 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,6 +1,6 @@ # Simple Role Syntax set :stage, :production -set :branch, 'master' +set :branch, "master" set :rails_env, :production # ================== # Supports bulk-adding hosts to roles, the primary @@ -8,9 +8,9 @@ # unless any hosts have the primary property set. # Don't declare `role :all`, it's a meta role -role :app, %w{dirac@fsektionen.se} -role :web, %w{dirac@fsektionen.se} -role :db, %w{dirac@fsektionen.se} +role :app, %w[dirac@fsektionen.se] +role :web, %w[dirac@fsektionen.se] +role :db, %w[dirac@fsektionen.se] # Extended Server Syntax # ====================== @@ -18,7 +18,7 @@ # definition into the server list. The second argument # something that quacks like a hash can be used to set # extended properties on the server. -server 'fsektionen.se', user: 'dirac', roles: %w{web app} +server "fsektionen.se", user: "dirac", roles: %w[web app] set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}/#{fetch(:stage)}" set :tmp_dir, "/home/#{fetch(:user)}/tmp/#{fetch(:stage)}" @@ -26,11 +26,11 @@ # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) # set it globally -#set :ssh_options, { +# set :ssh_options, { # keys: %w(/home/rlisowski/.ssh/id_rsa), # forward_agent: false, # auth_methods: %w(password) -#} +# } # and/or per server # server 'example.com', # user: 'user_name', diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 57912d622..59f36f4dd 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,6 +1,6 @@ # Simple Role Syntax set :stage, :staging -set :branch, 'stage' +set :branch, "stage" set :rails_env, :staging # ================== @@ -8,9 +8,9 @@ # server in each group is considered to be the first # unless any hosts have the primary property set. # Don't declare `role :all`, it's a meta role -role :app, %w{dirac@fsektionen.se} -role :web, %w{dirac@fsektionen.se} -role :db, %w{dirac@fsektionen.se} +role :app, %w[dirac@fsektionen.se] +role :web, %w[dirac@fsektionen.se] +role :db, %w[dirac@fsektionen.se] # Extended Server Syntax # ====================== @@ -18,7 +18,7 @@ # definition into the server list. The second argument # something that quacks like a hash can be used to set # extended properties on the server. -server 'fsektionen.se', user: 'dirac', roles: %w{web app} +server "fsektionen.se", user: "dirac", roles: %w[web app] set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}/#{fetch(:stage)}" set :tmp_dir, "/home/#{fetch(:user)}/tmp/#{fetch(:stage)}" diff --git a/config/environment.rb b/config/environment.rb index d988dc337..9ba571df3 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require File.expand_path("../application", __FILE__) # Initialize the Rails application. Fsek::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index f73521e9a..16d1cc857 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,5 @@ -# encoding: UTF-8 Fsek::Application.configure do - PUBLIC_URL = 'http://localhost:3000'.freeze + PUBLIC_URL = "http://localhost:3000".freeze # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -15,12 +14,12 @@ config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp/caching-dev.txt').exist? + if Rails.root.join("tmp/caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=172800' + "Cache-Control" => "public, max-age=172800" } else config.action_controller.perform_caching = false @@ -30,18 +29,18 @@ # Don't care if the mailer can't send. # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - config.action_mailer.default_url_options = { host: PUBLIC_URL } + config.action_mailer.default_url_options = {host: PUBLIC_URL} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = false - config.action_mailer.default charset: 'utf-8' + config.action_mailer.default charset: "utf-8" config.action_mailer.perform_caching = false config.action_mailer.smtp_settings = { - address: '127.0.0.1', + address: "127.0.0.1", port: 1025, domain: PUBLIC_URL, - authentication: 'plain', + authentication: "plain", enable_starttls_auto: false } @@ -76,7 +75,7 @@ Bullet.add_footer = true end - config.action_cable.allowed_request_origins = [PUBLIC_URL, 'file://', 'file:///'] + config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. diff --git a/config/environments/production.rb b/config/environments/production.rb index 804443815..33eb724f0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,5 @@ Rails.application.configure do - PUBLIC_URL = 'https://fsektionen.se'.freeze + PUBLIC_URL = "https://fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -36,7 +36,7 @@ # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for nginx # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil @@ -74,20 +74,20 @@ # config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :notify config.action_mailer.asset_host = PUBLIC_URL - config.action_mailer.default charset: 'utf-8' - config.action_mailer.default_url_options = { host: PUBLIC_URL } + config.action_mailer.default charset: "utf-8" + config.action_mailer.default_url_options = {host: PUBLIC_URL} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_caching = false config.action_mailer.smtp_settings = { - address: 'smtp-relay.gmail.com', + address: "smtp-relay.gmail.com", port: 587, - domain: 'fsektionen.se', - authentication: 'plain', + domain: "fsektionen.se", + authentication: "plain", enable_starttls_auto: true, - openssl_verify_mode: 'none' + openssl_verify_mode: "none" } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to @@ -106,5 +106,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_cable.allowed_request_origins = [PUBLIC_URL, 'file://', 'file:///'] + config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 2a4011adc..7c16652f2 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,5 +1,5 @@ Rails.application.configure do - PUBLIC_URL = 'https://stage.fsektionen.se'.freeze + PUBLIC_URL = "https://stage.fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -36,7 +36,7 @@ # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -61,20 +61,20 @@ # config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :notify config.action_mailer.asset_host = PUBLIC_URL - config.action_mailer.default charset: 'utf-8' - config.action_mailer.default_url_options = { host: PUBLIC_URL } + config.action_mailer.default charset: "utf-8" + config.action_mailer.default_url_options = {host: PUBLIC_URL} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_caching = false config.action_mailer.smtp_settings = { - address: 'smtp-relay.gmail.com', + address: "smtp-relay.gmail.com", port: 587, - domain: 'fsektionen.se', - authentication: 'plain', + domain: "fsektionen.se", + authentication: "plain", enable_starttls_auto: true, - openssl_verify_mode: 'none' + openssl_verify_mode: "none" } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to @@ -93,5 +93,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_cable.allowed_request_origins = [PUBLIC_URL, 'file://', 'file:///'] + config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] end diff --git a/config/environments/test.rb b/config/environments/test.rb index 40554301c..24a487c6c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,5 @@ Fsek::Application.configure do - PUBLIC_URL = 'http://localhost:3000'.freeze + PUBLIC_URL = "http://localhost:3000".freeze # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -17,10 +17,10 @@ config.public_file_server.enabled = true - config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } + config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"} # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. @@ -39,7 +39,7 @@ config.active_support.deprecation = :stderr config.action_controller.asset_host = PUBLIC_URL - config.action_mailer.default_url_options = { host: PUBLIC_URL } + config.action_mailer.default_url_options = {host: PUBLIC_URL} config.action_mailer.asset_host = PUBLIC_URL config.action_view.raise_on_missing_translations = true diff --git a/config/initializers/action_cable_config.rb b/config/initializers/action_cable_config.rb index 79bd2ffd4..b9d22ea2c 100644 --- a/config/initializers/action_cable_config.rb +++ b/config/initializers/action_cable_config.rb @@ -2,7 +2,7 @@ module ActionCableConfig # Read a value from cable.yml def self.[](key) unless @config - template = ERB.new(File.read(Rails.root + 'config/cable.yml')) + template = ERB.new(File.read(Rails.root + "config/cable.yml")) @config = YAML.load(template.result(binding))[Rails.env].symbolize_keys end @@ -17,9 +17,9 @@ def self.[](key) begin keys = redis.scan_each(match: "connected_to_group_*").to_a redis.del(keys) unless keys.blank? - Rails.logger.info('[ConnectedList]: Successfully cleared list of connected users.') + Rails.logger.info("[ConnectedList]: Successfully cleared list of connected users.") rescue - Rails.logger.error('[ConnectedList]: Failed to clear ConnectedList from redis. Have you started redis?') - Rails.logger.warn('[ConnectedList]: The list of users connected with action cable has not been reset.') + Rails.logger.error("[ConnectedList]: Failed to clear ConnectedList from redis. Have you started redis?") + Rails.logger.warn("[ConnectedList]: The list of users connected with action cable has not been reset.") end end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 5eb3875d1..28db36a44 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -2,15 +2,15 @@ module Fsek class Application < Rails::Application # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.2' + config.assets.version = "1.2" config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ - config.assets.precompile += %w( application.scss email.scss ) + config.assets.precompile += %w[application.scss email.scss] # # # Precompile additional assets. # # application.js, application.css, and all non-JS/CSS in app/assets folder are # already added. # # Rails.application.config.assets.precompile += %w( search.js ) - config.assets.paths << Rails.root.join('node_modules') + config.assets.paths << Rails.root.join("node_modules") end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 2b2e441ab..768229dda 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -10,7 +10,7 @@ # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'spindelman@fsektionen.se' + config.mailer_sender = "spindelman@fsektionen.se" # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' @@ -19,7 +19,7 @@ # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be # available as additional gems. - require 'devise/orm/active_record' + require "devise/orm/active_record" # ==> Configuration for any authentication mechanism # Configure which keys are used when authenticating a user. The default is @@ -200,7 +200,6 @@ # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you # are using only default views. - # Configure the default scope given to Warden. By default it's the first # devise role declared in your routes (usually :user). @@ -254,6 +253,6 @@ end Rails.application.config.to_prepare do - Devise::Mailer.layout('email') - Devise::Mailer.helper('email') + Devise::Mailer.layout("email") + Devise::Mailer.helper("email") end diff --git a/config/initializers/devise_token_auth.rb b/config/initializers/devise_token_auth.rb index 122e4d24e..fe15ce61d 100644 --- a/config/initializers/devise_token_auth.rb +++ b/config/initializers/devise_token_auth.rb @@ -50,6 +50,6 @@ # value, we will have to specify one every time we create a new account with # the API. Since we let regular devise handle email confirmation, and have # disabled the confirmation routes for devise_token_auth, this can be set to anything. - config.default_confirm_success_url = '/' - config.redirect_whitelist = ['/*', 'file://*'] + config.default_confirm_success_url = "/" + config.redirect_whitelist = ["/*", "file://*"] end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4780b08da..a877dcf0b 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,4 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password,:password_confirmation,:civic] +Rails.application.config.filter_parameters += [:password, :password_confirmation, :civic] diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index da902f4a0..72aca7e44 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,4 +2,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone \ No newline at end of file +# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index 702705e22..a0addcd7a 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -22,4 +22,4 @@ Rails.application.config.active_record.belongs_to_required_by_default = false # Do not halt callback chains when a callback returns false. Previous versions had true. -#ActiveSupport.halt_callback_chains_on_return_false = true +# ActiveSupport.halt_callback_chains_on_return_false = true diff --git a/config/initializers/paperclip_defaults.rb b/config/initializers/paperclip_defaults.rb index 2bfa66e9a..f0f0a5d18 100644 --- a/config/initializers/paperclip_defaults.rb +++ b/config/initializers/paperclip_defaults.rb @@ -1,3 +1,3 @@ -Paperclip::Attachment.default_options.update({ - :hash_secret => "2pRXPl0rLY+5U+7Cw7kCOQSpdr31tH+TSMG7fYIx8pM=" -}) \ No newline at end of file +Paperclip::Attachment.default_options.update({ + hash_secret: "2pRXPl0rLY+5U+7Cw7kCOQSpdr31tH+TSMG7fYIx8pM=" +}) diff --git a/config/initializers/ranged_datetime_wrapper.rb b/config/initializers/ranged_datetime_wrapper.rb index 3873c3bbf..35a190a31 100644 --- a/config/initializers/ranged_datetime_wrapper.rb +++ b/config/initializers/ranged_datetime_wrapper.rb @@ -1,15 +1,15 @@ SimpleForm.setup do |config| config.wrappers :ranged_datetime, - tag: 'div', class: 'form-group col-md-6', - error_class: 'has-error' do |b| + tag: "div", class: "form-group col-md-6", + error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.optional :readonly - b.use :label, class: 'control-label' - b.use :input, class: 'form-control' + b.use :label, class: "control-label" + b.use :input, class: "form-control" - b.use :error, wrap_with: { tag: 'span', class: 'help-block' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.use :error, wrap_with: {tag: "span", class: "help-block"} + b.use :hint, wrap_with: {tag: "p", class: "help-block"} end end diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb index 3be95e4f0..276cbe8da 100644 --- a/config/initializers/rollbar.rb +++ b/config/initializers/rollbar.rb @@ -2,14 +2,14 @@ # Without configuration, Rollbar is enabled in all environments. # To disable in specific environments, set config.enabled=false. - config.access_token = ENV['ROLLBAR_TOKEN'] + config.access_token = ENV["ROLLBAR_TOKEN"] # Here we'll disable in 'test': if Rails.env.test? config.enabled = false end - config.exception_level_filters['ActionController::RoutingError'] = 'ignore' + config.exception_level_filters["ActionController::RoutingError"] = "ignore" # By default, Rollbar will try to call the `current_user` controller method # to fetch the logged-in user object, and then call that object's `id`, @@ -37,12 +37,12 @@ # Enable delayed reporting (using Sidekiq) config.use_sidekiq # You can supply custom Sidekiq options: - config.use_sidekiq 'queue' => 'rollbar' + config.use_sidekiq "queue" => "rollbar" # If you run your staging application instance in production environment then # you'll want to override the environment reported by `Rails.env` with an # environment variable like this: `ROLLBAR_ENV=staging`. This is a recommended # setup for Heroku. See: # https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment - config.environment = ENV['ROLLBAR_ENV'] || Rails.env + config.environment = ENV["ROLLBAR_ENV"] || Rails.env end diff --git a/config/initializers/rpush.rb b/config/initializers/rpush.rb index 228ea59f8..9724169d5 100644 --- a/config/initializers/rpush.rb +++ b/config/initializers/rpush.rb @@ -1,5 +1,4 @@ Rpush.configure do |config| - # Supported clients are :active_record and :redis config.client = :active_record @@ -16,23 +15,21 @@ config.batch_size = 100 # Path to write PID file. Relative to current directory unless absolute. - config.pid_file = 'tmp/rpush.pid' + config.pid_file = "tmp/rpush.pid" # Path to log file. Relative to current directory unless absolute. - config.log_file = 'log/rpush.log' + config.log_file = "log/rpush.log" - config.log_level = (defined?(Rails) && Rails.logger) ? Rails.logger.level : ::Logger::Severity::INFO + config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO # Define a custom logger. # config.logger = MyLogger.new # config.apns.feedback_receiver.enabled = true # config.apns.feedback_receiver.frequency = 60 - end Rpush.reflect do |on| - # Called with a Rpush::Apns::Feedback instance when feedback is received # from the APNs that a notification has failed to be delivered. # Further notifications should not be sent to the device. diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index e2bce93d8..61a0c7e25 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Fsek::Application.config.session_store :cookie_store, key: '_fsek_session' +Fsek::Application.config.session_store :cookie_store, key: "_fsek_session" diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 7fa4986c2..aadd2196e 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,8 +1,8 @@ -redis = { url: "redis://localhost:6379/#{ENV['SIDEKIQ_DB_NUMBER'] || 0}" } +redis = {url: "redis://localhost:6379/#{ENV["SIDEKIQ_DB_NUMBER"] || 0}"} schedule_file = "config/schedule.yml" if Rails.env == "test" - redis = { url: "redis://localhost:6379/0" } + redis = {url: "redis://localhost:6379/0"} end Sidekiq.configure_server do |config| diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index d7c7a2446..4961da4d0 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -42,8 +42,8 @@ ## Inputs b.use :label_input - b.use :hint, wrap_with: { tag: :span, class: :hint } - b.use :error, wrap_with: { tag: :span, class: :error } + b.use :hint, wrap_with: {tag: :span, class: :hint} + b.use :error, wrap_with: {tag: :span, class: :error} ## full_messages_for # If you want to display the full error message for the attribute, you can @@ -62,7 +62,7 @@ config.boolean_style = :nested # Default class for buttons - config.button_class = 'btn' + config.button_class = "btn" # Method used to tidy up errors. Specify any Rails Array method. # :first lists the first message for each field. @@ -73,7 +73,7 @@ config.error_notification_tag = :div # CSS class to add for error notification helper. - config.error_notification_class = 'error_notification' + config.error_notification_class = "error_notification" # ID to add for error notification helper. # config.error_notification_id = nil @@ -156,7 +156,7 @@ # config.input_class = nil # Define the default class of the input wrapper of the boolean input. - config.boolean_label_class = 'checkbox' + config.boolean_label_class = "checkbox" # Defines if the default input wrapper class should be included in radio # collection wrappers. @@ -165,15 +165,15 @@ # Defines which i18n scope will be used in Simple Form. # config.i18n_scope = 'simple_form' - config.wrappers :with_devise, tag: 'div', class: 'form-group', error_class: 'error' do |b| + config.wrappers :with_devise, tag: "div", class: "form-group", error_class: "error" do |b| b.use :html5 - b.use :label, class: 'control-label col-md-4' - b.wrapper tag: 'div', class: 'col-md-8' do |ba| + b.use :label, class: "control-label col-md-4" + b.wrapper tag: "div", class: "col-md-8" do |ba| ba.use :placeholder ba.use :input - ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } - ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + ba.use :error, wrap_with: {tag: "span", class: "help-inline"} + ba.use :hint, wrap_with: {tag: "p", class: "help-block"} end end end diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index 7230e9326..f442af81d 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -1,134 +1,134 @@ # Use this setup block to configure all options available in SimpleForm. SimpleForm.setup do |config| - config.error_notification_class = 'alert alert-danger' - config.button_class = 'btn primary' + config.error_notification_class = "alert alert-danger" + config.button_class = "btn primary" config.boolean_label_class = nil - config.wrappers :vertical_form, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :vertical_form, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.optional :maxlength b.optional :pattern b.optional :min_max b.optional :readonly - b.use :label, class: 'control-label' + b.use :label, class: "control-label" - b.use :input, class: 'form-control' - b.use :error, wrap_with: { tag: 'span', class: 'help-block' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.use :input, class: "form-control" + b.use :error, wrap_with: {tag: "span", class: "help-block"} + b.use :hint, wrap_with: {tag: "p", class: "help-block"} end - config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :vertical_file_input, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.optional :maxlength b.optional :readonly - b.use :label, class: 'control-label' + b.use :label, class: "control-label" b.use :input - b.use :error, wrap_with: { tag: 'span', class: 'help-block' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.use :error, wrap_with: {tag: "span", class: "help-block"} + b.use :hint, wrap_with: {tag: "p", class: "help-block"} end - config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :vertical_boolean, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.optional :readonly - b.wrapper tag: 'div', class: 'checkbox' do |ba| + b.wrapper tag: "div", class: "checkbox" do |ba| ba.use :label_input end - b.use :error, wrap_with: { tag: 'span', class: 'help-block' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.use :error, wrap_with: {tag: "span", class: "help-block"} + b.use :hint, wrap_with: {tag: "p", class: "help-block"} end - config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :vertical_radio_and_checkboxes, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.optional :readonly - b.use :label, class: 'control-label' + b.use :label, class: "control-label" b.use :input - b.use :error, wrap_with: { tag: 'span', class: 'help-block' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.use :error, wrap_with: {tag: "span", class: "help-block"} + b.use :hint, wrap_with: {tag: "p", class: "help-block"} end - config.wrappers :horizontal_form, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :horizontal_form, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.optional :maxlength b.optional :pattern b.optional :min_max b.optional :readonly - b.use :label, class: 'col-sm-3 control-label' + b.use :label, class: "col-sm-3 control-label" - b.wrapper tag: 'div', class: 'col-sm-9' do |ba| - ba.use :input, class: 'form-control' - ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } - ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.wrapper tag: "div", class: "col-sm-9" do |ba| + ba.use :input, class: "form-control" + ba.use :error, wrap_with: {tag: "span", class: "help-block"} + ba.use :hint, wrap_with: {tag: "p", class: "help-block"} end end - config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :horizontal_file_input, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.optional :maxlength b.optional :readonly - b.use :label, class: 'col-sm-3 control-label' + b.use :label, class: "col-sm-3 control-label" - b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + b.wrapper tag: "div", class: "col-sm-9" do |ba| ba.use :input - ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } - ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + ba.use :error, wrap_with: {tag: "span", class: "help-block"} + ba.use :hint, wrap_with: {tag: "p", class: "help-block"} end end - config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :horizontal_boolean, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.optional :readonly - b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr| - wr.wrapper tag: 'div', class: 'checkbox' do |ba| - ba.use :label_input, class: 'col-sm-9' + b.wrapper tag: "div", class: "col-sm-offset-3 col-sm-9" do |wr| + wr.wrapper tag: "div", class: "checkbox" do |ba| + ba.use :label_input, class: "col-sm-9" end - wr.use :error, wrap_with: { tag: 'span', class: 'help-block' } - wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + wr.use :error, wrap_with: {tag: "span", class: "help-block"} + wr.use :hint, wrap_with: {tag: "p", class: "help-block"} end end - config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :horizontal_radio_and_checkboxes, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.optional :readonly - b.use :label, class: 'col-sm-3 control-label' + b.use :label, class: "col-sm-3 control-label" - b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + b.wrapper tag: "div", class: "col-sm-9" do |ba| ba.use :input - ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } - ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + ba.use :error, wrap_with: {tag: "span", class: "help-block"} + ba.use :hint, wrap_with: {tag: "p", class: "help-block"} end end - config.wrappers :inline_form, tag: 'div', class: 'form-group', - error_class: 'has-error' do |b| + config.wrappers :inline_form, tag: "div", class: "form-group", + error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.optional :maxlength b.optional :pattern b.optional :min_max b.optional :readonly - b.use :label, class: 'sr-only' + b.use :label, class: "sr-only" - b.use :input, class: 'form-control' - b.use :error, wrap_with: { tag: 'span', class: 'help-block' } - b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + b.use :input, class: "form-control" + b.use :error, wrap_with: {tag: "span", class: "help-block"} + b.use :hint, wrap_with: {tag: "p", class: "help-block"} end # Wrappers for forms and inputs using the Bootstrap toolkit. @@ -140,6 +140,6 @@ check_boxes: :vertical_radio_and_checkboxes, radio_buttons: :vertical_radio_and_checkboxes, file: :vertical_file_input, - boolean: :vertical_boolean, + boolean: :vertical_boolean } end diff --git a/config/initializers/wice_grid_config.rb b/config/initializers/wice_grid_config.rb index a751a78e6..ea49a0f7c 100644 --- a/config/initializers/wice_grid_config.rb +++ b/config/initializers/wice_grid_config.rb @@ -1,26 +1,25 @@ -# encoding: utf-8 if defined?(Wice::Defaults) # Default number of rows to show per page. Wice::Defaults::PER_PAGE = 20 # Default order direction - Wice::Defaults::ORDER_DIRECTION = 'asc' + Wice::Defaults::ORDER_DIRECTION = "asc" # Default name for a grid. A grid name is the basis for a lot of # names including parameter names, DOM IDs, etc # The shorter the name is the shorter the request URI will be. - Wice::Defaults::GRID_NAME = 'grid' + Wice::Defaults::GRID_NAME = "grid" # If REUSE_LAST_COLUMN_FOR_FILTER_ICONS is true and the last column doesn't have any filter and column name, it will be used # for filter related icons (filter icon, reset icon, show/hide icon), otherwise an additional table column is added. Wice::Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS = true # The label of the first option of a custom dropdown list meaning 'All items' - Wice::Defaults::CUSTOM_FILTER_ALL_LABEL = '--' + Wice::Defaults::CUSTOM_FILTER_ALL_LABEL = "--" # A list of classes for the table tag of the grid - Wice::Defaults::DEFAULT_TABLE_CLASSES = ['table', 'table-bordered', 'table-striped'] + Wice::Defaults::DEFAULT_TABLE_CLASSES = ["table", "table-bordered", "table-striped"] # Allow switching between a single and multiple selection modes in custom filters (dropdown boxes) Wice::Defaults::ALLOW_MULTIPLE_SELECTION = true @@ -32,7 +31,7 @@ Wice::Defaults::ENABLE_EXPORT_TO_CSV = false # Default CSV field separator - Wice::Defaults::CSV_FIELD_SEPARATOR = ',' + Wice::Defaults::CSV_FIELD_SEPARATOR = "," # Default CSV encoding (p.e. 'CP1252:UTF-8' to make Microsoft Excel(tm) happy) Wice::Defaults::CSV_ENCODING = nil @@ -47,7 +46,7 @@ Wice::Defaults::AUTO_RELOAD = false # SQL operator used for matching strings in string filters. - Wice::Defaults::STRING_MATCHING_OPERATOR = 'LIKE' + Wice::Defaults::STRING_MATCHING_OPERATOR = "LIKE" # STRING_MATCHING_OPERATOR = 'ILIKE' # Use this for Postgresql case-insensitive matching. # Defining one string matching operator globally for the whole application turns is not enough @@ -58,8 +57,8 @@ # # UPPER(table.field) LIKE UPPER(?)" Wice::Defaults::STRING_MATCHING_OPERATORS = { - 'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE', - 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE' + "ActiveRecord::ConnectionAdapters::MysqlAdapter" => "LIKE", + "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter" => "ILIKE" } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -113,7 +112,7 @@ # ActiveRecord model to store queries. Read the documentation for details # QUERY_STORE_MODEL = 'WiceGridSerializedQuery' - Wice::Defaults::QUERY_STORE_MODEL = 'WiceGridSerializedQuery' + Wice::Defaults::QUERY_STORE_MODEL = "WiceGridSerializedQuery" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Here go settings related to the date/datetime filters # @@ -130,25 +129,25 @@ # Format of the datetime displayed. # If you change the format, make sure to check if +DATETIME_PARSER+ can still parse this string. - Wice::Defaults::DATETIME_FORMAT = '%Y-%m-%d %H:%M' + Wice::Defaults::DATETIME_FORMAT = "%Y-%m-%d %H:%M" # Format of the date displayed. # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string. - Wice::Defaults::DATE_FORMAT = '%Y-%m-%d' + Wice::Defaults::DATE_FORMAT = "%Y-%m-%d" # Format of the date displayed in jQuery's Datepicker # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string. - Wice::Defaults::DATE_FORMAT_JQUERY = 'yy-mm-dd' + Wice::Defaults::DATE_FORMAT_JQUERY = "yy-mm-dd" # Format of the date displayed in Bootstrap's Datepicker # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string. - Wice::Defaults::DATE_FORMAT_BOOTSTRAP = 'yyyy-mm-dd' + Wice::Defaults::DATE_FORMAT_BOOTSTRAP = "yyyy-mm-dd" # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the # format defined by +DATETIME_FORMAT+ and must generate a DateTime object. # In many cases Time.zone.parse is enough, for instance, %Y-%m-%d. If you change the format, make sure to check this code # and modify it if needed. - Wice::Defaults::DATETIME_PARSER = lambda do|datetime_string| + Wice::Defaults::DATETIME_PARSER = lambda do |datetime_string| if datetime_string.blank? nil elsif Time.zone @@ -161,13 +160,13 @@ # The range of years to display in jQuery Datepicker. # It can always be changed dynamically with the following javascript: # $( ".hasDatepicker" ).datepicker( "option", "yearRange", "2000:2042" ); - Wice::Defaults::DATEPICKER_YEAR_RANGE = (from = Date.current.year - 10).to_s + ':' + (from + 15).to_s + Wice::Defaults::DATEPICKER_YEAR_RANGE = (from = Date.current.year - 10).to_s + ":" + (from + 15).to_s # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the # format defined by +DATETIME+ and must generate a Date object. # In many cases Date.parse is enough, for instance, %Y-%m-%d. If you change the format, make sure to check this code # and modify it if needed. - Wice::Defaults::DATE_PARSER = lambda do|date_string| + Wice::Defaults::DATE_PARSER = lambda do |date_string| if date_string.blank? nil else diff --git a/config/puma.rb b/config/puma.rb index 1e19380dc..33f5fae7a 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -9,7 +9,7 @@ # 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. # diff --git a/config/routes.rb b/config/routes.rb index 267c9397b..63acc23fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,50 +1,50 @@ Fsek::Application.routes.draw do filter :locale, exclude: /^\/admin/ # Resources on the page - get('/vecktorn', to: redirect('http://fsektionen.us11.list-manage.com/subscribe?u=b115d5ab658a971e771610695&id=aeb6a02396'), + get("/vecktorn", to: redirect("http://fsektionen.us11.list-manage.com/subscribe?u=b115d5ab658a971e771610695&id=aeb6a02396"), as: :vecktorn_signup, status: 301) - get('/weektorn', to: redirect('http://fsektionen.us11.list-manage.com/subscribe?u=b115d5ab658a971e771610695&id=3850d20a69'), + get("/weektorn", to: redirect("http://fsektionen.us11.list-manage.com/subscribe?u=b115d5ab658a971e771610695&id=3850d20a69"), as: :weektorn_signup, status: 301) - get('/vecktorn/arkiv', to: redirect('http://us11.campaign-archive2.com/home/?u=b115d5ab658a971e771610695&id=aeb6a02396'), + get("/vecktorn/arkiv", to: redirect("http://us11.campaign-archive2.com/home/?u=b115d5ab658a971e771610695&id=aeb6a02396"), as: :vecktorn_archive, status: 301) - get('/weektorn/archive', to: redirect('http://us11.campaign-archive2.com/home/?u=b115d5ab658a971e771610695&id=3850d20a69'), + get("/weektorn/archive", to: redirect("http://us11.campaign-archive2.com/home/?u=b115d5ab658a971e771610695&id=3850d20a69"), as: :weektorn_archive, status: 301) - get '/farad', to: redirect('http://www.farad.nu'), as: :farad, status: 301 - get '/facebook', to: redirect('https://www.facebook.com/Fsektionen'), as: :facebook, status: 301 - get '/twitter', to: redirect('https://www.twitter.com/Fsektionen'), as: :twitter, status: 301 - get '/youtube', to: redirect('https://www.youtube.com/user/fsektionen'), as: :youtube, status: 301 + get "/farad", to: redirect("http://www.farad.nu"), as: :farad, status: 301 + get "/facebook", to: redirect("https://www.facebook.com/Fsektionen"), as: :facebook, status: 301 + get "/twitter", to: redirect("https://www.twitter.com/Fsektionen"), as: :twitter, status: 301 + get "/youtube", to: redirect("https://www.youtube.com/user/fsektionen"), as: :youtube, status: 301 get :cookies_information, controller: :static_pages, as: :cookies, path: :cookies get :about, controller: :static_pages, path: :om get :privacy, controller: :static_pages, path: :sekretess get :influence, controller: :static_pages, path: :jagvill - get 'foretag/om', controller: :static_pages, action: :company_about, as: :company_about - get 'foretag/vi-erbjuder', controller: :static_pages, action: :company_offer, as: :company_offer - get 'robots.:format', controller: :static_pages, action: :robots, as: :robots + get "foretag/om", controller: :static_pages, action: :company_about, as: :company_about + get "foretag/vi-erbjuder", controller: :static_pages, action: :company_offer, as: :company_offer + get "robots.:format", controller: :static_pages, action: :robots, as: :robots - require 'sidekiq/web' + require "sidekiq/web" constraints Constraints::Sidekiq.new do - mount(Sidekiq::Web => '/sidekiq', as: :sidekiq) + mount(Sidekiq::Web => "/sidekiq", :as => :sidekiq) end - require 'sidekiq/cron/web' + require "sidekiq/cron/web" # User-related routes devise_for :users, skip: [:sessions, :registrations] devise_scope :user do - get 'avbryt_reg' => 'devise/registrations#cancel', as: :cancel_user_registration - post 'anvandare/skapa' => 'registrations#create', as: :user_registration - get 'anvandare/registrera' => 'devise/registrations#new', as: :new_user_registration + get "avbryt_reg" => "devise/registrations#cancel", :as => :cancel_user_registration + post "anvandare/skapa" => "registrations#create", :as => :user_registration + get "anvandare/registrera" => "devise/registrations#new", :as => :new_user_registration # sessions - get 'logga-in' => 'devise/sessions#new', as: :new_user_session - get 'logga_in', to: redirect('logga-in'), status: 301 - post 'logga-in' => 'devise/sessions#create', as: :user_session - delete 'logga-ut' => 'devise/sessions#destroy', as: :destroy_user_session + get "logga-in" => "devise/sessions#new", :as => :new_user_session + get "logga_in", to: redirect("logga-in"), status: 301 + post "logga-in" => "devise/sessions#create", :as => :user_session + delete "logga-ut" => "devise/sessions#destroy", :as => :destroy_user_session end # Scope to change urls to swedish - scope path_names: { new: 'ny', edit: 'redigera' } do + scope path_names: {new: "ny", edit: "redigera"} do resources :tools, path: :verktyg, only: [:show, :index] namespace :admin do @@ -61,7 +61,7 @@ end resource :user, path: :anvandare, as: :own_user, only: [:update] do - get '', action: :edit, as: :edit + get "", action: :edit, as: :edit patch :password, path: :losenord, action: :update_password patch :account, path: :konto, action: :update_account patch :accept_terms @@ -91,7 +91,7 @@ namespace :admin do get :cafe, path: :hilbertcafe, controller: :cafe, action: :index - get :overview_cafe, controller: :cafe, action: :overview, path: 'hilbertcafe/oversikt' + get :overview_cafe, controller: :cafe, action: :overview, path: "hilbertcafe/oversikt" resources :cafe_shifts, path: :hilbertcafe, except: :index do resources :cafe_workers, path: :jobba, only: [:create, :update, :destroy, :new] @@ -100,9 +100,9 @@ end end - get :ladybug_cafe, controller: :cafe, action: :ladybug, path: 'hilbertcafe/nyckelpiga' + get :ladybug_cafe, controller: :cafe, action: :ladybug, path: "hilbertcafe/nyckelpiga" get :cafe, path: :hilbertcafe, controller: :cafe, action: :index - get :competition_cafe, controller: :cafe, action: :competition, path: 'hilbertcafe/tavling' + get :competition_cafe, controller: :cafe, action: :competition, path: "hilbertcafe/tavling" resources :cafe_shifts, path: :hilbertcafe, only: :show do get :feed, on: :collection @@ -136,7 +136,7 @@ namespace :admin do resources :pages, path: :sida, except: :show do resources :page_elements, path: :element, except: :show - delete 'destroy_image/:image_id', on: :member, action: :destroy_image, as: :destroy_image + delete "destroy_image/:image_id", on: :member, action: :destroy_image, as: :destroy_image end end @@ -146,7 +146,7 @@ get :archive, path: :arkiv, on: :collection get :dance, path: :dans, on: :collection get :matrix, path: :matris, on: :collection - get 'modal/:date', action: :modal, as: :modal, on: :member + get "modal/:date", action: :modal, as: :modal, on: :member end resources :adventures, path: :aventyr, only: [:index, :show] do @@ -184,7 +184,7 @@ resources :councils, path: :utskott, except: :show do resources :posts, path: :poster, except: :show do collection do - delete 'anvandare/:post_user_id', action: :remove_user, as: :remove_user + delete "anvandare/:post_user_id", action: :remove_user, as: :remove_user patch :add_user end end @@ -222,7 +222,7 @@ resources :events, path: :evenemang, except: :show do resources :event_signups, path: :anmalan, only: [:create, :update, :destroy] resource :event_signup, path: :anmalan, only: :show, as: :signup do - get 'export', on: :collection + get "export", on: :collection end resources :event_users, path: :anmalningar, only: [:edit, :update, :destroy] end @@ -255,11 +255,11 @@ resources :elections, path: :val, only: :index do collection do - resources :nominations, controller: 'elections/nominations', + resources :nominations, controller: "elections/nominations", path: :nominera, only: [:create] do - get '', action: :new, on: :collection, as: :new + get "", action: :new, on: :collection, as: :new end - resources :candidates, controller: 'elections/candidates', + resources :candidates, controller: "elections/candidates", path: :kandidera, except: [:show, :update] resources :posts, path: :poster, only: :show do get :modal, on: :member @@ -285,13 +285,13 @@ namespace :admin do resources :permissions, only: :index do - get '/:post_id', action: :show_post, on: :collection, as: :post - patch '(/:post_id)', action: :update_post, on: :collection, as: :update + get "/:post_id", action: :show_post, on: :collection, as: :post + patch "(/:post_id)", action: :update_post, on: :collection, as: :update end resources :doors, path: :dorrar, except: :show do get :accesses, path: :accesser, on: :member - get :post, path: '/post/:post_id', on: :collection + get :post, path: "/post/:post_id", on: :collection end end @@ -370,8 +370,8 @@ end # API routes - namespace :api, constraints: { format: 'json' } do - mount_devise_token_auth_for 'User', at: 'auth', skip: [:omniauth_callbacks, :confirmations] + namespace :api, constraints: {format: "json"} do + mount_devise_token_auth_for "User", at: "auth", skip: [:omniauth_callbacks, :confirmations] resources :versions, only: :index @@ -435,12 +435,12 @@ resources :councils, only: :index end - get 'proposals/form' => 'proposals#form' - post 'proposals/generate' => 'proposals#generate' + get "proposals/form" => "proposals#form" + post "proposals/generate" => "proposals#generate" - root 'static_pages#index' + root "static_pages#index" # Catch-all for short links. # This must be at the bottom! - get '*link' => 'short_links#go' + get "*link" => "short_links#go" end diff --git a/config/sitemap.rb b/config/sitemap.rb index 3c9d0a09d..48e8d74fc 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -1,7 +1,7 @@ # Set the host name for URL creation puts PUBLIC_URL SitemapGenerator::Sitemap.default_host = PUBLIC_URL -SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/' +SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/" SitemapGenerator::Sitemap.create do add root_path, priority: 1.0 diff --git a/config/spring.rb b/config/spring.rb index c9119b40c..9fa7863f9 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,6 @@ -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/db/migrate/20160831154400_init_schema.rb b/db/migrate/20160831154400_init_schema.rb index 85aa1e9d7..959ffc595 100644 --- a/db/migrate/20160831154400_init_schema.rb +++ b/db/migrate/20160831154400_init_schema.rb @@ -1,23 +1,22 @@ class InitSchema < ActiveRecord::Migration[5.0] def up - create_table "accesses", force: :cascade do |t| - t.integer "door_id", limit: 4 - t.integer "post_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "door_id", limit: 4 + t.integer "post_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "accesses", ["door_id"], name: "index_accesses_on_door_id", using: :btree add_index "accesses", ["post_id"], name: "index_accesses_on_post_id", using: :btree create_table "adventure_groups", force: :cascade do |t| - t.integer "points", limit: 4, default: 0, null: false - t.integer "adventure_id", limit: 4 - t.integer "group_id", limit: 4 + t.integer "points", limit: 4, default: 0, null: false + t.integer "adventure_id", limit: 4 + t.integer "group_id", limit: 4 t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "adventure_groups", ["adventure_id"], name: "index_adventure_groups_on_adventure_id", using: :btree @@ -25,29 +24,29 @@ def up add_index "adventure_groups", ["group_id"], name: "index_adventure_groups_on_group_id", using: :btree create_table "adventure_translations", force: :cascade do |t| - t.integer "adventure_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "content", limit: 65535 + t.integer "adventure_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "content", limit: 65535 end add_index "adventure_translations", ["adventure_id"], name: "index_adventure_translations_on_adventure_id", using: :btree add_index "adventure_translations", ["locale"], name: "index_adventure_translations_on_locale", using: :btree create_table "adventures", force: :cascade do |t| - t.string "title", limit: 255 - t.text "content", limit: 65535 - t.integer "max_points", limit: 4, null: false - t.integer "introduction_id", limit: 4 - t.boolean "publish_results", default: false, null: false + t.string "title", limit: 255 + t.text "content", limit: 65535 + t.integer "max_points", limit: 4, null: false + t.integer "introduction_id", limit: 4 + t.boolean "publish_results", default: false, null: false t.datetime "start_date" t.datetime "end_date" t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "video", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "video", limit: 255 end add_index "adventures", ["deleted_at"], name: "index_adventures_on_deleted_at", using: :btree @@ -56,78 +55,78 @@ def up add_index "adventures", ["start_date"], name: "index_adventures_on_start_date", using: :btree create_table "album_translations", force: :cascade do |t| - t.integer "album_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.integer "album_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "description", limit: 65535 end add_index "album_translations", ["album_id"], name: "index_album_translations_on_album_id", using: :btree add_index "album_translations", ["locale"], name: "index_album_translations_on_locale", using: :btree create_table "albums", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.string "location", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.string "location", limit: 255 t.datetime "start_date" t.datetime "end_date" t.datetime "created_at" t.datetime "updated_at" - t.string "category", limit: 255 - t.integer "images_count", limit: 4, default: 0, null: false + t.string "category", limit: 255 + t.integer "images_count", limit: 4, default: 0, null: false end create_table "blog_post_translations", force: :cascade do |t| - t.integer "blog_post_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "preamble", limit: 65535 - t.text "content", limit: 65535 + t.integer "blog_post_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "preamble", limit: 65535 + t.text "content", limit: 65535 end add_index "blog_post_translations", ["blog_post_id"], name: "index_blog_post_translations_on_blog_post_id", using: :btree add_index "blog_post_translations", ["locale"], name: "index_blog_post_translations_on_locale", using: :btree create_table "blog_posts", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.string "title", limit: 255 - t.text "preamble", limit: 65535 - t.text "content", limit: 65535 + t.integer "user_id", limit: 4 + t.string "title", limit: 255 + t.text "preamble", limit: 65535 + t.text "content", limit: 65535 t.datetime "deleted_at" - t.string "cover_image", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "cover_image", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "blog_posts", ["deleted_at"], name: "index_blog_posts_on_deleted_at", using: :btree add_index "blog_posts", ["user_id"], name: "index_blog_posts_on_user_id", using: :btree create_table "cafe_shifts", force: :cascade do |t| - t.datetime "start", null: false - t.integer "pass", limit: 4, null: false - t.integer "lp", limit: 4, null: false - t.integer "lv", limit: 4, null: false + t.datetime "start", null: false + t.integer "pass", limit: 4, null: false + t.integer "lp", limit: 4, null: false + t.integer "lv", limit: 4, null: false end create_table "cafe_worker_councils", force: :cascade do |t| t.integer "cafe_worker_id", limit: 4 - t.integer "council_id", limit: 4 + t.integer "council_id", limit: 4 end add_index "cafe_worker_councils", ["cafe_worker_id"], name: "index_cafe_worker_councils_on_cafe_worker_id", using: :btree add_index "cafe_worker_councils", ["council_id"], name: "index_cafe_worker_councils_on_council_id", using: :btree create_table "cafe_workers", force: :cascade do |t| - t.integer "user_id", limit: 4, null: false - t.integer "cafe_shift_id", limit: 4, null: false - t.boolean "competition", default: true - t.string "group", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "user_id", limit: 4, null: false + t.integer "cafe_shift_id", limit: 4, null: false + t.boolean "competition", default: true + t.string "group", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cafe_workers", ["cafe_shift_id"], name: "index_cafe_workers_on_cafe_shift_id", using: :btree @@ -135,11 +134,11 @@ def up add_index "cafe_workers", ["user_id"], name: "index_cafe_workers_on_user_id", using: :btree create_table "candidates", force: :cascade do |t| - t.integer "post_id", limit: 4 - t.integer "election_id", limit: 4 + t.integer "post_id", limit: 4 + t.integer "election_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4 + t.integer "user_id", limit: 4 end add_index "candidates", ["election_id"], name: "index_candidates_on_election_id", using: :btree @@ -147,20 +146,20 @@ def up add_index "candidates", ["user_id"], name: "index_candidates_on_user_id", using: :btree create_table "categories", force: :cascade do |t| - t.string "title", limit: 255, null: false - t.string "slug", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "title", limit: 255, null: false + t.string "slug", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "categories", ["slug"], name: "index_categories_on_slug", using: :btree create_table "categorizations", force: :cascade do |t| - t.integer "category_id", limit: 4 - t.string "categorizable_type", limit: 255, null: false - t.integer "categorizable_id", limit: 4, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "category_id", limit: 4 + t.string "categorizable_type", limit: 255, null: false + t.integer "categorizable_id", limit: 4, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "categorizations", ["categorizable_id"], name: "index_categorizations_on_categorizable_id", using: :btree @@ -168,78 +167,78 @@ def up add_index "categorizations", ["category_id"], name: "index_categorizations_on_category_id", using: :btree create_table "constants", force: :cascade do |t| - t.string "name", limit: 255 - t.string "value", limit: 255 + t.string "name", limit: 255 + t.string "value", limit: 255 t.datetime "created_at" t.datetime "updated_at" end create_table "contact_translations", force: :cascade do |t| - t.integer "contact_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name", limit: 255 - t.text "text", limit: 65535 + t.integer "contact_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name", limit: 255 + t.text "text", limit: 65535 end add_index "contact_translations", ["contact_id"], name: "index_contact_translations_on_contact_id", using: :btree add_index "contact_translations", ["locale"], name: "index_contact_translations_on_locale", using: :btree create_table "contacts", force: :cascade do |t| - t.string "name", limit: 255 - t.string "email", limit: 255 - t.boolean "public" - t.text "text", limit: 65535 + t.string "name", limit: 255 + t.string "email", limit: 255 + t.boolean "public" + t.text "text", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 255 - t.integer "post_id", limit: 4 + t.string "slug", limit: 255 + t.integer "post_id", limit: 4 end add_index "contacts", ["post_id"], name: "index_contacts_on_post_id", using: :btree add_index "contacts", ["slug"], name: "index_contacts_on_slug", using: :btree create_table "councils", force: :cascade do |t| - t.string "title", limit: 255 - t.string "url", limit: 255 - t.text "description", limit: 65535 + t.string "title", limit: 255 + t.string "url", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.integer "president_id", limit: 4 + t.integer "president_id", limit: 4 end add_index "councils", ["president_id"], name: "index_councils_on_president_id", using: :btree add_index "councils", ["url"], name: "index_councils_on_url", using: :btree create_table "documents", force: :cascade do |t| - t.string "pdf_file_name", limit: 255 - t.string "pdf_content_type", limit: 255 - t.integer "pdf_file_size", limit: 4 + t.string "pdf_file_name", limit: 255 + t.string "pdf_content_type", limit: 255 + t.integer "pdf_file_size", limit: 4 t.datetime "pdf_updated_at" - t.string "title", limit: 255 - t.boolean "public" - t.boolean "download" - t.string "category", limit: 255 + t.string "title", limit: 255 + t.boolean "public" + t.boolean "download" + t.string "category", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4 - t.string "slug", limit: 255 + t.integer "user_id", limit: 4 + t.string "slug", limit: 255 end create_table "doors", force: :cascade do |t| - t.string "title", limit: 255 - t.string "slug", limit: 255 - t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.string "slug", limit: 255 + t.text "description", limit: 65535 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "election_posts", force: :cascade do |t| - t.integer "election_id", limit: 4 - t.integer "post_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "election_id", limit: 4 + t.integer "post_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "election_posts", ["election_id"], name: "index_election_posts_on_election_id", using: :btree @@ -248,56 +247,56 @@ def up create_table "elections", force: :cascade do |t| t.datetime "open" t.datetime "close_general" - t.boolean "visible" - t.string "url", limit: 255 - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.boolean "visible" + t.string "url", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.text "candidate_mail", limit: 65535 - t.text "nominate_mail", limit: 65535 - t.text "candidate_mail_star", limit: 65535 - t.string "mail_link", limit: 255 - t.string "board_mail_link", limit: 255 + t.text "candidate_mail", limit: 65535 + t.text "nominate_mail", limit: 65535 + t.text "candidate_mail_star", limit: 65535 + t.string "mail_link", limit: 255 + t.string "board_mail_link", limit: 255 t.datetime "close_all" - t.string "semester", limit: 255, default: "spring" + t.string "semester", limit: 255, default: "spring" end create_table "event_registrations", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "event_id", limit: 4 - t.boolean "reserve", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "answer", limit: 65535 + t.integer "user_id", limit: 4 + t.integer "event_id", limit: 4 + t.boolean "reserve", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "answer", limit: 65535 end create_table "event_signup_translations", force: :cascade do |t| - t.integer "event_signup_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "question", limit: 255 + t.integer "event_signup_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "question", limit: 255 end add_index "event_signup_translations", ["event_signup_id"], name: "index_event_signup_translations_on_event_signup_id", using: :btree add_index "event_signup_translations", ["locale"], name: "index_event_signup_translations_on_locale", using: :btree create_table "event_signups", force: :cascade do |t| - t.integer "event_id", limit: 4 - t.boolean "for_members", default: true, null: false - t.string "question", limit: 255 - t.integer "slots", limit: 4, null: false - t.datetime "closes", null: false - t.datetime "opens", null: false - t.integer "novice", limit: 4 - t.integer "mentor", limit: 4 - t.integer "member", limit: 4 - t.integer "custom", limit: 4 - t.string "custom_name", limit: 255 + t.integer "event_id", limit: 4 + t.boolean "for_members", default: true, null: false + t.string "question", limit: 255 + t.integer "slots", limit: 4, null: false + t.datetime "closes", null: false + t.datetime "opens", null: false + t.integer "novice", limit: 4 + t.integer "mentor", limit: 4 + t.integer "member", limit: 4 + t.integer "custom", limit: 4 + t.string "custom_name", limit: 255 t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "event_signups", ["deleted_at"], name: "index_event_signups_on_deleted_at", using: :btree @@ -305,28 +304,28 @@ def up add_index "event_signups", ["event_id"], name: "index_event_signups_on_event_id", using: :btree create_table "event_translations", force: :cascade do |t| - t.integer "event_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.string "short", limit: 255 - t.string "location", limit: 255 + t.integer "event_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.string "short", limit: 255 + t.string "location", limit: 255 end add_index "event_translations", ["event_id"], name: "index_event_translations_on_event_id", using: :btree add_index "event_translations", ["locale"], name: "index_event_translations_on_locale", using: :btree create_table "event_users", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "event_id", limit: 4 - t.integer "group_id", limit: 4 - t.text "answer", limit: 65535 - t.string "user_type", limit: 255 + t.integer "user_id", limit: 4 + t.integer "event_id", limit: 4 + t.integer "group_id", limit: 4 + t.text "answer", limit: 65535 + t.string "user_type", limit: 255 t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "event_users", ["deleted_at"], name: "index_event_users_on_deleted_at", using: :btree @@ -335,43 +334,43 @@ def up add_index "event_users", ["user_id"], name: "index_event_users_on_user_id", using: :btree create_table "events", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.string "location", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.string "location", limit: 255 t.datetime "starts_at" t.datetime "ends_at" - t.boolean "all_day" + t.boolean "all_day" t.datetime "created_at" t.datetime "updated_at" - t.string "image_file_name", limit: 255 - t.integer "council_id", limit: 4 - t.string "short", limit: 255 - t.string "dot", limit: 255 - t.boolean "drink" - t.boolean "food" - t.boolean "cash" + t.string "image_file_name", limit: 255 + t.integer "council_id", limit: 4 + t.string "short", limit: 255 + t.string "dot", limit: 255 + t.boolean "drink" + t.boolean "food" + t.boolean "cash" t.datetime "deleted_at" - t.integer "price", limit: 4 - t.string "dress_code", limit: 255 + t.integer "price", limit: 4 + t.string "dress_code", limit: 255 end create_table "faqs", force: :cascade do |t| - t.string "question", limit: 255 - t.text "answer", limit: 65535 - t.integer "sorting_index", limit: 4 + t.string "question", limit: 255 + t.text "answer", limit: 65535 + t.integer "sorting_index", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "category", limit: 255 + t.string "category", limit: 255 end add_index "faqs", ["category"], name: "index_faqs_on_category", using: :btree create_table "group_messages", force: :cascade do |t| - t.integer "group_id", limit: 4 - t.integer "message_id", limit: 4 + t.integer "group_id", limit: 4 + t.integer "message_id", limit: 4 t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "group_messages", ["deleted_at"], name: "index_group_messages_on_deleted_at", using: :btree @@ -379,12 +378,12 @@ def up add_index "group_messages", ["message_id"], name: "index_group_messages_on_message_id", using: :btree create_table "group_users", force: :cascade do |t| - t.integer "group_id", limit: 4 - t.integer "user_id", limit: 4 - t.boolean "fadder", default: false, null: false + t.integer "group_id", limit: 4 + t.integer "user_id", limit: 4 + t.boolean "fadder", default: false, null: false t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "group_users", ["deleted_at"], name: "index_group_users_on_deleted_at", using: :btree @@ -392,28 +391,28 @@ def up add_index "group_users", ["user_id"], name: "index_group_users_on_user_id", using: :btree create_table "groups", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "number", limit: 4 - t.integer "introduction_id", limit: 4 + t.string "name", limit: 255 + t.integer "number", limit: 4 + t.integer "introduction_id", limit: 4 t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "group_type", limit: 255, default: "regular", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "group_type", limit: 255, default: "regular", null: false end add_index "groups", ["deleted_at"], name: "index_groups_on_deleted_at", using: :btree add_index "groups", ["introduction_id"], name: "index_groups_on_introduction_id", using: :btree create_table "images", force: :cascade do |t| - t.integer "album_id", limit: 4 + t.integer "album_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "file", limit: 255 - t.string "filename", limit: 255 - t.integer "photographer_id", limit: 4 - t.string "photographer_name", limit: 255 - t.integer "width", limit: 4 - t.integer "height", limit: 4 + t.string "file", limit: 255 + t.string "filename", limit: 255 + t.integer "photographer_id", limit: 4 + t.string "photographer_name", limit: 255 + t.integer "width", limit: 4 + t.integer "height", limit: 4 end add_index "images", ["album_id"], name: "index_images_on_album_id", using: :btree @@ -422,97 +421,97 @@ def up add_index "images", ["photographer_id"], name: "index_images_on_photographer_id", using: :btree create_table "introduction_translations", force: :cascade do |t| - t.integer "introduction_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.integer "introduction_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "description", limit: 65535 end add_index "introduction_translations", ["introduction_id"], name: "index_introduction_translations_on_introduction_id", using: :btree add_index "introduction_translations", ["locale"], name: "index_introduction_translations_on_locale", using: :btree create_table "introductions", force: :cascade do |t| - t.string "title", limit: 255, default: "", null: false - t.datetime "start", null: false - t.datetime "stop", null: false - t.string "slug", limit: 255, null: false - t.text "description", limit: 65535 - t.boolean "current", default: true, null: false + t.string "title", limit: 255, default: "", null: false + t.datetime "start", null: false + t.datetime "stop", null: false + t.string "slug", limit: 255, null: false + t.text "description", limit: 65535 + t.boolean "current", default: true, null: false t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "introductions", ["deleted_at"], name: "index_introductions_on_deleted_at", using: :btree add_index "introductions", ["slug"], name: "index_introductions_on_slug", using: :btree create_table "mail_aliases", force: :cascade do |t| - t.string "username", limit: 255, null: false - t.string "domain", limit: 255, null: false - t.string "target", limit: 255, null: false - t.datetime "updated_at", null: false + t.string "username", limit: 255, null: false + t.string "domain", limit: 255, null: false + t.string "target", limit: 255, null: false + t.datetime "updated_at", null: false end add_index "mail_aliases", ["target"], name: "index_mail_aliases_on_target", using: :btree add_index "mail_aliases", ["username", "domain", "target"], name: "index_mail_aliases_on_username_and_domain_and_target", unique: true, using: :btree create_table "main_menu_translations", force: :cascade do |t| - t.integer "main_menu_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name", limit: 255 + t.integer "main_menu_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name", limit: 255 end add_index "main_menu_translations", ["locale"], name: "index_main_menu_translations_on_locale", using: :btree add_index "main_menu_translations", ["main_menu_id"], name: "index_main_menu_translations_on_main_menu_id", using: :btree create_table "main_menus", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "index", limit: 4 - t.boolean "mega", default: true, null: false - t.boolean "fw", default: false, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "name", limit: 255 + t.integer "index", limit: 4 + t.boolean "mega", default: true, null: false + t.boolean "fw", default: false, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "menu_translations", force: :cascade do |t| - t.integer "menu_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name", limit: 255 + t.integer "menu_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name", limit: 255 end add_index "menu_translations", ["locale"], name: "index_menu_translations_on_locale", using: :btree add_index "menu_translations", ["menu_id"], name: "index_menu_translations_on_menu_id", using: :btree create_table "menus", force: :cascade do |t| - t.integer "index", limit: 4 - t.string "link", limit: 255 - t.string "name", limit: 255 - t.boolean "visible", default: true - t.boolean "turbolinks", default: true - t.boolean "blank_p" + t.integer "index", limit: 4 + t.string "link", limit: 255 + t.string "name", limit: 255 + t.boolean "visible", default: true + t.boolean "turbolinks", default: true + t.boolean "blank_p" t.datetime "created_at" t.datetime "updated_at" - t.boolean "header", default: false, null: false - t.integer "column", limit: 4, default: 1, null: false - t.integer "main_menu_id", limit: 4 + t.boolean "header", default: false, null: false + t.integer "column", limit: 4, default: 1, null: false + t.integer "main_menu_id", limit: 4 end add_index "menus", ["main_menu_id"], name: "index_menus_on_main_menu_id", using: :btree create_table "message_comments", force: :cascade do |t| - t.integer "message_id", limit: 4 - t.integer "user_id", limit: 4 - t.text "content", limit: 65535, null: false + t.integer "message_id", limit: 4 + t.integer "user_id", limit: 4 + t.text "content", limit: 65535, null: false t.datetime "deleted_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "by_admin", default: false, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "by_admin", default: false, null: false end add_index "message_comments", ["deleted_at"], name: "index_message_comments_on_deleted_at", using: :btree @@ -520,14 +519,14 @@ def up add_index "message_comments", ["user_id"], name: "index_message_comments_on_user_id", using: :btree create_table "messages", force: :cascade do |t| - t.integer "user_id", limit: 4 - t.text "content", limit: 65535, null: false + t.integer "user_id", limit: 4 + t.text "content", limit: 65535, null: false t.datetime "deleted_at" - t.integer "message_comments_count", limit: 4, default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "by_admin", default: false, null: false - t.integer "introduction_id", limit: 4 + t.integer "message_comments_count", limit: 4, default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "by_admin", default: false, null: false + t.integer "introduction_id", limit: 4 end add_index "messages", ["deleted_at"], name: "index_messages_on_deleted_at", using: :btree @@ -535,105 +534,105 @@ def up add_index "messages", ["user_id"], name: "index_messages_on_user_id", using: :btree create_table "news", force: :cascade do |t| - t.string "title", limit: 255 - t.text "content", limit: 65535 + t.string "title", limit: 255 + t.text "content", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4 - t.string "url", limit: 255 - t.string "image", limit: 255 + t.integer "user_id", limit: 4 + t.string "url", limit: 255 + t.string "image", limit: 255 end create_table "news_translations", force: :cascade do |t| - t.integer "news_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "content", limit: 65535 + t.integer "news_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "content", limit: 65535 end add_index "news_translations", ["locale"], name: "index_news_translations_on_locale", using: :btree add_index "news_translations", ["news_id"], name: "index_news_translations_on_news_id", using: :btree create_table "nominations", force: :cascade do |t| - t.integer "post_id", limit: 4 - t.integer "election_id", limit: 4 - t.string "name", limit: 255 - t.string "email", limit: 255 - t.text "motivation", limit: 65535 + t.integer "post_id", limit: 4 + t.integer "election_id", limit: 4 + t.string "name", limit: 255 + t.string "email", limit: 255 + t.text "motivation", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "notice_translations", force: :cascade do |t| - t.integer "notice_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.integer "notice_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255 + t.text "description", limit: 65535 end add_index "notice_translations", ["locale"], name: "index_notice_translations_on_locale", using: :btree add_index "notice_translations", ["notice_id"], name: "index_notice_translations_on_notice_id", using: :btree create_table "notices", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.boolean "public" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.boolean "public" t.datetime "d_publish" t.datetime "d_remove" - t.integer "sort", limit: 4 - t.string "image", limit: 255 + t.integer "sort", limit: 4 + t.string "image", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4, null: false + t.integer "user_id", limit: 4, null: false end create_table "page_element_translations", force: :cascade do |t| - t.integer "page_element_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "text", limit: 65535 - t.string "headline", limit: 255 + t.integer "page_element_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "text", limit: 65535 + t.string "headline", limit: 255 end add_index "page_element_translations", ["locale"], name: "index_page_element_translations_on_locale", using: :btree add_index "page_element_translations", ["page_element_id"], name: "index_page_element_translations_on_page_element_id", using: :btree create_table "page_elements", force: :cascade do |t| - t.integer "index", limit: 4, default: 1 - t.boolean "sidebar" - t.boolean "visible", default: true - t.text "text", limit: 65535 - t.string "headline", limit: 255 - t.integer "page_id", limit: 4 + t.integer "index", limit: 4, default: 1 + t.boolean "sidebar" + t.boolean "visible", default: true + t.text "text", limit: 65535 + t.string "headline", limit: 255 + t.integer "page_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "element_type", limit: 255, default: "text", null: false - t.integer "page_image_id", limit: 4 - t.integer "contact_id", limit: 4 + t.string "element_type", limit: 255, default: "text", null: false + t.integer "page_image_id", limit: 4 + t.integer "contact_id", limit: 4 end add_index "page_elements", ["page_id"], name: "index_page_elements_on_page_id", using: :btree create_table "page_images", force: :cascade do |t| - t.integer "page_id", limit: 4 - t.string "image", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "page_id", limit: 4 + t.string "image", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "page_images", ["page_id"], name: "index_page_images_on_page_id", using: :btree create_table "page_translations", force: :cascade do |t| - t.integer "page_id", limit: 4, null: false - t.string "locale", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title", limit: 255, default: "" + t.integer "page_id", limit: 4, null: false + t.string "locale", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title", limit: 255, default: "" end add_index "page_translations", ["locale"], name: "index_page_translations_on_locale", using: :btree @@ -642,129 +641,129 @@ def up create_table "pages", force: :cascade do |t| t.datetime "created_at" t.datetime "updated_at" - t.integer "council_id", limit: 4 - t.string "url", limit: 255 - t.boolean "visible" - t.string "title", limit: 255 - t.boolean "public", default: true, null: false - t.string "namespace", limit: 255 + t.integer "council_id", limit: 4 + t.string "url", limit: 255 + t.boolean "visible" + t.string "title", limit: 255 + t.boolean "public", default: true, null: false + t.string "namespace", limit: 255 end add_index "pages", ["council_id"], name: "index_pages_on_council_id", using: :btree add_index "pages", ["url"], name: "index_pages_on_url", using: :btree create_table "permission_posts", force: :cascade do |t| - t.integer "permission_id", limit: 4 - t.integer "post_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "permission_id", limit: 4 + t.integer "post_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "permissions", force: :cascade do |t| - t.string "name", limit: 255 - t.string "subject_class", limit: 255 - t.string "action", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "name", limit: 255 + t.string "subject_class", limit: 255 + t.string "action", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "post_users", force: :cascade do |t| - t.integer "post_id", limit: 4 - t.integer "user_id", limit: 4 + t.integer "post_id", limit: 4 + t.integer "user_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end create_table "posts", force: :cascade do |t| - t.string "title", limit: 255 - t.integer "limit", limit: 4, default: 0 - t.text "description", limit: 65535 + t.string "title", limit: 255 + t.integer "limit", limit: 4, default: 0 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.integer "council_id", limit: 4 - t.string "elected_by", limit: 255 - t.string "semester", limit: 255, default: "both" - t.boolean "board" - t.integer "rec_limit", limit: 4, default: 0 - t.boolean "car_rent" + t.integer "council_id", limit: 4 + t.string "elected_by", limit: 255 + t.string "semester", limit: 255, default: "both" + t.boolean "board" + t.integer "rec_limit", limit: 4, default: 0 + t.boolean "car_rent" end create_table "rents", force: :cascade do |t| t.datetime "d_from" t.datetime "d_til" - t.text "purpose", limit: 65535 - t.boolean "aktiv", default: true - t.integer "council_id", limit: 4 + t.text "purpose", limit: 65535 + t.boolean "aktiv", default: true + t.integer "council_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.text "comment", limit: 65535 - t.string "status", limit: 255, default: "unconfirmed" - t.boolean "service", default: false - t.integer "user_id", limit: 4 + t.text "comment", limit: 65535 + t.string "status", limit: 255, default: "unconfirmed" + t.boolean "service", default: false + t.integer "user_id", limit: 4 end add_index "rents", ["council_id"], name: "index_rents_on_council_id", using: :btree add_index "rents", ["user_id"], name: "index_rents_on_user_id", using: :btree create_table "short_links", force: :cascade do |t| - t.string "link", limit: 255, null: false - t.text "target", limit: 65535, null: false + t.string "link", limit: 255, null: false + t.text "target", limit: 65535, null: false end add_index "short_links", ["link"], name: "index_short_links_on_link", using: :btree create_table "tool_rentings", force: :cascade do |t| - t.string "renter", limit: 255, null: false - t.string "purpose", limit: 255 - t.integer "tool_id", limit: 4, null: false - t.date "return_date", null: false - t.boolean "returned", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "renter", limit: 255, null: false + t.string "purpose", limit: 255 + t.integer "tool_id", limit: 4, null: false + t.date "return_date", null: false + t.boolean "returned", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "tool_rentings", ["renter"], name: "index_tool_rentings_on_renter", using: :btree add_index "tool_rentings", ["tool_id"], name: "index_tool_rentings_on_tool_id", using: :btree create_table "tools", force: :cascade do |t| - t.string "title", limit: 255, null: false - t.text "description", limit: 65535, null: false - t.integer "total", limit: 4, default: 1 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "title", limit: 255, null: false + t.text "description", limit: 65535, null: false + t.integer "total", limit: 4, default: 1 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "users", force: :cascade do |t| - t.string "email", limit: 255, default: "", null: false - t.string "encrypted_password", limit: 255, default: "", null: false - t.string "reset_password_token", limit: 255 + t.string "email", limit: 255, default: "", null: false + t.string "encrypted_password", limit: 255, default: "", null: false + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", limit: 4, default: 0, null: false + t.integer "sign_in_count", limit: 4, default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "firstname", limit: 255 - t.string "lastname", limit: 255 - t.string "phone", limit: 255 - t.integer "first_post_id", limit: 4 - t.string "avatar_file_name", limit: 255 - t.string "avatar_content_type", limit: 255 - t.integer "avatar_file_size", limit: 4 + t.string "firstname", limit: 255 + t.string "lastname", limit: 255 + t.string "phone", limit: 255 + t.integer "first_post_id", limit: 4 + t.string "avatar_file_name", limit: 255 + t.string "avatar_content_type", limit: 255 + t.integer "avatar_file_size", limit: 4 t.datetime "avatar_updated_at" - t.integer "start_year", limit: 4 - t.string "program", limit: 255 - t.string "confirmation_token", limit: 255 + t.integer "start_year", limit: 4 + t.string "program", limit: 255 + t.string "confirmation_token", limit: 255 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "unconfirmed_email", limit: 255 + t.string "unconfirmed_email", limit: 255 t.datetime "member_at" - t.string "food_preference", limit: 255 - t.string "student_id", limit: 255 - t.boolean "display_phone", default: false, null: false + t.string "food_preference", limit: 255 + t.string "student_id", limit: 255 + t.boolean "display_phone", default: false, null: false end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree @@ -772,20 +771,20 @@ def up add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "work_posts", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.string "company", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.string "company", limit: 255 t.datetime "deadline" - t.string "target_group", limit: 255 - t.boolean "visible", default: true + t.string "target_group", limit: 255 + t.boolean "visible", default: true t.datetime "publish" - t.integer "user_id", limit: 4 + t.integer "user_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "link", limit: 255 - t.string "kind", limit: 255 - t.string "image", limit: 255 - t.string "field", limit: 255 + t.string "link", limit: 255 + t.string "kind", limit: 255 + t.string "image", limit: 255 + t.string "field", limit: 255 end add_index "work_posts", ["field"], name: "index_work_posts_on_field", using: :btree diff --git a/db/migrate/20160904223300_change_event_signup_index.rb b/db/migrate/20160904223300_change_event_signup_index.rb index 0660aa067..6c99c999c 100644 --- a/db/migrate/20160904223300_change_event_signup_index.rb +++ b/db/migrate/20160904223300_change_event_signup_index.rb @@ -1,10 +1,10 @@ class ChangeEventSignupIndex < ActiveRecord::Migration[5.0] def up - remove_index(:event_signups, name: 'event_signups_unique_event_index') + remove_index(:event_signups, name: "event_signups_unique_event_index") end def down add_index(:event_signups, :event_id, unique: true, - name: 'event_signups_unique_event_index') + name: "event_signups_unique_event_index") end end diff --git a/db/migrate/20160922115838_add_use_case_to_category.rb b/db/migrate/20160922115838_add_use_case_to_category.rb index e667d8c9a..9b241af80 100644 --- a/db/migrate/20160922115838_add_use_case_to_category.rb +++ b/db/migrate/20160922115838_add_use_case_to_category.rb @@ -1,5 +1,5 @@ class AddUseCaseToCategory < ActiveRecord::Migration[5.0] def change - add_column(:categories, :use_case, :string, default: 'general', null: :false, index: true) + add_column(:categories, :use_case, :string, default: "general", null: :false, index: true) end end diff --git a/db/migrate/20160923132346_add_translations_to_categories.rb b/db/migrate/20160923132346_add_translations_to_categories.rb index a3e6409ee..193d80016 100644 --- a/db/migrate/20160923132346_add_translations_to_categories.rb +++ b/db/migrate/20160923132346_add_translations_to_categories.rb @@ -3,7 +3,7 @@ def change reversible do |dir| dir.up do Category.create_translation_table!({title: :string}, - {migrate_data: true, remove_source_columns: true}) + {migrate_data: true, remove_source_columns: true}) end dir.down do diff --git a/db/migrate/20160923170248_squasher_clean.rb b/db/migrate/20160923170248_squasher_clean.rb index d5b3aa251..39eb73bc1 100644 --- a/db/migrate/20160923170248_squasher_clean.rb +++ b/db/migrate/20160923170248_squasher_clean.rb @@ -3,7 +3,7 @@ class SchemaMigration < ActiveRecord::Base end def up - migrations = Dir.glob(File.join(File.dirname(__FILE__), '*.rb')) + migrations = Dir.glob(File.join(File.dirname(__FILE__), "*.rb")) versions = migrations.map { |file| File.basename(file)[/\A\d+/] } SchemaMigration.where("version NOT IN (?)", versions).delete_all end diff --git a/db/migrate/20170123191137_add_meetings.rb b/db/migrate/20170123191137_add_meetings.rb index 8688b9a40..4e526d04c 100644 --- a/db/migrate/20170123191137_add_meetings.rb +++ b/db/migrate/20170123191137_add_meetings.rb @@ -3,7 +3,7 @@ def change create_table :meetings do |t| t.datetime :start_date, index: true, null: false t.datetime :end_date, index: true, null: false - t.string :status, default: 'unconfirmed', null: false + t.string :status, default: "unconfirmed", null: false t.string :room, null: false t.string :title, null: false t.text :purpose diff --git a/db/migrate/20170227195000_add_translations_to_election.rb b/db/migrate/20170227195000_add_translations_to_election.rb index 8bb93d080..c82214488 100644 --- a/db/migrate/20170227195000_add_translations_to_election.rb +++ b/db/migrate/20170227195000_add_translations_to_election.rb @@ -2,8 +2,8 @@ class AddTranslationsToElection < ActiveRecord::Migration[5.0] def change reversible do |dir| dir.up do - Election.create_translation_table!({ title: :string, description: :text }, - { migrate_data: true, remove_source_columns: true }) + Election.create_translation_table!({title: :string, description: :text}, + {migrate_data: true, remove_source_columns: true}) end dir.down do diff --git a/db/migrate/20170621104453_add_rpush.rb b/db/migrate/20170621104453_add_rpush.rb index 0bced1e2f..b6a65c4c1 100644 --- a/db/migrate/20170621104453_add_rpush.rb +++ b/db/migrate/20170621104453_add_rpush.rb @@ -22,9 +22,9 @@ class AddRpush < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration def self.migrations [CreateRapnsNotifications, CreateRapnsFeedback, - AddAlertIsJsonToRapnsNotifications, AddAppToRapns, - CreateRapnsApps, AddGcm, AddWpns, AddAdm, RenameRapnsToRpush, - AddFailAfterToRpushNotifications] + AddAlertIsJsonToRapnsNotifications, AddAppToRapns, + CreateRapnsApps, AddGcm, AddWpns, AddAdm, RenameRapnsToRpush, + AddFailAfterToRpushNotifications] end def self.up @@ -32,40 +32,38 @@ def self.up end def self.down - migrations.reverse.each do |m| - begin - m.down - rescue ActiveRecord::StatementInvalid => e - p e - end + migrations.reverse_each do |m| + m.down + rescue ActiveRecord::StatementInvalid => e + p e end end class CreateRapnsNotifications < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration def self.up create_table :rapns_notifications do |t| - t.integer :badge, null: true - t.string :device_token, null: false, limit: 64 - t.string :sound, null: true, default: "1.aiff" - t.string :alert, null: true - t.text :attributes_for_device, null: true - t.integer :expiry, null: false, default: 1.day.to_i - t.boolean :delivered, null: false, default: false - t.timestamp :delivered_at, null: true - t.boolean :failed, null: false, default: false - t.timestamp :failed_at, null: true - t.integer :error_code, null: true - t.string :error_description, null: true - t.timestamp :deliver_after, null: true + t.integer :badge, null: true + t.string :device_token, null: false, limit: 64 + t.string :sound, null: true, default: "1.aiff" + t.string :alert, null: true + t.text :attributes_for_device, null: true + t.integer :expiry, null: false, default: 1.day.to_i + t.boolean :delivered, null: false, default: false + t.timestamp :delivered_at, null: true + t.boolean :failed, null: false, default: false + t.timestamp :failed_at, null: true + t.integer :error_code, null: true + t.string :error_description, null: true + t.timestamp :deliver_after, null: true t.timestamps end - add_index :rapns_notifications, [:delivered, :failed, :deliver_after], name: 'index_rapns_notifications_multi' + add_index :rapns_notifications, [:delivered, :failed, :deliver_after], name: "index_rapns_notifications_multi" end def self.down - if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true) - remove_index :rapns_notifications, name: 'index_rapns_notifications_multi' + if index_name_exists?(:rapns_notifications, "index_rapns_notifications_multi", true) + remove_index :rapns_notifications, name: "index_rapns_notifications_multi" end drop_table :rapns_notifications end @@ -74,8 +72,8 @@ def self.down class CreateRapnsFeedback < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration def self.up create_table :rapns_feedback do |t| - t.string :device_token, null: false, limit: 64 - t.timestamp :failed_at, null: false + t.string :device_token, null: false, limit: 64 + t.timestamp :failed_at, null: false t.timestamps end @@ -115,11 +113,11 @@ def self.down class CreateRapnsApps < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration def self.up create_table :rapns_apps do |t| - t.string :key, null: false - t.string :environment, null: false - t.text :certificate, null: false - t.string :password, null: true - t.integer :connections, null: false, default: 1 + t.string :key, null: false + t.string :environment, null: false + t.text :certificate, null: false + t.string :password, null: true + t.integer :connections, null: false, default: 1 t.timestamps end end @@ -132,12 +130,12 @@ def self.down class AddGcm < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration module Rapns class App < ActiveRecord::Base - self.table_name = 'rapns_apps' + self.table_name = "rapns_apps" end class Notification < ActiveRecord::Base belongs_to :app - self.table_name = 'rapns_notifications' + self.table_name = "rapns_notifications" end end @@ -145,18 +143,18 @@ def self.up add_column :rapns_notifications, :type, :string, null: true add_column :rapns_apps, :type, :string, null: true - AddGcm::Rapns::Notification.update_all type: 'Rapns::Apns::Notification' - AddGcm::Rapns::App.update_all type: 'Rapns::Apns::App' + AddGcm::Rapns::Notification.update_all type: "Rapns::Apns::Notification" + AddGcm::Rapns::App.update_all type: "Rapns::Apns::App" change_column :rapns_notifications, :type, :string, null: false change_column :rapns_apps, :type, :string, null: false - change_column :rapns_notifications, :device_token, :string, { null: true, limit: 64 } - change_column :rapns_notifications, :expiry, :integer, { null: true, default: 1.day.to_i } + change_column :rapns_notifications, :device_token, :string, {null: true, limit: 64} + change_column :rapns_notifications, :expiry, :integer, {null: true, default: 1.day.to_i} change_column :rapns_apps, :environment, :string, null: true change_column :rapns_apps, :certificate, :text, null: true, default: nil change_column :rapns_notifications, :error_description, :text, null: true, default: nil - change_column :rapns_notifications, :sound, :string, default: 'default' + change_column :rapns_notifications, :sound, :string, default: "default" rename_column :rapns_notifications, :attributes_for_device, :data rename_column :rapns_apps, :key, :name @@ -166,7 +164,7 @@ def self.up add_column :rapns_notifications, :collapse_key, :string, null: true add_column :rapns_notifications, :delay_while_idle, :boolean, null: false, default: false - reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?('Mysql') ? :mediumtext : :text + reg_ids_type = ActiveRecord::Base.connection.adapter_name.include?("Mysql") ? :mediumtext : :text add_column :rapns_notifications, :registration_ids, reg_ids_type, null: true add_column :rapns_notifications, :app_id, :integer, null: true add_column :rapns_notifications, :retries, :integer, null: true, default: 0 @@ -190,18 +188,18 @@ def self.up end def self.down - AddGcm::Rapns::Notification.where(type: 'Rapns::Gcm::Notification').delete_all + AddGcm::Rapns::Notification.where(type: "Rapns::Gcm::Notification").delete_all remove_column :rapns_notifications, :type remove_column :rapns_apps, :type - change_column :rapns_notifications, :device_token, :string, { null: false, limit: 64 } - change_column :rapns_notifications, :expiry, :integer, { null: false, default: 1.day.to_i } + change_column :rapns_notifications, :device_token, :string, {null: false, limit: 64} + change_column :rapns_notifications, :expiry, :integer, {null: false, default: 1.day.to_i} change_column :rapns_apps, :environment, :string, null: false change_column :rapns_apps, :certificate, :text, null: false change_column :rapns_notifications, :error_description, :string, null: true, default: nil - change_column :rapns_notifications, :sound, :string, default: '1.aiff' + change_column :rapns_notifications, :sound, :string, default: "1.aiff" rename_column :rapns_notifications, :data, :attributes_for_device rename_column :rapns_apps, :name, :key @@ -223,7 +221,7 @@ def self.down end if index_name_exists?(:rapns_notifications, :index_rapns_notifications_multi, true) - remove_index :rapns_notifications, name: :index_rapns_notifications_multi + remove_index :rapns_notifications, name: :index_rapns_notifications_multi end remove_column :rapns_notifications, :app_id @@ -235,7 +233,7 @@ def self.down class AddWpns < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration module Rapns class Notification < ActiveRecord::Base - self.table_name = 'rapns_notifications' + self.table_name = "rapns_notifications" end end @@ -244,7 +242,7 @@ def self.up end def self.down - AddWpns::Rapns::Notification.where(type: 'Rapns::Wpns::Notification').delete_all + AddWpns::Rapns::Notification.where(type: "Rapns::Wpns::Notification").delete_all remove_column :rapns_notifications, :uri end end @@ -252,7 +250,7 @@ def self.down class AddAdm < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration module Rapns class Notification < ActiveRecord::Base - self.table_name = 'rapns_notifications' + self.table_name = "rapns_notifications" end end @@ -264,7 +262,7 @@ def self.up end def self.down - AddAdm::Rapns::Notification.where(type: 'Rapns::Adm::Notification').delete_all + AddAdm::Rapns::Notification.where(type: "Rapns::Adm::Notification").delete_all remove_column :rapns_apps, :client_id remove_column :rapns_apps, :client_secret @@ -276,11 +274,11 @@ def self.down class RenameRapnsToRpush < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration module Rpush class App < ActiveRecord::Base - self.table_name = 'rpush_apps' + self.table_name = "rpush_apps" end class Notification < ActiveRecord::Base - self.table_name = 'rpush_notifications' + self.table_name = "rpush_notifications" end end @@ -301,27 +299,27 @@ def self.up rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token end - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification') - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Gcm::Notification', 'Rpush::Gcm::Notification') - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Adm::Notification', 'Rpush::Adm::Notification') - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Wpns::Notification', 'Rpush::Wpns::Notification') + update_type(RenameRapnsToRpush::Rpush::Notification, "Rapns::Apns::Notification", "Rpush::Apns::Notification") + update_type(RenameRapnsToRpush::Rpush::Notification, "Rapns::Gcm::Notification", "Rpush::Gcm::Notification") + update_type(RenameRapnsToRpush::Rpush::Notification, "Rapns::Adm::Notification", "Rpush::Adm::Notification") + update_type(RenameRapnsToRpush::Rpush::Notification, "Rapns::Wpns::Notification", "Rpush::Wpns::Notification") - update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Apns::App', 'Rpush::Apns::App') - update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Gcm::App', 'Rpush::Gcm::App') - update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Adm::App', 'Rpush::Adm::App') - update_type(RenameRapnsToRpush::Rpush::App, 'Rapns::Wpns::App', 'Rpush::Wpns::App') + update_type(RenameRapnsToRpush::Rpush::App, "Rapns::Apns::App", "Rpush::Apns::App") + update_type(RenameRapnsToRpush::Rpush::App, "Rapns::Gcm::App", "Rpush::Gcm::App") + update_type(RenameRapnsToRpush::Rpush::App, "Rapns::Adm::App", "Rpush::Adm::App") + update_type(RenameRapnsToRpush::Rpush::App, "Rapns::Wpns::App", "Rpush::Wpns::App") end def self.down - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Apns::Notification', 'Rapns::Apns::Notification') - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Gcm::Notification', 'Rapns::Gcm::Notification') - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Adm::Notification', 'Rapns::Adm::Notification') - update_type(RenameRapnsToRpush::Rpush::Notification, 'Rpush::Wpns::Notification', 'Rapns::Wpns::Notification') - - update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Apns::App', 'Rapns::Apns::App') - update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Gcm::App', 'Rapns::Gcm::App') - update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App') - update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App') + update_type(RenameRapnsToRpush::Rpush::Notification, "Rpush::Apns::Notification", "Rapns::Apns::Notification") + update_type(RenameRapnsToRpush::Rpush::Notification, "Rpush::Gcm::Notification", "Rapns::Gcm::Notification") + update_type(RenameRapnsToRpush::Rpush::Notification, "Rpush::Adm::Notification", "Rapns::Adm::Notification") + update_type(RenameRapnsToRpush::Rpush::Notification, "Rpush::Wpns::Notification", "Rapns::Wpns::Notification") + + update_type(RenameRapnsToRpush::Rpush::App, "Rpush::Apns::App", "Rapns::Apns::App") + update_type(RenameRapnsToRpush::Rpush::App, "Rpush::Gcm::App", "Rapns::Gcm::App") + update_type(RenameRapnsToRpush::Rpush::App, "Rpush::Adm::App", "Rapns::Adm::App") + update_type(RenameRapnsToRpush::Rpush::App, "Rpush::Wpns::App", "Rapns::Wpns::App") if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true) rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi diff --git a/db/migrate/20170621104454_rpush_2_0_0_updates.rb b/db/migrate/20170621104454_rpush_2_0_0_updates.rb index 9e1b5cda0..2fcb643fa 100644 --- a/db/migrate/20170621104454_rpush_2_0_0_updates.rb +++ b/db/migrate/20170621104454_rpush_2_0_0_updates.rb @@ -1,11 +1,11 @@ class Rpush200Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration module Rpush class App < ActiveRecord::Base - self.table_name = 'rpush_apps' + self.table_name = "rpush_apps" end class Notification < ActiveRecord::Base - self.table_name = 'rpush_notifications' + self.table_name = "rpush_notifications" end end @@ -21,12 +21,12 @@ def self.up remove_index :rpush_notifications, name: :index_rpush_notifications_multi end - add_index :rpush_notifications, [:delivered, :failed], name: 'index_rpush_notifications_multi', where: 'NOT delivered AND NOT failed' + add_index :rpush_notifications, [:delivered, :failed], name: "index_rpush_notifications_multi", where: "NOT delivered AND NOT failed" rename_column :rpush_feedback, :app, :app_id if postgresql? - execute('ALTER TABLE rpush_feedback ALTER COLUMN app_id TYPE integer USING (trim(app_id)::integer)') + execute("ALTER TABLE rpush_feedback ALTER COLUMN app_id TYPE integer USING (trim(app_id)::integer)") else change_column :rpush_feedback, :app_id, :integer end @@ -50,15 +50,15 @@ def self.down remove_index :rpush_notifications, name: :index_rpush_notifications_multi end - add_index :rpush_notifications, [:app_id, :delivered, :failed, :deliver_after], name: 'index_rpush_notifications_multi' + add_index :rpush_notifications, [:app_id, :delivered, :failed, :deliver_after], name: "index_rpush_notifications_multi" remove_column :rpush_notifications, :priority remove_column :rpush_notifications, :processing end def self.adapter_name - env = (defined?(Rails) && Rails.env) ? Rails.env : 'development' - Hash[ActiveRecord::Base.configurations[env].map { |k,v| [k.to_sym,v] }][:adapter] + env = defined?(Rails) && Rails.env ? Rails.env : "development" + ActiveRecord::Base.configurations[env].map { |k, v| [k.to_sym, v] }.to_h[:adapter] end def self.postgresql? diff --git a/db/migrate/20170621104456_rpush_2_6_0_updates.rb b/db/migrate/20170621104456_rpush_2_6_0_updates.rb index e21ee0618..35371463a 100644 --- a/db/migrate/20170621104456_rpush_2_6_0_updates.rb +++ b/db/migrate/20170621104456_rpush_2_6_0_updates.rb @@ -7,4 +7,3 @@ def self.down remove_column :rpush_notifications, :content_available end end - diff --git a/db/migrate/20170621104457_rpush_2_7_0_updates.rb b/db/migrate/20170621104457_rpush_2_7_0_updates.rb index 93ec65d0e..68bd844f4 100644 --- a/db/migrate/20170621104457_rpush_2_7_0_updates.rb +++ b/db/migrate/20170621104457_rpush_2_7_0_updates.rb @@ -9,4 +9,3 @@ def self.down remove_column :rpush_notifications, :notification end end - diff --git a/db/migrate/20170823124500_add_translations_to_post.rb b/db/migrate/20170823124500_add_translations_to_post.rb index e2ef1ed36..eca98ebc4 100644 --- a/db/migrate/20170823124500_add_translations_to_post.rb +++ b/db/migrate/20170823124500_add_translations_to_post.rb @@ -3,7 +3,7 @@ def change reversible do |dir| dir.up do Post.create_translation_table!({title: :string, description: :text}, - {migrate_data: true, remove_source_columns: true}) + {migrate_data: true, remove_source_columns: true}) end dir.down do diff --git a/db/migrate/20170823132130_add_translations_to_council.rb b/db/migrate/20170823132130_add_translations_to_council.rb index 6880b7c94..1c3541055 100644 --- a/db/migrate/20170823132130_add_translations_to_council.rb +++ b/db/migrate/20170823132130_add_translations_to_council.rb @@ -3,7 +3,7 @@ def change reversible do |dir| dir.up do Council.create_translation_table!({title: :string}, - {migrate_data: true, remove_source_columns: true}) + {migrate_data: true, remove_source_columns: true}) end dir.down do diff --git a/db/migrate/20180220003700_migrate_cafe.rb b/db/migrate/20180220003700_migrate_cafe.rb index 000b2ea6a..7db2b5d70 100644 --- a/db/migrate/20180220003700_migrate_cafe.rb +++ b/db/migrate/20180220003700_migrate_cafe.rb @@ -6,7 +6,7 @@ def up # # NOTE! We can not reverse this change!! CafeShift.where(pass: 2).update_all(pass: 1) - CafeShift.where('pass = ? OR pass = ?', 3, 4).update_all(pass: 2) + CafeShift.where("pass = ? OR pass = ?", 3, 4).update_all(pass: 2) end def down diff --git a/db/migrate/20180402140721_rpush_3_0_0_updates.rb b/db/migrate/20180402140721_rpush_3_0_0_updates.rb index f790f0592..f9b020897 100644 --- a/db/migrate/20180402140721_rpush_3_0_0_updates.rb +++ b/db/migrate/20180402140721_rpush_3_0_0_updates.rb @@ -6,6 +6,6 @@ def self.up def self.down remove_column :rpush_notifications, :mutable_content - change_column :rpush_notifications, :sound, :string, default: 'default' + change_column :rpush_notifications, :sound, :string, default: "default" end end diff --git a/db/migrate/20180815132130_add_translations_to_adventure_missions.rb b/db/migrate/20180815132130_add_translations_to_adventure_missions.rb index 4d137b127..5d01ffae0 100644 --- a/db/migrate/20180815132130_add_translations_to_adventure_missions.rb +++ b/db/migrate/20180815132130_add_translations_to_adventure_missions.rb @@ -3,7 +3,7 @@ def change reversible do |dir| dir.up do AdventureMission.create_translation_table!({title: :string, description: :text}, - {migrate_data: true, remove_source_columns: true}) + {migrate_data: true, remove_source_columns: true}) end dir.down do diff --git a/db/migrate/20180829074900_add_unique_constraint_to_adventure_mission_groups.rb b/db/migrate/20180829074900_add_unique_constraint_to_adventure_mission_groups.rb index 19b73ba66..c3ab05505 100644 --- a/db/migrate/20180829074900_add_unique_constraint_to_adventure_mission_groups.rb +++ b/db/migrate/20180829074900_add_unique_constraint_to_adventure_mission_groups.rb @@ -1,9 +1,9 @@ class AddUniqueConstraintToAdventureMissionGroups < ActiveRecord::Migration[5.0] def change add_index :adventure_mission_groups, - [:adventure_mission_id, :group_id], - unique: true, - # The auto generated name is too long, so we must choose one manually... - name: 'index_adv_mission_groups_on_adm_mission_and_group' + [:adventure_mission_id, :group_id], + unique: true, + # The auto generated name is too long, so we must choose one manually... + name: "index_adv_mission_groups_on_adm_mission_and_group" end end diff --git a/db/migrate/20190821201800_swap_song_category_to_association.rb b/db/migrate/20190821201800_swap_song_category_to_association.rb index 63c991057..89920dc06 100644 --- a/db/migrate/20190821201800_swap_song_category_to_association.rb +++ b/db/migrate/20190821201800_swap_song_category_to_association.rb @@ -4,16 +4,16 @@ def up if Song.count > 0 if SongCategory.count == 0 - SongCategory.create(name: 'Annan') + SongCategory.create(name: "Annan") end - + Song.all.each do |s| if s.song_category.nil? s.update(song_category: SongCategory.first) end end end - + change_column_null :songs, :song_category_id, false remove_column(:songs, :category) end diff --git a/db/seeds.rb b/db/seeds.rb index 08c494dbe..4266f355a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,82 +1,82 @@ # Main Menus guild = MainMenu.create!(index: 10, mega: true, fw: true, - name_sv: 'Sektionen', name_en: 'The Guild') + name_sv: "Sektionen", name_en: "The Guild") members = MainMenu.create!(index: 20, mega: true, fw: false, - name_sv: 'För medlemmar', name_en: 'For Members') + name_sv: "För medlemmar", name_en: "For Members") nollning = MainMenu.create!(index: 30, mega: false, fw: false, - name_sv: 'Nollning', name_en: 'Nollning') + name_sv: "Nollning", name_en: "Nollning") # Guild Menu Menu.create!(main_menu: guild, column: 1, index: 10, header: true, - name_sv: 'Allmänt', name_en: 'General', link: '#') + name_sv: "Allmänt", name_en: "General", link: "#") Menu.create!(main_menu: guild, column: 1, index: 20, - name_sv: 'Om oss', name_en: 'About us', link: '/om') + name_sv: "Om oss", name_en: "About us", link: "/om") Menu.create!(main_menu: guild, column: 1, index: 30, - name_sv: 'Utskott', name_en: 'Committees', link: '/utskott') + name_sv: "Utskott", name_en: "Committees", link: "/utskott") Menu.create!(main_menu: guild, column: 1, index: 40, - name_sv: 'Dokument', name_en: 'Documents', link: '/dokument') + name_sv: "Dokument", name_en: "Documents", link: "/dokument") Menu.create!(main_menu: guild, column: 1, index: 50, - name_sv: 'Blogg', name_en: 'Blog', link: '/blogg') + name_sv: "Blogg", name_en: "Blog", link: "/blogg") Menu.create!(main_menu: guild, column: 2, index: 10, header: true, - name_sv: 'För företag', name_en: 'For Companies', link: '#') + name_sv: "För företag", name_en: "For Companies", link: "#") Menu.create!(main_menu: guild, column: 2, index: 20, - name_sv: 'Om F-Sektionen', name_en: 'About F-Sektionen', link: '/foretag/om') + name_sv: "Om F-Sektionen", name_en: "About F-Sektionen", link: "/foretag/om") Menu.create!(main_menu: guild, column: 2, index: 30, - name_sv: 'Vi erbjuder', name_en: 'We Offer', link: '/foretag/vi-erbjuder') + name_sv: "Vi erbjuder", name_en: "We Offer", link: "/foretag/vi-erbjuder") Menu.create!(main_menu: guild, column: 2, index: 40, - name_sv: 'Kontakt', name_en: 'Contact', link: '/kontakter/4') + name_sv: "Kontakt", name_en: "Contact", link: "/kontakter/4") Menu.create!(main_menu: guild, column: 2, index: 40, blank_p: true, - name_sv: 'Farad', name_en: 'Farad', link: 'http://farad.nu') + name_sv: "Farad", name_en: "Farad", link: "http://farad.nu") Menu.create!(main_menu: guild, column: 3, index: 10, header: true, - name_sv: 'Kontakt', name_en: 'Contact', link: '#') + name_sv: "Kontakt", name_en: "Contact", link: "#") Menu.create!(main_menu: guild, column: 3, index: 20, - name_sv: 'Kontaktsida', name_en: 'Contact Page', link: '/kontakter') + name_sv: "Kontaktsida", name_en: "Contact Page", link: "/kontakter") Menu.create!(main_menu: guild, column: 3, index: 30, - name_sv: 'Ordförande', name_en: 'Chairman', link: '/kontakter/19') + name_sv: "Ordförande", name_en: "Chairman", link: "/kontakter/19") Menu.create!(main_menu: guild, column: 3, index: 40, - name_sv: 'Webbansvarig', name_en: 'Webmaster', link: '/kontakter/1') + name_sv: "Webbansvarig", name_en: "Webmaster", link: "/kontakter/1") Menu.create!(main_menu: guild, column: 4, index: 10, header: true, - name_sv: 'Feedback', name_en: 'Feedback', link: '#') + name_sv: "Feedback", name_en: "Feedback", link: "#") Menu.create!(main_menu: guild, column: 4, index: 20, blank_p: true, - name_sv: 'Tyck till', name_en: 'Leave Feedback', - link: 'https://fsektionen.typeform.com/to/a9Mmq9') + name_sv: "Tyck till", name_en: "Leave Feedback", + link: "https://fsektionen.typeform.com/to/a9Mmq9") Menu.create!(main_menu: guild, column: 4, index: 30, blank_p: true, - name_sv: 'Felrapport', name_en: 'Report a Bug', - link: 'https://davidwesmn.typeform.com/to/WiWWNn') + name_sv: "Felrapport", name_en: "Report a Bug", + link: "https://davidwesmn.typeform.com/to/WiWWNn") # Members menu Menu.create!(main_menu: members, column: 1, index: 10, header: true, - name_sv: 'Engagera dig', name_en: 'Get engaged', link: '#') + name_sv: "Engagera dig", name_en: "Get engaged", link: "#") Menu.create!(main_menu: members, column: 1, index: 20, - name_sv: 'Val', name_en: 'Election', link: '/val') + name_sv: "Val", name_en: "Election", link: "/val") Menu.create!(main_menu: members, column: 1, index: 30, - name_sv: 'Hilbert Café', name_en: 'Hilbert Café', link: '/hilbertcafe') + name_sv: "Hilbert Café", name_en: "Hilbert Café", link: "/hilbertcafe") Menu.create!(main_menu: members, column: 1, index: 40, - name_sv: 'Motionsmaskin', name_en: 'Motion Generator', link: '/proposals/form') + name_sv: "Motionsmaskin", name_en: "Motion Generator", link: "/proposals/form") Menu.create!(main_menu: members, column: 2, index: 10, header: true, - name_sv: 'Tjänster', name_en: 'Services', link: '#') + name_sv: "Tjänster", name_en: "Services", link: "#") Menu.create!(main_menu: members, column: 2, index: 20, - name_sv: 'Bildgalleri', name_en: 'Picture Gallery', link: '/galleri') + name_sv: "Bildgalleri", name_en: "Picture Gallery", link: "/galleri") Menu.create!(main_menu: members, column: 2, index: 30, - name_sv: 'Bilbokning', name_en: 'Car Rental', link: '/bilbokning') + name_sv: "Bilbokning", name_en: "Car Rental", link: "/bilbokning") Menu.create!(main_menu: members, column: 2, index: 40, - name_sv: 'Verktyg', name_en: 'Tools', link: '/verktyg') + name_sv: "Verktyg", name_en: "Tools", link: "/verktyg") Menu.create!(main_menu: members, column: 2, index: 50, - name_sv: 'Sångbok', name_en: 'Song Book', link: '/sangbok') + name_sv: "Sångbok", name_en: "Song Book", link: "/sangbok") Menu.create!(main_menu: members, column: 3, index: 10, header: true, - name_sv: 'Övrigt', name_en: 'Other', link: '#') + name_sv: "Övrigt", name_en: "Other", link: "#") Menu.create!(main_menu: members, column: 3, index: 20, - name_sv: 'Kalender', name_en: 'Calendar', link: '/kalender') + name_sv: "Kalender", name_en: "Calendar", link: "/kalender") Menu.create!(main_menu: members, column: 3, index: 30, - name_sv: 'Likabehandling', name_en: 'Student Equality', link: '/utskott/libu') + name_sv: "Likabehandling", name_en: "Student Equality", link: "/utskott/libu") Menu.create!(main_menu: members, column: 3, index: 40, - name_sv: 'Lokalbokning', name_en: 'Facility Reservations', link: '/lokalbokning') + name_sv: "Lokalbokning", name_en: "Facility Reservations", link: "/lokalbokning") # Nollning menu -Menu.create!(main_menu: nollning, index: 10, name_sv: 'Nollning 2016', - name_en: 'Nollning 2016', link: '/nollning') +Menu.create!(main_menu: nollning, index: 10, name_sv: "Nollning 2016", + name_en: "Nollning 2016", link: "/nollning") diff --git a/lib/constraints/sidekiq.rb b/lib/constraints/sidekiq.rb index a3cbaf2d2..235b494b5 100644 --- a/lib/constraints/sidekiq.rb +++ b/lib/constraints/sidekiq.rb @@ -1,7 +1,7 @@ module Constraints class Sidekiq def matches?(request) - user = request.env['warden'].user + user = request.env["warden"].user return false if user.blank? AdminAbility.new(user).can?(:manage, Sidekiq) end diff --git a/lib/route_prefixes.rb b/lib/route_prefixes.rb index ec25c28fb..f69371336 100644 --- a/lib/route_prefixes.rb +++ b/lib/route_prefixes.rb @@ -3,9 +3,9 @@ module RoutePrefixes # basically the set of urls that are reserved by the application # # i.e. [ 'assets', 'news' ] etc. - - PREFIXES = - Rails.application.routes.routes.map do |r| - r.path.spec.to_s.split('(').first.split('/').second + + PREFIXES = + Rails.application.routes.routes.map do |r| + r.path.spec.to_s.split("(").first.split("/").second end.select(&:itself).to_set end diff --git a/lib/tasks/event_signup_data.rake b/lib/tasks/event_signup_data.rake index 7fc98a53b..f62013cf3 100644 --- a/lib/tasks/event_signup_data.rake +++ b/lib/tasks/event_signup_data.rake @@ -1,31 +1,31 @@ namespace :event do - desc 'Loads some stuff into the database for local testing' + desc "Loads some stuff into the database for local testing" task(signup: :environment) do - introduction = Introduction.find_or_create_by!(title: 'En Ridderlig Nollning', - start: Time.zone.now.change(month: 8, day: 22).beginning_of_day, - stop: Time.zone.now.change(month: 9, day: 20).end_of_day, - slug: :ridderlig, current: true) - bk = Group.find_or_create_by!(group_type: Group::REGULAR, name: 'Black Knight', number: 1, introduction: introduction) - dk = Group.find_or_create_by!(group_type: Group::REGULAR, name: 'Dark Knights', number: 2, introduction: introduction) - ok = Group.find_or_create_by!(group_type: Group::REGULAR, name: 'Ordförande Knight', number: 3, introduction: introduction) + introduction = Introduction.find_or_create_by!(title: "En Ridderlig Nollning", + start: Time.zone.now.change(month: 8, day: 22).beginning_of_day, + stop: Time.zone.now.change(month: 9, day: 20).end_of_day, + slug: :ridderlig, current: true) + bk = Group.find_or_create_by!(group_type: Group::REGULAR, name: "Black Knight", number: 1, introduction: introduction) + dk = Group.find_or_create_by!(group_type: Group::REGULAR, name: "Dark Knights", number: 2, introduction: introduction) + ok = Group.find_or_create_by!(group_type: Group::REGULAR, name: "Ordförande Knight", number: 3, introduction: introduction) - fadder_bk = create_user('Fadder-BK') - nolla_bk = create_user('Nolla-1-BK') - nolla2_bk = create_user('Nolla-2-BK') + fadder_bk = create_user("Fadder-BK") + nolla_bk = create_user("Nolla-1-BK") + nolla2_bk = create_user("Nolla-2-BK") add_to_group(bk, fadder_bk, fadder: true) add_to_group(bk, nolla_bk) add_to_group(bk, nolla2_bk) - fadder_dk = create_user('Fadder-DK') - nolla_dk = create_user('Nolla-1-DK') - nolla2_dk = create_user('Nolla-2-DK') + fadder_dk = create_user("Fadder-DK") + nolla_dk = create_user("Nolla-1-DK") + nolla2_dk = create_user("Nolla-2-DK") add_to_group(dk, fadder_dk, fadder: true) add_to_group(dk, nolla_dk) add_to_group(dk, nolla2_dk) - fadder_ok = create_user('Fadder-OK') - nolla_ok = create_user('Nolla-1-OK') - nolla2_ok = create_user('Nolla-2-OK') + fadder_ok = create_user("Fadder-OK") + nolla_ok = create_user("Nolla-1-OK") + nolla2_ok = create_user("Nolla-2-OK") add_to_group(ok, fadder_ok, fadder: true) add_to_group(ok, nolla_ok) add_to_group(ok, nolla2_ok) @@ -33,10 +33,10 @@ namespace :event do def create_user(firstname) user = User.find_or_initialize_by(email: "#{firstname}@fsektionen.se", - firstname: firstname, lastname: 'Älg', - program: 'Teknisk Fysik', start_year: 1996) - user.food_preference = ['Mjölkprotein', 'Vegetarian', 'Pesketarian'].sample - user.password = 'passpass' + firstname: firstname, lastname: "Älg", + program: "Teknisk Fysik", start_year: 1996) + user.food_preference = ["Mjölkprotein", "Vegetarian", "Pesketarian"].sample + user.password = "passpass" user.confirmed_at = Time.zone.now user.member_at = Time.zone.now user.save! diff --git a/lib/tasks/introduction_events.rake b/lib/tasks/introduction_events.rake index 1ed923c25..12943fcb5 100644 --- a/lib/tasks/introduction_events.rake +++ b/lib/tasks/introduction_events.rake @@ -1,10 +1,10 @@ -namespace 'event' do - require 'csv' +namespace "event" do + require "csv" - desc('Import events for Introduction through csv') + desc("Import events for Introduction through csv") task(introduction: :environment) do - file = File.join(Rails.root, 'lib', 'assets', 'introduction_events.csv') - unless File.exists?(file) + file = File.join(Rails.root, "lib", "assets", "introduction_events.csv") + unless File.exist?(file) puts "No CSV-file found, place it in #{file}" return end @@ -15,17 +15,17 @@ namespace 'event' do CSV.foreach(file, headers: true) do |row| event_hash = row.to_hash - starts_at = Time.zone.parse(event_hash['starts_at']) - ends_at = Time.zone.parse(event_hash['ends_at']) + starts_at = Time.zone.parse(event_hash["starts_at"]) + ends_at = Time.zone.parse(event_hash["ends_at"]) event = Event.translations.slug(:nollning).find_or_initialize_by(starts_at: starts_at, ends_at: ends_at) - unless event.update(event_hash) - puts "#{event_hash[:title]} could not be saved because: #{event.errors.to_h.to_s}" - puts "------------------" - else + if event.update(event_hash) event.categories << Category.find_by(slug: :nollning) unless event.categories.include?(category) event.save! updated_count += 1 + else + puts "#{event_hash[:title]} could not be saved because: #{event.errors.to_h}" + puts "------------------" end end event_count = Event.count - event_count diff --git a/lib/tasks/permissions.rake b/lib/tasks/permissions.rake index ddc17dc7b..f3af11679 100644 --- a/lib/tasks/permissions.rake +++ b/lib/tasks/permissions.rake @@ -1,34 +1,34 @@ -namespace 'permissions' do - desc 'Loading all models and their related controller methods inpermissions table.' - task(:load => :environment) do - avoid_methods = ['can_administrate?', 'authorize_admin!', - 'load_permissions', 'model_name', - 'alert_create', 'alert_update', - 'alert_destroy', 'current_admin_ability'] +namespace "permissions" do + desc "Loading all models and their related controller methods inpermissions table." + task(load: :environment) do + avoid_methods = ["can_administrate?", "authorize_admin!", + "load_permissions", "model_name", + "alert_create", "alert_update", + "alert_destroy", "current_admin_ability"] arr = [] - #load all the controllers + # load all the controllers controllers = Dir.new("#{Rails.root}/app/controllers").entries controllers.each do |entry| - if entry =~ /_controller/ && entry != 'application_controller.rb' - #check if the controller is valid - arr << entry.camelize.gsub('.rb', '').constantize - elsif entry =~ /^[a-z]*$/ #namescoped controllers + if entry =~ /_controller/ && entry != "application_controller.rb" + # check if the controller is valid + arr << entry.camelize.gsub(".rb", "").constantize + elsif /^[a-z]*$/.match?(entry) # namescoped controllers Dir.new("#{Rails.root}/app/controllers/#{entry}").entries.each do |x| - if x =~ /_controller/ && entry != 'application_controller.rb' - arr << "#{entry.titleize}::#{x.camelize.gsub('.rb', '')}".constantize + if x =~ /_controller/ && entry != "application_controller.rb" + arr << "#{entry.titleize}::#{x.camelize.gsub(".rb", "")}".constantize end end end end arr.each do |controller| - #only that controller which represents a model + # only that controller which represents a model if controller.permission puts "Permissions for: #{controller.permission}" - #create a universal permission for that model. eg 'manage User' will allow all actions on User model. - write_permission(controller.permission, 'manage') #add permission to do CRUD for every model. + # create a universal permission for that model. eg 'manage User' will allow all actions on User model. + write_permission(controller.permission, "manage") # add permission to do CRUD for every model. controller.action_methods.each do |method| - if !avoid_methods.include?(method) && method =~ /^([A-Za-z\d*]+)+([\w]*)+([A-Za-z\d*]+)$/ #add_user, add_user_info, Add_user, add_User + if !avoid_methods.include?(method) && method =~ /^([A-Za-z\d*]+)+(\w*)+([A-Za-z\d*]+)$/ # add_user, add_user_info, Add_user, add_User _, cancan_action = eval_cancan_action(method) write_permission(controller.permission, cancan_action) end @@ -38,38 +38,38 @@ namespace 'permissions' do end end -#this method returns the cancan action for the action passed. +# this method returns the cancan action for the action passed. def eval_cancan_action(action) case action.to_s - when 'index' - name = 'list' - cancan_action = 'index' #let the cancan action be the actual method name + when "index" + name = "list" + cancan_action = "index" # let the cancan action be the actual method name action_desc = I18n.t(:list) - when 'new', 'create' - name = 'create and update' - cancan_action = 'create' + when "new", "create" + name = "create and update" + cancan_action = "create" action_desc = I18n.t :create - when 'show' - name = 'view' - cancan_action = 'view' + when "show" + name = "view" + cancan_action = "view" action_desc = I18n.t :view - when 'edit', 'update' - name = 'create and update' - cancan_action = 'update' + when "edit", "update" + name = "create and update" + cancan_action = "update" action_desc = I18n.t :update - when 'delete', 'destroy' - name = 'delete' - cancan_action = 'destroy' + when "delete", "destroy" + name = "delete" + cancan_action = "destroy" action_desc = I18n.t :destroy else name = action.to_s cancan_action = action.to_s - action_desc = 'Other: ' < cancan_action + action_desc = "Other: " < cancan_action end - return name, cancan_action + [name, cancan_action] end -#check if the permission is present else add a new one. +# check if the permission is present else add a new one. def write_permission(model, cancan_action) Permission.find_or_create_by(subject_class: model, action: cancan_action) end diff --git a/lib/tasks/promote_admin.rake b/lib/tasks/promote_admin.rake index c830db32a..626b621f5 100644 --- a/lib/tasks/promote_admin.rake +++ b/lib/tasks/promote_admin.rake @@ -1,12 +1,12 @@ -task :promote_admin => :environment do +task promote_admin: :environment do perm = Permission.find_or_create_by!(subject_class: :all, action: :manage) - council = Council.find_or_create_by!(title: 'Prylmästeriet', url: 'pryl') - post = Post.find_or_create_by!(title: 'Admin', - description: 'Administratör', - council: council, - limit: 3, - rec_limit: 0, - elected_by: Post::BOARD) + council = Council.find_or_create_by!(title: "Prylmästeriet", url: "pryl") + post = Post.find_or_create_by!(title: "Admin", + description: "Administratör", + council: council, + limit: 3, + rec_limit: 0, + elected_by: Post::BOARD) PermissionPost.find_or_create_by!(permission: perm, post: post) u = User.first u.posts << post diff --git a/lib/tasks/tests_data.rake b/lib/tasks/tests_data.rake index 631de536d..d24e3dd82 100644 --- a/lib/tasks/tests_data.rake +++ b/lib/tasks/tests_data.rake @@ -1,39 +1,39 @@ namespace :db do - desc 'Loads some stuff into the database for local testing' + desc "Loads some stuff into the database for local testing" task(populate_test: :environment) do # Councils - pryl = Council.find_or_create_by!(title: 'Prylmästeriet', - url: 'pryl', description: 'Detta är Prylmästeriet') + pryl = Council.find_or_create_by!(title: "Prylmästeriet", + url: "pryl", description: "Detta är Prylmästeriet") - sexm = Council.find_or_create_by!(title: 'Sexmästeriet', - url: 'sex', description: 'Detta är Sexmästeriet') - cafem = Council.find_or_create_by!(title: 'Cafemästeriet', - url: 'cafe', description: 'Detta är Cafemästeriet') + sexm = Council.find_or_create_by!(title: "Sexmästeriet", + url: "sex", description: "Detta är Sexmästeriet") + cafem = Council.find_or_create_by!(title: "Cafemästeriet", + url: "cafe", description: "Detta är Cafemästeriet") # Posts # Prylmästeriet - spindel = Post.find_or_create_by!(title: 'Spindelman', limit: 0, rec_limit: 10, description: 'En administratör', - council: pryl, elected_by: Post::BOARD, semester: Post::SPRING, car_rent: true) + spindel = Post.find_or_create_by!(title: "Spindelman", limit: 0, rec_limit: 10, description: "En administratör", + council: pryl, elected_by: Post::BOARD, semester: Post::SPRING, car_rent: true) - prylmast = Post.find_or_create_by!(title: 'Prylmästare', limit: 1, rec_limit: 1, - description: 'Prylmästarn', council: pryl, elected_by: Post::GENERAL, - board: true, semester: Post::SPRING, car_rent: true) + prylmast = Post.find_or_create_by!(title: "Prylmästare", limit: 1, rec_limit: 1, + description: "Prylmästarn", council: pryl, elected_by: Post::GENERAL, + board: true, semester: Post::SPRING, car_rent: true) # Sexmästeriet - sexmast = Post.find_or_create_by!(title: 'Sexmästare', limit: 1, rec_limit: 1, - description: 'Sexmästaren', council: sexm, elected_by: Post::GENERAL, - board: true, semester: Post::SPRING, car_rent: true) + sexmast = Post.find_or_create_by!(title: "Sexmästare", limit: 1, rec_limit: 1, + description: "Sexmästaren", council: sexm, elected_by: Post::GENERAL, + board: true, semester: Post::SPRING, car_rent: true) # Cafemästeriet - Post.find_or_create_by!(title: 'Vice cafemästare', limit: 1, rec_limit: 1, description: 'En vice cm', - council: cafem, elected_by: Post::GENERAL, - board: true, semester: Post::AUTUMN, car_rent: true) + Post.find_or_create_by!(title: "Vice cafemästare", limit: 1, rec_limit: 1, description: "En vice cm", + council: cafem, elected_by: Post::GENERAL, + board: true, semester: Post::AUTUMN, car_rent: true) - cafemast = Post.find_or_create_by!(title: 'Cafemästare', limit: 1, rec_limit: 1, - description: 'Cafemästaren', council: cafem, elected_by: Post::GENERAL, - board: true, semester: Post::AUTUMN, car_rent: true) + cafemast = Post.find_or_create_by!(title: "Cafemästare", limit: 1, rec_limit: 1, + description: "Cafemästaren", council: cafem, elected_by: Post::GENERAL, + board: true, semester: Post::AUTUMN, car_rent: true) - nyckelpiga = Post.find_or_create_by!(title: 'Nyckelpiga', limit: 0, rec_limit: 10, - description: 'Nyckelpigan!', council: cafem, elected_by: Post::BOARD, semester: Post::BOTH) + nyckelpiga = Post.find_or_create_by!(title: "Nyckelpiga", limit: 0, rec_limit: 10, + description: "Nyckelpigan!", council: cafem, elected_by: Post::BOARD, semester: Post::BOTH) # Set president! pryl.update(president: prylmast) @@ -41,24 +41,24 @@ namespace :db do cafem.update(president: cafemast) # Permissions - Rake::Task['permissions:load'].invoke + Rake::Task["permissions:load"].invoke perm_admin = Permission.find_or_create_by!(subject_class: :all, action: :manage) - perm_nyckelpiga = Permission.find_or_create_by!(subject_class: 'CafeWork', action: :nyckelpiga) + perm_nyckelpiga = Permission.find_or_create_by!(subject_class: "CafeWork", action: :nyckelpiga) # Give spindelman admin PermissionPost.find_or_create_by!(permission: perm_admin, post: spindel) PermissionPost.find_or_create_by!(permission: perm_nyckelpiga, post: nyckelpiga) - admin = User.find_or_initialize_by(email: 'admin@fsektionen.se', - firstname: 'Hilbert-Admin', lastname: 'Älg', - program: 'Teknisk Fysik', start_year: 1996) - admin.password = 'passpass' - admin.password_confirmation = 'passpass' + admin = User.find_or_initialize_by(email: "admin@fsektionen.se", + firstname: "Hilbert-Admin", lastname: "Älg", + program: "Teknisk Fysik", start_year: 1996) + admin.password = "passpass" + admin.password_confirmation = "passpass" admin.confirmed_at = Time.zone.now admin.member_at = Time.zone.now admin.save! - puts 'You can sign in as ADMIN with' - puts 'email: admin@fsektionen.se' - puts 'and password: passpass' + puts "You can sign in as ADMIN with" + puts "email: admin@fsektionen.se" + puts "and password: passpass" if admin.present? PostUser.find_or_create_by(post: spindel, user: admin) PostUser.find_or_create_by(post: prylmast, user: admin) @@ -66,112 +66,112 @@ namespace :db do PostUser.find_or_create_by(post: sexmast, user: admin) end - user = User.find_or_initialize_by(email: 'user@fsektionen.se', - firstname: 'Hilbert', lastname: 'Älg', - program: 'Teknisk Fysik', start_year: 1996) + user = User.find_or_initialize_by(email: "user@fsektionen.se", + firstname: "Hilbert", lastname: "Älg", + program: "Teknisk Fysik", start_year: 1996) user.confirmed_at = Time.zone.now user.member_at = Time.zone.now - user.password = 'passpass' - user.password_confirmation = 'passpass' + user.password = "passpass" + user.password_confirmation = "passpass" user.save! - puts 'You can sign in as USER with' - puts 'email: user@fsektionen.se' - puts 'and password: passpass' + puts "You can sign in as USER with" + puts "email: user@fsektionen.se" + puts "and password: passpass" if user.present? PostUser.find_or_create_by(post: prylmast, user: user) end # Election - election = Election.find_or_initialize_by(title: 'Vårterminsmöte', - url: 'vt-15', - visible: true, - semester: Post::SPRING) + election = Election.find_or_initialize_by(title: "Vårterminsmöte", + url: "vt-15", + visible: true, + semester: Post::SPRING) election.update!(open: 2.days.ago, - close_general: 5.days.from_now, - close_all: 10.days.from_now) + close_general: 5.days.from_now, + close_all: 10.days.from_now) # Contact - Contact.find_or_create_by(name: 'Spindelman', email: 'spindelman@fsektionen.se', - public: true, text: 'Detta är en liten spindelman', post: spindel) + Contact.find_or_create_by(name: "Spindelman", email: "spindelman@fsektionen.se", + public: true, text: "Detta är en liten spindelman", post: spindel) # News - News.find_or_create_by!(title: 'Ett helt nytt användarsystem', - content: 'Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.', - user: admin) - News.find_or_create_by!(title: 'Andra helt nytt användarsystem', - content: 'Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.', - user: admin) - News.find_or_create_by!(title: 'Tredje helt nytt användarsystem', - content: 'Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.', - user: admin) - News.find_or_create_by!(title: 'Fjärde helt nytt användarsystem', - content: 'Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.', - user: admin) - News.find_or_create_by!(title: 'Femte helt nytt användarsystem', - content: 'Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.', - user: admin) + News.find_or_create_by!(title: "Ett helt nytt användarsystem", + content: "Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.", + user: admin) + News.find_or_create_by!(title: "Andra helt nytt användarsystem", + content: "Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.", + user: admin) + News.find_or_create_by!(title: "Tredje helt nytt användarsystem", + content: "Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.", + user: admin) + News.find_or_create_by!(title: "Fjärde helt nytt användarsystem", + content: "Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.", + user: admin) + News.find_or_create_by!(title: "Femte helt nytt användarsystem", + content: "Nu har vi en himla massa roliga funktioner som blir mycket lättare att lägga in, det är ju
toppen.", + user: admin) # Events date = Time.zone.now.middle_of_day (1..10).each do |i| event = Event.create!(short_sv: %(E#{i}), title_sv: %(Evenemang #{i}), - title_en: %(Event #{i}), description_sv: 'Detta kommer bli ett evenemang!', - description_en: 'This will be an event!', - starts_at: date, ends_at: date + 5.hours, - food: true, drink: true, location: 'Gasquesalen') + title_en: %(Event #{i}), description_sv: "Detta kommer bli ett evenemang!", + description_en: "This will be an event!", + starts_at: date, ends_at: date + 5.hours, + food: true, drink: true, location: "Gasquesalen") event.update!(short_en: event.short) - date = date + 1.days + [-3,-2,-1,0,1,2,3].sample.hours + date = date + 1.days + [-3, -2, -1, 0, 1, 2, 3].sample.hours end # Gallery - Album.find_or_create_by!(title: 'Välkomstgasque', description: 'Väldans trevligt!', location: 'Gasquesalen', - start_date: Time.zone.now, category: 'Nollning', end_date: Time.zone.now + 10.hours) + Album.find_or_create_by!(title: "Välkomstgasque", description: "Väldans trevligt!", location: "Gasquesalen", + start_date: Time.zone.now, category: "Nollning", end_date: Time.zone.now + 10.hours) # Documents FactoryBot.create(:document) FactoryBot.create(:document) # Categories - Category.find_or_create_by!(title: 'Studier', slug: 'studie') - Category.find_or_create_by!(title: 'Sektionen', slug: 'sektion') - Category.find_or_create_by!(title: 'Fritid', slug: 'fritid') - Category.find_or_create_by!(title: 'Nollning', slug: 'nollning') + Category.find_or_create_by!(title: "Studier", slug: "studie") + Category.find_or_create_by!(title: "Sektionen", slug: "sektion") + Category.find_or_create_by!(title: "Fritid", slug: "fritid") + Category.find_or_create_by!(title: "Nollning", slug: "nollning") - #Tool - tool = Tool.find_or_create_by!(title: 'Hammare', description: 'spikar spikar m.m.', total: 5) + # Tool + tool = Tool.find_or_create_by!(title: "Hammare", description: "spikar spikar m.m.", total: 5) # Tool Renting - ToolRenting.find_or_create_by!(user_id: 1, tool: tool, purpose: 'for home use', return_date: Time.zone.now) - ToolRenting.find_or_create_by!(user_id: 2, tool: tool, purpose: 'for other use', return_date: Time.zone.now) + ToolRenting.find_or_create_by!(user_id: 1, tool: tool, purpose: "for home use", return_date: Time.zone.now) + ToolRenting.find_or_create_by!(user_id: 2, tool: tool, purpose: "for other use", return_date: Time.zone.now) # Introduction - introduction = Introduction.find_or_create_by!(title: 'En Ridderlig Nollning', - start: Time.zone.now.change(month: 8, day: 22).beginning_of_day, - stop: Time.zone.now.change(month: 9, day: 20).end_of_day, - slug: :ridderlig, current: true) + introduction = Introduction.find_or_create_by!(title: "En Ridderlig Nollning", + start: Time.zone.now.change(month: 8, day: 22).beginning_of_day, + stop: Time.zone.now.change(month: 9, day: 20).end_of_day, + slug: :ridderlig, current: true) - group = Group.find_or_create_by!(group_type: Group::REGULAR, name: 'Black Knight', number: 1, introduction: introduction) + group = Group.find_or_create_by!(group_type: Group::REGULAR, name: "Black Knight", number: 1, introduction: introduction) GroupUser.find_or_create_by!(group: group, user: user, fadder: true) # Song Categories - absurda_visor = SongCategory.find_or_create_by!(name: 'Absurda Visor') - teknologvisor = SongCategory.find_or_create_by!(name: 'Teknologvisor') - sektionsramsor = SongCategory.find_or_create_by!(name: 'Sektionsramsor', slug: 'chants') + absurda_visor = SongCategory.find_or_create_by!(name: "Absurda Visor") + teknologvisor = SongCategory.find_or_create_by!(name: "Teknologvisor") + sektionsramsor = SongCategory.find_or_create_by!(name: "Sektionsramsor", slug: "chants") # Songs - Song.find_or_create_by!(title: 'Hello World', - author: 'Edwin', - content: 'Det var en gång en liten Värld som utplånades! Skål!', - song_category: absurda_visor) - - Song.find_or_create_by!(title: 'Hello Sweden', - author: 'Gurra', - content: 'Sverige är Sverige och Sverige är bra!', - song_category: teknologvisor) - - Song.find_or_create_by!(title: 'F-sek är bäst', - author: 'Stefan', - content: 'F-sektionen, tjalalalala!!!', - song_category: sektionsramsor) + Song.find_or_create_by!(title: "Hello World", + author: "Edwin", + content: "Det var en gång en liten Värld som utplånades! Skål!", + song_category: absurda_visor) + + Song.find_or_create_by!(title: "Hello Sweden", + author: "Gurra", + content: "Sverige är Sverige och Sverige är bra!", + song_category: teknologvisor) + + Song.find_or_create_by!(title: "F-sek är bäst", + author: "Stefan", + content: "F-sektionen, tjalalalala!!!", + song_category: sektionsramsor) # Notifications Rpush::Gcm::App.find_or_create_by!(name: :firebase, auth_key: :test) diff --git a/old/import_old_albums.rb b/old/import_old_albums.rb index 8fd988a0a..95f84cded 100644 --- a/old/import_old_albums.rb +++ b/old/import_old_albums.rb @@ -7,14 +7,14 @@ fail "No! Don't run this code. It's for reference only." # Pull in the rails app environment -require './config/environment' +require "./config/environment" # Establish connection to the database conn = ActiveRecord::Base.connection # Load items and item attributes # Note: we are loading from an external database, not the app DB. -items_and_attributes = conn.execute <<-sql +items_and_attributes = conn.execute <<-SQL select I.g_id, I.g_canContainChildren, I.g_summary, I.g_title, A.g_parentSequence, F.g_pathComponent from gallery.g2_Item I @@ -22,13 +22,13 @@ join gallery.g2_FileSystemEntity F on I.g_id = F.g_id order by A.g_parentSequence asc ; -sql +SQL # Guess the root node root_id = items_and_attributes.first[0] # Build tree structure -tree = { root_id => { :title => 'ROOT', :children => { } } } +tree = {root_id => {title: "ROOT", children: {}}} items_and_attributes.each do |vals| id, ccc, summary, title, parents, pathcomp = vals @@ -36,7 +36,7 @@ next if id == root_id # Find parent node - parent_ids = parents.split('/').map(&:to_i) + parent_ids = parents.split("/").map(&:to_i) parent_ids.shift # remove root id parent = tree[root_id] @@ -47,9 +47,9 @@ # Add this node to the tree parent[:children][id] = { - :title => title, - :summary => summary, - :path => "#{parent[:path]}/#{pathcomp}", + title: title, + summary: summary, + path: "#{parent[:path]}/#{pathcomp}" } end @@ -63,17 +63,17 @@ def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year elsif level == 1 year = node[:title].to_i elsif level >= 2 && node[:children] - if name_acc - name_acc = "#{name_acc} - #{node[:title]}" + name_acc = if name_acc + "#{name_acc} - #{node[:title]}" else - name_acc = node[:title] + node[:title] end album = { - :year => year, - :title => name_acc, - :summary => node[:summary], - :pictures => [] + year: year, + title: name_acc, + summary: node[:summary], + pictures: [] } album_acc << album @@ -94,11 +94,11 @@ def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year album_table = [] recursive_collect tree[root_id], album_table -puts sprintf('Found %d pictures in %d albums.', @picture_counter, @album_counter) +puts sprintf("Found %d pictures in %d albums.", @picture_counter, @album_counter) # Insert all the found albums into the database. -BASE = '/oldroot/var/www/gallery_data/albums' +BASE = "/oldroot/var/www/gallery_data/albums" album_table.each do |ia| # No empty albums @@ -107,7 +107,7 @@ def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year end # Ensure we don't create any duplicates - result = conn.execute <<-sql + result = conn.execute <<-SQL select 1 from albums a, album_translations t where a.id = t.album_id and t.locale = 'sv' @@ -115,20 +115,20 @@ def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year and t.title = #{ActiveRecord::Base.sanitize(ia[:title])} limit 1 ; - sql + SQL if result.any? next end - description = ia[:summary].present?? ia[:summary] : '_' + description = ia[:summary].present? ? ia[:summary] : "_" - a = Album.new :title_sv => ia[:title], - :title_en => ia[:title], - :description_sv => description, - :description_en => description, - :start_date => Date.parse("#{ia[:year]}-01-02"), - :end_date => Date.parse("#{ia[:year]}-12-30") + a = Album.new title_sv: ia[:title], + title_en: ia[:title], + description_sv: description, + description_en: description, + start_date: Date.parse("#{ia[:year]}-01-02"), + end_date: Date.parse("#{ia[:year]}-12-30") begin a.save! rescue ActiveRecord::RecordInvalid => ex @@ -145,19 +145,19 @@ def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year end # A small attempt to reformat the "summary" to fit the new system. - photographer_name = ip[:summary] || '' - photograhper_name = photographer_name.gsub(/Fotografe?r?:? /, '') + photographer_name = ip[:summary] || "" + photograhper_name = photographer_name.gsub(/Fotografe?r?:? /, "") - i = Image.new :album_id => a.id, - :file => File.new(File.join(BASE, ip[:path])), - :photographer_name => photographer_name + i = Image.new album_id: a.id, + file: File.new(File.join(BASE, ip[:path])), + photographer_name: photographer_name begin i.save! rescue ActiveRecord::RecordInvalid => ex binding.pry end - print '.' + print "." $stdout.flush end @@ -165,9 +165,8 @@ def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year a.images_count = ia[:pictures].count a.save! - puts ' done' + puts " done" end # The cache doesn't work when we insert albums manually, so just nuke it. Rails.cache.clear - diff --git a/spec/controllers/admin/albums_controller_spec.rb b/spec/controllers/admin/albums_controller_spec.rb index c35927c44..963c5c603 100644 --- a/spec/controllers/admin/albums_controller_spec.rb +++ b/spec/controllers/admin/albums_controller_spec.rb @@ -1,58 +1,58 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::AlbumsController, type: :controller do let(:user) { create(:admin) } allow_user_to(:manage, [Album, Image]) - describe 'GET #show' do - it 'assigns the requested album as @album' do + describe "GET #show" do + it "assigns the requested album as @album" do album = create(:album) - get :show, params: { id: album.to_param } + get :show, params: {id: album.to_param} assigns(:album).should eq(album) end end - describe 'GET #new' do - it 'assigns a new album as @album' do + describe "GET #new" do + it "assigns a new album as @album" do get(:new) assigns(:album).should be_a_new(Album) end end - describe 'GET #index' do - it 'assigns albums sorted as @albums' do - create(:album, title: 'Second', start_date: 5.days.ago) - create(:album, title: 'First', start_date: 4.days.ago) - create(:album, title: 'Third', start_date: 6.days.ago) + describe "GET #index" do + it "assigns albums sorted as @albums" do + create(:album, title: "Second", start_date: 5.days.ago) + create(:album, title: "First", start_date: 4.days.ago) + create(:album, title: "Third", start_date: 6.days.ago) get(:index) - assigns(:albums).map(&:title).should eq(['First', 'Second', 'Third']) + assigns(:albums).map(&:title).should eq(["First", "Second", "Third"]) end end - describe 'POST #create' do - it 'works with valid parameters' do - attributes = { title_sv: 'Välkomstgasque', - description_sv: 'Detta är en välkomstgasque!', - location: 'Kårhuset: Gasquesalen', - start_date: 2.days.ago, - end_date: 2.days.ago + 5.hours } + describe "POST #create" do + it "works with valid parameters" do + attributes = {title_sv: "Välkomstgasque", + description_sv: "Detta är en välkomstgasque!", + location: "Kårhuset: Gasquesalen", + start_date: 2.days.ago, + end_date: 2.days.ago + 5.hours} lambda do - post :create, params: { album: attributes } + post :create, params: {album: attributes} end.should change(Album, :count).by(1) response.should redirect_to(admin_album_path(Album.last)) end - it 'does not work with invalid parameters' do - attributes = { title_sv: 'Välkomstgasque', - end_date: 2.days.ago + 5.hours } + it "does not work with invalid parameters" do + attributes = {title_sv: "Välkomstgasque", + end_date: 2.days.ago + 5.hours} lambda do - post :create, params: { album: attributes } + post :create, params: {album: attributes} end.should change(Album, :count).by(0) response.should render_template(:new) @@ -60,56 +60,56 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - album = create(:album, title: 'Välkomstgasque') + describe "PATCH #update" do + it "valid parameters" do + album = create(:album, title: "Välkomstgasque") - img = 'app/assets/images/hilbert.jpg' - album_params = { title_sv: 'Nollegasque', - photographer_user: user.id, - photographer_name: user.firstname, - image_upload: [Rack::Test::UploadedFile.new(File.open(img))] } + img = "app/assets/images/hilbert.jpg" + album_params = {title_sv: "Nollegasque", + photographer_user: user.id, + photographer_name: user.firstname, + image_upload: [Rack::Test::UploadedFile.new(File.open(img))]} - patch :update, params: { id: album.to_param, album: album_params } + patch :update, params: {id: album.to_param, album: album_params} album.reload - album.title.should eq('Nollegasque') + album.title.should eq("Nollegasque") response.should redirect_to(admin_album_path(album)) album.images.count.should eq(1) album.images.last.photographer.should eq(user) album.images.last.photographer_name.should eq(user.firstname) end - it 'invalid parameters' do - album = create(:album, title: 'Välkomstgasque') - patch :update, params: { id: album.to_param, album: { title_sv: nil } } + it "invalid parameters" do + album = create(:album, title: "Välkomstgasque") + patch :update, params: {id: album.to_param, album: {title_sv: nil}} album.reload - album.title.should eq('Välkomstgasque') + album.title.should eq("Välkomstgasque") response.should render_template(:show) response.should have_http_status(422) end end - describe 'DELETE #destroy' do - it 'destroys record' do + describe "DELETE #destroy" do + it "destroys record" do album = create(:album) lambda do - delete :destroy, params: { id: album.to_param } + delete :destroy, params: {id: album.to_param} end.should change(Album, :count).by(-1) response.should redirect_to(admin_albums_path) end end - describe 'DELETE #destroy_images' do - it 'destroys all images' do + describe "DELETE #destroy_images" do + it "destroys all images" do album = create(:album_with_images, image_count: 3) album.images.size.should eq(3) lambda do - delete :destroy_images, params: { id: album.to_param } + delete :destroy_images, params: {id: album.to_param} end.should change(Image, :count).by(-3) album.reload album.images.should be_empty diff --git a/spec/controllers/admin/blog_posts_controller_spec.rb b/spec/controllers/admin/blog_posts_controller_spec.rb index b3e4883a7..b2249c1ea 100644 --- a/spec/controllers/admin/blog_posts_controller_spec.rb +++ b/spec/controllers/admin/blog_posts_controller_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::BlogPostsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, BlogPost) - describe 'GET #index' do - it 'renders grid' do + describe "GET #index" do + it "renders grid" do create(:blog_post) get(:index) @@ -13,45 +13,45 @@ end end - describe 'GET #new' do - it 'sets new blog_post' do + describe "GET #new" do + it "sets new blog_post" do get(:new) assigns(:blog_post).should be_a_new(BlogPost) response.should have_http_status(200) end end - describe 'GET #edit' do - it 'sets blog_post' do + describe "GET #edit" do + it "sets blog_post" do blog_post = create(:blog_post) - get :edit, params: { id: blog_post.to_param } + get :edit, params: {id: blog_post.to_param} response.should have_http_status(200) assigns(:blog_post).should eq(blog_post) end end - describe 'POST #create' do - it 'valid parameters' do + describe "POST #create" do + it "valid parameters" do set_current_user(user) - attributes = { title_sv: 'A marvellous journey!', - preamble_sv: 'Some lines of code and an idea!', - content_sv: 'There once was a time' } + attributes = {title_sv: "A marvellous journey!", + preamble_sv: "Some lines of code and an idea!", + content_sv: "There once was a time"} lambda do - post :create, params: { blog_post: attributes } + post :create, params: {blog_post: attributes} end.should change(BlogPost, :count).by(1) response.should redirect_to(edit_admin_blog_post_path(BlogPost.last)) end - it 'invalid parameters' do + it "invalid parameters" do set_current_user(user) - attributes = { title_sv: nil, - content_sv: 'There once was a time' } + attributes = {title_sv: nil, + content_sv: "There once was a time"} lambda do - post :create, params: { blog_post: attributes } + post :create, params: {blog_post: attributes} end.should change(BlogPost, :count).by(0) response.should have_http_status(422) @@ -59,35 +59,35 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - blog_post = create(:blog_post, title: 'Oh, summernight!') - attributes = { title_sv: 'Not summer...' } + describe "PATCH #update" do + it "valid parameters" do + blog_post = create(:blog_post, title: "Oh, summernight!") + attributes = {title_sv: "Not summer..."} - patch :update, params: { id: blog_post.to_param, blog_post: attributes } + patch :update, params: {id: blog_post.to_param, blog_post: attributes} blog_post.reload response.should redirect_to(edit_admin_blog_post_path(blog_post)) - blog_post.title.should eq('Not summer...') + blog_post.title.should eq("Not summer...") end - it 'invalid parameters' do - blog_post = create(:blog_post, title: 'Vad är väl en Nollning?') - attributes = { title_sv: nil } + it "invalid parameters" do + blog_post = create(:blog_post, title: "Vad är väl en Nollning?") + attributes = {title_sv: nil} - patch :update, params: { id: blog_post.to_param, blog_post: attributes } + patch :update, params: {id: blog_post.to_param, blog_post: attributes} blog_post.reload response.should have_http_status(422) response.should render_template(:edit) - blog_post.title.should eq('Vad är väl en Nollning?') + blog_post.title.should eq("Vad är väl en Nollning?") end end - describe 'DELETE #destroy' do - it 'destroys blog_post' do + describe "DELETE #destroy" do + it "destroys blog_post" do blog_post = create(:blog_post) lambda do - delete :destroy, params: { id: blog_post.to_param } + delete :destroy, params: {id: blog_post.to_param} end.should change(BlogPost, :count).by(-1) response.should redirect_to(admin_blog_posts_path) end diff --git a/spec/controllers/admin/cafe_controller_spec.rb b/spec/controllers/admin/cafe_controller_spec.rb index d7aabdcc8..8e5097448 100644 --- a/spec/controllers/admin/cafe_controller_spec.rb +++ b/spec/controllers/admin/cafe_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::CafeController, type: :controller do let(:user) { create(:user) } @@ -9,15 +9,15 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #index' do - it 'loads index view properly' do + describe "GET #index" do + it "loads index view properly" do get :index response.status.should eq(200) end end - describe 'GET #overview' do - it 'loads overview view properly' do + describe "GET #overview" do + it "loads overview view properly" do get :overview response.status.should eq(200) end diff --git a/spec/controllers/admin/cafe_shifts_controller_spec.rb b/spec/controllers/admin/cafe_shifts_controller_spec.rb index b3cee8bbe..f1aac4362 100644 --- a/spec/controllers/admin/cafe_shifts_controller_spec.rb +++ b/spec/controllers/admin/cafe_shifts_controller_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::CafeShiftsController, type: :controller do - let(:user) { create(:user, firstname: 'First') } + let(:user) { create(:user, firstname: "First") } allow_user_to :manage, CafeShift @@ -9,67 +9,67 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #show' do - it 'assigns the requested cafe_shift as @cafe_shift' do + describe "GET #show" do + it "assigns the requested cafe_shift as @cafe_shift" do shift = create(:cafe_shift) - create(:council, title: 'Second') - create(:council, title: 'First') - create(:council, title: 'Third') - create(:user, firstname: 'Third') - create(:user, firstname: 'Second') + create(:council, title: "Second") + create(:council, title: "First") + create(:council, title: "Third") + create(:user, firstname: "Third") + create(:user, firstname: "Second") - get :show, params: { id: shift.to_param } + get :show, params: {id: shift.to_param} assigns(:cafe_view).shift.should eq(shift) - assigns(:cafe_view).councils.map(&:title).should eq(['First', 'Second', 'Third']) - assigns(:cafe_view).users.map(&:firstname).should eq(['First', 'Second', 'Third']) + assigns(:cafe_view).councils.map(&:title).should eq(["First", "Second", "Third"]) + assigns(:cafe_view).users.map(&:firstname).should eq(["First", "Second", "Third"]) assigns(:cafe_view).shift.cafe_worker.should be_a_new(CafeWorker) response.status.should eq(200) end - it 'error cafe_shift is not found' do + it "error cafe_shift is not found" do lambda do - get :show, params: { id: 9999777 } + get :show, params: {id: 9999777} end.should raise_error(ActionController::RoutingError) end end - describe 'GET #edit' do - it 'assigns the requested cafe_shift as @cafe_shift' do + describe "GET #edit" do + it "assigns the requested cafe_shift as @cafe_shift" do shift = create(:cafe_shift) - get :edit, params: { id: shift.to_param } + get :edit, params: {id: shift.to_param} assigns(:cafe_shift).should eq(shift) response.status.should eq(200) end - it 'error cafe_shift is not found' do + it "error cafe_shift is not found" do lambda do - get :show, params: { id: 9999777 } + get :show, params: {id: 9999777} end.should raise_error(ActionController::RoutingError) end end - describe 'GET #new' do - it 'assigns a new cafe_shift as @cafe_shift' do + describe "GET #new" do + it "assigns a new cafe_shift as @cafe_shift" do get(:new) assigns(:cafe_shift).new_record?.should be_truthy assigns(:cafe_shift).instance_of?(CafeShift).should be_truthy end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do lambda do - post :create, params: { cafe_shift: attributes_for(:cafe_shift) } + post :create, params: {cafe_shift: attributes_for(:cafe_shift)} end.should change(CafeShift, :count).by(1) response.should redirect_to([:admin, CafeShift.last]) end - it 'invalid params' do + it "invalid params" do lambda do - post :create, params: { cafe_shift: { start: nil } } + post :create, params: {cafe_shift: {start: nil}} end.should change(CafeShift, :count).by(0) response.should render_template(:new) @@ -77,20 +77,20 @@ end end - describe 'PATCH #update' do - it 'valid params' do + describe "PATCH #update" do + it "valid params" do shift = create(:cafe_shift, pass: 1) - post :update, params: { id: shift.to_param, cafe_shift: { pass: 2 } } + post :update, params: {id: shift.to_param, cafe_shift: {pass: 2}} shift.reload response.should redirect_to([:admin, shift]) shift.pass.should eq(2) end - it 'invalid params' do + it "invalid params" do shift = create(:cafe_shift, pass: 2) - post :update, params: { id: shift.to_param, cafe_shift: { pass: nil } } + post :update, params: {id: shift.to_param, cafe_shift: {pass: nil}} response.should render_template(:edit) response.status.should eq(422) @@ -99,35 +99,35 @@ end end - describe 'DELETE #destroy' do - it 'destroys record' do + describe "DELETE #destroy" do + it "destroys record" do shift = create(:cafe_shift) lambda do - delete :destroy, params: { id: shift.to_param } + delete :destroy, params: {id: shift.to_param} end.should change(CafeShift, :count).by(-1) response.should redirect_to(admin_cafe_shifts_path) end end - describe 'GET #setup' do - it 'assigns a new cafe_shift as @cafe_shift' do + describe "GET #setup" do + it "assigns a new cafe_shift as @cafe_shift" do get(:setup) assigns(:cafe_shift).new_record?.should be_truthy assigns(:cafe_shift).instance_of?(CafeShift).should be_truthy end end - describe 'POST #setup_create' do - it 'creates weeks of cafe_shifts' do - attributes = { lv: 1, - lv_last: 1, - start: Time.zone.now.change(hour: 8), - lp: 4, - setup_mode: :week } + describe "POST #setup_create" do + it "creates weeks of cafe_shifts" do + attributes = {lv: 1, + lv_last: 1, + start: Time.zone.now.change(hour: 8), + lp: 4, + setup_mode: :week} lambda do - post :setup_create, params: { cafe_shift: attributes } + post :setup_create, params: {cafe_shift: attributes} end.should change(CafeShift, :count).by(20) response.should redirect_to(admin_cafe_shifts_path) @@ -136,14 +136,14 @@ assigns(:cafe_shift).instance_of?(CafeShift).should be_truthy end - it 'creates days of cafe_shifts' do - attributes = { lv: 1, - lv_last: 1, - start: Time.zone.now.change(hour: 8), - lp: 4, - setup_mode: :day } + it "creates days of cafe_shifts" do + attributes = {lv: 1, + lv_last: 1, + start: Time.zone.now.change(hour: 8), + lp: 4, + setup_mode: :day} lambda do - post :setup_create, params: { cafe_shift: attributes } + post :setup_create, params: {cafe_shift: attributes} end.should change(CafeShift, :count).by(4) response.should redirect_to(admin_cafe_shifts_path) @@ -152,9 +152,9 @@ assigns(:cafe_shift).instance_of?(CafeShift).should be_truthy end - it 'invalid params' do + it "invalid params" do lambda do - post :setup_create, params: { cafe_shift: { start: nil } } + post :setup_create, params: {cafe_shift: {start: nil}} end.should change(CafeShift, :count).by(0) response.status.should eq(422) diff --git a/spec/controllers/admin/cafe_workers_controller_spec.rb b/spec/controllers/admin/cafe_workers_controller_spec.rb index cdcfde8ed..a1acd5d50 100644 --- a/spec/controllers/admin/cafe_workers_controller_spec.rb +++ b/spec/controllers/admin/cafe_workers_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::CafeWorkersController, type: :controller do let(:user) { create(:user) } @@ -10,34 +10,34 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #new' do - it 'assigns the requested cafe_view as @cafe_view' do + describe "GET #new" do + it "assigns the requested cafe_view as @cafe_view" do shift = create(:cafe_shift) - get :new, params: { cafe_shift_id: shift.to_param } + get :new, params: {cafe_shift_id: shift.to_param} assigns(:cafe_view).shift.should eq(shift) assigns(:cafe_view).shift.cafe_worker.should be_a_new(CafeWorker) response.status.should eq(200) end - it 'error cafe_shift is not found' do + it "error cafe_shift is not found" do lambda do - get :new, params: { cafe_shift_id: 9999 } + get :new, params: {cafe_shift_id: 9999} end.should raise_error(ActionController::RoutingError) end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do council = create(:council) shift = create(:cafe_shift) - attributes = { competition: true, - user_id: user.to_param, - council_ids: [council.id], - group: 'MUR' } + attributes = {competition: true, + user_id: user.to_param, + council_ids: [council.id], + group: "MUR"} lambda do - post :create, params: { cafe_shift_id: shift.to_param, cafe_worker: attributes } + post :create, params: {cafe_shift_id: shift.to_param, cafe_worker: attributes} end.should change(CafeWorker, :count).by(1) assigns(:cafe_view).shift.should eq(shift) @@ -46,10 +46,10 @@ response.should redirect_to([:admin, shift]) end - it 'invalid params' do + it "invalid params" do shift = create(:cafe_shift) lambda do - post :create, params: { cafe_shift_id: shift.to_param, cafe_worker: { user_id: nil } } + post :create, params: {cafe_shift_id: shift.to_param, cafe_worker: {user_id: nil}} end.should change(CafeWorker, :count).by(0) assigns(:cafe_view).shift.should eq(shift) @@ -58,17 +58,17 @@ end end - describe 'PATCH #update' do - it 'valid params' do + describe "PATCH #update" do + it "valid params" do shift = create(:cafe_shift) worker = create(:cafe_worker, - cafe_shift: shift, - user: user, - competition: true) + cafe_shift: shift, + user: user, + competition: true) - patch :update, params: { id: worker.to_param, - cafe_shift_id: shift.to_param, - cafe_worker: { competition: false } } + patch :update, params: {id: worker.to_param, + cafe_shift_id: shift.to_param, + cafe_worker: {competition: false}} shift.reload shift.cafe_worker.reload @@ -77,12 +77,12 @@ response.should redirect_to([:admin, shift]) end - it 'invalid_params' do + it "invalid_params" do shift = create(:cafe_shift) worker = create(:cafe_worker, cafe_shift: shift, competition: true) - patch :update, params: { id: worker.to_param, - cafe_shift_id: shift.to_param, - cafe_worker: { user_id: nil } } + patch :update, params: {id: worker.to_param, + cafe_shift_id: shift.to_param, + cafe_worker: {user_id: nil}} assigns(:cafe_view).shift.should eq(shift) assigns(:cafe_view).shift.cafe_worker.should_not be_nil @@ -91,14 +91,14 @@ end end - describe 'DELETE #destroy' do - it 'destroy worker' do + describe "DELETE #destroy" do + it "destroy worker" do shift = create(:cafe_shift) worker = create(:cafe_worker, - cafe_shift: shift, - user: user) + cafe_shift: shift, + user: user) - delete :destroy, params: { cafe_shift_id: shift.to_param, id: worker.to_param } + delete :destroy, params: {cafe_shift_id: shift.to_param, id: worker.to_param} response.should redirect_to([:admin, shift]) end end diff --git a/spec/controllers/admin/categories_controller_spec.rb b/spec/controllers/admin/categories_controller_spec.rb index 67ee63e6d..9008003fd 100644 --- a/spec/controllers/admin/categories_controller_spec.rb +++ b/spec/controllers/admin/categories_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::CategoriesController, type: :controller do let(:user) { create(:admin) } @@ -9,48 +9,48 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a category grid and categories' do - create(:category, title: 'First category') - create(:category, title: 'Second category') - create(:category, title: 'Third category') + describe "GET #index" do + it "assigns a category grid and categories" do + create(:category, title: "First category") + create(:category, title: "Second category") + create(:category, title: "Third category") get(:index) response.status.should eq(200) end end - describe 'GET #edit' do - it 'assigns given category as @category' do + describe "GET #edit" do + it "assigns given category as @category" do category = create(:category) - get :edit, params: { id: category.to_param } + get :edit, params: {id: category.to_param} assigns(:category).should eq(category) end end - describe 'GET #new' do - it 'assigns a new category as @category' do + describe "GET #new" do + it "assigns a new category as @category" do get(:new) assigns(:category).instance_of?(Category).should be_truthy assigns(:category).new_record?.should be_truthy end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { title_sv: 'Kategori 1', slug: 'kategori' } + describe "POST #create" do + it "valid parameters" do + attributes = {title_sv: "Kategori 1", slug: "kategori"} lambda do - post :create, params: { category: attributes } + post :create, params: {category: attributes} end.should change(Category, :count).by(1) response.should redirect_to(admin_categories_path) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { category: { slug: '' } } + post :create, params: {category: {slug: ""}} end.should change(Category, :count).by(0) response.status.should eq(422) @@ -58,35 +58,35 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - category = create(:category, title_en: 'A Bad Title') + describe "PATCH #update" do + it "valid parameters" do + category = create(:category, title_en: "A Bad Title") - patch :update, params: { id: category.to_param, category: { title_en: 'A Good Title' } } + patch :update, params: {id: category.to_param, category: {title_en: "A Good Title"}} category.reload - category.title_en.should eq('A Good Title') + category.title_en.should eq("A Good Title") response.should redirect_to(edit_admin_category_path(category)) end - it 'invalid parameters' do - category = create(:category, slug: 'good') + it "invalid parameters" do + category = create(:category, slug: "good") - patch :update, params: { id: category.to_param, category: { slug: '' } } + patch :update, params: {id: category.to_param, category: {slug: ""}} category.reload - category.slug.should eq('good') + category.slug.should eq("good") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do category = create(:category) lambda do - delete :destroy, params: { id: category.to_param } + delete :destroy, params: {id: category.to_param} end.should change(Category, :count).by(-1) response.should redirect_to(admin_categories_path) diff --git a/spec/controllers/admin/constants_controller_spec.rb b/spec/controllers/admin/constants_controller_spec.rb index 3e8ff7be9..98fd84258 100644 --- a/spec/controllers/admin/constants_controller_spec.rb +++ b/spec/controllers/admin/constants_controller_spec.rb @@ -1,18 +1,18 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::ConstantsController, type: :controller do - describe 'GET #index when not allowed' do - it 'returns http forbidden' do + describe "GET #index when not allowed" do + it "returns http forbidden" do get :index - #response.should have_http_status(:forbidden) + # response.should have_http_status(:forbidden) response.should redirect_to :new_user_session end end - describe 'GET #index when allowed' do + describe "GET #index when allowed" do allow_user_to :read, Constant - it 'succeeds' do + it "succeeds" do get :index response.should be_success diff --git a/spec/controllers/admin/contacts_controller_spec.rb b/spec/controllers/admin/contacts_controller_spec.rb index e4035b608..d3bcfdb52 100644 --- a/spec/controllers/admin/contacts_controller_spec.rb +++ b/spec/controllers/admin/contacts_controller_spec.rb @@ -1,13 +1,13 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::ContactsController, type: :controller do allow_user_to :manage, Contact - describe 'GET #index' do - it 'succeeds and assigns contacts' do - create(:contact, name: 'Second') - create(:contact, name: 'Third') - create(:contact, name: 'First') + describe "GET #index" do + it "succeeds and assigns contacts" do + create(:contact, name: "Second") + create(:contact, name: "Third") + create(:contact, name: "First") get :index @@ -15,8 +15,8 @@ end end - describe 'GET #new' do - it 'succeeds' do + describe "GET #new" do + it "succeeds" do get :new response.should be_success @@ -24,35 +24,35 @@ end end - describe 'GET #edit' do - it 'succeeds' do + describe "GET #edit" do + it "succeeds" do contact = create(:contact) - get :edit, params: { id: contact.to_param } + get :edit, params: {id: contact.to_param} response.should be_success assigns(:contact).should eq(contact) end end - describe 'POST #create' do - it 'valid params' do - attributes = { name_sv: 'David', - email: 'test@test.se', - public: 1, - text_sv: 'Jag kan svara på mejl' } + describe "POST #create" do + it "valid params" do + attributes = {name_sv: "David", + email: "test@test.se", + public: 1, + text_sv: "Jag kan svara på mejl"} lambda do - post :create, params: { contact: attributes } + post :create, params: {contact: attributes} end.should change(Contact, :count).by(1) response.should redirect_to(edit_admin_contact_path(Contact.last)) - Contact.last.name.should eq('David') + Contact.last.name.should eq("David") end - it 'invalid params' do + it "invalid params" do lambda do - post :create, params: { contact: { name_sv: nil } } + post :create, params: {contact: {name_sv: nil}} end.should change(Contact, :count).by(0) response.should render_template(:new) @@ -60,35 +60,35 @@ end end - describe 'PATCH #update' do - it 'valid params' do - contact = create(:contact, name: 'David') + describe "PATCH #update" do + it "valid params" do + contact = create(:contact, name: "David") - post :update, params: { id: contact.to_param, contact: { name_sv: 'Titel' } } + post :update, params: {id: contact.to_param, contact: {name_sv: "Titel"}} contact.reload response.should redirect_to(edit_admin_contact_path(contact)) - contact.name.should eq('Titel') + contact.name.should eq("Titel") end - it 'valid params' do - contact = create(:contact, name: 'David') - post :update, params: { id: contact.to_param, contact: { name_sv: '' } } + it "valid params" do + contact = create(:contact, name: "David") + post :update, params: {id: contact.to_param, contact: {name_sv: ""}} contact.reload - contact.name.should eq('David') + contact.name.should eq("David") response.should render_template(:edit) response.status.should eq(422) end end - describe 'DELETE #destroy' do - it 'succeeds' do + describe "DELETE #destroy" do + it "succeeds" do contact = create(:contact) lambda do - delete :destroy, params: { id: contact.to_param } + delete :destroy, params: {id: contact.to_param} end.should change(Contact, :count).by(-1) response.should redirect_to(admin_contacts_path) diff --git a/spec/controllers/admin/councils_controller_spec.rb b/spec/controllers/admin/councils_controller_spec.rb index aec4bc3ab..bc2f38caa 100644 --- a/spec/controllers/admin/councils_controller_spec.rb +++ b/spec/controllers/admin/councils_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::CouncilsController, type: :controller do let(:user) { create(:user) } @@ -9,11 +9,11 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a councils' do - create(:council, title: 'Second') - create(:council, title: 'First') - create(:council, title: 'Third') + describe "GET #index" do + it "assigns a councils" do + create(:council, title: "Second") + create(:council, title: "First") + create(:council, title: "Third") get(:index) response.status.should eq(200) @@ -21,39 +21,39 @@ end end - describe 'GET #new' do - it 'assigns a new council as @council' do + describe "GET #new" do + it "assigns a new council as @council" do get(:new) assigns(:council).instance_of?(Council).should be_truthy assigns(:council).new_record?.should be_truthy end end - describe 'GET #edit' do - it 'assigns given council as @council' do + describe "GET #edit" do + it "assigns given council as @council" do council = create(:council) - get :edit, params: { id: council.to_param } + get :edit, params: {id: council.to_param} assigns(:council).should eq(council) end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { title_sv: 'Prylmästeriet', - url: 'pryl' } + describe "POST #create" do + it "valid parameters" do + attributes = {title_sv: "Prylmästeriet", + url: "pryl"} lambda do - post :create, params: { council: attributes } + post :create, params: {council: attributes} end.should change(Council, :count).by(1) response.should redirect_to(edit_admin_council_path(Council.last)) - Council.last.title.should eq('Prylmästeriet') + Council.last.title.should eq("Prylmästeriet") end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { council: { title_sv: '' } } + post :create, params: {council: {title_sv: ""}} end.should change(Council, :count).by(0) response.status.should eq(422) @@ -61,37 +61,37 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - council = create(:council, title: 'A Bad Title') + describe "PATCH #update" do + it "valid parameters" do + council = create(:council, title: "A Bad Title") - attributes = { title_sv: 'A Good Title' } - patch :update, params: { id: council.to_param, council: attributes } + attributes = {title_sv: "A Good Title"} + patch :update, params: {id: council.to_param, council: attributes} council.reload response.should redirect_to(edit_admin_council_path(council)) - council.title.should eq('A Good Title') + council.title.should eq("A Good Title") end - it 'invalid parameters' do - council = create(:council, title: 'A Good Title') + it "invalid parameters" do + council = create(:council, title: "A Good Title") - attributes = { title_sv: '' } - patch :update, params: { id: council.to_param, council: attributes } + attributes = {title_sv: ""} + patch :update, params: {id: council.to_param, council: attributes} council.reload - council.title.should eq('A Good Title') + council.title.should eq("A Good Title") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'destroying' do + describe "DELETE #destroy" do + it "destroying" do council = create(:council) lambda do - delete :destroy, params: { id: council.to_param } + delete :destroy, params: {id: council.to_param} end.should change(Council, :count).by(-1) response.should redirect_to(admin_councils_path) diff --git a/spec/controllers/admin/documents_controller_spec.rb b/spec/controllers/admin/documents_controller_spec.rb index 4ea9550c3..f69ea0e93 100644 --- a/spec/controllers/admin/documents_controller_spec.rb +++ b/spec/controllers/admin/documents_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::DocumentsController, type: :controller do let(:user) { create(:admin) } @@ -9,40 +9,40 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a document grid and categories' do - create(:document, title: 'First document') - create(:document, title: 'Second document') - create(:document, title: 'Third document') + describe "GET #index" do + it "assigns a document grid and categories" do + create(:document, title: "First document") + create(:document, title: "Second document") + create(:document, title: "Third document") get(:index) response.status.should eq(200) end end - describe 'GET #edit' do - it 'assigns given document as @document' do + describe "GET #edit" do + it "assigns given document as @document" do document = create(:document) - get :edit, params: { id: document.to_param } + get :edit, params: {id: document.to_param} assigns(:document).should eq(document) end end - describe 'GET #new' do - it 'assigns a new document as @document' do + describe "GET #new" do + it "assigns a new document as @document" do get(:new) assigns(:document).instance_of?(Document).should be_truthy assigns(:document).new_record?.should be_truthy end end - describe 'POST #create' do - it 'valid parameters' do + describe "POST #create" do + it "valid parameters" do attributes = attributes_for(:document) lambda do - post :create, params: { document: attributes } + post :create, params: {document: attributes} end.should change(Document, :count).by(1) response.should redirect_to(edit_admin_document_path(Document.last)) @@ -50,9 +50,9 @@ Document.last.user_id.should eq(user.id) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { document: { title: '' } } + post :create, params: {document: {title: ""}} end.should change(Document, :count).by(0) response.status.should eq(422) @@ -60,12 +60,12 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - document = create(:document, title: 'A Bad Title', user_id: 99) + describe "PATCH #update" do + it "valid parameters" do + document = create(:document, title: "A Bad Title", user_id: 99) - attributes = { title: 'A Good Title' } - patch :update, params: { id: document.to_param, document: attributes } + attributes = {title: "A Good Title"} + patch :update, params: {id: document.to_param, document: attributes} document.reload response.should redirect_to(edit_admin_document_path(document)) @@ -73,25 +73,25 @@ document.user_id.should eq(user.id) end - it 'invalid parameters' do - document = create(:document, title: 'A Good Title') + it "invalid parameters" do + document = create(:document, title: "A Good Title") - attributes = { title: '' } - patch :update, params: { id: document.to_param, document: attributes } + attributes = {title: ""} + patch :update, params: {id: document.to_param, document: attributes} document.reload - document.title.should eq('A Good Title') + document.title.should eq("A Good Title") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do document = create(:document) lambda do - delete :destroy, params: { id: document.to_param } + delete :destroy, params: {id: document.to_param} end.should change(Document, :count).by(-1) response.should redirect_to(admin_documents_path) diff --git a/spec/controllers/admin/doors_controller_spec.rb b/spec/controllers/admin/doors_controller_spec.rb index 56a5387d2..41fe97003 100644 --- a/spec/controllers/admin/doors_controller_spec.rb +++ b/spec/controllers/admin/doors_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::DoorsController, type: :controller do let(:user) { create(:admin) } @@ -9,49 +9,49 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a door grid and doors' do - create(:door, title: 'First door') - create(:door, title: 'Second door') - create(:door, title: 'Third door') + describe "GET #index" do + it "assigns a door grid and doors" do + create(:door, title: "First door") + create(:door, title: "Second door") + create(:door, title: "Third door") get(:index) response.status.should eq(200) end end - describe 'GET #edit' do - it 'assigns given door as @door' do + describe "GET #edit" do + it "assigns given door as @door" do door = create(:door) - get :edit, params: { id: door.to_param } + get :edit, params: {id: door.to_param} assigns(:door).should eq(door) end end - describe 'GET #new' do - it 'assigns a new door as @door' do + describe "GET #new" do + it "assigns a new door as @door" do get(:new) assigns(:door).should be_a_new(Door) end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { title: 'Kategori 1', - slug: 'kategori', - description: 'En beskrivning' } + describe "POST #create" do + it "valid parameters" do + attributes = {title: "Kategori 1", + slug: "kategori", + description: "En beskrivning"} lambda do - post :create, params: { door: attributes } + post :create, params: {door: attributes} end.should change(Door, :count).by(1) response.should redirect_to(edit_admin_door_path(Door.last)) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { door: { title: '' } } + post :create, params: {door: {title: ""}} end.should change(Door, :count).by(0) response.status.should eq(422) @@ -59,36 +59,36 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - door = create(:door, title: 'A Bad Title') + describe "PATCH #update" do + it "valid parameters" do + door = create(:door, title: "A Bad Title") - attributes = { title: 'A Good Title' } - patch :update, params: { id: door.to_param, door: attributes } + attributes = {title: "A Good Title"} + patch :update, params: {id: door.to_param, door: attributes} door.reload response.should redirect_to(edit_admin_door_path(door)) end - it 'invalid parameters' do - door = create(:door, title: 'A Good Title') + it "invalid parameters" do + door = create(:door, title: "A Good Title") - attributes = { title: '' } - patch :update, params: { id: door.to_param, door: attributes } + attributes = {title: ""} + patch :update, params: {id: door.to_param, door: attributes} door.reload - door.title.should eq('A Good Title') + door.title.should eq("A Good Title") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do door = create(:door) lambda do - delete :destroy, params: { id: door.to_param } + delete :destroy, params: {id: door.to_param} end.should change(Door, :count).by(-1) response.should redirect_to(admin_doors_path) diff --git a/spec/controllers/admin/elections_controller_spec.rb b/spec/controllers/admin/elections_controller_spec.rb index eb3d14a65..9a669a80e 100644 --- a/spec/controllers/admin/elections_controller_spec.rb +++ b/spec/controllers/admin/elections_controller_spec.rb @@ -1,30 +1,30 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::ElectionsController, type: :controller do let(:user) { create(:user) } allow_user_to :manage, Election - describe 'GET #show' do - it 'assigns the requested election as @election' do + describe "GET #show" do + it "assigns the requested election as @election" do election = create(:election) - get :show, params: { id: election.to_param } + get :show, params: {id: election.to_param} assigns(:election).should eq(election) response.status.should eq(200) end end - describe 'GET #new' do - it 'assigns a new election as @election' do + describe "GET #new" do + it "assigns a new election as @election" do get(:new) response.should be_success assigns(:election).new_record?.should be_truthy end end - describe 'GET #index' do - it 'renders #index' do + describe "GET #index" do + it "renders #index" do create(:election) create(:election) diff --git a/spec/controllers/admin/event_signups_controller_spec.rb b/spec/controllers/admin/event_signups_controller_spec.rb index 179c30ff6..20408876b 100644 --- a/spec/controllers/admin/event_signups_controller_spec.rb +++ b/spec/controllers/admin/event_signups_controller_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::EventSignupsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, [Event, EventSignup]) - describe 'GET #show' do - it 'displays attending users and reserves correctly + sorts by group', pending: true do + describe "GET #show" do + it "displays attending users and reserves correctly + sorts by group", pending: true do # Because of sort_by in EventUser.for_grid the records are not return # exactly according to the priority order in the views # The priority is used for all other concerns but it is overridden for the @@ -46,7 +46,7 @@ attend = [first, second, third, fourth, eu4, eu7, eu5] reserve = [] - get :show, params: { event_id: event.to_param, event_signup: signup } + get :show, params: {event_id: event.to_param, event_signup: signup} assigns(:event_signup).should eq(signup) assigns(:attending).should eq(attend) assigns(:reserves).should eq(reserve) @@ -54,14 +54,14 @@ end end - describe 'GET #export as csv' do - it 'exports properly' do + describe "GET #export as csv" do + it "exports properly" do event = create(:event, :with_signup) create(:event_user, event: event) create(:event_user, event: event) create(:event_user, event: event) - get :export, format: :csv, params: { event_id: event } + get :export, format: :csv, params: {event_id: event} response.should have_http_status(200) end end diff --git a/spec/controllers/admin/events_controller_spec.rb b/spec/controllers/admin/events_controller_spec.rb index b35259b1b..2966c450d 100644 --- a/spec/controllers/admin/events_controller_spec.rb +++ b/spec/controllers/admin/events_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::EventsController, type: :controller do let(:user) { create(:user) } @@ -9,25 +9,25 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #new' do - it 'assigns a new event as @event' do + describe "GET #new" do + it "assigns a new event as @event" do get(:new) assigns(:event).new_record?.should be_truthy assigns(:event).instance_of?(Event).should be_truthy end end - describe 'GET #edit' do - it 'assigns a edit event as @event' do + describe "GET #edit" do + it "assigns a edit event as @event" do event = create(:event) - get :edit, params: { id: event.to_param } + get :edit, params: {id: event.to_param} assigns(:event).should eq(event) end end - describe 'GET #index' do - it 'assigns events sorted as stat_date @events' do + describe "GET #index" do + it "assigns events sorted as stat_date @events" do create(:event) get(:index) @@ -36,25 +36,25 @@ end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { title_sv: 'Välkomstgasque!', - title_en: 'Welcome gasque!', - description_sv: 'Det blir mat och dryck, waow!', - description_en: 'There will be food and drinks, waow!', - location_sv: 'Kårhuset: Gasquesalen', - starts_at: 5.days.from_now, - ends_at: 7.days.from_now } + describe "POST #create" do + it "valid parameters" do + attributes = {title_sv: "Välkomstgasque!", + title_en: "Welcome gasque!", + description_sv: "Det blir mat och dryck, waow!", + description_en: "There will be food and drinks, waow!", + location_sv: "Kårhuset: Gasquesalen", + starts_at: 5.days.from_now, + ends_at: 7.days.from_now} lambda do - post :create, params: { event: attributes } + post :create, params: {event: attributes} end.should change(Event, :count).by(1) response.should redirect_to(edit_admin_event_path(Event.last)) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { event: { title_sv: 'Not enough' } } + post :create, params: {event: {title_sv: "Not enough"}} end.should change(Event, :count).by(0) response.should render_template(:new) @@ -62,34 +62,34 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - event = create(:event, title: 'Välkomstgasque') + describe "PATCH #update" do + it "valid parameters" do + event = create(:event, title: "Välkomstgasque") - attributes = { title_sv: 'Nollegasque' } - patch :update, params: { id: event.to_param, event: attributes } + attributes = {title_sv: "Nollegasque"} + patch :update, params: {id: event.to_param, event: attributes} event.reload - event.title.should eq('Nollegasque') + event.title.should eq("Nollegasque") response.should redirect_to(edit_admin_event_path(event)) end - it 'invalid parameters' do - event = create(:event, title: 'Välkomstgasque') + it "invalid parameters" do + event = create(:event, title: "Välkomstgasque") - attributes = { title_sv: '' } - patch :update, params: { id: event.to_param, event: attributes } + attributes = {title_sv: ""} + patch :update, params: {id: event.to_param, event: attributes} response.should render_template(:edit) response.status.should eq(422) end end - describe 'DELETE #destroy' do - it 'removes event' do + describe "DELETE #destroy" do + it "removes event" do event = create(:event) lambda do - delete :destroy, params: { id: event.to_param } + delete :destroy, params: {id: event.to_param} end.should change(Event, :count).by(-1) response.should redirect_to(admin_events_path) end diff --git a/spec/controllers/admin/faqs_controller_spec.rb b/spec/controllers/admin/faqs_controller_spec.rb index 3a21ce7e6..19b3d09a1 100644 --- a/spec/controllers/admin/faqs_controller_spec.rb +++ b/spec/controllers/admin/faqs_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::FaqsController, type: :controller do let(:user) { create(:admin) } @@ -9,50 +9,50 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a faq grid and categories' do - create(:faq, question: 'First faq') - create(:faq, question: 'Second faq') - create(:faq, question: 'Third faq') + describe "GET #index" do + it "assigns a faq grid and categories" do + create(:faq, question: "First faq") + create(:faq, question: "Second faq") + create(:faq, question: "Third faq") get(:index) response.status.should eq(200) end end - describe 'GET #edit' do - it 'assigns given faq as @faq' do + describe "GET #edit" do + it "assigns given faq as @faq" do faq = create(:faq) - get :edit, params: { id: faq.to_param } + get :edit, params: {id: faq.to_param} assigns(:faq).should eq(faq) end end - describe 'GET #new' do - it 'assigns a new faq as @faq' do + describe "GET #new" do + it "assigns a new faq as @faq" do get(:new) assigns(:faq).instance_of?(Faq).should be_truthy assigns(:faq).new_record?.should be_truthy end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { question: 'Vem är Hilbert?', - answer: 'Han är en älg!', - category: 'Hilbert Café' } + describe "POST #create" do + it "valid parameters" do + attributes = {question: "Vem är Hilbert?", + answer: "Han är en älg!", + category: "Hilbert Café"} lambda do - post :create, params: { faq: attributes } + post :create, params: {faq: attributes} end.should change(Faq, :count).by(1) response.should redirect_to(edit_admin_faq_path(Faq.last)) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { faq: { question: '' } } + post :create, params: {faq: {question: ""}} end.should change(Faq, :count).by(0) response.status.should eq(422) @@ -60,37 +60,37 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - faq = create(:faq, question: 'A Bad Question') + describe "PATCH #update" do + it "valid parameters" do + faq = create(:faq, question: "A Bad Question") - attributes = { question: 'A Good Question' } - patch :update, params: { id: faq.to_param, faq: attributes } + attributes = {question: "A Good Question"} + patch :update, params: {id: faq.to_param, faq: attributes} faq.reload response.should redirect_to(edit_admin_faq_path(faq)) - faq.question.should eq('A Good Question') + faq.question.should eq("A Good Question") end - it 'invalid parameters' do - faq = create(:faq, question: 'A Good Question') + it "invalid parameters" do + faq = create(:faq, question: "A Good Question") - attributes = { question: '' } - patch :update, params: { id: faq.to_param, faq: attributes } + attributes = {question: ""} + patch :update, params: {id: faq.to_param, faq: attributes} faq.reload - faq.question.should eq('A Good Question') + faq.question.should eq("A Good Question") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do faq = create(:faq) lambda do - delete :destroy, params: { id: faq.to_param } + delete :destroy, params: {id: faq.to_param} end.should change(Faq, :count).by(-1) response.should redirect_to(admin_faqs_path) diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 6c591517b..4273d66bb 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::GroupsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, Group) - describe 'GET #index' do - it 'renders index successfully' do + describe "GET #index" do + it "renders index successfully" do create(:group) create(:group) @@ -14,64 +14,64 @@ end end - describe 'GET #new' do - it 'renders successfully' do + describe "GET #new" do + it "renders successfully" do get(:new) response.should have_http_status(200) assigns(:group).should be_a_new(Group) end end - describe 'GET #edit' do - it 'renders sucessfully' do + describe "GET #edit" do + it "renders sucessfully" do group = create(:group) - get :edit, params: { id: group.to_param } + get :edit, params: {id: group.to_param} response.should have_http_status(200) assigns(:group).should eq(group) end end - describe 'POST #create' do - it 'successful with valid params' do + describe "POST #create" do + it "successful with valid params" do introduction = create(:introduction) - attributes = { introduction_id: introduction.id, name: 'Rock the Knight', number: 7 } + attributes = {introduction_id: introduction.id, name: "Rock the Knight", number: 7} lambda do - post :create, params: { group: attributes } + post :create, params: {group: attributes} end.should change(Group, :count).by(1) response.should redirect_to(new_admin_group_path) end - it 'unsuccessful with invalid params' do - attributes = { number: 37 } + it "unsuccessful with invalid params" do + attributes = {number: 37} lambda do - post :create, params: { group: attributes } + post :create, params: {group: attributes} end.should change(Group, :count).by(0) response.should have_http_status(422) response.should render_template(:new) end end - describe 'PATCH #update' do - it 'successful with valid params' do - group = create(:group, name: 'En ogodtycklig grupp', number: 36) - attributes = { name: 'En Godtycklig grupp', number: 37 } + describe "PATCH #update" do + it "successful with valid params" do + group = create(:group, name: "En ogodtycklig grupp", number: 36) + attributes = {name: "En Godtycklig grupp", number: 37} - patch :update, params: { id: group.to_param, group: attributes } + patch :update, params: {id: group.to_param, group: attributes} group.reload response.should redirect_to(admin_groups_path) - group.name.should eq('En Godtycklig grupp') + group.name.should eq("En Godtycklig grupp") group.number.should eq(37) end - it 'unsuccessful with invalid params' do + it "unsuccessful with invalid params" do group = create(:group, number: 37) - attributes = { number: -1 } + attributes = {number: -1} - patch :update, params: { id: group.to_param, group: attributes } + patch :update, params: {id: group.to_param, group: attributes} group.reload group.number.should eq(37) @@ -80,12 +80,12 @@ end end - describe 'DELETE #destroy' do - it 'deletes group' do + describe "DELETE #destroy" do + it "deletes group" do group = create(:group) lambda do - delete :destroy, params: { id: group.to_param } + delete :destroy, params: {id: group.to_param} end.should change(Group, :count).by(-1) response.should redirect_to(admin_groups_path) end diff --git a/spec/controllers/admin/introductions_controller_spec.rb b/spec/controllers/admin/introductions_controller_spec.rb index cf17a1986..2f2e5179a 100644 --- a/spec/controllers/admin/introductions_controller_spec.rb +++ b/spec/controllers/admin/introductions_controller_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::IntroductionsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, Introduction) - describe 'GET #index' do - it 'renders index successfully' do + describe "GET #index" do + it "renders index successfully" do create(:introduction) create(:introduction) @@ -14,78 +14,78 @@ end end - describe 'GET #new' do - it 'renders successfully' do + describe "GET #new" do + it "renders successfully" do get(:new) response.should have_http_status(200) assigns(:introduction).should be_a_new(Introduction) end end - describe 'GET #edit' do - it 'renders sucessfully' do - introduction = create(:introduction, slug: 'spindel') + describe "GET #edit" do + it "renders sucessfully" do + introduction = create(:introduction, slug: "spindel") - get :edit, params: { id: 'spindel' } + get :edit, params: {id: "spindel"} response.should have_http_status(200) assigns(:introduction).should eq(introduction) end end - describe 'POST #create' do - it 'successful with valid params' do - attributes = { title_sv: 'Spindelnollning', title_en: 'Spider introduction', - slug: :spindel, start: 10.days.from_now, - stop: 37.days.from_now, description: 'Spindlarna kommer!' } + describe "POST #create" do + it "successful with valid params" do + attributes = {title_sv: "Spindelnollning", title_en: "Spider introduction", + slug: :spindel, start: 10.days.from_now, + stop: 37.days.from_now, description: "Spindlarna kommer!"} lambda do - post :create, params: { introduction: attributes } + post :create, params: {introduction: attributes} end.should change(Introduction, :count).by(1) response.should redirect_to(edit_admin_introduction_path(Introduction.last)) end - it 'unsuccessful with invalid params' do - attributes = { title_sv: 'Spindelnollning - not enough' } + it "unsuccessful with invalid params" do + attributes = {title_sv: "Spindelnollning - not enough"} lambda do - post :create, params: { introduction: attributes } + post :create, params: {introduction: attributes} end.should change(Introduction, :count).by(0) response.should have_http_status(422) response.should render_template(:new) end end - describe 'PATCH #update' do - it 'successful with valid params' do - introduction = create(:introduction, title_sv: 'Piratnollning') - attributes = { title_sv: 'Spindelnollning' } + describe "PATCH #update" do + it "successful with valid params" do + introduction = create(:introduction, title_sv: "Piratnollning") + attributes = {title_sv: "Spindelnollning"} - patch :update, params: { id: introduction.to_param, introduction: attributes } + patch :update, params: {id: introduction.to_param, introduction: attributes} introduction.reload response.should redirect_to(edit_admin_introduction_path(Introduction.last)) - introduction.title_sv.should eq('Spindelnollning') + introduction.title_sv.should eq("Spindelnollning") end - it 'unsuccessful with invalid params' do - introduction = create(:introduction, title_sv: 'Spindelnollning') - attributes = { title_sv: nil } + it "unsuccessful with invalid params" do + introduction = create(:introduction, title_sv: "Spindelnollning") + attributes = {title_sv: nil} - patch :update, params: { id: introduction.to_param, introduction: attributes } + patch :update, params: {id: introduction.to_param, introduction: attributes} introduction.reload - introduction.title_sv.should eq('Spindelnollning') + introduction.title_sv.should eq("Spindelnollning") response.should have_http_status(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'deletes introduction' do + describe "DELETE #destroy" do + it "deletes introduction" do introduction = create(:introduction) lambda do - delete :destroy, params: { id: introduction.to_param } + delete :destroy, params: {id: introduction.to_param} end.should change(Introduction, :count).by(-1) response.should redirect_to(admin_introductions_path) end diff --git a/spec/controllers/admin/mail_aliases_controller_spec.rb b/spec/controllers/admin/mail_aliases_controller_spec.rb index 1566aa3cb..addf88f0e 100644 --- a/spec/controllers/admin/mail_aliases_controller_spec.rb +++ b/spec/controllers/admin/mail_aliases_controller_spec.rb @@ -1,34 +1,34 @@ -require 'rails_helper' +require "rails_helper" describe Admin::MailAliasesController, type: :controller do - describe '#index' do + describe "#index" do allow_user_to :manage, MailAlias - it 'doesn\'t crash when requesting index' do + it "doesn't crash when requesting index" do get :index response.status.should eq(200) end - it 'presents the correct list for an example query' do + it "presents the correct list for an example query" do m = create(:mail_alias, - username: 'boss', - domain: 'fsektionen.se', - target: 'johan@forberg.se') + username: "boss", + domain: "fsektionen.se", + target: "johan@forberg.se") - get :search, format: :json, params: { q: 'boss' } + get :search, format: :json, params: {q: "boss"} response.status.should eq(200) assigns(:aliases).should eq([m]) end end - describe '#update' do + describe "#update" do allow_user_to :manage, MailAlias - it 'can destroy records' do + it "can destroy records" do c = create :mail_alias - attributes = { username: c.username, domain: c.domain, targets: [] } + attributes = {username: c.username, domain: c.domain, targets: []} - put :update, format: :json, params: { mail_alias: attributes } + put :update, format: :json, params: {mail_alias: attributes} response.status.should eq(200) MailAlias.count.should eq(0) diff --git a/spec/controllers/admin/menus_controller_spec.rb b/spec/controllers/admin/menus_controller_spec.rb index 16c090288..1676ee56c 100644 --- a/spec/controllers/admin/menus_controller_spec.rb +++ b/spec/controllers/admin/menus_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::MenusController, type: :controller do let(:user) { create(:admin) } @@ -9,8 +9,8 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a menu grid and categories' do + describe "GET #index" do + it "assigns a menu grid and categories" do create(:menu) get(:index) @@ -18,45 +18,45 @@ end end - describe 'GET #edit' do - it 'assigns given menu as @menu' do + describe "GET #edit" do + it "assigns given menu as @menu" do menu = create(:menu) - get :edit, params: { id: menu.to_param } + get :edit, params: {id: menu.to_param} assigns(:menu).should eq(menu) end end - describe 'GET #new' do - it 'assigns a new menu as @menu' do + describe "GET #new" do + it "assigns a new menu as @menu" do get(:new) assigns(:menu).instance_of?(Menu).should be_truthy assigns(:menu).new_record?.should be_truthy end end - describe 'POST #create' do - it 'valid parameters' do + describe "POST #create" do + it "valid parameters" do main = create(:main_menu) - attributes = { name_sv: 'Bildgalleri', - main_menu_id: main.id, - index: 1337, - link: '/galleri', - visible: true, - turbolinks: false, - blank_p: false } + attributes = {name_sv: "Bildgalleri", + main_menu_id: main.id, + index: 1337, + link: "/galleri", + visible: true, + turbolinks: false, + blank_p: false} lambda do - post :create, params: { menu: attributes } + post :create, params: {menu: attributes} end.should change(Menu, :count).by(1) response.should redirect_to(admin_menus_path) - Menu.last.name.should eq('Bildgalleri') + Menu.last.name.should eq("Bildgalleri") end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { menu: { name_sv: '' } } + post :create, params: {menu: {name_sv: ""}} end.should change(Menu, :count).by(0) response.status.should eq(422) @@ -64,37 +64,37 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - menu = create(:menu, name: 'Aftonbladet') + describe "PATCH #update" do + it "valid parameters" do + menu = create(:menu, name: "Aftonbladet") - attributes = { name_sv: 'Bildgalleri' } - patch :update, params: { id: menu.to_param, menu: attributes } + attributes = {name_sv: "Bildgalleri"} + patch :update, params: {id: menu.to_param, menu: attributes} menu.reload response.should redirect_to(edit_admin_menu_path(menu)) - menu.name.should eq('Bildgalleri') + menu.name.should eq("Bildgalleri") end - it 'invalid parameters' do - menu = create(:menu, name: 'Bildgalleri') + it "invalid parameters" do + menu = create(:menu, name: "Bildgalleri") - attributes = { name_sv: '' } - patch :update, params: { id: menu.to_param, menu: attributes } + attributes = {name_sv: ""} + patch :update, params: {id: menu.to_param, menu: attributes} menu.reload - menu.name.should eq('Bildgalleri') + menu.name.should eq("Bildgalleri") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do menu = create(:menu) lambda do - delete :destroy, params: { id: menu.to_param } + delete :destroy, params: {id: menu.to_param} end.should change(Menu, :count).by(-1) response.should redirect_to(admin_menus_path) diff --git a/spec/controllers/admin/news_controller_spec.rb b/spec/controllers/admin/news_controller_spec.rb index 36a18e749..4a561b1e4 100644 --- a/spec/controllers/admin/news_controller_spec.rb +++ b/spec/controllers/admin/news_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::NewsController, type: :controller do let(:user) { create(:user) } @@ -10,16 +10,16 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #new' do - it 'assigns a new news as @news' do + describe "GET #new" do + it "assigns a new news as @news" do get(:new) assigns(:news).new_record?.should be_truthy assigns(:news).instance_of?(News).should be_truthy end end - describe 'GET #index' do - it 'assigns news sorted as @news' do + describe "GET #index" do + it "assigns news sorted as @news" do create(:news) create(:news) @@ -28,28 +28,28 @@ end end - describe 'POST #create' do - it 'posts new news' do - attributes = { title_sv: 'Sektionsmöte wohoo!', - content_sv: 'Detta är en text om sektionsmötet', - url: 'https://rostsystem.se' } + describe "POST #create" do + it "posts new news" do + attributes = {title_sv: "Sektionsmöte wohoo!", + content_sv: "Detta är en text om sektionsmötet", + url: "https://rostsystem.se"} lambda do - post :create, params: { news: attributes } + post :create, params: {news: attributes} end.should change(News, :count).by(1) response.should redirect_to(edit_admin_news_path(News.last)) end end - describe 'PATCH #update' do - it 'update news' do - news = create(:news, title: 'Vårterminsmöte') + describe "PATCH #update" do + it "update news" do + news = create(:news, title: "Vårterminsmöte") - attributes = { title_sv: 'Höstterminsmöte' } - patch :update, params: { id: news.to_param, news: attributes } + attributes = {title_sv: "Höstterminsmöte"} + patch :update, params: {id: news.to_param, news: attributes} news.reload - news.title.should eq('Höstterminsmöte') + news.title.should eq("Höstterminsmöte") response.should redirect_to(edit_admin_news_path(news)) end end diff --git a/spec/controllers/admin/page_elements_controller_spec.rb b/spec/controllers/admin/page_elements_controller_spec.rb index 22a5598ce..9b63050b5 100644 --- a/spec/controllers/admin/page_elements_controller_spec.rb +++ b/spec/controllers/admin/page_elements_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::PageElementsController, type: :controller do let(:user) { create(:user) } @@ -10,11 +10,11 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #new' do - it 'assigns a new page_element as @page_element' do + describe "GET #new" do + it "assigns a new page_element as @page_element" do page = create(:page) - get :new, params: { page_id: page.to_param } + get :new, params: {page_id: page.to_param} assigns(:page).should eq(page) assigns(:page_element).new_record?.should be_truthy @@ -22,12 +22,12 @@ end end - describe 'GET #edit' do - it 'assigns the right page_element' do + describe "GET #edit" do + it "assigns the right page_element" do page = create(:page) page_element = create(:page_element, page: page) - get :edit, params: { page_id: page.to_param, id: page_element.to_param } + get :edit, params: {page_id: page.to_param, id: page_element.to_param} assigns(:page_element).should eq(page_element) @@ -35,41 +35,41 @@ end end - describe 'GET #index' do - it 'assigns page_element sorted as @page_elements' do + describe "GET #index" do + it "assigns page_element sorted as @page_elements" do page = create(:page) create(:page_element, page: page) create(:page_element, page: page) - get :index, params: { page_id: page.to_param } + get :index, params: {page_id: page.to_param} response.should be_success end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do page = create(:page) - attributes = { header_sv: 'About', - text_sv: '## Kom ihåg mig', - text_en: '## Remember remember', - element_type: PageElement::TEXT, - visible: true, - index: 10 } + attributes = {header_sv: "About", + text_sv: "## Kom ihåg mig", + text_en: "## Remember remember", + element_type: PageElement::TEXT, + visible: true, + index: 10} lambda do - post :create, params: { page_id: page, page_element: attributes } + post :create, params: {page_id: page, page_element: attributes} end.should change(PageElement, :count).by(1) response.should redirect_to(edit_admin_page_page_element_path(page, PageElement.last)) end - it 'invalid params' do + it "invalid params" do page = create(:page) - attributes = { header: 'About', - element_type: '' } + attributes = {header: "About", + element_type: ""} lambda do - post :create, params: { page_id: page, page_element: attributes } + post :create, params: {page_id: page, page_element: attributes} end.should change(PageElement, :count).by(0) response.status.should eq(422) @@ -77,29 +77,29 @@ end end - describe 'PATCH #update' do - it 'update page_element' do + describe "PATCH #update" do + it "update page_element" do page = create(:page) element = create(:page_element, page: page, - headline_sv: 'Om', - headline_en: 'About') + headline_sv: "Om", + headline_en: "About") - patch :update, params: { id: element.to_param, - page_id: page.to_param, - page_element: { headline_sv: 'Inte om' } } + patch :update, params: {id: element.to_param, + page_id: page.to_param, + page_element: {headline_sv: "Inte om"}} element.reload - element.headline.should eq('Inte om') + element.headline.should eq("Inte om") response.should redirect_to(edit_admin_page_page_element_path(page, element)) end - it 'update page_element' do + it "update page_element" do page = create(:page) element = create(:page_element, page: page, element_type: PageElement::TEXT) - patch :update, params: { id: element.to_param, - page_id: page.to_param, - page_element: { element_type: '' } } + patch :update, params: {id: element.to_param, + page_id: page.to_param, + page_element: {element_type: ""}} element.reload element.element_type.should eq(PageElement::TEXT) @@ -108,13 +108,13 @@ end end - describe 'DELETE #destroy' do - it 'deletes page_element' do + describe "DELETE #destroy" do + it "deletes page_element" do page = create(:page) element = create(:page_element, page: page) lambda do - delete :destroy, params: { page_id: page, id: element } + delete :destroy, params: {page_id: page, id: element} end.should change(PageElement, :count).by(-1) response.should redirect_to(edit_admin_page_path(page)) diff --git a/spec/controllers/admin/pages_controller_spec.rb b/spec/controllers/admin/pages_controller_spec.rb index cbfb37ab9..9821b5656 100644 --- a/spec/controllers/admin/pages_controller_spec.rb +++ b/spec/controllers/admin/pages_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::PagesController, type: :controller do let(:user) { create(:user) } @@ -9,44 +9,44 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #new' do - it 'assigns a new page as @page' do + describe "GET #new" do + it "assigns a new page as @page" do get(:new) assigns(:page).new_record?.should be_truthy assigns(:page).instance_of?(Page).should be_truthy end end - describe 'GET #index' do - it 'assigns pages sorted as @pages' do - create(:page, title_sv: 'First') - create(:page, title_sv: 'Third') - create(:page, title_sv: 'Second') + describe "GET #index" do + it "assigns pages sorted as @pages" do + create(:page, title_sv: "First") + create(:page, title_sv: "Third") + create(:page, title_sv: "Second") get(:index) response.should be_success end end - describe 'POST #create' do - it 'valid params' do - attributes = { title_sv: 'Projekt', - title_en: 'Project', - url: 'projekt-url', - public: true, - visible: true } + describe "POST #create" do + it "valid params" do + attributes = {title_sv: "Projekt", + title_en: "Project", + url: "projekt-url", + public: true, + visible: true} lambda do - post :create, params: { page: attributes } + post :create, params: {page: attributes} end.should change(Page, :count).by(1) response.should redirect_to(edit_admin_page_path(Page.last)) end - it 'invalid params' do - attributes = { title_sv: 'Projekt', url: '' } + it "invalid params" do + attributes = {title_sv: "Projekt", url: ""} lambda do - post :create, params: { page: attributes } + post :create, params: {page: attributes} end.should change(Page, :count).by(0) response.status.should eq(422) @@ -54,63 +54,63 @@ end end - describe 'PATCH #update' do - it 'valid params' do - page = create(:page, url: 'en_bra_url') - attributes = { url: 'en_annan_url' } + describe "PATCH #update" do + it "valid params" do + page = create(:page, url: "en_bra_url") + attributes = {url: "en_annan_url"} - patch :update, params: { id: page.to_param, page: attributes } + patch :update, params: {id: page.to_param, page: attributes} page.reload - page.url.should eq('en_annan_url') + page.url.should eq("en_annan_url") response.should redirect_to(edit_admin_page_path(page)) end - it 'invalid params' do - page = create(:page, url: 'en_bra_url') - attributes = { url: '' } + it "invalid params" do + page = create(:page, url: "en_bra_url") + attributes = {url: ""} - patch :update, params: { id: page.to_param, page: attributes } + patch :update, params: {id: page.to_param, page: attributes} page.reload - page.url.should eq('en_bra_url') + page.url.should eq("en_bra_url") response.status.should eq(422) response.should render_template(:edit) end - it 'uploads image' do + it "uploads image" do page = create(:page) - image = [Rack::Test::UploadedFile.new(File.open('app/assets/images/hilbert.jpg'))] - attributes = { image_upload: image } + image = [Rack::Test::UploadedFile.new(File.open("app/assets/images/hilbert.jpg"))] + attributes = {image_upload: image} lambda do - patch :update, params: { id: page.to_param, page: attributes } + patch :update, params: {id: page.to_param, page: attributes} end.should change(PageImage, :count).by(1) response.should redirect_to(edit_admin_page_path(page)) end end - describe 'DELETE #destroy' do - it 'delets page' do + describe "DELETE #destroy" do + it "delets page" do page = create(:page) lambda do - delete :destroy, params: { id: page.to_param } + delete :destroy, params: {id: page.to_param} end.should change(Page, :count).by(-1) response.should redirect_to(admin_pages_path) end end - describe 'DELETE #destroy_image' do - it 'deletes image' do + describe "DELETE #destroy_image" do + it "deletes image" do page = create(:page) image = create(:page_image, page: page) image_id = image.id lambda do - delete :destroy_image, xhr: true, format: :js, params: { id: page.to_param, - image_id: image.to_param } + delete :destroy_image, xhr: true, format: :js, params: {id: page.to_param, + image_id: image.to_param} end.should change(PageImage, :count).by(-1) assigns(:id).should eq(image_id.to_s) diff --git a/spec/controllers/admin/permissions_controller_spec.rb b/spec/controllers/admin/permissions_controller_spec.rb index c88f30fd9..9a67ef771 100644 --- a/spec/controllers/admin/permissions_controller_spec.rb +++ b/spec/controllers/admin/permissions_controller_spec.rb @@ -1,50 +1,50 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::PermissionsController, type: :controller do allow_user_to(:manage, [Permission, PermissionPost, Post]) - describe 'GET #index' do - it 'assigns a permission grid and categories' do + describe "GET #index" do + it "assigns a permission grid and categories" do council = create(:council) - create(:post, title: 'Bpost', council: council) - the_post = create(:post, title: 'Apost', council: council) + create(:post, title: "Bpost", council: council) + the_post = create(:post, title: "Apost", council: council) create(:permission_post, post: the_post) get(:index) response.status.should eq(200) - assigns(:posts).map(&:title).should eq(['Apost', 'Bpost']) + assigns(:posts).map(&:title).should eq(["Apost", "Bpost"]) end end - describe 'GET #show_post' do - it 'assigns permissions as @permission, sorted by subject_class' do + describe "GET #show_post" do + it "assigns permissions as @permission, sorted by subject_class" do the_post = create(:post) - create(:permission, name: 'Second', subject_class: 'tool') - permission = create(:permission, name: 'First', subject_class: 'cafe') + create(:permission, name: "Second", subject_class: "tool") + permission = create(:permission, name: "First", subject_class: "cafe") create(:permission_post, post: the_post, permission: permission) - get :show_post, params: { post_id: the_post.to_param } - assigns(:permissions).map(&:name).should eq(['First', 'Second']) + get :show_post, params: {post_id: the_post.to_param} + assigns(:permissions).map(&:name).should eq(["First", "Second"]) end end - describe 'PATCH #update_post' do - it 'valid parameters' do + describe "PATCH #update_post" do + it "valid parameters" do the_post = create(:post) - permission = create(:permission, name: 'Old') + permission = create(:permission, name: "Old") create(:permission_post, post: the_post, permission: permission) - the_post.permissions.map(&:name).should eq(['Old']) + the_post.permissions.map(&:name).should eq(["Old"]) - other_permission = create(:permission, name: 'New') + other_permission = create(:permission, name: "New") - post_attributes = { permission_ids: [other_permission.to_param] } - patch :update_post, params: { post_id: the_post.to_param, post: post_attributes } + post_attributes = {permission_ids: [other_permission.to_param]} + patch :update_post, params: {post_id: the_post.to_param, post: post_attributes} response.should redirect_to(admin_permissions_path) the_post.reload - the_post.permissions.map(&:name).should eq(['New']) + the_post.permissions.map(&:name).should eq(["New"]) end end end diff --git a/spec/controllers/admin/posts_controller_spec.rb b/spec/controllers/admin/posts_controller_spec.rb index fd0049c86..dbac56a62 100644 --- a/spec/controllers/admin/posts_controller_spec.rb +++ b/spec/controllers/admin/posts_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::PostsController, type: :controller do let(:user) { create(:user) } @@ -10,21 +10,21 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #edit' do - it 'assigns the requested post as @post' do + describe "GET #edit" do + it "assigns the requested post as @post" do council = create(:council) post = create(:post, council: council) - get :edit, params: { id: post.to_param, council_id: council.to_param } + get :edit, params: {id: post.to_param, council_id: council.to_param} assigns(:post).should eq(post) response.status.should eq(200) end end - describe 'GET #new' do - it 'assigns a new post as @post' do + describe "GET #new" do + it "assigns a new post as @post" do council = create(:council) - get :new, params: { council_id: council.to_param } + get :new, params: {council_id: council.to_param} assigns(:post).new_record?.should be_truthy assigns(:post).instance_of?(Post).should be_truthy @@ -32,44 +32,44 @@ end end - describe 'GET #index' do - it 'assigns post sorted as @posts' do + describe "GET #index" do + it "assigns post sorted as @posts" do council = create(:council) create(:post, council: council) create(:post, council: council) create(:post, council: council) - get :index, params: { council_id: council.to_param } + get :index, params: {council_id: council.to_param} response.status.should eq(200) assigns(:posts).should eq(Post.all) end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do council = create(:council) - attributes = { title_sv: 'Spindelman', - limit: 5, - rec_limit: 10, - semster: Post::AUTUMN, - elected_by: Post::BOARD, - description_sv: 'En webbmästare' } + attributes = {title_sv: "Spindelman", + limit: 5, + rec_limit: 10, + semster: Post::AUTUMN, + elected_by: Post::BOARD, + description_sv: "En webbmästare"} lambda do - post :create, params: { council_id: council.to_param, post: attributes } + post :create, params: {council_id: council.to_param, post: attributes} end.should change(Post, :count).by(1) response.should redirect_to(admin_council_posts_path(council)) end - it 'invalid params' do + it "invalid params" do council = create(:council) - attributes = { title_sv: '', - description_sv: 'En webbmästare' } + attributes = {title_sv: "", + description_sv: "En webbmästare"} lambda do - post :create, params: { council_id: council.to_param, post: attributes } + post :create, params: {council_id: council.to_param, post: attributes} end.should change(Post, :count).by(0) response.status.should eq(422) @@ -77,42 +77,42 @@ end end - describe 'PATCH #update' do - it 'update post' do + describe "PATCH #update" do + it "update post" do council = create(:council) - post = create(:post, council: council, title: 'Spindelman') + post = create(:post, council: council, title: "Spindelman") - patch :update, params: { council_id: council.to_param, - id: post.to_param, - post: { title_sv: 'Deadpool' } } + patch :update, params: {council_id: council.to_param, + id: post.to_param, + post: {title_sv: "Deadpool"}} post.reload - post.title.should eq('Deadpool') + post.title.should eq("Deadpool") response.should redirect_to(edit_admin_council_post_path(council, post)) end - it 'invalid params' do + it "invalid params" do council = create(:council) - post = create(:post, council: council, title: 'Spindelman') + post = create(:post, council: council, title: "Spindelman") - patch :update, params: { council_id: council.to_param, - id: post.to_param, - post: { title_sv: '' } } + patch :update, params: {council_id: council.to_param, + id: post.to_param, + post: {title_sv: ""}} post.reload - post.title.should eq('Spindelman') + post.title.should eq("Spindelman") response.should render_template(:edit) response.status.should eq(422) end end - describe 'DELETE #destroy' do - it 'works' do + describe "DELETE #destroy" do + it "works" do council = create(:council) post = create(:post, council: council) lambda do - delete :destroy, params: { council_id: council.to_param, id: post.to_param } + delete :destroy, params: {council_id: council.to_param, id: post.to_param} end.should change(Post, :count).by(-1) response.should redirect_to(admin_council_posts_path(council)) diff --git a/spec/controllers/admin/rents_controller_spec.rb b/spec/controllers/admin/rents_controller_spec.rb index 03481e891..0ece0f7c1 100644 --- a/spec/controllers/admin/rents_controller_spec.rb +++ b/spec/controllers/admin/rents_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::RentsController, type: :controller do let(:admin) { create(:user) } @@ -9,16 +9,16 @@ allow_user_to :manage, Rent - describe 'GET #show' do - it 'assigns the requested rent as @rent' do + describe "GET #show" do + it "assigns the requested rent as @rent" do rent = create(:rent) - get :show, params: { id: rent.to_param } + get :show, params: {id: rent.to_param} assigns(:rent).should eq(rent) end end - describe 'GET #new' do + describe "GET #new" do it :succeeds do get :new @@ -28,24 +28,24 @@ end end - describe 'POST #create' do - it 'valid parameters' do + describe "POST #create" do + it "valid parameters" do user = create(:user) - attributes = { d_from: 1.hours.from_now, - d_til: 10.hours.from_now, - purpose: 'Åka till ikea', - user_id: user.id } + attributes = {d_from: 1.hours.from_now, + d_til: 10.hours.from_now, + purpose: "Åka till ikea", + user_id: user.id} lambda do - post :create, params: { rent: attributes } + post :create, params: {rent: attributes} end.should change(Rent, :count).by(1) response.should redirect_to([:admin, Rent.last]) assigns(:rent).user.should eq(user) end - it 'invalid params' do + it "invalid params" do lambda do - post :create, params: { rent: { d_from: nil } } + post :create, params: {rent: {d_from: nil}} end.should change(Rent, :count).by(0) response.status.should eq(422) @@ -53,22 +53,22 @@ end end - describe 'PATCH #update' do - it 'valid params' do + describe "PATCH #update" do + it "valid params" do user = create(:user) - rent = create(:rent, user: user, purpose: 'Not IKEA') - attributes = { purpose: 'Indeed IKEA' } - patch :update, params: { id: rent.to_param, rent: attributes } + rent = create(:rent, user: user, purpose: "Not IKEA") + attributes = {purpose: "Indeed IKEA"} + patch :update, params: {id: rent.to_param, rent: attributes} assigns(:rent).should eq(rent) response.should redirect_to(admin_rent_path(rent)) end - it 'invalid params' do + it "invalid params" do user = create(:user) - rent = create(:rent, user: user, purpose: 'Not IKEA') - attributes = { purpose: '' } - patch :update, params: { id: rent.to_param, rent: attributes } + rent = create(:rent, user: user, purpose: "Not IKEA") + attributes = {purpose: ""} + patch :update, params: {id: rent.to_param, rent: attributes} assigns(:rent).should eq(rent) response.status.should eq(422) @@ -76,12 +76,12 @@ end end - describe 'DELETE #destroy' do - it 'destroys the requested rent' do + describe "DELETE #destroy" do + it "destroys the requested rent" do rent = create(:rent) lambda do - delete :destroy, format: :html, params: { id: rent.to_param } + delete :destroy, format: :html, params: {id: rent.to_param} end.should change(Rent, :count).by(-1) response.should redirect_to(:admin_rents) diff --git a/spec/controllers/admin/short_links_controller_spec.rb b/spec/controllers/admin/short_links_controller_spec.rb index 10492f5d5..8f5b4b054 100644 --- a/spec/controllers/admin/short_links_controller_spec.rb +++ b/spec/controllers/admin/short_links_controller_spec.rb @@ -1,24 +1,24 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::ShortLinksController, type: :controller do allow_user_to(:manage, ShortLink) - describe '#index' do - it 'renders page succesfully' do - create(:short_link, link: 'test') + describe "#index" do + it "renders page succesfully" do + create(:short_link, link: "test") get(:index) response.status.should eq(200) - assigns(:short_links).map(&:link).should eq(['test']) + assigns(:short_links).map(&:link).should eq(["test"]) end end - describe '#create' do + describe "#create" do allow_user_to :manage, ShortLink - it 'creates new shortlink for new link' do + it "creates new shortlink for new link" do sl = build :short_link - post :create, params: { short_link: sl.attributes } + post :create, params: {short_link: sl.attributes} response.status.should eq(302) @@ -27,11 +27,11 @@ created_sl.target.should eq(sl.target) end - it 'updates old shortlink for old link' do + it "updates old shortlink for old link" do old_sl = create :short_link - new_sl = build :short_link, target: 'newurl.com' + new_sl = build :short_link, target: "newurl.com" - post :create, params: { short_link: new_sl.attributes } + post :create, params: {short_link: new_sl.attributes} response.status.should eq(302) @@ -41,11 +41,11 @@ end end - describe '#destroy' do - it 'removes short_link' do + describe "#destroy" do + it "removes short_link" do short_link = create(:short_link) lambda do - delete :destroy, params: { id: short_link.to_param } + delete :destroy, params: {id: short_link.to_param} end.should change(ShortLink, :count).by(-1) response.should redirect_to(admin_short_links_path) diff --git a/spec/controllers/admin/tool_rentings_controller_spec.rb b/spec/controllers/admin/tool_rentings_controller_spec.rb index 566b9771a..06f8d3e54 100644 --- a/spec/controllers/admin/tool_rentings_controller_spec.rb +++ b/spec/controllers/admin/tool_rentings_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::ToolRentingsController, type: :controller do let(:user) { create(:user) } @@ -9,25 +9,25 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'POST #create' do - it 'valid parameters' do + describe "POST #create" do + it "valid parameters" do tool = create(:tool) attributes = attributes_for(:tool_renting, tool: tool) lambda do - post :create, params: { tool_id: tool, tool_renting: attributes } + post :create, params: {tool_id: tool, tool_renting: attributes} end.should change(ToolRenting, :count).by(1) response.should redirect_to(admin_tool_path(tool)) ToolRenting.last.user_id.should eq(attributes[:user_id]) end - it 'invalid parameters' do + it "invalid parameters" do tool = create(:tool) attributes = attributes_for(:tool_renting, user_id: nil, tool: tool) lambda do - post :create, params: { tool_id: tool, tool_renting: attributes } + post :create, params: {tool_id: tool, tool_renting: attributes} end.should change(ToolRenting, :count).by(0) response.status.should eq(422) @@ -35,44 +35,44 @@ end end - describe 'GET #new' do - it 'loads new view properly' do + describe "GET #new" do + it "loads new view properly" do tool = create(:tool) rent = create(:tool_renting, tool: tool) - get :new, params: { id: rent.to_param, tool_id: tool.to_param } + get :new, params: {id: rent.to_param, tool_id: tool.to_param} response.status.should eq(200) end end - describe 'GET #edit' do - it 'loads edit view properly' do + describe "GET #edit" do + it "loads edit view properly" do tool = create(:tool) rent = create(:tool_renting, tool: tool) - get :edit, params: { id: rent.to_param, tool_id: tool.to_param } + get :edit, params: {id: rent.to_param, tool_id: tool.to_param} response.status.should eq(200) end end - describe 'PATCH #update' do - it 'valid parameters' do + describe "PATCH #update" do + it "valid parameters" do tool = create(:tool) rent = create(:tool_renting, tool: tool, user_id: 1) - attributes = { user_id: 2 } + attributes = {user_id: 2} - patch :update, params: { tool_id: tool, id: rent, tool_renting: attributes } + patch :update, params: {tool_id: tool, id: rent, tool_renting: attributes} rent.reload rent.user_id.should eq(2) response.should redirect_to(admin_tool_path(tool)) end - it 'invalid parameters' do + it "invalid parameters" do tool = create(:tool) rent = create(:tool_renting, tool: tool) user_id_before = rent.user_id attributes = attributes_for(:tool_renting, user_id: nil, tool: tool) - patch :update, params: { tool_id: tool, id: rent, tool_renting: attributes } + patch :update, params: {tool_id: tool, id: rent, tool_renting: attributes} rent.reload rent.user_id.should eq(user_id_before) @@ -81,13 +81,13 @@ end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do tool = create(:tool) rent = create(:tool_renting, tool: tool) lambda do - delete :destroy, params: { tool_id: tool, id: rent } + delete :destroy, params: {tool_id: tool, id: rent} end.should change(ToolRenting, :count).by(-1) response.should redirect_to(admin_tool_path(tool)) diff --git a/spec/controllers/admin/tools_controller_spec.rb b/spec/controllers/admin/tools_controller_spec.rb index 784b8b496..3ff16d3bf 100644 --- a/spec/controllers/admin/tools_controller_spec.rb +++ b/spec/controllers/admin/tools_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::ToolsController, type: :controller do let(:user) { create(:user) } @@ -9,42 +9,42 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #index' do - it 'loads index view properly' do + describe "GET #index" do + it "loads index view properly" do get :index response.status.should eq(200) end end - describe 'GET #show' do - it 'loads show view properly' do + describe "GET #show" do + it "loads show view properly" do tool = create(:tool) create(:tool_renting, tool: tool) create(:tool_renting, tool: tool) - get :show, params: { id: tool.to_param } + get :show, params: {id: tool.to_param} response.status.should eq(200) end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { title: 'Skruvmejsel', - description: 'Skruvar skruvar', - total: 2 } + describe "POST #create" do + it "valid parameters" do + attributes = {title: "Skruvmejsel", + description: "Skruvar skruvar", + total: 2} lambda do - post :create, params: { tool: attributes } + post :create, params: {tool: attributes} end.should change(Tool, :count).by(1) response.should redirect_to(admin_tools_path) - Tool.last.title.should eq('Skruvmejsel') + Tool.last.title.should eq("Skruvmejsel") end - it 'invalid parameters' do - attributes = { title: nil } + it "invalid parameters" do + attributes = {title: nil} lambda do - post :create, params: { tool: attributes } + post :create, params: {tool: attributes} end.should change(Tool, :count).by(0) response.status.should eq(422) @@ -52,53 +52,53 @@ end end - describe 'GET #new' do - it 'loads new view properly' do + describe "GET #new" do + it "loads new view properly" do get :new response.status.should eq(200) end end - describe 'GET #edit' do - it 'loads edit view properly' do + describe "GET #edit" do + it "loads edit view properly" do tool = create(:tool) - get :edit, params: { id: tool.to_param } + get :edit, params: {id: tool.to_param} assigns(:tool).should eq(tool) response.status.should eq(200) end end - describe 'PATCH #update' do - it 'valid parameters' do - tool = create(:tool, title: 'Skruvmejsel') - attributes = { title: 'Hammare' } + describe "PATCH #update" do + it "valid parameters" do + tool = create(:tool, title: "Skruvmejsel") + attributes = {title: "Hammare"} - patch :update, params: { id: tool.to_param, tool: attributes } + patch :update, params: {id: tool.to_param, tool: attributes} tool.reload - tool.title.should eq('Hammare') + tool.title.should eq("Hammare") response.should redirect_to(admin_tool_path(tool)) end - it 'invalid parameters' do - tool = create(:tool, title: 'Skruvmejsel') - attributes = { title: nil } + it "invalid parameters" do + tool = create(:tool, title: "Skruvmejsel") + attributes = {title: nil} - patch :update, params: { id: tool.to_param, tool: attributes } + patch :update, params: {id: tool.to_param, tool: attributes} tool.reload - tool.title.should eq('Skruvmejsel') + tool.title.should eq("Skruvmejsel") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'valid parameters' do + describe "DELETE #destroy" do + it "valid parameters" do tool = create(:tool) lambda do - delete :destroy, params: { id: tool.to_param } + delete :destroy, params: {id: tool.to_param} end.should change(Tool, :count).by(-1) response.should redirect_to(admin_tools_path) diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index adb930340..d8d21a6d7 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -1,3 +1,3 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::UsersController, type: :controller do end diff --git a/spec/controllers/admin/work_posts_controller_spec.rb b/spec/controllers/admin/work_posts_controller_spec.rb index 587d3f158..f2640d90f 100644 --- a/spec/controllers/admin/work_posts_controller_spec.rb +++ b/spec/controllers/admin/work_posts_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Admin::WorkPostsController, type: :controller do let(:user) { create(:admin) } @@ -9,45 +9,45 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a work_post grid' do - create(:work_post, title: 'Second work_post') - create(:work_post, title: 'First work_post') - create(:work_post, title: 'Third work_post') + describe "GET #index" do + it "assigns a work_post grid" do + create(:work_post, title: "Second work_post") + create(:work_post, title: "First work_post") + create(:work_post, title: "Third work_post") get(:index) response.status.should eq(200) end end - describe 'GET #edit' do - it 'assigns given work_post as @work_post' do + describe "GET #edit" do + it "assigns given work_post as @work_post" do work_post = create(:work_post) - get :edit, params: { id: work_post.to_param } + get :edit, params: {id: work_post.to_param} assigns(:work_portal).current_post.should eq(work_post) end end - describe 'GET #new' do - it 'assigns a new work_post as @work_post' do + describe "GET #new" do + it "assigns a new work_post as @work_post" do get(:new) assigns(:work_portal).current_post.instance_of?(WorkPost).should be_truthy assigns(:work_portal).current_post.new_record?.should be_truthy end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { title: 'Sommarjobb Axis', - description: 'Ett trevligt sommarjobb?', - kind: 'Sommarjobb', - field: 'Programmering', - target_group: 'Fjärde och femter år', - company: 'Axis' } + describe "POST #create" do + it "valid parameters" do + attributes = {title: "Sommarjobb Axis", + description: "Ett trevligt sommarjobb?", + kind: "Sommarjobb", + field: "Programmering", + target_group: "Fjärde och femter år", + company: "Axis"} lambda do - post :create, params: { work_post: attributes } + post :create, params: {work_post: attributes} end.should change(WorkPost, :count).by(1) response.should redirect_to(edit_admin_work_post_path(WorkPost.last)) @@ -55,9 +55,9 @@ WorkPost.last.user.should eq(user) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { work_post: { title: '' } } + post :create, params: {work_post: {title: ""}} end.should change(WorkPost, :count).by(0) response.status.should eq(422) @@ -65,12 +65,12 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - work_post = create(:work_post, title: 'A Bad Title', user_id: 99) - attributes = { title: 'A Good Title' } + describe "PATCH #update" do + it "valid parameters" do + work_post = create(:work_post, title: "A Bad Title", user_id: 99) + attributes = {title: "A Good Title"} - patch :update, params: { id: work_post.to_param, work_post: attributes } + patch :update, params: {id: work_post.to_param, work_post: attributes} work_post.reload response.should redirect_to(edit_admin_work_post_path(work_post)) @@ -78,25 +78,25 @@ work_post.user.should eq(user) end - it 'invalid parameters' do - work_post = create(:work_post, title: 'A Good Title') - attributes = { title: '' } + it "invalid parameters" do + work_post = create(:work_post, title: "A Good Title") + attributes = {title: ""} - patch :update, params: { id: work_post.to_param, work_post: attributes } + patch :update, params: {id: work_post.to_param, work_post: attributes} work_post.reload - work_post.title.should eq('A Good Title') + work_post.title.should eq("A Good Title") response.status.should eq(422) response.should render_template(:edit) end end - describe 'DELETE #destroy' do - it 'destroying' do + describe "DELETE #destroy" do + it "destroying" do work_post = create(:work_post) lambda do - delete :destroy, params: { id: work_post.to_param } + delete :destroy, params: {id: work_post.to_param} end.should change(WorkPost, :count).by(-1) response.should redirect_to(admin_work_posts_path) diff --git a/spec/controllers/blog_posts_controller_spec.rb b/spec/controllers/blog_posts_controller_spec.rb index 1377ce90d..7f90efd5f 100644 --- a/spec/controllers/blog_posts_controller_spec.rb +++ b/spec/controllers/blog_posts_controller_spec.rb @@ -1,46 +1,46 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe BlogPostsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, BlogPost) - describe 'GET #index' do - it 'renders blog_posts' do - create(:blog_post, created_at: 5.days.ago, title: 'Last') - create(:blog_post, created_at: 1.days.ago, title: 'First') - create(:blog_post, created_at: 3.days.ago, title: 'Second') + describe "GET #index" do + it "renders blog_posts" do + create(:blog_post, created_at: 5.days.ago, title: "Last") + create(:blog_post, created_at: 1.days.ago, title: "First") + create(:blog_post, created_at: 3.days.ago, title: "Second") get(:index) response.should have_http_status(200) - assigns(:blog_posts).map(&:title).should eq(['First', 'Second', 'Last']) + assigns(:blog_posts).map(&:title).should eq(["First", "Second", "Last"]) end - it 'renders only on categories' do + it "renders only on categories" do category = create(:category) - blog_post = create(:blog_post, title: 'Shown') + blog_post = create(:blog_post, title: "Shown") blog_post.categories << category blog_post.save! - create(:blog_post, title: 'Not shown') + create(:blog_post, title: "Not shown") - get :index, params: { category: category } + get :index, params: {category: category} response.should have_http_status(200) assigns(:category).should eq(category) - assigns(:blog_posts).map(&:title).should eq(['Shown']) + assigns(:blog_posts).map(&:title).should eq(["Shown"]) end end - describe 'GET #show' do - it 'sets blog_post' do - blog_post = create(:blog_post, title: 'Waow') - create(:blog_post, created_at: 5.days.ago, title: 'Last') - create(:blog_post, created_at: 1.days.ago, title: 'First') - create(:blog_post, created_at: 3.days.ago, title: 'Second') - create(:blog_post, created_at: 10.days.ago, title: 'Not shown') + describe "GET #show" do + it "sets blog_post" do + blog_post = create(:blog_post, title: "Waow") + create(:blog_post, created_at: 5.days.ago, title: "Last") + create(:blog_post, created_at: 1.days.ago, title: "First") + create(:blog_post, created_at: 3.days.ago, title: "Second") + create(:blog_post, created_at: 10.days.ago, title: "Not shown") - get :show, params: { id: blog_post.to_param } + get :show, params: {id: blog_post.to_param} response.should have_http_status(200) assigns(:blog_post).should eq(blog_post) - assigns(:other_blog_posts).map(&:title).should eq(['First', 'Second', 'Last']) + assigns(:other_blog_posts).map(&:title).should eq(["First", "Second", "Last"]) end end end diff --git a/spec/controllers/cafe_controller_spec.rb b/spec/controllers/cafe_controller_spec.rb index 5aaca1198..8909327ae 100644 --- a/spec/controllers/cafe_controller_spec.rb +++ b/spec/controllers/cafe_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeController, type: :controller do include ActiveSupport::Testing::TimeHelpers @@ -11,23 +11,23 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #index' do - it 'loads index view properly' do + describe "GET #index" do + it "loads index view properly" do get :index response.status.should eq(200) end end - describe 'GET #competition' do - it 'loads competition view properly' do + describe "GET #competition" do + it "loads competition view properly" do get :competition response.status.should eq(200) end end - describe 'GET #ladybug' do - it 'loads ladybug page' do - date = Time.zone.local(2014, 03, 25, 8) + describe "GET #ladybug" do + it "loads ladybug page" do + date = Time.zone.local(2014, 0o3, 25, 8) travel_to date get :ladybug @@ -37,11 +37,11 @@ travel_back end - it 'loads ladybug page' do - date = Time.zone.local(2015, 03, 25, 8) + it "loads ladybug page" do + date = Time.zone.local(2015, 0o3, 25, 8) - attributes = { date: date } - get :ladybug, params: { ladybug: attributes } + attributes = {date: date} + get :ladybug, params: {ladybug: attributes} response.status.should eq(200) assigns(:date).should eq(date) diff --git a/spec/controllers/cafe_shifts_controller_spec.rb b/spec/controllers/cafe_shifts_controller_spec.rb index 03807c596..def730da6 100644 --- a/spec/controllers/cafe_shifts_controller_spec.rb +++ b/spec/controllers/cafe_shifts_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeShiftsController, type: :controller do let(:user) { create(:user) } @@ -10,31 +10,31 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #show' do - it 'assigns the requested cafe_shift as @cafe_shift' do + describe "GET #show" do + it "assigns the requested cafe_shift as @cafe_shift" do shift = create(:cafe_shift) - create(:council, title: 'Second') - create(:council, title: 'First') - create(:council, title: 'Third') + create(:council, title: "Second") + create(:council, title: "First") + create(:council, title: "Third") - get :show, params: { id: shift.to_param } + get :show, params: {id: shift.to_param} assigns(:cafe_view).shift.should eq(shift) - assigns(:cafe_view).councils.map(&:title).should eq(['First', 'Second', 'Third']) + assigns(:cafe_view).councils.map(&:title).should eq(["First", "Second", "Third"]) assigns(:cafe_view).shift.cafe_worker.should be_a_new(CafeWorker) response.status.should eq(200) end - it 'error cafe_shift is not found' do + it "error cafe_shift is not found" do lambda do - get :show, params: { id: 9999777 } + get :show, params: {id: 9999777} end.should raise_error(ActionController::RoutingError) end end - describe 'GET #feed' do - it 'renders feed' do - request.accept = 'application/json' + describe "GET #feed" do + it "renders feed" do + request.accept = "application/json" get :feed response.status.should eq(200) end diff --git a/spec/controllers/cafe_workers_controller_spec.rb b/spec/controllers/cafe_workers_controller_spec.rb index 783faf2bc..f9b4b3897 100644 --- a/spec/controllers/cafe_workers_controller_spec.rb +++ b/spec/controllers/cafe_workers_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeWorkersController, type: :controller do let(:user) { create(:user) } @@ -10,35 +10,35 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #new' do - it 'assigns the requested cafe_view as @cafe_view' do + describe "GET #new" do + it "assigns the requested cafe_view as @cafe_view" do shift = create(:cafe_shift) - create(:council, title: 'Second') - create(:council, title: 'First') - create(:council, title: 'Third') + create(:council, title: "Second") + create(:council, title: "First") + create(:council, title: "Third") - get :new, params: { cafe_shift_id: shift.to_param } + get :new, params: {cafe_shift_id: shift.to_param} assigns(:cafe_view).shift.should eq(shift) - assigns(:cafe_view).councils.map(&:title).should eq(['First', 'Second', 'Third']) + assigns(:cafe_view).councils.map(&:title).should eq(["First", "Second", "Third"]) assigns(:cafe_view).shift.cafe_worker.should be_a_new(CafeWorker) response.status.should eq(200) end - it 'error cafe_shift is not found' do + it "error cafe_shift is not found" do lambda do - get :new, params: { cafe_shift_id: 9999 } + get :new, params: {cafe_shift_id: 9999} end.should raise_error(ActionController::RoutingError) end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do shift = create(:cafe_shift) - cafe_worker_params = { competition: true, user_id: user.to_param } + cafe_worker_params = {competition: true, user_id: user.to_param} lambda do - post :create, params: { cafe_shift_id: shift.to_param, cafe_worker: cafe_worker_params } + post :create, params: {cafe_shift_id: shift.to_param, cafe_worker: cafe_worker_params} end.should change(CafeWorker, :count).by(1) assigns(:cafe_view).shift.should eq(shift) @@ -46,57 +46,57 @@ response.should redirect_to(shift) end - it 'invalid params' do + it "invalid params" do shift = create(:cafe_shift) lambda do - post :create, params: { cafe_shift_id: shift.to_param, cafe_worker: { user_id: nil } } + post :create, params: {cafe_shift_id: shift.to_param, cafe_worker: {user_id: nil}} end.should change(CafeWorker, :count).by(0) assigns(:cafe_view).shift.should eq(shift) - response.should render_template('cafe_shifts/show', layout: :application) + response.should render_template("cafe_shifts/show", layout: :application) response.status.should eq(422) end end - describe 'PATCH #update' do - it 'valid params' do + describe "PATCH #update" do + it "valid params" do shift = create(:cafe_shift) worker = create(:cafe_worker, cafe_shift: shift, user: user) - patch :update, params: { id: worker.to_param, - cafe_shift_id: shift.to_param, - cafe_worker: { group: 'MUR' } } + patch :update, params: {id: worker.to_param, + cafe_shift_id: shift.to_param, + cafe_worker: {group: "MUR"}} shift.reload shift.cafe_worker.reload assigns(:cafe_view).shift.should eq(shift) - shift.cafe_worker.group.should eq('MUR') + shift.cafe_worker.group.should eq("MUR") response.should redirect_to(shift) end - it 'invalid_params' do + it "invalid_params" do shift = create(:cafe_shift) worker = create(:cafe_worker, cafe_shift: shift, user: user) - patch :update, params: { id: worker.to_param, - cafe_shift_id: shift.to_param, - cafe_worker: { user_id: nil } } + patch :update, params: {id: worker.to_param, + cafe_shift_id: shift.to_param, + cafe_worker: {user_id: nil}} assigns(:cafe_view).shift.should eq(shift) assigns(:cafe_view).shift.cafe_worker.user_id.should eq(user.id) - response.should render_template('cafe_shifts/show', layout: :application) + response.should render_template("cafe_shifts/show", layout: :application) response.status.should eq(422) end end - describe 'DELETE #destroy' do - it 'destroy worker' do + describe "DELETE #destroy" do + it "destroy worker" do shift = create(:cafe_shift) worker = create(:cafe_worker, cafe_shift: shift, user: user) lambda do - delete :destroy, params: { cafe_shift_id: shift.to_param, id: worker.to_param } + delete :destroy, params: {cafe_shift_id: shift.to_param, id: worker.to_param} end.should change(CafeWorker, :count).by(-1) response.should redirect_to(shift) diff --git a/spec/controllers/calendar_controller_spec.rb b/spec/controllers/calendar_controller_spec.rb index bb1b4d8fd..f7e28bd8e 100644 --- a/spec/controllers/calendar_controller_spec.rb +++ b/spec/controllers/calendar_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CalendarsController, type: :controller do let(:user) { create(:user) } @@ -6,18 +6,18 @@ allow_user_to(:manage, :calendar) allow_user_to(:manage, Event) - describe 'GET #index' do - it 'loads the calendar' do + describe "GET #index" do + it "loads the calendar" do create(:event) get(:index) response.status.should eq(200) end - context 'json format' do - it 'shows events between from and end' do + context "json format" do + it "shows events between from and end" do event = create(:event, starts_at: Time.zone.now) create(:event, starts_at: 5.day.from_now) - get :index, format: :json, params: { start: 1.day.ago, end: 1.day.from_now } + get :index, format: :json, params: {start: 1.day.ago, end: 1.day.from_now} response.status.should eq(200) # Generate expected result @@ -30,76 +30,76 @@ end end - describe 'GET #export' do - it 'set calendar for export' do + describe "GET #export" do + it "set calendar for export" do get :export, format: :ics response.status.should eq(200) end - context 'locale' do - it 'returns given locale' do - create(:event, title_sv: 'Not shown', title_en: 'English title') - get :export, format: :ics, params: { locale: 'en' } - response.body.should include('SUMMARY:English title') + context "locale" do + it "returns given locale" do + create(:event, title_sv: "Not shown", title_en: "English title") + get :export, format: :ics, params: {locale: "en"} + response.body.should include("SUMMARY:English title") response.should have_http_status(200) end - it 'defaults to swedish' do - create(:event, title_sv: 'Visa som standard', - title_en: 'Not shown English title') + it "defaults to swedish" do + create(:event, title_sv: "Visa som standard", + title_en: "Not shown English title") get :export, format: :ics - response.body.should include('SUMMARY:Visa som standard') + response.body.should include("SUMMARY:Visa som standard") response.should have_http_status(200) end end - context 'after_date' do - it 'returns event after given date' do - create(:event, title_sv: 'After date', starts_at: 5.days.from_now) - create(:event, title_sv: 'Before date', starts_at: 5.days.ago) + context "after_date" do + it "returns event after given date" do + create(:event, title_sv: "After date", starts_at: 5.days.from_now) + create(:event, title_sv: "Before date", starts_at: 5.days.ago) - attributes = { after_date: Time.zone.now.to_date.to_s } - get :export, format: :ics, params: { calendar: attributes } + attributes = {after_date: Time.zone.now.to_date.to_s} + get :export, format: :ics, params: {calendar: attributes} - response.body.should include('SUMMARY:After date') - response.body.should_not include('SUMMARY:Before date') + response.body.should include("SUMMARY:After date") + response.body.should_not include("SUMMARY:Before date") response.should have_http_status(200) end - it 'defaults to 2 weeks ago' do - create(:event, title_sv: 'Less than 14 days ago', starts_at: 13.days.ago) - create(:event, title_sv: 'More than 14 days ago', starts_at: 15.days.ago) + it "defaults to 2 weeks ago" do + create(:event, title_sv: "Less than 14 days ago", starts_at: 13.days.ago) + create(:event, title_sv: "More than 14 days ago", starts_at: 15.days.ago) get :export, format: :ics - response.body.should include('SUMMARY:Less than 14 days ago') - response.body.should_not include('SUMMARY:More than 14 days ago') + response.body.should include("SUMMARY:Less than 14 days ago") + response.body.should_not include("SUMMARY:More than 14 days ago") response.should have_http_status(200) end end end - describe 'GET #introduction' do - it 'renders introduction' do + describe "GET #introduction" do + it "renders introduction" do create(:introduction, current: true) get :introduction, format: :ics response.status.should eq(200) end - it 'returns only introduction events category' do + it "returns only introduction events category" do create(:introduction, current: true, start: 10.days.from_now) category = create(:category, slug: :nollning) - first_event = create(:event, title: 'Shown', starts_at: 15.days.from_now) + first_event = create(:event, title: "Shown", starts_at: 15.days.from_now) first_event.categories << category first_event.save! - create(:event, title: 'Not shown', starts_at: 15.days.from_now) + create(:event, title: "Not shown", starts_at: 15.days.from_now) get :introduction, format: :ics - response.body.should include('SUMMARY:Shown') - response.body.should_not include('SUMMARY:Not shown') + response.body.should include("SUMMARY:Shown") + response.body.should_not include("SUMMARY:Not shown") response.should have_http_status(200) end - it 'redirects to export without Introduction' do + it "redirects to export without Introduction" do get :introduction, format: :ics response.should have_http_status(404) end diff --git a/spec/controllers/concerns/alerts_spec.rb b/spec/controllers/concerns/alerts_spec.rb index 2afd2a53a..e6b65a71b 100644 --- a/spec/controllers/concerns/alerts_spec.rb +++ b/spec/controllers/concerns/alerts_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" # Dummy class for testing module class Alert @@ -9,17 +9,17 @@ class Alert let(:alert) { Alert.new } subject { alert } - describe '#model_name' do - it 'returns human model name' do + describe "#model_name" do + it "returns human model name" do model = double(:model) model.stub(:model_name) { model } - model.stub(:human) { 'ModelName' } + model.stub(:human) { "ModelName" } model.stub(:instance_of?) { true } - alert.model_name(model).should eq('ModelName') + alert.model_name(model).should eq("ModelName") end - it 'returns nil if not Class' do + it "returns nil if not Class" do model = double(:model) model.stub(:instance_of?) { false } @@ -27,23 +27,23 @@ class Alert end end - describe 'alerts' do - it '#alert_update' do - alert.stub(:model_name) { 'Model' } - alert.alert_update(nil).should eq(text: "Model #{I18n.t('global_controller.success_update')}.", - type: 'success') + describe "alerts" do + it "#alert_update" do + alert.stub(:model_name) { "Model" } + alert.alert_update(nil).should eq(text: "Model #{I18n.t("global_controller.success_update")}.", + type: "success") end - it '#alert_create' do - alert.stub(:model_name) { 'Model' } - alert.alert_create(nil).should eq(text: "Model #{I18n.t('global_controller.success_create')}.", - type: 'success') + it "#alert_create" do + alert.stub(:model_name) { "Model" } + alert.alert_create(nil).should eq(text: "Model #{I18n.t("global_controller.success_create")}.", + type: "success") end - it '#alert_destroy' do - alert.stub(:model_name) { 'Model' } - alert.alert_destroy(nil).should eq(text: "Model #{I18n.t('global_controller.success_destroy')}.", - type: 'danger') + it "#alert_destroy" do + alert.stub(:model_name) { "Model" } + alert.alert_destroy(nil).should eq(text: "Model #{I18n.t("global_controller.success_destroy")}.", + type: "danger") end end end diff --git a/spec/controllers/concerns/controller_authorization_spec.rb b/spec/controllers/concerns/controller_authorization_spec.rb index 84c9a3d24..8cb620263 100644 --- a/spec/controllers/concerns/controller_authorization_spec.rb +++ b/spec/controllers/concerns/controller_authorization_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" # Dummy class for testing controller_authorization module class Controller extend ControllerAuthorization def self.name - 'Admin::TestingsController' + "Admin::TestingsController" end end @@ -17,12 +17,12 @@ class Testing let(:controller) { Controller.new } subject { controller } - describe '#permission' do - it 'returns constantized name' do + describe "#permission" do + it "returns constantized name" do Controller.permission.should eq(Testing.name) end - it 'returns nil if no name' do + it "returns nil if no name" do Controller.stub(:name) { nil } Controller.permission.should be_nil end diff --git a/spec/controllers/concerns/instance_authorization_spec.rb b/spec/controllers/concerns/instance_authorization_spec.rb index ff44649ca..8388436ac 100644 --- a/spec/controllers/concerns/instance_authorization_spec.rb +++ b/spec/controllers/concerns/instance_authorization_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" # Dummy class for testing instance_authorization module class Instance @@ -13,8 +13,8 @@ def current_user let(:instance) { Instance.new } subject { instance } - describe '#current_ability' do - it 'returns and assigns current_ability' do + describe "#current_ability" do + it "returns and assigns current_ability" do user = build_stubbed(:user) instance.stub(:current_user) { user } ability = Ability.new(user) @@ -25,8 +25,8 @@ def current_user end end - describe '#current_admin_ability' do - it 'returns and assigns current_admin_ability' do + describe "#current_admin_ability" do + it "returns and assigns current_admin_ability" do user = build_stubbed(:user) instance.stub(:current_user) { user } ability = AdminAbility.new(user) @@ -37,49 +37,49 @@ def current_user end end - describe '#load_permissions' do - it 'returns nil if no current_user' do + describe "#load_permissions" do + it "returns nil if no current_user" do instance.stub(:current_user) { nil } instance.load_permissions.should be_nil end - it 'returns and assigns current_permissions' do + it "returns and assigns current_permissions" do user = build_stubbed(:user) instance.stub(:current_user) { user } permissions = [] - permissions << Permission.new(subject_class: 'user', action: 'create') - permissions << Permission.new(subject_class: 'instance', action: 'manage') + permissions << Permission.new(subject_class: "user", action: "create") + permissions << Permission.new(subject_class: "instance", action: "manage") user.stub(:permissions) { permissions } - result = [%w(user create), %w(instance manage)] + result = [%w[user create], %w[instance manage]] instance.load_permissions.should eq(result) instance.instance_variable_get(:@current_permissions).should eq(result) end end - describe '#can_administrate?' do - it 'returns true from can?' do + describe "#can_administrate?" do + it "returns true from can?" do instance.current_admin_ability.stub(:can?) { true } instance.can_administrate?(Instance, :manage).should be_truthy end - it 'returns false from can?' do + it "returns false from can?" do instance.current_admin_ability.stub(:can?) { false } instance.can_administrate?(Instance, :manage).should be_falsey end end - describe '#authorize_admin!' do - it 'returns response from authorize!' do - instance.current_admin_ability.stub(:authorize!) { 'YES YOU CAN' } - instance.authorize_admin!(Instance, :manage).should eq('YES YOU CAN') + describe "#authorize_admin!" do + it "returns response from authorize!" do + instance.current_admin_ability.stub(:authorize!) { "YES YOU CAN" } + instance.authorize_admin!(Instance, :manage).should eq("YES YOU CAN") instance.instance_variable_get(:@_authorized).should be_truthy end - it 'returns response of can?' do - instance.current_admin_ability.stub(:authorize!) { 'NO YOU CANNOT' } - instance.authorize_admin!(Instance, :manage).should eq('NO YOU CANNOT') + it "returns response of can?" do + instance.current_admin_ability.stub(:authorize!) { "NO YOU CANNOT" } + instance.authorize_admin!(Instance, :manage).should eq("NO YOU CANNOT") instance.instance_variable_get(:@_authorized).should be_truthy end end diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index 6ddc251b8..8f787f0f8 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ContactsController, type: :controller do let(:contact) { create(:contact) } @@ -6,47 +6,47 @@ allow_user_to [:index, :show, :mail], Contact - describe 'GET #index' do - it 'succeeds and assigns contacts' do - create(:contact, name: 'Second') - create(:contact, name: 'Third') - create(:contact, name: 'First') + describe "GET #index" do + it "succeeds and assigns contacts" do + create(:contact, name: "Second") + create(:contact, name: "Third") + create(:contact, name: "First") get :index response.should be_success - assigns(:contacts).map(&:name).should eq(['First', 'Second', 'Third']) + assigns(:contacts).map(&:name).should eq(["First", "Second", "Third"]) end end - describe 'GET #show' do - it 'succeeds' do + describe "GET #show" do + it "succeeds" do contact = create(:contact) - get :show, params: { id: contact.to_param } + get :show, params: {id: contact.to_param} response.should be_success assigns(:contact).should eq(contact) end end - describe 'POST #mail' do - it 'valid params' do + describe "POST #mail" do + it "valid params" do contact = create(:contact) - attributes = { name: 'David', - email: 'david@google.com', - message: 'Jag vill prova kontaktformuläret' } - post :mail, params: { id: contact.to_param, contact_message: attributes } + attributes = {name: "David", + email: "david@google.com", + message: "Jag vill prova kontaktformuläret"} + post :mail, params: {id: contact.to_param, contact_message: attributes} assigns(:contact).should eq(contact) response.should redirect_to(contact_path(contact)) end - it 'invalid params' do + it "invalid params" do contact = create(:contact) - attributes = { name: 'David', - email: 'inte_en_epost', - message: 'Jag vill prova kontaktformuläret' } - post :mail, params: { id: contact.to_param, contact_message: attributes } + attributes = {name: "David", + email: "inte_en_epost", + message: "Jag vill prova kontaktformuläret"} + post :mail, params: {id: contact.to_param, contact_message: attributes} assigns(:contact).should eq(contact) response.status.should eq(422) diff --git a/spec/controllers/councils_controller_spec.rb b/spec/controllers/councils_controller_spec.rb index a02146c7f..be3cd36a7 100644 --- a/spec/controllers/councils_controller_spec.rb +++ b/spec/controllers/councils_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CouncilsController, type: :controller do let(:user) { create(:user) } @@ -9,28 +9,27 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a councils' do - create(:council, title: 'Second') - create(:council, title: 'First') - create(:council, title: 'Third') + describe "GET #index" do + it "assigns a councils" do + create(:council, title: "Second") + create(:council, title: "First") + create(:council, title: "Third") get(:index) response.status.should eq(200) - assigns(:councils).map(&:title).should eq(['First', - 'Second', - 'Third']) + assigns(:councils).map(&:title).should eq(["First", + "Second", + "Third"]) end end - describe 'GET #show' do - it 'sets council' do + describe "GET #show" do + it "sets council" do council = create(:council) - get :show, params: { id: council.to_param } + get :show, params: {id: council.to_param} response.status.should eq(200) assigns(:council).should eq(council) end end - end diff --git a/spec/controllers/documents_controller_spec.rb b/spec/controllers/documents_controller_spec.rb index 2e51acdfb..d760474f9 100644 --- a/spec/controllers/documents_controller_spec.rb +++ b/spec/controllers/documents_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe DocumentsController, type: :controller do let(:user) { create(:user) } @@ -9,25 +9,25 @@ controller.stub(:current_user).and_return(user) end - describe 'GET #index' do - it 'assigns a document grid and categories' do - create(:document, title: 'First document') - create(:document, title: 'Second document') - create(:document, title: 'Third document') + describe "GET #index" do + it "assigns a document grid and categories" do + create(:document, title: "First document") + create(:document, title: "Second document") + create(:document, title: "Third document") get(:index) response.status.should eq(200) end end - describe 'GET #show' do - it 'assigns given document as @document' do + describe "GET #show" do + it "assigns given document as @document" do document = create(:document) controller.stub(:render) controller.should_receive(:send_file).and_return(controller: :render, nothing: true) - get :show, params: { id: document.to_param }, format: :pdf + get :show, params: {id: document.to_param}, format: :pdf end end end diff --git a/spec/controllers/elections/candidates_controller_spec.rb b/spec/controllers/elections/candidates_controller_spec.rb index a392726b7..98f025b39 100644 --- a/spec/controllers/elections/candidates_controller_spec.rb +++ b/spec/controllers/elections/candidates_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Elections::CandidatesController, type: :controller do let(:user) { create(:user) } @@ -8,8 +8,8 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #index' do - it 'succeeds' do + describe "GET #index" do + it "succeeds" do create(:candidate, user: user) get :index @@ -18,9 +18,9 @@ end end - describe 'GET #new' do - it 'assigns candidate' do - create(:election, :autumn, title: 'Terminsmötet') + describe "GET #new" do + it "assigns candidate" do + create(:election, :autumn, title: "Terminsmötet") create(:post, :autumn) get :new @@ -30,28 +30,28 @@ end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do create(:election, :autumn) postt = create(:post, :autumn) - attributes = { user_id: user.id, - post_id: postt.id } + attributes = {user_id: user.id, + post_id: postt.id} lambda do - post :create, params: { candidate: attributes } + post :create, params: {candidate: attributes} end.should change(Candidate, :count).by(1) response.should redirect_to(candidates_path) end - it 'invalid params' do + it "invalid params" do create(:election, :autumn) create(:post, :autumn) - attributes = { user_id: user.id, - post_id: nil } + attributes = {user_id: user.id, + post_id: nil} lambda do - post :create, params: { candidate: attributes } + post :create, params: {candidate: attributes} end.should change(Candidate, :count).by(0) response.status.should eq(422) @@ -59,12 +59,12 @@ end end - describe 'DELETE #destroy' do - it 'destroys the requested candidate' do + describe "DELETE #destroy" do + it "destroys the requested candidate" do candidate = create(:candidate) lambda do - delete :destroy, params: { id: candidate.to_param } + delete :destroy, params: {id: candidate.to_param} end.should change(Candidate, :count).by(-1) response.should redirect_to(candidates_path) diff --git a/spec/controllers/elections/nominations_controller_spec.rb b/spec/controllers/elections/nominations_controller_spec.rb index 40968b8a7..1d0ce04c2 100644 --- a/spec/controllers/elections/nominations_controller_spec.rb +++ b/spec/controllers/elections/nominations_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Elections::NominationsController, type: :controller do let(:user) { create(:user) } @@ -8,8 +8,8 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #new' do - it 'valid election' do + describe "GET #new" do + it "valid election" do election = create(:election, :autumn) create(:post, :autumn) @@ -18,11 +18,11 @@ assigns(:election_view).nomination.should be_a_new(Nomination) end - it 'valid election with post' do + it "valid election with post" do election = create(:election, :autumn) postt = create(:post, :autumn) - get :new, params: { post: postt.id } + get :new, params: {post: postt.id} response.should be_success assigns(:election_view).election.should eq(election) @@ -30,39 +30,39 @@ assigns(:election_view).nomination.post.should eq(postt) end - it 'no valid election' do + it "no valid election" do create(:post, :autumn) get :new - response.should render_template('elections/no_election', layout: :application) + response.should render_template("elections/no_election", layout: :application) response.status.should eq(404) end end - describe 'POST #create' do - it 'valid params' do + describe "POST #create" do + it "valid params" do create(:election, :autumn) postt = create(:post, :autumn) - attributes = { name: 'Hilbert Älg', - email: 'hilbert@fsektionen.se', - motivation: 'Underrum', - post_id: postt.id } + attributes = {name: "Hilbert Älg", + email: "hilbert@fsektionen.se", + motivation: "Underrum", + post_id: postt.id} lambda do - post :create, params: { nomination: attributes } + post :create, params: {nomination: attributes} end.should change(Nomination, :count).by(1) response.should redirect_to(new_nominations_path) end - it 'invalid params' do + it "invalid params" do create(:election, :autumn) create(:post, :autumn) - attributes = { name: 'Hilbert Älg', - motivation: 'Underrum' } + attributes = {name: "Hilbert Älg", + motivation: "Underrum"} lambda do - post :create, params: { nomination: attributes } + post :create, params: {nomination: attributes} end.should change(Nomination, :count).by(0) response.should render_template(:new) diff --git a/spec/controllers/elections_controller_spec.rb b/spec/controllers/elections_controller_spec.rb index 931c69fc2..38867afe5 100644 --- a/spec/controllers/elections_controller_spec.rb +++ b/spec/controllers/elections_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ElectionsController, type: :controller do let(:user) { create(:user) } @@ -9,8 +9,8 @@ controller.stub(:current_user).and_return(user) end - describe 'GET #index' do - it 'assigns current election' do + describe "GET #index" do + it "assigns current election" do election = create(:election, :autumn) post1 = create(:post, :autumn) post2 = create(:post, :autumn) @@ -22,10 +22,10 @@ assigns(:election_view).election.posts.should eq([post1, post2]) end - it 'redirects if no election' do + it "redirects if no election" do get(:index) response.status.should eq(200) - response.should render_template('no_election') + response.should render_template("no_election") end end end diff --git a/spec/controllers/event_users_controller_spec.rb b/spec/controllers/event_users_controller_spec.rb index cfdeb7a0f..e3e611b95 100644 --- a/spec/controllers/event_users_controller_spec.rb +++ b/spec/controllers/event_users_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe EventUsersController, type: :controller do let(:user) { create(:user) } @@ -9,96 +9,96 @@ set_current_user(user) end - describe 'POST #create' do - it 'works' do + describe "POST #create" do + it "works" do event = create(:event, :with_signup) - attributes = { user_type: EventSignup::MEMBER } + attributes = {user_type: EventSignup::MEMBER} lambda do - post :create, xhr: true, params: { event_id: event.to_param, event_user: attributes } + post :create, xhr: true, params: {event_id: event.to_param, event_user: attributes} end.should change(EventUser, :count).by(1) EventUser.last.user.should eq(user) end - it 'fails if signup has not yet opened' do + it "fails if signup has not yet opened" do event = create(:event) create(:event_signup, event: event, opens: Time.zone.now + 1.day, closes: Time.zone.now + 2.days) - attributes = { user_type: EventSignup::MEMBER } + attributes = {user_type: EventSignup::MEMBER} lambda do - post :create, xhr: true, params: { event_id: event.to_param, event_user: attributes } + post :create, xhr: true, params: {event_id: event.to_param, event_user: attributes} end.should change(EventUser, :count).by(0) end - it 'fails if signup has closed' do + it "fails if signup has closed" do event = create(:event) create(:event_signup, event: event, opens: Time.zone.now - 2.days, closes: Time.zone.now - 1.day) - attributes = { user_type: EventSignup::MEMBER } + attributes = {user_type: EventSignup::MEMBER} lambda do - post :create, xhr: true, params: { event_id: event.to_param, event_user: attributes } + post :create, xhr: true, params: {event_id: event.to_param, event_user: attributes} end.should change(EventUser, :count).by(0) end - it 'fails if already signed up to same event' do + it "fails if already signed up to same event" do event = create(:event) create(:event_signup, event: event) create(:event_user, event: event, user: user) - attributes = { user_type: EventSignup::MEMBER } + attributes = {user_type: EventSignup::MEMBER} lambda do - post :create, xhr: true, params: { event_id: event.to_param, event_user: attributes } + post :create, xhr: true, params: {event_id: event.to_param, event_user: attributes} end.should_not change(EventUser, :count) assigns(:event_user).errors[:user_id].should \ - include(I18n.t('model.event_user.already_registered')) + include(I18n.t("model.event_user.already_registered")) end - it 'succeeds even when user signup to another event' do + it "succeeds even when user signup to another event" do create(:event_user, user: user) event = create(:event, :with_signup) - attributes = { user_type: EventSignup::MEMBER } + attributes = {user_type: EventSignup::MEMBER} lambda do - post :create, xhr: true, params: { event_id: event.to_param, event_user: attributes } + post :create, xhr: true, params: {event_id: event.to_param, event_user: attributes} end.should change(EventUser, :count).by(1) end end - describe 'DELETE #destroy' do - it 'works' do + describe "DELETE #destroy" do + it "works" do event = create(:event, :with_signup) event_user = create(:event_user, event: event, user: user) lambda do - delete :destroy, xhr: true, params: { event_id: event.to_param, - id: event_user.to_param } + delete :destroy, xhr: true, params: {event_id: event.to_param, + id: event_user.to_param} end.should change(EventUser, :count).by(-1) end - it 'fails if signup is closed' do + it "fails if signup is closed" do event = create(:event) signup = create(:event_signup, event: event) event_user = create(:event_user, event: event, user: user) signup.update(closes: Time.zone.now) lambda do - delete :destroy, xhr: true, params: { event_id: event.to_param, - id: event_user.to_param } + delete :destroy, xhr: true, params: {event_id: event.to_param, + id: event_user.to_param} end.should change(EventUser, :count).by(0) end - it 'does only allow owner to destroy' do + it "does only allow owner to destroy" do event = create(:event, :with_signup) event_user = create(:event_user, event: event, user: create(:user)) lambda do - delete :destroy, xhr: true, params: { event_id: event_user.event.to_param, - id: event_user.to_param } + delete :destroy, xhr: true, params: {event_id: event_user.event.to_param, + id: event_user.to_param} end.should raise_error(ActionController::RoutingError) end end diff --git a/spec/controllers/faqs_controller_spec.rb b/spec/controllers/faqs_controller_spec.rb index e832207f1..85452af0c 100644 --- a/spec/controllers/faqs_controller_spec.rb +++ b/spec/controllers/faqs_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe FaqsController, type: :controller do let(:user) { create(:user) } @@ -9,19 +9,19 @@ controller.stub(:current_user).and_return(user) end - describe 'GET #index' do - it 'assigns a faq grid and categories' do - create(:faq, question: 'First faq') - create(:faq, question: 'Second faq') - create(:faq, question: 'Third faq') + describe "GET #index" do + it "assigns a faq grid and categories" do + create(:faq, question: "First faq") + create(:faq, question: "Second faq") + create(:faq, question: "Third faq") get(:index) response.status.should eq(200) end end - describe 'GET #new' do - it 'assigns new faq as @faq' do + describe "GET #new" do + it "assigns new faq as @faq" do get(:new) response.status.should eq(200) @@ -30,20 +30,20 @@ end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { question: 'Vem var Hilbert?' } + describe "POST #create" do + it "valid parameters" do + attributes = {question: "Vem var Hilbert?"} lambda do - post :create, params: { faq: attributes } + post :create, params: {faq: attributes} end.should change(Faq, :count).by(1) response.should redirect_to(faqs_path) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post :create, params: { faq: { question: '' } } + post :create, params: {faq: {question: ""}} end.should change(Faq, :count).by(0) response.status.should eq(422) diff --git a/spec/controllers/gallery/albums_controller_spec.rb b/spec/controllers/gallery/albums_controller_spec.rb index c80b693d9..852c5af28 100644 --- a/spec/controllers/gallery/albums_controller_spec.rb +++ b/spec/controllers/gallery/albums_controller_spec.rb @@ -1,22 +1,22 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Gallery::AlbumsController, type: :controller do let(:user) { create(:user) } allow_user_to(:show, Album) - describe 'GET #show member' do - it 'assigns the requested album as @album' do + describe "GET #show member" do + it "assigns the requested album as @album" do album = create(:album) - get :show, params: { id: album.to_param } + get :show, params: {id: album.to_param} response.should have_http_status(200) assigns(:album).should eq(album) response.should have_http_status(200) end - it 'assigns start based on given index' do + it "assigns start based on given index" do album = create(:album) - get :show, params: { id: album.to_param, start: '37' } + get :show, params: {id: album.to_param, start: "37"} response.should have_http_status(200) assigns(:start).should eq(37) diff --git a/spec/controllers/gallery/gallery_controller_spec.rb b/spec/controllers/gallery/gallery_controller_spec.rb index 2fc055037..835f09331 100644 --- a/spec/controllers/gallery/gallery_controller_spec.rb +++ b/spec/controllers/gallery/gallery_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe GalleryController, type: :controller do let(:user) { create(:user) } @@ -10,21 +10,21 @@ user.stub(:summerchild?).and_return(false) end - describe 'GET #index' do - it 'assigns albums for current year as @albums' do - create(:album, images_count: 5, title: 'Shown') - create(:album, images_count: 5, title: 'Not shown', start_date: 1.year.ago) + describe "GET #index" do + it "assigns albums for current year as @albums" do + create(:album, images_count: 5, title: "Shown") + create(:album, images_count: 5, title: "Not shown", start_date: 1.year.ago) get(:index) - assigns(:albums).map(&:title).should eq(['Shown']) + assigns(:albums).map(&:title).should eq(["Shown"]) end - it 'assigns albums for assigned year as @albums' do - create(:album, images_count: 5, title: 'Not shown') - create(:album, images_count: 5, title: 'Shown', start_date: 1.year.ago) + it "assigns albums for assigned year as @albums" do + create(:album, images_count: 5, title: "Not shown") + create(:album, images_count: 5, title: "Shown", start_date: 1.year.ago) - get :index, params: { year: 1.year.ago.year } - assigns(:albums).map(&:title).should eq(['Shown']) + get :index, params: {year: 1.year.ago.year} + assigns(:albums).map(&:title).should eq(["Shown"]) end end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 1358f65a7..d5dcd2379 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe GroupsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, Group) - describe 'GET #index' do - it 'gets current introduction without parameters' do + describe "GET #index" do + it "gets current introduction without parameters" do introduction = create(:introduction, current: true) other_introduction = create(:introduction) @@ -16,11 +16,11 @@ assigns(:introductions).should eq([other_introduction]) end - it 'gets introduction with params' do + it "gets introduction with params" do introduction = create(:introduction, current: true) other_introduction = create(:introduction) - get :index, params: { introduction_id: other_introduction.id } + get :index, params: {introduction_id: other_introduction.id} response.should have_http_status(200) assigns(:introduction).should eq(other_introduction) diff --git a/spec/controllers/introductions_controller_spec.rb b/spec/controllers/introductions_controller_spec.rb index 2490ddcd0..d47e46cd2 100644 --- a/spec/controllers/introductions_controller_spec.rb +++ b/spec/controllers/introductions_controller_spec.rb @@ -1,13 +1,13 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe IntroductionsController, type: :controller do let(:user) { create(:user) } allow_user_to(:manage, Introduction) - describe 'GET #index' do - it 'sets current @introduction' do - create(:introduction, title: 'Not shown') + describe "GET #index" do + it "sets current @introduction" do + create(:introduction, title: "Not shown") introduction = create(:introduction, current: true) get(:index) @@ -15,120 +15,120 @@ response.should have_http_status(200) end - it 'renders archive instead' do - create(:introduction, title: 'Second', start: 1.year.ago) - create(:introduction, title: 'First', start: 1.day.from_now) + it "renders archive instead" do + create(:introduction, title: "Second", start: 1.year.ago) + create(:introduction, title: "First", start: 1.day.from_now) get(:index) response.should render_template(:archive) - assigns(:introductions).map(&:title).should eq(['First', 'Second']) + assigns(:introductions).map(&:title).should eq(["First", "Second"]) response.should have_http_status(404) end end - describe 'GET #archive' do - it 'sets introductions' do - create(:introduction, title: 'Second', start: 1.year.ago) - create(:introduction, title: 'First', start: 1.day.from_now) + describe "GET #archive" do + it "sets introductions" do + create(:introduction, title: "Second", start: 1.year.ago) + create(:introduction, title: "First", start: 1.day.from_now) get(:archive) - assigns(:introductions).map(&:title).should eq(['First', 'Second']) + assigns(:introductions).map(&:title).should eq(["First", "Second"]) response.should have_http_status(200) end end - describe 'GET #show' do - it 'renders introduction' do + describe "GET #show" do + it "renders introduction" do introduction = create(:introduction, current: false) - get :show, params: { id: introduction.to_param } + get :show, params: {id: introduction.to_param} assigns(:introduction).should eq(introduction) response.should render_template(:index) end end - describe 'GET #matrix' do - it 'sets introduction to current' do - create(:introduction, title: 'En Spindelig Nollning', current: true) + describe "GET #matrix" do + it "sets introduction to current" do + create(:introduction, title: "En Spindelig Nollning", current: true) get(:matrix) response.should have_http_status(200) - assigns(:introduction).title.should eq('En Spindelig Nollning') + assigns(:introduction).title.should eq("En Spindelig Nollning") end - it 'sets introductions and render archive' do - create(:introduction, title: 'Gammal', start: 1.year.ago) - create(:introduction, title: 'Äldre', start: 2.years.ago) + it "sets introductions and render archive" do + create(:introduction, title: "Gammal", start: 1.year.ago) + create(:introduction, title: "Äldre", start: 2.years.ago) get(:matrix) response.should have_http_status(404) response.should render_template(:archive) - assigns(:introductions).map(&:title).should eq(['Gammal', 'Äldre']) + assigns(:introductions).map(&:title).should eq(["Gammal", "Äldre"]) end end - describe 'GET #modal' do - it 'sets introduction by param' do + describe "GET #modal" do + it "sets introduction by param" do introduction = create(:introduction) - get :modal, params: { id: introduction.to_param, date: 1.day.ago.to_date } + get :modal, params: {id: introduction.to_param, date: 1.day.ago.to_date} assigns(:introduction).should eq(introduction) end - it 'sets date by param' do + it "sets date by param" do introduction = create(:introduction) - get :modal, params: { id: introduction.to_param, date: 1.day.ago.to_date } + get :modal, params: {id: introduction.to_param, date: 1.day.ago.to_date} assigns(:date).should eq(1.day.ago.to_date) end - it 'sets date to today' do + it "sets date to today" do introduction = create(:introduction) - get :modal, params: { id: introduction.to_param, date: '--' } + get :modal, params: {id: introduction.to_param, date: "--"} assigns(:date).should eq(Date.today) end - it 'sets events' do + it "sets events" do introduction = create(:introduction, start: 3.day.ago, stop: 3.day.from_now) - event = create(:event, title: 'Introduction event', starts_at: 1.day.ago) + event = create(:event, title: "Introduction event", starts_at: 1.day.ago) event.categories << create(:category, slug: :nollning) event.save! - create(:event, title: 'Not introduction', starts_at: 1.day.ago) + create(:event, title: "Not introduction", starts_at: 1.day.ago) - get :modal, params: { id: introduction.to_param, date: 1.day.ago.to_date } - assigns(:events).map(&:title).should eq(['Introduction event']) + get :modal, params: {id: introduction.to_param, date: 1.day.ago.to_date} + assigns(:events).map(&:title).should eq(["Introduction event"]) end - it 'renders matrix' do + it "renders matrix" do introduction = create(:introduction) - get :modal, params: { id: introduction.to_param, date: 1.day.ago.to_date } + get :modal, params: {id: introduction.to_param, date: 1.day.ago.to_date} response.should have_http_status(303) response.should render_template(:matrix) end - it 'renders modal if js' do + it "renders modal if js" do introduction = create(:introduction) - get :modal, xhr: true, params: { id: introduction.to_param, date: 1.day.ago.to_date } + get :modal, xhr: true, params: {id: introduction.to_param, date: 1.day.ago.to_date} response.should have_http_status(200) end - it 'only include translated events if other locale' do + it "only include translated events if other locale" do introduction = create(:introduction, start: 3.day.ago, stop: 3.day.from_now) category = create(:category, slug: :nollning) - swedish = create(:event, title_sv: 'Svensk titel', title_en: 'Engelsk titel', starts_at: 1.day.ago) + swedish = create(:event, title_sv: "Svensk titel", title_en: "Engelsk titel", starts_at: 1.day.ago) swedish.categories << category swedish.save! - english = create(:event, title: 'Översatt event', title_en: 'English title', starts_at: 1.day.ago) - swedish.title_sv.should eq('Svensk titel') - english.title_en.should eq('English title') + english = create(:event, title: "Översatt event", title_en: "English title", starts_at: 1.day.ago) + swedish.title_sv.should eq("Svensk titel") + english.title_en.should eq("English title") english.categories << category english.save! - get :modal, params: { id: introduction.to_param, date: 1.day.ago.to_date, locale: :en } - assigns(:events).map(&:title_en).should eq(['Engelsk titel', 'English title']) + get :modal, params: {id: introduction.to_param, date: 1.day.ago.to_date, locale: :en} + assigns(:events).map(&:title_en).should eq(["Engelsk titel", "English title"]) end end end diff --git a/spec/controllers/meetings_controller_spec.rb b/spec/controllers/meetings_controller_spec.rb index 469e2375c..c7dbe74ef 100644 --- a/spec/controllers/meetings_controller_spec.rb +++ b/spec/controllers/meetings_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" include MeetingHelper, TimeHelper RSpec.describe MeetingsController, type: :controller do @@ -10,9 +10,9 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #index' do - context 'html' do - it 'sets proper variables' do + describe "GET #index" do + context "html" do + it "sets proper variables" do meeting1 = create(:meeting, start_date: 1.hour.from_now, end_date: 3.hours.from_now) meeting2 = create(:meeting, start_date: 6.hours.from_now, end_date: 10.hours.from_now) @@ -22,29 +22,29 @@ end end - context 'json' do - it 'sets proper variables' do + context "json" do + it "sets proper variables" do meeting1 = create(:meeting, start_date: 1.hour.from_now, end_date: 3.hours.from_now) meeting2 = create(:meeting, start_date: 6.hours.from_now, end_date: 10.hours.from_now) create(:meeting, start_date: 13.hours.from_now, end_date: 15.hours.from_now) - get :index, format: :json, params: { start: 1.hour.ago, end: 7.hours.from_now } + get :index, format: :json, params: {start: 1.hour.ago, end: 7.hours.from_now} response.body.should eq([meeting1, meeting2].to_json) end end end - describe 'GET #show' do - it 'assigns the requested rent as @meeting' do + describe "GET #show" do + it "assigns the requested rent as @meeting" do meeting = create(:meeting) - get :show, params: { id: meeting.to_param } + get :show, params: {id: meeting.to_param} response.should have_http_status(200) assigns(:meeting).should eq(meeting) end end - describe 'GET #new' do + describe "GET #new" do it :succeeds do get :new @@ -53,28 +53,28 @@ end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { start_date: 3.hours.from_now, - end_date: 7.hours.from_now, - title: 'Spider Meeting', - room: :sk } + describe "POST #create" do + it "valid parameters" do + attributes = {start_date: 3.hours.from_now, + end_date: 7.hours.from_now, + title: "Spider Meeting", + room: :sk} lambda do - post :create, params: { meeting: attributes } + post :create, params: {meeting: attributes} end.should change(Meeting, :count).by(1) response.should redirect_to(edit_meeting_path(Meeting.last)) assigns(:meeting).user.should eq(user) - assigns(:meeting).title.should eq('Spider Meeting') + assigns(:meeting).title.should eq("Spider Meeting") end - it 'invalid params' do - attributes = { start_date: 3.hours.from_now, - end_date: 1.hours.from_now, - title: 'Spider Meeting', - room: :sk } + it "invalid params" do + attributes = {start_date: 3.hours.from_now, + end_date: 1.hours.from_now, + title: "Spider Meeting", + room: :sk} lambda do - post :create, params: { meeting: attributes } + post :create, params: {meeting: attributes} end.should change(Meeting, :count).by(0) response.status.should eq(422) @@ -82,50 +82,50 @@ end end - describe 'PATCH #update' do - it 'works with valid params' do - meeting = create(:meeting, user: user, title: 'Wrong title') - attributes = { title: 'Correct title' } - patch :update, params: { id: meeting.to_param, meeting: attributes } + describe "PATCH #update" do + it "works with valid params" do + meeting = create(:meeting, user: user, title: "Wrong title") + attributes = {title: "Correct title"} + patch :update, params: {id: meeting.to_param, meeting: attributes} meeting.reload - meeting.title.should eq('Correct title') + meeting.title.should eq("Correct title") response.status.should eq(302) response.should redirect_to(edit_meeting_path(meeting)) assigns(:meeting).should eq(meeting) end - it 'fails with invalid params' do - meeting = create(:meeting, user: user, title: 'Wrong title') - attributes = { title: '' } - patch :update, params: { id: meeting.to_param, meeting: attributes } + it "fails with invalid params" do + meeting = create(:meeting, user: user, title: "Wrong title") + attributes = {title: ""} + patch :update, params: {id: meeting.to_param, meeting: attributes} meeting.reload - meeting.title.should eq('Wrong title') + meeting.title.should eq("Wrong title") response.status.should eq(422) response.should render_template(:edit) assigns(:meeting).should eq(meeting) end - it 'fails with valid params if the status is confirmed' do - meeting = create(:meeting, user: user, title: 'Wrong title', + it "fails with valid params if the status is confirmed" do + meeting = create(:meeting, user: user, title: "Wrong title", status: :confirmed, is_admin: true) - attributes = { title: 'Correct title' } - patch :update, params: { id: meeting.to_param, meeting: attributes } + attributes = {title: "Correct title"} + patch :update, params: {id: meeting.to_param, meeting: attributes} meeting.reload - meeting.title.should eq('Wrong title') + meeting.title.should eq("Wrong title") end end - describe 'DELETE #destroy' do - it 'destroys the requested meeting' do + describe "DELETE #destroy" do + it "destroys the requested meeting" do meeting = create(:meeting, user: user, room: :sk) lambda do - delete :destroy, params: { id: meeting.to_param } + delete :destroy, params: {id: meeting.to_param} end.should change(Meeting, :count).by(-1) response.should redirect_to(meetings_path(room: :sk)) diff --git a/spec/controllers/news_controller_spec.rb b/spec/controllers/news_controller_spec.rb index 9a25d45a5..9c9c51458 100644 --- a/spec/controllers/news_controller_spec.rb +++ b/spec/controllers/news_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe NewsController, type: :controller do let(:user) { create(:user) } @@ -9,8 +9,8 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns news sorted as @news' do + describe "GET #index" do + it "assigns news sorted as @news" do get(:index) assigns(:news).should eq(News.all.order(created_at: :desc).page(0)) end diff --git a/spec/controllers/notfications_controller_spec.rb b/spec/controllers/notfications_controller_spec.rb index 7e8672846..4cb404b22 100644 --- a/spec/controllers/notfications_controller_spec.rb +++ b/spec/controllers/notfications_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe(NotificationsController, type: :controller) do let(:user) { create(:user) } @@ -9,12 +9,12 @@ allow(Rpush::Gcm::Notification).to receive(:create!) { Rpush::Gcm::Notification.new } end - describe 'PATCH #visit' do - it 'marks notification as visited' do + describe "PATCH #visit" do + it "marks notification as visited" do notification = create(:notification, :create, user: user, seen: false, visited: false) set_current_user(user) - patch :visit, params: { id: notification.to_param } + patch :visit, params: {id: notification.to_param} response.should have_http_status(200) notification.reload @@ -22,8 +22,8 @@ end end - describe 'GET #index' do - it 'renders users notifications' do + describe "GET #index" do + it "renders users notifications" do set_current_user(user) first = create(:notification, :create, user: user) second = create(:notification, :create, user: user) @@ -38,8 +38,8 @@ end end - describe 'GET #look_all' do - it 'sets all notifications as seen' do + describe "GET #look_all" do + it "sets all notifications as seen" do set_current_user(user) create(:notification, :create, user: user, seen: false) create(:notification, :create, user: user, seen: false) diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index dbe1588c5..d381d83a3 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PagesController, type: :controller do let(:user) { create(:user) } @@ -9,38 +9,38 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #show' do - it 'assigns public and visible page' do + describe "GET #show" do + it "assigns public and visible page" do page = create(:page, public: true, visible: true) allow(user).to receive(:member?) { false } - get :show, params: { id: page.to_param } + get :show, params: {id: page.to_param} assigns(:page).should eq(page) end - it 'raises error if page is not visible' do + it "raises error if page is not visible" do page = create(:page, public: true, visible: false) allow(user).to receive(:member?) { false } lambda do - get :show, params: { id: page.to_param } + get :show, params: {id: page.to_param} end.should raise_error(ActionController::RoutingError) end - it 'assigns non public but visible page if member' do + it "assigns non public but visible page if member" do page = create(:page, public: false, visible: true) allow(user).to receive(:member?) { true } - get :show, params: { id: page.to_param } + get :show, params: {id: page.to_param} assigns(:page).should eq(page) end - it 'raises error for not public or page' do + it "raises error for not public or page" do page = create(:page, public: false, visible: false) allow(user).to receive(:member?) { true } lambda do - get :show, params: { id: page.to_param } + get :show, params: {id: page.to_param} end.should raise_error(ActionController::RoutingError) end end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 5872ff275..b7c236280 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PostsController, type: :controller do let(:user) { create(:user) } @@ -10,40 +10,40 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #show' do - it 'sets election and post' do + describe "GET #show" do + it "sets election and post" do election = create(:election, :autumn) the_post = create(:post, :autumn) - get :show, params: { id: the_post.to_param } + get :show, params: {id: the_post.to_param} response.should have_http_status(200) assigns(:election).should eq(election) assigns(:post).should eq(the_post) end - it 'returns 404 if no election' do + it "returns 404 if no election" do Election.stub(:current) { nil } the_post = create(:post) - get :show, params: { id: the_post.to_param } + get :show, params: {id: the_post.to_param} response.should have_http_status(404) - response.should render_template('elections/no_election') + response.should render_template("elections/no_election") end end - describe 'GET #modal' do - it 'renders modal' do + describe "GET #modal" do + it "renders modal" do create(:election, :autumn) the_post = create(:post, :autumn) - get :modal, xhr: true, params: { id: the_post.to_param } + get :modal, xhr: true, params: {id: the_post.to_param} response.should have_http_status(200) end - it 'renders error page' do + it "renders error page" do the_post = create(:post, :autumn) - get :modal, xhr: true, params: { id: the_post.to_param } + get :modal, xhr: true, params: {id: the_post.to_param} response.should have_http_status(404) end end diff --git a/spec/controllers/proposals_controller_spec.rb b/spec/controllers/proposals_controller_spec.rb index 82527d874..d818480f7 100644 --- a/spec/controllers/proposals_controller_spec.rb +++ b/spec/controllers/proposals_controller_spec.rb @@ -1,16 +1,15 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ProposalsController, type: :controller do - describe '#generate' do + describe "#generate" do render_views - it 'doesn\'t die horribly when you try to use it' do - attributes = { title: 'my proposal', points: [''] } + it "doesn't die horribly when you try to use it" do + attributes = {title: "my proposal", points: [""]} lambda do - post :generate, format: :pdf, params: { proposal: attributes } + post :generate, format: :pdf, params: {proposal: attributes} end.should_not raise_error response.should be_success end end end - diff --git a/spec/controllers/rents_controller_spec.rb b/spec/controllers/rents_controller_spec.rb index dd03d8983..1ba87d760 100644 --- a/spec/controllers/rents_controller_spec.rb +++ b/spec/controllers/rents_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe RentsController, type: :controller do let(:user) { create(:user) } @@ -9,41 +9,41 @@ allow(controller).to receive(:current_user).and_return(user) end - describe 'GET #index' do - context 'html' do - it 'sets proper variables' do + describe "GET #index" do + context "html" do + it "sets proper variables" do create(:rent, d_from: 1.hour.from_now, d_til: 5.hour.from_now) create(:rent, d_from: 6.hour.from_now, d_til: 10.hour.from_now) create(:rent, d_from: 11.hour.from_now, d_til: 16.hour.from_now) - create(:faq, category: 'Bil', question: 'Vad kostar bilen?') + create(:faq, category: "Bil", question: "Vad kostar bilen?") get :index - assigns(:faqs).map(&:question).should eq(['Vad kostar bilen?']) + assigns(:faqs).map(&:question).should eq(["Vad kostar bilen?"]) end end - context 'json' do - it 'sets proper variables' do + context "json" do + it "sets proper variables" do first = create(:rent, d_from: 1.hour.from_now, d_til: 5.hour.from_now) second = create(:rent, d_from: 6.hour.from_now, d_til: 10.hour.from_now) create(:rent, d_from: 11.hour.from_now, d_til: 16.hour.from_now) - get :index, format: :json, params: { start: 1.hour.ago, end: 7.hours.from_now } + get :index, format: :json, params: {start: 1.hour.ago, end: 7.hours.from_now} response.body.should eq([first, second].to_json) end end end - describe 'GET #show' do - it 'assigns the requested rent as @rent' do + describe "GET #show" do + it "assigns the requested rent as @rent" do rent = create(:rent) - get :show, params: { id: rent.to_param } + get :show, params: {id: rent.to_param} assigns(:rent).should eq(rent) end end - describe 'GET #new' do + describe "GET #new" do it :succeeds do get :new @@ -53,23 +53,23 @@ end end - describe 'POST #create' do - it 'valid parameters' do - attributes = { d_from: 1.hours.from_now, - d_til: 10.hours.from_now, - purpose: 'Åka till ikea', - user_id: user.id } + describe "POST #create" do + it "valid parameters" do + attributes = {d_from: 1.hours.from_now, + d_til: 10.hours.from_now, + purpose: "Åka till ikea", + user_id: user.id} lambda do - post :create, params: { rent: attributes } + post :create, params: {rent: attributes} end.should change(Rent, :count).by(1) response.should redirect_to(Rent.last) assigns(:rent).user.should eq(user) end - it 'invalid params' do + it "invalid params" do lambda do - post :create, params: { rent: { d_from: nil } } + post :create, params: {rent: {d_from: nil}} end.should change(Rent, :count).by(0) response.status.should eq(422) @@ -77,22 +77,22 @@ end end - describe 'PATCH #update' do - it 'valid params' do - rent = create(:rent, user: user, purpose: 'Not IKEA') - attributes = { purpose: 'Indeed IKEA', \ - d_from: 1.hours.from_now.strftime('%Y-%m-%d %H:%M'), \ - d_til: 10.hours.from_now.strftime('%Y-%m-%d %H:%M') } - patch :update, params: { id: rent.to_param, rent: attributes } + describe "PATCH #update" do + it "valid params" do + rent = create(:rent, user: user, purpose: "Not IKEA") + attributes = {purpose: "Indeed IKEA", \ + d_from: 1.hours.from_now.strftime("%Y-%m-%d %H:%M"), \ + d_til: 10.hours.from_now.strftime("%Y-%m-%d %H:%M")} + patch :update, params: {id: rent.to_param, rent: attributes} assigns(:rent).should eq(rent) response.should redirect_to(edit_rent_path(rent)) end - it 'invalid params' do - rent = create(:rent, user: user, purpose: 'Not IKEA') - attributes = { purpose: '' } - patch :update, params: { id: rent.to_param, rent: attributes } + it "invalid params" do + rent = create(:rent, user: user, purpose: "Not IKEA") + attributes = {purpose: ""} + patch :update, params: {id: rent.to_param, rent: attributes} assigns(:rent).should eq(rent) response.status.should eq(422) @@ -100,12 +100,12 @@ end end - describe 'DELETE #destroy' do - it 'destroys the requested rent' do + describe "DELETE #destroy" do + it "destroys the requested rent" do rent = create(:rent, user: user) lambda do - delete :destroy, params: { id: rent.to_param } + delete :destroy, params: {id: rent.to_param} end.should change(Rent, :count).by(-1) response.should redirect_to(rents_path) diff --git a/spec/controllers/short_links_controller_spec.rb b/spec/controllers/short_links_controller_spec.rb index 01b244354..a63655185 100644 --- a/spec/controllers/short_links_controller_spec.rb +++ b/spec/controllers/short_links_controller_spec.rb @@ -1,40 +1,40 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ShortLinksController, type: :controller do allow_user_to(:manage, ShortLink) - describe '#go' do - it 'redirects to the link when present' do - link = 'hej' - target = 'http://hej.se' + describe "#go" do + it "redirects to the link when present" do + link = "hej" + target = "http://hej.se" sl = create(:short_link, link: link, target: target) - get :go, params: { link: link } + get :go, params: {link: link} response.status.should eq(301) response.location.should eq(sl.target) end - it 'throws 404 when link is not found' do + it "throws 404 when link is not found" do lambda do - get :go, params: { link: 'nonexistent' } + get :go, params: {link: "nonexistent"} end.should raise_error ActionController::RoutingError end end - describe '#check' do - it 'returns 204 when link exists' do - link = 'testlink' + describe "#check" do + it "returns 204 when link exists" do + link = "testlink" create :short_link, link: link - get :check, params: { link: link } + get :check, params: {link: link} response.status.should eq(204) response.body.should be_empty end - it 'returns 404 when link doesn\' exist' do - get :check, params: { link: 'nonexistent' } + it "returns 404 when link doesn' exist" do + get :check, params: {link: "nonexistent"} response.status.should eq(404) response.body.should be_empty diff --git a/spec/controllers/static_pages_controller_spec.rb b/spec/controllers/static_pages_controller_spec.rb index 0f1189afb..1cb0fec62 100644 --- a/spec/controllers/static_pages_controller_spec.rb +++ b/spec/controllers/static_pages_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe StaticPagesController, type: :controller do let(:user) { create(:user) } @@ -9,36 +9,36 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #about' do - it 'renders page with status 200' do + describe "GET #about" do + it "renders page with status 200" do get(:about) response.status.should eq(200) end end - describe 'GET #cookies' do - it 'renders page with status 200' do + describe "GET #cookies" do + it "renders page with status 200" do get(:cookies_information) response.status.should eq(200) end end - describe 'GET #company_offer' do - it 'renders page with status 200' do + describe "GET #company_offer" do + it "renders page with status 200" do get(:company_offer) response.status.should eq(200) end end - describe 'GET #company_about' do - it 'renders page with status 200' do + describe "GET #company_about" do + it "renders page with status 200" do get(:company_about) response.status.should eq(200) end end - describe 'GET #index' do - it 'not signed in, renders page with status 200' do + describe "GET #index" do + it "not signed in, renders page with status 200" do get(:index) response.status.should eq(200) diff --git a/spec/controllers/tools_controller_spec.rb b/spec/controllers/tools_controller_spec.rb index 27ad07d4b..fd68cd09d 100644 --- a/spec/controllers/tools_controller_spec.rb +++ b/spec/controllers/tools_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ToolsController, type: :controller do let(:user) { create(:user) } @@ -9,19 +9,19 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'loads index view properly' do + describe "GET #index" do + it "loads index view properly" do get :index response.status.should eq(200) end end - describe 'GET #show' do - it 'loads show view properly' do + describe "GET #show" do + it "loads show view properly" do tool = create(:tool) create(:tool_renting, tool: tool) create(:tool_renting, tool: tool) - get :show, params: { id: tool.to_param } + get :show, params: {id: tool.to_param} response.status.should eq(200) end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index a22647772..a0d6fdc69 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,20 +1,20 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe UsersController, type: :controller do allow_user_to :manage, User - describe 'GET #show' do - it 'assigns the requested user as @user' do + describe "GET #show" do + it "assigns the requested user as @user" do user = create(:user) - get :show, params: { id: user.to_param } + get :show, params: {id: user.to_param} response.should have_http_status(200) assigns(:user).should eq(user) end end - describe 'GET #edit' do - it 'should render edit page' do + describe "GET #edit" do + it "should render edit page" do user = create(:user) controller.stub(:current_user).and_return(user) @@ -23,34 +23,34 @@ end end - describe 'PATCH #update' do - it 'valid parameters' do - user = create(:user, firstname: 'Hacke') + describe "PATCH #update" do + it "valid parameters" do + user = create(:user, firstname: "Hacke") controller.stub(:current_user).and_return(user) - patch :update, params: { user: { firstname: 'Hilbert' } } + patch :update, params: {user: {firstname: "Hilbert"}} user.reload - user.firstname.should eq('Hilbert') + user.firstname.should eq("Hilbert") response.should have_http_status(200) response.should render_template(:edit) end end - describe 'PATCH #update_account' do - it 'valid parameters' do - user = create(:user, email: 'hilbert@fsektionen.se') + describe "PATCH #update_account" do + it "valid parameters" do + user = create(:user, email: "hilbert@fsektionen.se") controller.stub(:current_user).and_return(user) - patch :update_account, params: { user: { email: 'alg@fsektionen.se', current_password: '12345678' } } + patch :update_account, params: {user: {email: "alg@fsektionen.se", current_password: "12345678"}} user.reload - user.unconfirmed_email.should eq('alg@fsektionen.se') + user.unconfirmed_email.should eq("alg@fsektionen.se") response.should have_http_status(200) response.should render_template(:edit) end - it 'invalid parameters' do - user = create(:user, email: 'hilbert@fsektionen.se') + it "invalid parameters" do + user = create(:user, email: "hilbert@fsektionen.se") controller.stub(:current_user).and_return(user) - patch :update_account, params: { user: { email: 'alg@fsektionen.se', current_password: 'not_valid' } } + patch :update_account, params: {user: {email: "alg@fsektionen.se", current_password: "not_valid"}} user.reload user.unconfirmed_email.should be_nil response.should have_http_status(422) @@ -58,28 +58,28 @@ end end - describe 'PATCH #update_password' do - it 'valid parameters' do + describe "PATCH #update_password" do + it "valid parameters" do user = create(:user) controller.stub(:current_user).and_return(user) - patch :update_password, params: { user: { password: 'testatesta', - password_confirmation: 'testatesta', - current_password: '12345678' } } + patch :update_password, params: {user: {password: "testatesta", + password_confirmation: "testatesta", + current_password: "12345678"}} user.reload - user.valid_password?('testatesta').should be_truthy + user.valid_password?("testatesta").should be_truthy response.should have_http_status(200) response.should render_template(:edit) assigns(:tab).should eq(:password) end - it 'invalid parameters' do + it "invalid parameters" do user = create(:user) controller.stub(:current_user).and_return(user) - patch :update_password, params: { user: { password: 'fail_testa', - password_confirmation: 'fail_fail', - current_password: '12345678' } } + patch :update_password, params: {user: {password: "fail_testa", + password_confirmation: "fail_fail", + current_password: "12345678"}} user.reload - user.valid_password?('fail_testa').should be_falsey + user.valid_password?("fail_testa").should be_falsey response.should have_http_status(422) response.should render_template(:edit) assigns(:tab).should eq(:password) diff --git a/spec/controllers/work_posts_controller_spec.rb b/spec/controllers/work_posts_controller_spec.rb index 32bf56bad..92f9d2d49 100644 --- a/spec/controllers/work_posts_controller_spec.rb +++ b/spec/controllers/work_posts_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe WorkPostsController, type: :controller do let(:user) { create(:admin) } @@ -9,25 +9,25 @@ allow(controller).to receive(:current_user) { user } end - describe 'GET #index' do - it 'assigns a @work_portal with work_posts' do - create(:work_post, title: 'First work_post') - create(:work_post, title: 'Second work_post', visible: false) - create(:work_post, title: 'Third work_post') + describe "GET #index" do + it "assigns a @work_portal with work_posts" do + create(:work_post, title: "First work_post") + create(:work_post, title: "Second work_post", visible: false) + create(:work_post, title: "Third work_post") get(:index) response.status.should eq(200) - assigns(:work_portal).work_posts.map(&:title).should eq(['First work_post', - 'Third work_post']) + assigns(:work_portal).work_posts.map(&:title).should eq(["First work_post", + "Third work_post"]) end end - describe 'GET #show' do - it 'assings work_post as @work_post' do + describe "GET #show" do + it "assings work_post as @work_post" do work_post = create(:work_post) - get :show, params: { id: work_post.to_param } + get :show, params: {id: work_post.to_param} response.status.should eq(200) assigns(:work_post).should eq(work_post) diff --git a/spec/factories/albums.rb b/spec/factories/albums.rb index b9dcfe4da..a729786b3 100644 --- a/spec/factories/albums.rb +++ b/spec/factories/albums.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :album do title diff --git a/spec/factories/cafe_shifts.rb b/spec/factories/cafe_shifts.rb index 66ac36323..cfa3e9694 100644 --- a/spec/factories/cafe_shifts.rb +++ b/spec/factories/cafe_shifts.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :cafe_shift do pass 1 @@ -13,7 +12,7 @@ end trait :invalid do - pass -5 + pass(-5) lv 1337 lp 6122 end diff --git a/spec/factories/constants.rb b/spec/factories/constants.rb index 9eebe7d9d..d85a8c512 100644 --- a/spec/factories/constants.rb +++ b/spec/factories/constants.rb @@ -1,4 +1,3 @@ -#encoding: UTF-8 FactoryBot.define do factory :constant do name diff --git a/spec/factories/contact_messages.rb b/spec/factories/contact_messages.rb index 16d4cb2d3..c9e9fdc19 100644 --- a/spec/factories/contact_messages.rb +++ b/spec/factories/contact_messages.rb @@ -1,9 +1,8 @@ -# encoding: UTF-8 FactoryBot.define do factory :contact_message do skip_create - name 'Hilbert Älg' - email 'utomifran@gmail.se' + name "Hilbert Älg" + email "utomifran@gmail.se" message { generate(:description) } end end diff --git a/spec/factories/contacts.rb b/spec/factories/contacts.rb index 45d6dcd4b..a48aad88f 100644 --- a/spec/factories/contacts.rb +++ b/spec/factories/contacts.rb @@ -1,7 +1,6 @@ -# encoding: UTF-8 FactoryBot.define do factory :contact do |c| - name 'Spindelmän' + name "Spindelmän" email c.public { [true, false].sample } text { generate(:description) } diff --git a/spec/factories/councils.rb b/spec/factories/councils.rb index a8528e66e..6983b232d 100644 --- a/spec/factories/councils.rb +++ b/spec/factories/councils.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :council do title diff --git a/spec/factories/documents.rb b/spec/factories/documents.rb index 09688cfb3..669e76103 100644 --- a/spec/factories/documents.rb +++ b/spec/factories/documents.rb @@ -1,8 +1,7 @@ -# encoding: UTF-8 FactoryBot.define do factory :document do title - pdf Rack::Test::UploadedFile.new(File.open('spec/assets/pdf.pdf')) - category { ['Styrdokument', 'Protokoll', 'Von Tänen'].sample } + pdf Rack::Test::UploadedFile.new(File.open("spec/assets/pdf.pdf")) + category { ["Styrdokument", "Protokoll", "Von Tänen"].sample } end end diff --git a/spec/factories/event_signups.rb b/spec/factories/event_signups.rb index c4879f273..3ed09aea4 100644 --- a/spec/factories/event_signups.rb +++ b/spec/factories/event_signups.rb @@ -4,7 +4,7 @@ slots 5 opens { Time.zone.now } closes { opens + 1.day } - custom_name 'Dryga gamla fös' + custom_name "Dryga gamla fös" custom 37 novice 30 mentor 20 diff --git a/spec/factories/faq.rb b/spec/factories/faq.rb index 8cb94f1fb..db8fa6edb 100644 --- a/spec/factories/faq.rb +++ b/spec/factories/faq.rb @@ -1,8 +1,7 @@ -# encoding: UTF-8 FactoryBot.define do factory :faq do question { generate(:description) } answer { generate(:description) } - category { ['Hilbert Café', 'F-bilen', 'Styrelsen'].sample } + category { ["Hilbert Café", "F-bilen", "Styrelsen"].sample } end end diff --git a/spec/factories/images.rb b/spec/factories/images.rb index 55fe9f879..d34cae5b5 100644 --- a/spec/factories/images.rb +++ b/spec/factories/images.rb @@ -1,9 +1,8 @@ -# encoding: UTF-8 FactoryBot.define do factory :image do album photographer { FactoryBot.create(:user) } - file Rack::Test::UploadedFile.new(File.open('spec/assets/image.jpg')) + file Rack::Test::UploadedFile.new(File.open("spec/assets/image.jpg")) filename { generate(:firstname) } end end diff --git a/spec/factories/mail_aliases.rb b/spec/factories/mail_aliases.rb index 87b29b807..55960ad36 100644 --- a/spec/factories/mail_aliases.rb +++ b/spec/factories/mail_aliases.rb @@ -1,8 +1,7 @@ FactoryBot.define do factory :mail_alias do - username 'mr_boss' - domain 'fsektionen.se' - target 'johan@forberg.se' + username "mr_boss" + domain "fsektionen.se" + target "johan@forberg.se" end end - diff --git a/spec/factories/news.rb b/spec/factories/news.rb index c18f32249..4a3318513 100644 --- a/spec/factories/news.rb +++ b/spec/factories/news.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :news do title @@ -6,7 +5,7 @@ user trait :with_image do - image Rack::Test::UploadedFile.new(File.open('spec/assets/image.jpg')) + image Rack::Test::UploadedFile.new(File.open("spec/assets/image.jpg")) end end end diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb index 0468590e8..784085c09 100644 --- a/spec/factories/notifications.rb +++ b/spec/factories/notifications.rb @@ -2,7 +2,7 @@ factory :notification do user seen false - mode Notification::ALLOWED['EventUser'].keys.first + mode Notification::ALLOWED["EventUser"].keys.first # To be able to use the same user for an event_user this hack is used. # Callable as build(:notification, :build) diff --git a/spec/factories/page_elements.rb b/spec/factories/page_elements.rb index fc99b2fc3..8eec912fd 100644 --- a/spec/factories/page_elements.rb +++ b/spec/factories/page_elements.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :page_element do page diff --git a/spec/factories/page_images.rb b/spec/factories/page_images.rb index ff3d7c470..25a210d61 100644 --- a/spec/factories/page_images.rb +++ b/spec/factories/page_images.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :page_image do page - image Rack::Test::UploadedFile.new(File.open('spec/assets/image.jpg')) + image Rack::Test::UploadedFile.new(File.open("spec/assets/image.jpg")) end end diff --git a/spec/factories/pages.rb b/spec/factories/pages.rb index 2b6613efc..1debfb7da 100644 --- a/spec/factories/pages.rb +++ b/spec/factories/pages.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :page do url diff --git a/spec/factories/permissions.rb b/spec/factories/permissions.rb index 8db4a8ed6..8ed8ae957 100644 --- a/spec/factories/permissions.rb +++ b/spec/factories/permissions.rb @@ -1,9 +1,9 @@ FactoryBot.define do factory :permission do - subject_class { ['News', 'CafeWork', 'Post', 'Rent', 'Event'].sample } - action { ['read', 'create', 'update', 'manage', 'new'].sample } + subject_class { ["News", "CafeWork", "Post", "Rent", "Event"].sample } + action { ["read", "create", "update", "manage", "new"].sample } end - factory :admin_permission, class: 'Permission' do + factory :admin_permission, class: "Permission" do subject_class :all action :manage end diff --git a/spec/factories/posts.rb b/spec/factories/posts.rb index 78ba6eafa..e3c87ed8f 100644 --- a/spec/factories/posts.rb +++ b/spec/factories/posts.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 FactoryBot.define do factory :post do title diff --git a/spec/factories/rents.rb b/spec/factories/rents.rb index 4e66bc3b8..6a03f282f 100644 --- a/spec/factories/rents.rb +++ b/spec/factories/rents.rb @@ -1,14 +1,12 @@ -# encoding: UTF-8 FactoryBot.define do - factory :rent do user - purpose 'Handla möbler på IKEA' + purpose "Handla möbler på IKEA" d_from { Time.zone.now + 10.days } d_til { Time.zone.now + 10.days + 12.hours } aktiv true status :confirmed - terms '1' + terms "1" # Override after_create callbacks. after(:build) do |rent| @@ -35,10 +33,10 @@ end trait :purpose do - purpose 'Handla möbler på IKEA' + purpose "Handla möbler på IKEA" end trait :comment do - comment 'Du har uppebarligen inget körkort' + comment "Du har uppebarligen inget körkort" end end diff --git a/spec/factories/shared.rb b/spec/factories/shared.rb index 1b05bf6af..f1809e5c4 100644 --- a/spec/factories/shared.rb +++ b/spec/factories/shared.rb @@ -1,16 +1,16 @@ FactoryBot.define do sequence(:description) { |n| "This describes the most impressive nr#{n}" } sequence(:email) { |n| "d.wessman#{n}@fsektionen.se" } - sequence(:lastname, 'A') { |n| "Wessman#{n}" } + sequence(:lastname, "A") { |n| "Wessman#{n}" } sequence(:name) { |n| "David#{n}" } - sequence(:firstname, 'A') { |n| "David#{n}" } + sequence(:firstname, "A") { |n| "David#{n}" } sequence(:phone) { |n| "070#{n}606122" } sequence(:student_id) { |n| "tfy54dw#{n}" } sequence(:title) { |n| "Titel#{n}" } sequence(:url) { |n| "url#{n}" } sequence(:username) { |n| "davidwessman#{n}" } sequence(:value) { |n| "david#{n}" } - sequence(:location) { ['MH:A','Hilbert','Kårhuset','Ön-ön','Sjönsjön','Bastun'].sample } + sequence(:location) { ["MH:A", "Hilbert", "Kårhuset", "Ön-ön", "Sjönsjön", "Bastun"].sample } sequence(:date) { |n| Time.zone.now + 10.days + n.days } trait :with_user do diff --git a/spec/factories/short_links.rb b/spec/factories/short_links.rb index bc3d780c7..331cc6136 100644 --- a/spec/factories/short_links.rb +++ b/spec/factories/short_links.rb @@ -1,7 +1,6 @@ FactoryBot.define do factory :short_link do - link 'my_awesomeshort-link0' - target 'http://randomwebpage.com:80/some/resource/yeah?q=asdf&yeah=' + link "my_awesomeshort-link0" + target "http://randomwebpage.com:80/some/resource/yeah?q=asdf&yeah=" end end - diff --git a/spec/factories/tool_rentings.rb b/spec/factories/tool_rentings.rb index ed97cffdf..425183d89 100644 --- a/spec/factories/tool_rentings.rb +++ b/spec/factories/tool_rentings.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :tool_renting do user_id 1 - purpose 'to use' + purpose "to use" tool return_date { Time.zone.now + 10.days } returned false diff --git a/spec/factories/tools.rb b/spec/factories/tools.rb index 4901a02a2..ba8b5e598 100644 --- a/spec/factories/tools.rb +++ b/spec/factories/tools.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :tool do - title 'Awesome Tool' + title "Awesome Tool" description total 3 end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index fb94b2c13..fcc882b6c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,8 +1,8 @@ FactoryBot.define do factory :user do email - password '12345678' - password_confirmation '12345678' + password "12345678" + password_confirmation "12345678" firstname lastname phone @@ -13,15 +13,15 @@ terms_version 1 trait :admin do - password '12345678' + password "12345678" with_admin_post end end - factory :admin, class: 'User' do + factory :admin, class: "User" do email - password '12345678' - password_confirmation '12345678' + password "12345678" + password_confirmation "12345678" firstname lastname phone @@ -40,12 +40,12 @@ trait :unconfirmed do confirmed_at nil - confirmation_token 'confirmmyaccount' + confirmation_token "confirmmyaccount" confirmation_sent_at { Time.zone.now } end trait :reset_password do - reset_password_token 'resetmypassword' + reset_password_token "resetmypassword" reset_password_sent_at { Time.zone.now } end diff --git a/spec/factories/work_posts.rb b/spec/factories/work_posts.rb index 90f81110d..5653798c1 100644 --- a/spec/factories/work_posts.rb +++ b/spec/factories/work_posts.rb @@ -1,18 +1,17 @@ -# encoding: UTF-8 FactoryBot.define do factory :work_post do title description - kind { ['Sommarjobb', 'Examensarbete', 'Deltid'].sample } - company { ['IKEA', 'Axis', 'Sony', 'Flatfrog'].sample } - target_group { ['Teknisk matematik', 'Teknisk fysik', 'Teknisk nanovetenskap'].sample } - field { ['Fysik', 'IT', 'Ekonomi'].sample } + kind { ["Sommarjobb", "Examensarbete", "Deltid"].sample } + company { ["IKEA", "Axis", "Sony", "Flatfrog"].sample } + target_group { ["Teknisk matematik", "Teknisk fysik", "Teknisk nanovetenskap"].sample } + field { ["Fysik", "IT", "Ekonomi"].sample } deadline { Time.zone.now + 10.days } visible true publish { Time.zone.now - 1.days } trait :image do - image Rack::Test::UploadedFile.new(File.open('spec/assets/image.jpg')) + image Rack::Test::UploadedFile.new(File.open("spec/assets/image.jpg")) end end end diff --git a/spec/features/admin/visit_spec.rb b/spec/features/admin/visit_spec.rb index 1b4d29a94..992c3a5f3 100644 --- a/spec/features/admin/visit_spec.rb +++ b/spec/features/admin/visit_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' +require "rails_helper" -RSpec.feature 'admin visits paths' do +RSpec.feature "admin visits paths" do let(:user) { create(:admin) } paths = { @@ -36,7 +36,7 @@ value.each do |v| scenario %(controller: #{key}, action: #{v}) do if v == :show || v == :edit - resource = create(key.to_s.split('/').last.singularize.to_sym) + resource = create(key.to_s.split("/").last.singularize.to_sym) page.visit url_for(controller: key, action: v, id: resource.to_param) else diff --git a/spec/features/cafe_shift_spec.rb b/spec/features/cafe_shift_spec.rb index cffa17cea..e4380715c 100644 --- a/spec/features/cafe_shift_spec.rb +++ b/spec/features/cafe_shift_spec.rb @@ -1,15 +1,15 @@ -require 'rails_helper' -RSpec.feature 'Visit cafe', type: :feature do - scenario 'sign up to work' do +require "rails_helper" +RSpec.feature "Visit cafe", type: :feature do + scenario "sign up to work" do user = create(:user) cafe_shift = create(:cafe_shift) sign_in_as(user, path: cafe_shift_path(cafe_shift)) - check 'cafe_worker_competition' - click_button I18n.t('helpers.submit.cafe_worker.create') - page.should have_css('div.alert.alert-info') - find('div.alert.alert-info').text.should include(I18n.t('model.cafe_worker.created')) + check "cafe_worker_competition" + click_button I18n.t("helpers.submit.cafe_worker.create") + page.should have_css("div.alert.alert-info") + find("div.alert.alert-info").text.should include(I18n.t("model.cafe_worker.created")) cafe_shift.reload cafe_shift.cafe_worker.user.should eq(user) diff --git a/spec/features/contacts_spec.rb b/spec/features/contacts_spec.rb index 25afe0728..8a31031e4 100644 --- a/spec/features/contacts_spec.rb +++ b/spec/features/contacts_spec.rb @@ -1,27 +1,27 @@ -require 'rails_helper' -RSpec.feature 'fill out send_form', type: :feature do - scenario 'contact via index page' do +require "rails_helper" +RSpec.feature "fill out send_form", type: :feature do + scenario "contact via index page" do contact = create(:contact, public: true) message = create(:contact_message) page.visit(contacts_path) - page.should have_css('#contacts_title', - text: I18n.t('contacts.index.title')) + page.should have_css("#contacts_title", + text: I18n.t("contacts.index.title")) first(:linkhref, contact_path(contact)).click page.status_code.should eq(200) - page.fill_in 'contact_message_name', with: message.name - page.fill_in 'contact_message_email', with: message.email - page.fill_in 'contact_message_message', with: message.message + page.fill_in "contact_message_name", with: message.name + page.fill_in "contact_message_email", with: message.email + page.fill_in "contact_message_message", with: message.message find('input[name="commit"]').click page.should have_http_status(200) end - scenario 'contact with invalid info' do + scenario "contact with invalid info" do contact = create(:contact, public: true) page.visit contact_path(contact) - page.fill_in 'contact_message_email', with: 'my_email' - page.fill_in 'contact_message_message', with: 'my message' + page.fill_in "contact_message_email", with: "my_email" + page.fill_in "contact_message_message", with: "my message" find('input[name="commit"]').click page.should have_http_status(422) diff --git a/spec/features/election/candidate_spec.rb b/spec/features/election/candidate_spec.rb index f87ffd49a..5a8b1185b 100644 --- a/spec/features/election/candidate_spec.rb +++ b/spec/features/election/candidate_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' -RSpec.feature 'Visit Election', type: :feature do - scenario 'creates a candidate' do +require "rails_helper" +RSpec.feature "Visit Election", type: :feature do + scenario "creates a candidate" do user = create(:user) create(:election, :autumn) postt = create(:post, :autumn) @@ -9,11 +9,11 @@ find(:linkhref, new_candidate_path).click page.status_code.should eq(200) - select(postt, from: 'candidate_post_id') - select(user, from: 'candidate_user_id') - find('#candidate-submit').click + select(postt, from: "candidate_post_id") + select(user, from: "candidate_user_id") + find("#candidate-submit").click - page.should have_css('div.alert.alert-success') - find('div.alert.alert-success').text.should include(I18n.t('global_controller.success_create')) + page.should have_css("div.alert.alert-success") + find("div.alert.alert-success").text.should include(I18n.t("global_controller.success_create")) end end diff --git a/spec/features/election/election_spec.rb b/spec/features/election/election_spec.rb index aa97e5838..60db3fc7d 100644 --- a/spec/features/election/election_spec.rb +++ b/spec/features/election/election_spec.rb @@ -1,32 +1,32 @@ -require 'rails_helper' -RSpec.feature 'Visit Election' do - scenario 'visits election before_general' do +require "rails_helper" +RSpec.feature "Visit Election" do + scenario "visits election before_general" do create(:post, :autumn) election = create(:election, :before_general, :autumn) page.visit elections_path page.should have_http_status(200) - page.should have_css('h1#election-title') - find('h1#election-title').text.should include(election.title) + page.should have_css("h1#election-title") + find("h1#election-title").text.should include(election.title) end - scenario 'visits election after_general' do + scenario "visits election after_general" do create(:post, :autumn) election = create(:election, :after_general, :autumn) page.visit elections_path page.should have_http_status(200) - page.should have_css('h1#election-title') - find('h1#election-title').text.should include(election.title) + page.should have_css("h1#election-title") + find("h1#election-title").text.should include(election.title) end - scenario 'visits election closed' do + scenario "visits election closed" do create(:post, :autumn) election = create(:election, :closed, :autumn) page.visit elections_path page.should have_http_status(200) - page.should have_css('h1#election-title') - find('h1#election-title').text.should include(election.title) + page.should have_css("h1#election-title") + find("h1#election-title").text.should include(election.title) end end diff --git a/spec/features/election/nomination_spec.rb b/spec/features/election/nomination_spec.rb index 05b256847..9b6cedc35 100644 --- a/spec/features/election/nomination_spec.rb +++ b/spec/features/election/nomination_spec.rb @@ -1,20 +1,20 @@ -require 'rails_helper' -RSpec.feature 'Visit Election', type: :feature do - scenario 'nominating successfully' do +require "rails_helper" +RSpec.feature "Visit Election", type: :feature do + scenario "nominating successfully" do user = create(:user) create(:election, :autumn) the_post = create(:post, :autumn) sign_in_as(user, path: new_nominations_path) - fill_in 'nomination_name', with: 'David Wessman' - fill_in 'nomination_email', with: 'd.wessman@fsektionen.se' - select(the_post, from: 'nomination_post_id') - fill_in 'nomination_motivation', with: 'Foo' + fill_in "nomination_name", with: "David Wessman" + fill_in "nomination_email", with: "d.wessman@fsektionen.se" + select(the_post, from: "nomination_post_id") + fill_in "nomination_motivation", with: "Foo" - find('#nomination-submit').click + find("#nomination-submit").click page.status_code.should eq(200) - page.should have_css('div.alert.alert-success') - find('div.alert.alert-success').text.should include(I18n.t('global_controller.success_create')) + page.should have_css("div.alert.alert-success") + find("div.alert.alert-success").text.should include(I18n.t("global_controller.success_create")) end end diff --git a/spec/features/groups_spec.rb b/spec/features/groups_spec.rb index 61fb43078..07e74d403 100644 --- a/spec/features/groups_spec.rb +++ b/spec/features/groups_spec.rb @@ -1,29 +1,29 @@ -require 'rails_helper' -RSpec.feature 'Groups' do - scenario 'group member visits group' do +require "rails_helper" +RSpec.feature "Groups" do + scenario "group member visits group" do user = create(:user) - group = create(:group, name: 'Godtycklig grupp') + group = create(:group, name: "Godtycklig grupp") create(:group_user, group: group, user: user) sign_in_as(user) page.visit(group_path(group)) - page.should have_css('div.group-user-list') + page.should have_css("div.group-user-list") page.should have_text(group.name) - page.should_not have_css('div.alert.alert-danger') + page.should_not have_css("div.alert.alert-danger") end - scenario 'non group member visits group' do + scenario "non group member visits group" do user = create(:user) - group = create(:group, name: 'Godtycklig grupp') + group = create(:group, name: "Godtycklig grupp") sign_in_as(user) page.visit(group_path(group)) page.should_not have_text(group.name) - page.should have_css('div.alert.alert-danger') - find('div.alert.alert-danger').text.should include(I18n.t('unauthorized.manage.all', - action: 'show', - subject: 'group')) + page.should have_css("div.alert.alert-danger") + find("div.alert.alert-danger").text.should include(I18n.t("unauthorized.manage.all", + action: "show", + subject: "group")) end end diff --git a/spec/features/introductions_spec.rb b/spec/features/introductions_spec.rb index e956b9dd9..cf1d32302 100644 --- a/spec/features/introductions_spec.rb +++ b/spec/features/introductions_spec.rb @@ -1,24 +1,24 @@ -require 'rails_helper' +require "rails_helper" -RSpec.feature 'visit introductions' do +RSpec.feature "visit introductions" do let(:user) { create(:user) } before(:each) do sign_in_as(user) end - it 'visits current introduction' do - create(:introduction, title: 'En Ridderlig Nollning', current: true) + it "visits current introduction" do + create(:introduction, title: "En Ridderlig Nollning", current: true) page.visit(introductions_path) page.should have_http_status(200) - find('.headline > h1').text.should include('En Ridderlig Nollning') + find(".headline > h1").text.should include("En Ridderlig Nollning") end - it 'visit introductions, render archive' do - create(:introduction, title: 'En Ridderlig Nollning', current: false) + it "visit introductions, render archive" do + create(:introduction, title: "En Ridderlig Nollning", current: false) page.visit(introductions_path) page.should have_http_status(404) - find('.headline > h1').text.should include(I18n.t('introductions.archive.title')) + find(".headline > h1").text.should include(I18n.t("introductions.archive.title")) end end diff --git a/spec/features/messages_spec.rb b/spec/features/messages_spec.rb index f6bc37dc5..947a7dc3c 100644 --- a/spec/features/messages_spec.rb +++ b/spec/features/messages_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" -RSpec.feature 'Send messages', type: :feature do - it 'sends messsage' do +RSpec.feature "Send messages", type: :feature do + it "sends messsage" do user = create(:user) group = create(:group) group.users << user @@ -9,6 +9,6 @@ sign_in_as(user, path: group_path(group)) page.status_code.should eq(200) - page.fill_in('message_content', with: 'Hej och välkomna, liksom waow') + page.fill_in("message_content", with: "Hej och välkomna, liksom waow") end end diff --git a/spec/features/pages_spec.rb b/spec/features/pages_spec.rb index 726d75d2d..fa2aa8bb2 100644 --- a/spec/features/pages_spec.rb +++ b/spec/features/pages_spec.rb @@ -1,14 +1,14 @@ -require 'rails_helper' -RSpec.feature 'Pages' do - it 'visits as normal user' do +require "rails_helper" +RSpec.feature "Pages" do + it "visits as normal user" do user = create(:user) - page_object = create(:page, visible: true, public: true, title: 'Motioner') + page_object = create(:page, visible: true, public: true, title: "Motioner") create(:page_element, :text, page: page_object, visible: true) create(:page_element, :image, page: page_object, visible: true) sign_in_as(user, path: page_path(page_object)) page.status_code.should eq(200) - find('.headline h1').text.should eq('Motioner') - page.should_not have_css('.col-md-12 a.pull-right') + find(".headline h1").text.should eq("Motioner") + page.should_not have_css(".col-md-12 a.pull-right") end end diff --git a/spec/features/user/account_spec.rb b/spec/features/user/account_spec.rb index 7925af228..9040ce812 100644 --- a/spec/features/user/account_spec.rb +++ b/spec/features/user/account_spec.rb @@ -1,60 +1,60 @@ -require 'rails_helper' -RSpec.feature 'Update account', type: :feature do - scenario 'information' do +require "rails_helper" +RSpec.feature "Update account", type: :feature do + scenario "information" do user = create(:user, student_id: nil) sign_in_as(user, path: edit_own_user_path) page.should have_http_status(200) - fill_in('user_student_id', with: %(tfy#{Time.zone.now.year - 2000}ggg)) - click_button('user-info-submit') - page.should have_css('div.alert.alert-success') + fill_in("user_student_id", with: %(tfy#{Time.zone.now.year - 2000}ggg)) + click_button("user-info-submit") + page.should have_css("div.alert.alert-success") - find('div.alert.alert-success').text.should include(I18n.t('global_controller.success_update')) + find("div.alert.alert-success").text.should include(I18n.t("global_controller.success_update")) page.should have_http_status(200) user.reload user.student_id.should eq(%(tfy#{Time.zone.now.year - 2000}ggg)) end - scenario 'email' do + scenario "email" do user = create(:user) sign_in_as(user, path: edit_own_user_path) page.should have_http_status(200) find(:linkhref, edit_own_user_path(tab: :account)).click - fill_in('user_email', with: 'new@fsektionen.se') - fill_in('user_current_password', with: '12345678') - click_button('user-account-submit') + fill_in("user_email", with: "new@fsektionen.se") + fill_in("user_current_password", with: "12345678") + click_button("user-account-submit") - page.should have_css('div.alert.alert-info') + page.should have_css("div.alert.alert-info") - find('div.alert.alert-info').text.should \ - include(I18n.t('model.user.account_updated')) + find("div.alert.alert-info").text.should \ + include(I18n.t("model.user.account_updated")) user.reload - user.unconfirmed_email.should eq('new@fsektionen.se') + user.unconfirmed_email.should eq("new@fsektionen.se") end - scenario 'password' do + scenario "password" do user = create(:user) sign_in_as(user, path: edit_own_user_path) page.should have_http_status(200) find(:linkhref, edit_own_user_path(tab: :password)).click - fill_in('user_password', with: '87654321') - fill_in('user_password_confirmation', with: '87654321') - fill_in('user_current_password', with: '12345678') - click_button('user-password-submit') + fill_in("user_password", with: "87654321") + fill_in("user_password_confirmation", with: "87654321") + fill_in("user_current_password", with: "12345678") + click_button("user-password-submit") - page.should have_css('div.alert.alert-info') + page.should have_css("div.alert.alert-info") - find('div.alert.alert-info').text.should \ - include(I18n.t('model.user.password_updated')) + find("div.alert.alert-info").text.should \ + include(I18n.t("model.user.password_updated")) user.reload - user.valid_password?('87654321').should be_truthy + user.valid_password?("87654321").should be_truthy end end diff --git a/spec/features/user/confirm_account_spec.rb b/spec/features/user/confirm_account_spec.rb index 49c506502..6be1ca90b 100644 --- a/spec/features/user/confirm_account_spec.rb +++ b/spec/features/user/confirm_account_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' -RSpec.feature 'Confirm account' do +require "rails_helper" +RSpec.feature "Confirm account" do let(:user) { create(:user, :unconfirmed) } - scenario 'confirm' do + scenario "confirm" do page.visit(user_confirmation_url(confirmation_token: user.confirmation_token)) page.status_code.should eq(200) - find('div.alert.alert-info').text.should include(I18n.t('devise.confirmations.confirmed')) + find("div.alert.alert-info").text.should include(I18n.t("devise.confirmations.confirmed")) user.reload.confirmed?.should be_truthy end end diff --git a/spec/features/user/log_in_spec.rb b/spec/features/user/log_in_spec.rb index 15c76f4ad..1cc81bb0b 100644 --- a/spec/features/user/log_in_spec.rb +++ b/spec/features/user/log_in_spec.rb @@ -1,43 +1,43 @@ -require 'rails_helper' -RSpec.feature 'User sign in' do +require "rails_helper" +RSpec.feature "User sign in" do let(:user) { create(:user) } - scenario 'sign in correct credentials' do + scenario "sign in correct credentials" do page.visit(new_user_session_path) - page.fill_in 'user_email', with: user.email - page.fill_in 'user_password', with: '12345678' - page.click_button I18n.t('devise.sign_in') - page.should have_css('div.alert.alert-info') - find('div.alert.alert-info').text.should include(I18n.t('devise.sessions.signed_in')) + page.fill_in "user_email", with: user.email + page.fill_in "user_password", with: "12345678" + page.click_button I18n.t("devise.sign_in") + page.should have_css("div.alert.alert-info") + find("div.alert.alert-info").text.should include(I18n.t("devise.sessions.signed_in")) end - scenario 'sign in incorrect password' do + scenario "sign in incorrect password" do page.visit(new_user_session_path) - page.fill_in 'user_email', with: user.email - page.fill_in 'user_password', with: 'wrong' - page.click_button I18n.t('devise.sign_in') - page.should have_css('div.alert.alert-danger') - find('div.alert.alert-danger').text.should include(I18n.t('devise.failure.invalid')) + page.fill_in "user_email", with: user.email + page.fill_in "user_password", with: "wrong" + page.click_button I18n.t("devise.sign_in") + page.should have_css("div.alert.alert-danger") + find("div.alert.alert-danger").text.should include(I18n.t("devise.failure.invalid")) end - scenario 'sign in non existing email' do + scenario "sign in non existing email" do page.visit(new_user_session_path) - page.fill_in 'user_email', with: 'not-existing@email.com' - page.fill_in 'user_password', with: 'wrong' - page.click_button I18n.t('devise.sign_in') - page.should have_css('div.alert.alert-danger') - find('div.alert.alert-danger').text.should \ - include(I18n.t('devise.failure.user.not_found_in_database')) + page.fill_in "user_email", with: "not-existing@email.com" + page.fill_in "user_password", with: "wrong" + page.click_button I18n.t("devise.sign_in") + page.should have_css("div.alert.alert-danger") + find("div.alert.alert-danger").text.should \ + include(I18n.t("devise.failure.user.not_found_in_database")) end - scenario 'redirected back to the right page' do + scenario "redirected back to the right page" do page.visit(new_rent_path) - find('div.alert.alert-danger').text.should include(I18n.t('unauthorized.new.rent')) - page.fill_in 'user_email', with: user.email - page.fill_in 'user_password', with: '12345678' - page.click_button I18n.t('devise.sign_in') - page.should have_css('div.alert.alert-info') - find('div.alert.alert-info').text.should include(I18n.t('devise.sessions.signed_in')) + find("div.alert.alert-danger").text.should include(I18n.t("unauthorized.new.rent")) + page.fill_in "user_email", with: user.email + page.fill_in "user_password", with: "12345678" + page.click_button I18n.t("devise.sign_in") + page.should have_css("div.alert.alert-info") + find("div.alert.alert-info").text.should include(I18n.t("devise.sessions.signed_in")) page.current_path.should eq(new_rent_path) end end diff --git a/spec/features/user/reset_password_spec.rb b/spec/features/user/reset_password_spec.rb index 49c506502..6be1ca90b 100644 --- a/spec/features/user/reset_password_spec.rb +++ b/spec/features/user/reset_password_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' -RSpec.feature 'Confirm account' do +require "rails_helper" +RSpec.feature "Confirm account" do let(:user) { create(:user, :unconfirmed) } - scenario 'confirm' do + scenario "confirm" do page.visit(user_confirmation_url(confirmation_token: user.confirmation_token)) page.status_code.should eq(200) - find('div.alert.alert-info').text.should include(I18n.t('devise.confirmations.confirmed')) + find("div.alert.alert-info").text.should include(I18n.t("devise.confirmations.confirmed")) user.reload.confirmed?.should be_truthy end end diff --git a/spec/features/user/sign_up_spec.rb b/spec/features/user/sign_up_spec.rb index 62290b9e8..217db7852 100644 --- a/spec/features/user/sign_up_spec.rb +++ b/spec/features/user/sign_up_spec.rb @@ -1,17 +1,17 @@ -require 'rails_helper' -RSpec.feature 'Sign up' do - scenario 'signs up' do +require "rails_helper" +RSpec.feature "Sign up" do + scenario "signs up" do user = build(:user) page.visit(new_user_registration_path) page.status_code.should eq(200) - fill_in 'user_firstname', with: user.firstname - fill_in 'user_lastname', with: user.lastname - fill_in 'user_email', with: user.email - fill_in 'user_password', with: '12345678' - fill_in 'user_password_confirmation', with: '12345678' - click_button('user-submit') + fill_in "user_firstname", with: user.firstname + fill_in "user_lastname", with: user.lastname + fill_in "user_email", with: user.email + fill_in "user_password", with: "12345678" + fill_in "user_password_confirmation", with: "12345678" + click_button("user-submit") - find('div.alert.alert-info').text.should include(I18n.t('devise.registrations.signed_up_but_unconfirmed')) + find("div.alert.alert-info").text.should include(I18n.t("devise.registrations.signed_up_but_unconfirmed")) end end diff --git a/spec/features/visit_spec.rb b/spec/features/visit_spec.rb index 656436d4e..d2ae43515 100644 --- a/spec/features/visit_spec.rb +++ b/spec/features/visit_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' +require "rails_helper" -RSpec.feature 'visits paths' do +RSpec.feature "visits paths" do let(:user) { create(:user) } paths = { @@ -37,7 +37,7 @@ value.each do |v| scenario %(controller: #{key}, action: #{v}) do if v == :show || v == :edit - resource = create(key.to_s.split('/').last.singularize.to_sym) + resource = create(key.to_s.split("/").last.singularize.to_sym) page.visit url_for(controller: key, action: v, id: resource.to_param) else diff --git a/spec/features/visitor_visit_spec.rb b/spec/features/visitor_visit_spec.rb index 86b103542..1d779d022 100644 --- a/spec/features/visitor_visit_spec.rb +++ b/spec/features/visitor_visit_spec.rb @@ -1,5 +1,5 @@ -require 'rails_helper' -RSpec.feature 'visitor visits paths' do +require "rails_helper" +RSpec.feature "visitor visits paths" do paths = { cafe: [:index], contacts: [:index, :show], @@ -24,7 +24,7 @@ value.each do |v| scenario %(controller: #{key}, action: #{v}) do if v == :show || v == :edit - resource = create(key.to_s.split('/').last.singularize.to_sym) + resource = create(key.to_s.split("/").last.singularize.to_sym) page.visit url_for(controller: key, action: v, id: resource.to_param) else diff --git a/spec/helpers/contact_helper_spec.rb b/spec/helpers/contact_helper_spec.rb index 343f87d0c..c078e1fde 100644 --- a/spec/helpers/contact_helper_spec.rb +++ b/spec/helpers/contact_helper_spec.rb @@ -1,31 +1,31 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ContactHelper do - describe 'contact_link' do - it 'creates link with favicon' do - contact = build_stubbed(:contact, email: 'spindelman@fsektionen.se', + describe "contact_link" do + it "creates link with favicon" do + contact = build_stubbed(:contact, email: "spindelman@fsektionen.se", id: 10) result = helper.contact_link(contact) - result.should include('kontakter/10') + result.should include("kontakter/10") end - it 'returns nil if no contact' do + it "returns nil if no contact" do result = helper.contact_link(nil) result.should be_nil end end - describe 'contact_from_slug' do - it 'finds contact with slug' do - create(:contact, id: 10, email: 'spindelman@fsektionen.se', - slug: 'spindelman_contact') + describe "contact_from_slug" do + it "finds contact with slug" do + create(:contact, id: 10, email: "spindelman@fsektionen.se", + slug: "spindelman_contact") - result = helper.contact_from_slug(slug: 'spindelman_contact') + result = helper.contact_from_slug(slug: "spindelman_contact") - result.should include('kontakter/10') + result.should include("kontakter/10") end end end diff --git a/spec/helpers/election_mailer_helper_spec.rb b/spec/helpers/election_mailer_helper_spec.rb index 9c7c1a051..a6e7380b2 100644 --- a/spec/helpers/election_mailer_helper_spec.rb +++ b/spec/helpers/election_mailer_helper_spec.rb @@ -1,30 +1,30 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ElectionMailerHelper do - describe 'candidate_mail_link' do - it 'not a board post' do - election = build_stubbed(:election, board_mail_link: 'http://board.com', - mail_link: 'http://normal.com') + describe "candidate_mail_link" do + it "not a board post" do + election = build_stubbed(:election, board_mail_link: "http://board.com", + mail_link: "http://normal.com") postt = build_stubbed(:post, board: false) candidate = build_stubbed(:candidate, election: election, post: postt) result = helper.candidate_mail_link(candidate) - result.should eq('http://normal.com') + result.should eq("http://normal.com") end - it 'a board post' do - election = build_stubbed(:election, board_mail_link: 'http://board.com', - mail_link: 'http://normal.com') + it "a board post" do + election = build_stubbed(:election, board_mail_link: "http://board.com", + mail_link: "http://normal.com") postt = build_stubbed(:post, board: true) candidate = build_stubbed(:candidate, election: election, post: postt) result = helper.candidate_mail_link(candidate) - result.should eq('http://board.com') + result.should eq("http://board.com") end - it 'returns nil if no candidate' do + it "returns nil if no candidate" do result = helper.candidate_mail_link(nil) result.should be_nil diff --git a/spec/helpers/event_helper_spec.rb b/spec/helpers/event_helper_spec.rb index e1595423b..1ae6ab784 100644 --- a/spec/helpers/event_helper_spec.rb +++ b/spec/helpers/event_helper_spec.rb @@ -1,24 +1,24 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe EventHelper do - describe 'event_reg_logged_in_or_member' do - it 'says sign in' do + describe "event_reg_logged_in_or_member" do + it "says sign in" do event = create(:event, :with_signup) response = helper.event_reg_logged_in_or_member(event, nil) - response.should include(I18n.t('helper.event.need_to_sign_in')) + response.should include(I18n.t("helper.event.need_to_sign_in")) end - it 'says confirm membership' do + it "says confirm membership" do event = create(:event) create(:event_signup, event: event, for_members: true) user = User.new(member_at: nil) response = helper.event_reg_logged_in_or_member(event, user) - response.should include(I18n.t('helper.event.membership_required')) + response.should include(I18n.t("helper.event.membership_required")) end - it 'returns nil if signup false' do + it "returns nil if signup false" do event = create(:event) user = User.new @@ -26,7 +26,7 @@ response.should be_nil end - it 'returns nil if user not member but not needing member' do + it "returns nil if user not member but not needing member" do event = create(:event) create(:event_signup, event: event, for_members: false) user = User.new @@ -35,7 +35,7 @@ response.should be_nil end - it 'returns nil if user is member' do + it "returns nil if user is member" do event = create(:event) create(:event_signup, event: event, for_members: false) user = User.new(member_at: 5.hours.ago) @@ -45,20 +45,20 @@ end end - describe 'event_user_type methods' do - it 'event_user_type returns correct values' do - signup = EventSignup.new(custom_name: 'Gammal och dryg') - helper.event_user_type(signup, EventSignup::CUSTOM).should eq('Gammal och dryg') - helper.event_user_type(signup, EventSignup::MEMBER).should eq(I18n.t('model.event_signup.user_types.member')) - helper.event_user_type(signup, nil).should eq(I18n.t('model.event_signup.user_types.other')) + describe "event_user_type methods" do + it "event_user_type returns correct values" do + signup = EventSignup.new(custom_name: "Gammal och dryg") + helper.event_user_type(signup, EventSignup::CUSTOM).should eq("Gammal och dryg") + helper.event_user_type(signup, EventSignup::MEMBER).should eq(I18n.t("model.event_signup.user_types.member")) + helper.event_user_type(signup, nil).should eq(I18n.t("model.event_signup.user_types.other")) end - it 'maps event user_types' do - signup = EventSignup.new(custom_name: 'Gammal och dryg') + it "maps event user_types" do + signup = EventSignup.new(custom_name: "Gammal och dryg") order = [EventSignup::CUSTOM, EventSignup::NOVICE, EventSignup::MENTOR] - expected = [['Gammal och dryg', EventSignup::CUSTOM], - [I18n.t('model.event_signup.user_types.novice'), EventSignup::NOVICE], - [I18n.t('model.event_signup.user_types.mentor'), EventSignup::MENTOR]] + expected = [["Gammal och dryg", EventSignup::CUSTOM], + [I18n.t("model.event_signup.user_types.novice"), EventSignup::NOVICE], + [I18n.t("model.event_signup.user_types.mentor"), EventSignup::MENTOR]] helper.map_event_user_types(signup, order).should eq(expected) end diff --git a/spec/helpers/markdown_helper_spec.rb b/spec/helpers/markdown_helper_spec.rb index d2d0b272d..155d93050 100644 --- a/spec/helpers/markdown_helper_spec.rb +++ b/spec/helpers/markdown_helper_spec.rb @@ -1,25 +1,25 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe MarkdownHelper do - describe 'markdown' do - it 'changing markdown to html' do - input = '**Strong text** *Italics*' + describe "markdown" do + it "changing markdown to html" do + input = "**Strong text** *Italics*" result = helper.markdown(input) - result.should include('') - result.should include('') + result.should include("") + result.should include("") end - it 'does not allow XSS' do + it "does not allow XSS" do xss = "" result = helper.markdown(xss) - result.should_not include('') + result.should_not include("") end - it 'appends data-turbolinks false to links' do - input = '[Document](http://localhost:3000/dokument)' + it "appends data-turbolinks false to links" do + input = "[Document](http://localhost:3000/dokument)" result = helper.markdown(input) expected = 'Document' @@ -27,21 +27,21 @@ end end - describe 'plain' do - it 'does not allow XSS' do + describe "plain" do + it "does not allow XSS" do xss = "" result = helper.markdown_plain(xss) - result.should_not include('') + result.should_not include("") end - it 'remove html-tags' do - input = '**Strong text** *Italics*' + it "remove html-tags" do + input = "**Strong text** *Italics*" result = helper.markdown_plain(input) - result.should_not include('') - result.should_not include('') + result.should_not include("") + result.should_not include("") end end end diff --git a/spec/helpers/posts_helper_spec.rb b/spec/helpers/posts_helper_spec.rb index 7d3d08090..6418f35f2 100644 --- a/spec/helpers/posts_helper_spec.rb +++ b/spec/helpers/posts_helper_spec.rb @@ -1,29 +1,29 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PostHelper do - describe 'print_post_limit' do - it 'star' do + describe "print_post_limit" do + it "star" do position = build_stubbed(:post, rec_limit: 0, limit: 0) - helper.print_post_limit(position).should eq('*') + helper.print_post_limit(position).should eq("*") position.rec_limit = 5 position.limit = 1 - helper.print_post_limit(position).should eq('*') + helper.print_post_limit(position).should eq("*") end - it '(x)' do + it "(x)" do position = build_stubbed(:post, rec_limit: 2, limit: 2) - helper.print_post_limit(position).should eq('2 (x)') + helper.print_post_limit(position).should eq("2 (x)") end - it 'recommended' do + it "recommended" do position = build_stubbed(:post, rec_limit: 0, limit: 5) helper.print_post_limit(position).should eq(5) end - it 'interval' do + it "interval" do position = build_stubbed(:post, rec_limit: 3, limit: 5) - helper.print_post_limit(position).should eq('3 - 5') + helper.print_post_limit(position).should eq("3 - 5") end end end diff --git a/spec/helpers/time_helper_spec.rb b/spec/helpers/time_helper_spec.rb index 040bfe32e..ab0f6be15 100644 --- a/spec/helpers/time_helper_spec.rb +++ b/spec/helpers/time_helper_spec.rb @@ -1,150 +1,150 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe TimeHelper do - describe 'date_range' do - context 'same day' do + describe "date_range" do + context "same day" do from_date = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_date = from_date + 8.hours - it 'print only one date' do + it "print only one date" do helper.date_range(from_date, until_date).should \ - eq(%(#{I18n.l(from_date.to_date)})) + eq(I18n.l(from_date.to_date).to_s) end - it 'print only one date, short' do + it "print only one date, short" do helper.date_range(from_date, until_date, format: :short).should \ - eq(%(#{I18n.l(from_date.to_date, format: :short)})) + eq(I18n.l(from_date.to_date, format: :short).to_s) end end - context 'same month' do + context "same month" do from_date = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_date = from_date + 4.days + 8.hours - it 'day span with month and year' do + it "day span with month and year" do helper.date_range(from_date, until_date).should \ eq(%(#{I18n.l(from_date.to_date, format: :day)} - #{I18n.l(until_date.to_date)})) end - it 'day span with month and year, short' do + it "day span with month and year, short" do helper.date_range(from_date, until_date, format: :short).should \ eq(%(#{I18n.l(from_date.to_date, format: :day)} - #{I18n.l(until_date.to_date, format: :short)})) end end - context 'same year' do + context "same year" do from_date = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_date = from_date + 14.days + 8.hours - it 'print with same year' do + it "print with same year" do helper.date_range(from_date, until_date).should \ eq(%(#{I18n.l(from_date.to_date, format: :day_month)} - #{I18n.l(until_date.to_date)})) end - it 'print with same year, short' do + it "print with same year, short" do helper.date_range(from_date, until_date, format: :short).should \ eq(%(#{I18n.l(from_date.to_date, format: :day_month)} - #{I18n.l(until_date.to_date, format: :short)})) end end - context 'missing variable' do + context "missing variable" do from_date = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_date = from_date + 8.hours - it 'print first date' do + it "print first date" do helper.date_range(from_date, nil).should \ eq(I18n.l(from_date.to_date)) end - it 'print second date' do + it "print second date" do helper.date_range(from_date, nil).should \ eq(I18n.l(until_date.to_date)) end - it 'print first date, short' do + it "print first date, short" do helper.date_range(from_date, nil, format: :short).should \ eq(I18n.l(from_date.to_date, format: :short)) end - it 'print second date, short' do + it "print second date, short" do helper.date_range(nil, until_date, format: :short).should \ eq(I18n.l(until_date.to_date, format: :short)) end end end - describe 'time range' do - context 'same day' do + describe "time range" do + context "same day" do from_time = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_time = from_time + 8.hours - it 'print both times followed by one date' do + it "print both times followed by one date" do helper.time_range(from_time, until_time).should \ eq(%(#{I18n.l(from_time, format: :time)} - #{I18n.l(until_time)})) end - it 'print both times followed by one date, short' do + it "print both times followed by one date, short" do helper.time_range(from_time, until_time, format: :short).should \ eq(%(#{I18n.l(from_time, format: :time)} - #{I18n.l(until_time, format: :short)})) end end - context 'not same day' do + context "not same day" do from_time = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_time = from_time + 4.days + 8.hours - it 'time range' do + it "time range" do helper.time_range(from_time, until_time).should \ eq(%(#{I18n.l(from_time)} - #{I18n.l(until_time)})) end - it 'time range, short' do + it "time range, short" do helper.time_range(from_time, until_time, format: :short).should \ eq(%(#{I18n.l(from_time, format: :short)} - #{I18n.l(until_time, format: :short)})) end end - context 'missing variable' do + context "missing variable" do from_time = Time.zone.local(Time.zone.now.year, 3, 25, 12) until_time = from_time + 8.hours - it 'print first date' do + it "print first date" do helper.time_range(from_time, nil).should \ eq(I18n.l(from_time)) end - it 'print second date' do + it "print second date" do helper.time_range(from_time, nil).should \ eq(I18n.l(from_time)) end - it 'print first date, short' do + it "print first date, short" do helper.time_range(from_time, nil, format: :short).should \ eq(I18n.l(from_time, format: :short)) end - it 'print second time, short' do + it "print second time, short" do helper.time_range(nil, until_time, format: :short).should \ eq(I18n.l(until_time, format: :short)) end end end - describe 'dots' do - it 'does not append if no dot given' do + describe "dots" do + it "does not append if no dot given" do format = :long helper.dot_format(format).should eq(:long) end - it 'appends dot' do + it "appends dot" do format = :long helper.dot_format(format, dot: :single).should eq(:long_dot) - helper.dot_format(format, dot: 'single').should eq(:long_dot) + helper.dot_format(format, dot: "single").should eq(:long_dot) end - it 'appends ddot' do + it "appends ddot" do format = :long helper.dot_format(format, dot: :double).should eq(:long_ddot) - helper.dot_format(format, dot: 'double').should eq(:long_ddot) + helper.dot_format(format, dot: "double").should eq(:long_ddot) end - it 'appends without' do + it "appends without" do format = :long helper.dot_format(format, dot: :without).should eq(:long_without) - helper.dot_format(format, dot: 'without').should eq(:long_without) + helper.dot_format(format, dot: "without").should eq(:long_without) end end end diff --git a/spec/lib/tasks/promote_admin_spec.rb b/spec/lib/tasks/promote_admin_spec.rb index a0bd72320..945542b5c 100644 --- a/spec/lib/tasks/promote_admin_spec.rb +++ b/spec/lib/tasks/promote_admin_spec.rb @@ -1,9 +1,9 @@ -require 'rails_helper' +require "rails_helper" -RSpec.describe 'promote_admin' do - include_context 'rake' +RSpec.describe "promote_admin" do + include_context "rake" - it 'promotes the first user to admin' do + it "promotes the first user to admin" do user = create(:user) subject.invoke AdminAbility.new(user).can?(:manage, :all).should eq(true) diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index f3d006235..4e5cc17b1 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -1,16 +1,16 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ApplicationMailer, type: :mailer do mailer = Class.new(ApplicationMailer) do def an_email - mail(body: '') + mail(body: "") end end - describe 'Message-ID' do - it 'sets header' do + describe "Message-ID" do + it "sets header" do mail = mailer.an_email - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end end end diff --git a/spec/mailers/contact_mailer_spec.rb b/spec/mailers/contact_mailer_spec.rb index 457ca3872..3302fc1d6 100644 --- a/spec/mailers/contact_mailer_spec.rb +++ b/spec/mailers/contact_mailer_spec.rb @@ -1,45 +1,45 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ContactMailer, type: :mailer do - describe 'mail' do - it 'has appropriate subject' do + describe "mail" do + it "has appropriate subject" do message = build(:contact_message, - name: 'Hilbert Älg', - email: 'utomifran@gmail.com') + name: "Hilbert Älg", + email: "utomifran@gmail.com") contact = create(:contact, message: message) mail = ContactMailer.contact_email(contact) - mail.subject.should eq(I18n.t('contact_mailer.subject', sender: 'Hilbert Älg')) + mail.subject.should eq(I18n.t("contact_mailer.subject", sender: "Hilbert Älg")) end - it 'sends to the given contact' do - contact = create(:contact, :with_message, email: 'david@fsektionen.se') + it "sends to the given contact" do + contact = create(:contact, :with_message, email: "david@fsektionen.se") mail = ContactMailer.contact_email(contact) - mail.to.should eq(['david@fsektionen.se']) + mail.to.should eq(["david@fsektionen.se"]) end - it 'sends from dirac' do + it "sends from dirac" do contact = create(:contact, :with_message) mail = ContactMailer.contact_email(contact) - mail.from.should eq(['dirac@fsektionen.se']) + mail.from.should eq(["dirac@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do contact = create(:contact, :with_message) mail = ContactMailer.contact_email(contact) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - context 'HTML body' do - it 'includes the text' do - message = build(:contact_message, message: 'What a wonderful day') + context "HTML body" do + it "includes the text" do + message = build(:contact_message, message: "What a wonderful day") contact = create(:contact, message: message) mail = ContactMailer.contact_email(contact) - mail.body.should include('What a wonderful day') + mail.body.should include("What a wonderful day") end end end diff --git a/spec/mailers/election_mailer_spec.rb b/spec/mailers/election_mailer_spec.rb index 2c07cf918..9e13dd58c 100644 --- a/spec/mailers/election_mailer_spec.rb +++ b/spec/mailers/election_mailer_spec.rb @@ -1,102 +1,102 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ElectionMailer, type: :mailer do - describe 'nomination' do - it 'has appropriate subject' do + describe "nomination" do + it "has appropriate subject" do nomination = create(:nomination) mail = ElectionMailer.nominate_email(nomination.id) - mail.subject.should eq(I18n.t('election_mailer.nominate_email.subject_nominated')) + mail.subject.should eq(I18n.t("election_mailer.nominate_email.subject_nominated")) end - it 'sends from dirac' do + it "sends from dirac" do nomination = create(:nomination) mail = ElectionMailer.nominate_email(nomination.id) - mail.from.should eq(['valb@fsektionen.se']) + mail.from.should eq(["valb@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do nomination = create(:nomination) mail = ElectionMailer.nominate_email(nomination.id) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'includes the text' do + it "includes the text" do nomination = create(:nomination, - motivation: 'What a wonderful day') + motivation: "What a wonderful day") mail = ElectionMailer.nominate_email(nomination.id) - mail.body.should include('What a wonderful day') + mail.body.should include("What a wonderful day") end end - describe 'candidate' do - it 'has appropriate subject' do + describe "candidate" do + it "has appropriate subject" do candidate = create(:candidate) mail = ElectionMailer.candidate_email(candidate.id) - mail.subject.should eq(I18n.t('election_mailer.candidate_email.subject_candidated')) + mail.subject.should eq(I18n.t("election_mailer.candidate_email.subject_candidated")) end - it 'sends from dirac' do + it "sends from dirac" do candidate = create(:candidate) mail = ElectionMailer.candidate_email(candidate.id) - mail.from.should eq(['valb@fsektionen.se']) + mail.from.should eq(["valb@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do candidate = create(:candidate) mail = ElectionMailer.candidate_email(candidate.id) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'board post' do + it "board post" do election = create(:election, :before_general, :autumn, - candidate_mail: 'This is the general and board email', - candidate_mail_star: 'This is the not general email', - nominate_mail: 'This is the nomination email') + candidate_mail: "This is the general and board email", + candidate_mail_star: "This is the not general email", + nominate_mail: "This is the nomination email") postt = create(:post, :autumn, :general, board: true) candidate = create(:candidate, post: postt, election: election) mail = ElectionMailer.candidate_email(candidate.id) - mail.body.should include('This is the general and board email') + mail.body.should include("This is the general and board email") end - it 'post elected at general meeting' do + it "post elected at general meeting" do election = create(:election, :before_general, :autumn, - candidate_mail: 'This is the general and board email', - candidate_mail_star: 'This is the not general email', - nominate_mail: 'This is the nomination email') + candidate_mail: "This is the general and board email", + candidate_mail_star: "This is the not general email", + nominate_mail: "This is the nomination email") postt = create(:post, :autumn, :general, board: false) candidate = create(:candidate, post: postt, election: election) mail = ElectionMailer.candidate_email(candidate.id) - mail.body.should include('This is the general and board email') + mail.body.should include("This is the general and board email") end - it 'posts not elected at general meeting' do + it "posts not elected at general meeting" do election = create(:election, :before_general, :autumn, - candidate_mail: 'This is the general and board email', - candidate_mail_star: 'This is the not general email', - nominate_mail: 'This is the nomination email') + candidate_mail: "This is the general and board email", + candidate_mail_star: "This is the not general email", + nominate_mail: "This is the nomination email") postt = create(:post, :autumn, :board, board: false) candidate = create(:candidate, post: postt, election: election) mail = ElectionMailer.candidate_email(candidate.id) - mail.body.should include('This is the not general email') + mail.body.should include("This is the not general email") end end end diff --git a/spec/mailers/meeting_mailer_spec.rb b/spec/mailers/meeting_mailer_spec.rb index b85e22b9a..1f6f81b2d 100644 --- a/spec/mailers/meeting_mailer_spec.rb +++ b/spec/mailers/meeting_mailer_spec.rb @@ -1,9 +1,9 @@ -require 'rails_helper' +require "rails_helper" include MeetingHelper, TimeHelper RSpec.describe MeetingMailer, type: :mailer do - describe 'booking email' do - it 'has appropriate subject' do + describe "booking email" do + it "has appropriate subject" do meeting = build_stubbed(:meeting) mail = MeetingMailer.book_email(meeting) @@ -13,32 +13,32 @@ mail.subject.should include(Meeting.human_attribute_name(meeting.status)) end - it 'sends from @fsektionen' do + it "sends from @fsektionen" do meeting = build_stubbed(:meeting) mail = MeetingMailer.book_email(meeting) - mail.from.should eq(['lokalbokning@fsektionen.se']) + mail.from.should eq(["lokalbokning@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do meeting = build_stubbed(:meeting) mail = MeetingMailer.book_email(meeting) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'includes the text' do - meeting = build_stubbed(:meeting, title: 'Spiderman meeting') + it "includes the text" do + meeting = build_stubbed(:meeting, title: "Spiderman meeting") mail = MeetingMailer.book_email(meeting) - mail.body.should include('Spiderman meeting') + mail.body.should include("Spiderman meeting") end end - describe 'update_email' do - it 'has appropriate subject' do + describe "update_email" do + it "has appropriate subject" do meeting = build_stubbed(:meeting, status: :confirmed, is_admin: true) mail = MeetingMailer.update_email(meeting, meeting.user) @@ -48,27 +48,27 @@ mail.subject.should include(Meeting.human_attribute_name(meeting.status)) end - it 'sends from @fsektionen' do + it "sends from @fsektionen" do meeting = build_stubbed(:meeting) mail = MeetingMailer.update_email(meeting, meeting.user) - mail.from.should eq(['lokalbokning@fsektionen.se']) + mail.from.should eq(["lokalbokning@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do meeting = build_stubbed(:meeting) mail = MeetingMailer.update_email(meeting, meeting.user) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'includes the text' do - meeting = build_stubbed(:meeting, title: 'Spiderman meeting') + it "includes the text" do + meeting = build_stubbed(:meeting, title: "Spiderman meeting") mail = MeetingMailer.update_email(meeting, meeting.user) - mail.body.should include('Spiderman meeting') + mail.body.should include("Spiderman meeting") end end end diff --git a/spec/mailers/rent_mailer_spec.rb b/spec/mailers/rent_mailer_spec.rb index ca136bb38..f5113f492 100644 --- a/spec/mailers/rent_mailer_spec.rb +++ b/spec/mailers/rent_mailer_spec.rb @@ -1,120 +1,120 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe RentMailer, type: :mailer do - describe 'rent_email' do - it 'has appropriate subject' do + describe "rent_email" do + it "has appropriate subject" do rent = build_stubbed(:rent) mail = RentMailer.rent_email(rent) - mail.subject.should eq(I18n.t('rent_mailer.mailer.subject', - date: rent.p_time, - status: I18n.t("model.rent.#{rent.status}"))) + mail.subject.should eq(I18n.t("rent_mailer.mailer.subject", + date: rent.p_time, + status: I18n.t("model.rent.#{rent.status}"))) end - it 'sends from @fsektionen' do + it "sends from @fsektionen" do rent = build_stubbed(:rent) mail = RentMailer.rent_email(rent) - mail.from.should eq(['bil@fsektionen.se']) + mail.from.should eq(["bil@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do rent = build_stubbed(:rent) mail = RentMailer.rent_email(rent) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'includes the text' do - rent = build_stubbed(:rent, purpose: 'Driving home for Christmas') + it "includes the text" do + rent = build_stubbed(:rent, purpose: "Driving home for Christmas") mail = RentMailer.rent_email(rent) - mail.body.should include('Driving home for Christmas') + mail.body.should include("Driving home for Christmas") end end - describe 'status_email' do - it 'has appropriate subject' do + describe "status_email" do + it "has appropriate subject" do rent = build_stubbed(:rent) mail = RentMailer.status_email(rent) - mail.subject.should eq(I18n.t('rent_mailer.mailer.subject', - date: rent.p_time, - status: I18n.t("model.rent.#{rent.status}"))) + mail.subject.should eq(I18n.t("rent_mailer.mailer.subject", + date: rent.p_time, + status: I18n.t("model.rent.#{rent.status}"))) end - it 'sends from @fsektionen' do + it "sends from @fsektionen" do rent = build_stubbed(:rent) mail = RentMailer.status_email(rent) - mail.from.should eq(['bil@fsektionen.se']) + mail.from.should eq(["bil@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do rent = build_stubbed(:rent) mail = RentMailer.status_email(rent) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'includes the text' do - rent = build_stubbed(:rent, purpose: 'Driving home for Christmas') + it "includes the text" do + rent = build_stubbed(:rent, purpose: "Driving home for Christmas") mail = RentMailer.status_email(rent) - mail.body.should include('Driving home for Christmas') + mail.body.should include("Driving home for Christmas") end end - describe 'active_email' do - context 'subject line' do - it 'has right subject when active' do + describe "active_email" do + context "subject line" do + it "has right subject when active" do rent = build_stubbed(:rent, aktiv: true) mail = RentMailer.active_email(rent) - mail.subject.should eq(I18n.t('rent_mailer.mailer.subject', - date: rent.p_time, - status: I18n.t('rent_mailer.active_email.marked_active'))) + mail.subject.should eq(I18n.t("rent_mailer.mailer.subject", + date: rent.p_time, + status: I18n.t("rent_mailer.active_email.marked_active"))) end - it 'has right subject when inactive' do + it "has right subject when inactive" do rent = build_stubbed(:rent, aktiv: false) mail = RentMailer.active_email(rent) - mail.subject.should eq(I18n.t('rent_mailer.mailer.subject', - date: rent.p_time, - status: I18n.t('rent_mailer.active_email.marked_inactive'))) + mail.subject.should eq(I18n.t("rent_mailer.mailer.subject", + date: rent.p_time, + status: I18n.t("rent_mailer.active_email.marked_inactive"))) end end - it 'sends from @fsektionen' do + it "sends from @fsektionen" do rent = build_stubbed(:rent) mail = RentMailer.active_email(rent) - mail.from.should eq(['bil@fsektionen.se']) + mail.from.should eq(["bil@fsektionen.se"]) end - it 'Message-ID has right domain' do + it "Message-ID has right domain" do rent = build_stubbed(:rent) mail = RentMailer.active_email(rent) - mail.message_id.should include('@fsektionen.se') + mail.message_id.should include("@fsektionen.se") end - it 'includes the text' do - rent = build_stubbed(:rent, purpose: 'Driving home for Christmas') + it "includes the text" do + rent = build_stubbed(:rent, purpose: "Driving home for Christmas") mail = RentMailer.active_email(rent) - mail.body.should include('Driving home for Christmas') + mail.body.should include("Driving home for Christmas") end end end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index ac09e3aee..08981555c 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -1,78 +1,78 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Ability do standard = :read, :create, :update, :destroy ab_visitor = { - Album.new => { yes: [], no: standard }, - CafeShift.new => { yes: [], no: [:index, :feed, :show] }, - Candidate.new => { yes: [], no: standard }, - Constant.new => { yes: [], no: standard }, - Contact.new => { yes: [], no: [:mail, :create, :update, :destroy, :read] }, - Contact.new(public: true) => { yes: [:read, :mail], no: [:create, :update] }, - Council.new => { yes: [:read], no: [:create, :update, :destroy] }, - Document.new(public: true) => { yes: [:read], no: [:create, :update, :destroy] }, - Document.new => { yes: [], no: standard }, - Election.new => { yes: [:index], no: [:create, :update, :destroy] }, - Event.new => { yes: [], no: [:create, :update, :destroy, :read] }, - Faq.new => { yes: [:read, :new, :create], no: [:update, :destroy] }, - Menu.new => { yes: [], no: standard }, - News.new => { yes: [:read], no: [:create, :update, :destroy] }, - Nomination.new => { yes: [], no: [:create] }, - PageElement.new => { yes: [], no: standard }, - Page.new(visible: true) => { yes: [:show], no: [:index, :new, :create, :update, :destroy] }, - Permission.new => { yes: [], no: standard }, - Post.new => { yes: [:show, :modal], no: [:standard] }, - Rent.new => { yes: [], no: [:index, :create, :update, :destroy] }, - WorkPost.new => { no: [:create, :update, :destroy], yes: [:index, :show] }, - static_pages: { yes: [:index, - :cookies_information, - :company_about, - :company_offer, - :about, :robots], - no: [] } + Album.new => {yes: [], no: standard}, + CafeShift.new => {yes: [], no: [:index, :feed, :show]}, + Candidate.new => {yes: [], no: standard}, + Constant.new => {yes: [], no: standard}, + Contact.new => {yes: [], no: [:mail, :create, :update, :destroy, :read]}, + Contact.new(public: true) => {yes: [:read, :mail], no: [:create, :update]}, + Council.new => {yes: [:read], no: [:create, :update, :destroy]}, + Document.new(public: true) => {yes: [:read], no: [:create, :update, :destroy]}, + Document.new => {yes: [], no: standard}, + Election.new => {yes: [:index], no: [:create, :update, :destroy]}, + Event.new => {yes: [], no: [:create, :update, :destroy, :read]}, + Faq.new => {yes: [:read, :new, :create], no: [:update, :destroy]}, + Menu.new => {yes: [], no: standard}, + News.new => {yes: [:read], no: [:create, :update, :destroy]}, + Nomination.new => {yes: [], no: [:create]}, + PageElement.new => {yes: [], no: standard}, + Page.new(visible: true) => {yes: [:show], no: [:index, :new, :create, :update, :destroy]}, + Permission.new => {yes: [], no: standard}, + Post.new => {yes: [:show, :modal], no: [:standard]}, + Rent.new => {yes: [], no: [:index, :create, :update, :destroy]}, + WorkPost.new => {no: [:create, :update, :destroy], yes: [:index, :show]}, + :static_pages => {yes: [:index, + :cookies_information, + :company_about, + :company_offer, + :about, :robots], + no: []} } ab_signed = { - Album.new => { yes: [], no: standard }, - CafeShift.new => { yes: [:index, :feed, :show], no: [] }, - :calendar => { yes: [:index, :export], no: [] }, - Candidate.new => { yes: [], no: standard }, - Constant.new => { yes: [], no: standard }, - Contact.new => { yes: [:read, :mail], no: [:create, :update, :destroy] }, - Council.new => { yes: [:read], no: [:create, :update, :destroy] }, - Document.new(public: true) => { yes: [:read], no: [:create, :update, :destroy] }, - Election.new => { yes: [:index], no: [:create, :update, :destroy] }, - Event.new => { yes: [:read], no: [:create, :update, :destroy] }, - Faq.new => { yes: [:read, :create], no: [:update, :destroy] }, - Menu.new => { yes: [], no: standard }, - News.new => { yes: [:read], no: [:create, :update, :destroy] }, - Nomination.new => { yes: [], no: [:create] }, - PageElement.new => { yes: [], no: standard }, - Page.new(visible: true) => { yes: [:show], no: [:new, :index, :create, :update, :destroy] }, - Permission.new => { yes: [], no: standard }, - Post.new => { yes: [:show, :modal], no: [:standard] }, - Rent.new => { yes: [:index], no: [:overview, :create] } + Album.new => {yes: [], no: standard}, + CafeShift.new => {yes: [:index, :feed, :show], no: []}, + :calendar => {yes: [:index, :export], no: []}, + Candidate.new => {yes: [], no: standard}, + Constant.new => {yes: [], no: standard}, + Contact.new => {yes: [:read, :mail], no: [:create, :update, :destroy]}, + Council.new => {yes: [:read], no: [:create, :update, :destroy]}, + Document.new(public: true) => {yes: [:read], no: [:create, :update, :destroy]}, + Election.new => {yes: [:index], no: [:create, :update, :destroy]}, + Event.new => {yes: [:read], no: [:create, :update, :destroy]}, + Faq.new => {yes: [:read, :create], no: [:update, :destroy]}, + Menu.new => {yes: [], no: standard}, + News.new => {yes: [:read], no: [:create, :update, :destroy]}, + Nomination.new => {yes: [], no: [:create]}, + PageElement.new => {yes: [], no: standard}, + Page.new(visible: true) => {yes: [:show], no: [:new, :index, :create, :update, :destroy]}, + Permission.new => {yes: [], no: standard}, + Post.new => {yes: [:show, :modal], no: [:standard]}, + Rent.new => {yes: [:index], no: [:overview, :create]} } ab_member = { - Album.new => { yes: [], no: standard }, - CafeShift.new => { yes: [:index, :feed], no: [] }, - Candidate.new => { yes: [:index, :create], no: [] }, - Constant.new => { yes: [], no: standard }, - Contact.new => { yes: [:read, :mail], no: [:create, :update, :destroy] }, - Council.new => { yes: [:read], no: [:create, :update, :destroy] }, - Document.new => { yes: [:read], no: [:create, :update, :destroy] }, - Election.new => { yes: [:index], no: [:create, :update, :destroy] }, - Event.new => { yes: [:read], no: [:create, :update, :destroy] }, - Faq.new => { yes: [:read, :create], no: [:update, :destroy] }, - Menu.new => { yes: [], no: standard }, - News.new => { yes: [:read], no: [:create, :update, :destroy] }, - Nomination.new => { yes: [:create], no: [] }, - PageElement.new => { yes: [], no: standard }, - Page.new(visible: true) => { yes: [:show], no: [:index, :new, :create, :update, :destroy] }, - Permission.new => { yes: [], no: standard }, - Post.new => { yes: [:show, :modal], no: [:standard] }, - Rent.new => { yes: [:show, :overview, :create, :index], no: [:update, :destroy] }, + Album.new => {yes: [], no: standard}, + CafeShift.new => {yes: [:index, :feed], no: []}, + Candidate.new => {yes: [:index, :create], no: []}, + Constant.new => {yes: [], no: standard}, + Contact.new => {yes: [:read, :mail], no: [:create, :update, :destroy]}, + Council.new => {yes: [:read], no: [:create, :update, :destroy]}, + Document.new => {yes: [:read], no: [:create, :update, :destroy]}, + Election.new => {yes: [:index], no: [:create, :update, :destroy]}, + Event.new => {yes: [:read], no: [:create, :update, :destroy]}, + Faq.new => {yes: [:read, :create], no: [:update, :destroy]}, + Menu.new => {yes: [], no: standard}, + News.new => {yes: [:read], no: [:create, :update, :destroy]}, + Nomination.new => {yes: [:create], no: []}, + PageElement.new => {yes: [], no: standard}, + Page.new(visible: true) => {yes: [:show], no: [:index, :new, :create, :update, :destroy]}, + Permission.new => {yes: [], no: standard}, + Post.new => {yes: [:show, :modal], no: [:standard]}, + Rent.new => {yes: [:show, :overview, :create, :index], no: [:update, :destroy]} } subject(:visitor) { Ability.new(nil) } @@ -83,7 +83,7 @@ let(:member) { build_stubbed(:user, member_at: Time.zone.now) } subject(:member_ability) { Ability.new(member) } - describe 'Not signed in' do + describe "Not signed in" do ab_visitor.each do |obj, value| if value[:yes].present? it { visitor.should have_abilities(value[:yes], obj) } @@ -95,7 +95,7 @@ end end - describe 'Signed in' do + describe "Signed in" do ab_signed.each do |obj, value| if value[:yes].present? it { signed_ability.should have_abilities(value[:yes], obj) } @@ -110,11 +110,11 @@ # These also count for the members it do signed_ability.should have_abilities([:create, :update, :destroy], - CafeWorker.new(user: signed)) + CafeWorker.new(user: signed)) end end - describe 'Member' do + describe "Member" do ab_member.each do |obj, value| if value[:yes].present? it { member_ability.should have_abilities(value[:yes], obj) } @@ -129,7 +129,7 @@ it { member_ability.should have_abilities([:show, :update, :destroy], Rent.new(user: member)) } it do member_ability.should have_abilities([:destroy], - Candidate.new(user: member)) + Candidate.new(user: member)) end end end diff --git a/spec/models/access_spec.rb b/spec/models/access_spec.rb index ef6a7aa69..db6706b2c 100644 --- a/spec/models/access_spec.rb +++ b/spec/models/access_spec.rb @@ -1,14 +1,14 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Access, type: :model do - it 'has valid factory' do + it "has valid factory" do build_stubbed(:access).should be_valid end - describe 'validations' do + describe "validations" do it { Access.new.should validate_presence_of(:door) } it { Access.new.should validate_presence_of(:post) } - it 'checks uniqueness of door and post' do + it "checks uniqueness of door and post" do door = create(:door) post = create(:post) diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 1003628fd..caa035b6f 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Album, type: :model do subject { build_stubbed(:album) } - it 'has a valid factory' do + it "has a valid factory" do should be_valid end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do it { should have_many(:images) } end end diff --git a/spec/models/blog_post_spec.rb b/spec/models/blog_post_spec.rb index 51f51802a..5436ed782 100644 --- a/spec/models/blog_post_spec.rb +++ b/spec/models/blog_post_spec.rb @@ -1,14 +1,14 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe BlogPost, type: :model do - it 'has valid factory' do + it "has valid factory" do build_stubbed(:blog_post).should be_valid end - describe '#to_param' do - it 'formats title' do - blog_post = BlogPost.new(id: 37, title: 'Detta är en title') - blog_post.to_param.should eq('37-detta-ar-en-title') + describe "#to_param" do + it "formats title" do + blog_post = BlogPost.new(id: 37, title: "Detta är en title") + blog_post.to_param.should eq("37-detta-ar-en-title") end end end diff --git a/spec/models/cafe_shift_spec.rb b/spec/models/cafe_shift_spec.rb index b89594cbb..1ef609190 100644 --- a/spec/models/cafe_shift_spec.rb +++ b/spec/models/cafe_shift_spec.rb @@ -1,13 +1,13 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeShift, type: :model do let(:shift) { build_stubbed(:cafe_shift) } let(:with_worker) { build_stubbed(:cafe_shift, :with_worker) } - it 'has a valid factory' do + it "has a valid factory" do shift.should be_valid end - describe 'ActiveModel validations' do + describe "ActiveModel validations" do # Basic validations it { CafeShift.new.should validate_presence_of(:start) } it { CafeShift.new.should validate_presence_of(:pass) } @@ -18,7 +18,7 @@ it { CafeShift.new.should validate_inclusion_of(:lv).in_range(0..8) } end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do # Associations it { CafeShift.new.should have_one(:user) } it { CafeShift.new.should have_one(:cafe_worker) } @@ -28,22 +28,22 @@ # Fullcalendars json-feed # Ref.: https://github.com/fsek/web/issues/99 describe :json do - it 'check date format is iso8601' do + it "check date format is iso8601" do shift.as_json.to_json.should include(shift.start.iso8601.to_json) shift.as_json.to_json.should include(shift.stop.iso8601.to_json) end - it 'green color if checked by worker' do - with_worker.as_json(user: with_worker.user)[:backgroundColor].should eq('green') + it "green color if checked by worker" do + with_worker.as_json(user: with_worker.user)[:backgroundColor].should eq("green") end - it 'orange color if checked by other' do - with_worker.as_json[:backgroundColor].should eq('orange') + it "orange color if checked by other" do + with_worker.as_json[:backgroundColor].should eq("orange") end - it 'white color if no worker' do - shift.as_json[:backgroundColor].should eq('white') - shift.as_json(user: with_worker.user)[:backgroundColor].should eq('white') + it "white color if no worker" do + shift.as_json[:backgroundColor].should eq("white") + shift.as_json(user: with_worker.user)[:backgroundColor].should eq("white") end end end diff --git a/spec/models/cafe_worker_spec.rb b/spec/models/cafe_worker_spec.rb index 34cf7ebae..ae9463184 100644 --- a/spec/models/cafe_worker_spec.rb +++ b/spec/models/cafe_worker_spec.rb @@ -1,17 +1,17 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeWorker, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build_stubbed(:cafe_worker).should be_valid end - describe 'ActiveModel validations' do + describe "ActiveModel validations" do # Basic validations it { CafeWorker.new.should validate_presence_of(:user_id) } it { CafeWorker.new.should validate_presence_of(:cafe_shift_id) } end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do # Associations it { CafeWorker.new.should belong_to(:user) } it { CafeWorker.new.should belong_to(:cafe_shift) } diff --git a/spec/models/candidate_spec.rb b/spec/models/candidate_spec.rb index 58482c32f..a091f2f7f 100644 --- a/spec/models/candidate_spec.rb +++ b/spec/models/candidate_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Candidate, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build(:candidate).should be_valid end - describe 'validations' do - it 'validates uniqueness of post to user and eleciton' do + describe "validations" do + it "validates uniqueness of post to user and eleciton" do election = create(:election, :autumn) postt = create(:post, :autumn) user = create(:user) @@ -17,14 +17,14 @@ new_cand = build(:candidate, election: election, post: postt, user: user) new_cand.should be_invalid - new_cand.errors[:post].should include(I18n.t('model.candidate.similar_candidate')) + new_cand.errors[:post].should include(I18n.t("model.candidate.similar_candidate")) end it { Candidate.new.should validate_presence_of(:election) } it { Candidate.new.should validate_presence_of(:user) } it { Candidate.new.should validate_presence_of(:post) } - it 'invalid if wrong semester on post and election' do + it "invalid if wrong semester on post and election" do election = create(:election, :autumn) postt = create(:post, :spring) cand = build_stubbed(:candidate, post: postt, election: election) @@ -33,15 +33,15 @@ end end - describe 'associations' do + describe "associations" do # Associations it { Candidate.new.should belong_to(:election) } it { Candidate.new.should belong_to(:post) } it { Candidate.new.should belong_to(:user) } end - describe 'public methods' do - it 'is editable?' do + describe "public methods" do + it "is editable?" do # candidates elected by General meeting is only editable :before_general election = create(:election, :before_general, :autumn) @@ -51,7 +51,7 @@ candidate.editable?.should be_truthy end - it 'is not editable' do + it "is not editable" do # candidates elected by General meeting is only editable :before_general, # not :after_general election = create(:election, :after_general, :autumn) diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 7bba891eb..01f5b013b 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -1,34 +1,34 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Category, type: :model do - it 'has valid factory' do + it "has valid factory" do build(:category).should be_valid end - it 'to param' do - category = build_stubbed(:category, slug: 'categorieees_url') - category.to_param.should eq('categorieees_url') + it "to param" do + category = build_stubbed(:category, slug: "categorieees_url") + category.to_param.should eq("categorieees_url") end - it 'allows use_case' do + it "allows use_case" do category = build_stubbed(:category) category.should be_valid - category.use_case = 'invalid_use_case' + category.use_case = "invalid_use_case" category.should be_invalid - category.errors[:use_case].should include(I18n.t('model.category.not_allowed_use_case')) + category.errors[:use_case].should include(I18n.t("model.category.not_allowed_use_case")) category.use_case = Category::USE_CASES.last category.should be_valid - category.errors[:use_case].should_not include(I18n.t('model.category.not_allowed_use_case')) + category.errors[:use_case].should_not include(I18n.t("model.category.not_allowed_use_case")) end - it 'checks if use case is allowed' do + it "checks if use case is allowed" do category = Category.new(use_case: Category::GENERAL) - category.allowed_use_case?('whatever').should be_truthy + category.allowed_use_case?("whatever").should be_truthy - category.use_case = 'BlogPost' - category.allowed_use_case?('whatever').should be_falsey - category.allowed_use_case?('BlogPost').should be_truthy + category.use_case = "BlogPost" + category.allowed_use_case?("whatever").should be_falsey + category.allowed_use_case?("BlogPost").should be_truthy end end diff --git a/spec/models/constant_spec.rb b/spec/models/constant_spec.rb index e398526cd..b63d6a417 100644 --- a/spec/models/constant_spec.rb +++ b/spec/models/constant_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Constant, type: :model do subject(:constant) { build(:constant) } @@ -8,14 +8,14 @@ it { should validate_uniqueness_of(:name) } end - it 'is valid with a name and a value' do - c = Constant.new(name: 'foo', value: 'bar') + it "is valid with a name and a value" do + c = Constant.new(name: "foo", value: "bar") c.should be_valid end - it 'can return value by calling the get() function' do - Constant.create(name: 'foo', value: 'bar') - val = Constant.get 'foo' - val.should eq('bar') + it "can return value by calling the get() function" do + Constant.create(name: "foo", value: "bar") + val = Constant.get "foo" + val.should eq("bar") end end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index be1fa78b2..df75c6c93 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Contact, type: :model do subject(:contact) { build(:contact) } diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb index 2d1dd55ed..4768cd627 100644 --- a/spec/models/document_spec.rb +++ b/spec/models/document_spec.rb @@ -1,14 +1,14 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Document, type: :model do - describe 'valid factory' do - it 'has valid factory' do + describe "valid factory" do + it "has valid factory" do build_stubbed(:document).should be_valid end end - describe 'associations' do - it 'belongs_to user' do + describe "associations" do + it "belongs_to user" do Document.new.should belong_to(:user) end end diff --git a/spec/models/door_spec.rb b/spec/models/door_spec.rb index ee929a8a7..073991696 100644 --- a/spec/models/door_spec.rb +++ b/spec/models/door_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Door, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build_stubbed(:door).should be_valid end end diff --git a/spec/models/election_post_spec.rb b/spec/models/election_post_spec.rb index e3e4b7d30..c71fd0808 100644 --- a/spec/models/election_post_spec.rb +++ b/spec/models/election_post_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ElectionPost, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build_stubbed(:election_post).should be_valid end subject { ElectionPost.new } @@ -12,7 +12,7 @@ it { should validate_presence_of(:election) } it { should validate_presence_of(:post) } - it 'validates uniqueness of post and election' do + it "validates uniqueness of post and election" do post = create(:post) election = create(:election) diff --git a/spec/models/election_spec.rb b/spec/models/election_spec.rb index cbe30a942..6d07d7012 100644 --- a/spec/models/election_spec.rb +++ b/spec/models/election_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Election, type: :model do subject { build_stubbed(:election) } - it 'has a valid factory' do + it "has a valid factory" do should be_valid end - describe 'ActiveModel validations' do + describe "ActiveModel validations" do it { should validate_presence_of(:url) } it { should validate_presence_of(:open) } it { should validate_presence_of(:close_general) } @@ -14,20 +14,20 @@ it { should validate_presence_of(:title) } it { should validate_presence_of(:semester) } - it 'validates url format' do + it "validates url format" do should validate_presence_of(:url) - should allow_value('abc_123-abc').for(:url) - should_not allow_value('ABC').for(:url) + should allow_value("abc_123-abc").for(:url) + should_not allow_value("ABC").for(:url) end end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do it { should have_many(:nominations) } it { should have_many(:candidates) } it { should have_many(:extra_posts) } end - describe '#state' do + describe "#state" do it :not_opened do e = build_stubbed(:election, :not_opened) e.state.should equal(:not_opened) @@ -49,13 +49,13 @@ end end - describe '#post_closing' do - it 'returns close_general for post elected at general' do + describe "#post_closing" do + it "returns close_general for post elected at general" do close_general = 1.day.ago close_all = 1.day.from_now election = build_stubbed(:election, :autumn, - close_general: close_general, - close_all: close_all) + close_general: close_general, + close_all: close_all) general_post = build_stubbed(:post, :autumn, :general) after_general_post = build_stubbed(:post, :autumn, :board) @@ -66,8 +66,8 @@ end end - describe '#countdown' do - it 'returns countdowns for different states' do + describe "#countdown" do + it "returns countdowns for different states" do open = 5.days.ago close_general = 3.days.ago close_all = 2.days.from_now @@ -91,52 +91,52 @@ end end - context 'post queries' do - describe '#posts' do - it 'returns according to semester' do + context "post queries" do + describe "#posts" do + it "returns according to semester" do election = create(:election) - create(:post, :autumn, title: 'In the Autumn') - create(:post, :spring, title: 'In the Spring') - election.extra_posts << create(:post, semester: 'not_by_semester', - title: 'An extra one') + create(:post, :autumn, title: "In the Autumn") + create(:post, :spring, title: "In the Spring") + election.extra_posts << create(:post, semester: "not_by_semester", + title: "An extra one") election.stub(:semester).and_return(Post::AUTUMN) - election.posts.map(&:title).should eq(['In the Autumn']) + election.posts.map(&:title).should eq(["In the Autumn"]) election.stub(:semester).and_return(Post::SPRING) - election.posts.map(&:title).should eq(['In the Spring']) + election.posts.map(&:title).should eq(["In the Spring"]) election.stub(:semester).and_return(Post::OTHER) - election.posts.map(&:title).should eq(['An extra one']) + election.posts.map(&:title).should eq(["An extra one"]) end end - describe '#current_posts' do - it 'returns according to state' do + describe "#current_posts" do + it "returns according to state" do election = create(:election, :autumn) - create(:post, :autumn, :general, title: 'Elected at General') - create(:post, :autumn, :board, title: 'Elected by Board') + create(:post, :autumn, :general, title: "Elected at General") + create(:post, :autumn, :board, title: "Elected by Board") election.stub(:state).and_return(:not_opened) - election.current_posts.map(&:title).should eq(['Elected at General', - 'Elected by Board']) + election.current_posts.map(&:title).should eq(["Elected at General", + "Elected by Board"]) election.stub(:state).and_return(:before_general) - election.current_posts.map(&:title).should eq(['Elected at General', - 'Elected by Board']) + election.current_posts.map(&:title).should eq(["Elected at General", + "Elected by Board"]) election.stub(:state).and_return(:after_general) - election.current_posts.map(&:title).should eq(['Elected by Board']) + election.current_posts.map(&:title).should eq(["Elected by Board"]) election.stub(:state).and_return(:closed) election.current_posts.map(&:title).should eq([]) end end - describe '#current_posts' do - it 'returns according to state' do + describe "#current_posts" do + it "returns according to state" do election = build_stubbed(:election) - election.stub(:current_posts).and_return('yeppyepp') + election.stub(:current_posts).and_return("yeppyepp") election.stub(:state).and_return(:not_opened) election.searchable_posts.should eq(Post.none) @@ -145,10 +145,10 @@ election.searchable_posts.should eq(Post.none) election.stub(:state).and_return(:before_general) - election.searchable_posts.should eq('yeppyepp') + election.searchable_posts.should eq("yeppyepp") election.stub(:state).and_return(:after_general) - election.searchable_posts.should eq('yeppyepp') + election.searchable_posts.should eq("yeppyepp") end end end diff --git a/spec/models/event_signup_spec.rb b/spec/models/event_signup_spec.rb index 0a6755ce5..fe3048e40 100644 --- a/spec/models/event_signup_spec.rb +++ b/spec/models/event_signup_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe EventSignup, type: :model do - it 'has valid factory' do + it "has valid factory" do build_stubbed(:event_signup).should be_valid end - it 'returns open?' do + it "returns open?" do signup = build_stubbed(:event_signup, opens: 1.day.ago, closes: 2.days.from_now) signup.open?.should be_truthy @@ -13,7 +13,7 @@ signup.open?.should be_falsey end - it 'returns order of priority' do + it "returns order of priority" do event_signup = build_stubbed(:event_signup, novice: nil, mentor: nil, member: nil, custom: nil) event_signup.order.should eq([]) @@ -22,34 +22,34 @@ event_signup.order.should eq([EventSignup::MENTOR, EventSignup::NOVICE]) end - describe '#selectable_types' do - it 'returns users highest priority type' do + describe "#selectable_types" do + it "returns users highest priority type" do event_signup = build_stubbed(:event_signup, novice: 37, mentor: 27, member: 17, custom: 7, - custom_name: 'woop') + custom_name: "woop") user = User.new user.stub(:mentor?).and_return(false) user.stub(:novice?).and_return(false) user.stub(:member?).and_return(true) event_signup.selectable_types(user).should eq([EventSignup::MEMBER, - EventSignup::CUSTOM]) - + EventSignup::CUSTOM]) + user.stub(:novice?).and_return(true) event_signup.selectable_types(user).should eq([EventSignup::NOVICE, - EventSignup::CUSTOM]) + EventSignup::CUSTOM]) user.stub(:mentor?).and_return(true) event_signup.selectable_types(user).should eq([EventSignup::MENTOR, - EventSignup::CUSTOM]) + EventSignup::CUSTOM]) event_signup.custom = nil event_signup.selectable_types(user).should eq([EventSignup::MENTOR]) end - it 'returns nil if no suiting type' do + it "returns nil if no suiting type" do event_signup = build_stubbed(:event_signup, novice: 10, mentor: nil, member: nil, @@ -62,19 +62,19 @@ end end - describe 'validations' do - it 'checks no priority is equal (except nil)' do + describe "validations" do + it "checks no priority is equal (except nil)" do event_signup = build_stubbed(:event_signup, novice: 37, mentor: 37) event_signup.should be_invalid - event_signup.errors[:novice].should include(I18n.t('model.event_signup.same_priority')) + event_signup.errors[:novice].should include(I18n.t("model.event_signup.same_priority")) end - it 'checks custom name is present if custom not nil' do + it "checks custom name is present if custom not nil" do event_signup = build_stubbed(:event_signup, custom: 37, custom_name: nil) event_signup.should be_invalid - event_signup.errors[:custom_name].should include(I18n.t('model.event_signup.custom_name_missing')) + event_signup.errors[:custom_name].should include(I18n.t("model.event_signup.custom_name_missing")) end end end diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 7a60c03a0..767a1829d 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -1,25 +1,25 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Event, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build_stubbed(:event).should be_valid end - it 'has valid factory with signup' do + it "has valid factory with signup" do build_stubbed(:event, :with_signup).should be_valid end - describe 'by locale' do - it 'returns event depending on locale' do - create(:event, title_sv: 'Ej översatt', title_en: 'Not translated') - event_en = create(:event, title_sv: 'Kommer att översättas', title_en: 'Kommer att översättas') - event_en.update!(title_en: 'Will be translated') - - Event.by_locale.map(&:title).should eq(['Ej översatt', - 'Kommer att översättas']) - Event.by_locale(locale: 'en').order(:created_at).map(&:title_en).should eq(['Not translated', - 'Will be translated']) - Event.by_locale(locale: 'nope').should be_empty + describe "by locale" do + it "returns event depending on locale" do + create(:event, title_sv: "Ej översatt", title_en: "Not translated") + event_en = create(:event, title_sv: "Kommer att översättas", title_en: "Kommer att översättas") + event_en.update!(title_en: "Will be translated") + + Event.by_locale.map(&:title).should eq(["Ej översatt", + "Kommer att översättas"]) + Event.by_locale(locale: "en").order(:created_at).map(&:title_en).should eq(["Not translated", + "Will be translated"]) + Event.by_locale(locale: "nope").should be_empty end end @@ -27,7 +27,7 @@ # Fullcalendars json-feed # Ref.: https://github.com/fsek/web/issues/99 describe :json do - it 'check date format is iso8601' do + it "check date format is iso8601" do start = 1.day.from_now stop = 3.days.from_now event = build_stubbed(:event, starts_at: start, @@ -38,11 +38,11 @@ serializer = EventSerializer.new(event) json = JSON.parse(ActiveModelSerializers::Adapter.create(serializer, adapter: :attributes).to_json) - json['start'].should eq(start.iso8601) - json['end'].should eq(stop.iso8601) + json["start"].should eq(start.iso8601) + json["end"].should eq(stop.iso8601) end - it 'adds one day if all_day' do + it "adds one day if all_day" do start = 1.day.from_now stop = 3.days.from_now event = build_stubbed(:event, starts_at: start, @@ -53,8 +53,8 @@ serializer = EventSerializer.new(event) json = JSON.parse(ActiveModelSerializers::Adapter.create(serializer, adapter: :attributes).to_json) - json['start'].should eq(start.to_date.iso8601) - json['end'].should eq((stop + 1.day).to_date.iso8601) + json["start"].should eq(start.to_date.iso8601) + json["end"].should eq((stop + 1.day).to_date.iso8601) end end end diff --git a/spec/models/event_user_spec.rb b/spec/models/event_user_spec.rb index f81858573..beaedd1fa 100644 --- a/spec/models/event_user_spec.rb +++ b/spec/models/event_user_spec.rb @@ -1,47 +1,47 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe EventUser, type: :model do - it 'should have valid factory' do + it "should have valid factory" do create(:event_user).should be_valid end - describe 'validations' do - it 'checks if signup is open' do + describe "validations" do + it "checks if signup is open" do event_user = create(:event_user) event_user.event_signup.stub(:open?).and_return(false) event_user.valid?.should be_falsey - event_user.errors[:event].should include(I18n.t('model.event_signup.not_open')) + event_user.errors[:event].should include(I18n.t("model.event_signup.not_open")) end - it 'checks for membership' do + it "checks for membership" do event_user = create(:event_user) event_user.event_signup.stub(:for_members?).and_return(true) event_user.user.stub(:member_at).and_return(false) event_user.valid?.should be_falsey - event_user.errors[:user].should include(I18n.t('model.event_user.user_not_member')) + event_user.errors[:user].should include(I18n.t("model.event_user.user_not_member")) end - it 'checks user_type' do + it "checks user_type" do event_user = create(:event_user, user_type: nil) event_user.should be_valid event_user.user_type = EventSignup::NOVICE event_user.event_signup.stub(:order).and_return([EventSignup::MEMBER]) event_user.valid?.should be_falsey - event_user.errors[:user_type].should include(I18n.t('model.event_user.unavailable_type')) + event_user.errors[:user_type].should include(I18n.t("model.event_user.unavailable_type")) end - it 'checks selected user_type' do + it "checks selected user_type" do event_user = create(:event_user) event_user.user_type = EventSignup::NOVICE event_user.user.stub(:novice?).and_return(false) event_user.valid?.should be_falsey - event_user.errors[:user_type].should include(I18n.t('model.event_user.user_type_not_allowed')) + event_user.errors[:user_type].should include(I18n.t("model.event_user.user_type_not_allowed")) end - it 'checks if user is in selected group' do + it "checks if user is in selected group" do event_user = create(:event_user) group = create(:group_user, user: event_user.user).group event_user.group = group @@ -49,12 +49,12 @@ event_user.user.stub(:groups).and_return([]) event_user.valid?.should be_falsey - event_user.errors[:group_id].should include(I18n.t('model.event_user.not_in_group')) + event_user.errors[:group_id].should include(I18n.t("model.event_user.not_in_group")) end end - describe 'scopes' do - it 'returns attending users and reserves correctly' do + describe "scopes" do + it "returns attending users and reserves correctly" do event = create(:event) create(:event_signup, event: event, slots: 5, @@ -78,7 +78,7 @@ EventUser.reserves(event).should eq(reserve) end - it 'orders attending users by group' do + it "orders attending users by group" do event = create(:event) create(:event_signup, event: event, slots: 5, diff --git a/spec/models/image_spec.rb b/spec/models/image_spec.rb index 579406721..871c16daa 100644 --- a/spec/models/image_spec.rb +++ b/spec/models/image_spec.rb @@ -1,18 +1,18 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Image, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build(:image).should be_valid end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do it { Image.new.should belong_to(:album) } it { Image.new.should belong_to(:photographer) } end - context 'callbacks' do - describe 'public instance methods' do - context 'responds to its methods' do + context "callbacks" do + describe "public instance methods" do + context "responds to its methods" do it { Image.new.should respond_to(:original) } it { Image.new.should respond_to(:thumb) } it { Image.new.should respond_to(:view) } diff --git a/spec/models/introduction_spec.rb b/spec/models/introduction_spec.rb index 1f8f45ec1..4e2624b36 100644 --- a/spec/models/introduction_spec.rb +++ b/spec/models/introduction_spec.rb @@ -1,12 +1,12 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Introduction, type: :model do - it 'have valid factory' do + it "have valid factory" do build_stubbed(:introduction).should be_valid end - describe 'introduction week' do - it 'gives introduction week for a date, if same year' do + describe "introduction week" do + it "gives introduction week for a date, if same year" do date = Time.current.change(month: 8).beginning_of_week introduction = build_stubbed(:introduction, start: date) @@ -16,7 +16,7 @@ introduction.week(date + 15.days).should eq(2) end - it 'returns nil if not same year' do + it "returns nil if not same year" do date = Time.current.change(month: 12, day: 31).beginning_of_week introduction = build_stubbed(:introduction, start: date) @@ -24,7 +24,7 @@ introduction.week(date + 8.days).should be_nil end - it 'gives introduction week for an integer' do + it "gives introduction week for an integer" do date = Time.current.beginning_of_week week = date.to_date.cweek introduction = build_stubbed(:introduction, start: date) diff --git a/spec/models/mail_alias_spec.rb b/spec/models/mail_alias_spec.rb index 27d44e20b..c94b2720a 100644 --- a/spec/models/mail_alias_spec.rb +++ b/spec/models/mail_alias_spec.rb @@ -1,75 +1,75 @@ -require 'rails_helper' +require "rails_helper" describe MailAlias do - describe '#validate!' do - it 'requires all fields' do - [ :username, :domain, :target ].each do |a| + describe "#validate!" do + it "requires all fields" do + [:username, :domain, :target].each do |a| build_stubbed(:mail_alias, a => nil).should_not be_valid end end - it 'validates the provided example' do + it "validates the provided example" do build_stubbed(:mail_alias).should be_valid end - it 'rejects duplicate aliases on the same domain' do - create :mail_alias, :username => 'johan', :domain => 'fsektionen.se', - :target => 'jaforberg@gmail.com' - build(:mail_alias, :username => 'johan', :domain => 'fsektionen.se', - :target => 'jaforberg@gmail.com').should_not be_valid + it "rejects duplicate aliases on the same domain" do + create :mail_alias, username: "johan", domain: "fsektionen.se", + target: "jaforberg@gmail.com" + build(:mail_alias, username: "johan", domain: "fsektionen.se", + target: "jaforberg@gmail.com").should_not be_valid end - it 'rejects invalid domains' do - build(:mail_alias, :domain => 'microsoft.com').should_not be_valid + it "rejects invalid domains" do + build(:mail_alias, domain: "microsoft.com").should_not be_valid end - it 'rejects bad username formats' do - build(:mail_alias, :username => 'yeaha@#$@$^').should_not be_valid + it "rejects bad username formats" do + build(:mail_alias, username: 'yeaha@#$@$^').should_not be_valid end - it 'rejects bad target formats' do - build(:mail_alias, :target => 'bitches').should_not be_valid + it "rejects bad target formats" do + build(:mail_alias, target: "bitches").should_not be_valid end end - describe '#address' do - it 'returns the expected value' do - build(:mail_alias, :username => 'johan', - :domain => 'fsektionen.se').address.should == 'johan@fsektionen.se' + describe "#address" do + it "returns the expected value" do + build(:mail_alias, username: "johan", + domain: "fsektionen.se").address.should == "johan@fsektionen.se" end end - describe '.fulltext_search' do - it 'works as expected for a few examples' do - m1 = create(:mail_alias, :username => 'johan', :domain => 'fsektionen.se', - :target => 'jaforberg@gmail.com') - m2 = create(:mail_alias, :username => 'erik', :domain => 'fsektionen.se', - :target => 'erikhenrikssn@gmail.com') + describe ".fulltext_search" do + it "works as expected for a few examples" do + m1 = create(:mail_alias, username: "johan", domain: "fsektionen.se", + target: "jaforberg@gmail.com") + m2 = create(:mail_alias, username: "erik", domain: "fsektionen.se", + target: "erikhenrikssn@gmail.com") - MailAlias.fulltext_search('johan').should == [ m1 ] - MailAlias.fulltext_search('jo').should == [ m1 ] - MailAlias.fulltext_search('johannes').should == [ ] - MailAlias.fulltext_search('erik').should == [ m2 ] + MailAlias.fulltext_search("johan").should == [m1] + MailAlias.fulltext_search("jo").should == [m1] + MailAlias.fulltext_search("johannes").should == [] + MailAlias.fulltext_search("erik").should == [m2] end end - describe '.insert_aliases!' do - it 'can set empty target list (clear)' do + describe ".insert_aliases!" do + it "can set empty target list (clear)" do c = create :mail_alias MailAlias.insert_aliases! c.username, c.domain, [] MailAlias.count.should == 0 end - it 'can create new alias' do + it "can create new alias" do c = build :mail_alias - ts = [ 'test@gmail.com', 'hej@what.com', 'lol@whut.se' ] + ts = ["test@gmail.com", "hej@what.com", "lol@whut.se"] MailAlias.insert_aliases! c.username, c.domain, ts MailAlias.all.pluck(:target).should =~ ts end - it 'touches existing records' do - c = create :mail_alias, :updated_at => 1.month.ago - MailAlias.insert_aliases! c.username, c.domain, [ c.target ] + it "touches existing records" do + c = create :mail_alias, updated_at: 1.month.ago + MailAlias.insert_aliases! c.username, c.domain, [c.target] MailAlias.count.should == 1 MailAlias.first.updated_at.to_date.should == Time.zone.now.to_date end diff --git a/spec/models/meeting_spec.rb b/spec/models/meeting_spec.rb index 53fd7012e..116af001f 100644 --- a/spec/models/meeting_spec.rb +++ b/spec/models/meeting_spec.rb @@ -1,53 +1,53 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe EventUser, type: :model do - it 'should have valid factory' do + it "should have valid factory" do create(:meeting).should be_valid end - describe 'validations' do - it 'fails for non-members' do + describe "validations" do + it "fails for non-members" do user = build_stubbed(:user, :not_member) meeting = build_stubbed(:meeting, user: user) meeting.should be_invalid - meeting.errors[:user].should include(I18n.t('model.meeting.membership_needed')) + meeting.errors[:user].should include(I18n.t("model.meeting.membership_needed")) end - it 'requires user details' do + it "requires user details" do user = build_stubbed(:user, phone: nil) meeting = build_stubbed(:meeting, user: user) meeting.should be_invalid - meeting.errors[:user].should include(I18n.t('model.meeting.add_user_information')) + meeting.errors[:user].should include(I18n.t("model.meeting.add_user_information")) end - it 'works for members with user details' do + it "works for members with user details" do user = build_stubbed(:user) meeting = build_stubbed(:meeting, user: user) meeting.should be_valid end - it 'fails for end date before start date' do + it "fails for end date before start date" do meeting = build_stubbed(:meeting, start_date: 1.hour.from_now, end_date: 1.hour.ago) meeting.should be_invalid - meeting.errors[:end_date].should include(I18n.t('model.meeting.end_after_start')) + meeting.errors[:end_date].should include(I18n.t("model.meeting.end_after_start")) end - it 'does not allow users to create confirmed reservations' do + it "does not allow users to create confirmed reservations" do meeting = build_stubbed(:meeting, status: :confirmed) meeting.should be_invalid - meeting.errors[:status].should include(I18n.t('errors.messages.inclusion', attribute: 'Status')) + meeting.errors[:status].should include(I18n.t("errors.messages.inclusion", attribute: "Status")) end - it 'allows admins to create confirmed reservations' do + it "allows admins to create confirmed reservations" do meeting = build_stubbed(:meeting, status: :confirmed, is_admin: true) meeting.should be_valid end - it 'does not allow confirmed meetings to overlap' do + it "does not allow confirmed meetings to overlap" do start_d = 1.hour.from_now end_d = 3.hours.from_now meeting1 = create(:meeting, start_date: start_d, end_date: end_d, @@ -57,11 +57,11 @@ meeting1.should be_valid meeting2.should be_invalid - meeting2.errors[:start_date].should include(I18n.t('model.meeting.overlaps_confirmed')) - meeting2.errors[:end_date].should include(I18n.t('model.meeting.overlaps_confirmed')) + meeting2.errors[:start_date].should include(I18n.t("model.meeting.overlaps_confirmed")) + meeting2.errors[:end_date].should include(I18n.t("model.meeting.overlaps_confirmed")) end - it 'allows unconfirmed meetings to overlap with one confirmed meeting' do + it "allows unconfirmed meetings to overlap with one confirmed meeting" do start_d = 1.hour.from_now end_d = 3.hours.from_now meeting1 = create(:meeting, start_date: start_d, end_date: end_d, diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index fd504289c..2d94df558 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -1,20 +1,20 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Message, type: :model do it { Message.new.should validate_presence_of(:content) } - describe 'validations' do - it 'is valid if user is in group' do + describe "validations" do + it "is valid if user is in group" do intro = create(:introduction) user = create(:user) group = create(:group, introduction: intro) - m = Message.new(content: 'I got a text', user: user, introduction: intro) + m = Message.new(content: "I got a text", user: user, introduction: intro) m.should be_invalid - m.errors[:groups].should include(I18n.t('model.message.need_groups')) + m.errors[:groups].should include(I18n.t("model.message.need_groups")) m.groups << group m.should be_invalid - m.errors[:groups].should include(I18n.t('model.message.not_part_of_selected_groups')) + m.errors[:groups].should include(I18n.t("model.message.not_part_of_selected_groups")) create(:group_user, group: group, user: user) user.reload @@ -23,28 +23,28 @@ m.groups << create(:group, introduction: intro) m.should be_invalid - m.errors[:groups].should include(I18n.t('model.message.not_part_of_selected_groups')) + m.errors[:groups].should include(I18n.t("model.message.not_part_of_selected_groups")) end - it 'is valid if admin' do + it "is valid if admin" do intro = create(:introduction) user = create(:user) - m = Message.new(content: 'with a text', user: user, introduction: intro) + m = Message.new(content: "with a text", user: user, introduction: intro) m.groups << create(:group, introduction: intro) << create(:group, introduction: intro) m.should be_invalid - m.errors[:groups].should include(I18n.t('model.message.not_part_of_selected_groups')) + m.errors[:groups].should include(I18n.t("model.message.not_part_of_selected_groups")) m.by_admin = true m.should be_valid end end - describe 'with_group' do - it 'is true if any group overlap' do + describe "with_group" do + it "is true if any group overlap" do intro = create(:introduction) sender = create(:user) group = create(:group, introduction: intro) - message = Message.new(content: 'A text', user: sender, introduction: intro) + message = Message.new(content: "A text", user: sender, introduction: intro) message.groups << group << create(:group, introduction: intro) message.by_admin = true diff --git a/spec/models/news_spec.rb b/spec/models/news_spec.rb index 1ba5d327b..15793dbeb 100644 --- a/spec/models/news_spec.rb +++ b/spec/models/news_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe News, type: :model do - it 'has valid factory' do + it "has valid factory" do build_stubbed(:news).should be_valid end end diff --git a/spec/models/nomination_spec.rb b/spec/models/nomination_spec.rb index b35b18bc5..8ba7ce8f6 100644 --- a/spec/models/nomination_spec.rb +++ b/spec/models/nomination_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Nomination, type: :model do - describe 'validations' do + describe "validations" do subject { Nomination.new } it { should validate_presence_of(:name) } @@ -9,18 +9,18 @@ it { should validate_presence_of(:post) } it { should validate_presence_of(:election) } - it 'checks email format' do + it "checks email format" do nomination = Nomination.new - nomination.should allow_value('hilbert911.1@fsektionen.se').for(:email) - nomination.should_not allow_value('hilbert').for(:email) - nomination.should_not allow_value('hilbert@fsektionen').for(:email) - nomination.should_not allow_value('@fsektionen.se').for(:email) + nomination.should allow_value("hilbert911.1@fsektionen.se").for(:email) + nomination.should_not allow_value("hilbert").for(:email) + nomination.should_not allow_value("hilbert@fsektionen").for(:email) + nomination.should_not allow_value("@fsektionen.se").for(:email) end end - describe 'public methods' do - it 'has candidate_url' do + describe "public methods" do + it "has candidate_url" do nomination = build_stubbed(:nomination) post = nomination.post diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 13428e5c3..aaa601436 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Notification, type: :model do - it 'has valid factory' do + it "has valid factory" do build_stubbed(:notification, :build_stubbed).should be_valid end end diff --git a/spec/models/page_element_spec.rb b/spec/models/page_element_spec.rb index 5269d6a66..3d1e98760 100644 --- a/spec/models/page_element_spec.rb +++ b/spec/models/page_element_spec.rb @@ -1,37 +1,37 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PageElement, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build(:page_element).should be_valid end - describe 'ActiveRecord associations' do - it 'validates element_type and page_id present' do + describe "ActiveRecord associations" do + it "validates element_type and page_id present" do page_element = build(:page_element) page_element.should validate_presence_of(:page) page_element.should validate_presence_of(:element_type) end end - describe 'public methods' do - it 'has valid to_s' do - page_element = build_stubbed(:page_element, id: 1337, headline: 'Cool') - page_element.to_s.should eq('Cool') + describe "public methods" do + it "has valid to_s" do + page_element = build_stubbed(:page_element, id: 1337, headline: "Cool") + page_element.to_s.should eq("Cool") page_element.headline = nil page_element.to_s.should eq(1337) end - it 'gives the right partial path if image' do + it "gives the right partial path if image" do page_element = build_stubbed(:page_element, element_type: PageElement::IMAGE) - page_element.to_partial_path.should eq('/pages/image_element') + page_element.to_partial_path.should eq("/pages/image_element") end - it 'gives the right partial path if text' do + it "gives the right partial path if text" do page_element = build_stubbed(:page_element, element_type: PageElement::TEXT) - page_element.to_partial_path.should eq('/pages/text_element') + page_element.to_partial_path.should eq("/pages/text_element") end end end diff --git a/spec/models/page_image_spec.rb b/spec/models/page_image_spec.rb index 417d8c0f0..ffb60bb62 100644 --- a/spec/models/page_image_spec.rb +++ b/spec/models/page_image_spec.rb @@ -1,19 +1,19 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PageImage, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build_stubbed(:page_image).should be_valid end - describe 'ActiveRecord associations' do - it 'validates image and page_id present' do + describe "ActiveRecord associations" do + it "validates image and page_id present" do PageImage.new.should validate_presence_of(:page) PageImage.new.should validate_presence_of(:image) end end - describe 'public methods' do - it 'has valid to_s' do + describe "public methods" do + it "has valid to_s" do build_stubbed(:page_image, id: 1337).to_s.should eq(1337) end end diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb index 8ba72ce1f..b805b97b1 100644 --- a/spec/models/page_spec.rb +++ b/spec/models/page_spec.rb @@ -1,64 +1,64 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Page, type: :model do - it 'has a valid factory' do + it "has a valid factory" do build(:page).should be_valid end - describe 'validations' do - it 'validates url' do - page = build_stubbed(:page, url: 'abc') + describe "validations" do + it "validates url" do + page = build_stubbed(:page, url: "abc") page.should validate_presence_of(:url) - page.should allow_value('abc_123-abc').for(:url) - page.should_not allow_value('ABC').for(:url) - page.should allow_value('abc_123-abc').for(:namespace) - page.should_not allow_value('ABC').for(:namespace) - page.should_not allow_value('https://illegal.com').for(:url) + page.should allow_value("abc_123-abc").for(:url) + page.should_not allow_value("ABC").for(:url) + page.should allow_value("abc_123-abc").for(:namespace) + page.should_not allow_value("ABC").for(:namespace) + page.should_not allow_value("https://illegal.com").for(:url) end end - context 'page elements' do - describe 'main' do - it 'returns all visible main fields' do + context "page elements" do + describe "main" do + it "returns all visible main fields" do page = create(:page) - create(:page_element, page: page, headline: 'Second', + create(:page_element, page: page, headline: "Second", visible: true, index: 10, sidebar: false) - create(:page_element, page: page, headline: 'First', + create(:page_element, page: page, headline: "First", visible: true, index: 1, sidebar: false) - create(:page_element, page: page, headline: 'Not visible', + create(:page_element, page: page, headline: "Not visible", visible: false, sidebar: false) - create(:page_element, page: page, headline: 'Sidebar', + create(:page_element, page: page, headline: "Sidebar", visible: true, sidebar: true) - create(:page_element, headline: 'Other page', + create(:page_element, headline: "Other page", visible: true, sidebar: false) - page.main.map(&:headline).should eq(['First', 'Second']) + page.main.map(&:headline).should eq(["First", "Second"]) end end - describe 'side' do - it 'returns all visible sidebar fields' do + describe "side" do + it "returns all visible sidebar fields" do page = create(:page) - create(:page_element, page: page, headline: 'Second', + create(:page_element, page: page, headline: "Second", visible: true, index: 10, sidebar: true) - create(:page_element, page: page, headline: 'Not visible', + create(:page_element, page: page, headline: "Not visible", visible: false, index: 5, sidebar: true) - create(:page_element, page: page, headline: 'First', + create(:page_element, page: page, headline: "First", visible: true, index: 1, sidebar: true) - create(:page_element, page: page, headline: 'Main field', + create(:page_element, page: page, headline: "Main field", visible: true, index: 10, sidebar: false) - create(:page_element, headline: 'Other page', + create(:page_element, headline: "Other page", visible: true, index: 10, sidebar: true) - page.side.map(&:headline).should eq(['First', 'Second']) + page.side.map(&:headline).should eq(["First", "Second"]) end end end diff --git a/spec/models/permission_post_spec.rb b/spec/models/permission_post_spec.rb index 53607d2cb..f363e7915 100644 --- a/spec/models/permission_post_spec.rb +++ b/spec/models/permission_post_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PermissionPost, type: :model do it { PermissionPost.new.should validate_presence_of(:permission) } diff --git a/spec/models/permission_spec.rb b/spec/models/permission_spec.rb index 2c2b83e46..f6e49eb37 100644 --- a/spec/models/permission_spec.rb +++ b/spec/models/permission_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Permission, type: :model do it { should validate_presence_of(:subject_class) } diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 1e5e180f4..7b7705344 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1,7 +1,7 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Post, type: :model do - it 'has a valid factory' do + it "has a valid factory" do (build(:post)).should be_valid end @@ -11,14 +11,14 @@ let(:permission) { create(:permission) } subject { build(:post, council: council) } - describe 'ActiveModel validations' do + describe "ActiveModel validations" do # Basic validations it { should validate_presence_of(:limit) } it { should validate_presence_of(:rec_limit) } it { should validate_presence_of(:description) } end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do # Associations it { should belong_to(:council) } it { should have_many(:post_users) } @@ -29,16 +29,16 @@ it { should have_many(:permission_posts) } end - describe 'public instance methods' do - context 'responds to its methods' do + describe "public instance methods" do + context "responds to its methods" do it { should respond_to(:to_s) } it { should respond_to(:limited?) } it { should respond_to(:set_permissions) } end - context 'executes methods correctly' do - context 'valid parameters' do - it 'set_permissions' do + context "executes methods correctly" do + context "valid parameters" do + it "set_permissions" do post.set_permissions(permission_ids: [permission.id]) post.permissions.should include(permission) diff --git a/spec/models/post_user_spec.rb b/spec/models/post_user_spec.rb index d76b93e1e..5dd6c4e3d 100644 --- a/spec/models/post_user_spec.rb +++ b/spec/models/post_user_spec.rb @@ -1,28 +1,28 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PostUser.new, type: :model do let(:post_user) { build_stubbed(:post_user) } it { post_user.should be_valid } - describe 'ActiveModel validations' do + describe "ActiveModel validations" do # Basic validations it { PostUser.new.should validate_presence_of(:user_id) } it { PostUser.new.should validate_presence_of(:post_id) } - it 'validates uniqueness' do - PostUser.new.should validate_uniqueness_of(:user_id).scoped_to(:post_id). - with_message(I18n.t('model.post_user.already_have_post')) + it "validates uniqueness" do + PostUser.new.should validate_uniqueness_of(:user_id).scoped_to(:post_id) + .with_message(I18n.t("model.post_user.already_have_post")) end end - describe 'ActiveRecord associations' do + describe "ActiveRecord associations" do # Associations it { PostUser.new.should belong_to(:post) } it { PostUser.new.should belong_to(:user) } end - describe 'public instance methods' do - context 'responds to its methods' do + describe "public instance methods" do + context "responds to its methods" do it { post_user.should respond_to(:to_s) } end end diff --git a/spec/models/rent_spec.rb b/spec/models/rent_spec.rb index 612e2182d..b668e0adc 100644 --- a/spec/models/rent_spec.rb +++ b/spec/models/rent_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Rent, type: :model do describe :associations do @@ -12,21 +12,21 @@ describe :duration do context :when_no_council do - it 'add error if duration is over 48' do + it "add error if duration is over 48" do rent = build_stubbed(:rent, :over_48) rent.should_not be_valid - rent.errors[:d_from].should include(I18n.t('model.rent.validation.duration')) + rent.errors[:d_from].should include(I18n.t("model.rent.validation.duration")) end - it 'do not add error if duration is under 48' do + it "do not add error if duration is under 48" do rent = build_stubbed(:rent, :under_48) rent.should be_valid end end context :when_council do - it 'do not add error if duration is over 48' do + it "do not add error if duration is over 48" do rent = build_stubbed(:rent, :over_48, :with_council) rent.should be_valid end @@ -35,121 +35,121 @@ describe :dates_in_future do context :when_future do - it 'add error if d_from > d_til' do + it "add error if d_from > d_til" do rent = build_stubbed(:rent, d_from: 5.hours.from_now, d_til: 4.hours.from_now) rent.should_not be_valid - rent.errors[:d_til].should include(I18n.t('model.rent.validation.ascending')) + rent.errors[:d_til].should include(I18n.t("model.rent.validation.ascending")) end end context :when_past do - it 'add error if d_from > d_til' do + it "add error if d_from > d_til" do rent = build_stubbed(:rent, d_from: 5.hours.ago, d_til: 10.hours.ago, id: nil) rent.should_not be_valid - rent.errors[:d_from].should include(I18n.t('model.rent.validation.future')) + rent.errors[:d_from].should include(I18n.t("model.rent.validation.future")) end - it 'add error if d_from < d_til' do + it "add error if d_from < d_til" do rent = build_stubbed(:rent, d_from: 10.hours.ago, d_til: 5.hours.ago, id: nil) rent.should_not be_valid - rent.errors[:d_from].should include(I18n.t('model.rent.validation.future')) + rent.errors[:d_from].should include(I18n.t("model.rent.validation.future")) end end end # Validate if overlap describe :overlap do - context 'no councils' do - it 'overlaps with d_til' do + context "no councils" do + it "overlaps with d_til" do rent = create(:rent, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, - d_from: rent.d_from + 5.hours, - d_til: rent.d_til + 5.hours) + d_from: rent.d_from + 5.hours, + d_til: rent.d_til + 5.hours) new_rent.should_not be_valid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap")) end - it 'overlaps with d_from' do + it "overlaps with d_from" do rent = create(:rent, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, - d_from: rent.d_from - 5.hours, - d_til: rent.d_from + 5.hours) + d_from: rent.d_from - 5.hours, + d_til: rent.d_from + 5.hours) new_rent.should_not be_valid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap")) end - it 'overlaps with both d_from and d_til' do + it "overlaps with both d_from and d_til" do rent = create(:rent, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, - d_from: rent.d_from - 5.hours, - d_til: rent.d_til + 5.hours) + d_from: rent.d_from - 5.hours, + d_til: rent.d_til + 5.hours) new_rent.should_not be_valid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap")) end - it 'overlaps between d_from and d_til' do + it "overlaps between d_from and d_til" do rent = create(:rent, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, - d_from: rent.d_from + 5.hours, - d_til: rent.d_til - 5.hours) + d_from: rent.d_from + 5.hours, + d_til: rent.d_til - 5.hours) new_rent.should_not be_valid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap")) end - it 'does not overlap' do + it "does not overlap" do rent = create(:rent, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, - d_from: rent.d_til + 5.hours, - d_til: rent.d_til + 10.hours) + d_from: rent.d_til + 5.hours, + d_til: rent.d_til + 10.hours) new_rent.should be_valid new_rent.errors[:d_from].should be_empty end end - context 'new council booking' do - it 'allows to overlap non council' do + context "new council booking" do + it "allows to overlap non council" do rent = create(:rent, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, :with_council, - d_from: rent.d_from + 5.hours, - d_til: rent.d_til - 5.hours) + d_from: rent.d_from + 5.hours, + d_til: rent.d_til - 5.hours) new_rent.should be_valid end - it 'does not allow to overbook if < 5 days away' do + it "does not allow to overbook if < 5 days away" do rent = create(:rent, d_from: 3.days.from_now, d_til: 4.days.from_now) new_rent = build_stubbed(:rent, :with_council, - d_from: rent.d_from + 5.hours, - d_til: rent.d_til - 5.hours) + d_from: rent.d_from + 5.hours, + d_til: rent.d_til - 5.hours) new_rent.should be_invalid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap_overbook')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap_overbook")) end end - context 'saved council' do - it 'does not allow non council booking to overlap' do + context "saved council" do + it "does not allow non council booking to overlap" do rent = create(:rent, :with_council, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, - d_from: rent.d_from + 5.hours, - d_til: rent.d_til - 5.hours) + d_from: rent.d_from + 5.hours, + d_til: rent.d_til - 5.hours) new_rent.should be_invalid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap")) end - it 'does not allow new council booking to overlap' do + it "does not allow new council booking to overlap" do rent = create(:rent, :with_council, d_from: 10.days.from_now, d_til: 11.days.from_now) new_rent = build_stubbed(:rent, :with_council, - d_from: rent.d_from + 5.hours, - d_til: rent.d_til - 5.hours) + d_from: rent.d_from + 5.hours, + d_til: rent.d_til - 5.hours) new_rent.should be_invalid - new_rent.errors[:d_from].should include(I18n.t('model.rent.validation.overlap_council')) + new_rent.errors[:d_from].should include(I18n.t("model.rent.validation.overlap_council")) end end end @@ -158,7 +158,7 @@ # Fullcalendars json-feed # Ref.: https://github.com/fsek/web/issues/99 describe :Json do - it 'check date format is iso8601' do + it "check date format is iso8601" do rent = build_stubbed(:rent) (rent.as_json.to_json).should include(rent.d_from.iso8601.to_json) (rent.as_json.to_json).should include(rent.d_til.iso8601.to_json) diff --git a/spec/models/short_link_spec.rb b/spec/models/short_link_spec.rb index 796726c40..035a450a8 100644 --- a/spec/models/short_link_spec.rb +++ b/spec/models/short_link_spec.rb @@ -1,58 +1,58 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ShortLink, type: :model do - describe '#valid?' do + describe "#valid?" do subject { build :short_link } - it 'accepts well-formed shortlink' do + it "accepts well-formed shortlink" do subject.should be_valid end - it 'rejects without link' do + it "rejects without link" do subject.link = nil subject.should_not be_valid end - it 'rejects without target' do + it "rejects without target" do subject.target = nil subject.should_not be_valid end - it 'rejects duplicate link' do + it "rejects duplicate link" do subject.save! other = subject.dup - other.target = 'http://other.target.com/' + other.target = "http://other.target.com/" other.should_not be_valid end - it 'rejects invalid url' do - subject.target = 'notarealurl' + it "rejects invalid url" do + subject.target = "notarealurl" subject.should_not be_valid - subject.target = 'https://invalid' + subject.target = "https://invalid" subject.should_not be_valid end - it 'rejects invalid link' do - subject.link = 'imnot12313valid!' + it "rejects invalid link" do + subject.link = "imnot12313valid!" subject.should_not be_valid end - it 'rejects link that collides with app routes' do - subject.link = 'assets' + it "rejects link that collides with app routes" do + subject.link = "assets" subject.should_not be_valid end end - describe '#target=' do - it 'tacks on http when scheme is missing' do - build(:short_link, target: 'google.com'). - target.should == 'http://google.com' + describe "#target=" do + it "tacks on http when scheme is missing" do + build(:short_link, target: "google.com") + .target.should == "http://google.com" end - it 'does not mess with existing scheme' do - build(:short_link, target: 'gopher://google.com'). - target.should == 'gopher://google.com' + it "does not mess with existing scheme" do + build(:short_link, target: "gopher://google.com") + .target.should == "gopher://google.com" end end end diff --git a/spec/models/tool_renting_spec.rb b/spec/models/tool_renting_spec.rb index 1722c3742..3e4f22836 100644 --- a/spec/models/tool_renting_spec.rb +++ b/spec/models/tool_renting_spec.rb @@ -1,21 +1,21 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ToolRenting, type: :model do describe :Validations do - it 'check presence user_id' do + it "check presence user_id" do ToolRenting.new.should validate_presence_of(:user_id) end - it 'check presence tool' do + it "check presence tool" do ToolRenting.new.should validate_presence_of(:tool) end - it 'check presence return_date' do + it "check presence return_date" do ToolRenting.new.should validate_presence_of(:return_date) end - context 'free tools' do - it 'valid with free tool' do + context "free tools" do + it "valid with free tool" do tool = create(:tool, total: 1) rent = create(:tool_renting, user_id: 1, tool_id: tool.id) @@ -23,7 +23,7 @@ rent.valid?.should eq(true) end - it 'invalid without free tool' do + it "invalid without free tool" do tool = create(:tool, total: 1) create(:tool_renting, user_id: 1, tool_id: tool.id) @@ -32,7 +32,7 @@ rent = build(:tool_renting, tool_id: tool.id) rent.valid?.should eq(false) - rent.errors[:returned].should include(I18n.t('model.tool_renting.no_more_tools')) + rent.errors[:returned].should include(I18n.t("model.tool_renting.no_more_tools")) end end end diff --git a/spec/models/tool_spec.rb b/spec/models/tool_spec.rb index 04b21f461..f6b6df24e 100644 --- a/spec/models/tool_spec.rb +++ b/spec/models/tool_spec.rb @@ -1,36 +1,35 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe Tool, type: :model do describe :Validations do - it 'check presence title' do + it "check presence title" do tool = build(:tool) tool.should validate_presence_of(:title) end - it 'check presence total' do + it "check presence total" do tool = build(:tool) tool.should validate_presence_of(:total) end - it 'check total greater than 0' do + it "check total greater than 0" do tool = build(:tool) tool.should validate_numericality_of(:total) tool.should_not allow_value(-1).for(:total) tool.should allow_value(1).for(:total) end - - it 'check total not under rented tools' do + it "check total not under rented tools" do tool = create(:tool, total: 1) create(:tool_renting, tool: tool) tool.total = 0 tool.valid?.should eq(false) - tool.errors[:total].should include(I18n.t('model.tool.not_allowed_change_total')) + tool.errors[:total].should include(I18n.t("model.tool.not_allowed_change_total")) end end - describe 'method free' do - it 'check renting' do + describe "method free" do + it "check renting" do tool = create(:tool) (1..tool.total).each do |i| create(:tool_renting, tool: tool) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5fe467f5b..fdad002fe 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,78 +1,78 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe User, type: :model do - it 'has a valid factory' do + it "has a valid factory" do (build_stubbed(:user)).should be_valid end let(:user) { build_stubbed(:user) } - describe 'validations' do + describe "validations" do new_user = User.new it { new_user.should validate_presence_of(:email) } it { new_user.should validate_presence_of(:firstname) } it { new_user.should validate_presence_of(:lastname) } end - describe 'name validation' do - it 'accepts names with at least two characters' do - user.lastname = 'Pi' + describe "name validation" do + it "accepts names with at least two characters" do + user.lastname = "Pi" user.should be_valid end - it 'does not accept names with less than 2 characters' do - user.lastname = 'F' + it "does not accept names with less than 2 characters" do + user.lastname = "F" user.should be_invalid end - it 'accepts unicode names with accents' do - user.lastname = 'Ναβροζίδης' + it "accepts unicode names with accents" do + user.lastname = "Ναβροζίδης" user.should be_valid end - it 'accepts spaces and hyphens' do - user.lastname = 'Älg-Älg Älg' + it "accepts spaces and hyphens" do + user.lastname = "Älg-Älg Älg" user.should be_valid end - it 'does not accept numbers' do - user.lastname = 'Nisse37' + it "does not accept numbers" do + user.lastname = "Nisse37" user.should be_invalid end - it 'does not accept special characters' do - user.lastname = 'Ka$$ör' + it "does not accept special characters" do + user.lastname = "Ka$$ör" user.should be_invalid end end - describe 'public instance methods' do - context 'printing' do - it 'print_id' do + describe "public instance methods" do + context "printing" do + it "print_id" do user.print_id.should eq(%(#{user.firstname} #{user.lastname} - #{user.id})) end - it 'print_email' do + it "print_email" do user.print_email.should eq(%(#{user.firstname} #{user.lastname} <#{user.email}>)) end - it 'to_s' do + it "to_s" do user.to_s.should eq(%(#{user.firstname} #{user.lastname})) end - it 'program_year' do + it "program_year" do user = User.new(program: User::PHYSICS, start_year: 1996) - user.program_year.should eq('F96') + user.program_year.should eq("F96") end - it 'print_program' do + it "print_program" do user = User.new(program: User::PHYSICS, start_year: 1996, - firstname: 'Hilbert', lastname: 'Älg') - user.print_program.should eq('Hilbert Älg - F96') + firstname: "Hilbert", lastname: "Älg") + user.print_program.should eq("Hilbert Älg - F96") end end - it 'checks if summerchild' do + it "checks if summerchild" do user = build_stubbed(:user, member_at: User.summer + 10.days) user.summerchild?.should be_truthy diff --git a/spec/query_objects/cafe_queries_spec.rb b/spec/query_objects/cafe_queries_spec.rb index e472eb4ca..9bb1b8ef0 100644 --- a/spec/query_objects/cafe_queries_spec.rb +++ b/spec/query_objects/cafe_queries_spec.rb @@ -1,9 +1,9 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeQueries do include ActiveSupport::Testing::TimeHelpers before do - travel_to Time.zone.local(2014, 03, 25, 8) + travel_to Time.zone.local(2014, 0o3, 25, 8) # Travel back to the spring of 2014. # It is the end of the third study period end @@ -28,26 +28,26 @@ def shift(pass: 1, lp: 3, start: 7.days.ago) end describe :working_users do - it 'should give all working users' do - first_user = create(:user, firstname: 'First') + it "should give all working users" do + first_user = create(:user, firstname: "First") shift_with_worker(user: first_user, pass: 1) - second_user = create(:user, firstname: 'Second') + second_user = create(:user, firstname: "Second") shift_with_worker(user: second_user, pass: 2) - create(:user, firstname: 'Third') + create(:user, firstname: "Third") CafeQueries.working_users(3, Time.zone.now).map(&:firstname).should - eq(['First', 'Second']) + eq(["First", "Second"]) end end describe :cafe_workers do - it 'should give all working users' do - first_user = create(:user, firstname: 'First') + it "should give all working users" do + first_user = create(:user, firstname: "First") first_shift = shift_with_worker(user: first_user, pass: 1) - second_user = create(:user, firstname: 'Second') + second_user = create(:user, firstname: "Second") second_shift = shift_with_worker(user: second_user, pass: 2) workers = CafeQueries.cafe_workers(3, Time.zone.now) @@ -57,11 +57,11 @@ def shift(pass: 1, lp: 3, start: 7.days.ago) end describe :highscore do - it 'gives the highscore of working users' do - first_user = create(:user, firstname: 'First') + it "gives the highscore of working users" do + first_user = create(:user, firstname: "First") shift_with_worker(user: first_user, pass: 1) - second_user = create(:user, firstname: 'Second') + second_user = create(:user, firstname: "Second") shift_with_worker(user: second_user, pass: 1) shift_with_worker(user: second_user, pass: 2) @@ -78,11 +78,11 @@ def shift(pass: 1, lp: 3, start: 7.days.ago) first_shift = CafeShift.new(start: 7.days.ago, lp: 3, pass: 1, lv: 6) first_shift.save! - first_user = create(:user, firstname: 'First') + first_user = create(:user, firstname: "First") first_shift.build_cafe_worker(user: first_user).save! end - it 'should give free shift' do + it "should give free shift" do free_shift = shift(pass: 1, start: 2.days.from_now) shift_with_worker(pass: 2, start: 2.days.from_now, user: create(:user)) @@ -92,7 +92,7 @@ def shift(pass: 1, lp: 3, start: 7.days.ago) free.count.should eq(1) end - it 'should not contain old free shift' do + it "should not contain old free shift" do old_free_shift = shift(start: 2.days.ago) free = CafeQueries.free_shifts(3, Time.zone.now) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9adc70a6e..10b6d0f01 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,17 +1,17 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) +ENV["RAILS_ENV"] ||= "test" +require File.expand_path("../../config/environment", __FILE__) # Prevent database truncation if the environment is production -abort('The Rails environment is running in production mode!') if Rails.env.production? -require 'spec_helper' -require 'rspec/rails' +abort("The Rails environment is running in production mode!") if Rails.env.production? +require "spec_helper" +require "rspec/rails" # Add additional requires below this line. Rails is not loaded until this point! -Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } # Do preferebly add it to 'spec/support/*' -require 'shoulda/matchers' -require 'rspec/example_steps' -require 'devise' +require "shoulda/matchers" +require "rspec/example_steps" +require "devise" ActiveRecord::Migration.maintain_test_schema! diff --git a/spec/requests/api/authorization_spec.rb b/spec/requests/api/authorization_spec.rb index 297ddce4d..4620d6374 100644 --- a/spec/requests/api/authorization_spec.rb +++ b/spec/requests/api/authorization_spec.rb @@ -1,71 +1,71 @@ -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Authentication', type: :request do - describe 'POST /auth (Sign Up process)' do - it 'valid parameters' do +RSpec.describe "Authentication", type: :request do + describe "POST /auth (Sign Up process)" do + it "valid parameters" do lambda do - post api_user_registration_path(firstname: 'Jakob', - lastname: 'Navrozidis', - email: 'jakob@fsektionen.se', - password: 'godtyckligt', - password_confirmation: 'godtyckligt') + post api_user_registration_path(firstname: "Jakob", + lastname: "Navrozidis", + email: "jakob@fsektionen.se", + password: "godtyckligt", + password_confirmation: "godtyckligt") end.should change(User, :count).by(1) response.should have_http_status(200) end - it 'invalid parameters' do + it "invalid parameters" do lambda do - post api_user_registration_path(firstname: 'Jakob', - email: 'jakob@fsektionen.se', - password: 'godtyckligt', - password_confirmation: 'godtyckligt') + post api_user_registration_path(firstname: "Jakob", + email: "jakob@fsektionen.se", + password: "godtyckligt", + password_confirmation: "godtyckligt") end.should change(User, :count).by(0) response.should have_http_status(422) end - it 'no password confirmation' do + it "no password confirmation" do lambda do - post api_user_registration_path(firstname: 'Jakob', - lastname: 'Navrozidis', - email: 'jakob@fsektionen.se', - password: 'godtyckligt') + post api_user_registration_path(firstname: "Jakob", + lastname: "Navrozidis", + email: "jakob@fsektionen.se", + password: "godtyckligt") end.should change(User, :count).by(0) response.should have_http_status(422) end end - describe 'POST /auth/sign_in (Sign In process)' do - it 'valid parameters' do + describe "POST /auth/sign_in (Sign In process)" do + it "valid parameters" do # Create a new user - post api_user_registration_path(firstname: 'Jakob', - lastname: 'Navrozidis', - email: 'jakob@fsektionen.se', - password: 'godtyckligt', - password_confirmation: 'godtyckligt') + post api_user_registration_path(firstname: "Jakob", + lastname: "Navrozidis", + email: "jakob@fsektionen.se", + password: "godtyckligt", + password_confirmation: "godtyckligt") # Mark email as confirmed User.last.update!(confirmed_at: Time.zone.now) # Sign In - post api_user_session_path(email: 'jakob@fsektionen.se', password: 'godtyckligt') + post api_user_session_path(email: "jakob@fsektionen.se", password: "godtyckligt") response.should be_success response.should have_http_status(200) end - it 'invalid parameters' do + it "invalid parameters" do # Create a new user - post api_user_registration_path(firstname: 'Jakob', - lastname: 'Navrozidis', - email: 'jakob@fsektionen.se', - password: 'godtyckligt', - password_confirmation: 'godtyckligt') + post api_user_registration_path(firstname: "Jakob", + lastname: "Navrozidis", + email: "jakob@fsektionen.se", + password: "godtyckligt", + password_confirmation: "godtyckligt") # Mark email as confirmed User.last.update!(confirmed_at: Time.zone.now) # Sign In - post api_user_session_path(email: 'jakob@fsektionen.se', password: 'ogodtyckligt') + post api_user_session_path(email: "jakob@fsektionen.se", password: "ogodtyckligt") response.should_not be_success response.should have_http_status(401) end diff --git a/spec/services/cafe_service_spec.rb b/spec/services/cafe_service_spec.rb index 76c1e8f7f..032280540 100644 --- a/spec/services/cafe_service_spec.rb +++ b/spec/services/cafe_service_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeService do describe :setup_week do @@ -55,11 +55,11 @@ end describe :setup do - it 'creates week' do + it "creates week" do cafe_shift = build(:cafe_shift, lv: 1) cafe_shift.pass = nil cafe_shift.lv_last = 3 - cafe_shift.setup_mode = 'week' + cafe_shift.setup_mode = "week" check = false lambda do @@ -69,10 +69,10 @@ check.should be_truthy end - it 'creates day' do + it "creates day" do cafe_shift = build(:cafe_shift, lv: 1) cafe_shift.pass = nil - cafe_shift.setup_mode = 'day' + cafe_shift.setup_mode = "day" check = false lambda do diff --git a/spec/services/calendar_service_spec.rb b/spec/services/calendar_service_spec.rb index e6e452238..626ba19a5 100644 --- a/spec/services/calendar_service_spec.rb +++ b/spec/services/calendar_service_spec.rb @@ -1,25 +1,25 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CalendarService do - describe 'set all_day' do - it 'sets date if all_day' do + describe "set all_day" do + it "sets date if all_day" do events = [] events << build_stubbed(:event, :timestamps, all_day: true, - title: 'Hela dagen', + title: "Hela dagen", starts_at: 1.day.from_now, ends_at: 3.days.from_now) events << build_stubbed(:event, :timestamps, all_day: false, - title: 'Inte hela dagen') + title: "Inte hela dagen") result = CalendarService.export(events) - result.to_ical.should include("DTSTART;VALUE=DATE:#{1.day.from_now.strftime('%Y%m%d')}") + result.to_ical.should include("DTSTART;VALUE=DATE:#{1.day.from_now.strftime("%Y%m%d")}") # Need to add one day to the end time - result.to_ical.should include("DTEND;VALUE=DATE:#{(3 + 1).day.from_now.strftime('%Y%m%d')}") + result.to_ical.should include("DTEND;VALUE=DATE:#{(3 + 1).day.from_now.strftime("%Y%m%d")}") end end - describe 'set_timezone' do - it 'sets the right timezone' do + describe "set_timezone" do + it "sets the right timezone" do events = [] events << build_stubbed(:event, :timestamps) events << build_stubbed(:event, :timestamps) @@ -28,16 +28,16 @@ result.to_ical.should include("TZID:#{Event::TZID}") end - it 'sets UTC for created and modified' do + it "sets UTC for created and modified" do event = build_stubbed(:event, :timestamps) ical = CalendarService.export([event]).to_ical - ical.should include("CREATED:#{event.created_at.utc.strftime('%Y%m%dT%H%M%SZ')}") - ical.should include("LAST-MODIFIED:#{event.created_at.utc.strftime('%Y%m%dT%H%M%SZ')}") + ical.should include("CREATED:#{event.created_at.utc.strftime("%Y%m%dT%H%M%SZ")}") + ical.should include("LAST-MODIFIED:#{event.created_at.utc.strftime("%Y%m%dT%H%M%SZ")}") end end - describe '#set_timezone' do - it 'sets TZInfo' do + describe "#set_timezone" do + it "sets TZInfo" do calendar = Icalendar::Calendar.new calendar.has_timezone?.should be_falsey @@ -47,27 +47,27 @@ end end - describe '#event' do - it 'sets title from locale' do + describe "#event" do + it "sets title from locale" do event = build_stubbed(:event, :timestamps, - title_sv: 'Svensk titel', title_en: 'English title', - description_sv: 'Svensk beskrivning', - description_en: 'English description') + title_sv: "Svensk titel", title_en: "English title", + description_sv: "Svensk beskrivning", + description_en: "English description") result = CalendarService.event(event) - en_result = CalendarService.event(event, locale: 'en') - result.summary.should eq('Svensk titel') - en_result.summary.should eq('English title') - result.description.should include('Svensk beskrivning') - en_result.description.should include('English description') + en_result = CalendarService.event(event, locale: "en") + result.summary.should eq("Svensk titel") + en_result.summary.should eq("English title") + result.description.should include("Svensk beskrivning") + en_result.description.should include("English description") end - it 'applies timezone to starts_at and ends_at' do + it "applies timezone to starts_at and ends_at" do starts_at = 1.hour.from_now ends_at = starts_at + 4.hours event = build_stubbed(:event, :timestamps, - starts_at: starts_at, - ends_at: ends_at) + starts_at: starts_at, + ends_at: ends_at) result = CalendarService.event(event) diff --git a/spec/services/election_service_spec.rb b/spec/services/election_service_spec.rb index 11f49a581..c2ad235d4 100644 --- a/spec/services/election_service_spec.rb +++ b/spec/services/election_service_spec.rb @@ -1,10 +1,10 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ElectionService do include ActiveJob::TestHelper - describe 'create_candidate' do - it 'creates a valid candidate' do + describe "create_candidate" do + it "creates a valid candidate" do election = create(:election, :before_general, :autumn) user = create(:user) the_post = create(:post, :autumn) @@ -15,7 +15,7 @@ end.should change(Candidate, :count).by(1) end - it 'sends mail' do + it "sends mail" do user = create(:user) candidate = build(:candidate, user: nil) @@ -25,7 +25,7 @@ end.should change(ActionMailer::Base.deliveries, :count).by(1) end - it 'returns false if candidate invalid' do + it "returns false if candidate invalid" do election = create(:election, :before_general, :autumn) user = create(:user) the_post = create(:post, :spring) @@ -37,15 +37,15 @@ end end - describe '#destroy_candidate' do - it 'destroys candidate if editable' do + describe "#destroy_candidate" do + it "destroys candidate if editable" do candidate = create(:candidate) candidate.stub(:editable?).and_return(true) ElectionService.destroy_candidate(candidate).should be_truthy end - it 'does not destroy candidate if not editable' do + it "does not destroy candidate if not editable" do candidate = create(:candidate) candidate.stub(:editable?).and_return(false) @@ -53,8 +53,8 @@ end end - describe '#create_nomination' do - it 'valid parameters' do + describe "#create_nomination" do + it "valid parameters" do nomination = build(:nomination) lambda do @@ -62,7 +62,7 @@ end.should change(Nomination, :count).by(1) end - it 'should send email' do + it "should send email" do nomination = build(:nomination) lambda do @@ -71,7 +71,7 @@ end.should change(ActionMailer::Base.deliveries, :count).by(1) end - it 'invalid_parameters' do + it "invalid_parameters" do nomination = build(:nomination, email: nil) lambda do diff --git a/spec/services/page_service_spec.rb b/spec/services/page_service_spec.rb index b8f6a93d4..ce387eac1 100644 --- a/spec/services/page_service_spec.rb +++ b/spec/services/page_service_spec.rb @@ -1,10 +1,10 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PageService do - describe 'upload images' do - it 'valid attributes' do + describe "upload images" do + it "valid attributes" do page = create(:page) - page.image_upload = [Rack::Test::UploadedFile.new(File.open('app/assets/images/hilbert.jpg'))] + page.image_upload = [Rack::Test::UploadedFile.new(File.open("app/assets/images/hilbert.jpg"))] lambda do PageService.upload_images(page) diff --git a/spec/services/post_user_service_spec.rb b/spec/services/post_user_service_spec.rb index bdfad4e97..d24c66f8e 100644 --- a/spec/services/post_user_service_spec.rb +++ b/spec/services/post_user_service_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe PostUserService do let(:post_user) { build(:post_user) } diff --git a/spec/services/rent_service_spec.rb b/spec/services/rent_service_spec.rb index 31b138364..b9270b33b 100644 --- a/spec/services/rent_service_spec.rb +++ b/spec/services/rent_service_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe RentService do describe :make_reservation do @@ -22,7 +22,7 @@ end describe :overbook do - it 'should let council overbook normal' do + it "should let council overbook normal" do user = create(:user) overbook = create(:rent, user: user) council_rent = build(:rent, :with_council, user: user) @@ -35,7 +35,7 @@ overbook.aktiv.should be_falsey end - it 'should not let normal overbook council' do + it "should not let normal overbook council" do user = create(:user) overbook = create(:rent, user: user) rent = build(:rent, user: user) @@ -48,7 +48,7 @@ overbook.aktiv.should be_truthy end - it 'should not let council overbook council' do + it "should not let council overbook council" do user = create(:user) overbook = create(:rent, :with_council, user: user) council_rent = build(:rent, :with_council, user: user) @@ -63,34 +63,34 @@ end describe :authorized_update do - it 'valid parameters' do + it "valid parameters" do user = create(:user) - rent = create(:rent, user: user, purpose: 'Nope') + rent = create(:rent, user: user, purpose: "Nope") - RentService.update({ purpose: 'A test', \ - d_from: 1.hours.from_now.strftime('%Y-%m-%d %H:%M'), \ - d_til: 10.hours.from_now.strftime('%Y-%m-%d %H:%M') }, \ - user, rent).should be_truthy + RentService.update({purpose: "A test", \ + d_from: 1.hours.from_now.strftime("%Y-%m-%d %H:%M"), \ + d_til: 10.hours.from_now.strftime("%Y-%m-%d %H:%M")}, \ + user, rent).should be_truthy rent.reload - rent.purpose.should eq('A test') + rent.purpose.should eq("A test") end - it 'invalid parameters' do + it "invalid parameters" do user = create(:user) - rent = create(:rent, purpose: 'Nope', d_from: 1.hours.from_now, d_til: 10.hours.from_now) + rent = create(:rent, purpose: "Nope", d_from: 1.hours.from_now, d_til: 10.hours.from_now) rent.owner?(user).should be_falsey - RentService.update({ purpose: 'A test', \ - d_from: 1.hours.from_now.strftime('%Y-%m-%d %H:%M'), \ - d_til: 10.hours.from_now.strftime('%Y-%m-%d %H:%M') }, \ - user, rent).should be_falsey - Rent.first.purpose.should eq('Nope') + RentService.update({purpose: "A test", \ + d_from: 1.hours.from_now.strftime("%Y-%m-%d %H:%M"), \ + d_til: 10.hours.from_now.strftime("%Y-%m-%d %H:%M")}, \ + user, rent).should be_falsey + Rent.first.purpose.should eq("Nope") end end describe :admin_reservation do - it 'valid parameters' do + it "valid parameters" do rent = build(:rent) lambda do @@ -98,7 +98,7 @@ end.should change(Rent, :count).by(1) end - it 'invalid parameters' do + it "invalid parameters" do rent = build(:rent, user: nil) lambda do @@ -108,13 +108,13 @@ end describe :administrate do - it 'valid parameters' do - rent = create(:rent, purpose: 'Nope') - RentService.administrate(rent, purpose: 'A test').should be_truthy - Rent.first.purpose.should eq('A test') + it "valid parameters" do + rent = create(:rent, purpose: "Nope") + RentService.administrate(rent, purpose: "A test").should be_truthy + Rent.first.purpose.should eq("A test") end - it 'invalid parameters' do + it "invalid parameters" do rent = create(:rent) RentService.administrate(rent, user: nil).should be_falsey end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 72df658fa..7bd8ee516 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,7 @@ end if config.files_to_run.one? - config.default_formatter = 'doc' + config.default_formatter = "doc" end # Need to be disabled to allow :should syntax diff --git a/spec/support/cancan_matchers.rb b/spec/support/cancan_matchers.rb index 756d54aca..a29528930 100644 --- a/spec/support/cancan_matchers.rb +++ b/spec/support/cancan_matchers.rb @@ -30,15 +30,15 @@ description do obj_name = @obj.class.name - obj_name = @obj.to_s.capitalize if [Class, Module, Symbol]. - include?(@obj.class) - "have abilities #{@expected_hash.keys.join(', ')} on #{obj_name}" + obj_name = @obj.to_s.capitalize if [Class, Module, Symbol] + .include?(@obj.class) + "have abilities #{@expected_hash.keys.join(", ")} on #{obj_name}" end failure_message do obj_name = @obj.class.name - obj_name = @obj.to_s.capitalize if [Class, Module, Symbol]. - include?(@obj.class) + obj_name = @obj.to_s.capitalize if [Class, Module, Symbol] + .include?(@obj.class) "expected user to have abilities: #{@expected_hash} for " \ "#{obj_name}, but got #{@actual_hash}" end @@ -50,8 +50,8 @@ match do |ability| verify_ability_type(ability) if actions.is_a?(Hash) - fail ArgumentError, 'You cannot pass a hash to not_have_abilities. ' \ - 'Use have_abilities instead.' + fail ArgumentError, "You cannot pass a hash to not_have_abilities. " \ + "Use have_abilities instead." end @expected_hash = build_expected_hash(actions, default_expectation: false) @obj = obj @@ -64,17 +64,19 @@ description do obj_name = @obj.class.name - obj_name = @obj.to_s.capitalize if [Class, Module, Symbol]. - include?(@obj.class) - "not have abilities #{@expected_hash.keys.join(', ')} " \ - "on #{obj_name}" if @expected_hash.present? + obj_name = @obj.to_s.capitalize if [Class, Module, Symbol] + .include?(@obj.class) + if @expected_hash.present? + "not have abilities #{@expected_hash.keys.join(", ")} " \ + "on #{obj_name}" + end end failure_message do obj_name = @obj.class.name - obj_name = @obj.to_s.capitalize if [Class, Module, Symbol]. - include?(@obj.class) - "expected user NOT to have abilities #{@expected_hash.keys.join(', ')} " \ + obj_name = @obj.to_s.capitalize if [Class, Module, Symbol] + .include?(@obj.class) + "expected user NOT to have abilities #{@expected_hash.keys.join(", ")} " \ "for #{obj_name}, but got #{@actual_hash}" end end @@ -89,14 +91,14 @@ def build_expected_hash(actions, default_expectation:) actions.each { |action| expected_hash[action] = default_expectation } elsif actions.is_a?(Symbol) # Build a hash if it's just a symbol. - expected_hash = { actions => default_expectation } + expected_hash = {actions => default_expectation} end expected_hash end def verify_ability_type(ability) return if ability.class.ancestors.include?(CanCan::Ability) - fail TypeError, 'subject must mixin CanCan::Ability, got a ' \ + fail TypeError, "subject must mixin CanCan::Ability, got a " \ "#{ability.class.name} class." end end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 4d8cdaae5..9bc6a14bf 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,6 +1,6 @@ -require 'capybara/rspec' -require 'capybara/rails' -require 'capybara/poltergeist' +require "capybara/rspec" +require "capybara/rails" +require "capybara/poltergeist" Capybara.javascript_driver = :poltergeist Capybara.add_selector(:linkhref) do diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 43edcc5bc..899f812a8 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,4 +1,4 @@ -require 'database_cleaner' +require "database_cleaner" RSpec.configure do |config| # Cleans out database before each test suite is run diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb index a0893301a..e296c7212 100644 --- a/spec/support/factory_girl.rb +++ b/spec/support/factory_girl.rb @@ -1,4 +1,4 @@ -require 'factory_bot' +require "factory_bot" RSpec.configure do |config| config.include FactoryBot::Syntax::Methods end diff --git a/spec/support/feature_macros.rb b/spec/support/feature_macros.rb index 4c086410b..10e393004 100644 --- a/spec/support/feature_macros.rb +++ b/spec/support/feature_macros.rb @@ -1,5 +1,5 @@ module FeatureMacros - def sign_in_as(user, path: '/') + def sign_in_as(user, path: "/") login_as(user, scope: :user) visit(path) end diff --git a/spec/support/shared_context/rake.rb b/spec/support/shared_context/rake.rb index 4989d2661..15c45fae5 100644 --- a/spec/support/shared_context/rake.rb +++ b/spec/support/shared_context/rake.rb @@ -1,13 +1,13 @@ -require 'rake' +require "rake" -RSpec.shared_examples 'rake' do - let(:rake) { Rake::Application.new } +RSpec.shared_examples "rake" do + let(:rake) { Rake::Application.new } let(:task_name) { self.class.top_level_description } let(:task_path) { "lib/tasks/#{task_name.split(":").first}" } - subject { rake[task_name] } + subject { rake[task_name] } def loaded_files_excluding_current_rake_file - $".reject {|file| file == Rails.root.join("#{task_path}.rake").to_s } + $".reject { |file| file == Rails.root.join("#{task_path}.rake").to_s } end before do diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 83ffaeea1..a93c43bf9 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -1,8 +1,8 @@ -require 'simplecov' +require "simplecov" # save to CircleCI's artifacts directory if we're on CircleCI -if ENV['CIRCLE_ARTIFACTS'] - dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage') +if ENV["CIRCLE_ARTIFACTS"] + dir = File.join(ENV["CIRCLE_ARTIFACTS"], "coverage") SimpleCov.coverage_dir(dir) end SimpleCov.start diff --git a/spec/uploaders/document_uploader_spec.rb b/spec/uploaders/document_uploader_spec.rb index 4680d7937..825ab7230 100644 --- a/spec/uploaders/document_uploader_spec.rb +++ b/spec/uploaders/document_uploader_spec.rb @@ -1,5 +1,5 @@ -require 'rails_helper' -require 'carrierwave/test/matchers' +require "rails_helper" +require "carrierwave/test/matchers" RSpec.describe DocumentUploader do include CarrierWave::Test::Matchers @@ -9,7 +9,7 @@ before do DocumentUploader.enable_processing = true - File.open('spec/assets/pdf.pdf') do |f| + File.open("spec/assets/pdf.pdf") do |f| uploader.store!(f) end end @@ -19,9 +19,9 @@ uploader.remove! end - context 'uploaded document' do - it 'has the proper filename' do - uploader.filename.should eq('pdf.pdf') + context "uploaded document" do + it "has the proper filename" do + uploader.filename.should eq("pdf.pdf") end end end diff --git a/spec/uploaders/image_uploader_spec.rb b/spec/uploaders/image_uploader_spec.rb index 9cf9aa7f6..e015feb7b 100644 --- a/spec/uploaders/image_uploader_spec.rb +++ b/spec/uploaders/image_uploader_spec.rb @@ -1,5 +1,5 @@ -require 'rails_helper' -require 'carrierwave/test/matchers' +require "rails_helper" +require "carrierwave/test/matchers" RSpec.describe ImageUploader do include CarrierWave::Test::Matchers @@ -9,7 +9,7 @@ before do ImageUploader.enable_processing = true - File.open('spec/assets/image.jpg') do |f| + File.open("spec/assets/image.jpg") do |f| uploader.store!(f) end end @@ -19,14 +19,14 @@ uploader.remove! end - context 'the thumb version' do - it 'should scale down a landscape image to be exactly 350 by 350 pixels', pending: true do + context "the thumb version" do + it "should scale down a landscape image to be exactly 350 by 350 pixels", pending: true do uploader.thumb.should have_dimensions(350, 350) end end - context 'the small version' do - it 'should scale down a landscape image to fit within 1680 by 10000 pixels', pending: true do + context "the small version" do + it "should scale down a landscape image to fit within 1680 by 10000 pixels", pending: true do uploader.large.should be_no_larger_than(1680, 10000) end end diff --git a/spec/validators/contact_message_validator_spec.rb b/spec/validators/contact_message_validator_spec.rb index 99e9a46cb..888dddcdd 100644 --- a/spec/validators/contact_message_validator_spec.rb +++ b/spec/validators/contact_message_validator_spec.rb @@ -1,33 +1,33 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe ContactMessageValidator do - it 'valid params' do - message = build(:contact_message, name: 'David', - email: 'david@google.com') + it "valid params" do + message = build(:contact_message, name: "David", + email: "david@google.com") message.validate!.should be_truthy - message.name.should eq('David') + message.name.should eq("David") end - it 'invalid email' do - message = build(:contact_message, name: 'David', - email: 'david@') + it "invalid email" do + message = build(:contact_message, name: "David", + email: "david@") message.validate!.should be_falsey message.errors[:email].present?.should be_truthy end - it 'blank name' do - message = build(:contact_message, name: '', - email: 'david@google.se') + it "blank name" do + message = build(:contact_message, name: "", + email: "david@google.se") message.validate!.should be_falsey message.errors[:name].present?.should be_truthy end - it 'blank email' do - message = build(:contact_message, name: 'David', - email: '') + it "blank email" do + message = build(:contact_message, name: "David", + email: "") message.validate!.should be_falsey message.errors[:email].present?.should be_truthy diff --git a/spec/view_objects/cafe_competition_spec.rb b/spec/view_objects/cafe_competition_spec.rb index d7d76707f..52f1d0cbc 100644 --- a/spec/view_objects/cafe_competition_spec.rb +++ b/spec/view_objects/cafe_competition_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe CafeCompetition do let(:first_user) { create(:user) } @@ -14,42 +14,42 @@ allow(CafeQueries).to receive(:cafe_workers) { CafeWorker.all } allow(CafeQueries).to receive(:working_users) { User.all } - @cafe_comp = CafeCompetition.new(lp: '3', year: Time.zone.now, amount: 10) + @cafe_comp = CafeCompetition.new(lp: "3", year: Time.zone.now, amount: 10) end describe :attributes do - it 'should give workers' do + it "should give workers" do @cafe_comp.cafe_workers.should eq(CafeWorker.all) end - it 'should give users' do + it "should give users" do @cafe_comp.users.should eq(User.all) end - it 'should give lp' do - @cafe_comp.lp.should eq('3') + it "should give lp" do + @cafe_comp.lp.should eq("3") end - it 'should give lps' do - @cafe_comp.lps.should eq(['1', '2', '4']) + it "should give lps" do + @cafe_comp.lps.should eq(["1", "2", "4"]) end - it 'should give year' do + it "should give year" do @cafe_comp.year.should eq(Time.zone.now.year) end - it 'should give years' do + it "should give years" do @cafe_comp.years.should eq((2015..Time.zone.now.year + 1).to_a - [Time.zone.now.year]) end end describe :methods do - it 'should give count of cafe workers' do + it "should give count of cafe workers" do @cafe_comp.count.should eq(CafeWorker.count) end - it 'should give user count' do + it "should give user count" do @cafe_comp.user_count.should eq(User.count) end end diff --git a/spec/view_objects/start_page_spec.rb b/spec/view_objects/start_page_spec.rb index 4808cd598..c2bd8e31c 100644 --- a/spec/view_objects/start_page_spec.rb +++ b/spec/view_objects/start_page_spec.rb @@ -1,34 +1,34 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe StartPage do - describe '#news' do - it 'lists five news' do - create(:news, title: 'First') - create(:news, title: 'Second', created_at: 2.minutes.ago) - create(:news, title: 'Third', created_at: 3.minutes.ago) - create(:news, title: 'Fourth', created_at: 4.minutes.ago) - create(:news, title: 'Fifth', created_at: 5.minutes.ago) - create(:news, title: 'Sixth', created_at: 6.minutes.ago) + describe "#news" do + it "lists five news" do + create(:news, title: "First") + create(:news, title: "Second", created_at: 2.minutes.ago) + create(:news, title: "Third", created_at: 3.minutes.ago) + create(:news, title: "Fourth", created_at: 4.minutes.ago) + create(:news, title: "Fifth", created_at: 5.minutes.ago) + create(:news, title: "Sixth", created_at: 6.minutes.ago) start = StartPage.new - start.news.map(&:title).should eq(['First', - 'Second', - 'Third', - 'Fourth', - 'Fifth']) + start.news.map(&:title).should eq(["First", + "Second", + "Third", + "Fourth", + "Fifth"]) end end - describe '#events' do - it 'lists events for the nearest week' do - create(:event, title: 'Second', starts_at: 3.days.from_now) - create(:event, title: 'First', starts_at: 2.days.from_now) - create(:event, title: 'Third', starts_at: 8.days.from_now) + describe "#events" do + it "lists events for the nearest week" do + create(:event, title: "Second", starts_at: 3.days.from_now) + create(:event, title: "First", starts_at: 2.days.from_now) + create(:event, title: "Third", starts_at: 8.days.from_now) start = StartPage.new - start.events.map(&:title).should eq(['First', 'Second']) + start.events.map(&:title).should eq(["First", "Second"]) end end end diff --git a/spec/view_objects/work_portal_spec.rb b/spec/view_objects/work_portal_spec.rb index a64ab9cdd..6b40057f7 100644 --- a/spec/view_objects/work_portal_spec.rb +++ b/spec/view_objects/work_portal_spec.rb @@ -1,74 +1,74 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe WorkPortal do - describe 'published' do - it 'gives only published' do - create(:work_post, publish: 5.days.from_now, title: 'First') - create(:work_post, publish: 5.days.ago, title: 'Second') - create(:work_post, publish: 5.days.ago, title: 'Third') + describe "published" do + it "gives only published" do + create(:work_post, publish: 5.days.from_now, title: "First") + create(:work_post, publish: 5.days.ago, title: "Second") + create(:work_post, publish: 5.days.ago, title: "Third") portal = WorkPortal.new(work_posts: WorkPost.published) - portal.work_posts.map(&:title).should eq(['Second', 'Third']) + portal.work_posts.map(&:title).should eq(["Second", "Third"]) end end - describe 'target_groups' do - it 'gives target_groups' do - create(:work_post, target_group: 'Teknisk fysik') - create(:work_post, target_group: 'Teknisk fysik') - create(:work_post, target_group: 'Teknisk matematik') + describe "target_groups" do + it "gives target_groups" do + create(:work_post, target_group: "Teknisk fysik") + create(:work_post, target_group: "Teknisk fysik") + create(:work_post, target_group: "Teknisk matematik") portal = WorkPortal.new(work_posts: WorkPost.published) - portal.target_groups.should eq(['Teknisk fysik', 'Teknisk matematik']) + portal.target_groups.should eq(["Teknisk fysik", "Teknisk matematik"]) end end - describe 'fields' do - it 'gives fields' do - create(:work_post, field: 'IT') - create(:work_post, field: 'IT') - create(:work_post, field: 'Ekonomi') + describe "fields" do + it "gives fields" do + create(:work_post, field: "IT") + create(:work_post, field: "IT") + create(:work_post, field: "Ekonomi") portal = WorkPortal.new(work_posts: WorkPost.published) - portal.fields.should eq(['Ekonomi', 'IT']) + portal.fields.should eq(["Ekonomi", "IT"]) end end - describe 'kinds' do - it 'gives kinds' do - create(:work_post, kind: 'Sommarjobb') - create(:work_post, kind: 'Sommarjobb') - create(:work_post, kind: 'Deltid') + describe "kinds" do + it "gives kinds" do + create(:work_post, kind: "Sommarjobb") + create(:work_post, kind: "Sommarjobb") + create(:work_post, kind: "Deltid") portal = WorkPortal.new(work_posts: WorkPost.published) - portal.kinds.should eq(['Deltid', 'Sommarjobb']) + portal.kinds.should eq(["Deltid", "Sommarjobb"]) end end - describe '#current_and_filter' do - it 'sets current and filters' do + describe "#current_and_filter" do + it "sets current and filters" do filter_params = {} - filter_params[:target] = 'Teknisk fysik' - filter_params[:field] = 'IT' - filter_params[:kind] = 'Deltid' + filter_params[:target] = "Teknisk fysik" + filter_params[:field] = "IT" + filter_params[:kind] = "Deltid" - create(:work_post, title: 'Hidden target', target_group: 'Teknisk matematik', - field: 'IT', kind: 'Deltid') - create(:work_post, title: 'Hidden field', target_group: 'Teknisk fysik', - field: 'Ekonomi', kind: 'Deltid') - create(:work_post, title: 'Hidden kind', target_group: 'Teknisk fysik', - field: 'IT', kind: 'Sommarjobb') - create(:work_post, title: 'Showing', target_group: 'Teknisk fysik', - field: 'IT', kind: 'Deltid') + create(:work_post, title: "Hidden target", target_group: "Teknisk matematik", + field: "IT", kind: "Deltid") + create(:work_post, title: "Hidden field", target_group: "Teknisk fysik", + field: "Ekonomi", kind: "Deltid") + create(:work_post, title: "Hidden kind", target_group: "Teknisk fysik", + field: "IT", kind: "Sommarjobb") + create(:work_post, title: "Showing", target_group: "Teknisk fysik", + field: "IT", kind: "Deltid") portal = WorkPortal.new(work_posts: WorkPost.published) - portal.work_posts.map(&:title).should eq(['Hidden target', - 'Hidden field', - 'Hidden kind', - 'Showing']) + portal.work_posts.map(&:title).should eq(["Hidden target", + "Hidden field", + "Hidden kind", + "Showing"]) portal.current_and_filter(filter_params) - portal.work_posts.map(&:title).should eq(['Showing']) + portal.work_posts.map(&:title).should eq(["Showing"]) end end end From a96092ad7e424efc8275bc1b973c45abc659f4b5 Mon Sep 17 00:00:00 2001 From: David Wessman Date: Sun, 17 Oct 2021 15:35:03 +0200 Subject: [PATCH 3/4] Setup overcommit and disable hound --- .hound.yml | 7 +++---- .overcommit.yml | 4 ++++ .rubocop.yml | 56 ------------------------------------------------- Gemfile | 1 + Gemfile.lock | 7 +++++++ 5 files changed, 15 insertions(+), 60 deletions(-) create mode 100644 .overcommit.yml delete mode 100644 .rubocop.yml diff --git a/.hound.yml b/.hound.yml index 9e537b95c..973ad515c 100644 --- a/.hound.yml +++ b/.hound.yml @@ -1,7 +1,6 @@ -ruby: - config_file: .rubocop.yml - exclude: - -"config/initializers/wice_grid_config.rb" +# Run as commit-hook instead +rubocop: + enabled: false java_script: config_file: .javascript-style.json exclude: diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 000000000..a1e04320c --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,4 @@ +PreCommit: + StandardRb: + enabled: true + command: ['bundle', 'exec', 'standardrb', '--fix'] # Invoke within Bundler context diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index e6d5bb0a8..000000000 --- a/.rubocop.yml +++ /dev/null @@ -1,56 +0,0 @@ -AllCops: - TargetRubyVersion: 2.5 - Exclude: - - 'db/schema.rb' - -Style/ClassAndModuleChildren: - Description: 'Checks style of children classes and modules.' - Enabled: true - EnforcedStyle: compact - -Style/EmptyMethod: - Description: 'Checks the formatting of empty method definitions.' - StyleGuide: '#no-single-line-methods' - Enabled: true - EnforcedStyle: expanded - -Style/Documentation: - Description: 'Document classes and non-namespace modules.' - Enabled: false - Exclude: - - 'spec/**/*' - - 'test/**/*' - -Style/GuardClause: - Description: 'Check for conditionals that can be replaced with guard clauses' - StyleGuide: '#no-nested-conditionals' - Enabled: false - -Metrics/AbcSize: - Description: >- - A calculated magnitude based on number of assignments, - branches, and conditions. - Reference: 'http://c2.com/cgi/wiki?AbcMetric' - Enabled: true - Max: 17.5 - -Metrics/MethodLength: - Description: 'Avoid methods longer than 10 lines of code.' - StyleGuide: '#short-methods' - Enabled: true - Max: 15 - -Metrics/LineLength: - Description: 'Limit lines to 80 characters.' - StyleGuide: '#80-character-limits' - Enabled: true - Max: 110 - -Style/SymbolArray: - EnforcedStyle: brackets - -Style/FrozenStringLiteralComment: - EnforcedStyle: never - -Style/AndOr: - EnforcedStyle: conditionals diff --git a/Gemfile b/Gemfile index 3476d3679..ff7859ae7 100644 --- a/Gemfile +++ b/Gemfile @@ -87,6 +87,7 @@ group :development do gem "bullet" gem "foreman" gem "onesky-rails" + gem "overcommit", "~> 0.58.0" gem "standard", "~> 1.4" gem "web-console" end diff --git a/Gemfile.lock b/Gemfile.lock index f29532438..d83cd2b1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,7 @@ GEM mimemagic (>= 0.3.0) case_transform (0.2) activesupport + childprocess (4.1.0) climate_control (0.2.0) cliver (0.3.2) codeclimate-test-reporter (1.0.8) @@ -215,6 +216,7 @@ GEM i18n (1.7.0) concurrent-ruby (~> 1.0) icalendar (2.4.1) + iniparse (1.5.0) jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -273,6 +275,10 @@ GEM onesky-ruby (1.0.1) rest-client (~> 1.8) orm_adapter (0.5.0) + overcommit (0.58.0) + childprocess (>= 0.6.3, < 5) + iniparse (~> 1.4) + rexml (~> 3.2) pagedown-bootstrap-rails (2.1.4) railties (> 3.1) paperclip (6.0.0) @@ -551,6 +557,7 @@ DEPENDENCIES momentjs-rails nokogiri (>= 1.7) onesky-rails + overcommit (~> 0.58.0) pagedown-bootstrap-rails paperclip (>= 5.2.0) paranoia From 6378def59e769dc950ff018391c52e841303ebac Mon Sep 17 00:00:00 2001 From: David Wessman Date: Sun, 17 Oct 2021 15:35:22 +0200 Subject: [PATCH 4/4] Fixes rubocop errors --- .../admin/mail_aliases_controller.rb | 2 +- app/controllers/adventures_controller.rb | 4 +- .../api/push_devices_controller.rb | 2 +- app/controllers/cafe_controller.rb | 2 +- app/helpers/notification_helper.rb | 1 - app/models/adventures/adventure_mission.rb | 2 +- app/models/cars/rent.rb | 2 +- app/models/constant.rb | 2 +- app/models/council.rb | 2 +- app/models/introduction.rb | 2 - app/models/messages/message_token.rb | 2 +- app/models/nomination.rb | 2 +- app/models/notifications/notification.rb | 4 +- app/models/user.rb | 2 +- app/serializers/api/cafe_shift_serializer.rb | 2 +- app/serializers/api/news_serializer.rb | 2 +- app/serializers/message_serializer.rb | 4 +- app/services/cafe_service.rb | 4 +- app/services/calendar_service.rb | 2 +- app/services/meeting_service.rb | 4 +- app/view_objects/cafe_competition.rb | 2 +- app/view_objects/election_view.rb | 2 +- .../election_mailer/candidate_email.html.erb | 2 +- config/environments/development.rb | 13 +- config/environments/production.rb | 8 +- config/environments/staging.rb | 8 +- config/environments/test.rb | 8 +- config/initializers/action_cable_config.rb | 3 +- config/initializers/carrierwave.rb | 2 + config/initializers/rpush.rb | 2 +- config/puma.rb | 6 +- config/sitemap.rb | 4 +- ...20160922115838_add_use_case_to_category.rb | 2 +- lib/tasks/permissions.rake | 6 - old/import_old_albums.rb | 172 ------------------ .../admin/event_signups_controller_spec.rb | 6 +- .../admin/short_links_controller_spec.rb | 2 +- spec/models/mail_alias_spec.rb | 12 +- spec/models/nomination_spec.rb | 2 +- 39 files changed, 65 insertions(+), 246 deletions(-) delete mode 100644 old/import_old_albums.rb diff --git a/app/controllers/admin/mail_aliases_controller.rb b/app/controllers/admin/mail_aliases_controller.rb index 12522f007..76c92781f 100644 --- a/app/controllers/admin/mail_aliases_controller.rb +++ b/app/controllers/admin/mail_aliases_controller.rb @@ -20,7 +20,7 @@ def update @aliases = MailAlias.insert_aliases! mail_alias_params[:username], mail_alias_params[:domain], mail_alias_params[:targets] || [] - rescue ActiveRecord::RecordInvalid => ex + rescue ActiveRecord::RecordInvalid render nothing: true, status: :unprocessable_entity return end diff --git a/app/controllers/adventures_controller.rb b/app/controllers/adventures_controller.rb index 6e4494a90..6631e08df 100644 --- a/app/controllers/adventures_controller.rb +++ b/app/controllers/adventures_controller.rb @@ -35,12 +35,12 @@ def set_mission_variables(adventure) @group = current_user.groups.regular.last @adventure_missions.each do |am| - @group_points_sum += am.points(@group) + @group_points_sum += am.points_per_group(@group) end @adventure_missions.map do |am| am.finished = am.finished?(@group) - am.points = am.points(@group) + am.points = am.points_per_group(@group) end @grid = initialize_grid(@adventure_missions, locale: :sv, order: "adventure_missions.index") diff --git a/app/controllers/api/push_devices_controller.rb b/app/controllers/api/push_devices_controller.rb index aa63ef122..f9f1d201a 100644 --- a/app/controllers/api/push_devices_controller.rb +++ b/app/controllers/api/push_devices_controller.rb @@ -14,7 +14,7 @@ def create def destroy @push_device = current_user.push_devices.find_by(token: params[:token]) - if @push_device && @push_device.destroy + if @push_device&.destroy render json: {}, status: :ok else render json: {errors: "Failed to destroy push device"}, status: 422 diff --git a/app/controllers/cafe_controller.rb b/app/controllers/cafe_controller.rb index e9474f61d..fee51cd7f 100644 --- a/app/controllers/cafe_controller.rb +++ b/app/controllers/cafe_controller.rb @@ -23,7 +23,7 @@ def competition def ladybug authorize_admin!(:ladybug, :cafe) - @date = if date = ladybug_date + @date = if (date = ladybug_date) Time.zone.parse(date) else Time.zone.now diff --git a/app/helpers/notification_helper.rb b/app/helpers/notification_helper.rb index 73fc1b724..8a6f03edb 100644 --- a/app/helpers/notification_helper.rb +++ b/app/helpers/notification_helper.rb @@ -4,7 +4,6 @@ def notification_context(notification, data) end def notification_icon(notification) - icon = "" if notification.notifyable_type == "EventUser" if notification.mode == "position" icon("fas", "check") diff --git a/app/models/adventures/adventure_mission.rb b/app/models/adventures/adventure_mission.rb index 09e5e98fe..73c18bc85 100644 --- a/app/models/adventures/adventure_mission.rb +++ b/app/models/adventures/adventure_mission.rb @@ -27,7 +27,7 @@ def accepted?(group) finished?(group) && adventure_mission_groups.by_group(group).first.pending == false end - def points(group) + def points_per_group(group) # Points only rewarded once mission is accepted if accepted?(group) adventure_mission_groups.by_group(group).first.points.to_i diff --git a/app/models/cars/rent.rb b/app/models/cars/rent.rb index 85a814fbf..d6e26cc14 100644 --- a/app/models/cars/rent.rb +++ b/app/models/cars/rent.rb @@ -62,7 +62,7 @@ def p_time # Requests route-helper to print url and path def p_url - Rails.application.routes.url_helpers.rent_url(id, host: PUBLIC_URL) + Rails.application.routes.url_helpers.rent_url(id, host: Rails.application.config.public_url) end def p_path diff --git a/app/models/constant.rb b/app/models/constant.rb index 0057862a1..43424272a 100644 --- a/app/models/constant.rb +++ b/app/models/constant.rb @@ -5,6 +5,6 @@ class Constant < ApplicationRecord def self.get(name) c = Constant.where(name: name).first - c && c.value || "" + c&.value.presence || "" end end diff --git a/app/models/council.rb b/app/models/council.rb index cddc9a453..c9afce00e 100644 --- a/app/models/council.rb +++ b/app/models/council.rb @@ -41,7 +41,7 @@ def to_param end def p_url - Rails.application.routes.url_helpers.council_url(id, host: PUBLIC_URL) + Rails.application.routes.url_helpers.council_url(id, host: Rails.application.config.public_url) end def p_path diff --git a/app/models/introduction.rb b/app/models/introduction.rb index 7524dee8d..3bdc8f88a 100644 --- a/app/models/introduction.rb +++ b/app/models/introduction.rb @@ -5,8 +5,6 @@ class Introduction < ApplicationRecord globalize_accessors(locales: [:en, :sv], attributes: [:title, :description]) - attr_reader :dates, :events_by_day, :dates_by_week - has_many :groups, dependent: :destroy has_many :group_users, through: :groups has_many :users, through: :groups diff --git a/app/models/messages/message_token.rb b/app/models/messages/message_token.rb index 2500a9661..5ecd2e31d 100644 --- a/app/models/messages/message_token.rb +++ b/app/models/messages/message_token.rb @@ -15,7 +15,7 @@ def self.add(user_id) expires = 30.seconds.from_now.to_i redis.expireat(KEY_BASE + token, expires) - data = {token: token, expires: expires} + {token: token, expires: expires} end # Finds the user_id for a token and removes the token diff --git a/app/models/nomination.rb b/app/models/nomination.rb index 6b451ba93..6cfb9814f 100644 --- a/app/models/nomination.rb +++ b/app/models/nomination.rb @@ -9,7 +9,7 @@ class Nomination < ApplicationRecord def candidate_url Rails.application.routes.url_helpers.new_candidate_url(post: post, - host: PUBLIC_URL) + host: Rails.application.config.public_url) end private diff --git a/app/models/notifications/notification.rb b/app/models/notifications/notification.rb index 391e46325..ad51c9aa7 100644 --- a/app/models/notifications/notification.rb +++ b/app/models/notifications/notification.rb @@ -41,11 +41,11 @@ def valid_notifyable end def allowed_class?(notifyable) - ALLOWED.keys.include?(notifyable.class.name) + ALLOWED.key?(notifyable.class.name) end def allowed_mode?(notifyable, mode) - ALLOWED[notifyable.class.name].keys.include?(mode) + ALLOWED[notifyable.class.name].key?(mode) end def update_counter_cache diff --git a/app/models/user.rb b/app/models/user.rb index 555e8991b..77eb8a301 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -88,7 +88,7 @@ def program_year str = "F" if program == PHYSICS str = "Pi" if program == MATH str = "N" if program == NANO - str += start_year.to_s.split("").last(2).join if start_year.present? + str += start_year.to_s.chars.last(2).join if start_year.present? str end diff --git a/app/serializers/api/cafe_shift_serializer.rb b/app/serializers/api/cafe_shift_serializer.rb index 163fc385f..77a350b91 100644 --- a/app/serializers/api/cafe_shift_serializer.rb +++ b/app/serializers/api/cafe_shift_serializer.rb @@ -17,7 +17,7 @@ def isme def councils councils = object.cafe_worker&.councils - council_map = { + { chosen: councils&.map { |c| [c.title, c.id] }.to_h, available: @instance_options[:current_user].councils.map { |c| [c.title, c.id] }.to_h } diff --git a/app/serializers/api/news_serializer.rb b/app/serializers/api/news_serializer.rb index 7ea577f3a..a410f42d9 100644 --- a/app/serializers/api/news_serializer.rb +++ b/app/serializers/api/news_serializer.rb @@ -9,7 +9,7 @@ def content end def image - PUBLIC_URL + object.image.large.url if object.image.present? + Rails.application.config.public_url + object.image.large.url if object.image.present? end class Api::UserSerializer < ActiveModel::Serializer diff --git a/app/serializers/message_serializer.rb b/app/serializers/message_serializer.rb index 767c7b857..4750b62be 100644 --- a/app/serializers/message_serializer.rb +++ b/app/serializers/message_serializer.rb @@ -15,7 +15,7 @@ def updated_at def image_url if object.image.present? # scope is group_id - "#{PUBLIC_URL}#{download_image_group_message_path(group_id: scope, id: object.id)}" + "#{Rails.application.config.public_url}#{download_image_group_message_path(group_id: scope, id: object.id)}" end end @@ -25,6 +25,6 @@ def image_url attribute(:avatar) def avatar - PUBLIC_URL + object.user.thumb_avatar if object.user.thumb_avatar + Rails.application.config.public_url + object.user.thumb_avatar if object.user.thumb_avatar end end diff --git a/app/services/cafe_service.rb b/app/services/cafe_service.rb index 70faf9a77..fc87e2372 100644 --- a/app/services/cafe_service.rb +++ b/app/services/cafe_service.rb @@ -95,9 +95,7 @@ def self.group_cafe_shifts(date_start, date_end, shifts) month = shift.start.month day_name = I18n.t("date.day_names")[week_day].capitalize month_name = I18n.t("date.month_names")[month].capitalize - unless h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].nil? - h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].push(Api::CafeShiftSerializer::Index.new(shift).as_json) - end + h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"]&.push(Api::CafeShiftSerializer::Index.new(shift).as_json) end end end diff --git a/app/services/calendar_service.rb b/app/services/calendar_service.rb index 0220eb7c5..fc09ea3d4 100644 --- a/app/services/calendar_service.rb +++ b/app/services/calendar_service.rb @@ -39,7 +39,7 @@ def self.event(resource, locale: "sv") ical_event.created = date_time(resource.created_at.utc, tzid: "UTC") ical_event.last_modified = date_time(resource.updated_at.utc, tzid: "UTC") ical_event.url = Rails.application.routes.url_helpers.event_url(resource.id, - host: PUBLIC_URL) + host: Rails.application.config.public_url) ical_event.ip_class = "PUBLIC" ical_event end diff --git a/app/services/meeting_service.rb b/app/services/meeting_service.rb index efbf5ef86..c37c9e7eb 100644 --- a/app/services/meeting_service.rb +++ b/app/services/meeting_service.rb @@ -23,9 +23,7 @@ def self.create_recurring_meeting(meeting_params, old_recurring = nil) begin RecurringMeeting.transaction do # If old recurring is specified destroy it - if !old_recurring.nil? - old_recurring.destroy! - end + old_recurring&.destroy! recurring_meeting = RecurringMeeting.new(every: every) recurring_meeting.save! meetings.each do |meeting| diff --git a/app/view_objects/cafe_competition.rb b/app/view_objects/cafe_competition.rb index 8e3cd9993..6aabdffb9 100644 --- a/app/view_objects/cafe_competition.rb +++ b/app/view_objects/cafe_competition.rb @@ -1,5 +1,5 @@ class CafeCompetition - attr_accessor :cafe_workers, :lp, :users, :lps, :year, :years, :amount + attr_accessor :cafe_workers, :lp, :users, :lps, :year, :amount def initialize(lp:, year:, amount:) @cafe_workers = CafeQueries.cafe_workers(lp, year) @lp = lp diff --git a/app/view_objects/election_view.rb b/app/view_objects/election_view.rb index e3788ac1c..46e18b51c 100644 --- a/app/view_objects/election_view.rb +++ b/app/view_objects/election_view.rb @@ -1,5 +1,5 @@ class ElectionView - attr_reader :election, :post_count + attr_reader :election attr_accessor :rest_grid, :grid, :candidate, :user, :nomination def initialize(election, candidate: nil) diff --git a/app/views/election_mailer/candidate_email.html.erb b/app/views/election_mailer/candidate_email.html.erb index ba745a1f4..d4c701037 100644 --- a/app/views/election_mailer/candidate_email.html.erb +++ b/app/views/election_mailer/candidate_email.html.erb @@ -20,7 +20,7 @@ date: l(@candidate.election.post_closing(@candidate.post)))) %>
-<%= link_to(t('.show_your_candidacies'), candidates_url(host: PUBLIC_URL), class: 'btn') %> +<%= link_to(t('.show_your_candidacies'), candidates_url(host: Rails.application.config.public_url), class: 'btn') %>

diff --git a/config/environments/development.rb b/config/environments/development.rb index 16d1cc857..8c2e8ffee 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,5 +1,6 @@ Fsek::Application.configure do - PUBLIC_URL = "http://localhost:3000".freeze + config.public_url = "http://localhost:3000".freeze + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on @@ -29,7 +30,7 @@ # Don't care if the mailer can't send. # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - config.action_mailer.default_url_options = {host: PUBLIC_URL} + config.action_mailer.default_url_options = {host: config.public_url} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = false @@ -39,7 +40,7 @@ config.action_mailer.smtp_settings = { address: "127.0.0.1", port: 1025, - domain: PUBLIC_URL, + domain: config.public_url, authentication: "plain", enable_starttls_auto: false } @@ -58,8 +59,8 @@ config.assets.digest = false # Assets for mailers - config.action_controller.asset_host = PUBLIC_URL - config.action_mailer.asset_host = PUBLIC_URL + config.action_controller.asset_host = config.public_url + config.action_mailer.asset_host = config.public_url config.action_view.raise_on_missing_translations = true @@ -75,7 +76,7 @@ Bullet.add_footer = true end - config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] + config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"] # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. diff --git a/config/environments/production.rb b/config/environments/production.rb index 33eb724f0..28ccebc4d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,5 @@ Rails.application.configure do - PUBLIC_URL = "https://fsektionen.se".freeze + config.public_url = "https://fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -73,9 +73,9 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :notify - config.action_mailer.asset_host = PUBLIC_URL + config.action_mailer.asset_host = config.public_url config.action_mailer.default charset: "utf-8" - config.action_mailer.default_url_options = {host: PUBLIC_URL} + config.action_mailer.default_url_options = {host: config.public_url} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true @@ -106,5 +106,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] + config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"] end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 7c16652f2..66a790e1b 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,5 +1,5 @@ Rails.application.configure do - PUBLIC_URL = "https://stage.fsektionen.se".freeze + config.public_url = "https://stage.fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. @@ -60,9 +60,9 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false config.active_support.deprecation = :notify - config.action_mailer.asset_host = PUBLIC_URL + config.action_mailer.asset_host = config.public_url config.action_mailer.default charset: "utf-8" - config.action_mailer.default_url_options = {host: PUBLIC_URL} + config.action_mailer.default_url_options = {host: config.public_url} config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true @@ -93,5 +93,5 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"] + config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"] end diff --git a/config/environments/test.rb b/config/environments/test.rb index 24a487c6c..1f0858557 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,5 @@ Fsek::Application.configure do - PUBLIC_URL = "http://localhost:3000".freeze + config.public_url = "https://fsektionen.se".freeze # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's @@ -38,9 +38,9 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - config.action_controller.asset_host = PUBLIC_URL - config.action_mailer.default_url_options = {host: PUBLIC_URL} - config.action_mailer.asset_host = PUBLIC_URL + config.action_controller.asset_host = config.public_url + config.action_mailer.default_url_options = {host: config.public_url} + config.action_mailer.asset_host = config.public_url config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/action_cable_config.rb b/config/initializers/action_cable_config.rb index b9d22ea2c..7c6bad9ae 100644 --- a/config/initializers/action_cable_config.rb +++ b/config/initializers/action_cable_config.rb @@ -3,7 +3,8 @@ module ActionCableConfig def self.[](key) unless @config template = ERB.new(File.read(Rails.root + "config/cable.yml")) - @config = YAML.load(template.result(binding))[Rails.env].symbolize_keys + # TODO: Use safe_load switched to ruby 2.6 + @config = YAML.load(template.result(binding))[Rails.env].symbolize_keys # rubocop:disable Security/YAMLLoad end @config[key] diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index e564b1216..512aab17e 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -4,9 +4,11 @@ config.enable_processing = false end + # rubocop:disable Lint/Void AttachedImageUploader DocumentUploader ImageUploader + # rubocop:enable Lint/Void CarrierWave::Uploader::Base.descendants.each do |klass| next if klass.anonymous? diff --git a/config/initializers/rpush.rb b/config/initializers/rpush.rb index 9724169d5..6b8e1ea77 100644 --- a/config/initializers/rpush.rb +++ b/config/initializers/rpush.rb @@ -20,7 +20,7 @@ # Path to log file. Relative to current directory unless absolute. config.log_file = "log/rpush.log" - config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO + config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO # rubocop:disable Lint/RequireParentheses # Define a custom logger. # config.logger = MyLogger.new diff --git a/config/puma.rb b/config/puma.rb index 33f5fae7a..943aeaf62 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,16 +4,16 @@ # 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. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) threads threads_count, 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 number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/sitemap.rb b/config/sitemap.rb index 48e8d74fc..ca14989b8 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -1,6 +1,6 @@ # Set the host name for URL creation -puts PUBLIC_URL -SitemapGenerator::Sitemap.default_host = PUBLIC_URL +puts Rails.application.config.public_url +SitemapGenerator::Sitemap.default_host = Rails.application.config.public_url SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/" SitemapGenerator::Sitemap.create do diff --git a/db/migrate/20160922115838_add_use_case_to_category.rb b/db/migrate/20160922115838_add_use_case_to_category.rb index 9b241af80..5edde9c3f 100644 --- a/db/migrate/20160922115838_add_use_case_to_category.rb +++ b/db/migrate/20160922115838_add_use_case_to_category.rb @@ -1,5 +1,5 @@ class AddUseCaseToCategory < ActiveRecord::Migration[5.0] def change - add_column(:categories, :use_case, :string, default: "general", null: :false, index: true) + add_column(:categories, :use_case, :string, default: "general", null: false, index: true) end end diff --git a/lib/tasks/permissions.rake b/lib/tasks/permissions.rake index f3af11679..a8488f88d 100644 --- a/lib/tasks/permissions.rake +++ b/lib/tasks/permissions.rake @@ -44,27 +44,21 @@ def eval_cancan_action(action) when "index" name = "list" cancan_action = "index" # let the cancan action be the actual method name - action_desc = I18n.t(:list) when "new", "create" name = "create and update" cancan_action = "create" - action_desc = I18n.t :create when "show" name = "view" cancan_action = "view" - action_desc = I18n.t :view when "edit", "update" name = "create and update" cancan_action = "update" - action_desc = I18n.t :update when "delete", "destroy" name = "delete" cancan_action = "destroy" - action_desc = I18n.t :destroy else name = action.to_s cancan_action = action.to_s - action_desc = "Other: " < cancan_action end [name, cancan_action] end diff --git a/old/import_old_albums.rb b/old/import_old_albums.rb deleted file mode 100644 index 95f84cded..000000000 --- a/old/import_old_albums.rb +++ /dev/null @@ -1,172 +0,0 @@ -### -### Mega album import script. -### This code was run on 31 Oct 2016 to import the old image albums. -### - -# Ensure no-one runs this by mistake -fail "No! Don't run this code. It's for reference only." - -# Pull in the rails app environment -require "./config/environment" - -# Establish connection to the database -conn = ActiveRecord::Base.connection - -# Load items and item attributes -# Note: we are loading from an external database, not the app DB. -items_and_attributes = conn.execute <<-SQL - select I.g_id, I.g_canContainChildren, I.g_summary, I.g_title, - A.g_parentSequence, F.g_pathComponent - from gallery.g2_Item I - join gallery.g2_ItemAttributesMap A on I.g_id = A.g_itemId - join gallery.g2_FileSystemEntity F on I.g_id = F.g_id - order by A.g_parentSequence asc - ; -SQL - -# Guess the root node -root_id = items_and_attributes.first[0] - -# Build tree structure -tree = {root_id => {title: "ROOT", children: {}}} - -items_and_attributes.each do |vals| - id, ccc, summary, title, parents, pathcomp = vals - - next if id == root_id - - # Find parent node - parent_ids = parents.split("/").map(&:to_i) - parent_ids.shift # remove root id - parent = tree[root_id] - - parent_ids.each do |i| - parent = parent[:children][i] - parent[:children] ||= {} - end - - # Add this node to the tree - parent[:children][id] = { - title: title, - summary: summary, - path: "#{parent[:path]}/#{pathcomp}" - } -end - -# Transform tree to flat table of albums - -@album_counter = 0 -@picture_counter = 0 - -def recursive_collect node, album_acc, pictures_acc = nil, name_acc = nil, year = nil, level = 0 - if level == 0 - elsif level == 1 - year = node[:title].to_i - elsif level >= 2 && node[:children] - name_acc = if name_acc - "#{name_acc} - #{node[:title]}" - else - node[:title] - end - - album = { - year: year, - title: name_acc, - summary: node[:summary], - pictures: [] - } - - album_acc << album - pictures_acc = album[:pictures] - @album_counter += 1 - end - - if node[:children] - node[:children].each do |k, v| - recursive_collect v, album_acc, pictures_acc, name_acc, year, level + 1 - end - else - pictures_acc << node - @picture_counter += 1 - end -end - -album_table = [] -recursive_collect tree[root_id], album_table - -puts sprintf("Found %d pictures in %d albums.", @picture_counter, @album_counter) - -# Insert all the found albums into the database. - -BASE = "/oldroot/var/www/gallery_data/albums" - -album_table.each do |ia| - # No empty albums - if ia[:pictures].empty? - next - end - - # Ensure we don't create any duplicates - result = conn.execute <<-SQL - select 1 from albums a, album_translations t - where a.id = t.album_id - and t.locale = 'sv' - and year(a.start_date) = #{ia[:year]} - and t.title = #{ActiveRecord::Base.sanitize(ia[:title])} - limit 1 - ; - SQL - - if result.any? - next - end - - description = ia[:summary].present? ? ia[:summary] : "_" - - a = Album.new title_sv: ia[:title], - title_en: ia[:title], - description_sv: description, - description_en: description, - start_date: Date.parse("#{ia[:year]}-01-02"), - end_date: Date.parse("#{ia[:year]}-12-30") - begin - a.save! - rescue ActiveRecord::RecordInvalid => ex - binding.pry - end - - puts "#{a.id}: #{a.title} (#{a.start_date.year})" - - ia[:pictures].each do |ip| - # If there are still any bad files in the tree at this point, they are ignored. - filename = File.join(BASE, ip[:path]) - if !File.exist?(filename) || File.directory?(filename) - next - end - - # A small attempt to reformat the "summary" to fit the new system. - photographer_name = ip[:summary] || "" - photograhper_name = photographer_name.gsub(/Fotografe?r?:? /, "") - - i = Image.new album_id: a.id, - file: File.new(File.join(BASE, ip[:path])), - photographer_name: photographer_name - begin - i.save! - rescue ActiveRecord::RecordInvalid => ex - binding.pry - end - - print "." - $stdout.flush - end - - # No idea if this is needed. - a.images_count = ia[:pictures].count - a.save! - - puts " done" -end - -# The cache doesn't work when we insert albums manually, so just nuke it. -Rails.cache.clear diff --git a/spec/controllers/admin/event_signups_controller_spec.rb b/spec/controllers/admin/event_signups_controller_spec.rb index 20408876b..f1fdbf0e6 100644 --- a/spec/controllers/admin/event_signups_controller_spec.rb +++ b/spec/controllers/admin/event_signups_controller_spec.rb @@ -33,14 +33,14 @@ fourth = new_event_user(event, EventSignup::MEMBER, group1) # Group 2 - eu1 = new_event_user(event, EventSignup::MEMBER, group2) + _eu1 = new_event_user(event, EventSignup::MEMBER, group2) eu4 = new_event_user(event, EventSignup::NOVICE, group2) eu7 = new_event_user(event, EventSignup::NOVICE, group2) # Group 3 - eu2 = new_event_user(event, EventSignup::MEMBER, group3) + _eu2 = new_event_user(event, EventSignup::MEMBER, group3) eu5 = new_event_user(event, EventSignup::CUSTOM, group3) - eu8 = new_event_user(event, EventSignup::MEMBER, group3) + _eu8 = new_event_user(event, EventSignup::MEMBER, group3) # Expected results attend = [first, second, third, fourth, eu4, eu7, eu5] diff --git a/spec/controllers/admin/short_links_controller_spec.rb b/spec/controllers/admin/short_links_controller_spec.rb index 8f5b4b054..9127227ce 100644 --- a/spec/controllers/admin/short_links_controller_spec.rb +++ b/spec/controllers/admin/short_links_controller_spec.rb @@ -28,7 +28,7 @@ end it "updates old shortlink for old link" do - old_sl = create :short_link + create :short_link new_sl = build :short_link, target: "newurl.com" post :create, params: {short_link: new_sl.attributes} diff --git a/spec/models/mail_alias_spec.rb b/spec/models/mail_alias_spec.rb index c94b2720a..060ff46fa 100644 --- a/spec/models/mail_alias_spec.rb +++ b/spec/models/mail_alias_spec.rb @@ -46,10 +46,10 @@ m2 = create(:mail_alias, username: "erik", domain: "fsektionen.se", target: "erikhenrikssn@gmail.com") - MailAlias.fulltext_search("johan").should == [m1] - MailAlias.fulltext_search("jo").should == [m1] - MailAlias.fulltext_search("johannes").should == [] - MailAlias.fulltext_search("erik").should == [m2] + MailAlias.fulltext_search("johan").should eq([m1]) + MailAlias.fulltext_search("jo").should eq([m1]) + MailAlias.fulltext_search("johannes").should eq([]) + MailAlias.fulltext_search("erik").should eq([m2]) end end @@ -57,7 +57,7 @@ it "can set empty target list (clear)" do c = create :mail_alias MailAlias.insert_aliases! c.username, c.domain, [] - MailAlias.count.should == 0 + MailAlias.count.should eq(0) end it "can create new alias" do @@ -70,7 +70,7 @@ it "touches existing records" do c = create :mail_alias, updated_at: 1.month.ago MailAlias.insert_aliases! c.username, c.domain, [c.target] - MailAlias.count.should == 1 + MailAlias.count.should eq(1) MailAlias.first.updated_at.to_date.should == Time.zone.now.to_date end end diff --git a/spec/models/nomination_spec.rb b/spec/models/nomination_spec.rb index 8ba7ce8f6..228f36e90 100644 --- a/spec/models/nomination_spec.rb +++ b/spec/models/nomination_spec.rb @@ -24,7 +24,7 @@ nomination = build_stubbed(:nomination) post = nomination.post - nomination.candidate_url.should eq(new_candidate_url(post: post.id, host: PUBLIC_URL)) + nomination.candidate_url.should eq(new_candidate_url(post: post.id, host: Rails.application.config.public_url)) end end end