From 1d6d9c513c0c550e30f33b83d26d8b72ac9dd980 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 4 Mar 2015 21:49:47 -0700 Subject: add specs for user. --- spec/models/user_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/models/user_spec.rb (limited to 'spec') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..7532721 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe User do + subject { build(:user, password: "password") } + + describe "#validations" do + it "validates the presence of a username" do + subject.username = nil + expect(subject).to_not be_valid + expect(subject.errors[:username]).to_not be_empty + + subject.username = "" + expect(subject).to_not be_valid + expect(subject.errors[:username]).to_not be_empty + end + + it "is valid" do + expect(subject).to be_valid + end + end + + describe "#authenticate" do + context "when the password is correct" do + it "returns true" do + expect(subject.authenticate("password")).to be_truthy + end + end + + context "when the password is incorrect" do + it "returns false" do + expect(subject.authenticate("wrong")).to be_falsey + end + end + end +end -- cgit v1.2.3