Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/iron
20.19.4
2 changes: 1 addition & 1 deletion app/views/admin/services/editors/_custom-fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% meta = s.object.meta.find_or_initialize_by(label: field.label) %>
<%= s.fields_for :meta, meta do |c| %>
<%= c.hidden_field :label %>
<%= c.hidden_field :key %>
<%= c.hidden_field :key, value: field.key %>

<% if field.field_type === "checkbox" %>
<div class="field">
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/custom_field_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
factory :custom_field_section do
name { Faker::Lorem.sentence }
end

trait :expose_in_public_api do
api_public { true }
end
end
31 changes: 31 additions & 0 deletions spec/features/using_custom_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,35 @@
end
end

context 'as a super admin' do
before do
admin_user = FactoryBot.create :user, :superadmin
login_as admin_user
visit root_path
end

scenario 'I can create and use custom fields for services with a key', js: true do
service = FactoryBot.create :service
custom_field_section = FactoryBot.create :custom_field_section, :expose_in_public_api
date = Date.today

click_link 'Services'
click_link 'Custom fields'
click_link custom_field_section.name
click_link 'Add a field'
expect(page).to have_content 'This is a unique field used to refer to this field in the API.'
fill_in('Label', with: 'Custom date')
fill_in('Key', with: 'Custom date')
select 'Date', from: 'Field type'
click_link_or_button 'Update'
expect(page).to have_content 'Fields have been updated'
expect(find_field('Key').value).to eq 'custom-date'

visit admin_services_path
click_link service.name
fill_in 'Custom date', with: date
expect(page).to have_field('Custom date', type: 'date', with: date)
end
end

end