Sha256: 28013dbe64476d026d2b635ef27fc088186eda2e5771b87182942b6b1837c744

Contents?: true

Size: 1.75 KB

Versions: 38

Compression:

Stored size: 1.75 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class AllowMassAssignmentOfMatcherTest < ActiveSupport::TestCase # :nodoc:

  context "an attribute that is blacklisted from mass-assignment" do
    setup do
      define_model :example, :attr => :string do
        attr_protected :attr
      end
      @model = Example.new
    end

    should "reject being mass-assignable" do
      assert_rejects allow_mass_assignment_of(:attr), @model
    end
  end

  context "an attribute that is not whitelisted for mass-assignment" do
    setup do
      define_model :example, :attr => :string, :other => :string do
        attr_accessible :other
      end
      @model = Example.new
    end

    should "reject being mass-assignable" do
      assert_rejects allow_mass_assignment_of(:attr), @model
    end
  end

  context "an attribute that is whitelisted for mass-assignment" do
    setup do
      define_model :example, :attr => :string do
        attr_accessible :attr
      end
      @model = Example.new
    end

    should "accept being mass-assignable" do
      assert_accepts allow_mass_assignment_of(:attr), @model
    end
  end

  context "an attribute not included in the mass-assignment blacklist" do
    setup do
      define_model :example, :attr => :string, :other => :string do
        attr_protected :other
      end
      @model = Example.new
    end

    should "accept being mass-assignable" do
      assert_accepts allow_mass_assignment_of(:attr), @model
    end
  end

  context "an attribute on a class with no protected attributes" do
    setup do
      define_model :example, :attr => :string
      @model = Example.new
    end

    should "accept being mass-assignable" do
      assert_accepts allow_mass_assignment_of(:attr), @model
    end
  end

end

Version data entries

38 entries across 38 versions & 10 rubygems

Version Path
thoughtbot-shoulda-2.10.2 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
lockbox_middleware-1.2.1 vendor/gems/shoulda-2.10.2/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
robert-shoulda-2.10.4 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
robert-shoulda-2.10.3 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/shoulda-2.10.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/shoulda-2.10.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
shoulda-2.10.3 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
tpitale-shoulda-2.11.0 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
shoulda-2.10.2 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.15 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.14 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.13 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.8 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.7 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.6 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.4 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.3 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
poolparty-1.3.1 vendor/gems/shoulda/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb