summaryrefslogtreecommitdiff
path: root/spec/models/user_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/user_spec.rb')
-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