module Admin
class CustomEmojisController < BaseController
def index
- @custom_emojis = CustomEmoji.where(domain: nil)
+ @custom_emojis = CustomEmoji.local
end
def new
--- /dev/null
+# frozen_string_literal: true
+
+class Api::V1::CustomEmojisController < Api::BaseController
+ respond_to :json
+
+ def index
+ render json: CustomEmoji.local, each_serializer: REST::CustomEmojiSerializer
+ end
+end
validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { in: 0..50.kilobytes }
validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 }
+ scope :local, -> { where(domain: nil) }
+
include Remotable
class << self
--- /dev/null
+# frozen_string_literal: true
+
+class REST::CustomEmojiSerializer < ActiveModel::Serializer
+ include RoutingHelper
+
+ attributes :shortcode, :url
+
+ def url
+ full_asset_url(object.image.url)
+ end
+end
has_many :media_attachments, serializer: REST::MediaAttachmentSerializer
has_many :mentions
has_many :tags
- has_many :emojis
+ has_many :emojis, serializer: REST::CustomEmojiSerializer
def id
object.id.to_s
tag_url(object)
end
end
-
- class CustomEmojiSerializer < ActiveModel::Serializer
- include RoutingHelper
-
- attributes :shortcode, :url
-
- def url
- full_asset_url(object.image.url)
- end
- end
end
end
resources :streaming, only: [:index]
+ resources :custom_emojis, only: [:index]
get '/search', to: 'search#index', as: :search
--- /dev/null
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Api::V1::CustomEmojisController, type: :controller do
+ render_views
+
+ describe 'GET #index' do
+ before do
+ Fabricate(:custom_emoji)
+ get :index
+ end
+
+ it 'returns http success' do
+ expect(response).to have_http_status(:success)
+ end
+ end
+end