Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
Sarah Mei
a validé
describe "private key" do
it 'has a key' do
alice.encryption_key.should_not be nil
end
Sarah Mei
a validé
it 'marshalls the key to and from the db correctly' do
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password')
user.save!
Sarah Mei
a validé
expect{
user.reload.encryption_key
}.should_not raise_error
end
danielgrippi
a validé
context 'callbacks' do
describe '#save_person!' do
it 'saves the corresponding user if it has changed' do
alice.person.url = "http://stuff.com"
Person.any_instance.should_receive(:save)
alice.save
end
it 'does not save the corresponding user if it has not changed' do
Person.any_instance.should_not_receive(:save)
alice.save
end
end
describe '#infer_email_from_invitation_provider' do
it 'sets corresponding email if invitation_service is email' do
addr = '12345@alice.com'
alice.invitation_service = 'email'
alice.invitation_identifier = addr
Raphael Sofaer
a validé
danielgrippi
a validé
lambda {
alice.infer_email_from_invitation_provider
}.should change(alice, :email)
end
it 'does not set an email if invitation_service is not email' do
addr = '1233123'
alice.invitation_service = 'facebook'
alice.invitation_identifier = addr
Raphael Sofaer
a validé
danielgrippi
a validé
lambda {
alice.infer_email_from_invitation_provider
}.should_not change(alice, :email)
end
end
end
describe 'overwriting people' do
it 'does not overwrite old users with factory' do
new_user = Factory.create(:user, :id => alice.id)
}.should raise_error ActiveRecord::RecordNotUnique
it 'does not overwrite old users with create' do
params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:person =>
{:profile =>
{:first_name => "O",
new_user = User.build(params)
new_user.save
new_user.persisted?.should be_true
describe "validation" do
describe "of associated person" do
it "fails if person is not valid" do
user.person.serialized_public_key = nil
user.person.should_not be_valid
user.should_not be_valid
user.errors.full_messages.count.should == 1
user.errors.full_messages.first.should =~ /Person is invalid/i
describe "of username" do
alice.username = nil
alice.should_not be_valid
end
it "requires uniqueness" do
alice.username = eve.username
alice.should_not be_valid
end
Maxwell Salzberg
a validé
it 'requires uniqueness also amount Person objects with diaspora handle' do
p = Factory(:person, :diaspora_handle => "jimmy@#{AppConfig[:pod_uri].host}")
alice.username = 'jimmy'
alice.should_not be_valid
end
it "downcases username" do
user = Factory.build(:user, :username => "WeIrDcAsE")
user.should be_valid
user.username.should == "weirdcase"
it "fails if the requested username is only different in case from an existing username" do
alice.username = eve.username.upcase
alice.should_not be_valid
user = Factory.build(:user, :username => " janie ")
user.should be_valid
user.username.should == "janie"
end
it "fails if there's whitespace in the middle" do
alice.username = "bobby tables"
alice.should_not be_valid
it 'can not contain non url safe characters' do
alice.username = "kittens;"
alice.should_not be_valid
end
it 'should not contain periods' do
alice.username = "kittens."
alice.should_not be_valid
it "can be 32 characters long" do
alice.username = "hexagoooooooooooooooooooooooooon"
alice.should be_valid
end
it "cannot be 33 characters" do
alice.username = "hexagooooooooooooooooooooooooooon"
alice.should_not be_valid
end
it "cannot be one of the blacklist names" do
['hostmaster', 'postmaster', 'root', 'webmaster'].each do |username|
alice.username = username
alice.should_not be_valid
end
end
describe "of email" do
it "requires email address" do
end
it "requires a unique email address" do
alice.email = eve.email
alice.should_not be_valid
it "requires a vaild email address" do
alice.email = "somebody@anywhere"
alice.should_not be_valid
end
describe "of unconfirmed_email" do
it "unconfirmed_email address can be nil/blank" do
alice.unconfirmed_email = nil
alice.should be_valid
alice.unconfirmed_email = ""
alice.should be_valid
end
it "does NOT require a unique unconfirmed_email address" do
eve.update_attribute :unconfirmed_email, "new@email.com"
alice.unconfirmed_email = "new@email.com"
alice.should be_valid
end
it "requires a vaild unconfirmed_email address" do
alice.unconfirmed_email = "somebody@anywhere"
alice.should_not be_valid
end
describe "of language" do
it "requires availability" do
alice.language = 'some invalid language'
alice.should_not be_valid
end
it "should save with current language if blank" do
I18n.locale = :fr
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password')
user.language.should == 'fr'
end
it "should save with language what is set" do
I18n.locale = :fr
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password', :language => 'de')
user.language.should == 'de'
end
Maxwell Salzberg
a validé
describe '#seed_aspects' do
it 'follows the default account' do
Webfinger.stub_chain(:new, :fetch).and_return(Factory(:person))
expect{
eve.seed_aspects
}.to change(eve.contacts, :count).by(1)
end
end
describe ".build" do
context 'with valid params' do
before do
params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:person =>
{:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
@user = User.build(params)
end
@user.persisted?.should be_false
@user.person.persisted?.should be_false
User.find_by_username("ohai").should be_nil
end
it 'saves successfully' do
@user.save.should be_true
@user.persisted?.should be_true
@user.person.persisted?.should be_true
User.find_by_username("ohai").should == @user
end
describe "with invalid params" do
before do
@invalid_params = {
:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "wrongpasswordz",
:person => {:profile => {:first_name => "", :last_name => ""}}}
end
it "raises no error" do
lambda { User.build(@invalid_params) }.should_not raise_error
it "does not save" do
User.build(@invalid_params).save.should be_false
it 'does not save a person' do
lambda { User.build(@invalid_params) }.should_not change(Person, :count)
end
it 'does not generate a key' do
User.should_receive(:generate_key).exactly(0).times
User.build(@invalid_params)
end
describe "with malicious params" do
let(:person) {Factory.create :person}
before do
@invalid_params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
end
it "does not assign it to the person" do
User.build(@invalid_params).person.id.should_not == person.id
end
end
describe "#can_add?" do
it "returns true if there is no existing connection" do
alice.can_add?(eve.person).should be_true
end
it "returns false if the user and the person are the same" do
alice.can_add?(alice.person).should be_false
end
it "returns false if the users are already connected" do
alice.can_add?(bob.person).should be_false
end
it "returns false if the user has already sent a request to that person" do
alice.share_with(eve.person, alice.aspects.first)
alice.reload
eve.reload
alice.can_add?(eve.person).should be_false
end
end
danielgrippi
a validé
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
describe '.find_by_invitation' do
let(:invited_user) {
inv = Factory.build(:invitation, :recipient => @recipient, :service => @type, :identifier => @identifier)
User.find_by_invitation(inv)
}
context 'send a request to an existing' do
before do
@recipient = alice
end
context 'active user' do
it 'by service' do
@type = 'facebook'
@identifier = '123456'
@recipient.services << Services::Facebook.new(:uid => @identifier)
@recipient.save
invited_user.should == @recipient
end
it 'by email' do
@type = 'email'
@identifier = alice.email
invited_user.should == @recipient
end
end
context 'invited user' do
it 'by service and identifier' do
@identifier = alice.email
@type = 'email'
invited_user.should == alice
end
end
context 'not on server (not yet invited)' do
it 'returns nil' do
@recipient = nil
Raphael Sofaer
a validé
@identifier = 'foo@bar.com'
danielgrippi
a validé
@type = 'email'
invited_user.should be_nil
end
end
end
end
describe '.find_or_create_by_invitation'
describe '.create_from_invitation!' do
before do
@identifier = 'max@foobar.com'
@inv = Factory.build(:invitation, :admin => true, :service => 'email', :identifier => @identifier)
Raphael Sofaer
a validé
@user = User.create_from_invitation!(@inv)
end
it 'creates a persisted user' do
@user.should be_persisted
end
it 'sets the email if the service is email' do
@user.email.should == @inv.identifier
end
end
describe 'update_user_preferences' do
before do
@pref_count = UserPreference::VALID_EMAIL_TYPES.count
end
it 'unsets disable mail and makes the right amount of prefs' do
alice.disable_mail = true
Sarah Mei
a validé
expect {
alice.update_user_preferences({})
Sarah Mei
a validé
}.to change(alice.user_preferences, :count).by(@pref_count)
it 'still sets new prefs to false on update' do
alice.disable_mail = true
Sarah Mei
a validé
expect {
alice.update_user_preferences({'mentioned' => false})
Sarah Mei
a validé
}.to change(alice.user_preferences, :count).by(@pref_count-1)
alice.reload.disable_mail.should be_false
Raphael Sofaer
a validé
describe ".find_for_database_authentication" do
Raphael Sofaer
a validé
User.find_for_database_authentication(:username => alice.username).should == alice
end
it 'finds a user by email' do
User.find_for_database_authentication(:username => alice.email).should == alice
Raphael Sofaer
a validé
User.find_for_database_authentication(:username => alice.username.upcase).should == alice
it 'errors out when passed a non-hash' do
lambda {
Raphael Sofaer
a validé
User.find_for_database_authentication(alice.username)
describe '#update_profile' do
before do
@params = {
:first_name => 'bob',
:last_name => 'billytown',
danielgrippi
a validé
it 'dispatches the profile when tags are set' do
@params = {:tags => '#what #hey'}
mailman = Postzord::Dispatcher.build(alice, Profile.new)
Postzord::Dispatcher.should_receive(:build).and_return(mailman)
danielgrippi
a validé
alice.update_profile(@params).should be_true
end
it 'sends a profile to their contacts' do
mailman = Postzord::Dispatcher.build(alice, Profile.new)
Postzord::Dispatcher.should_receive(:build).and_return(mailman)
alice.update_profile(@params).should be_true
it 'updates names' do
alice.update_profile(@params).should be_true
alice.reload.profile.first_name.should == 'bob'
it 'updates image_url' do
params = {:image_url => "http://clown.com"}
alice.update_profile(params).should be_true
alice.reload.profile.image_url.should == "http://clown.com"
context 'passing in a photo' do
before do
fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
image = File.open(fixture_name)
@photo = Photo.diaspora_initialize(:author => alice.person, :user_file => image)
@photo.save!
@params = {:photo => @photo}
end
it 'updates image_url' do
alice.update_profile(@params).should be_true
alice.reload
alice.profile.image_url.should =~ Regexp.new(@photo.url(:thumb_large))
alice.profile.image_url_medium.should =~ Regexp.new(@photo.url(:thumb_medium))
alice.profile.image_url_small.should =~ Regexp.new(@photo.url(:thumb_small))
it 'unpends the photo' do
@photo.pending = true
@photo.save!
@photo.reload
alice.update_profile(@params).should be true
@photo.reload.pending.should be_false
end
describe '#update_post' do
it 'sends a notification to aspects' do
Postzord::Dispatcher.should_receive(:build).and_return(m)
photo = alice.build_post(:photo, :user_file => uploaded_photo, :text => "hello", :to => alice.aspects.first.id)
alice.update_post(photo, :text => 'hellp')
Michael Nutt
a validé
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
describe '#notify_if_mentioned' do
before do
@post = Factory.create(:status_message, :author => bob.person)
end
it 'notifies the user if the incoming post mentions them' do
@post.should_receive(:mentions?).with(alice.person).and_return(true)
@post.should_receive(:notify_person).with(alice.person)
alice.notify_if_mentioned(@post)
end
it 'does not notify the user if the incoming post does not mention them' do
@post.should_receive(:mentions?).with(alice.person).and_return(false)
@post.should_not_receive(:notify_person)
alice.notify_if_mentioned(@post)
end
it 'does not notify the user if the post author is not a contact' do
@post = Factory.create(:status_message, :author => eve.person)
@post.stub(:mentions?).and_return(true)
@post.should_not_receive(:notify_person)
alice.notify_if_mentioned(@post)
end
end
describe 'account deletion' do
describe '#remove_all_traces' do
it 'should disconnect everyone' do
alice.should_receive(:disconnect_everyone)
alice.remove_all_traces
end
it 'should remove mentions' do
alice.should_receive(:remove_mentions)
alice.remove_all_traces
end
it 'should remove person' do
alice.should_receive(:remove_person)
alice.remove_all_traces
end
Kiran Soumya
a validé
it 'should remove all aspects' do
lambda {
alice.remove_all_traces
}.should change{ alice.aspects(true).count }.by(-1)
end
describe '#destroy' do
it 'removes invitations from the user' do
danielgrippi
a validé
Factory(:invitation, :sender => alice)
lambda {
alice.destroy
}.should change {alice.invitations_from_me(true).count }.by(-1)
end
it 'removes invitations to the user' do
Maxwell Salzberg
a validé
Invitation.new(:sender => eve, :recipient => alice, :identifier => alice.email, :aspect => eve.aspects.first).save(:validate => false)
lambda {
alice.destroy
}.should change {alice.invitations_to_me(true).count }.by(-1)
end
it 'removes all service connections' do
Services::Facebook.create(:access_token => 'what', :user_id => alice.id)
lambda {
alice.destroy
}.should change {
alice.services.count
}.by(-1)
end
describe '#remove_person' do
it 'should remove the person object' do
alice.remove_person
person.should be_nil
message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id)
alice.remove_person
Sarah Mei
a validé
expect { message.reload }.to raise_error ActiveRecord::RecordNotFound
Kiran Soumya
a validé
describe '#remove_mentions' do
it 'should remove the mentions' do
person = alice.person
sm = Factory(:status_message)
mention = Mention.create(:person => person, :post=> sm)
alice.reload
alice.remove_mentions
Sarah Mei
a validé
expect { mention.reload }.to raise_error ActiveRecord::RecordNotFound
Kiran Soumya
a validé
end
end
describe '#disconnect_everyone' do
it 'has no error on a local friend who has deleted his account' do
Jobs::DeleteAccount.perform(alice.id)
bob.disconnect_everyone
}.should_not raise_error
end
it 'has no error when the user has sent local requests' do
alice.share_with(eve.person, alice.aspects.first)
alice.disconnect_everyone
it 'sends retractions to remote poeple' do
person.owner_id = nil
alice.contacts.create(:person => person, :aspects => [alice.aspects.first])
alice.disconnect_everyone
it 'disconnects local people' do
Michael Sofaer and Raphael Sofaer
a validé
lambda {
alice.remove_all_traces
}.should change{bob.reload.contacts.count}.by(-1)
it 'removes all contacts' do
lambda {
alice.disconnect_everyone
}.should change {
alice.contacts.count
}.by(-1)
end
describe '#mail' do
it 'enqueues a mail job' do
Resque.should_receive(:enqueue).with(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid').once
alice.mail(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid')
it 'does not enqueue a mail job if the correct corresponding job has a prefrence entry' do
alice.user_preferences.create(:email_type => 'started_sharing')
alice.mail(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid')
maxwell
a validé
it 'does not send a mail if disable_mail is set to true' do
alice.disable_mail = true
alice.save
alice.reload
Resque.should_not_receive(:enqueue)
alice.mail(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid')
maxwell
a validé
end
context "aspect management" do
before do
@contact = alice.contact_for(bob.person)
Sarah Mei
a validé
@original_aspect = alice.aspects.where(:name => "generic").first
@new_aspect = alice.aspects.create(:name => 'two')
end
describe "#add_contact_to_aspect" do
it 'adds the contact to the aspect' do
Sarah Mei
a validé
alice.add_contact_to_aspect(@contact, @new_aspect)
}.should change(@new_aspect.contacts, :count).by(1)
end
it 'returns true if they are already in the aspect' do
Sarah Mei
a validé
alice.add_contact_to_aspect(@contact, @original_aspect).should be_true
end
end
context 'moving and removing posts' do
describe 'User#move_contact' do
it 'should be able to move a contact from one of users existing aspects to another' do
Sarah Mei
a validé
alice.move_contact(bob.person, @new_aspect, @original_aspect)
Sarah Mei
a validé
@original_aspect.contacts(true).include?(@contact).should be_false
@new_aspect.contacts(true).include?(@contact).should be_true
end
it "should not move a person who is not a contact" do
non_contact = eve.person
Sarah Mei
a validé
expect {
alice.move_contact(non_contact, @new_aspect, @original_aspect)
}.to raise_error
Sarah Mei
a validé
@original_aspect.contacts.where(:person_id => non_contact.id).should be_empty
@new_aspect.contacts.where(:person_id => non_contact.id).should be_empty
end
it 'does not try to delete if add person did not go through' do
alice.should_receive(:add_contact_to_aspect).and_return(false)
alice.should_not_receive(:delete_person_from_aspect)
Sarah Mei
a validé
alice.move_contact(bob.person, @new_aspect, @original_aspect)
Sarah Mei
a validé
alices_aspect = alice.aspects.where(:name => "generic").first
bobs_aspect = bob.aspects.where(:name => "generic").first
@message = alice.post(:status_message, :text => "cool", :to => alices_aspect)
@message2 = bob.post(:status_message, :text => "uncool", :to => bobs_aspect)
@like = alice.like(true, :target => @message)
@like2 = bob.like(true, :target => @message)
describe '#like_for' do
it 'returns the correct like' do
alice.like_for(@message).should == @like
danielgrippi
a validé
bob.like_for(@message).should == @like2
it "returns nil if there's no like" do
alice.like_for(@message2).should be_nil
end
end
describe '#liked?' do
it "returns true if there's a like" do
alice.liked?(@message).should be_true
bob.liked?(@message).should be_true
end
it "returns false if there's no like" do
alice.liked?(@message2).should be_false
end
end
end
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
context 'change email' do
let(:user){ alice }
describe "#unconfirmed_email" do
it "is nil by default" do
user.unconfirmed_email.should eql(nil)
end
it "forces blank to nil" do
user.unconfirmed_email = ""
user.save!
user.unconfirmed_email.should eql(nil)
end
it "is ignored if it equals email" do
user.unconfirmed_email = user.email
user.save!
user.unconfirmed_email.should eql(nil)
end
it "allows change to valid new email" do
user.unconfirmed_email = "alice@newmail.com"
user.save!
user.unconfirmed_email.should eql("alice@newmail.com")
end
end
describe "#confirm_email_token" do
it "is nil by default" do
user.confirm_email_token.should eql(nil)
end
it "is autofilled when unconfirmed_email is set to new email" do
user.unconfirmed_email = "alice@newmail.com"
user.save!
user.confirm_email_token.should_not be_blank
user.confirm_email_token.size.should eql(30)
end
it "is set back to nil when unconfirmed_email is empty" do
user.unconfirmed_email = "alice@newmail.com"
user.save!
user.confirm_email_token.should_not be_blank
user.unconfirmed_email = nil
user.save!
user.confirm_email_token.should eql(nil)
end
it "generates new token on every new unconfirmed_email" do
user.unconfirmed_email = "alice@newmail.com"
user.save!
first_token = user.confirm_email_token
user.unconfirmed_email = "alice@andanotherone.com"
user.save!
user.confirm_email_token.should_not eql(first_token)
user.confirm_email_token.size.should eql(30)
end
end
describe '#mail_confirm_email' do
it 'enqueues a mail job on user with unconfirmed email' do
user.update_attribute(:unconfirmed_email, "alice@newmail.com")
Resque.should_receive(:enqueue).with(Jobs::Mail::ConfirmEmail, alice.id).once
alice.mail_confirm_email.should eql(true)
end
it 'enqueues NO mail job on user without unconfirmed email' do
Resque.should_not_receive(:enqueue).with(Jobs::Mail::ConfirmEmail, alice.id)
alice.mail_confirm_email.should eql(false)
end
end
describe '#confirm_email' do
context 'on user with unconfirmed email' do
before do
user.update_attribute(:unconfirmed_email, "alice@newmail.com")
end
it 'confirms email and set the unconfirmed_email to email on valid token' do
user.confirm_email(user.confirm_email_token).should eql(true)
user.email.should eql("alice@newmail.com")
user.unconfirmed_email.should eql(nil)
user.confirm_email_token.should eql(nil)
end
it 'returns false and does not change anything on wrong token' do
user.confirm_email(user.confirm_email_token.reverse).should eql(false)
user.email.should_not eql("alice@newmail.com")
user.unconfirmed_email.should_not eql(nil)
user.confirm_email_token.should_not eql(nil)
end
it 'returns false and does not change anything on blank token' do
user.confirm_email("").should eql(false)
user.email.should_not eql("alice@newmail.com")
user.unconfirmed_email.should_not eql(nil)
user.confirm_email_token.should_not eql(nil)
end
it 'returns false and does not change anything on blank token' do
user.confirm_email(nil).should eql(false)
user.email.should_not eql("alice@newmail.com")
user.unconfirmed_email.should_not eql(nil)
user.confirm_email_token.should_not eql(nil)
end
end
context 'on user without unconfirmed email' do
it 'returns false and does not change anything on any token' do
user.confirm_email("12345"*6).should eql(false)
user.email.should_not eql("alice@newmail.com")
user.unconfirmed_email.should eql(nil)
user.confirm_email_token.should eql(nil)
end
it 'returns false and does not change anything on blank token' do
user.confirm_email("").should eql(false)
user.email.should_not eql("alice@newmail.com")
user.unconfirmed_email.should eql(nil)
user.confirm_email_token.should eql(nil)
end
it 'returns false and does not change anything on blank token' do
user.confirm_email(nil).should eql(false)
user.email.should_not eql("alice@newmail.com")
user.unconfirmed_email.should eql(nil)
user.confirm_email_token.should eql(nil)
end
end
end
danielgrippi
a validé
describe "#accept_invitation!" do
before do
fantasy_resque do
@invitation = Factory.create(:invitation, :sender => eve, :identifier => 'invitee@example.org', :aspect => eve.aspects.first)
end
@invitation.reload
Sarah Mei
a validé
@form_params = {
:invitation_token => "abc",
:email => "a@a.com",
:username => "user",
:password => "secret",
:password_confirmation => "secret",
:person => {
:profile => {:first_name => "Bob", :last_name => "Smith"}
}
}
danielgrippi
a validé
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
end
context 'after invitation acceptance' do
it 'destroys the invitations' do
user = @invitation.recipient.accept_invitation!(@form_params)
user.invitations_to_me.count.should == 0
end
it "should create the person with the passed in params" do
lambda {
@invitation.recipient.accept_invitation!(@form_params)
}.should change(Person, :count).by(1)
end
it 'resolves incoming invitations into contact requests' do
user = @invitation.recipient.accept_invitation!(@form_params)
eve.contacts.where(:person_id => user.person.id).count.should == 1
end
end
context 'from an admin' do
it 'should work' do
i = nil
fantasy_resque do
i = Invitation.create!(:admin => true, :service => 'email', :identifier => "new_invitee@example.com")
end
i.reload
i.recipient.accept_invitation!(@form_params)
end
end
end
describe '#retract' do
before do
@retraction = mock
@post = Factory(:status_message, :author => bob.person, :public => true)
Raphael Sofaer
a validé
context "posts" do
Raphael Sofaer
a validé
SignedRetraction.stub(:build).and_return(@retraction)
@retraction.stub(:perform)
end
it 'sends a retraction' do
dispatcher = mock
Postzord::Dispatcher.should_receive(:build).with(bob, @retraction, anything()).and_return(dispatcher)
dispatcher.should_receive(:post)
bob.retract(@post)
end
it 'adds resharers of target post as additional subsctibers' do
person = Factory(:person)
reshare = Factory(:reshare, :root => @post, :author => person)
@post.reshares << reshare
dispatcher = mock
Postzord::Dispatcher.should_receive(:build).with(bob, @retraction, {:additional_subscribers => [person]}).and_return(dispatcher)
dispatcher.should_receive(:post)
bob.retract(@post)
end
end
end
describe "#send_reset_password_instructions" do
it "generates a reset password token if it's supposed to" do
user = User.new
user.stub!(:should_generate_token?).and_return(true)
user.should_receive(:generate_reset_password_token)
user.send_reset_password_instructions
end
it "does not generate a reset password token if it's not supposed to" do
user = User.new
user.stub!(:should_generate_token?).and_return(false)
user.should_not_receive(:generate_reset_password_token)
user.send_reset_password_instructions
end