mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 09:17:30 +08:00
Merge pull request #2424 from abezzub/website
Move website from User to UserProfile
This commit is contained in:
commit
b16c18e667
|
@ -770,7 +770,6 @@ end
|
|||
# username_lower :string(60) not null
|
||||
# auth_token :string(32)
|
||||
# last_seen_at :datetime
|
||||
# website :string(255)
|
||||
# admin :boolean default(FALSE), not null
|
||||
# last_emailed_at :datetime
|
||||
# email_digests :boolean not null
|
||||
|
|
|
@ -7,4 +7,5 @@ end
|
|||
#
|
||||
# user_id :integer not null, primary key
|
||||
# location :string(255)
|
||||
# website :string(255)
|
||||
#
|
||||
|
|
|
@ -110,12 +110,19 @@ class UserSerializer < BasicUserSerializer
|
|||
end
|
||||
|
||||
def location
|
||||
object.user_profile.try(:location)
|
||||
object.user_profile.location
|
||||
end
|
||||
def include_location?
|
||||
location.present?
|
||||
end
|
||||
|
||||
def website
|
||||
object.user_profile.website
|
||||
end
|
||||
def include_website?
|
||||
website.present?
|
||||
end
|
||||
|
||||
def stats
|
||||
UserAction.stats(object.id, scope)
|
||||
end
|
||||
|
|
|
@ -28,7 +28,8 @@ class UserUpdater
|
|||
end
|
||||
|
||||
def update(attributes = {})
|
||||
user.website = format_url(attributes.fetch(:website) { user.website })
|
||||
user_profile = user.user_profile
|
||||
user_profile.website = format_url(attributes.fetch(:website) { user_profile.website })
|
||||
|
||||
user.bio_raw = attributes.fetch(:bio_raw) { user.bio_raw }
|
||||
user.name = attributes.fetch(:name) { user.name }
|
||||
|
@ -59,7 +60,6 @@ class UserUpdater
|
|||
end
|
||||
end
|
||||
|
||||
user_profile = user.user_profile
|
||||
PROFILE_ATTR.each do |attribute|
|
||||
user_profile.send("#{attribute.to_s}=", attributes[attribute])
|
||||
end
|
||||
|
|
17
db/migrate/20140607035234_add_website_to_user_profiles.rb
Normal file
17
db/migrate/20140607035234_add_website_to_user_profiles.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class AddWebsiteToUserProfiles < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :user_profiles, :website, :string
|
||||
|
||||
execute "UPDATE user_profiles SET website = (SELECT website FROM users where user_profiles.user_id = users.id)"
|
||||
|
||||
remove_column :users, :website
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :users, :website, :string
|
||||
|
||||
execute "UPDATE users SET website = (SELECT website FROM user_profiles where user_profiles.user_id = users.id)"
|
||||
|
||||
remove_column :user_profiles, :website
|
||||
end
|
||||
end
|
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
|
||||
|
||||
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(:json) { serializer.as_json }
|
||||
|
||||
|
@ -32,7 +32,14 @@ describe UserSerializer do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
context "with filled out website" do
|
||||
before do
|
||||
user.user_profile.website = 'http://example.com'
|
||||
end
|
||||
|
||||
it "has a website" do
|
||||
expect(json[:website]).to eq 'http://example.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ describe UserUpdater do
|
|||
|
||||
updater.update(website: 'http://example.com')
|
||||
|
||||
expect(user.reload.website).to eq 'http://example.com'
|
||||
expect(user.reload.user_profile.website).to eq 'http://example.com'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -79,7 +79,7 @@ describe UserUpdater do
|
|||
|
||||
updater.update(website: 'example.com')
|
||||
|
||||
expect(user.reload.website).to eq 'http://example.com'
|
||||
expect(user.reload.user_profile.website).to eq 'http://example.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user