Sha256: 3d1db91f79f263fc09e71458aae1d71345be7a97f1b863cc4714c97426b4fa4d

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

require "spec_helper"

describe "Token expiration" do
  describe "after signing in" do
    before do
      Timecop.freeze
      create_user_and_sign_in
      @initial_cookies = remember_token_cookies
    end

    after do
      Timecop.return
    end

    it "should have a remember_token cookie with a future expiration" do
      expect(first_cookie.expires).to be_between(
        1.years.from_now - 1.second,
        1.years.from_now,
      )
    end
  end

  describe "after signing in and making a followup request" do
    before do
      create_user_and_sign_in
      @initial_cookies = remember_token_cookies

      Timecop.travel(1.minute.from_now) do
        get root_path
        @followup_cookies = remember_token_cookies
      end
    end

    it "should set a remember_token on each request with updated expiration" do
      expect(@followup_cookies.length).to be >= 1,
        "remember token wasn't set on second request"

      expect(second_cookie.expires).to be > first_cookie.expires
    end
  end

  def first_cookie
    Rack::Test::Cookie.new @initial_cookies.last
  end

  def second_cookie
    Rack::Test::Cookie.new @followup_cookies.last
  end

  def create_user_and_sign_in
    user = create(:user, password: "password")

    get sign_in_path

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
clearance-2.8.0 spec/requests/token_expiration_spec.rb
clearance-2.7.2 spec/requests/token_expiration_spec.rb
clearance-2.7.0 spec/requests/token_expiration_spec.rb
clearance-2.6.2 spec/requests/token_expiration_spec.rb
clearance-2.6.1 spec/requests/token_expiration_spec.rb
clearance-2.6.0 spec/requests/token_expiration_spec.rb
clearance-2.5.0 spec/requests/token_expiration_spec.rb
clearance-2.4.0 spec/requests/token_expiration_spec.rb
clearance-2.3.1 spec/requests/token_expiration_spec.rb
clearance-2.3.0 spec/requests/token_expiration_spec.rb
clearance-2.2.1 spec/requests/token_expiration_spec.rb
clearance-2.2.0 spec/requests/token_expiration_spec.rb
clearance-2.1.0 spec/requests/token_expiration_spec.rb
clearance-2.0.0 spec/requests/token_expiration_spec.rb
clearance-2.0.0.beta2 spec/requests/token_expiration_spec.rb