Sha256: c732bb0ba166a2a07dacbd9306c3247a41fb35c944123d87c0d01bed7c2d924a

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

shared_examples_for "rails_3_remember_me_model" do
  let(:user) { create_new_user }

  describe "loaded plugin configuration" do

    before(:all) do
      sorcery_reload!([:remember_me])
    end
  
    after(:each) do
      User.sorcery_config.reset!
    end
    
    it "allows configuration option 'remember_me_token_attribute_name'" do
      sorcery_model_property_set(:remember_me_token_attribute_name, :my_token)

      expect(User.sorcery_config.remember_me_token_attribute_name).to eq :my_token
    end

    it "allows configuration option 'remember_me_token_expires_at_attribute_name'" do
      sorcery_model_property_set(:remember_me_token_expires_at_attribute_name, :my_expires)

      expect(User.sorcery_config.remember_me_token_expires_at_attribute_name).to eq :my_expires
    end
    
    specify { expect(user).to respond_to :remember_me! }

    specify { expect(user).to respond_to :forget_me! }
    
    it "generates a new token on 'remember_me!'" do
      expect(user.remember_me_token).to be_nil

      user.remember_me!

      expect(user.remember_me_token).not_to be_nil
    end
    
    # FIXME: assert on line 37 sometimes fails by a second
    it "sets an expiration based on 'remember_me_for' attribute" do
      sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
      user.remember_me!

      expect(user.remember_me_token_expires_at.utc.to_s).to eq (Time.now.in_time_zone + 2 * 60 * 60 * 24).utc.to_s
    end
    
    it "deletes the token and expiration on 'forget_me!'" do
      user.remember_me!

      expect(user.remember_me_token).not_to be_nil

      user.forget_me!

      expect(user.remember_me_token).to be_nil
      expect(user.remember_me_token_expires_at).to be_nil
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
cbsorcery-0.8.6 spec/shared_examples/user_remember_me_shared_examples.rb
cb-sorcery-0.8.6 spec/shared_examples/user_remember_me_shared_examples.rb
sorcery-0.8.6 spec/shared_examples/user_remember_me_shared_examples.rb