[deploy] Add LiquidTagsController (#10241)

This commit is contained in:
Michael Kohl 2020-09-08 23:07:33 +07:00 committed by GitHub
parent 2d881ef571
commit 729a17a7a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,13 @@
class LiquidTagsController < ApplicationController
before_action :authenticate_user!
FILTER_REGEX = /^(?:NullTag|Liquid::)/.freeze
def index
custom_tags = Liquid::Template.tags.filter_map do |name, tag|
name unless tag.match?(FILTER_REGEX)
end.sort
render json: { liquid_tags: custom_tags }
end
end

View file

@ -284,6 +284,8 @@ Rails.application.routes.draw do
resources :profiles, only: %i[update]
resources :profile_field_groups, only: %i[index], defaults: { format: :json }
resources :liquid_tags, only: %i[index], defaults: { format: :json }
get "/verify_email_ownership", to: "email_authorizations#verify", as: :verify_email_authorizations
get "/search/tags" => "search#tags"
get "/search/chat_channels" => "search#chat_channels"

View file

@ -0,0 +1,28 @@
require "rails_helper"
RSpec.describe "LiquidTags", type: :request do
describe "GET /liquid_tags" do
context "when not signed in do" do
it "returns a list of all custom Liquid tags" do
get liquid_tags_path
expect(response).to have_http_status(:unauthorized)
end
end
context "when signed in" do
let(:user) { create(:user) }
before { sign_in(user) }
it "returns an array of all custom Liquid tags", :aggregate_failures do
get liquid_tags_path
expect(response).to have_http_status(:ok)
json = response.parsed_body
expect(json["liquid_tags"]).to be_an_instance_of(Array)
expect(json["liquid_tags"]).not_to be_empty
end
end
end
end