Handle the case in which the pod owner has not set up featured users.
This commit is contained in:
parent
ac063ed938
commit
421bfe6d8f
2 changed files with 32 additions and 22 deletions
|
|
@ -47,9 +47,7 @@ class Person < ActiveRecord::Base
|
|||
scope :local, where('people.owner_id IS NOT NULL')
|
||||
|
||||
def self.featured_users
|
||||
if AppConfig[:featured_users].present?
|
||||
Person.where(:diaspora_handle => AppConfig[:featured_users])
|
||||
end
|
||||
AppConfig[:featured_users].present? ? Person.where(:diaspora_handle => AppConfig[:featured_users]) : []
|
||||
end
|
||||
|
||||
def self.search_query_string(query)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ describe Person do
|
|||
|
||||
before do
|
||||
@user = bob
|
||||
@person = Factory.create(:person)
|
||||
@person = Factory.create(:person)
|
||||
end
|
||||
|
||||
context 'scopes' do
|
||||
|
|
@ -146,7 +146,7 @@ describe Person do
|
|||
end
|
||||
|
||||
it "deletes all of a person's posts upon person deletion" do
|
||||
lambda {@deleter.destroy}.should change(Post, :count).by(-1)
|
||||
lambda { @deleter.destroy }.should change(Post, :count).by(-1)
|
||||
end
|
||||
|
||||
it "deletes a person's profile" do
|
||||
|
|
@ -156,30 +156,30 @@ describe Person do
|
|||
end
|
||||
|
||||
it "deletes a person's comments on person deletion" do
|
||||
Factory.create(:comment, :author_id => @deleter.id, :diaspora_handle => @deleter.diaspora_handle, :text => "i love you", :post => @other_status)
|
||||
Factory.create(:comment, :author_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => @other_status)
|
||||
Factory.create(:comment, :author_id => @deleter.id, :diaspora_handle => @deleter.diaspora_handle, :text => "i love you", :post => @other_status)
|
||||
Factory.create(:comment, :author_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => @other_status)
|
||||
|
||||
lambda {@deleter.destroy}.should change(Comment, :count).by(-1)
|
||||
lambda { @deleter.destroy }.should change(Comment, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "disconnecting" do
|
||||
before do
|
||||
@user2 = Factory(:user)
|
||||
@aspect = @user.aspects.create(:name => "Dudes")
|
||||
@user2 = Factory(:user)
|
||||
@aspect = @user.aspects.create(:name => "Dudes")
|
||||
@aspect2 = @user2.aspects.create(:name => "Abscence of Babes")
|
||||
end
|
||||
it 'should not delete an orphaned contact' do
|
||||
@user.contacts.create(:person => @person, :aspects => [@aspect])
|
||||
|
||||
lambda {@user.disconnect(@user.contact_for(@person))}.should_not change(Person, :count)
|
||||
lambda { @user.disconnect(@user.contact_for(@person)) }.should_not change(Person, :count)
|
||||
end
|
||||
|
||||
it 'should not delete an un-orphaned contact' do
|
||||
@user.contacts.create(:person => @person, :aspects => [@aspect])
|
||||
@user2.contacts.create(:person => @person, :aspects => [@aspect2])
|
||||
|
||||
lambda {@user.disconnect(@user.contact_for(@person))}.should_not change(Person, :count)
|
||||
lambda { @user.disconnect(@user.contact_for(@person)) }.should_not change(Person, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -198,22 +198,22 @@ describe Person do
|
|||
@casey_grippi = Factory.create(:searchable_person)
|
||||
|
||||
@robert_grimm.profile.first_name = "Robert"
|
||||
@robert_grimm.profile.last_name = "Grimm"
|
||||
@robert_grimm.profile.last_name = "Grimm"
|
||||
@robert_grimm.profile.save
|
||||
@robert_grimm.reload
|
||||
|
||||
@eugene_weinstein.profile.first_name = "Eugene"
|
||||
@eugene_weinstein.profile.last_name = "Weinstein"
|
||||
@eugene_weinstein.profile.last_name = "Weinstein"
|
||||
@eugene_weinstein.profile.save
|
||||
@eugene_weinstein.reload
|
||||
|
||||
@yevgeniy_dodis.profile.first_name = "Yevgeniy"
|
||||
@yevgeniy_dodis.profile.last_name = "Dodis"
|
||||
@yevgeniy_dodis.profile.last_name = "Dodis"
|
||||
@yevgeniy_dodis.profile.save
|
||||
@yevgeniy_dodis.reload
|
||||
|
||||
@casey_grippi.profile.first_name = "Casey"
|
||||
@casey_grippi.profile.last_name = "Grippi"
|
||||
@casey_grippi.profile.last_name = "Grippi"
|
||||
@casey_grippi.profile.save
|
||||
@casey_grippi.reload
|
||||
end
|
||||
|
|
@ -231,7 +231,7 @@ describe Person do
|
|||
@casey_grippi.profile.save
|
||||
|
||||
people = Person.search("AAA", @user)
|
||||
people.map{|p| p.name}.should == [@yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map{|p|p.name}
|
||||
people.map { |p| p.name }.should == [@yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map { |p| p.name }
|
||||
end
|
||||
|
||||
it 'should return nothing on an empty query' do
|
||||
|
|
@ -266,7 +266,7 @@ describe Person do
|
|||
end
|
||||
|
||||
it 'only displays searchable people' do
|
||||
invisible_person = Factory(:person, :profile => Factory.build(:profile,:searchable => false, :first_name => "johnson"))
|
||||
invisible_person = Factory(:person, :profile => Factory.build(:profile, :searchable => false, :first_name => "johnson"))
|
||||
Person.search("johnson", @user).should_not include invisible_person
|
||||
Person.search("", @user).should_not include invisible_person
|
||||
end
|
||||
|
|
@ -292,13 +292,13 @@ describe Person do
|
|||
@user.contacts.create(:person => @casey_grippi, :aspects => [@user.aspects.first])
|
||||
|
||||
people = Person.search("AAA", @user)
|
||||
people.map{|p| p.name}.should == [@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map{|p|p.name}
|
||||
people.map { |p| p.name }.should == [@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map { |p| p.name }
|
||||
end
|
||||
end
|
||||
|
||||
context 'people finders for webfinger' do
|
||||
let(:user) {Factory(:user)}
|
||||
let(:person) {Factory(:person)}
|
||||
let(:user) { Factory(:user) }
|
||||
let(:person) { Factory(:person) }
|
||||
|
||||
describe '.by_account_identifier' do
|
||||
it 'should find a local users person' do
|
||||
|
|
@ -387,10 +387,22 @@ describe Person do
|
|||
end
|
||||
it 'return tags if asked' do
|
||||
@person.as_json(:includes => "tags").
|
||||
should == @person.as_json.merge(:tags => @person.profile.tags.map{|t| "##{t.name}"})
|
||||
should == @person.as_json.merge(:tags => @person.profile.tags.map { |t| "##{t.name}" })
|
||||
end
|
||||
end
|
||||
|
||||
describe '.featured_users' do
|
||||
describe "when the pod owner hasn't set up any featured users" do
|
||||
before do
|
||||
@existing_featured_users = AppConfig[:featured_users]
|
||||
AppConfig[:featured_users] = nil
|
||||
end
|
||||
after do
|
||||
AppConfig[:featured_users] = @existing_featured_users
|
||||
end
|
||||
it "returns an empty array" do
|
||||
Person.featured_users.should == []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue