Sha256: 49f187b405fae7b21689993edf073b75000e1178d55f4daef888c0164c8157bd

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe "Strong parameters" do
  context 'A document with strong parameters protection' do
    if ::ActiveModel.const_defined?(:ForbiddenAttributesProtection)
      require "action_controller/metal/strong_parameters"

      before do
        @doc_class = Doc do
          plugin MongoMapper::Plugins::StrongParameters

          key :name, String
          key :admin, Boolean, :default => false
        end

        @doc = @doc_class.create(:name => 'Steve Sloan')
      end

      let(:params) {
        {name: "Permitted", admin: true}
      }

      let(:strong_params) {
        ActionController::Parameters.new params
      }

      it "allows assignment of attribute hashes" do
        @doc.attributes = params
        @doc.name.should =="Permitted"
      end

      it "doesn't allow mass assignment of ActionController::Parameters" do
        lambda {
          @doc.attributes = strong_params
        }.should raise_error(ActiveModel::ForbiddenAttributesError)
      end

      it "does not allow mass assignment of non-permitted attributes" do
        @doc.attributes = strong_params.permit(:name)
        @doc.admin.should == false
      end

      it "allows mass assignment of permitted attributes" do
        @doc.attributes = strong_params.permit(:name)
        @doc.name.should == "Permitted"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongo_mapper-0.17.0 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.16.0 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.15.6 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.15.5 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.15.4 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.15.3 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.15.2 spec/functional/strong_parameters_spec.rb
mongo_mapper-0.15.1 spec/functional/strong_parameters_spec.rb