0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 01:40:29 +01:00
discourse-custom-wizard/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb
Angus McLeod 35021eb176 DEV: Integrate subscription gem classes in rspec suite
I've tweaked the subscription client gem so we can just use the gem's models and tables in this plugin's rspec, which makes duplicating and stubbing them unnecessary.

See further https://github.com/paviliondev/discourse_subscription_client
2023-11-25 13:16:55 +01:00

33 Zeilen
1,1 KiB
Ruby

# frozen_string_literal: true
describe CustomWizard::FieldSerializer do
fab!(:user) { Fabricate(:user) }
let(:template) { get_wizard_fixture("wizard") }
before do
CustomWizard::Template.save(template, skip_jobs: true)
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
end
it "should return basic field attributes" do
json_array = ActiveModel::ArraySerializer.new(
@wizard.steps.first.fields,
each_serializer: CustomWizard::FieldSerializer,
scope: Guardian.new(user)
).as_json
expect(json_array.size).to eq(@wizard.steps.first.fields.size)
expect(json_array[0][:label]).to eq("<p>Text</p>")
expect(json_array[0][:description]).to eq("Text field description.")
expect(json_array[2][:index]).to eq(2)
end
it "should return optional field attributes" do
json_array = ActiveModel::ArraySerializer.new(
@wizard.steps.second.fields,
each_serializer: CustomWizard::FieldSerializer,
scope: Guardian.new(user)
).as_json
expect(json_array[0][:format]).to eq("YYYY-MM-DD")
end
end