Sha256: cba47c500c6567361acbebac8cf42819a53750be1b2bc0679eeec5068c0dd05d

Contents?: true

Size: 1.89 KB

Versions: 91

Compression:

Stored size: 1.89 KB

Contents

require '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

    should "assign a negative failure message" do
      matcher = allow_mass_assignment_of(:attr)
      matcher.matches?(@model)
      assert_not_nil matcher.negative_failure_message
    end
  end

end

Version data entries

91 entries across 61 versions & 10 rubygems

Version Path
challah-0.5.4 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.5.3 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.5.2 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.2 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.2 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.5.1 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.5.0 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.1 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.1 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.0 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
dirty_history-0.5.0 dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/dirty_history-0.2.0/dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.4.1 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.4.0 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.3.5 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
faster_shoulda-2.11.4 test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
challah-0.3.4 vendor/bundle/gems/shoulda-2.11.3/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb