Sha256: cfb03fc4dbaffaa2e908a28604008b5d01265a4f65080abf99db27a9b20ee8e6

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helpers/boot'

if defined?(Rails)
  describe Protector::Engine do
    before(:all) do
      Combustion.initialize! :active_record do
        config.protector.paranoid = true
        config.action_controller.action_on_unpermitted_parameters = :raise
      end

      Protector.activate!

      unless Protector::Adapters::ActiveRecord.modern?
        ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
        ActiveRecord::Base.send(:include, Protector::ActiveRecord::StrongParameters)
      end
    end

    after(:all) do
      Protector.config.paranoid = false
    end

  	it "inherits Rails config" do
      Protector.config.paranoid?.should == true
      Protector.config.strong_parameters?.should == true
    end

    describe "strong_parameters" do
      before(:all) do
        load 'migrations/active_record.rb'

        Dummy.instance_eval do
          protect do
            can :create, :string
            can :update, :number
          end
        end
      end

      def params(*args)
        ActionController::Parameters.new *args
      end

      it "creates" do
        expect{ Dummy.restrict!.new params(string: 'test') }.to_not raise_error
        expect{ Dummy.restrict!.new params(number: 1) }.to raise_error
      end

      it "updates" do
        dummy = Dummy.create!

        expect{ dummy.restrict!.assign_attributes params(string: 'test') }.to raise_error
        expect{ dummy.restrict!.assign_attributes params(number: 1) }.to_not raise_error
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
protector-0.6.1 spec/lib/engine_spec.rb
protector-0.6.0 spec/lib/engine_spec.rb
protector-0.6.0.beta.1 spec/lib/engine_spec.rb
protector-0.5.5 spec/lib/engine_spec.rb
protector-0.5.4 spec/lib/engine_spec.rb
protector-0.5.3 spec/lib/engine_spec.rb
protector-0.5.2 spec/lib/engine_spec.rb
protector-0.5.1 spec/lib/engine_spec.rb