diff --git a/Gemfile b/Gemfile index 831c5ffb..75055dad 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source 'https://rubygems.org' ruby '2.3.0' @@ -47,10 +48,10 @@ end group :development, :test do gem 'better_errors' gem 'binding_of_caller' + gem 'faker' gem 'pry-byebug' gem 'pry-rails' - gem 'rubocop' - gem 'tunemygc' - gem 'faker' + gem 'rubocop', '~> 0.46.0' # match code climate https://github.com/tootsuite/mastodon/issues/1758 gem 'timecop' + gem 'tunemygc' end diff --git a/Gemfile.lock b/Gemfile.lock index c1b98be7..2951c264 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -166,7 +166,6 @@ GEM cocaine (~> 0.5.5) mime-types mimemagic (~> 0.3.0) - parallel (1.12.0) parser (2.4.0.0) ast (~> 2.2) pg (0.21.0) @@ -241,14 +240,13 @@ GEM rspec-mocks (~> 3.6.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) - rubocop (0.49.1) - parallel (~> 1.10) - parser (>= 2.3.3.1, < 3.0) + rubocop (0.46.0) + parser (>= 2.3.1.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) + ruby-progressbar (1.9.0) sass (3.5.1) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -333,7 +331,7 @@ DEPENDENCIES rails (~> 5.0.0) redis (~> 3.3.3) rspec-rails - rubocop + rubocop (~> 0.46.0) sass-rails shoulda-matchers simplecov diff --git a/Rakefile b/Rakefile index 74eb42c7..451f68bb 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ #!/usr/bin/env rake # frozen_string_literal: true + # 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. diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index 51e3e936..9aec2305 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 5eb79fae..101a8dc1 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base identified_by :current_user diff --git a/app/channels/map_channel.rb b/app/channels/map_channel.rb index d8a2ddaf..421cc7b3 100644 --- a/app/channels/map_channel.rb +++ b/app/channels/map_channel.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MapChannel < ApplicationCable::Channel # Called when the consumer has successfully # become a subscriber of this channel. diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index 4ce85022..d4c56add 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + class AccessController < ApplicationController - before_action :require_user, only: [:access, :access_request, - :approve_access, :approve_access_post, - :deny_access, :deny_access_post, :request_access] - before_action :set_map, only: [:access, :access_request, - :approve_access, :approve_access_post, - :deny_access, :deny_access_post, :request_access] + before_action :require_user, only: %i(access access_request + approve_access approve_access_post + deny_access deny_access_post request_access) + before_action :set_map, only: %i(access access_request + approve_access approve_access_post + deny_access deny_access_post request_access) after_action :verify_authorized # GET maps/:id/request_access diff --git a/app/controllers/api/v1/deprecated_controller.rb b/app/controllers/api/v1/deprecated_controller.rb index 3269a1a8..5dd75f1b 100644 --- a/app/controllers/api/v1/deprecated_controller.rb +++ b/app/controllers/api/v1/deprecated_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V1 class DeprecatedController < ApplicationController diff --git a/app/controllers/api/v2/mappings_controller.rb b/app/controllers/api/v2/mappings_controller.rb index f00ce185..7f3eb9b1 100644 --- a/app/controllers/api/v2/mappings_controller.rb +++ b/app/controllers/api/v2/mappings_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class MappingsController < WithUpdatesController diff --git a/app/controllers/api/v2/maps_controller.rb b/app/controllers/api/v2/maps_controller.rb index 9cf093bc..9f542c47 100644 --- a/app/controllers/api/v2/maps_controller.rb +++ b/app/controllers/api/v2/maps_controller.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + module Api module V2 class MapsController < WithUpdatesController def searchable_columns - [:name, :desc] + %i(name desc) end def apply_filters(collection) diff --git a/app/controllers/api/v2/metacodes_controller.rb b/app/controllers/api/v2/metacodes_controller.rb index 71cd4a50..0ca0ea64 100644 --- a/app/controllers/api/v2/metacodes_controller.rb +++ b/app/controllers/api/v2/metacodes_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class MetacodesController < RestfulController diff --git a/app/controllers/api/v2/restful_controller.rb b/app/controllers/api/v2/restful_controller.rb index 417f7bc9..57f1b82d 100644 --- a/app/controllers/api/v2/restful_controller.rb +++ b/app/controllers/api/v2/restful_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class RestfulController < ActionController::Base @@ -7,7 +8,7 @@ module Api snorlax_used_rest! - before_action :load_resource, only: [:show, :update, :destroy] + before_action :load_resource, only: %i(show update destroy) after_action :verify_authorized def index @@ -91,7 +92,7 @@ module Api end def doorkeeper_user - return unless doorkeeper_token.present? + return if doorkeeper_token.blank? doorkeeper_render_error unless valid_doorkeeper_token? @doorkeeper_user ||= User.find(doorkeeper_token.resource_owner_id) end diff --git a/app/controllers/api/v2/sessions_controller.rb b/app/controllers/api/v2/sessions_controller.rb index 2aa93669..b9fa393a 100644 --- a/app/controllers/api/v2/sessions_controller.rb +++ b/app/controllers/api/v2/sessions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class SessionsController < ApplicationController diff --git a/app/controllers/api/v2/stars_controller.rb b/app/controllers/api/v2/stars_controller.rb index 8b62ee36..2a811eb5 100644 --- a/app/controllers/api/v2/stars_controller.rb +++ b/app/controllers/api/v2/stars_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class StarsController < RestfulController diff --git a/app/controllers/api/v2/synapses_controller.rb b/app/controllers/api/v2/synapses_controller.rb index e9ea22a1..1032186d 100644 --- a/app/controllers/api/v2/synapses_controller.rb +++ b/app/controllers/api/v2/synapses_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class SynapsesController < WithUpdatesController diff --git a/app/controllers/api/v2/tokens_controller.rb b/app/controllers/api/v2/tokens_controller.rb index 28dfc120..5283ac59 100644 --- a/app/controllers/api/v2/tokens_controller.rb +++ b/app/controllers/api/v2/tokens_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class TokensController < RestfulController diff --git a/app/controllers/api/v2/topics_controller.rb b/app/controllers/api/v2/topics_controller.rb index d27683d0..99233cfe 100644 --- a/app/controllers/api/v2/topics_controller.rb +++ b/app/controllers/api/v2/topics_controller.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + module Api module V2 class TopicsController < WithUpdatesController def searchable_columns - [:name, :desc, :link] + %i(name desc link) end end end diff --git a/app/controllers/api/v2/users_controller.rb b/app/controllers/api/v2/users_controller.rb index 092a95b5..144707f8 100644 --- a/app/controllers/api/v2/users_controller.rb +++ b/app/controllers/api/v2/users_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class UsersController < RestfulController diff --git a/app/controllers/api/v2/with_updates_controller.rb b/app/controllers/api/v2/with_updates_controller.rb index 888ccd11..a42a6dd0 100644 --- a/app/controllers/api/v2/with_updates_controller.rb +++ b/app/controllers/api/v2/with_updates_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class WithUpdatesController < RestfulController diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4bb5be10..d4e58224 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ApplicationController < ActionController::Base include ApplicationHelper include Pundit diff --git a/app/controllers/explore_controller.rb b/app/controllers/explore_controller.rb index 2e713213..5f828e1c 100644 --- a/app/controllers/explore_controller.rb +++ b/app/controllers/explore_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + class ExploreController < ApplicationController - before_action :require_authentication, only: [:mine, :shared, :starred] + before_action :require_authentication, only: %i(mine shared starred) before_action :authorize_explore after_action :verify_authorized after_action :verify_policy_scoped diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index d21d039f..db7a9bb3 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # bad code that should be checked over before entering one of the # nice files from the right side of this repo class HacksController < ApplicationController diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 38d9458c..42a52916 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MainController < ApplicationController before_action :authorize_main after_action :verify_authorized diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index f0ac37ed..2089379b 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + class MappingsController < ApplicationController - before_action :require_user, only: [:create, :update, :destroy] + before_action :require_user, only: %i(create update destroy) after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index c5b9870a..573f2441 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class MapsController < ApplicationController - before_action :require_user, only: [:create, :update, :destroy, :events, :follow, :unfollow] - before_action :set_map, only: [:show, :conversation, :update, :destroy, :contains, :events, :export, :follow, :unfollow, :unfollow_from_email] + before_action :require_user, only: %i(create update destroy events follow unfollow) + before_action :set_map, only: %i(show conversation update destroy contains events export follow unfollow unfollow_from_email) after_action :verify_authorized # GET maps/:id @@ -23,7 +24,7 @@ class MapsController < ApplicationController format.ttl { redirect_to action: :export, format: :ttl } end end - + # GET maps/:id/conversation def conversation respond_to do |format| @@ -140,7 +141,7 @@ class MapsController < ApplicationController # POST maps/:id/follow def follow - follow = FollowService.follow(@map, current_user, 'followed') + follow = FollowService.follow(@map, current_user, 'followed') respond_to do |format| format.json do @@ -155,7 +156,7 @@ class MapsController < ApplicationController # POST maps/:id/unfollow def unfollow - FollowService.unfollow(@map, current_user) + FollowService.unfollow(@map, current_user) respond_to do |format| format.json do diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index dd3544e9..27116ef2 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MessagesController < ApplicationController before_action :require_user, except: [:show] after_action :verify_authorized diff --git a/app/controllers/metacode_sets_controller.rb b/app/controllers/metacode_sets_controller.rb index 55b8e99a..956236b1 100644 --- a/app/controllers/metacode_sets_controller.rb +++ b/app/controllers/metacode_sets_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MetacodeSetsController < ApplicationController before_action :require_admin diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 00f92878..6f73785e 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class MetacodesController < ApplicationController - before_action :require_admin, except: [:index, :show] - before_action :set_metacode, only: [:edit, :update] + before_action :require_admin, except: %i(index show) + before_action :set_metacode, only: %i(edit update) # GET /metacodes # GET /metacodes.json diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 22a34452..3103b2aa 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + class NotificationsController < ApplicationController - before_action :set_receipts, only: [:index, :show, :mark_read, :mark_unread] - before_action :set_notification, only: [:show, :mark_read, :mark_unread] - before_action :set_receipt, only: [:show, :mark_read, :mark_unread] + before_action :set_receipts, only: %i(index show mark_read mark_unread) + before_action :set_notification, only: %i(show mark_read mark_unread) + before_action :set_receipt, only: %i(show mark_read mark_unread) def index @notifications = current_user.mailbox.notifications.page(params[:page]).per(25) @@ -27,14 +28,14 @@ class NotificationsController < ApplicationController respond_to do |format| format.html do case @notification.notification_code - when MAP_ACCESS_APPROVED, MAP_INVITE_TO_EDIT - redirect_to map_path(@notification.notified_object.map) - when TOPIC_ADDED_TO_MAP - redirect_to map_path(@notification.notified_object.map) - when TOPIC_CONNECTED_1 - redirect_to topic_path(@notification.notified_object.topic1) - when TOPIC_CONNECTED_2 - redirect_to topic_path(@notification.notified_object.topic2) + when MAP_ACCESS_APPROVED, MAP_INVITE_TO_EDIT + redirect_to map_path(@notification.notified_object.map) + when TOPIC_ADDED_TO_MAP + redirect_to map_path(@notification.notified_object.map) + when TOPIC_CONNECTED_1 + redirect_to topic_path(@notification.notified_object.topic1) + when TOPIC_CONNECTED_2 + redirect_to topic_path(@notification.notified_object.topic2) end end format.json do diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 8edf0324..234b3293 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class SearchController < ApplicationController include TopicsHelper include MapsHelper @@ -7,7 +8,7 @@ class SearchController < ApplicationController before_action :authorize_search after_action :verify_authorized - after_action :verify_policy_scoped, only: [:maps, :mappers, :synapses, :topics] + after_action :verify_policy_scoped, only: %i(maps mappers synapses topics) # get /search/topics?term=SOMETERM def topics @@ -140,13 +141,13 @@ class SearchController < ApplicationController topic1id = params[:topic1id] topic2id = params[:topic2id] - if term && !term.empty? + if term.present? @synapses = policy_scope(Synapse) .where('LOWER("desc") like ?', '%' + term.downcase.strip + '%') .order('"desc"') @synapses = @synapses.uniq(&:desc) - elsif topic1id && !topic1id.empty? + elsif topic1id.present? one = policy_scope(Synapse).where(topic1_id: topic1id, topic2_id: topic2id) two = policy_scope(Synapse).where(topic2_id: topic1id, topic1_id: topic2id) @synapses = one + two diff --git a/app/controllers/stars_controller.rb b/app/controllers/stars_controller.rb index ec4d1347..3292b6f0 100644 --- a/app/controllers/stars_controller.rb +++ b/app/controllers/stars_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class StarsController < ApplicationController before_action :require_user before_action :set_map diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index 62daf735..5f19224b 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + class SynapsesController < ApplicationController include TopicsHelper - before_action :require_user, only: [:create, :update, :destroy] + before_action :require_user, only: %i(create update destroy) after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index diff --git a/app/controllers/tokens_controller.rb b/app/controllers/tokens_controller.rb index b434d122..fd888b42 100644 --- a/app/controllers/tokens_controller.rb +++ b/app/controllers/tokens_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class TokensController < ApplicationController before_action :require_user, only: [:new] diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index c992bd14..b8a26593 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + class TopicsController < ApplicationController include TopicsHelper - before_action :require_user, only: [:create, :update, :destroy, :follow, :unfollow] - before_action :set_topic, only: [:show, :update, :relative_numbers, - :relatives, :network, :destroy, - :follow, :unfollow, :unfollow_from_email] + before_action :require_user, only: %i(create update destroy follow unfollow) + before_action :set_topic, only: %i(show update relative_numbers + relatives network destroy + follow unfollow unfollow_from_email) after_action :verify_authorized, except: :autocomplete_topic respond_to :html, :js, :json @@ -13,7 +14,7 @@ class TopicsController < ApplicationController # GET /topics/autocomplete_topic def autocomplete_topic term = params[:term] - if term && !term.empty? + if term.present? topics = policy_scope(Topic) .where('LOWER("name") like ?', term.downcase + '%') .order('"name"') diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index 8e8bccfc..6ea7704c 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Users class PasswordsController < Devise::PasswordsController protected diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 9332d422..f45c61c0 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Users class RegistrationsController < Devise::RegistrationsController before_action :configure_sign_up_params, only: [:create] @@ -29,7 +30,7 @@ module Users end def configure_sign_up_params - devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :joinedwithcode]) + devise_parameter_sanitizer.permit(:sign_up, keys: %i(name joinedwithcode)) end def configure_account_update_params diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 1c9c0a1e..12419b04 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Users class SessionsController < Devise::SessionsController after_action :store_location, only: [:new] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 79360403..fe4d63fc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true + class UsersController < ApplicationController - before_action :require_user, only: [:edit, :update, :updatemetacodes, :update_metacode_focus] + before_action :require_user, only: %i(edit update updatemetacodes update_metacode_focus) respond_to :html, :json @@ -100,7 +101,7 @@ class UsersController < ApplicationController @user.settings.metacode_focus = params[:value] @user.save respond_to do |format| - format.json { render json: { success: "success" }} + format.json { render json: { success: 'success' } } end end diff --git a/app/decorators/notification_decorator.rb b/app/decorators/notification_decorator.rb index cc503821..b699ba32 100644 --- a/app/decorators/notification_decorator.rb +++ b/app/decorators/notification_decorator.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class NotificationDecorator class << self def decorate(notification, receipt) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2bb1c925..a773ff5f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ApplicationHelper def invite_link "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 4fb2fe84..3e96a858 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ContentHelper def resource_name :user diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index 4b34effc..98048c95 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module DeviseHelper def devise_error_messages! resource.errors.to_a[0] diff --git a/app/helpers/in_metacode_sets_helper.rb b/app/helpers/in_metacode_sets_helper.rb index 0c45fd98..c0b4441e 100644 --- a/app/helpers/in_metacode_sets_helper.rb +++ b/app/helpers/in_metacode_sets_helper.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + module InMetacodeSetsHelper end diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb index 33378f43..b95f19dc 100644 --- a/app/helpers/main_helper.rb +++ b/app/helpers/main_helper.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + module MainHelper end diff --git a/app/helpers/map_mailer_helper.rb b/app/helpers/map_mailer_helper.rb index be95ea04..533d03fb 100644 --- a/app/helpers/map_mailer_helper.rb +++ b/app/helpers/map_mailer_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MapMailerHelper def access_approved_subject(map) map.name + ' - access approved' @@ -5,9 +7,9 @@ module MapMailerHelper def access_request_subject(map) map.name + ' - request to edit' - end + end def invite_to_edit_subject(map) map.name + ' - invited to edit' end -end \ No newline at end of file +end diff --git a/app/helpers/mapping_helper.rb b/app/helpers/mapping_helper.rb index 9dd903ca..e1b37c42 100644 --- a/app/helpers/mapping_helper.rb +++ b/app/helpers/mapping_helper.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + module MappingHelper end diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb index e1932766..b1efae4d 100644 --- a/app/helpers/maps_helper.rb +++ b/app/helpers/maps_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module MapsHelper # JSON autocomplete format for typeahead def autocomplete_map_array_json(maps) diff --git a/app/helpers/metacodes_helper.rb b/app/helpers/metacodes_helper.rb index bcdd8dd2..60da0bf7 100644 --- a/app/helpers/metacodes_helper.rb +++ b/app/helpers/metacodes_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module MetacodesHelper def metacodeset metacodes = current_user.settings.metacodes diff --git a/app/helpers/synapses_helper.rb b/app/helpers/synapses_helper.rb index def3b985..0fbaf925 100644 --- a/app/helpers/synapses_helper.rb +++ b/app/helpers/synapses_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module SynapsesHelper ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_synapse_generic_json(unique) diff --git a/app/helpers/topic_mailer_helper.rb b/app/helpers/topic_mailer_helper.rb index 81b87de0..51db3e47 100644 --- a/app/helpers/topic_mailer_helper.rb +++ b/app/helpers/topic_mailer_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module TopicMailerHelper def added_to_map_subject(topic, map) topic.name + ' was added to map ' + map.name @@ -7,4 +8,4 @@ module TopicMailerHelper def connected_subject(topic) 'new synapse to topic ' + topic.name end -end \ No newline at end of file +end diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 4fe9a597..2cc5e85d 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module TopicsHelper ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_array_json(topics) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 379cf20a..484c56d5 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module UsersHelper # build custom json autocomplete for typeahead def autocomplete_user_array_json(users) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index fdd2fa85..9a43f2b4 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'team@metamaps.cc' layout 'mailer' @@ -6,24 +7,24 @@ class ApplicationMailer < ActionMailer::Base class << self def mail_for_notification(notification) case notification.notification_code - when MAP_ACCESS_REQUEST - request = notification.notified_object - MapMailer.access_request(request) - when MAP_ACCESS_APPROVED - request = notification.notified_object - MapMailer.access_approved(request) - when MAP_INVITE_TO_EDIT - user_map = notification.notified_object - MapMailer.invite_to_edit(user_map) - when TOPIC_ADDED_TO_MAP - event = notification.notified_object - TopicMailer.added_to_map(event, notification.recipients[0]) - when TOPIC_CONNECTED_1 - synapse = notification.notified_object - TopicMailer.connected(synapse, synapse.topic1, notification.recipients[0]) - when TOPIC_CONNECTED_2 - synapse = notification.notified_object - TopicMailer.connected(synapse, synapse.topic2, notification.recipients[0]) + when MAP_ACCESS_REQUEST + request = notification.notified_object + MapMailer.access_request(request) + when MAP_ACCESS_APPROVED + request = notification.notified_object + MapMailer.access_approved(request) + when MAP_INVITE_TO_EDIT + user_map = notification.notified_object + MapMailer.invite_to_edit(user_map) + when TOPIC_ADDED_TO_MAP + event = notification.notified_object + TopicMailer.added_to_map(event, notification.recipients[0]) + when TOPIC_CONNECTED_1 + synapse = notification.notified_object + TopicMailer.connected(synapse, synapse.topic1, notification.recipients[0]) + when TOPIC_CONNECTED_2 + synapse = notification.notified_object + TopicMailer.connected(synapse, synapse.topic2, notification.recipients[0]) end end end diff --git a/app/mailers/map_activity_mailer.rb b/app/mailers/map_activity_mailer.rb index 977ece4f..1e30931b 100644 --- a/app/mailers/map_activity_mailer.rb +++ b/app/mailers/map_activity_mailer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MapActivityMailer < ApplicationMailer default from: 'team@metamaps.cc' diff --git a/app/mailers/map_mailer.rb b/app/mailers/map_mailer.rb index 6a207b23..8830d624 100644 --- a/app/mailers/map_mailer.rb +++ b/app/mailers/map_mailer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MapMailer < ApplicationMailer include MapMailerHelper default from: 'team@metamaps.cc' diff --git a/app/mailers/topic_mailer.rb b/app/mailers/topic_mailer.rb index 76464148..8f359b50 100644 --- a/app/mailers/topic_mailer.rb +++ b/app/mailers/topic_mailer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class TopicMailer < ApplicationMailer include TopicMailerHelper default from: 'team@metamaps.cc' diff --git a/app/models/access_request.rb b/app/models/access_request.rb index a26146ff..dad5bf41 100644 --- a/app/models/access_request.rb +++ b/app/models/access_request.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + class AccessRequest < ApplicationRecord belongs_to :user belongs_to :map has_one :user_map - + after_create :after_created_async def approve @@ -27,9 +28,9 @@ class AccessRequest < ApplicationRecord Mailboxer::Receipt.where(notification: notification).update_all(is_read: true) end end - + protected - + def after_created_async NotificationService.access_request(self) end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 767a072b..71fbba5b 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 9c65cec1..5dd49e8d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Attachment < ApplicationRecord belongs_to :attachable, polymorphic: true diff --git a/app/models/concerns/attachable.rb b/app/models/concerns/attachable.rb index 0a5a6b12..c4154bef 100644 --- a/app/models/concerns/attachable.rb +++ b/app/models/concerns/attachable.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Attachable extend ActiveSupport::Concern diff --git a/app/models/concerns/routing.rb b/app/models/concerns/routing.rb index ddbfad6f..c8474c93 100644 --- a/app/models/concerns/routing.rb +++ b/app/models/concerns/routing.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Routing extend ActiveSupport::Concern include Rails.application.routes.url_helpers diff --git a/app/models/event.rb b/app/models/event.rb index 4ea0b3bf..a463314e 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Event < ApplicationRecord KINDS = %w(user_present_on_map user_not_present_on_map conversation_started_on_map diff --git a/app/models/events/conversation_started_on_map.rb b/app/models/events/conversation_started_on_map.rb index 3d3df6ef..01e15ebe 100644 --- a/app/models/events/conversation_started_on_map.rb +++ b/app/models/events/conversation_started_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class ConversationStartedOnMap < Event # after_create :notify_users! diff --git a/app/models/events/synapse_added_to_map.rb b/app/models/events/synapse_added_to_map.rb index cb6f83b0..5287ee9e 100644 --- a/app/models/events/synapse_added_to_map.rb +++ b/app/models/events/synapse_added_to_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class SynapseAddedToMap < Event # after_create :notify_users! diff --git a/app/models/events/synapse_removed_from_map.rb b/app/models/events/synapse_removed_from_map.rb index 9833e635..07b9d34e 100644 --- a/app/models/events/synapse_removed_from_map.rb +++ b/app/models/events/synapse_removed_from_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class SynapseRemovedFromMap < Event # after_create :notify_users! diff --git a/app/models/events/synapse_updated.rb b/app/models/events/synapse_updated.rb index a0d8992d..958fe1b6 100644 --- a/app/models/events/synapse_updated.rb +++ b/app/models/events/synapse_updated.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class SynapseUpdated < Event # after_create :notify_users! diff --git a/app/models/events/topic_added_to_map.rb b/app/models/events/topic_added_to_map.rb index c9259ca8..a7ea9033 100644 --- a/app/models/events/topic_added_to_map.rb +++ b/app/models/events/topic_added_to_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class TopicAddedToMap < Event after_create :notify_users! @@ -10,7 +11,7 @@ module Events user: user, meta: meta) end - + def notify_users! # in the future, notify followers of both the topic, and the map NotificationService.notify_followers(eventable, TOPIC_ADDED_TO_MAP, self) diff --git a/app/models/events/topic_moved_on_map.rb b/app/models/events/topic_moved_on_map.rb index 5805a73f..07b495c0 100644 --- a/app/models/events/topic_moved_on_map.rb +++ b/app/models/events/topic_moved_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class TopicMovedOnMap < Event # after_create :notify_users! diff --git a/app/models/events/topic_removed_from_map.rb b/app/models/events/topic_removed_from_map.rb index f82e04d5..8adc7c8e 100644 --- a/app/models/events/topic_removed_from_map.rb +++ b/app/models/events/topic_removed_from_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class TopicRemovedFromMap < Event # after_create :notify_users! diff --git a/app/models/events/topic_updated.rb b/app/models/events/topic_updated.rb index 090cfcda..d6289f8a 100644 --- a/app/models/events/topic_updated.rb +++ b/app/models/events/topic_updated.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + module Events class TopicUpdated < Event - #after_create :notify_users! + # after_create :notify_users! def self.publish!(topic, user, meta) create!(kind: 'topic_updated', @@ -9,7 +10,7 @@ module Events user: user, meta: meta) end - + def notify_users! NotificationService.notify_followers(eventable, 'topic_updated', self) end diff --git a/app/models/events/user_not_present_on_map.rb b/app/models/events/user_not_present_on_map.rb index 811ed72a..41874b3b 100644 --- a/app/models/events/user_not_present_on_map.rb +++ b/app/models/events/user_not_present_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class UserNotPresentOnMap < Event # after_create :notify_users! diff --git a/app/models/events/user_present_on_map.rb b/app/models/events/user_present_on_map.rb index 34b7dae9..8bcf0303 100644 --- a/app/models/events/user_present_on_map.rb +++ b/app/models/events/user_present_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Events class UserPresentOnMap < Event # after_create :notify_users! diff --git a/app/models/follow.rb b/app/models/follow.rb index cf1d5f17..66fdb230 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true -class Follow < ApplicationRecord +class Follow < ApplicationRecord belongs_to :user belongs_to :followed, polymorphic: true has_one :follow_reason, dependent: :destroy - + validates :user, presence: true validates :followed, presence: true validates :user, uniqueness: { scope: :followed, message: 'This entity is already followed by this user' } - + after_create :add_subsetting scope :active, -> { where(muted: false) - } + } private diff --git a/app/models/follow_reason.rb b/app/models/follow_reason.rb index baf70a6a..732db132 100644 --- a/app/models/follow_reason.rb +++ b/app/models/follow_reason.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true + class FollowReason < ApplicationRecord REASONS = %w(created commented contributed followed shared_on starred).freeze belongs_to :follow - + validates :follow, presence: true - + def has_reason created || commented || contributed || followed || shared_on || starred end -end \ No newline at end of file +end diff --git a/app/models/in_metacode_set.rb b/app/models/in_metacode_set.rb index 78dc1c29..cdadff80 100644 --- a/app/models/in_metacode_set.rb +++ b/app/models/in_metacode_set.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class InMetacodeSet < ApplicationRecord belongs_to :metacode, class_name: 'Metacode', foreign_key: 'metacode_id' belongs_to :metacode_set, class_name: 'MetacodeSet', foreign_key: 'metacode_set_id' diff --git a/app/models/map.rb b/app/models/map.rb index 76fddcd8..6f58af2e 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Map < ApplicationRecord ATTRS_TO_WATCH = %w(name desc permission).freeze @@ -15,7 +16,7 @@ class Map < ApplicationRecord has_many :messages, as: :resource, dependent: :destroy has_many :stars, dependent: :destroy has_many :follows, as: :followed, dependent: :destroy - has_many :followers, :through => :follows, source: :user + has_many :followers, through: :follows, source: :user has_many :access_requests, dependent: :destroy has_many :user_maps, dependent: :destroy @@ -89,10 +90,10 @@ class Map < ApplicationRecord def as_json(_options = {}) json = super( - methods: [:user_name, :user_image, :star_count, :topic_count, :synapse_count, - :contributor_count, :collaborator_ids, :screenshot_url], - except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, - :screenshot_updated_at] + methods: %i(user_name user_image star_count topic_count synapse_count + contributor_count collaborator_ids screenshot_url), + except: %i(screenshot_content_type screenshot_file_size screenshot_file_name + screenshot_updated_at) ) json[:created_at_clean] = created_at_str json[:updated_at_clean] = updated_at_str @@ -133,16 +134,16 @@ class Map < ApplicationRecord end removed.compact end - + def update_deferring_topics_and_synapses Topic.where(defer_to_map_id: id).update(permission: permission) Synapse.where(defer_to_map_id: id).update(permission: permission) end protected - + def after_created - FollowService.follow(self, self.user, 'created') + FollowService.follow(self, user, 'created') # notify users following the map creator end @@ -150,7 +151,7 @@ class Map < ApplicationRecord return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } ActionCable.server.broadcast 'map_' + id.to_s, type: 'mapUpdated' end - + def after_updated_async if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } FollowService.follow(self, updated_by, 'contributed') diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 270d3574..5139bad3 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Mapping < ApplicationRecord scope :topicmapping, -> { where(mappable_type: :Topic) } scope :synapsemapping, -> { where(mappable_type: :Synapse) } @@ -24,7 +25,7 @@ class Mapping < ApplicationRecord end def as_json(_options = {}) - super(methods: [:user_name, :user_image]) + super(methods: %i(user_name user_image)) end def after_created diff --git a/app/models/message.rb b/app/models/message.rb index 01cd4c34..f0ea0af2 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Message < ApplicationRecord belongs_to :user belongs_to :resource, polymorphic: true @@ -6,15 +7,14 @@ class Message < ApplicationRecord delegate :name, to: :user, prefix: true after_create :after_created - #after_create :after_created_async - + # after_create :after_created_async def user_image user.image.url end def as_json(_options = {}) - json = super(methods: [:user_name, :user_image]) + json = super(methods: %i(user_name user_image)) json end diff --git a/app/models/metacode.rb b/app/models/metacode.rb index c97c4fb5..4a099d76 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Metacode < ApplicationRecord has_many :in_metacode_sets has_many :metacode_sets, through: :in_metacode_sets diff --git a/app/models/metacode_set.rb b/app/models/metacode_set.rb index 72bcc719..6b39df03 100644 --- a/app/models/metacode_set.rb +++ b/app/models/metacode_set.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MetacodeSet < ApplicationRecord belongs_to :user has_many :in_metacode_sets diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb index 207854ac..0fb9ef21 100644 --- a/app/models/permitted_params.rb +++ b/app/models/permitted_params.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class PermittedParams < Struct.new(:params) %w(map synapse topic mapping token).each do |kind| define_method(kind) do @@ -15,18 +16,18 @@ class PermittedParams < Struct.new(:params) end def map_attributes - [:name, :desc, :permission, :arranged] + %i(name desc permission arranged) end def synapse_attributes - [:desc, :category, :weight, :permission, :topic1_id, :topic2_id] + %i(desc category weight permission topic1_id topic2_id) end def topic_attributes - [:name, :desc, :link, :permission, :metacode_id] + %i(name desc link permission metacode_id) end def mapping_attributes - [:xloc, :yloc, :map_id, :mappable_type, :mappable_id] + %i(xloc yloc map_id mappable_type mappable_id) end end diff --git a/app/models/star.rb b/app/models/star.rb index 8a45a0c3..e1d8b7e9 100644 --- a/app/models/star.rb +++ b/app/models/star.rb @@ -1,20 +1,21 @@ # frozen_string_literal: true -class Star < ActiveRecord::Base + +class Star < ApplicationRecord belongs_to :user belongs_to :map validates :map, uniqueness: { scope: :user, message: 'You have already starred this map' } - #after_create :after_created_async - #before_destroy :before_destroyed - + # after_create :after_created_async + # before_destroy :before_destroyed + protected - + def after_created_async FollowService.follow(map, user, 'starred') NotificationService.notify_followers(map, 'map_starred', self, 'created') end handle_asynchronously :after_created_async - + def before_destroyed FollowService.remove_reason(map, user, 'starred') end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 4def4147..7e09ad2e 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Synapse < ApplicationRecord ATTRS_TO_WATCH = %w(desc category permission defer_to_map_id).freeze @@ -38,7 +39,7 @@ class Synapse < ApplicationRecord def collaborator_ids if defer_to_map - defer_to_map.editors.select { |mapper| mapper != user }.map(&:id) + defer_to_map.editors.reject { |mapper| mapper == user }.map(&:id) else [] end @@ -54,7 +55,7 @@ class Synapse < ApplicationRecord end def as_json(_options = {}) - super(methods: [:user_name, :user_image, :collaborator_ids]) + super(methods: %i(user_name user_image collaborator_ids)) end def as_rdf @@ -96,7 +97,7 @@ class Synapse < ApplicationRecord def before_destroyed # hard to know how to do this yet, because the synapse actually gets destroyed - #NotificationService.notify_followers(topic1, 'topic_disconnected', self) - #NotificationService.notify_followers(topic2, 'topic_disconnected', self) + # NotificationService.notify_followers(topic1, 'topic_disconnected', self) + # NotificationService.notify_followers(topic2, 'topic_disconnected', self) end end diff --git a/app/models/token.rb b/app/models/token.rb index 9cd93043..b482b162 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Token < ApplicationRecord belongs_to :user diff --git a/app/models/topic.rb b/app/models/topic.rb index 82efb8bc..9e551cc3 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Topic < ApplicationRecord ATTRS_TO_WATCH = %w(name desc link metacode_id permission defer_to_map_id).freeze include TopicsHelper @@ -16,7 +17,7 @@ class Topic < ApplicationRecord has_many :mappings, as: :mappable, dependent: :destroy has_many :maps, through: :mappings has_many :follows, as: :followed, dependent: :destroy - has_many :followers, :through => :follows, source: :user + has_many :followers, through: :follows, source: :user belongs_to :metacode @@ -25,7 +26,7 @@ class Topic < ApplicationRecord after_create :after_created_async after_update :after_updated after_update :after_updated_async - #before_destroy :before_destroyed + # before_destroy :before_destroyed validates :permission, presence: true validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } @@ -69,7 +70,7 @@ class Topic < ApplicationRecord end def as_json(options = {}) - super(methods: [:user_name, :user_image, :collaborator_ids]) + super(methods: %i(user_name user_image collaborator_ids)) .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmapsLinks(options[:user]), map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user])) end @@ -89,7 +90,7 @@ class Topic < ApplicationRecord def collaborator_ids if defer_to_map - defer_to_map.editors.select { |mapper| mapper != user }.map(&:id) + defer_to_map.editors.reject { |mapper| mapper == user }.map(&:id) else [] end @@ -154,9 +155,9 @@ class Topic < ApplicationRecord self.link = Rails.application.routes.url_helpers .map_url(host: ENV['MAILER_DEFAULT_URL'], id: @map.id) end - + def after_created_async - FollowService.follow(self, self.user, 'created') + FollowService.follow(self, user, 'created') # notify users following the topic creator end handle_asynchronously :after_created_async @@ -173,7 +174,7 @@ class Topic < ApplicationRecord end end end - + def after_updated_async if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } FollowService.follow(self, updated_by, 'contributed') @@ -183,6 +184,6 @@ class Topic < ApplicationRecord def before_destroyed # hard to know how to do this yet, because the topic actually gets destroyed - #NotificationService.notify_followers(self, 'topic_deleted', ?) + # NotificationService.notify_followers(self, 'topic_deleted', ?) end end diff --git a/app/models/user.rb b/app/models/user.rb index d9e25cad..3b3a0045 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'open-uri' class User < ApplicationRecord @@ -53,24 +54,22 @@ class User < ApplicationRecord # override default as_json def as_json(_options = {}) json = { id: id, - name: name, - image: image.url(:sixtyfour), - admin: admin } - if (_options[:follows]) + name: name, + image: image.url(:sixtyfour), + admin: admin } + if _options[:follows] json['follows'] = { topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id), maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id) } end - if (_options[:follow_settings]) - json['follow_topic_on_created'] = settings.follow_topic_on_created == "1" - json['follow_topic_on_contributed'] = settings.follow_topic_on_contributed == "1" - json['follow_map_on_created'] = settings.follow_map_on_created == "1" - json['follow_map_on_contributed'] = settings.follow_map_on_contributed == "1" - end - if (_options[:email]) - json['email'] = email + if _options[:follow_settings] + json['follow_topic_on_created'] = settings.follow_topic_on_created == '1' + json['follow_topic_on_contributed'] = settings.follow_topic_on_contributed == '1' + json['follow_map_on_created'] = settings.follow_map_on_created == '1' + json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1' end + json['email'] = email if _options[:email] json end @@ -134,19 +133,19 @@ class User < ApplicationRecord def has_map_open(map) latestEvent = Event.where(map: map, user: self) - .where(kind: ['user_present_on_map', 'user_not_present_on_map']) + .where(kind: %w(user_present_on_map user_not_present_on_map)) .order(:created_at) .last latestEvent && latestEvent.kind == 'user_present_on_map' end def has_map_with_synapse_open(synapse) - synapse.maps.any?{|map| has_map_open(map)} + synapse.maps.any? { |map| has_map_open(map) } end def settings self[:settings] = UserPreference.new if self[:settings].nil? - if not self[:settings].respond_to?(:follow_topic_on_created) + unless self[:settings].respond_to?(:follow_topic_on_created) self[:settings].initialize_follow_settings end self[:settings] diff --git a/app/models/user_map.rb b/app/models/user_map.rb index 61b578ca..7c992191 100644 --- a/app/models/user_map.rb +++ b/app/models/user_map.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + class UserMap < ApplicationRecord belongs_to :map belongs_to :user belongs_to :access_request - + after_create :after_created_async before_destroy :before_destroyed @@ -12,20 +13,20 @@ class UserMap < ApplicationRecord Mailboxer::Receipt.where(notification: notification).update_all(is_read: true) end end - + protected - + def after_created_async FollowService.follow(map, user, 'shared_on') if access_request - NotificationService.access_approved(self.access_request) + NotificationService.access_approved(access_request) else NotificationService.invite_to_edit(self) end # NotificationService.notify_followers(map, 'map_collaborator_added', self, 'shared_on') end handle_asynchronously :after_created_async - + def before_destroyed FollowService.remove_reason(map, user, 'shared_on') end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index d92eb7a9..5a746612 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class UserPreference attr_accessor :metacodes, :metacode_focus, :follow_topic_on_created, :follow_topic_on_contributed, :follow_map_on_created, :follow_map_on_contributed diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 65057411..038c8985 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhook < ApplicationRecord belongs_to :hookable, polymorphic: true diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index 27f95861..e2fac6ae 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Webhooks::Slack::Base = Struct.new(:webhook, :event) do include Routing diff --git a/app/models/webhooks/slack/conversation_started_on_map.rb b/app/models/webhooks/slack/conversation_started_on_map.rb index 6b6595ce..71bfcf6f 100644 --- a/app/models/webhooks/slack/conversation_started_on_map.rb +++ b/app/models/webhooks/slack/conversation_started_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base def text "There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}" diff --git a/app/models/webhooks/slack/synapse_added_to_map.rb b/app/models/webhooks/slack/synapse_added_to_map.rb index 3d944878..5f9ad239 100644 --- a/app/models/webhooks/slack/synapse_added_to_map.rb +++ b/app/models/webhooks/slack/synapse_added_to_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base def text connector = eventable.desc.empty? ? '->' : eventable.desc diff --git a/app/models/webhooks/slack/synapse_removed_from_map.rb b/app/models/webhooks/slack/synapse_removed_from_map.rb index 532488e8..01940a7c 100644 --- a/app/models/webhooks/slack/synapse_removed_from_map.rb +++ b/app/models/webhooks/slack/synapse_removed_from_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::SynapseRemovedFromMap < Webhooks::Slack::Base def text connector = eventable.desc.empty? ? '->' : eventable.desc diff --git a/app/models/webhooks/slack/topic_added_to_map.rb b/app/models/webhooks/slack/topic_added_to_map.rb index 4f726069..7e75fde3 100644 --- a/app/models/webhooks/slack/topic_added_to_map.rb +++ b/app/models/webhooks/slack/topic_added_to_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base def text "*#{eventable.name}* was added by *#{event.user.name}* to the map *#{view_map_on_metamaps}*" diff --git a/app/models/webhooks/slack/topic_moved_on_map.rb b/app/models/webhooks/slack/topic_moved_on_map.rb index dfe088ed..50631c9a 100644 --- a/app/models/webhooks/slack/topic_moved_on_map.rb +++ b/app/models/webhooks/slack/topic_moved_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::TopicMovedOnMap < Webhooks::Slack::Base def text "*#{eventable.name}* was moved by *#{event.user.name}* on the map *#{view_map_on_metamaps}*" diff --git a/app/models/webhooks/slack/topic_removed_from_map.rb b/app/models/webhooks/slack/topic_removed_from_map.rb index 05a79c3b..d758c5c1 100644 --- a/app/models/webhooks/slack/topic_removed_from_map.rb +++ b/app/models/webhooks/slack/topic_removed_from_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::TopicRemovedFromMap < Webhooks::Slack::Base def text "*#{eventable.name}* was removed by *#{event.user.name}* from the map *#{view_map_on_metamaps}*" diff --git a/app/models/webhooks/slack/user_present_on_map.rb b/app/models/webhooks/slack/user_present_on_map.rb index 4cee2992..3bae7cfd 100644 --- a/app/models/webhooks/slack/user_present_on_map.rb +++ b/app/models/webhooks/slack/user_present_on_map.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base def text "Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}" diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 348ef5f2..d7a42374 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ApplicationPolicy attr_reader :user, :record diff --git a/app/policies/explore_policy.rb b/app/policies/explore_policy.rb index ce17d4f4..03a312b4 100644 --- a/app/policies/explore_policy.rb +++ b/app/policies/explore_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class ExplorePolicy < ApplicationPolicy def active? true diff --git a/app/policies/hack_policy.rb b/app/policies/hack_policy.rb index bdc9eaab..3be8bbf3 100644 --- a/app/policies/hack_policy.rb +++ b/app/policies/hack_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class HackPolicy < ApplicationPolicy def load_url_title? true diff --git a/app/policies/main_policy.rb b/app/policies/main_policy.rb index 2eb5b3e8..b349cc2f 100644 --- a/app/policies/main_policy.rb +++ b/app/policies/main_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MainPolicy < ApplicationPolicy def home? true diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index 6325b256..ea231ad7 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MapPolicy < ApplicationPolicy class Scope < Scope def resolve @@ -20,7 +21,7 @@ class MapPolicy < ApplicationPolicy record.collaborators.include?(user) || record.user == user end - + def conversation? show? && %w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email) end @@ -30,7 +31,7 @@ class MapPolicy < ApplicationPolicy end def update? - return false unless user.present? + return false if user.blank? record.permission == 'commons' || record.collaborators.include?(user) || record.user == user diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index 6cdb7e9b..011e5f4b 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MappingPolicy < ApplicationPolicy class Scope < Scope def resolve diff --git a/app/policies/message_policy.rb b/app/policies/message_policy.rb index 8a140788..bbc03639 100644 --- a/app/policies/message_policy.rb +++ b/app/policies/message_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MessagePolicy < ApplicationPolicy class Scope < Scope def resolve diff --git a/app/policies/metacode_policy.rb b/app/policies/metacode_policy.rb index 626d23e3..220ac24d 100644 --- a/app/policies/metacode_policy.rb +++ b/app/policies/metacode_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MetacodePolicy < ApplicationPolicy def index? true diff --git a/app/policies/search_policy.rb b/app/policies/search_policy.rb index 5b783457..8b78d373 100644 --- a/app/policies/search_policy.rb +++ b/app/policies/search_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class SearchPolicy < ApplicationPolicy def topics? true diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index ae0796cd..e789fdc3 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class SynapsePolicy < ApplicationPolicy class Scope < Scope def resolve @@ -28,7 +29,7 @@ class SynapsePolicy < ApplicationPolicy end def update? - if !user.present? + if user.blank? false elsif record.defer_to_map.present? map_policy.update? diff --git a/app/policies/token_policy.rb b/app/policies/token_policy.rb index e96e4db8..73a504b4 100644 --- a/app/policies/token_policy.rb +++ b/app/policies/token_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class TokenPolicy < ApplicationPolicy class Scope < Scope def resolve diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index c283f469..5ed050e5 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class TopicPolicy < ApplicationPolicy class Scope < Scope def resolve @@ -27,7 +28,7 @@ class TopicPolicy < ApplicationPolicy end def update? - return false unless user.present? + return false if user.blank? if record.defer_to_map.present? map_policy.update? else diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 4de64c57..72540538 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class UserPolicy < ApplicationPolicy def index? true diff --git a/app/serializers/api/v2/application_serializer.rb b/app/serializers/api/v2/application_serializer.rb index c0399db6..ba025e5a 100644 --- a/app/serializers/api/v2/application_serializer.rb +++ b/app/serializers/api/v2/application_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class ApplicationSerializer < ActiveModel::Serializer diff --git a/app/serializers/api/v2/map_serializer.rb b/app/serializers/api/v2/map_serializer.rb index 3ba158f9..65b6a7c9 100644 --- a/app/serializers/api/v2/map_serializer.rb +++ b/app/serializers/api/v2/map_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class MapSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/mapping_serializer.rb b/app/serializers/api/v2/mapping_serializer.rb index d418b31c..fca5760e 100644 --- a/app/serializers/api/v2/mapping_serializer.rb +++ b/app/serializers/api/v2/mapping_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class MappingSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/metacode_serializer.rb b/app/serializers/api/v2/metacode_serializer.rb index 0b1ac553..9d6e3c6e 100644 --- a/app/serializers/api/v2/metacode_serializer.rb +++ b/app/serializers/api/v2/metacode_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class MetacodeSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/synapse_serializer.rb b/app/serializers/api/v2/synapse_serializer.rb index 3f95af35..ae6f8c44 100644 --- a/app/serializers/api/v2/synapse_serializer.rb +++ b/app/serializers/api/v2/synapse_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class SynapseSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/token_serializer.rb b/app/serializers/api/v2/token_serializer.rb index 8f86757b..5db8e8b2 100644 --- a/app/serializers/api/v2/token_serializer.rb +++ b/app/serializers/api/v2/token_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class TokenSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/topic_serializer.rb b/app/serializers/api/v2/topic_serializer.rb index 8da46a2a..aaf6a11a 100644 --- a/app/serializers/api/v2/topic_serializer.rb +++ b/app/serializers/api/v2/topic_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class TopicSerializer < ApplicationSerializer diff --git a/app/serializers/api/v2/user_serializer.rb b/app/serializers/api/v2/user_serializer.rb index 7f18f02b..f23df5b7 100644 --- a/app/serializers/api/v2/user_serializer.rb +++ b/app/serializers/api/v2/user_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Api module V2 class UserSerializer < ApplicationSerializer diff --git a/app/serializers/event_serializer.rb b/app/serializers/event_serializer.rb index 4d994472..1f79d308 100644 --- a/app/serializers/event_serializer.rb +++ b/app/serializers/event_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class EventSerializer < ActiveModel::Serializer attributes :id, :sequence_id, :kind, :map_id, :created_at diff --git a/app/serializers/webhook_serializer.rb b/app/serializers/webhook_serializer.rb index c1f0e266..8c7c75ce 100644 --- a/app/serializers/webhook_serializer.rb +++ b/app/serializers/webhook_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class WebhookSerializer < ActiveModel::Serializer attributes :text, :username, :icon_url attribute :channel, if: :has_channel? diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 87ac3be5..173d56ba 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true + class FollowService class << self def follow(entity, user, reason) - return unless user return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason) @@ -30,9 +30,7 @@ class FollowService follow = Follow.where(followed: entity, user: user).first if follow follow.follow_reason.update_attribute(reason, false) - if !follow.follow_reason.has_reason - follow.destroy - end + follow.destroy unless follow.follow_reason.has_reason end end diff --git a/app/services/map_activity_service.rb b/app/services/map_activity_service.rb index 51424b68..5bfafa24 100644 --- a/app/services/map_activity_service.rb +++ b/app/services/map_activity_service.rb @@ -1,5 +1,6 @@ -class MapActivityService +# frozen_string_literal: true +class MapActivityService def self.subject_line(map) 'Activity on map ' + map.name end @@ -15,27 +16,25 @@ class MapActivityService scoped_synapse_ids = SynapsePolicy::Scope.new(user, map.synapses).resolve.map(&:id) message_count = Message.where(resource: map) - .where("created_at > ? AND created_at < ?", since, until_moment) + .where('created_at > ? AND created_at < ?', since, until_moment) .where.not(user: user).count - if message_count > 0 - results[:stats][:messages_sent] = message_count - end + results[:stats][:messages_sent] = message_count if message_count > 0 moved_count = Event.where(kind: 'topic_moved_on_map', map: map) - .where("created_at > ? AND created_at < ?", since, until_moment) + .where('created_at > ? AND created_at < ?', since, until_moment) .where(eventable_id: scoped_topic_ids) .where.not(user: user).group(:eventable_id).count - if moved_count.keys.length > 0 + unless moved_count.keys.empty? results[:stats][:topics_moved] = moved_count.keys.length end topics_added_events = Event.where(kind: 'topic_added_to_map', map: map) - .where("created_at > ? AND created_at < ?", since, until_moment) + .where('created_at > ? AND created_at < ?', since, until_moment) .where.not(user: user) .order(:created_at) topics_removed_events = Event.where(kind: 'topic_removed_from_map', map: map) - .where("created_at > ? AND created_at < ?", since, until_moment) + .where('created_at > ? AND created_at < ?', since, until_moment) .where.not(user: user) .order(:created_at) @@ -45,7 +44,7 @@ class MapActivityService num_removes = topics_removed_events.where(eventable_id: ta.eventable_id).count topics_added_to_include[ta.eventable_id] = ta if num_adds > num_removes && scoped_topic_ids.include?(ta.eventable.id) end - if topics_added_to_include.keys.length > 0 + unless topics_added_to_include.keys.empty? results[:stats][:topics_added] = topics_added_to_include.keys.length results[:topics_added] = topics_added_to_include.values end @@ -56,28 +55,28 @@ class MapActivityService num_removes = topics_removed_events.where(eventable_id: ta.eventable_id).count topics_removed_to_include[ta.eventable_id] = ta if num_removes > num_adds && TopicPolicy.new(user, ta.eventable).show? end - if topics_removed_to_include.keys.length > 0 + unless topics_removed_to_include.keys.empty? results[:stats][:topics_removed] = topics_removed_to_include.keys.length results[:topics_removed] = topics_removed_to_include.values end synapses_added_events = Event.where(kind: 'synapse_added_to_map', map: map) - .where("created_at > ? AND created_at < ?", since, until_moment) - .where.not(user: user) - .order(:created_at) - - synapses_removed_events = Event.where(kind: 'synapse_removed_from_map', map: map) - .where("created_at > ? AND created_at < ?", since, until_moment) + .where('created_at > ? AND created_at < ?', since, until_moment) .where.not(user: user) .order(:created_at) + synapses_removed_events = Event.where(kind: 'synapse_removed_from_map', map: map) + .where('created_at > ? AND created_at < ?', since, until_moment) + .where.not(user: user) + .order(:created_at) + synapses_added_to_include = {} synapses_added_events.each do |ta| num_adds = synapses_added_events.where(eventable_id: ta.eventable_id).count num_removes = synapses_removed_events.where(eventable_id: ta.eventable_id).count synapses_added_to_include[ta.eventable_id] = ta if num_adds > num_removes && scoped_synapse_ids.include?(ta.eventable.id) end - if synapses_added_to_include.keys.length > 0 + unless synapses_added_to_include.keys.empty? results[:stats][:synapses_added] = synapses_added_to_include.keys.length results[:synapses_added] = synapses_added_to_include.values end @@ -88,7 +87,7 @@ class MapActivityService num_removes = synapses_removed_events.where(eventable_id: ta.eventable_id).count synapses_removed_to_include[ta.eventable_id] = ta if num_removes > num_adds && SynapsePolicy.new(user, ta.eventable).show? end - if synapses_removed_to_include.keys.length > 0 + unless synapses_removed_to_include.keys.empty? results[:stats][:synapses_removed] = synapses_removed_to_include.keys.length results[:synapses_removed] = synapses_removed_to_include.values end diff --git a/app/services/map_export_service.rb b/app/services/map_export_service.rb index e500575e..2defd7eb 100644 --- a/app/services/map_export_service.rb +++ b/app/services/map_export_service.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class MapExportService attr_reader :user, :map, :base_url @@ -46,16 +47,16 @@ class MapExportService private def topic_headings - [:id, :name, :metacode, :x, :y, :description, :link, :user, :permission] + %i(id name metacode x y description link user permission) end def synapse_headings - [:topic1, :topic2, :category, :description, :user, :permission] + %i(topic1 topic2 category description user permission) end def exportable_topics visible_topics ||= Pundit.policy_scope!(user, map.topics) - topic_mappings = Mapping.includes(mappable: [:metacode, :user]) + topic_mappings = Mapping.includes(mappable: %i(metacode user)) .where(mappable: visible_topics, map: map) topic_mappings.map do |mapping| topic = mapping.mappable diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 7d7f0512..e78c1bd3 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class NotificationService extend TopicMailerHelper extend MapMailerHelper @@ -14,59 +15,57 @@ class NotificationService def self.get_settings_for_event(entity, event_type, event) case event_type - when TOPIC_ADDED_TO_MAP - subject = added_to_map_subject(entity, event.map) - template = 'topic_mailer/added_to_map' - when TOPIC_CONNECTED_1 - subject = connected_subject(event.topic1) - template = 'topic_mailer/connected' - when TOPIC_CONNECTED_2 - subject = connected_subject(event.topic2) - template = 'topic_mailer/connected' + when TOPIC_ADDED_TO_MAP + subject = added_to_map_subject(entity, event.map) + template = 'topic_mailer/added_to_map' + when TOPIC_CONNECTED_1 + subject = connected_subject(event.topic1) + template = 'topic_mailer/connected' + when TOPIC_CONNECTED_2 + subject = connected_subject(event.topic2) + template = 'topic_mailer/connected' end - - {template: template, subject: subject} + + { template: template, subject: subject } end def self.send_for_follows(follows, entity, event_type, event) - return if follows.length == 0 + return if follows.empty? settings = get_settings_for_event(entity, event_type, event) # we'll prbly want to put the body into the actual loop so we can pass the current user in as a local body = renderer.render(template: settings[:template], locals: { entity: entity, event: event }, layout: false) - follows.each{|follow| + follows.each do |follow| case event_type - when TOPIC_ADDED_TO_MAP - next unless TopicPolicy.new(follow.user, entity).show? && MapPolicy.new(follow.user, event.map).show? - next if follow.user.has_map_open(event.map) - # note, the caveat to this fork related code is that no future updates will be sent - # either. only the notifications for the initial fork should be squashed like this - next if event.map.source_id # if map is a fork, send notification for that instead - when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 - next unless SynapsePolicy.new(follow.user, event).show? - next if follow.user.has_map_with_synapse_open(event) + when TOPIC_ADDED_TO_MAP + next unless TopicPolicy.new(follow.user, entity).show? && MapPolicy.new(follow.user, event.map).show? + next if follow.user.has_map_open(event.map) + # note, the caveat to this fork related code is that no future updates will be sent + # either. only the notifications for the initial fork should be squashed like this + next if event.map.source_id # if map is a fork, send notification for that instead + when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 + next unless SynapsePolicy.new(follow.user, event).show? + next if follow.user.has_map_with_synapse_open(event) end # this handles email and in-app notifications, in the future, include push follow.user.notify(settings[:subject], body, event, false, event_type, follow.user.emails_allowed, event.user) # push could be handled with Actioncable to send transient notifications to the UI # the receipt from the notify call could be used to link to the full notification - } + end end def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil) follows = entity.follows.active.where.not(user_id: event.user.id) - if !exclude_follows.nil? - follows = follows.where.not(id: exclude_follows) - end - + follows = follows.where.not(id: exclude_follows) unless exclude_follows.nil? + if reason_filter.class == String && FollowReason::REASONS.include?(reason_filter) follows = follows.joins(:follow_reason).where('follow_reasons.' + reason_filter => true) elsif reason_filter.class == Array # TODO: throw an error here if all the reasons aren't valid - follows = follows.joins(:follow_reason).where(reason_filter.map{|r| "follow_reasons.#{r} = 't'"}.join(' OR ')) + follows = follows.joins(:follow_reason).where(reason_filter.map { |r| "follow_reasons.#{r} = 't'" }.join(' OR ')) end send_for_follows(follows, entity, event_type, event) - return follows.map(&:id) + follows.map(&:id) end def self.access_request(request) diff --git a/app/services/perm.rb b/app/services/perm.rb index 57e0816f..c220a306 100644 --- a/app/services/perm.rb +++ b/app/services/perm.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + class Perm # e.g. Perm::ISSIONS - ISSIONS = [:commons, :public, :private].freeze + ISSIONS = %i(commons public private).freeze class << self def short(permission) diff --git a/app/services/webhook_service.rb b/app/services/webhook_service.rb index c2a91a80..8eec2789 100644 --- a/app/services/webhook_service.rb +++ b/app/services/webhook_service.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class WebhookService def self.publish!(webhook:, event:) return false unless webhook.event_types.include? event.kind diff --git a/config.ru b/config.ru index ab79c07d..207953e1 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) diff --git a/config/application.rb b/config/application.rb index 06842eb6..f7dbf17b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'boot' require 'csv' diff --git a/config/boot.rb b/config/boot.rb index f17b883c..6868388e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + require 'rubygems' require 'rails/commands/server' module Rails class Server def default_options - super.merge(Host: '0.0.0.0', Port: 3000) + super.merge(Host: '0.0.0.0', Port: 3000) end end end diff --git a/config/environment.rb b/config/environment.rb index 12ea62f8..d5abe558 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 381bca7b..a71a1590 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/environments/production.rb b/config/environments/production.rb index fd7ff05a..9a175e01 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/environments/test.rb b/config/environments/test.rb index d85899fd..4c7426b7 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Metamaps::Application.configure do # Settings specified here will take precedence over those in config/application.rb diff --git a/config/initializers/access_codes.rb b/config/initializers/access_codes.rb index fdf4e4b3..c735b13a 100644 --- a/config/initializers/access_codes.rb +++ b/config/initializers/access_codes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + $codes = [] if ActiveRecord::Base.connection.data_source_exists? 'users' $codes = ActiveRecord::Base.connection diff --git a/config/initializers/active_model_serializers.rb b/config/initializers/active_model_serializers.rb index 929be340..84e882e4 100644 --- a/config/initializers/active_model_serializers.rb +++ b/config/initializers/active_model_serializers.rb @@ -1,2 +1,3 @@ # frozen_string_literal: true + ActiveModelSerializers.config.adapter = :json diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 2c9cdbb8..da5460e3 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Rails.application.configure do # Version of your assets, change this if you want to expire all your assets. config.assets.version = '2.0' @@ -9,5 +10,5 @@ Rails.application.configure do # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - config.assets.precompile += %w( application-secret.css application-secret.js webpacked/metamaps.bundle.js ) + config.assets.precompile += %w(application-secret.css application-secret.js webpacked/metamaps.bundle.js) end diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 74ea9274..046c7487 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index cb46d3ef..a93b5b32 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins '*' resource '/api/*', headers: :any, - methods: [:get, :post, :put, :delete, :options, :head] + methods: %i(get post put delete options head) end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 6740cdc9..71f72490 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 21b08bc2..3182dd03 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Doorkeeper.configure do # Change the ORM that doorkeeper will use (needs plugins) orm :active_record diff --git a/config/initializers/exception_notification.rb b/config/initializers/exception_notification.rb index 84c51be0..29ef9e5e 100644 --- a/config/initializers/exception_notification.rb +++ b/config/initializers/exception_notification.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'exception_notification/rails' module ExceptionNotifier diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index b7fe1231..7a4f47b4 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/internal_testers.rb b/config/initializers/internal_testers.rb index 079fc119..a014f3a4 100644 --- a/config/initializers/internal_testers.rb +++ b/config/initializers/internal_testers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def is_tester(user) user && %w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email) end diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb index 5b9883ab..fb53dfce 100644 --- a/config/initializers/kaminari_config.rb +++ b/config/initializers/kaminari_config.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Kaminari.configure do |config| # config.default_per_page = 25 # config.max_per_page = nil diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 2e0132a6..3d4dd77f 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index d3c12d7b..69b31ed1 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.0 upgrade. diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 6f094b7c..45b5e913 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true + Paperclip::Attachment.default_options[:url] = ':s3_domain_url' Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index b79f0d10..83a978a8 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Rack class Attack Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 4da6fb50..3c3b0242 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 57d69156..d7bb3be0 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_Metamaps_session' diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 9a487067..7b848569 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + METAMAPS_VERSION = '3.5' METAMAPS_BUILD = `git log -1 --pretty=%H`.chomp[0..11].freeze METAMAPS_LAST_UPDATED = `git log -1 --pretty='%ad'`.split(' ').values_at(1, 2, 4).join(' ').freeze diff --git a/config/initializers/warden_hooks.rb b/config/initializers/warden_hooks.rb index a0d8fd88..3b212513 100644 --- a/config/initializers/warden_hooks.rb +++ b/config/initializers/warden_hooks.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Warden::Manager.after_set_user do |user, auth, opts| scope = opts[:scope] auth.cookies.signed["#{scope}.id"] = user.id diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index d65576db..1dbadf48 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index da41eff9..03a28243 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers a minimum and maximum. # Any libraries that use thread pools should be configured to match diff --git a/config/routes.rb b/config/routes.rb index 80c0dbb4..667e0965 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + Metamaps::Application.routes.draw do use_doorkeeper mount ActionCable.server => '/cable' @@ -16,7 +17,7 @@ Metamaps::Application.routes.draw do end get :explore, to: redirect('/') - resources :maps, except: [:index, :edit] do + resources :maps, except: %i(index edit) do member do get :conversation get :export @@ -54,10 +55,10 @@ Metamaps::Application.routes.draw do end end - resources :mappings, except: [:index, :new, :edit] + resources :mappings, except: %i(index new edit) - resources :messages, only: [:show, :create, :update, :destroy] - resources :notifications, only: [:index, :show] do + resources :messages, only: %i(show create update destroy) + resources :notifications, only: %i(index show) do collection do get :unsubscribe end @@ -79,9 +80,9 @@ Metamaps::Application.routes.draw do get :synapses end - resources :synapses, except: [:index, :new, :edit] + resources :synapses, except: %i(index new edit) - resources :topics, except: [:index, :new, :edit] do + resources :topics, except: %i(index new edit) do member do get :network get :relative_numbers @@ -110,7 +111,7 @@ Metamaps::Application.routes.draw do get 'join' => 'users/registrations#new', :as => :sign_up end - resources :users, except: [:index, :destroy] do + resources :users, except: %i(index destroy) do member do get :details end @@ -120,16 +121,16 @@ Metamaps::Application.routes.draw do namespace :api, path: '/api', default: { format: :json } do namespace :v2, path: '/v2' do - resources :metacodes, only: [:index, :show] - resources :mappings, only: [:index, :create, :show, :update, :destroy] - resources :maps, only: [:index, :create, :show, :update, :destroy] do + resources :metacodes, only: %i(index show) + resources :mappings, only: %i(index create show update destroy) + resources :maps, only: %i(index create show update destroy) do post :stars, to: 'stars#create', on: :member delete :stars, to: 'stars#destroy', on: :member end - resources :synapses, only: [:index, :create, :show, :update, :destroy] - resources :tokens, only: [:index, :create, :destroy] - resources :topics, only: [:index, :create, :show, :update, :destroy] - resources :users, only: [:index, :show] do + resources :synapses, only: %i(index create show update destroy) + resources :tokens, only: %i(index create destroy) + resources :topics, only: %i(index create show update destroy) + resources :users, only: %i(index show) do get :current, on: :collection end match '*path', to: 'restful#catch_404', via: :all diff --git a/config/spring.rb b/config/spring.rb index b0ca9589..c35b7474 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + %w( .ruby-version .ruby-gemset diff --git a/lib/tasks/emails.rake b/lib/tasks/emails.rake index 02e6e372..a14c840a 100644 --- a/lib/tasks/emails.rake +++ b/lib/tasks/emails.rake @@ -1,5 +1,7 @@ +# frozen_string_literal: true + namespace :metamaps do - desc "delivers recent map activity digest emails to users" + desc 'delivers recent map activity digest emails to users' task deliver_map_activity_emails: :environment do summarize_map_activity end diff --git a/lib/tasks/extensions.rake b/lib/tasks/extensions.rake index 96de0368..c60e0058 100644 --- a/lib/tasks/extensions.rake +++ b/lib/tasks/extensions.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + namespace :assets do task :js_compile do system 'npm install' diff --git a/lib/tasks/heroku.rake b/lib/tasks/heroku.rake index d7ce308f..47829fcf 100644 --- a/lib/tasks/heroku.rake +++ b/lib/tasks/heroku.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'dotenv/tasks' namespace :heroku do diff --git a/lib/tasks/perms.rake b/lib/tasks/perms.rake index bf087bd0..06f76afd 100644 --- a/lib/tasks/perms.rake +++ b/lib/tasks/perms.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'dotenv/tasks' namespace :perms do diff --git a/spec/api/v2/mappings_api_spec.rb b/spec/api/v2/mappings_api_spec.rb index f8854e91..f7bb378d 100644 --- a/spec/api/v2/mappings_api_spec.rb +++ b/spec/api/v2/mappings_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe 'mappings API', type: :request do diff --git a/spec/api/v2/maps_api_spec.rb b/spec/api/v2/maps_api_spec.rb index f7e30751..f3c22482 100644 --- a/spec/api/v2/maps_api_spec.rb +++ b/spec/api/v2/maps_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # t frozen_string_literal: true require 'rails_helper' diff --git a/spec/api/v2/metacodes_api_spec.rb b/spec/api/v2/metacodes_api_spec.rb index 67d3d543..17743790 100644 --- a/spec/api/v2/metacodes_api_spec.rb +++ b/spec/api/v2/metacodes_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe 'metacodes API', type: :request do diff --git a/spec/api/v2/synapses_api_spec.rb b/spec/api/v2/synapses_api_spec.rb index 032750f6..15de44cc 100644 --- a/spec/api/v2/synapses_api_spec.rb +++ b/spec/api/v2/synapses_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe 'synapses API', type: :request do diff --git a/spec/api/v2/tokens_api_spec.rb b/spec/api/v2/tokens_api_spec.rb index c9ec77ed..8aac1f57 100644 --- a/spec/api/v2/tokens_api_spec.rb +++ b/spec/api/v2/tokens_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe 'tokens API', type: :request do diff --git a/spec/api/v2/topics_api_spec.rb b/spec/api/v2/topics_api_spec.rb index ac2fb56a..cec2b910 100644 --- a/spec/api/v2/topics_api_spec.rb +++ b/spec/api/v2/topics_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe 'topics API', type: :request do diff --git a/spec/api/v2/users_api_spec.rb b/spec/api/v2/users_api_spec.rb index 279224f3..4775e40b 100644 --- a/spec/api/v2/users_api_spec.rb +++ b/spec/api/v2/users_api_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe 'users API', type: :request do diff --git a/spec/controllers/explore_controller_spec.rb b/spec/controllers/explore_controller_spec.rb index 4e298a92..a1955857 100644 --- a/spec/controllers/explore_controller_spec.rb +++ b/spec/controllers/explore_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe ExploreController, type: :controller do diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index e5f59db7..c6da6e21 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MappingsController, type: :controller do diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 800ab4dc..e3935f5a 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MapsController, type: :controller do diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index b25017b9..4ba0e3d8 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MetacodesController, type: :controller do diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 21151ffc..c295b140 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe SynapsesController, type: :controller do diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 16526835..55dafb53 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe TopicsController, type: :controller do diff --git a/spec/factories/access_requests.rb b/spec/factories/access_requests.rb index 40dde45a..c85d4a53 100644 --- a/spec/factories/access_requests.rb +++ b/spec/factories/access_requests.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :access_request do map diff --git a/spec/factories/mappings.rb b/spec/factories/mappings.rb index ec06b613..13746de1 100644 --- a/spec/factories/mappings.rb +++ b/spec/factories/mappings.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :mapping do xloc 0 diff --git a/spec/factories/maps.rb b/spec/factories/maps.rb index 12bb5625..557a400f 100644 --- a/spec/factories/maps.rb +++ b/spec/factories/maps.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :map do sequence(:name) { |n| "Cool Map ##{n}" } diff --git a/spec/factories/message.rb b/spec/factories/message.rb index a0930fec..280b2c8f 100644 --- a/spec/factories/message.rb +++ b/spec/factories/message.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :message do association :resource, factory: :map diff --git a/spec/factories/metacodes.rb b/spec/factories/metacodes.rb index 2ed71beb..4e5a0d52 100644 --- a/spec/factories/metacodes.rb +++ b/spec/factories/metacodes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :metacode do sequence(:name) { |n| "Cool Metacode ##{n}" } diff --git a/spec/factories/stars.rb b/spec/factories/stars.rb index 60b10cf1..9be99242 100644 --- a/spec/factories/stars.rb +++ b/spec/factories/stars.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :star do end diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb index 0692c955..2d8ec60f 100644 --- a/spec/factories/synapses.rb +++ b/spec/factories/synapses.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :synapse do sequence(:desc) { |n| "Cool synapse ##{n}" } diff --git a/spec/factories/tokens.rb b/spec/factories/tokens.rb index 6d5f110b..26541fca 100644 --- a/spec/factories/tokens.rb +++ b/spec/factories/tokens.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :token do user diff --git a/spec/factories/topics.rb b/spec/factories/topics.rb index fb113cd5..1def8f19 100644 --- a/spec/factories/topics.rb +++ b/spec/factories/topics.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + FactoryGirl.define do factory :topic do user diff --git a/spec/factories/user_maps.rb b/spec/factories/user_maps.rb index 0175e8b8..db4d5b0e 100644 --- a/spec/factories/user_maps.rb +++ b/spec/factories/user_maps.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + FactoryGirl.define do factory :user_map do map user end -end \ No newline at end of file +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index b5b20b9a..20762285 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # This file supports three factories, because code and joinedwithcode # make things complicated! diff --git a/spec/mailers/map_activity_mailer_spec.rb b/spec/mailers/map_activity_mailer_spec.rb index 897a38c0..13b81c29 100644 --- a/spec/mailers/map_activity_mailer_spec.rb +++ b/spec/mailers/map_activity_mailer_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MapActivityMailer, type: :mailer do - end diff --git a/spec/mailers/map_mailer_spec.rb b/spec/mailers/map_mailer_spec.rb index 1ff217a3..20553557 100644 --- a/spec/mailers/map_mailer_spec.rb +++ b/spec/mailers/map_mailer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MapMailer, type: :mailer do diff --git a/spec/mailers/previews/map_activity_mailer_preview.rb b/spec/mailers/previews/map_activity_mailer_preview.rb index 3d943eee..9fab67fc 100644 --- a/spec/mailers/previews/map_activity_mailer_preview.rb +++ b/spec/mailers/previews/map_activity_mailer_preview.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/map_activity_mailer class MapActivityMailerPreview < ActionMailer::Preview def daily_summary @@ -10,100 +11,101 @@ class MapActivityMailerPreview < ActionMailer::Preview end private - def generate_recent_activity_on_map(map) - mapping = nil - mapping2 = nil - mapping3 = nil - mapping4 = nil - mapping5 = nil - mapping6 = nil - mapping7 = nil - mapping8 = nil - mapping9 = nil - mapping10 = nil - Timecop.freeze(2.days.ago) do - mapping = topic_added_to_map(map) - mapping2 = topic_added_to_map(map) - mapping3 = topic_added_to_map(map) - mapping4 = topic_added_to_map(map) - mapping5 = topic_added_to_map(map) - mapping6 = topic_added_to_map(map) - mapping7 = topic_added_to_map(map) - mapping8 = topic_added_to_map(map) - mapping9 = synapse_added_to_map(map, mapping.mappable, mapping2.mappable) - mapping10 = synapse_added_to_map(map, mapping.mappable, mapping8.mappable) - end - Timecop.return + def generate_recent_activity_on_map(map) + mapping = nil + mapping2 = nil + mapping3 = nil + mapping4 = nil + mapping5 = nil + mapping6 = nil + mapping7 = nil + mapping8 = nil + mapping9 = nil + mapping10 = nil - Timecop.freeze(2.hours.ago) do - topic_moved_on_map(mapping7) - topic_moved_on_map(mapping8) - generate_message(map) - generate_message(map) - generate_message(map) - synapse_added_to_map(map, mapping7.mappable, mapping8.mappable) - synapse_added_to_map(map, mapping.mappable, mapping8.mappable) - synapse_removed_from_map(mapping9) - synapse_removed_from_map(mapping10) - end - Timecop.return - - Timecop.freeze(30.minutes.ago) do - topic_removed_from_map(mapping3) - topic_removed_from_map(mapping4) - topic_removed_from_map(mapping5) - topic_removed_from_map(mapping6) - topic_added_to_map(map) - topic_added_to_map(map) - topic_added_to_map(map) - topic_added_to_map(map) - topic_added_to_map(map) - topic_added_to_map(map) - topic_added_to_map(map) - topic_added_to_map(map) - end - Timecop.return + Timecop.freeze(2.days.ago) do + mapping = topic_added_to_map(map) + mapping2 = topic_added_to_map(map) + mapping3 = topic_added_to_map(map) + mapping4 = topic_added_to_map(map) + mapping5 = topic_added_to_map(map) + mapping6 = topic_added_to_map(map) + mapping7 = topic_added_to_map(map) + mapping8 = topic_added_to_map(map) + mapping9 = synapse_added_to_map(map, mapping.mappable, mapping2.mappable) + mapping10 = synapse_added_to_map(map, mapping.mappable, mapping8.mappable) end + Timecop.return - def generate_user - User.create(name: Faker::Name.name, email: Faker::Internet.email, password: "password", password_confirmation: "password", joinedwithcode: 'qwertyui') + Timecop.freeze(2.hours.ago) do + topic_moved_on_map(mapping7) + topic_moved_on_map(mapping8) + generate_message(map) + generate_message(map) + generate_message(map) + synapse_added_to_map(map, mapping7.mappable, mapping8.mappable) + synapse_added_to_map(map, mapping.mappable, mapping8.mappable) + synapse_removed_from_map(mapping9) + synapse_removed_from_map(mapping10) end + Timecop.return - def generate_map - Map.create(name: Faker::HarryPotter.book, permission: 'commons', arranged: false, user: generate_user) + Timecop.freeze(30.minutes.ago) do + topic_removed_from_map(mapping3) + topic_removed_from_map(mapping4) + topic_removed_from_map(mapping5) + topic_removed_from_map(mapping6) + topic_added_to_map(map) + topic_added_to_map(map) + topic_added_to_map(map) + topic_added_to_map(map) + topic_added_to_map(map) + topic_added_to_map(map) + topic_added_to_map(map) + topic_added_to_map(map) end + Timecop.return + end - def topic_added_to_map(map) - user = generate_user - topic = Topic.create(name: Faker::Friends.quote, permission: 'commons', user: user) - mapping = Mapping.create(map: map, mappable: topic, user: user) - end + def generate_user + User.create(name: Faker::Name.name, email: Faker::Internet.email, password: 'password', password_confirmation: 'password', joinedwithcode: 'qwertyui') + end - def topic_moved_on_map(mapping) - meta = { 'x': 10, 'y': 20, 'mapping_id': mapping.id } - Events::TopicMovedOnMap.publish!(mapping.mappable, mapping.map, generate_user, meta) - end + def generate_map + Map.create(name: Faker::HarryPotter.book, permission: 'commons', arranged: false, user: generate_user) + end - def topic_removed_from_map(mapping) - user = generate_user - mapping.updated_by = user - mapping.destroy - end + def topic_added_to_map(map) + user = generate_user + topic = Topic.create(name: Faker::Friends.quote, permission: 'commons', user: user) + mapping = Mapping.create(map: map, mappable: topic, user: user) + end - def synapse_added_to_map(map, topic1, topic2) - user = generate_user - topic = Synapse.create(desc: 'describes', permission: 'commons', user: user, topic1: topic1, topic2: topic2) - mapping = Mapping.create(map: map, mappable: topic, user: user) - end + def topic_moved_on_map(mapping) + meta = { 'x': 10, 'y': 20, 'mapping_id': mapping.id } + Events::TopicMovedOnMap.publish!(mapping.mappable, mapping.map, generate_user, meta) + end - def synapse_removed_from_map(mapping) - user = generate_user - mapping.updated_by = user - mapping.destroy - end + def topic_removed_from_map(mapping) + user = generate_user + mapping.updated_by = user + mapping.destroy + end - def generate_message(map) - Message.create(message: Faker::HarryPotter.quote, resource: map, user: generate_user) - end + def synapse_added_to_map(map, topic1, topic2) + user = generate_user + topic = Synapse.create(desc: 'describes', permission: 'commons', user: user, topic1: topic1, topic2: topic2) + mapping = Mapping.create(map: map, mappable: topic, user: user) + end + + def synapse_removed_from_map(mapping) + user = generate_user + mapping.updated_by = user + mapping.destroy + end + + def generate_message(map) + Message.create(message: Faker::HarryPotter.quote, resource: map, user: generate_user) + end end diff --git a/spec/mailers/previews/map_mailer_preview.rb b/spec/mailers/previews/map_mailer_preview.rb index 9766c0da..c12e0b2b 100644 --- a/spec/mailers/previews/map_mailer_preview.rb +++ b/spec/mailers/previews/map_mailer_preview.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/map_mailer class MapMailerPreview < ActionMailer::Preview def invite_to_edit diff --git a/spec/mailers/previews/topic_mailer_preview.rb b/spec/mailers/previews/topic_mailer_preview.rb index 7ce12b8d..6f8d3edf 100644 --- a/spec/mailers/previews/topic_mailer_preview.rb +++ b/spec/mailers/previews/topic_mailer_preview.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/topic_mailer class TopicMailerPreview < ActionMailer::Preview def added_to_map diff --git a/spec/models/access_request_spec.rb b/spec/models/access_request_spec.rb index 52697698..9d686134 100644 --- a/spec/models/access_request_spec.rb +++ b/spec/models/access_request_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe AccessRequest, type: :model do diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 3f3089cf..9d0f63e9 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe Map, type: :model do diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb index 2f0db8f2..d8bfb775 100644 --- a/spec/models/mapping_spec.rb +++ b/spec/models/mapping_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe Mapping, type: :model do diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb index 49354898..40308c2e 100644 --- a/spec/models/metacode_spec.rb +++ b/spec/models/metacode_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe Metacode, type: :model do diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index c5b63a41..b13f2171 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe Synapse, type: :model do diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index 82582218..53df9fe5 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe Token, type: :model do diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 50e6d74b..28118b01 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe Topic, type: :model do diff --git a/spec/policies/map_policy_spec.rb b/spec/policies/map_policy_spec.rb index c08432dd..8ac8c793 100644 --- a/spec/policies/map_policy_spec.rb +++ b/spec/policies/map_policy_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MapPolicy, type: :policy do diff --git a/spec/policies/mapping_policy_spec.rb b/spec/policies/mapping_policy_spec.rb index 4010e589..ab13d5de 100644 --- a/spec/policies/mapping_policy_spec.rb +++ b/spec/policies/mapping_policy_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe MappingPolicy, type: :policy do diff --git a/spec/policies/synapse_policy.rb b/spec/policies/synapse_policy.rb index 4d9d422c..95ce326b 100644 --- a/spec/policies/synapse_policy.rb +++ b/spec/policies/synapse_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe SynapsePolicy, type: :policy do diff --git a/spec/policies/topic_policy_spec.rb b/spec/policies/topic_policy_spec.rb index ef80e8dc..4df8727d 100644 --- a/spec/policies/topic_policy_spec.rb +++ b/spec/policies/topic_policy_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'rails_helper' RSpec.describe TopicPolicy, type: :policy do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ddf0781c..6a9830fa 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) diff --git a/spec/services/map_activity_service_spec.rb b/spec/services/map_activity_service_spec.rb index fe283e01..d9190015 100644 --- a/spec/services/map_activity_service_spec.rb +++ b/spec/services/map_activity_service_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe MapActivityService do let(:map) { create(:map, created_at: 1.week.ago) } let(:other_user) { create(:user) } let(:email_user) { create(:user) } - let(:empty_response) { {stats:{}} } + let(:empty_response) { { stats: {} } } it 'includes nothing if nothing happened' do response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end describe 'topics added to map' do @@ -47,7 +49,7 @@ RSpec.describe MapActivityService do mapping2 = create(:mapping, user: other_user, map: map, mappable: topic, created_at: 5.hours.ago) Event.where(kind: 'topic_added_to_map').where("meta->>'mapping_id' = ?", mapping2.id.to_s).first.update_columns(created_at: 5.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes a topic added outside the last 24 hours' do @@ -55,7 +57,7 @@ RSpec.describe MapActivityService do mapping = create(:mapping, user: other_user, map: map, mappable: topic, created_at: 25.hours.ago) Event.find_by(kind: 'topic_added_to_map', eventable_id: topic.id).update_columns(created_at: 25.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes topics added by the user who will receive the data' do @@ -103,7 +105,7 @@ RSpec.describe MapActivityService do event = Events::TopicMovedOnMap.publish!(topic, map, other_user, {}) event.update(created_at: 25.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes ones moved by the user who will receive the data' do @@ -112,7 +114,7 @@ RSpec.describe MapActivityService do event = Events::TopicMovedOnMap.publish!(topic, map, email_user, {}) event.update(created_at: 5.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end end @@ -138,7 +140,7 @@ RSpec.describe MapActivityService do mapping.destroy Event.find_by(kind: 'topic_removed_from_map', eventable_id: topic.id).update_columns(created_at: 25.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes topics removed by the user who will receive the data' do @@ -197,7 +199,7 @@ RSpec.describe MapActivityService do mapping2 = create(:mapping, user: other_user, map: map, mappable: synapse, created_at: 5.hours.ago) Event.where(kind: 'synapse_added_to_map').where("meta->>'mapping_id' = ?", mapping2.id.to_s).first.update_columns(created_at: 5.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes a synapse added outside the last 24 hours' do @@ -205,7 +207,7 @@ RSpec.describe MapActivityService do mapping = create(:mapping, user: other_user, map: map, mappable: synapse, created_at: 25.hours.ago) Event.find_by(kind: 'synapse_added_to_map', eventable_id: synapse.id).update_columns(created_at: 25.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes synapses added by the user who will receive the data' do @@ -244,7 +246,7 @@ RSpec.describe MapActivityService do mapping.destroy Event.find_by(kind: 'synapse_removed_from_map', eventable_id: synapse.id).update_columns(created_at: 25.hours.ago) response = MapActivityService.summarize_data(map, email_user) - expect(response).to eq (empty_response) + expect(response).to eq empty_response end it 'excludes synapses removed by the user who will receive the data' do @@ -280,9 +282,7 @@ RSpec.describe MapActivityService do Timecop.return response = MapActivityService.summarize_data(map, email_user) - expect(response[:stats]).to eq({ - topics_added: 1 - }) + expect(response[:stats]).to eq(topics_added: 1) expect(response[:topics_added].map(&:eventable_id)).to include(new_topic.id) expect(response[:topics_added].map(&:eventable_id)).to_not include(new_private_topic.id) end @@ -312,9 +312,7 @@ RSpec.describe MapActivityService do Timecop.return response = MapActivityService.summarize_data(map, email_user) - expect(response[:stats]).to eq({ - topics_removed: 1 - }) + expect(response[:stats]).to eq(topics_removed: 1) expect(response[:topics_removed].map(&:eventable_id)).to include(old_topic.id) expect(response[:topics_removed].map(&:eventable_id)).to_not include(old_private_topic.id) end @@ -334,9 +332,7 @@ RSpec.describe MapActivityService do Timecop.return response = MapActivityService.summarize_data(map, email_user) - expect(response[:stats]).to eq({ - synapses_added: 1 - }) + expect(response[:stats]).to eq(synapses_added: 1) expect(response[:synapses_added].map(&:eventable_id)).to include(new_synapse.id) expect(response[:synapses_added].map(&:eventable_id)).to_not include(new_private_synapse.id) end @@ -366,9 +362,7 @@ RSpec.describe MapActivityService do Timecop.return response = MapActivityService.summarize_data(map, email_user) - expect(response[:stats]).to eq({ - synapses_removed: 1 - }) + expect(response[:stats]).to eq(synapses_removed: 1) expect(response[:synapses_removed].map(&:eventable_id)).to include(old_synapse.id) expect(response[:synapses_removed].map(&:eventable_id)).to_not include(old_private_synapse.id) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3477eb7..1f910a42 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index 1d24b7ca..7b3f5492 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs require 'devise' diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb index 0d10fa34..8a7958c9 100644 --- a/spec/support/factory_girl.rb +++ b/spec/support/factory_girl.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # lets you type create(:user) instead of FactoryGirl.create(:user) RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods diff --git a/spec/support/pundit.rb b/spec/support/pundit.rb index 6e8dc0ce..53813030 100644 --- a/spec/support/pundit.rb +++ b/spec/support/pundit.rb @@ -1,2 +1,3 @@ # frozen_string_literal: true + require 'pundit/rspec' diff --git a/spec/support/schema_matcher.rb b/spec/support/schema_matcher.rb index 998771d9..f0b4a206 100644 --- a/spec/support/schema_matcher.rb +++ b/spec/support/schema_matcher.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec::Matchers.define :match_json_schema do |schema_name| match do |response| schema_directory = Rails.root.join('doc', 'api', 'schemas').to_s diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 1d48d7c8..47d5df0c 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -1,2 +1,3 @@ # frozen_string_literal: true + require 'simplecov'