move bio to UserProfile from User

This commit is contained in:
Andrew Bezzub
2014-06-13 14:55:32 -04:00
committed by Robin Ward
parent 10f0ddbbdd
commit 9ffd173873
12 changed files with 211 additions and 105 deletions
+5 -2
View File
@@ -7,7 +7,6 @@ Fabricator(:user) do
email { sequence(:email) { |i| "bruce#{i}@wayne.com" } }
password 'myawesomepassword'
trust_level TrustLevel.levels[:basic]
bio_raw "I'm batman!"
ip_address { sequence(:ip_address) { |i| "99.232.23.#{i%254}"} }
end
@@ -60,7 +59,11 @@ Fabricator(:active_user, from: :user) do
password 'myawesomepassword'
trust_level TrustLevel.levels[:basic]
active true
bio_raw "Don't ask me about my dad!"
after_create do |user|
user.user_profile.bio_raw = "Don't ask me about my dad!"
user.user_profile.save!
end
end
Fabricator(:leader, from: :user) do
@@ -1,2 +1,3 @@
Fabricator(:user_profile) do
bio_raw "I'm batman!"
end
+102 -1
View File
@@ -1,8 +1,109 @@
require 'spec_helper'
describe UserProfile do
it "is created automatically when a user is created" do
it 'is created automatically when a user is created' do
user = Fabricate(:evil_trout)
user.user_profile.should be_present
end
describe 'new' do
let(:user_profile) { Fabricate.build(:user_profile) }
it 'is not valid without user' do
expect(user_profile.valid?).to be_false
end
it 'is is valid with user' do
user_profile.user = Fabricate.build(:user)
expect(user_profile.valid?).to be_true
end
describe 'after save' do
let(:user) { Fabricate(:user) }
before do
user.user_profile.bio_raw = 'my bio'
user.user_profile.save
end
it 'has cooked bio' do
expect(user.user_profile.bio_cooked).to be_present
end
it 'has bio summary' do
expect(user.user_profile.bio_summary).to be_present
end
end
end
describe 'changing bio' do
let(:user) { Fabricate(:user) }
before do
user.user_profile.bio_raw = "**turtle power!**"
user.user_profile.save
user.user_profile.reload
end
it 'should markdown the raw_bio and put it in cooked_bio' do
user.user_profile.bio_cooked.should == "<p><strong>turtle power!</strong></p>"
end
end
describe 'bio link stripping' do
it 'returns an empty string with no bio' do
expect(Fabricate.build(:user_profile).bio_excerpt).to be_blank
end
context 'with a user that has a link in their bio' do
let(:user_profile) { Fabricate.build(:user_profile, bio_raw: "im sissy and i love http://ponycorns.com") }
let(:user) do
user = Fabricate.build(:user, user_profile: user_profile)
user_profile.user = user
user
end
let(:created_user) do
user = Fabricate(:user)
user.user_profile.bio_raw = 'im sissy and i love http://ponycorns.com'
user.user_profile.save!
user
end
it 'includes the link as nofollow if the user is not new' do
user.user_profile.send(:cook)
expect(user_profile.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com' rel='nofollow'>http://ponycorns.com</a>")
expect(user_profile.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\" rel=\"nofollow\">http://ponycorns.com</a></p>")
end
it 'removes the link if the user is new' do
user.trust_level = TrustLevel.levels[:newuser]
user_profile.send(:cook)
expect(user_profile.bio_excerpt).to eq("im sissy and i love http://ponycorns.com")
expect(user_profile.bio_processed).to eq("<p>im sissy and i love http://ponycorns.com</p>")
end
it 'includes the link without nofollow if the user is trust level 3 or higher' do
user.trust_level = TrustLevel.levels[:leader]
user_profile.send(:cook)
expect(user_profile.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com'>http://ponycorns.com</a>")
expect(user_profile.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\">http://ponycorns.com</a></p>")
end
it 'removes nofollow from links in bio when trust level is increased' do
created_user.change_trust_level!(:leader)
expect(created_user.user_profile.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com'>http://ponycorns.com</a>")
expect(created_user.user_profile.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\">http://ponycorns.com</a></p>")
end
it 'adds nofollow to links in bio when trust level is decreased' do
created_user.trust_level = TrustLevel.levels[:leader]
created_user.save
created_user.change_trust_level!(:regular)
expect(created_user.user_profile.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com' rel='nofollow'>http://ponycorns.com</a>")
expect(created_user.user_profile.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\" rel=\"nofollow\">http://ponycorns.com</a></p>")
end
end
end
end
-64
View File
@@ -241,8 +241,6 @@ describe User do
end
its(:email_tokens) { should be_present }
its(:bio_cooked) { should be_present }
its(:bio_summary) { should be_present }
end
end
@@ -565,21 +563,6 @@ describe User do
end
end
describe 'changing bio' do
let(:user) { Fabricate(:user) }
before do
user.bio_raw = "**turtle power!**"
user.save
user.reload
end
it "should markdown the raw_bio and put it in cooked_bio" do
user.bio_cooked.should == "<p><strong>turtle power!</strong></p>"
end
end
describe "previous_visit_at" do
let(:user) { Fabricate(:user) }
@@ -744,53 +727,6 @@ describe User do
end
describe "bio link stripping" do
it "returns an empty string with no bio" do
expect(Fabricate.build(:user).bio_excerpt).to be_blank
end
context "with a user that has a link in their bio" do
let(:user) { Fabricate.build(:user, bio_raw: "im sissy and i love http://ponycorns.com") }
it "includes the link as nofollow if the user is not new" do
user.send(:cook)
expect(user.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com' rel='nofollow'>http://ponycorns.com</a>")
expect(user.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\" rel=\"nofollow\">http://ponycorns.com</a></p>")
end
it "removes the link if the user is new" do
user.trust_level = TrustLevel.levels[:newuser]
user.send(:cook)
expect(user.bio_excerpt).to eq("im sissy and i love http://ponycorns.com")
expect(user.bio_processed).to eq("<p>im sissy and i love http://ponycorns.com</p>")
end
it "includes the link without nofollow if the user is trust level 3 or higher" do
user.trust_level = TrustLevel.levels[:leader]
user.send(:cook)
expect(user.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com'>http://ponycorns.com</a>")
expect(user.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\">http://ponycorns.com</a></p>")
end
it "removes nofollow from links in bio when trust level is increased" do
user.save
user.change_trust_level!(:leader)
expect(user.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com'>http://ponycorns.com</a>")
expect(user.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\">http://ponycorns.com</a></p>")
end
it "adds nofollow to links in bio when trust level is decreased" do
user.trust_level = TrustLevel.levels[:leader]
user.save
user.change_trust_level!(:regular)
expect(user.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com' rel='nofollow'>http://ponycorns.com</a>")
expect(user.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\" rel=\"nofollow\">http://ponycorns.com</a></p>")
end
end
end
describe '#readable_name' do
context 'when name is missing' do
it 'returns just the username' do
+15
View File
@@ -41,5 +41,20 @@ describe UserSerializer do
expect(json[:website]).to eq 'http://example.com'
end
end
context "with filled out bio" do
before do
user.user_profile.bio_raw = 'my raw bio'
user.user_profile.bio_cooked = 'my cooked bio'
end
it "has a bio" do
expect(json[:bio_raw]).to eq 'my raw bio'
end
it "has a cooked bio" do
expect(json[:bio_cooked]).to eq 'my cooked bio'
end
end
end
end
+9
View File
@@ -14,6 +14,15 @@ describe UserUpdater do
expect(user.reload.name).to eq 'Jim Tom'
end
it 'updates bio' do
user = Fabricate(:user)
updater = described_class.new(acting_user, user)
updater.update(bio_raw: 'my new bio')
expect(user.reload.user_profile.bio_raw).to eq 'my new bio'
end
context 'when update succeeds' do
it 'returns true' do
user = Fabricate(:user)