summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-03-04 21:49:47 -0700
committermo khan <mo@mokhan.ca>2015-03-04 21:49:47 -0700
commit1d6d9c513c0c550e30f33b83d26d8b72ac9dd980 (patch)
tree1cd1ff7b2d0bb2a302472c700bfc910abdcd0ed7
parenta54a62996f7f46fafe23d2bc019441a54821e1e2 (diff)
add specs for user.
-rw-r--r--spec/models/user_spec.rb35
1 files changed, 35 insertions, 0 deletions
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