diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 22a1786d..9c0693de 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -1,35 +1,35 @@ # frozen_string_literal: true class FollowService - + class << self + def follow(entity, user, reason) - def self.follow(entity, user, reason) + return unless is_tester(user) - return unless is_tester(user) - - follow = Follow.where(followed: entity, user: user).first_or_create - if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason) - follow.follow_reason.update_attribute(reason, true) - end - end - - def self.unfollow(entity, user) - Follow.where(followed: entity, user: user).destroy_all - end - - def self.remove_reason(entity, user, reason) - return unless FollowReason::REASONS.include?(reason) - 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 + follow = Follow.where(followed: entity, user: user).first_or_create + if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason) + follow.follow_reason.update_attribute(reason, true) end end - end - - protected - - def is_tester(user) - %w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email) + + def unfollow(entity, user) + Follow.where(followed: entity, user: user).destroy_all + end + + def remove_reason(entity, user, reason) + return unless FollowReason::REASONS.include?(reason) + 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 + end + end + + protected + + def is_tester(user) + %w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email) + end end end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 7abeb2ee..21151ffc 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -2,11 +2,12 @@ require 'rails_helper' RSpec.describe SynapsesController, type: :controller do - let(:synapse) { create(:synapse) } + let(:user) { create(:user) } + let(:synapse) { create(:synapse, user: user, updated_by: user) } let(:valid_attributes) { synapse.attributes.except('id') } let(:invalid_attributes) { { permission: :invalid_lol } } before :each do - sign_in create(:user) + sign_in(user) end describe 'POST #create' do