Sha256: 14a42dc87c5f2db245de08ac7cd5aa1f3297274a721b33021349cb12d84c954a

Contents?: true

Size: 1.31 KB

Versions: 30

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe ActiveFedora::Attributes, ".new" do
  before(:all) do
    class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
      attr_accessor :permitted
      alias permitted? permitted

      def initialize(attributes)
        super(attributes)
        @permitted = false
      end

      def permit!
        @permitted = true
        self
      end

      def dup
        super.tap do |duplicate|
          duplicate.instance_variable_set :@permitted, @permitted
        end
      end
    end

    class Person < ActiveFedora::Base
      property :first_name, predicate: ::RDF::FOAF.firstName, multiple: false
      property :gender, predicate: ::RDF::FOAF.gender, multiple: false
    end
  end

  after(:all) do
    Object.send(:remove_const, :ProtectedParams)
    Object.send(:remove_const, :Person)
  end

  context "forbidden attributes" do
    let(:params) { ProtectedParams.new(first_name: 'Guille', gender: 'm') }
    it "cannot be used for mass assignment" do
      expect { Person.new(params) }.to raise_error ActiveModel::ForbiddenAttributesError
    end
  end

  context "permitted attributes" do
    let(:params) { ProtectedParams.new(first_name: 'Guille', gender: 'm').permit! }
    it "can be used for mass assignment" do
      expect { Person.new(params) }.not_to raise_error
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
active-fedora-10.3.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.7.3 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.3.0.rc2 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.3.0.rc1 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.2.1 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.2.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.1.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.1.0.rc1 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.7.2 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.0.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.0.0.beta4 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.0.0.beta3 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.0.0.beta2 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-10.0.0.beta1 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.13.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.12.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.11.0 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.10.4 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.10.3 spec/unit/forbidden_attributes_protection_spec.rb
active-fedora-9.10.2 spec/unit/forbidden_attributes_protection_spec.rb