Sha256: f2a9e943a65a2ddb5677e8872ed5b1cb960b22f810f41c05596d32b70c34c5cf

Contents?: true

Size: 673 Bytes

Versions: 17

Compression:

Stored size: 673 Bytes

Contents

shared_examples_for 'ActiveRecord-like mass assignment' do |attributes|

  it 'assigns all given attributes' do
    subject.attributes = attributes

    attributes.each do |key, value|
      subject.send(key).should == value
    end
  end

  if ActiveRecord::VERSION::MAJOR >= 4

    it 'raises on unpermitted parameters' do
      params = ProtectedParams.new(attributes)
      expect { subject.attributes = params }.to raise_error(ActiveModel::ForbiddenAttributesError)
    end

    it 'accepts permitted parameters' do
      params = ProtectedParams.new(attributes)
      params.permit!
      expect { subject.attributes = params }.to_not raise_error
    end

  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_type-0.4.4 spec/shared_examples/mass_assignment.rb
active_type-0.4.3 spec/shared_examples/mass_assignment.rb
active_type-0.4.2 spec/shared_examples/mass_assignment.rb
active_type-0.4.1 spec/shared_examples/mass_assignment.rb
active_type-0.4.0 spec/shared_examples/mass_assignment.rb
active_type-0.3.5 spec/shared_examples/mass_assignment.rb
active_type-0.3.4 spec/shared_examples/mass_assignment.rb
active_type-0.3.3 spec/shared_examples/mass_assignment.rb
active_type-0.3.2 spec/shared_examples/mass_assignment.rb
active_type-0.3.1 spec/shared_examples/mass_assignment.rb
active_type-0.3.0 spec/shared_examples/mass_assignment.rb
active_type-0.2.1 spec/shared_examples/mass_assignment.rb
active_type-0.2.0 spec/shared_examples/mass_assignment.rb
active_type-0.1.3 spec/shared_examples/mass_assignment.rb
active_type-0.1.2 spec/shared_examples/mass_assignment.rb
active_type-0.1.1 spec/shared_examples/mass_assignment.rb
active_type-0.1.0 spec/shared_examples/mass_assignment.rb