Sha256: 8d4d1e40d59419b2f44e77d22bf4a201f855a8c924f0e05aaad876cb8ac29039

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "hanami/config/actions"

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

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

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

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

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

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

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

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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hanami-2.1.0.beta1 spec/unit/hanami/config/actions/csrf_protection_spec.rb
hanami-2.0.3 spec/unit/hanami/config/actions/csrf_protection_spec.rb
hanami-2.0.2 spec/unit/hanami/config/actions/csrf_protection_spec.rb
hanami-2.0.1 spec/unit/hanami/config/actions/csrf_protection_spec.rb
hanami-2.0.0 spec/unit/hanami/config/actions/csrf_protection_spec.rb
hanami-2.0.0.rc1 spec/unit/hanami/config/actions/csrf_protection_spec.rb
hanami-2.0.0.beta4 spec/unit/hanami/config/actions/csrf_protection_spec.rb