Sha256: 5acba4598e8c2c3f9f6dc0c97e555f421c2f3c95756e19948321828421f34486

Contents?: true

Size: 1.26 KB

Versions: 12

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'
require 'dm-rails/mass_assignment_security'

# Because mass-assignment security is based on ActiveModel we just have to
# ensure that ActiveModel is called.
describe DataMapper::MassAssignmentSecurity do
  before :all do
    class Fake
      super_module = Module.new do
        def _super_attributes=(*args)
        end

        def attributes=(*args)
          self.send(:_super_attributes=, *args)
        end
      end
      include super_module

      include ::DataMapper::MassAssignmentSecurity
    end
  end

  describe '#attributes=' do
    it 'calls super with sanitized attributes' do
      attributes = { :name => 'John', :is_admin => true }
      sanitized_attributes = { :name => 'John' }
      model = Fake.new
      model.should_receive(:sanitize_for_mass_assignment).with(attributes).and_return(sanitized_attributes)
      model.should_receive(:_super_attributes=).with(sanitized_attributes)

      model.attributes = attributes
    end

    it 'skips sanitation when called with true' do
      attributes = { :name => 'John', :is_admin => true }
      sanitized_attributes = { :name => 'John' }
      model = Fake.new
      model.should_receive(:_super_attributes=).with(attributes)

      model.send(:attributes=, attributes, true)
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
ardm-rails-1.2.1 spec/unit/mass_assignment_security_spec.rb
tpitale-dm-rails-1.3.0 spec/unit/mass_assignment_security_spec.rb
tpitale-dm-rails-1.2.2 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.2.1 spec/unit/mass_assignment_security_spec.rb
tpitale-dm-rails-1.2.1 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.2.0 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.2.0.rc2 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.2.0.rc1 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.1.0 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.1.0.rc3 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.1.0.rc2 spec/unit/mass_assignment_security_spec.rb
dm-rails-1.1.0.rc1 spec/unit/mass_assignment_security_spec.rb