mirror of https://github.com/mastodon/mastodon
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
Ruby
61 lines
1.6 KiB
Ruby
4 years ago
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'rails_helper'
|
||
|
|
||
7 months ago
|
RSpec.describe PreloadingConcern do
|
||
4 years ago
|
controller(ApplicationController) do
|
||
7 months ago
|
include PreloadingConcern
|
||
4 years ago
|
|
||
|
def empty_array
|
||
7 months ago
|
render plain: preload_collection([], Status).size
|
||
4 years ago
|
end
|
||
|
|
||
|
def empty_relation
|
||
7 months ago
|
render plain: preload_collection(Status.none, Status).size
|
||
4 years ago
|
end
|
||
1 year ago
|
|
||
|
def account_statuses_favourites
|
||
7 months ago
|
render plain: preload_collection(Status.where(account_id: params[:id]), Status).map(&:favourites_count)
|
||
1 year ago
|
end
|
||
4 years ago
|
end
|
||
|
|
||
|
before do
|
||
|
routes.draw do
|
||
1 year ago
|
get 'empty_array' => 'anonymous#empty_array'
|
||
|
get 'empty_relation' => 'anonymous#empty_relation'
|
||
|
get 'account_statuses_favourites' => 'anonymous#account_statuses_favourites'
|
||
4 years ago
|
end
|
||
|
end
|
||
|
|
||
7 months ago
|
describe '#preload_collection' do
|
||
2 years ago
|
context 'when given an empty array' do
|
||
4 years ago
|
it 'returns an empty array' do
|
||
|
get :empty_array
|
||
|
expect(response.body).to eq '0'
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context 'when given an empty relation' do
|
||
4 years ago
|
it 'returns an empty array' do
|
||
|
get :empty_relation
|
||
|
expect(response.body).to eq '0'
|
||
|
end
|
||
|
end
|
||
1 year ago
|
|
||
|
context 'when given a collection of statuses' do
|
||
|
let!(:account) { Fabricate(:account) }
|
||
|
let!(:status) { Fabricate(:status, account: account) }
|
||
|
|
||
|
it 'correctly updates with new interactions' do
|
||
|
get :account_statuses_favourites, params: { id: account.id }
|
||
|
expect(response.body).to eq '[0]'
|
||
|
|
||
|
FavouriteService.new.call(account, status)
|
||
|
|
||
|
get :account_statuses_favourites, params: { id: account.id }
|
||
|
expect(response.body).to eq '[1]'
|
||
|
end
|
||
|
end
|
||
4 years ago
|
end
|
||
|
end
|