Skip to content

Commit

Permalink
Remove minitests
Browse files Browse the repository at this point in the history
  • Loading branch information
tclaus committed May 28, 2023
1 parent 10655c5 commit 94fcd7d
Show file tree
Hide file tree
Showing 101 changed files with 163 additions and 1,758 deletions.
179 changes: 91 additions & 88 deletions app/models/user/querying.rb
Original file line number Diff line number Diff line change
@@ -1,112 +1,115 @@
# frozen_string_literal: true

module User::Querying
def find_visible_shareable_by_id(klass, id, opts={})
key = (opts.delete(:key) || :id)
find_visible_shareable_by_id = EvilQuery::VisibleShareableById.new(self, klass, key, id, opts)
find_visible_shareable_by_id.post!
end
class User
module Querying
def find_visible_shareable_by_id(klass, id, opts={})
key = (opts.delete(:key) || :id)
find_visible_shareable_by_id = EvilQuery::VisibleShareableById.new(self, klass, key, id, opts)
find_visible_shareable_by_id.post!
end

def visible_shareables(klass, opts={})
opts = prep_opts(klass, opts)
shareable_ids = visible_shareable_ids(klass, opts)
klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*")
.limit(opts[:limit]).order(opts[:order_with_table])
end
def visible_shareables(klass, opts={})
opts = prep_opts(klass, opts)
shareable_ids = visible_shareable_ids(klass, opts)
klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*")
.limit(opts[:limit]).order(opts[:order_with_table])
end

# @param [TrueClass] with_order
def posts_from(person, with_order: true)
base_query = Post.from_person_visible_by_user(self, person)
return base_query.order("posts.created_at desc") if with_order
# @param [TrueClass] with_order
def posts_from(person, with_order: true)
base_query = Post.from_person_visible_by_user(self, person)
return base_query.order("posts.created_at desc") if with_order

base_query
end
base_query
end

def photos_from(person, opts={})
opts = prep_opts(Photo, opts)
Photo.from_person_visible_by_user(self, person)
.limit(opts[:limit])
end
def photos_from(person, opts={})
opts = prep_opts(Photo, opts)
Photo.from_person_visible_by_user(self, person)
.limit(opts[:limit])
end

def contact_for(person)
return nil unless person
def contact_for(person)
return nil unless person

contact_for_person_id(person.id)
end
contact_for_person_id(person.id)
end

def block_for(person)
return nil unless person
blocks.find_by(person_id: person.id)
end
def block_for(person)
return nil unless person

def aspects_with_shareable(base_class_name_or_class, shareable_id)
base_class_name = base_class_name_or_class
base_class_name = base_class_name_or_class.base_class.to_s if base_class_name_or_class.is_a?(Class)
self.aspects.joins(:aspect_visibilities).where(:aspect_visibilities => {:shareable_id => shareable_id, :shareable_type => base_class_name})
end
blocks.find_by(person_id: person.id)
end

def contact_for_person_id(person_id)
Contact.includes(person: :profile)
.find_by(user_id: id, person_id: person_id)
end
def aspects_with_shareable(base_class_name_or_class, shareable_id)
base_class_name = base_class_name_or_class
base_class_name = base_class_name_or_class.base_class.to_s if base_class_name_or_class.is_a?(Class)
aspects.joins(:aspect_visibilities).where(aspect_visibilities: {shareable_id: shareable_id,
shareable_type: base_class_name})
end

def contact_for_person_id(person_id)
Contact.includes(person: :profile)
.find_by(user_id: id, person_id: person_id)
end

# @param [Person] person
# @return [Boolean] whether person is a contact of this user
def has_contact_for?(person)
Contact.exists?(:user_id => self.id, :person_id => person.id)
end
# @param [Person] person
# @return [Boolean] whether person is a contact of this user
def has_contact_for?(person)
Contact.exists?(user_id: id, person_id: person.id)
end

def people_in_aspects(requested_aspects, opts={})
allowed_aspects = self.aspects & requested_aspects
aspect_ids = allowed_aspects.map(&:id)
def people_in_aspects(requested_aspects, opts={})
allowed_aspects = aspects & requested_aspects
aspect_ids = allowed_aspects.map(&:id)

people = Person.in_aspects(aspect_ids)
people = Person.in_aspects(aspect_ids)

if opts[:type] == 'remote'
people = people.where(:owner_id => nil)
elsif opts[:type] == 'local'
people = people.where('people.owner_id IS NOT NULL')
if opts[:type] == "remote"
people = people.where(owner_id: nil)
elsif opts[:type] == "local"
people = people.where.not(people: {owner_id: nil})
end
people
end
people
end

def aspects_with_person(person)
contact_for(person).aspects
end
def aspects_with_person(person)
contact_for(person).aspects
end

def posts_from(person, with_order=true)
base_query = Post.from_person_visible_by_user(self, person)
return base_query.order("posts.created_at desc") if with_order
def posts_from(person, with_order=true)
base_query = Post.from_person_visible_by_user(self, person)
return base_query.order("posts.created_at desc") if with_order

base_query
end
base_query
end

def photos_from(person, opts={})
opts = prep_opts(Photo, opts)
Photo.from_person_visible_by_user(self, person)
.by_max_time(opts[:max_time])
.limit(opts[:limit])
end
def photos_from(person, opts={})
opts = prep_opts(Photo, opts)
Photo.from_person_visible_by_user(self, person)
.by_max_time(opts[:max_time])
.limit(opts[:limit])
end

protected

# @return [Hash]
def prep_opts(klass, opts)
defaults = {
order: "created_at DESC",
limit: 15,
hidden: false
}
defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post
opts = defaults.merge(opts)
opts.delete(:limit) if opts[:limit] == :all

opts[:order_field] = opts[:order].split.first.to_sym
opts[:order_with_table] = "#{klass.table_name}.#{opts[:order]}"

opts[:max_time] = Time.zone.at(opts[:max_time]) if opts[:max_time].is_a?(Integer)
opts[:max_time] ||= Time.zone.now + 1
opts
protected

# @return [Hash]
def prep_opts(klass, opts)
defaults = {
order: "created_at DESC",
limit: 15,
hidden: false
}
defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post
opts = defaults.merge(opts)
opts.delete(:limit) if opts[:limit] == :all

opts[:order_field] = opts[:order].split.first.to_sym
opts[:order_with_table] = "#{klass.table_name}.#{opts[:order]}"

opts[:max_time] = Time.zone.at(opts[:max_time]) if opts[:max_time].is_a?(Integer)
opts[:max_time] ||= Time.zone.now + 1
opts
end
end
end
100 changes: 51 additions & 49 deletions app/models/user/social_actions.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,71 @@
# frozen_string_literal: true

module User::SocialActions
def comment!(target, text, opts={})
Comment::Generator.new(self, target, text).create!(opts).tap do
update_or_create_participation!(target)
class User
module SocialActions
def comment!(target, text, opts={})
Comment::Generator.new(self, target, text).create!(opts).tap do
update_or_create_participation!(target)
end
end
end

def participate!(target, opts={})
Participation::Generator.new(self, target).create!(opts)
end
def participate!(target, opts={})
Participation::Generator.new(self, target).create!(opts)
end

def like!(target, opts={})
Like::Generator.new(self, target).create!(opts).tap do
update_or_create_participation!(target)
def like!(target, opts={})
Like::Generator.new(self, target).create!(opts).tap do
update_or_create_participation!(target)
end
end
end

def like_comment!(target, opts={})
Like::Generator.new(self, target).create!(opts)
end
def like_comment!(target, opts={})
Like::Generator.new(self, target).create!(opts)
end

def participate_in_poll!(target, answer, opts={})
PollParticipation::Generator.new(self, target, answer).create!(opts).tap do
update_or_create_participation!(target)
def participate_in_poll!(target, answer, opts={})
PollParticipation::Generator.new(self, target, answer).create!(opts).tap do
update_or_create_participation!(target)
end
end
end

def reshare!(target, opts={})
raise I18n.t("reshares.create.error") if target.author.guid == guid
def reshare!(target, opts={})
raise I18n.t("reshares.create.error") if target.author.guid == guid

build_post(:reshare, root_guid: target.guid).tap do |reshare|
reshare.text = opts[:text]
reshare.save!
update_or_create_participation!(target)
Diaspora::Federation::Dispatcher.defer_dispatch(self, reshare)
build_post(:reshare, root_guid: target.guid).tap do |reshare|
reshare.text = opts[:text]
reshare.save!
update_or_create_participation!(target)
Diaspora::Federation::Dispatcher.defer_dispatch(self, reshare)
end
end
end

def build_conversation(opts={})
Conversation.new do |c|
c.author = person
c.subject = opts[:subject]
c.participant_ids = [*opts[:participant_ids]] | [person_id]
c.messages_attributes = [
{author: person, text: opts[:message][:text]}
]
def build_conversation(opts={})
Conversation.new do |c|
c.author = person
c.subject = opts[:subject]
c.participant_ids = [*opts[:participant_ids]] | [person_id]
c.messages_attributes = [
{author: person, text: opts[:message][:text]}
]
end
end
end

def build_message(conversation, opts={})
conversation.messages.build(
text: opts[:text],
author: person
)
end
def build_message(conversation, opts={})
conversation.messages.build(
text: opts[:text],
author: person
)
end

def update_or_create_participation!(target)
return if target.author == person
def update_or_create_participation!(target)
return if target.author == person

participation = participations.find_by(target_id: target)
if participation.present?
participation.update!(count: participation.count.next)
else
participate!(target)
participation = participations.find_by(target_id: target)
if participation.present?
participation.update!(count: participation.count.next)
else
participate!(target)
end
end
end
end
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = false

# for fixture_builder
ENV["FIXTURES_PATH"] = "spec/fixtures"
end
File renamed without changes.
6 changes: 2 additions & 4 deletions spec/models/user/connecting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

require 'rails_helper'

describe User::Connecting, type: :model do
let(:aspect1) { alice.aspects.first }
let(:aspect2) { alice.aspects.create(name: "other") }
Expand Down Expand Up @@ -98,7 +96,7 @@
local_leia.disconnect(contact)
end

it "should remove the contact from all aspects they are in" do
it "removes the contact from all aspects they are in" do
contact = alice.contact_for(bob.person)
alice.add_contact_to_aspect(contact, aspect2)

Expand Down Expand Up @@ -201,7 +199,7 @@
expect(alice.contact_for(eve.person)).to be_receiving
end

it "should mark the corresponding notification as 'read'" do
it "marks the corresponding notification as 'read'" do
FactoryBot.create(:notification, target: eve.person, recipient: alice, type: "Notifications::StartedSharing")
expect(Notifications::StartedSharing.find_by(recipient_id: alice.id, target: eve.person).unread).to be_truthy

Expand Down
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require "spec_helper"

ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
Expand All @@ -13,6 +12,8 @@

require "rspec/rails"

require "spec_helper"

# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def peter
$process_queue = false
end

config.fixture_path = Rails.root.join("spec", "fixtures")
config.global_fixtures = :all

# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
Expand Down
Loading

0 comments on commit 94fcd7d

Please sign in to comment.