Sha256: bf2d3ebcd9dfbbe94566f0a43379e79955200391c8d7df3aa396a65257f22297

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

require "spec_helper"

describe "Cookie options" do
  before do
    Clearance.configuration.httponly = httponly
  end

  context "when httponly config value is false" do
    let(:httponly) { false }
    describe "sign in" do
      before do
        user = create(:user, password: "password")
        get sign_in_path

        post session_path, params: {
          session: { email: user.email, password: "password" },
        }
      end

      it { should_have_one_remember_token }

      it "should not have the httponly flag set" do
        expect(remember_token_cookies.last).not_to match(/HttpOnly/)
      end
    end
  end

  context "when httponly config value is true" do
    let(:httponly) { true }
    describe "sign in" do
      before do
        user = create(:user, password: "password")
        get sign_in_path

        post session_path, params: {
          session: { email: user.email, password: "password" },
        }
      end

      it { should_have_one_remember_token }

      it "should have the httponly flag set" do
        expect(remember_token_cookies.last).to match(/HttpOnly/)
      end
    end
  end

  def should_have_one_remember_token
    expect(remember_token_cookies.length).to eq(1),
      "expected one 'remember_token' cookie:\n#{remember_token_cookies}"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
clearance-2.6.1 spec/requests/cookie_options_spec.rb
clearance-2.6.0 spec/requests/cookie_options_spec.rb
clearance-2.5.0 spec/requests/cookie_options_spec.rb
clearance-2.4.0 spec/requests/cookie_options_spec.rb
clearance-2.3.1 spec/requests/cookie_options_spec.rb
clearance-2.3.0 spec/requests/cookie_options_spec.rb
clearance-2.2.1 spec/requests/cookie_options_spec.rb
clearance-2.2.0 spec/requests/cookie_options_spec.rb
clearance-2.1.0 spec/requests/cookie_options_spec.rb
clearance-2.0.0 spec/requests/cookie_options_spec.rb
clearance-2.0.0.beta2 spec/requests/cookie_options_spec.rb
clearance-2.0.0.beta1 spec/requests/cookie_options_spec.rb
clearance-1.17.0 spec/requests/cookie_options_spec.rb
clearance-1.16.2 spec/requests/cookie_options_spec.rb