summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2016-04-30 09:39:37 -0600
committermo khan <mo@mokhan.ca>2016-04-30 09:39:37 -0600
commitd352a8604b2f3cea2834367fe4fd697d9e92ee76 (patch)
treee6a5e10652a0a9b59b6ed547b47b62921beb026d /spec/models
parentd723a6c93fc5f1086d596934e5e2362654a83f21 (diff)
start to move authentication logic to UserSession.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/user_session.rb33
-rw-r--r--spec/models/user_spec.rb29
2 files changed, 33 insertions, 29 deletions
diff --git a/spec/models/user_session.rb b/spec/models/user_session.rb
new file mode 100644
index 0000000..bdbb4e2
--- /dev/null
+++ b/spec/models/user_session.rb
@@ -0,0 +1,33 @@
+require 'rails_helper'
+
+describe UserSession do
+ describe "#authenticate" do
+ context "when credentials are correct" do
+ it "returns true" do
+ user = create(:user, password: "password", password_confirmation: "password")
+ expect(UserSession.authenticate(user.email.upcase, "password")).to eql(user)
+ end
+
+ it "is case in-sensitive for username" do
+ user = create(:user,
+ username: "upcase",
+ password: "password",
+ password_confirmation: "password"
+ )
+ expect(UserSession.authenticate("UPcase", "password")).to eql(user)
+ end
+ end
+
+ context "when the email is not registered" do
+ it "returns nil" do
+ expect(UserSession.authenticate("sofake@noteven.com", "password")).to be_nil
+ end
+ end
+
+ context "when the username is not registered" do
+ it "returns nil" do
+ expect(UserSession.authenticate("sofake", "password")).to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 88cd73c..84057b1 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -99,35 +99,6 @@ describe User do
end
end
- describe "#authenticate" do
- context "when credentials are correct" do
- it "returns true" do
- user = create(:user, password: "password", password_confirmation: "password")
- expect(User.authenticate(user.email.upcase, "password")).to eql(user)
- end
-
- it "is case in-sensitive for username" do
- user = create(:user,
- username: "upcase",
- password: "password",
- password_confirmation: "password"
- )
- expect(User.authenticate("UPcase", "password")).to eql(user)
- end
- end
-
- context "when the email is not registered" do
- it "returns nil" do
- expect(User.authenticate("sofake@noteven.com", "password")).to be_nil
- end
- end
-
- context "when the username is not registered" do
- it "returns nil" do
- expect(User.authenticate("sofake", "password")).to be_nil
- end
- end
- end
describe "#to_param" do
it "returns the username as the uniq identifier" do