diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 1640bfd9e..fd151a0b4 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -9,7 +9,7 @@ describe HomeController do render_views before do - @user = Factory.create(:user) + @user = alice sign_in @user sign_out @user end @@ -37,7 +37,7 @@ describe HomeController do describe "custom logging on redirect" do before do - sign_in :user, Factory(:user) + sign_in :user, bob @action = :show @action_params = {"lasers" => "green"} end diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 72626d7b7..07272b689 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -9,22 +9,20 @@ describe InvitationsController do render_views - let!(:user) { Factory.create(:user) } - let!(:aspect) { user.aspects.create(:name => "WIN!!") } - before do + @user = alice + @aspect = @user.aspects.first request.env["devise.mapping"] = Devise.mappings[:user] end describe "#create" do before do + @user.invites = 5 - user.invites = 5 - - sign_in :user, user - @invite = {:invite_message=>"test", :aspect_id=> aspect.id.to_s, :email=>"abc@example.com"} - @controller.stub!(:current_user).and_return(user) + sign_in :user, @user + @invite = {:invite_message=>"test", :aspect_id=> @aspect.id.to_s, :email=>"abc@example.com"} + @controller.stub!(:current_user).and_return(@user) request.env["HTTP_REFERER"]= 'http://test.host/cats/foo' end @@ -54,8 +52,8 @@ describe InvitationsController do end it "doesn't invite anyone if you have 0 invites" do - user.invites = 0 - user.save! + @user.invites = 0 + @user.save! lambda { post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") }.should_not change(User, :count) @@ -69,8 +67,8 @@ describe InvitationsController do describe "#update" do before do - user.invites = 5 - @invited_user = user.invite_user("a@a.com", user.aspects.first.id) + @user.invites = 5 + @invited_user = @user.invite_user("a@a.com", @aspect.id) @accept_params = {:user=> {:password_confirmation =>"password", :username=>"josh", @@ -91,7 +89,6 @@ describe InvitationsController do end it 'adds a pending request' do - put :update, @accept_params Request.where(:recipient_id => invited.person.id).count.should == 1 end @@ -100,7 +97,7 @@ describe InvitationsController do context 'failure' do before do @fail_params = @accept_params - @fail_params[:user][:username] = user.username + @fail_params[:user][:username] = @user.username end it 'stays on the invitation accept form' do put :update, @fail_params @@ -115,7 +112,7 @@ describe InvitationsController do describe '#new' do it 'renders' do - sign_in :user, user + sign_in :user, @user get :new end end diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index b89cec9b3..614d6d33d 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -6,24 +6,24 @@ require 'spec_helper' describe NotificationsController do - let!(:user) { Factory.create(:user) } - let!(:aspect) { user.aspects.create(:name => "AWESOME!!") } before do - sign_in :user, user + @user = alice + @aspect = @user.aspects.first + sign_in :user, @user end describe '#update' do it 'marks a notification as read' do - note = Notification.create(:recipient_id => user.id) + note = Notification.create(:recipient_id => @user.id) put :update, :id => note.id Notification.first.unread.should == false end it 'only lets you read your own notifications' do - user2 = Factory.create(:user) + user2 = bob - Notification.create(:recipient_id => user.id) + Notification.create(:recipient_id => @user.id) note = Notification.create(:recipient_id => user2.id) put :update, :id => note.id @@ -35,8 +35,8 @@ describe NotificationsController do describe "#read_all" do it 'marks all notifications as read' do request.env["HTTP_REFERER"] = "I wish I were spelled right" - Notification.create(:recipient_id => user.id) - Notification.create(:recipient_id => user.id) + Notification.create(:recipient_id => @user.id) + Notification.create(:recipient_id => @user.id) Notification.where(:unread => true).count.should == 2 get :read_all @@ -47,7 +47,7 @@ describe NotificationsController do describe '#index' do it 'paginates the notifications' do 35.times do - Notification.create(:recipient_id => user.id) + Notification.create(:recipient_id => @user.id) end get :index diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 7d913f28c..1e51f2c38 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -7,21 +7,20 @@ require 'spec_helper' describe PeopleController do render_views - let(:user) { Factory.create(:user) } - let!(:aspect) { user.aspects.create(:name => "lame-os") } - before do - sign_in :user, user + @user = alice + @aspect = @user.aspects.first + sign_in :user, @user end describe '#similar_people' do before do @contacts = [] - @aspect1 = user.aspects.create(:name => "foos") - @aspect2 = user.aspects.create(:name => "bars") + @aspect1 = @user.aspects.create(:name => "foos") + @aspect2 = @user.aspects.create(:name => "bars") 3.times do - @contacts << Contact.create(:user => user, :person => Factory.create(:person)) + @contacts << Contact.create(:user => @user, :person => Factory.create(:person)) end end @@ -57,7 +56,7 @@ describe PeopleController do @contacts[0].save 20.times do - c = Contact.create(:user => user, :person => Factory.create(:person)) + c = Contact.create(:user => @user, :person => Factory.create(:person)) c.aspects << @aspect1 c.save @contacts << c @@ -83,16 +82,16 @@ describe PeopleController do @everyone << Factory.create(:person) end - user.send_contact_request_to(@everyone[3], aspect) - user.send_contact_request_to(@everyone[2], aspect) - user.activate_contact(@everyone[4], aspect) - user.activate_contact(@everyone[5], aspect) + @user.send_contact_request_to(@everyone[3], @aspect) + @user.send_contact_request_to(@everyone[2], @aspect) + @user.activate_contact(@everyone[4], @aspect) + @user.activate_contact(@everyone[5], @aspect) - user.reload - user.aspects.reload + @user.reload + @user.aspects.reload @people = @everyone @people.length.should == 10 - @hashes = @controller.hashes_for_people(@people, user.aspects) + @hashes = @controller.hashes_for_people(@people, @user.aspects) end it 'has the correct result for no relationship' do hash = @hashes.first @@ -100,21 +99,21 @@ describe PeopleController do hash[:person].should == @people.first hash[:contact].should be_false hash[:request].should be_false - hash[:aspects].should == user.aspects + hash[:aspects].should == @user.aspects end it 'has the correct result for a connected person' do hash = @hashes[4] hash[:person].should == @people[4] hash[:contact].should be_true hash[:contact].should_not be_pending - hash[:aspects].should == user.aspects + hash[:aspects].should == @user.aspects end it 'has the correct result for a requested person' do hash = @hashes[2] hash[:person].should == @people[2] hash[:contact].should be_true hash[:contact].should be_pending - hash[:aspects].should == user.aspects + hash[:aspects].should == @user.aspects end end describe '#index' do @@ -144,14 +143,13 @@ describe PeopleController do assigns[:people].should =~ [@eugene, eugene2] end it 'shows a contact' do - user2 = Factory.create(:user) - connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience')) + user2 = bob get :index, :q => user2.person.profile.first_name.to_s response.should redirect_to user2.person end it 'shows a non-contact' do - user2 = Factory.create(:user) + user2 = eve user2.person.profile.searchable = true user2.save get :index, :q => user2.person.profile.first_name.to_s @@ -171,20 +169,20 @@ describe PeopleController do describe '#show' do it 'goes to the current_user show page' do - get :show, :id => user.person.id + get :show, :id => @user.person.id response.should be_success end it 'renders with a post' do - user.post :status_message, :message => 'test more', :to => aspect.id - get :show, :id => user.person.id + @user.post :status_message, :message => 'test more', :to => @aspect.id + get :show, :id => @user.person.id response.should be_success end it 'renders with a post' do - message = user.post :status_message, :message => 'test more', :to => aspect.id - user.comment 'I mean it', :on => message - get :show, :id => user.person.id + message = @user.post :status_message, :message => 'test more', :to => @aspect.id + @user.comment 'I mean it', :on => message + get :show, :id => @user.person.id response.should be_success end @@ -194,25 +192,24 @@ describe PeopleController do end it "redirects to #index if no person is found" do - get :show, :id => user.id + get :show, :id => 3920397846 response.should redirect_to people_path end it "renders the show page of a contact" do - user2 = Factory.create(:user) - connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience')) + user2 = bob get :show, :id => user2.person.id response.should be_success end it "renders the show page of a non-contact" do - user2 = Factory.create(:user) + user2 = eve get :show, :id => user2.person.id response.should be_success end it "renders with public posts of a non-contact" do - user2 = Factory.create(:user) + user2 = eve status_message = user2.post(:status_message, :message => "hey there", :to => 'all', :public => true) get :show, :id => user2.person.id @@ -223,14 +220,14 @@ describe PeopleController do describe '#webfinger' do it 'enqueues a webfinger job' do - Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, user.id, user.diaspora_handle, anything).once - get :retrieve_remote, :diaspora_handle => user.diaspora_handle + Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once + get :retrieve_remote, :diaspora_handle => @user.diaspora_handle end end describe '#update' do it "sets the flash" do - put :update, :id => user.person.id, + put :update, :id => @user.person.id, :profile => { :image_url => "", :first_name => "Will", @@ -241,35 +238,35 @@ describe PeopleController do context 'with a profile photo set' do before do - @params = { :id => user.person.id, + @params = { :id => @user.person.id, :profile => {:image_url => "", - :last_name => user.person.profile.last_name, - :first_name => user.person.profile.first_name }} + :last_name => @user.person.profile.last_name, + :first_name => @user.person.profile.first_name }} - user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" - user.person.profile.save + @user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" + @user.person.profile.save end it "doesn't overwrite the profile photo when an empty string is passed in" do - image_url = user.person.profile.image_url + image_url = @user.person.profile.image_url put :update, @params - Person.find(user.person.id).profile.image_url.should == image_url + Person.find(@user.person.id).profile.image_url.should == image_url end end it 'does not allow mass assignment' do - person = user.person + person = @user.person new_user = Factory.create(:user) - person.owner_id.should == user.id - put :update, :id => user.person.id, :owner_id => new_user.id - Person.find(person.id).owner_id.should == user.id + person.owner_id.should == @user.id + put :update, :id => @user.person.id, :owner_id => new_user.id + Person.find(person.id).owner_id.should == @user.id end it 'does not overwrite the profile diaspora handle' do - handle_params = {:id => user.person.id, + handle_params = {:id => @user.person.id, :profile => {:diaspora_handle => 'abc@a.com'} } put :update, handle_params - Person.find(user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com' + Person.find(@user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com' end end end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 23b0f8f7a..f9d64ad37 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -7,35 +7,31 @@ require 'spec_helper' describe PhotosController do render_views - let(:user1) {Factory.create(:user)} - let(:user2) {Factory.create(:user)} - - let(:aspect1) { user1.aspects.create(:name => 'winners') } - let(:aspect2) { user2.aspects.create(:name => 'winners') } - - let(:filename) { 'button.png' } - let(:fixture_name) { File.join(File.dirname(__FILE__), '..', 'fixtures', filename) } - let(:photo1) { user1.post(:photo, :user_file => File.open(fixture_name), :to => aspect1.id) } - let(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) } - before do - connect_users(user1, aspect1, user2, aspect2) - photo1; photo2 - @controller.stub!(:current_user).and_return(user1) - sign_in :user, user1 + @user1 = alice + @user2 = bob + + @aspect1 = @user1.aspects.first + @aspect2 = @user2.aspects.first + + @photo1 = @user1.post(:photo, :user_file => uploaded_photo, :to => @aspect1.id) + @photo2 = @user2.post(:photo, :user_file => uploaded_photo, :to => @aspect2.id) + + @controller.stub!(:current_user).and_return(@user1) + sign_in :user, @user1 end it 'has working context' do - photo1.url.should_not be_nil - Photo.find(photo1.id).url.should_not be_nil - photo2.url.should_not be_nil - Photo.find(photo2.id).url.should_not be_nil + @photo1.url.should_not be_nil + Photo.find(@photo1.id).url.should_not be_nil + @photo2.url.should_not be_nil + Photo.find(@photo2.id).url.should_not be_nil end describe '#create' do before do - @controller.stub!(:file_handler).and_return(File.open(fixture_name)) - @params = {:photo => {:user_file => File.open(fixture_name), :aspect_ids => "all"} } + @controller.stub!(:file_handler).and_return(uploaded_photo) + @params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} } end it 'can make a photo' do @@ -44,100 +40,100 @@ describe PhotosController do }.should change(Photo, :count).by(1) end it 'can set the photo as the profile photo' do - old_url = user1.person.profile.image_url + old_url = @user1.person.profile.image_url @params[:photo][:set_profile_photo] = true post :create, @params - user1.reload.person.profile.image_url.should_not == old_url + @user1.reload.person.profile.image_url.should_not == old_url end end describe '#index' do it "displays the logged in user's pictures" do - get :index, :person_id => user1.person.id.to_s - assigns[:person].should == user1.person - assigns[:posts].should == [photo1] + get :index, :person_id => @user1.person.id.to_s + assigns[:person].should == @user1.person + assigns[:posts].should == [@photo1] end it "displays another person's pictures" do - get :index, :person_id => user2.person.id.to_s + get :index, :person_id => @user2.person.id.to_s - assigns[:person].should == user2.person - assigns[:posts].should == [photo2] + assigns[:person].should == @user2.person + assigns[:posts].should == [@photo2] end end describe '#show' do it 'assigns the photo based on the photo id' do - get :show, :id => photo1.id + get :show, :id => @photo1.id response.status.should == 200 - assigns[:photo].should == photo1 + assigns[:photo].should == @photo1 assigns[:ownership].should be_true end it "renders a show page for another user's photo" do - get :show, :id => photo2.id + get :show, :id => @photo2.id response.status.should == 200 - assigns[:photo].should == photo2 + assigns[:photo].should == @photo2 assigns[:ownership].should be_false end end describe '#edit' do it 'lets the user edit a photo' do - get :edit, :id => photo1.id + get :edit, :id => @photo1.id response.status.should == 200 end it 'does not let the user edit a photo that is not his' do - get :edit, :id => photo2.id - response.should redirect_to(:action => :index, :person_id => user1.person.id.to_s) + get :edit, :id => @photo2.id + response.should redirect_to(:action => :index, :person_id => @user1.person.id.to_s) end end describe '#destroy' do it 'allows the user to delete his photos' do - delete :destroy, :id => photo1.id - Photo.find_by_id(photo1.id).should be_nil + delete :destroy, :id => @photo1.id + Photo.find_by_id(@photo1.id).should be_nil end it 'will not let you destory posts you do not own' do - delete :destroy, :id => photo2.id - Photo.find_by_id(photo2.id).should be_true + delete :destroy, :id => @photo2.id + Photo.find_by_id(@photo2.id).should be_true end end describe "#update" do it "updates the caption of a photo" do - put :update, :id => photo1.id, :photo => { :caption => "now with lasers!" } - photo1.reload.caption.should == "now with lasers!" + put :update, :id => @photo1.id, :photo => { :caption => "now with lasers!" } + @photo1.reload.caption.should == "now with lasers!" end it "doesn't overwrite random attributes" do new_user = Factory.create(:user) params = { :caption => "now with lasers!", :person_id => new_user.id } - put :update, :id => photo1.id, :photo => params - photo1.reload.person_id.should == user1.person.id + put :update, :id => @photo1.id, :photo => params + @photo1.reload.person_id.should == @user1.person.id end it 'redirects if you do not have access to the post' do params = { :caption => "now with lasers!" } - put :update, :id => photo2.id, :photo => params - response.should redirect_to(:action => :index, :person_id => user1.person.id.to_s) + put :update, :id => @photo2.id, :photo => params + response.should redirect_to(:action => :index, :person_id => @user1.person.id.to_s) end end describe "#make_profile_photo" do it 'should return a 201 on a js success' do - get :make_profile_photo, :photo_id => photo1.id, :format => 'js' + get :make_profile_photo, :photo_id => @photo1.id, :format => 'js' response.code.should == "201" end it 'should return a 406 on failure' do - get :make_profile_photo, :photo_id => photo2.id + get :make_profile_photo, :photo_id => @photo2.id response.code.should == "406" end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 5c3426358..b75c9e53a 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -6,21 +6,21 @@ require 'spec_helper' describe PostsController do render_views - + before do - @user = Factory.create(:user) + @user = alice @controller.stub!(:current_user).and_return(nil) end describe '#show' do it 'shows a public post' do - status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all') + status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all') get :show, :id => status.id response.status= 200 end it 'does not show a private post' do - status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all') + status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all') get :show, :id => status.id response.status = 302 end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index fe714b2be..b3fe3cf36 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -7,60 +7,62 @@ require 'spec_helper' describe PublicsController do render_views - let(:user) { Factory.create(:user) } - let(:person) { Factory(:person) } + before do + @user = alice + @person = Factory(:person) + end describe '#receive' do let(:xml) { "" } it 'succeeds' do - post :receive, "id" => user.person.id.to_s, "xml" => xml + post :receive, "id" => @user.person.id.to_s, "xml" => xml response.should be_success end it 'enqueues a receive job' do - Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once - post :receive, "id" => user.person.id.to_s, "xml" => xml + Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, xml).once + post :receive, "id" => @user.person.id.to_s, "xml" => xml end it 'unescapes the xml before sending it to receive_salmon' do - aspect = user.aspects.create(:name => 'foo') - post1 = user.post(:status_message, :message => 'moms', :to => [aspect.id]) + aspect = @user.aspects.create(:name => 'foo') + post1 = @user.post(:status_message, :message => 'moms', :to => [aspect.id]) xml2 = post1.to_diaspora_xml user2 = Factory(:user) - salmon_factory = Salmon::SalmonSlap.create(user, xml2) + salmon_factory = Salmon::SalmonSlap.create(@user, xml2) enc_xml = salmon_factory.xml_for(user2.person) - Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, enc_xml).once + Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, enc_xml).once - post :receive, "id" => user.person.id.to_s, "xml" => CGI::escape(enc_xml) + post :receive, "id" => @user.person.id.to_s, "xml" => CGI::escape(enc_xml) end it 'returns a 422 if no xml is passed' do - post :receive, "id" => person.id.to_s + post :receive, "id" => @person.id.to_s response.code.should == '422' end it 'returns a 404 if no user is found' do - post :receive, "id" => person.id.to_s, "xml" => xml + post :receive, "id" => @person.id.to_s, "xml" => xml response.should be_not_found end end describe '#hcard' do it "succeeds" do - post :hcard, "id" => user.person.id.to_s + post :hcard, "id" => @user.person.id.to_s response.should be_success end it 'sets the person' do - post :hcard, "id" => user.person.id.to_s - assigns[:person].should == user.person + post :hcard, "id" => @user.person.id.to_s + assigns[:person].should == @user.person end it 'does not query by user id' do - post :hcard, "id" => user.id.to_s + post :hcard, "id" => 90348257609247856.to_s assigns[:person].should be_nil response.should be_not_found end @@ -68,8 +70,7 @@ describe PublicsController do describe '#webfinger' do it "succeeds when the person and user exist locally" do - user = Factory.create(:user) - post :webfinger, 'q' => user.person.diaspora_handle + post :webfinger, 'q' => @user.person.diaspora_handle response.should be_success end @@ -80,8 +81,7 @@ describe PublicsController do end it "404s when the person is local but doesn't have an owner" do - person = Factory(:person) - post :webfinger, 'q' => person.diaspora_handle + post :webfinger, 'q' => @person.diaspora_handle response.should be_not_found end diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index d6b0d19ea..92ec71b3c 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -7,17 +7,12 @@ require 'spec_helper' describe RequestsController do render_views before do - @user = Factory.create(:user) + @user = alice + @other_user = eve + @controller.stub!(:current_user).and_return(@user) sign_in :user, @user request.env["HTTP_REFERER"] = "http://test.host" - - @user.aspects.create!(:name => "lame-os") - @user.reload - - @other_user = Factory.create(:user) - @other_user.aspects.create!(:name => "meh") - @other_user.reload end describe '#destroy' do diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index d940243c6..6c4b70eb0 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -6,10 +6,6 @@ require 'spec_helper' describe ServicesController do render_views - let(:user) { Factory.create(:user) } - let!(:aspect) { user.aspects.create(:name => "lame-os") } - - let(:mock_access_token) { Object.new } let(:omniauth_auth) { @@ -21,20 +17,22 @@ describe ServicesController do } before do - sign_in :user, user - @controller.stub!(:current_user).and_return(user) + @user = alice + @aspect = @user.aspects.first + + sign_in :user, @user + @controller.stub!(:current_user).and_return(@user) mock_access_token.stub!(:token => "12345", :secret => "56789") end describe '#index' do - let!(:service1) {a = Factory(:service); user.services << a; a} - let!(:service2) {a = Factory(:service); user.services << a; a} - let!(:service3) {a = Factory(:service); user.services << a; a} - let!(:service4) {a = Factory(:service); user.services << a; a} - it 'displays all connected serivices for a user' do + 4.times do + @user.services << Factory(:service) + end + get :index - assigns[:services].should == user.services + assigns[:services].should == @user.services end end @@ -43,18 +41,18 @@ describe ServicesController do request.env['omniauth.auth'] = omniauth_auth lambda{ post :create - }.should change(user.services, :count).by(1) + }.should change(@user.services, :count).by(1) end it 'redirects to getting started if the user is getting started' do - user.getting_started = true + @user.getting_started = true request.env['omniauth.auth'] = omniauth_auth post :create response.should redirect_to getting_started_path(:step => 3) end it 'redirects to services url' do - user.getting_started = false + @user.getting_started = false request.env['omniauth.auth'] = omniauth_auth post :create response.should redirect_to services_url @@ -63,23 +61,22 @@ describe ServicesController do it 'creates a twitter service' do Service.delete_all - user.getting_started = false + @user.getting_started = false request.env['omniauth.auth'] = omniauth_auth post :create - user.reload - user.services.first.class.name.should == "Services::Twitter" + @user.reload.services.first.class.name.should == "Services::Twitter" end end describe '#destroy' do before do @service1 = Factory.create(:service) - user.services << @service1 + @user.services << @service1 end it 'destroys a service selected by id' do lambda{ delete :destroy, :id => @service1.id - }.should change(user.services, :count).by(-1) + }.should change(@user.services, :count).by(-1) end end end diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index 970edbfda..c8bab6399 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -13,13 +13,13 @@ EOT describe SocketsController do render_views before do - @user = Factory.create(:user) + @user = alice @controller = SocketsController.new end describe 'actionhash' do before do - @aspect = @user.aspects.create(:name => "losers") + @aspect = @user.aspects.first @message = @user.post :status_message, :message => "post through user for victory", :to => @aspect.id @fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png' end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 789c71d13..2b4f1926e 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -7,26 +7,25 @@ require 'spec_helper' describe StatusMessagesController do render_views - let!(:user1) { Factory.create(:user) } - let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") } - - let!(:user2) { Factory.create(:user) } - let!(:aspect2) { user2.aspects.create(:name => "WIN!!") } - before do - connect_users(user1, aspect1, user2, aspect2) + @user1 = alice + @user2 = bob + + @aspect1 = @user1.aspects.first + @aspect2 = @user2.aspects.first + request.env["HTTP_REFERER"] = "" - sign_in :user, user1 - @controller.stub!(:current_user).and_return(user1) - user1.reload + sign_in :user, @user1 + @controller.stub!(:current_user).and_return(@user1) + @user1.reload end describe '#show' do it 'succeeds' do - message = user1.build_post :status_message, :message => "ohai", :to => aspect1.id + message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id message.save! - user1.add_to_streams(message, [aspect1]) - user1.dispatch_post message, :to => aspect1.id + @user1.add_to_streams(message, [@aspect1]) + @user1.dispatch_post message, :to => @aspect1.id get :show, "id" => message.id.to_s response.should be_success @@ -39,7 +38,7 @@ describe StatusMessagesController do :public => "true", :message => "facebook, is that you?", }, - :aspect_ids => [aspect1.id.to_s] } + :aspect_ids => [@aspect1.id.to_s] } } it 'responds to js requests' do post :create, status_message_hash.merge(:format => 'js') @@ -47,14 +46,14 @@ describe StatusMessagesController do end it "doesn't overwrite person_id" do - status_message_hash[:status_message][:person_id] = user2.person.id + status_message_hash[:status_message][:person_id] = @user2.person.id post :create, status_message_hash new_message = StatusMessage.find_by_message(status_message_hash[:status_message][:message]) - new_message.person_id.should == user1.person.id + new_message.person_id.should == @user1.person.id end it "doesn't overwrite id" do - old_status_message = user1.post(:status_message, :message => "hello", :to => aspect1.id) + old_status_message = @user1.post(:status_message, :message => "hello", :to => @aspect1.id) status_message_hash[:status_message][:id] = old_status_message.id post :create, status_message_hash old_status_message.reload.message.should == 'hello' @@ -65,8 +64,8 @@ describe StatusMessagesController do fixture_filename = 'button.png' fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) - @photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) - @photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) + @photo1 = @user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => @aspect1.id) + @photo2 = @user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => @aspect1.id) @photo1.save! @photo2.save! @@ -75,7 +74,7 @@ describe StatusMessagesController do @hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s] end it "dispatches all referenced photos" do - user1.should_receive(:dispatch_post).exactly(3).times + @user1.should_receive(:dispatch_post).exactly(3).times post :create, @hash end it "sets the pending bit of referenced photos" do @@ -87,8 +86,8 @@ describe StatusMessagesController do end describe '#destroy' do - let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)} - let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)} + let!(:message) {@user1.post(:status_message, :message => "hey", :to => @aspect1.id)} + let!(:message2) {@user2.post(:status_message, :message => "hey", :to => @aspect2.id)} it 'let a user delete his photos' do delete :destroy, :id => message.id diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 7f1adfff8..84304444a 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -7,8 +7,8 @@ require 'spec_helper' describe UsersController do render_views - let(:user) { Factory.create(:user) } - let!(:aspect) { user.aspects.create(:name => "lame-os") } + let(:user) { alice } + let!(:aspect) { user.aspects.first } let!(:old_password) { user.encrypted_password } let!(:old_language) { user.language } diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 0f1eb22c5..9b41426ed 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe ApplicationHelper do before do - @user = Factory(:user) + @user = alice @person = Factory.create(:person) end @@ -41,7 +41,7 @@ describe ApplicationHelper do person_image_link(@person).should include(person_path(@person)) end end - + describe "#person_image_tag" do it "should not allow basic XSS/HTML" do @person.profile.first_name = "I'm

Evil" @@ -176,7 +176,7 @@ describe ApplicationHelper do message = '[link text](http://someurl.com "some title") [link text](http://someurl.com "some title")' markdownify(message).should == 'link text link text' end - + it "should have a robust link parsing" do message = "This [*text*](http://en.wikipedia.org/wiki/Text_(literary_theory)) with many [links](google.com) tests [_http_](http://google.com/search?q=with_multiple__underscores*and**asterisks), [___FTP___](ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4 \"File Transfer Protocol\"), [**any protocol**](foo://bar.example.org/yes_it*makes*no_sense)" markdownify(message).should == 'This text with many links tests http, FTP, any protocol' @@ -199,7 +199,7 @@ describe ApplicationHelper do it 'skips inserting newlines if you pass the newlines option' do message = "These\nare\n\some\nnew\lines" res = markdownify(message, :newlines => false) - res.should == message + res.should == message end it 'generates breaklines' do @@ -207,7 +207,7 @@ describe ApplicationHelper do res = markdownify(message) res.should == "These
are
some
new
lines" end - + it 'should render newlines and basic http links correctly' do message = "Some text, then a line break and a link\nhttp://joindiaspora.com\nsome more text" res = markdownify(message) @@ -229,19 +229,19 @@ describe ApplicationHelper do person_link(@person).should include @person.diaspora_handle end - + it 'uses diaspora handle if first name and first name are rails#blank?' do - @person.profile.first_name = " " + @person.profile.first_name = " " @person.profile.last_name = " " person_link(@person).should include @person.diaspora_handle end - + it "should not allow basic XSS/HTML" do @person.profile.first_name = "I'm

Evil" @person.profile.last_name = "I'm

Evil" person_link(@person).should_not include("

") - end + end end context 'performance' do before do diff --git a/spec/helpers/requests_helper_spec.rb b/spec/helpers/requests_helper_spec.rb deleted file mode 100644 index c02743f40..000000000 --- a/spec/helpers/requests_helper_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe RequestsHelper do - -end diff --git a/spec/helpers/sockets_helper_spec.rb b/spec/helpers/sockets_helper_spec.rb deleted file mode 100644 index 4d93f00e6..000000000 --- a/spec/helpers/sockets_helper_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -# -require 'spec_helper' - -describe SocketsHelper do -end diff --git a/spec/helpers/stream_helper_spec.rb b/spec/helpers/stream_helper_spec.rb index 2247d6945..812845457 100644 --- a/spec/helpers/stream_helper_spec.rb +++ b/spec/helpers/stream_helper_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' describe StreamHelper do before do - @user = Factory(:user) - @aspect = @user.aspects.create(:name => 'aspect') + @user = alice + @aspect = @user.aspects.first @post = @user.post(:status_message, :message => "hi", :to => @aspect.id) end it 'renders a new comment form' do - new_comment_form(@post.id).should == + new_comment_form(@post.id).should == @controller.render_to_string(:partial => 'comments/new_comment', :locals => {:post_id => @post.id}) end it 'renders it fast the second time' do diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index b6df383b4..5e8562aac 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -5,15 +5,17 @@ require 'spec_helper' describe UsersHelper do describe '#first_name_or_username' do - let(:user){ Factory(:user) } + before do + @user = alice + end it 'should display the first name if it is set' do - first_name_or_username(user).should == user.person.profile.first_name + first_name_or_username(@user).should == @user.person.profile.first_name end it 'should display the username if the first name is empty' do - user.person.profile.first_name = "" - first_name_or_username(user).should == user.username + @user.person.profile.first_name = "" + first_name_or_username(@user).should == @user.username end end end diff --git a/spec/intergration/receiving_spec.rb b/spec/intergration/receiving_spec.rb index 310cfea33..afe49755f 100644 --- a/spec/intergration/receiving_spec.rb +++ b/spec/intergration/receiving_spec.rb @@ -6,73 +6,72 @@ require 'spec_helper' describe 'a user receives a post' do - let(:user) { Factory.create(:user) } - let(:aspect) { user.aspects.create(:name => 'heroes') } - - let(:user2) { Factory.create(:user) } - let(:aspect2) { user2.aspects.create(:name => 'losers') } - - let(:user3) { Factory.create(:user) } - let(:aspect3) { user3.aspects.create(:name => 'heroes') } - def receive_with_zord(user, person, xml) zord = Postzord::Receiver.new(user, :person => person) zord.parse_and_receive(xml) end before do - connect_users(user, aspect, user2, aspect2) + @user1 = alice + @aspect = @user1.aspects.first + + @user2 = bob + @aspect2 = @user2.aspects.first + + @user3 = eve + @aspect3 = @user3.aspects.first + end it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do - contact = user.contact_for(user2.person) - user.add_contact_to_aspect(contact, user.aspects.create(:name => "villains")) - status = user2.build_post(:status_message, :message => "Users do things", :to => aspect2.id) + contact = @user1.contact_for(@user2.person) + @user1.add_contact_to_aspect(contact, @user1.aspects.create(:name => "villains")) + status = @user2.build_post(:status_message, :message => "Users do things", :to => @aspect2.id) Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once) - zord = Postzord::Receiver.new(user, :object => status, :person => user2.person) + zord = Postzord::Receiver.new(@user1, :object => status, :person => @user2.person) zord.receive_object end it 'should be able to parse and store a status message from xml' do - status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id + status_message = @user2.post :status_message, :message => 'store this!', :to => @aspect2.id xml = status_message.to_diaspora_xml - user2.delete + @user2.delete status_message.destroy lambda { - receive_with_zord(user, user2.person, xml) + receive_with_zord(@user1, @user2.person, xml) }.should change(Post,:count).by(1) end it 'should not create new aspects on message receive' do - num_aspects = user.aspects.size + num_aspects = @user1.aspects.size 2.times do |n| - status_message = user2.post :status_message, :message => "store this #{n}!", :to => aspect2.id + status_message = @user2.post :status_message, :message => "store this #{n}!", :to => @aspect2.id end - user.aspects.size.should == num_aspects + @user1.aspects.size.should == num_aspects end context 'update posts' do it 'does not update posts not marked as mutable' do - status = user.post :status_message, :message => "store this!", :to => aspect.id + status = @user1.post :status_message, :message => "store this!", :to => @aspect.id status.message = 'foo' xml = status.to_diaspora_xml - receive_with_zord(user2, user.person, xml) + receive_with_zord(@user2, @user1.person, xml) status.reload.message.should == 'store this!' end it 'updates posts marked as mutable' do - photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id) + photo = @user1.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => @aspect.id) photo.caption = 'foo' xml = photo.to_diaspora_xml - user2.reload + @user2.reload - receive_with_zord(user2, user.person, xml) + receive_with_zord(@user2, @user1.person, xml) photo.reload.caption.should match(/foo/) end @@ -80,115 +79,116 @@ describe 'a user receives a post' do describe 'post refs' do before do - @status_message = user2.post :status_message, :message => "hi", :to => aspect2.id - user.reload - aspect.reload + @status_message = @user2.post :status_message, :message => "hi", :to => @aspect2.id + @user1.reload + @aspect.reload end it "adds a received post to the aspect and visible_posts array" do - user.raw_visible_posts.include?(@status_message).should be_true - aspect.posts.include?(@status_message).should be_true + @user1.raw_visible_posts.include?(@status_message).should be_true + @aspect.posts.include?(@status_message).should be_true end it 'removes posts upon disconnecting' do - user.disconnect(user2.person) - user.reload - user.raw_visible_posts.should_not include @status_message + @user1.disconnect(@user2.person) + @user1.reload + @user1.raw_visible_posts.should_not include @status_message end it 'deletes a post if the noone links to it' do person = Factory(:person) - user.activate_contact(person, aspect) + @user1.activate_contact(person, @aspect) post = Factory.create(:status_message, :person => person) post.post_visibilities.should be_empty - receive_with_zord(user, person, post.to_diaspora_xml) - aspect.post_visibilities.reset - aspect.posts(true).should include(post) + receive_with_zord(@user1, person, post.to_diaspora_xml) + @aspect.post_visibilities.reset + @aspect.posts(true).should include(post) post.post_visibilities.reset post.post_visibilities.length.should == 1 lambda { - user.disconnected_by(person) + @user1.disconnected_by(person) }.should change(Post, :count).by(-1) end it 'deletes post_visibilities on disconnected by' do person = Factory(:person) - user.activate_contact(person, aspect) + @user1.activate_contact(person, @aspect) post = Factory.create(:status_message, :person => person) post.post_visibilities.should be_empty - receive_with_zord(user, person, post.to_diaspora_xml) - aspect.post_visibilities.reset - aspect.posts(true).should include(post) + receive_with_zord(@user1, person, post.to_diaspora_xml) + @aspect.post_visibilities.reset + @aspect.posts(true).should include(post) post.post_visibilities.reset post.post_visibilities.length.should == 1 lambda { - user.disconnected_by(person) + @user1.disconnected_by(person) }.should change{post.post_visibilities(true).count}.by(-1) end it 'should keep track of user references for one person ' do @status_message.reload - @status_message.user_refs.should == 2 + @status_message.user_refs.should == 3 - user.disconnect(user2.person) + @user1.disconnect(@user2.person) @status_message.reload - @status_message.user_refs.should == 1 + @status_message.user_refs.should == 2 end it 'should not override userrefs on receive by another person' do - @status_message.post_visibilities.reset - @status_message.user_refs.should == 2 - - user3.activate_contact(user2.person, aspect3) - xml = @status_message.to_diaspora_xml - - receive_with_zord(user3, user2.person, xml) - + new_user = Factory(:user) @status_message.post_visibilities.reset @status_message.user_refs.should == 3 - user.disconnect(user2.person) + new_user.activate_contact(@user2.person, @aspect3) + xml = @status_message.to_diaspora_xml + + receive_with_zord(new_user, @user2.person, xml) + @status_message.post_visibilities.reset - @status_message.user_refs.should == 2 + @status_message.user_refs.should == 4 + + @user1.disconnect(@user2.person) + @status_message.post_visibilities.reset + @status_message.user_refs.should == 3 end end describe 'comments' do before do - connect_users(user, aspect, user3, aspect3) - @post = user.post :status_message, :message => "hello", :to => aspect.id + connect_users(@user1, @aspect, @user3, @aspect3) + @post = @user1.post :status_message, :message => "hello", :to => @aspect.id xml = @post.to_diaspora_xml - receive_with_zord(user2, user.person, xml) - receive_with_zord(user3, user.person, xml) + receive_with_zord(@user2, @user1.person, xml) + receive_with_zord(@user3, @user1.person, xml) - @comment = user3.comment('tada',:on => @post) - @comment.post_creator_signature = @comment.sign_with_key(user.encryption_key) + @comment = @user3.comment('tada',:on => @post) + @comment.post_creator_signature = @comment.sign_with_key(@user1.encryption_key) @xml = @comment.to_diaspora_xml @comment.delete end it 'should correctly attach the user already on the pod' do - user2.reload.raw_visible_posts.size.should == 1 + @user2.reload.raw_visible_posts.size.should == 1 post_in_db = StatusMessage.find(@post.id) post_in_db.comments.should == [] - receive_with_zord(user2, user.person, @xml) + receive_with_zord(@user2, @user1.person, @xml) - post_in_db.comments(true).first.person.should == user3.person + post_in_db.comments(true).first.person.should == @user3.person end it 'should correctly marshal a stranger for the downstream user' do - remote_person = user3.person.dup - user3.person.delete - user3.delete + remote_person = @user3.person.dup + @user3.person.delete + @user3.delete remote_person.id = nil #stubs async webfinger Person.should_receive(:by_account_identifier).twice.and_return{ |handle| - if handle == user.person.diaspora_handle - user.person.save - user.person + if handle == @user1.person.diaspora_handle + @user1.person.save + @user1.person else remote_person.profile = Factory(:profile) remote_person.save! @@ -196,27 +196,27 @@ describe 'a user receives a post' do end } - user2.reload.raw_visible_posts.size.should == 1 + @user2.reload.raw_visible_posts.size.should == 1 post_in_db = StatusMessage.find(@post.id) post_in_db.comments.should == [] - receive_with_zord(user2, user.person, @xml) + receive_with_zord(@user2, @user1.person, @xml) post_in_db.comments(true).first.person.should == remote_person end end describe 'salmon' do - let(:post){user.post :status_message, :message => "hello", :to => aspect.id} - let(:salmon){user.salmon( post )} + let(:post){@user1.post :status_message, :message => "hello", :to => @aspect.id} + let(:salmon){@user1.salmon( post )} it 'processes a salmon for a post' do - salmon_xml = salmon.xml_for(user2.person) + salmon_xml = salmon.xml_for(@user2.person) - zord = Postzord::Receiver.new(user2, :salmon_xml => salmon_xml) + zord = Postzord::Receiver.new(@user2, :salmon_xml => salmon_xml) zord.perform - user2.raw_visible_posts.include?(post).should be_true + @user2.raw_visible_posts.include?(post).should be_true end end end diff --git a/spec/lib/diaspora/exporter_spec.rb b/spec/lib/diaspora/exporter_spec.rb index a3d3981ff..ed8f98ebf 100644 --- a/spec/lib/diaspora/exporter_spec.rb +++ b/spec/lib/diaspora/exporter_spec.rb @@ -8,21 +8,18 @@ require File.join(Rails.root, 'lib/diaspora/exporter') describe Diaspora::Exporter do before do - @user1 = Factory.create(:user) + @user1 = alice @user2 = Factory.create(:user) - @user3 = Factory.create(:user) + @user3 = bob - @aspect = @user1.aspects.create(:name => "Old Work") + @aspect = @user1.aspects.first @aspect1 = @user1.aspects.create(:name => "Work") @aspect2 = @user2.aspects.create(:name => "Family") - @aspect3 = @user3.aspects.create(:name => "Pivots") + @aspect3 = @user3.aspects.first @status_message1 = @user1.post(:status_message, :message => "One", :public => true, :to => @aspect1.id) @status_message2 = @user1.post(:status_message, :message => "Two", :public => true, :to => @aspect1.id) @status_message3 = @user2.post(:status_message, :message => "Three", :public => false, :to => @aspect2.id) - - @user1.reload - @user2.reload end def exported @@ -50,8 +47,7 @@ describe Diaspora::Exporter do context '' do before do - connect_users(@user1, @aspect1, @user3, @aspect3) - @user1.add_contact_to_aspect(@user1.contact_for(@user3.person), @aspect) + @user1.add_contact_to_aspect(@user1.contact_for(@user3.person), @aspect1) @user1.reload end @@ -71,10 +67,7 @@ describe Diaspora::Exporter do context '' do let(:people_xml) {exported.xpath('//people').to_s} - before do - connect_users(@user1, @aspect1, @user3, @aspect3) - @user1.reload - end + it 'should include persons id' do people_xml.should include @user3.person.guid end diff --git a/spec/lib/diaspora/ostatus_builder.rb b/spec/lib/diaspora/ostatus_builder.rb index 890c47516..687443104 100644 --- a/spec/lib/diaspora/ostatus_builder.rb +++ b/spec/lib/diaspora/ostatus_builder.rb @@ -8,8 +8,8 @@ require File.join(Rails.root, 'lib/diaspora/ostatus_builder') describe Diaspora::OstatusBuilder do - let!(:user) { Factory.create(:user) } - let(:aspect) { user.aspects.create(:name => "Public People") } + let!(:user) { alice } + let(:aspect) { user.aspects.first } let!(:public_status_messages) { 3.times.inject([]) do |arr,n| s = user.post(:status_message, :message => "hey#{n}", :public => true, :to => aspect.id) diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index b174948a6..2cab417bb 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -6,15 +6,20 @@ require 'spec_helper' describe Diaspora::Parser do before do - @user = Factory.create(:user) - @aspect = @user.aspects.create(:name => 'spies') - @user2 = Factory.create(:user) - @aspect2 = @user2.aspects.create(:name => "pandas") + @user1 = alice + @user2 = bob + @user3 = eve + + @aspect1 = @user1.aspects.first + @aspect2 = @user2.aspects.first + @aspect3 = @user3.aspects.first + @person = Factory.create(:person) end + describe "parsing compliant XML object" do it 'should be able to correctly parse comment fields' do - post = @user.post :status_message, :message => "hello", :to => @aspect.id + post = @user1.post :status_message, :message => "hello", :to => @aspect.id comment = Factory.create(:comment, :post => post, :person => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!") comment.delete xml = comment.to_diaspora_xml @@ -26,44 +31,41 @@ describe Diaspora::Parser do end it 'should accept retractions' do - connect_users(@user, @aspect, @user2, @aspect2) message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id) retraction = Retraction.for(message) xml = retraction.to_diaspora_xml lambda { - zord = Postzord::Receiver.new(@user, :person => @user2.person) + zord = Postzord::Receiver.new(@user1, :person => @user2.person) zord.parse_and_receive(xml) }.should change(StatusMessage, :count).by(-1) end it "should activate the Person if I initiated a request to that url" do - @user.send_contact_request_to(@user2.person, @aspect) - request = @user2.request_from(@user.person) + @user1.send_contact_request_to(@user3.person, @aspect) + request = @user3.request_from(@user1.person) fantasy_resque do - @user2.accept_and_respond(request.id, @aspect2.id) + @user3.accept_and_respond(request.id, @aspect3.id) end - @user.reload + @user1.reload @aspect.reload - new_contact = @user.contact_for(@user2.person) + new_contact = @user1.contact_for(@user3.person) @aspect.contacts.include?(new_contact).should be true - @user.contacts.include?(new_contact).should be true + @user1.contacts.include?(new_contact).should be true end it 'should process retraction for a person' do - connect_users(@user, @aspect, @user2, @aspect2) retraction = Retraction.for(@user2) retraction_xml = retraction.to_diaspora_xml lambda { - zord = Postzord::Receiver.new(@user, :person => @user2.person) + zord = Postzord::Receiver.new(@user1, :person => @user2.person) zord.parse_and_receive(retraction_xml) }.should change { @aspect.contacts(true).size }.by(-1) end it 'should marshal a profile for a person' do - connect_users(@user, @aspect, @user2, @aspect2) #Create person person = @user2.person id = person.id @@ -85,7 +87,7 @@ describe Diaspora::Parser do old_profile.first_name.should == 'bob' #Marshal profile - zord = Postzord::Receiver.new(@user, :person => person) + zord = Postzord::Receiver.new(@user1, :person => person) zord.parse_and_receive(xml) #Check that marshaled profile is the same as old profile diff --git a/spec/lib/diaspora/web_socket_spec.rb b/spec/lib/diaspora/web_socket_spec.rb index 0cb495cd1..eacfc9407 100644 --- a/spec/lib/diaspora/web_socket_spec.rb +++ b/spec/lib/diaspora/web_socket_spec.rb @@ -25,8 +25,8 @@ end describe Diaspora::Socketable do before do - @user = Factory.create(:user) - @aspect = @user.aspects.create(:name => "losers") + @user = alice + @aspect = @user.aspects.first @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) @post.save end diff --git a/spec/lib/diaspora/webhooks_spec.rb b/spec/lib/diaspora/webhooks_spec.rb index 590b737b7..99d2b0617 100644 --- a/spec/lib/diaspora/webhooks_spec.rb +++ b/spec/lib/diaspora/webhooks_spec.rb @@ -10,7 +10,7 @@ describe Diaspora::Webhooks do class Foo include Diaspora::Webhooks end - + f = Foo.new proc{ f.subscribers(1)}.should raise_error /override subscribers/ diff --git a/spec/lib/encryptor_spec.rb b/spec/lib/encryptor_spec.rb index 9f1e4d310..476afd08f 100644 --- a/spec/lib/encryptor_spec.rb +++ b/spec/lib/encryptor_spec.rb @@ -6,8 +6,8 @@ require 'spec_helper' describe 'user encryption' do before do - @user = Factory.create(:user) - @aspect = @user.aspects.create(:name => 'dudes') + @user = alice + @aspect = @user.aspects.first end describe 'encryption' do diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index 8e9b8ec77..14d13a24b 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -9,7 +9,7 @@ require File.join(Rails.root, 'lib/postzord/dispatch') describe Postzord::Dispatch do before do - @user = Factory(:user) + @user = alice @sm = Factory(:status_message, :public => true) @subscribers = [] 5.times{@subscribers << Factory(:person)} diff --git a/spec/lib/postzord/receiver_spec.rb b/spec/lib/postzord/receiver_spec.rb index ea97f533e..088c4ac0d 100644 --- a/spec/lib/postzord/receiver_spec.rb +++ b/spec/lib/postzord/receiver_spec.rb @@ -10,17 +10,14 @@ require File.join(Rails.root, 'lib/postzord/receiver') describe Postzord::Receiver do before do - @user = Factory(:user) - @user2 = Factory(:user) + @user = alice + @user2 = bob @person2 = @user2.person - aspect1 = @user.aspects.create(:name => "hey") - aspect2 = @user2.aspects.create(:name => "hey") - - connect_users(@user, aspect1, @user2, aspect2) + aspect1 = @user.aspects.first + aspect2 = @user2.aspects.first @original_post = @user2.build_post(:status_message, :message => "hey", :aspect_ids => [aspect2.id]) - @salmon_xml = @user2.salmon(@original_post).xml_for(@user.person) end diff --git a/spec/lib/pubsubhubbub_spec.rb b/spec/lib/pubsubhubbub_spec.rb index 6428a9aca..e1fe7bf92 100644 --- a/spec/lib/pubsubhubbub_spec.rb +++ b/spec/lib/pubsubhubbub_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' require File.join(Rails.root, 'lib', 'pubsubhubbub') describe Pubsubhubbub do - + before do RestClient.unstub!(:post) end @@ -15,9 +15,6 @@ describe Pubsubhubbub do RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success)) end - describe '#initialize' do - end - describe '#publish' do it 'posts the feed to the given hub' do hub = "http://hubzord.com/" diff --git a/spec/lib/salmon_salmon_spec.rb b/spec/lib/salmon_salmon_spec.rb index 210b9a916..4e4d4e088 100644 --- a/spec/lib/salmon_salmon_spec.rb +++ b/spec/lib/salmon_salmon_spec.rb @@ -5,8 +5,8 @@ require 'spec_helper' describe Salmon do - let(:user){Factory.create(:user)} - let(:user2) {Factory.create(:user)} + let(:user){alice} + let(:user2) {eve} let(:user3) {Factory.create(:user)} let(:post){ user.post :status_message, :message => "hi", :to => user.aspects.create(:name => "sdg").id } @@ -71,8 +71,8 @@ describe Salmon do it 'should fail if no author is found' do parsed_salmon.author_email = 'tom@tom.joindiaspora.com' - - + + proc {parsed_salmon.author.public_key}.should raise_error "did you remember to async webfinger?" end diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index 7c60e2658..712ad5e41 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -7,8 +7,8 @@ require 'spec_helper' require File.join(Rails.root, 'lib/webfinger') describe Webfinger do - let(:user1) { Factory.create(:user) } - let(:user2) { Factory.create(:user) } + let(:user1) { alice } + let(:user2) { eve } let(:account) {"foo@tom.joindiaspora.com"} let(:person){ Factory(:person, :diaspora_handle => account)} @@ -39,7 +39,7 @@ describe Webfinger do end end - context 'webfinger query chain processing' do + context 'webfinger query chain processing' do describe '#webfinger_profile_url' do it 'should parse out the webfinger template' do finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}" @@ -79,14 +79,14 @@ describe Webfinger do diaspora_finger.stub!(:body).and_return(diaspora_finger) RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) #new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") - # http://tom.joindiaspora.com/.well-known/host-meta + # http://tom.joindiaspora.com/.well-known/host-meta f = Webfinger.new("tom@tom.joindiaspora.com").fetch f.should be_valid end - + it 'should retry with http if https fails' do - f = Webfinger.new("tom@tom.joindiaspora.com") + f = Webfinger.new("tom@tom.joindiaspora.com") diaspora_xrd.stub!(:body).and_return(diaspora_xrd) RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd) diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 94509d091..e64bd47eb 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe Notifier do - let!(:user) {Factory.create(:user)} - let!(:user2) {Factory.create(:user)} + let!(:user) {alice} + let!(:user2) {eve} let!(:aspect) {user.aspects.create(:name => "win")} let!(:aspect2) {user2.aspects.create(:name => "win")} diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index a80af2750..ae8adb5bd 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -5,13 +5,13 @@ require 'spec_helper' describe Aspect do - let(:user ) { Factory.create(:user) } + let(:user ) { alice } let(:connected_person) { Factory.create(:person) } - let(:user2) { Factory.create(:user) } + let(:user2) { eve } let(:connected_person_2) { Factory.create(:person) } - let(:aspect) {user.aspects.create(:name => 'losers')} - let(:aspect2) {user2.aspects.create(:name => 'failures')} + let(:aspect) {user.aspects.first } + let(:aspect2) {user2.aspects.first } let(:aspect1) {user.aspects.create(:name => 'cats')} let(:user3) {Factory.create(:user)} let(:aspect3) {user3.aspects.create(:name => "lala")} diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 7d7e480f4..921d5538c 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -5,13 +5,11 @@ require 'spec_helper' describe Comment do - let(:user) {Factory.create(:user)} - let(:aspect) {user.aspects.create(:name => "Doofuses")} + let(:user) {alice} + let(:aspect) {user.aspects.first} - let(:user2) {Factory.create(:user)} - let(:aspect2) {user2.aspects.create(:name => "Lame-faces")} - - let!(:connecting) { connect_users(user, aspect, user2, aspect2) } + let(:user2) {bob} + let(:aspect2) {user2.aspects.first} describe '.hash_from_post_ids' do before do diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index c16763270..29fe1e135 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' describe Invitation do - let(:user) {Factory.create(:user)} - let!(:aspect) {user.aspects.create(:name => "Invitees")} - let(:user2) {Factory.create(:user)} + let(:user) {alice} + let(:aspect) {user.aspects.first} + let(:user2) {eve} before do user.invites = 20 user.save diff --git a/spec/models/jobs/notify_local_users_spec.rb b/spec/models/jobs/notify_local_users_spec.rb index 2512f07c4..61286fe88 100644 --- a/spec/models/jobs/notify_local_users_spec.rb +++ b/spec/models/jobs/notify_local_users_spec.rb @@ -7,12 +7,12 @@ require 'spec_helper' describe Jobs::NotifyLocalUsers do describe '#perfom' do it 'should call Notification.notify on the object' do - user = Factory(:user) + user = alice person = Factory :person object = Factory :status_message Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)) Jobs::NotifyLocalUsers.perform(user.id, object.class.to_s, object.id, person.id) - end + end end end diff --git a/spec/models/jobs/post_to_service_spec.rb b/spec/models/jobs/post_to_service_spec.rb index 8e0b34511..3319d39e2 100644 --- a/spec/models/jobs/post_to_service_spec.rb +++ b/spec/models/jobs/post_to_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Jobs::PostToService do it 'calls service#post with the given service' do - user = Factory(:user) + user = alice aspect = user.aspects.create(:name => "yeah") post = user.post(:status_message, :message => 'foo', :to => aspect.id) User.stub!(:find_by_id).with(user.id.to_s).and_return(user) diff --git a/spec/models/jobs/post_to_services_spec.rb b/spec/models/jobs/post_to_services_spec.rb index 09809c5d1..706119adf 100644 --- a/spec/models/jobs/post_to_services_spec.rb +++ b/spec/models/jobs/post_to_services_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Jobs::PostToServices do it 'calls post to services from the given user with given post' do - user = Factory.create(:user) + user = alice aspect = user.aspects.create(:name => "yeah") post = user.post(:status_message, :message => 'foo', :to => aspect.id) User.stub!(:find_by_id).with(user.id.to_s).and_return(user) diff --git a/spec/models/jobs/receive_local_spec.rb b/spec/models/jobs/receive_local_spec.rb index 454d64e4e..4ea62d920 100644 --- a/spec/models/jobs/receive_local_spec.rb +++ b/spec/models/jobs/receive_local_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe Jobs::ReceiveLocal do before do - @user1 = Factory.create(:user) - @user2 = Factory.create(:user) + @user1 = alice + @user2 = eve @status = Factory(:status_message) @status_type = @status.class.to_s diff --git a/spec/models/jobs/receive_salmon_spec.rb b/spec/models/jobs/receive_salmon_spec.rb index b5cd2f290..15bc2de2a 100644 --- a/spec/models/jobs/receive_salmon_spec.rb +++ b/spec/models/jobs/receive_salmon_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Jobs::ReceiveSalmon do before do - @user = Factory.create(:user) + @user = alice @xml = '' User.stub(:find){ |id| if id == @user.id diff --git a/spec/models/jobs/receive_spec.rb b/spec/models/jobs/receive_spec.rb index 0a93fba68..c5f34895e 100644 --- a/spec/models/jobs/receive_spec.rb +++ b/spec/models/jobs/receive_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Jobs::Receive do before do - @user = Factory.create(:user) + @user = alice @person = Factory(:person) @xml = '' User.stub(:find){ |id| diff --git a/spec/models/jobs/socket_webfinger_spec.rb b/spec/models/jobs/socket_webfinger_spec.rb index 4d1e53645..c17b70a07 100644 --- a/spec/models/jobs/socket_webfinger_spec.rb +++ b/spec/models/jobs/socket_webfinger_spec.rb @@ -2,7 +2,7 @@ require File.join(Rails.root, 'spec/spec_helper') describe Jobs::SocketWebfinger do before do - @user = Factory.create(:user) + @user = alice @account = "tom@tom.joindiaspora.com" end it 'Makes a Webfinger object' do @@ -30,7 +30,7 @@ describe Jobs::SocketWebfinger do Webfinger.stub(:new).and_return(finger) person = Factory.create(:person) finger.stub(:fetch).and_return(person) - + opts = {:symbol => true} person.should_receive(:socket_to_user).with(@user, opts) Jobs::SocketWebfinger.perform(@user.id, @account, opts) @@ -39,10 +39,10 @@ describe Jobs::SocketWebfinger do finger = mock() Webfinger.stub(:new).and_return(finger) finger.stub(:fetch).and_raise(Webfinger::WebfingerFailedError) - + opts = {:class => 'people', :status => 'fail', :query => @account, :response => I18n.t('people.webfinger.fail', :handle => @account )}.to_json Diaspora::WebSocket.should_receive(:queue_to_user).with(@user.id, opts) Jobs::SocketWebfinger.perform(@user.id, @account) - + end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index d7243ae44..85a5cfd53 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -8,8 +8,8 @@ describe Notification do before do @sm = Factory(:status_message) @person = Factory(:person) - @user = Factory.create(:user) - @user2 = Factory.create(:user) + @user = alice + @user2 = eve @aspect = @user.aspects.create(:name => "dudes") @opts = {:target_id => @sm.id, :target_type => @sm.class.name, diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 3609e84d7..4c9041ff2 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -6,8 +6,8 @@ require 'spec_helper' describe Photo do before do - @user = Factory.create(:user) - @aspect = @user.aspects.create(:name => "losers") + @user = alice + @aspect = @user.aspects.first @fixture_filename = 'button.png' @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 6236ae42a..2269e855f 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe Post do before do - @user = Factory(:user) + @user = alice @aspect = @user.aspects.create(:name => "winners") end diff --git a/spec/models/post_visibility_spec.rb b/spec/models/post_visibility_spec.rb index cd371ba81..3c2cf91c3 100644 --- a/spec/models/post_visibility_spec.rb +++ b/spec/models/post_visibility_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe PostVisibility do before do - @user = Factory(:user) + @user = alice @aspect = @user.aspects.create(:name => 'Boozers') @person = Factory(:person) diff --git a/spec/models/retraction_spec.rb b/spec/models/retraction_spec.rb index da60168a4..5d2050bbc 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/models/retraction_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe Retraction do - let(:user) { Factory.create(:user) } + let(:user) { alice } let(:person) { Factory(:person) } let(:aspect) { user.aspects.create(:name => "Bruisers") } let!(:activation) { user.activate_contact(person, aspect) } diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index eb851e67f..dd911cd10 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -1,10 +1,9 @@ require 'spec_helper' -describe Services::Facebook do +describe Services::Facebook do before do - @user = Factory.create(:user) - @user.aspects.create(:name => "whatever") + @user = alice @post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id) @service = Services::Facebook.new(:access_token => "yeah") @user.services << @service @@ -12,7 +11,7 @@ describe Services::Facebook do describe '#post' do it 'posts a status message to facebook' do - RestClient.should_receive(:post).with("https://graph.facebook.com/me/feed", :message => @post.message, :access_token => @service.access_token) + RestClient.should_receive(:post).with("https://graph.facebook.com/me/feed", :message => @post.message, :access_token => @service.access_token) @service.post(@post) end it 'swallows exception raised by facebook always being down' do diff --git a/spec/models/services/twitter_spec.rb b/spec/models/services/twitter_spec.rb index ccf8b20d4..5d6005ced 100644 --- a/spec/models/services/twitter_spec.rb +++ b/spec/models/services/twitter_spec.rb @@ -1,10 +1,9 @@ require 'spec_helper' -describe Services::Twitter do +describe Services::Twitter do before do - @user = Factory.create(:user) - @user.aspects.create(:name => "whatever") + @user = alice @post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id) @service = Services::Twitter.new(:access_token => "yeah", :access_secret => "foobar") @user.services << @service @@ -12,7 +11,7 @@ describe Services::Twitter do describe '#post' do it 'posts a status message to twitter' do - Twitter.should_receive(:update).with(@post.message) + Twitter.should_receive(:update).with(@post.message) @service.post(@post) end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index dc203946e..2d51d6cda 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -7,8 +7,8 @@ require 'spec_helper' describe StatusMessage do before do - @user = Factory(:user) - @aspect = @user.aspects.create(:name => "losers") + @user = alice + @aspect = @user.aspects.first end describe '#diaspora_handle=' do diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index c5c93b0da..9978e5181 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -6,13 +6,13 @@ require 'spec_helper' describe "attack vectors" do - let(:user) { Factory.create(:user) } - let(:aspect) { user.aspects.create(:name => 'heroes') } + let(:user) { alice } + let(:aspect) { user.aspects.first } let(:bad_user) { Factory.create(:user)} - let(:user2) { Factory.create(:user) } - let(:aspect2) { user2.aspects.create(:name => 'losers') } + let(:user2) { eve } + let(:aspect2) { user2.aspects.first } let(:user3) { Factory.create(:user) } let(:aspect3) { user3.aspects.create(:name => 'heroes') } diff --git a/spec/models/user/commenting_spec.rb b/spec/models/user/commenting_spec.rb index bbf4561d5..8534549e5 100644 --- a/spec/models/user/commenting_spec.rb +++ b/spec/models/user/commenting_spec.rb @@ -6,13 +6,12 @@ require 'spec_helper' describe User do - let!(:user1){Factory.create(:user)} - let!(:user2){Factory.create(:user)} - let!(:aspect1){user1.aspects.create(:name => 'heroes')} - let!(:aspect2){user2.aspects.create(:name => 'others')} + let!(:user1){alice} + let!(:user2){bob} + let!(:aspect1){user1.aspects.first} + let!(:aspect2){user2.aspects.first} before do - connect_users(user1, aspect1, user2, aspect2) @post = user1.build_post(:status_message, :message => "hey", :to => aspect1.id) @post.save user1.dispatch_post(@post, :to => "all") @@ -23,7 +22,7 @@ describe User do it "doesn't call receive on local users" do user1.should_not_receive(:receive_comment) user2.should_not_receive(:receive_comment) - + comment = user2.build_comment "why so formal?", :on => @post comment.save! user2.dispatch_comment comment @@ -34,7 +33,7 @@ describe User do it "doesn't call receive on local users" do user1.should_not_receive(:receive_comment) user2.should_not_receive(:receive_comment) - + comment = user1.build_comment "why so formal?", :on => @post comment.save! user1.dispatch_comment comment diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index d0b9be4ab..d27655352 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' describe Diaspora::UserModules::Connecting do - let(:user) { Factory.create(:user) } + let(:user) { alice } let(:aspect) { user.aspects.create(:name => 'heroes') } let(:aspect1) { user.aspects.create(:name => 'other') } let(:person) { Factory.create(:person) } @@ -14,7 +14,7 @@ describe Diaspora::UserModules::Connecting do let(:person_two) { Factory.create :person } let(:person_three) { Factory.create :person } - let(:user2) { Factory.create(:user) } + let(:user2) { eve } let(:aspect2) { user2.aspects.create(:name => "aspect two") } describe '#send_contact_request_to' do diff --git a/spec/models/user/invite_spec.rb b/spec/models/user/invite_spec.rb index 0e120e6b2..7f5c9612a 100644 --- a/spec/models/user/invite_spec.rb +++ b/spec/models/user/invite_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' describe User do - let(:inviter) {new_user = Factory.create(:user); new_user.invites = 5; new_user.save; new_user;} + let(:inviter) {new_user = eve; new_user.invites = 5; new_user.save; new_user;} let(:aspect) {inviter.aspects.create(:name => "awesome")} - let(:another_user) {Factory.create(:user)} + let(:another_user) {alice} let(:wrong_aspect) {another_user.aspects.create(:name => "super")} let(:inviter_with_3_invites) { new_user = Factory.create(:user); new_user.invites = 3; new_user.save; new_user;} let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")} diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 8615e6de4..eef990404 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -6,12 +6,12 @@ require 'spec_helper' describe User do - let!(:user) { Factory.create(:user) } - let!(:user2) { Factory.create(:user) } + let!(:user) { alice } + let!(:user2) { eve } - let!(:aspect) { user.aspects.create(:name => 'heroes') } + let!(:aspect) { user.aspects.first } let!(:aspect1) { user.aspects.create(:name => 'other') } - let!(:aspect2) { user2.aspects.create(:name => 'losers') } + let!(:aspect2) { user2.aspects.first } let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s } let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 875b2963a..0b7ba0ef7 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -7,9 +7,9 @@ require 'spec_helper' describe User do before do - @user = Factory(:user) - @aspect = @user.aspects.create(:name => "cats") - @user2 = Factory(:user_with_aspect) + @user = alice + @aspect = @user.aspects.first + @user2 = eve @aspect2 = @user2.aspects.first @person_one = Factory.create :person diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a7df19be0..ef1a48569 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' describe User do - let(:user) { Factory.create(:user) } + let(:user) { alice } let(:aspect) { user.aspects.create(:name => 'heroes') } - let(:user2) { Factory.create(:user) } + let(:user2) { eve } let(:aspect2) { user2.aspects.create(:name => 'stuff') } it 'should have a key' do @@ -16,7 +16,6 @@ describe User do describe 'overwriting people' do it 'does not overwrite old users with factory' do - pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" new_user = Factory.create(:user, :id => user.id) new_user.persisted?.should be_true new_user.id.should_not == user.id diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b824f3dfd..45bd7401a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,12 +21,13 @@ include HelperMethods Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| - #DatabaseCleaner.strategy = nil config.mock_with :mocha config.mock_with :rspec config.use_transactional_fixtures = true + config.global_fixtures = :all + config.before(:each) do I18n.locale = :en RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success)) @@ -36,14 +37,17 @@ RSpec.configure do |config| end def alice + #users(:alice) User.where(:username => 'alice').first end def bob + #users(:bob) User.where(:username => 'bob').first end def eve + #users(:eve) User.where(:username => 'eve').first end module Diaspora::WebSocket