mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 23:10:37 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
87 lines
2.5 KiB
Ruby
87 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe FormTemplatesController do
|
|
fab!(:user)
|
|
|
|
before { SiteSetting.experimental_form_templates = true }
|
|
|
|
describe "#index" do
|
|
fab!(:form_template)
|
|
fab!(:form_template_2) { Fabricate(:form_template) }
|
|
fab!(:form_template_3) { Fabricate(:form_template) }
|
|
|
|
context "when logged in as a user" do
|
|
before { sign_in(user) }
|
|
|
|
it "should return all form templates ordered by its ids" do
|
|
get "/form-templates.json"
|
|
expect(response.status).to eq(200)
|
|
json = response.parsed_body
|
|
expect(json["form_templates"]).to be_present
|
|
expect(json["form_templates"].length).to eq(3)
|
|
|
|
templates = json["form_templates"].map { |template| template["id"] }
|
|
form_templates = [form_template, form_template_2, form_template_3].sort_by(&:id).map(&:id)
|
|
|
|
expect(templates).to eq(form_templates)
|
|
end
|
|
end
|
|
|
|
context "when you are not logged in" do
|
|
it "should deny access" do
|
|
get "/form-templates.json"
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
|
|
context "when experimental form templates is disabled" do
|
|
before do
|
|
sign_in(user)
|
|
SiteSetting.experimental_form_templates = false
|
|
end
|
|
|
|
it "should not work if you are a logged in user" do
|
|
get "/form-templates.json"
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#show" do
|
|
fab!(:form_template)
|
|
|
|
context "when logged in as a user" do
|
|
before { sign_in(user) }
|
|
|
|
it "should return a single template" do
|
|
get "/form-templates/#{form_template.id}.json"
|
|
expect(response.status).to eq(200)
|
|
json = response.parsed_body
|
|
current_template = json["form_template"]
|
|
expect(current_template["id"]).to eq(form_template.id)
|
|
expect(current_template["name"]).to eq(form_template.name)
|
|
expect(current_template["template"]).to eq(form_template.template)
|
|
end
|
|
end
|
|
|
|
context "when you are not logged in" do
|
|
it "should deny access" do
|
|
get "/form-templates/#{form_template.id}.json"
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
|
|
context "when experimental form templates is disabled" do
|
|
before do
|
|
sign_in(user)
|
|
SiteSetting.experimental_form_templates = false
|
|
end
|
|
|
|
it "should not work if you are a logged in user" do
|
|
get "/form-templates/#{form_template.id}.json"
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
end
|
|
end
|