mirror of
https://github.com/discourse/discourse.git
synced 2025-06-10 17:23:49 +08:00
do not use try in UserSerializer for fields coming from UserProfile
This commit is contained in:
@ -110,14 +110,14 @@ class UserSerializer < BasicUserSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def location
|
def location
|
||||||
object.user_profile.try(:location)
|
object.user_profile.location
|
||||||
end
|
end
|
||||||
def include_location?
|
def include_location?
|
||||||
location.present?
|
location.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def website
|
def website
|
||||||
object.user_profile.try(:website)
|
object.user_profile.website
|
||||||
end
|
end
|
||||||
def include_website?
|
def include_website?
|
||||||
website.present?
|
website.present?
|
||||||
|
2
spec/fabricators/user_profile_fabricator.rb
Normal file
2
spec/fabricators/user_profile_fabricator.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Fabricator(:user_profile) do
|
||||||
|
end
|
@ -4,7 +4,7 @@ require_dependency 'user'
|
|||||||
describe UserSerializer do
|
describe UserSerializer do
|
||||||
|
|
||||||
context "with a user" do
|
context "with a user" do
|
||||||
let(:user) { Fabricate.build(:user) }
|
let(:user) { Fabricate.build(:user, user_profile: Fabricate.build(:user_profile) ) }
|
||||||
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
|
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
|
||||||
let(:json) { serializer.as_json }
|
let(:json) { serializer.as_json }
|
||||||
|
|
||||||
@ -32,7 +32,14 @@ describe UserSerializer do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with filled out website" do
|
||||||
|
before do
|
||||||
|
user.user_profile.website = 'http://example.com'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "has a website" do
|
||||||
|
expect(json[:website]).to eq 'http://example.com'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user