spec/tokens_spec.rb in tokens-2.0.1 vs spec/tokens_spec.rb in tokens-2.1.0

- old
+ new

@@ -112,15 +112,15 @@ expect(@user.find_token_by_name(:uid)).to be_nil end it "is a valid token" do token = @user.add_token(:uid) - expect(@user.valid_token?(:uid, token.to_s)).to be_true + expect(@user.valid_token?(:uid, token.to_s)).to be_truthy end it "isn't a valid token" do - expect(@user.valid_token?(:uid, "invalid")).to be_false + expect(@user.valid_token?(:uid, "invalid")).to be_falsy end it "finds token by its name and hash" do token = @user.add_token(:uid) expect(@user.find_token(:uid, token.to_s)).to eql(token) @@ -138,11 +138,11 @@ expect(@user.add_token(:uid, :expires_at => 3.days.ago)).to be_expired end it "removes token" do @user.add_token(:uid) - expect(@user.remove_token(:uid)).to be_true + expect(@user.remove_token(:uid)).to be_truthy end it "doesn't remove other users tokens" do @user.add_token(:uid) @another_user.add_token(:uid) @@ -156,8 +156,27 @@ it "isn't duplicated" do @user.add_token(:uid) @user.add_token(:uid) expect(@user.tokens.where(name: "uid").count).to eql(1) + end + + it "returns valid token" do + token = @user.add_token(:uid) + expect(@user.find_valid_token(:uid, token.to_s)).to eql(token) + end + + it "returns nothing for invalid token" do + token = @user.add_token(:uid) + expect(@user.find_valid_token(:uid, "invalid")).to be_nil + end + + it "returns nothing for missing token" do + expect(@user.find_valid_token(:uid, "invalid")).to be_nil + end + + it "returns nothing for expired token" do + token = @user.add_token(:uid, expires_at: 2.weeks.ago) + expect(@user.find_valid_token(:uid, "invalid")).to be_nil end end end