Sha256: 906be9633f2828988ca8dc837411b9f3329c18514d812f5297bc86ed6402009f
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 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::Adapters::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' end let(:dummy) do Class.new(ActiveRecord::Base) do def self.model_name; ActiveModel::Name.new(self, nil, "dummy"); end self.table_name = "dummies" 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!.create(params(string: 'test')).delete }.to_not raise_error expect{ dummy.restrict!.create!(params(string: 'test')).delete }.to_not raise_error expect{ dummy.restrict!.new params(number: 1) }.to raise_error end it "updates" do instance = dummy.create! expect{ instance.restrict!.assign_attributes params(string: 'test') }.to raise_error expect{ instance.restrict!.assign_attributes params(number: 1) }.to_not raise_error end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
protector-0.7.7 | spec/lib/protector/engine_spec.rb |
protector-0.7.6 | spec/lib/protector/engine_spec.rb |