Sha256: b987da60122bb869854bc2398f019ed374a41e11eabc425dd522f20ff633302f

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe Sufia::Forms::GenericFileEditForm do
  subject { described_class.new(GenericFile.new) }

  describe "#terms" do
    it "should return a list" do
      expect(subject.terms).to eq([:resource_type, :title, :creator, :contributor, :description, :tag,
                    :rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url])
    end

    it "doesn't contain fields that users shouldn't be allowed to edit" do
      # date_uploaded is reserved for the original creation date of the record.
      expect(subject.terms).not_to include(:date_uploaded)
    end
  end

  it "should initialize multivalued fields" do
    expect(subject.title).to eq ['']
  end

  describe ".model_attributes" do
    let(:params) { ActionController::Parameters.new(title: ['foo'], description: [''], "permissions_attributes"=>{"2"=>{"access"=>"edit", "_destroy"=>"true", "id"=>"a987551e-b87f-427a-8721-3e5942273125"}})}
    subject { described_class.model_attributes(params) }

    it "should only change title" do
      expect(subject['title']).to eq ["foo"]
      expect(subject['description']).to be_empty
      expect(subject['permissions_attributes']).to eq("2" => {"access"=>"edit", "id"=>"a987551e-b87f-427a-8721-3e5942273125", "_destroy"=>"true"})
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sufia-6.2.0 spec/forms/generic_file_edit_form_spec.rb
sufia-6.1.0 spec/forms/generic_file_edit_form_spec.rb
sufia-6.0.0 spec/forms/generic_file_edit_form_spec.rb
sufia-6.0.0.rc4 spec/forms/generic_file_edit_form_spec.rb
sufia-6.0.0.rc3 spec/forms/generic_file_edit_form_spec.rb