Skip to content

Commit 2a2acbc

Browse files
committed
fix tests
1 parent 679e35e commit 2a2acbc

File tree

3 files changed

+3
-24
lines changed

3 files changed

+3
-24
lines changed

app/models/user.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ def self.from_omniauth(auth)
3939
db_user = find_by(zauth_id: auth.uid)
4040

4141
if db_user.nil?
42-
db_user = find_or_create_by!(name: auth.extra.raw_info["username"]) do |user|
42+
db_user = find_or_create_by!(zauth_id: auth.uid) do |user|
4343
user.generate_key!
4444
user.private = true
4545
end
46-
47-
db_user.zauth_id = auth.uid
4846
end
4947

5048
# overwrite name (for if name changed)

spec/factories/users.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
FactoryBot.define do
2727
factory :user do
2828
name { Faker::Internet.user_name }
29+
zauth_id { Faker::String.random }
2930
private { false }
3031

3132
factory :admin do

spec/models/user_spec.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
let(:auth_hash) do
8989
OmniAuth::AuthHash.new(
9090
{
91-
uid: 7,
91+
uid: "7",
9292
extra: {
9393
raw_info: { roles: [], username: existing_user.name }
9494
}
@@ -106,26 +106,6 @@
106106
end
107107
end
108108

109-
describe "when the user already exists but without zauth id" do
110-
let!(:existing_user) { create(:user) }
111-
let(:auth_hash) do
112-
OmniAuth::AuthHash.new(
113-
{
114-
uid: "7",
115-
extra: {
116-
raw_info: { roles: [], username: existing_user.name }
117-
}
118-
}
119-
)
120-
end
121-
122-
it "finds the existing user" do
123-
user = described_class.from_omniauth(auth_hash)
124-
expect(user).to eq(existing_user)
125-
expect(user.admin).to be(false)
126-
end
127-
end
128-
129109
describe "when the user exists but has changed their name" do
130110
let!(:existing_user) { create(:user) }
131111
let(:auth_hash) do

0 commit comments

Comments
 (0)