Commit 1d6d9c5

mo khan <mo@mokhan.ca>
2015-03-05 04:49:47
add specs for user.
1 parent a54a629
Changed files (1)
spec
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