Sha256: 0e0a3b6cb5be85d518ebbdddb94e83bdfb986c8044a965fa0d798c282edafa1e

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require 'test_helper'

class AttrInitializableTest < ActiveSupport::TestCase
  test 'default role cannot mass-assign manufacturer at creation time' do
    manufacturer = Manufacturer.create
    assert_raise ActiveModel::MassAssignmentSecurity::Error do
      Widget.new({ :manufacturer_id => manufacturer.id }, :as => :default)
    end
  end

  test 'admin role can mass-assign manufacturer at creation time' do
    manufacturer = Manufacturer.create
    widget = Widget.new({ :manufacturer_id => manufacturer.id }, :as => :admin)
    assert_equal manufacturer, widget.manufacturer
  end

  test 'default role cannot mass-assign manufacturer at update time' do
    manufacturer = Manufacturer.create
    widget = Widget.new(:name => 'name')
    widget.manufacturer = manufacturer
    widget.save!
    assert_equal manufacturer, widget.manufacturer

    assert_raise ActiveModel::MassAssignmentSecurity::Error do
      widget.update_attributes({ :manufacturer_id => Manufacturer.create.id }, :as => :default)
    end
    assert_equal manufacturer, widget.manufacturer
  end

  test 'admin role cannot mass-assign manufacturer at update time' do
    manufacturer = Manufacturer.create
    widget = Widget.new(:name => 'name')
    widget.manufacturer = manufacturer
    widget.save!
    assert_equal manufacturer, widget.manufacturer

    assert_raise ActiveModel::MassAssignmentSecurity::Error do
      widget.update_attributes({ :manufacturer_id => Manufacturer.create.id }, :as => :admin)
    end
    assert_equal manufacturer, widget.manufacturer
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attr_initializable-0.0.2 test/attr_initializable_test.rb
attr_initializable-0.0.1 test/attr_initializable_test.rb