[deploy] Add LiquidTagsController (#10241)
This commit is contained in:
parent
2d881ef571
commit
729a17a7a3
3 changed files with 43 additions and 0 deletions
13
app/controllers/liquid_tags_controller.rb
Normal file
13
app/controllers/liquid_tags_controller.rb
Normal 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
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
28
spec/requests/liquid_tags_request_spec.rb
Normal file
28
spec/requests/liquid_tags_request_spec.rb
Normal 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
|
||||
Loading…
Add table
Reference in a new issue