diff --git a/app/models/user.rb b/app/models/user.rb index 8ef6111c1ae..a1cbfa42fc4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb index e762563147c..35bd8459211 100644 --- a/app/models/user_profile.rb +++ b/app/models/user_profile.rb @@ -7,4 +7,5 @@ end # # user_id :integer not null, primary key # location :string(255) +# website :string(255) # diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index d9eb48a831b..c2d39e972b2 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -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 diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index aa27f5dcdf7..e6c90a390b8 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -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 diff --git a/db/migrate/20140607035234_add_website_to_user_profiles.rb b/db/migrate/20140607035234_add_website_to_user_profiles.rb new file mode 100644 index 00000000000..4194dcf1393 --- /dev/null +++ b/db/migrate/20140607035234_add_website_to_user_profiles.rb @@ -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 diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 686cdc7d120..6cb60bd42c7 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -75,4 +75,4 @@ Fabricator(:elder, from: :user) do username { sequence(:username) { |i| "elder#{i}" } } email { sequence(:email) { |i| "elder#{i}@elderfun.com" } } trust_level TrustLevel.levels[:elder] -end \ No newline at end of file +end diff --git a/spec/fabricators/user_profile_fabricator.rb b/spec/fabricators/user_profile_fabricator.rb new file mode 100644 index 00000000000..52bd1977843 --- /dev/null +++ b/spec/fabricators/user_profile_fabricator.rb @@ -0,0 +1,2 @@ +Fabricator(:user_profile) do +end diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb index 26c24722bfb..527ae3a9eab 100644 --- a/spec/serializers/user_serializer_spec.rb +++ b/spec/serializers/user_serializer_spec.rb @@ -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 diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb index b6b7bf1a48c..f43ef1f4453 100644 --- a/spec/services/user_updater_spec.rb +++ b/spec/services/user_updater_spec.rb @@ -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