diff --git a/app/forms/hydra_editor/form.rb b/app/forms/hydra_editor/form.rb index eabd9fa..888c54b 100644 --- a/app/forms/hydra_editor/form.rb +++ b/app/forms/hydra_editor/form.rb @@ -1,6 +1,9 @@ module HydraEditor module Form + extend ActiveSupport::Autoload + autoload :Permissions extend ActiveSupport::Concern + include Hydra::Presenter included do class_attribute :required_fields @@ -50,7 +53,6 @@ def build_permitted_params permitted << term end end - permitted << { permissions_attributes: [:type, :name, :access] } permitted end end diff --git a/app/forms/hydra_editor/form/permissions.rb b/app/forms/hydra_editor/form/permissions.rb new file mode 100644 index 0000000..200e053 --- /dev/null +++ b/app/forms/hydra_editor/form/permissions.rb @@ -0,0 +1,16 @@ +module HydraEditor + module Form + module Permissions + extend ActiveSupport::Concern + + module ClassMethods + + def build_permitted_params + permitted = super + permitted << { permissions_attributes: [:type, :name, :access, :id, :_destroy] } + permitted + end + end + end + end +end diff --git a/spec/forms/hydra_editor_form_permissions_spec.rb b/spec/forms/hydra_editor_form_permissions_spec.rb new file mode 100644 index 0000000..9beeb29 --- /dev/null +++ b/spec/forms/hydra_editor_form_permissions_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe HydraEditor::Form::Permissions do + class TestModel < ActiveFedora::Base + property :title, predicate: ::RDF::DC.title + property :creator, predicate: ::RDF::DC.creator, multiple: false + end + + class TestForm + include HydraEditor::Form + include HydraEditor::Form::Permissions + self.model_class = TestModel + # Terms is the list of fields displayed by app/views/records/_form.html.erb + self.terms = [:title, :creator] + end + + describe "model_attributes" do + let(:params) { ActionController::Parameters.new(title: [''], creator: 'bob', description: ['huh'], permissions_attributes: {'0' => { id: '123', _destroy: 'true' }}) } + subject { TestForm.model_attributes(params) } + + it { is_expected.to eq('creator' => 'bob', 'title' => [], + 'permissions_attributes' => { '0' => { 'id' => '123', '_destroy' => 'true' } }) } + end +end diff --git a/spec/forms/hydra_editor_form_spec.rb b/spec/forms/hydra_editor_form_spec.rb index 07064db..df542da 100644 --- a/spec/forms/hydra_editor_form_spec.rb +++ b/spec/forms/hydra_editor_form_spec.rb @@ -16,6 +16,13 @@ class TestForm describe "class methods" do subject { TestForm.model_name } it { is_expected.to eq 'TestModel' } + + describe "model_attributes" do + let(:params) { ActionController::Parameters.new(title: [''], creator: 'bob', description: ['huh']) } + subject { TestForm.model_attributes(params) } + + it { is_expected.to eq('creator' => 'bob', 'title' => []) } + end end let(:object) { TestModel.new(title: ['foo', 'bar'], creator: 'baz') }