Skip to content

Commit

Permalink
Added a permission form that supports destroy and id. Fixes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jan 20, 2015
1 parent 5e0fcb6 commit af08f88
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/forms/hydra_editor/form.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -50,7 +53,6 @@ def build_permitted_params
permitted << term
end
end
permitted << { permissions_attributes: [:type, :name, :access] }
permitted
end
end
Expand Down
16 changes: 16 additions & 0 deletions app/forms/hydra_editor/form/permissions.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions spec/forms/hydra_editor_form_permissions_spec.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions spec/forms/hydra_editor_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down

0 comments on commit af08f88

Please sign in to comment.