Sha256: e3a90d108e96dcb7dbfec8c8fbc8e33fb7ab6a0fcf636e77703261a192e09c05

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require "hanami/configuration/actions"

RSpec.describe Hanami::Configuration::Actions, "#csrf_protection" do
  let(:configuration) { described_class.new }
  subject(:value) { configuration.csrf_protection }

  context "non-finalized configuration" do
    it "returns a default of nil" do
      is_expected.to be_nil
    end

    it "can be explicitly enabled" do
      configuration.csrf_protection = true
      is_expected.to be true
    end

    it "can be explicitly disabled" do
      configuration.csrf_protection = false
      is_expected.to be false
    end
  end

  context "finalized configuration" do
    context "sessions enabled" do
      before do
        configuration.sessions = :cookie, {secret: "abc"}
        configuration.finalize!
      end

      it "is true" do
        is_expected.to be true
      end

      context "explicitly disabled" do
        before do
          configuration.csrf_protection = false
        end

        it "is false" do
          is_expected.to be false
        end
      end
    end

    context "sessions not enabled" do
      before do
        configuration.finalize!
      end

      it "is true" do
        is_expected.to be false
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hanami-2.0.0.beta3 spec/unit/hanami/configuration/actions/csrf_protection_spec.rb
hanami-2.0.0.beta2 spec/unit/hanami/configuration/actions/csrf_protection_spec.rb
hanami-2.0.0.beta1.1 spec/unit/hanami/configuration/actions/csrf_protection_spec.rb
hanami-2.0.0.beta1 spec/unit/hanami/configuration/actions/csrf_protection_spec.rb