Sha256: e2798ca841316d35a5228fb3575155aca5d63560347c66e65c6ead8a46efe7ec

Contents?: true

Size: 1.65 KB

Versions: 17

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

begin
  require 'rack/test'
  require 'active_model/forbidden_attributes_protection'
  require 'action_controller/metal/strong_parameters'

  describe 'forbidden attributes protection' do
    context 'when initializing a new object' do
      it 'raises an error when passing non-permitted attributes' do
        expect {
          Child.new ActionController::Parameters.new(:text => 'xx')
        }.to raise_error(ActiveModel::ForbiddenAttributesError)
      end

      it 'raises no error when passing permitted attributes' do
        expect {
          Child.new ActionController::Parameters.new(:text => 'xx').permit!
        }.to_not raise_error
      end

      it "raises no error when passing attributes that don't respond to permitted?" do
        expect {
          Child.new :text => 'xx'
        }.to_not raise_error
      end
    end

    context 'when mass-assigning attributes to an object' do
      let(:subject) {Child.new}

      it 'raises an error when passing non-permitted attributes' do
        expect {
          subject.attributes = ActionController::Parameters.new(:text => 'xx')
        }.to raise_error(ActiveModel::ForbiddenAttributesError)
      end

      it 'raises no error when passing permitted attributes' do
        expect {
          subject.attributes = ActionController::Parameters.new(:text => 'xx').permit!
        }.to_not raise_error
      end

      it "raises no error when passing attributes that don't respond to permitted?" do
        expect {
          subject.attributes = {:text => 'xx'}
        }.to_not raise_error
      end
    end
  end
rescue LoadError
  puts "Skipping forbidden attributes protection specs."
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
couch_potato-1.18.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.17.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.16.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.15.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.14.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.13.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.12.1 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.12.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.11.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.10.1 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.10.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.9.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.7.1 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.7.0 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.6.5 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.6.4 spec/unit/forbidden_attributes_protection_spec.rb
couch_potato-1.6.3 spec/unit/forbidden_attributes_protection_spec.rb