Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
zhitomirskiyi 2011-01-18 17:23:03 -08:00
commit 960058803a
65 changed files with 551 additions and 581 deletions

2
.gitignore vendored
View file

@ -20,7 +20,7 @@ public/stylesheets/sessions.css
public/stylesheets/ui.css public/stylesheets/ui.css
public/stylesheets/mobile.css public/stylesheets/mobile.css
public/diaspora public/diaspora
spec/fixtures/users.yaml spec/fixtures/*.yml
# Uploded files and local files # Uploded files and local files
public/uploads/* public/uploads/*

View file

@ -56,12 +56,13 @@ end
group :test do group :test do
gem 'factory_girl_rails' gem 'factory_girl_rails'
gem 'fixture_builder', '~> 0.2.0'
gem 'capybara', '~> 0.3.9' gem 'capybara', '~> 0.3.9'
gem 'cucumber-rails', '0.3.2' gem 'cucumber-rails', '0.3.2'
gem 'rspec', '>= 2.0.0' gem 'rspec', '>= 2.0.0'
gem 'rspec-rails', '>= 2.0.0' gem 'rspec-rails', '>= 2.0.0'
gem 'mocha' gem 'mocha'
gem 'database_cleaner', '0.5.2' gem 'database_cleaner', '0.6.0'
gem 'webmock', :require => false gem 'webmock', :require => false
gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false
gem 'mongrel', :require => false if RUBY_VERSION.include? '1.8' gem 'mongrel', :require => false if RUBY_VERSION.include? '1.8'

View file

@ -136,7 +136,7 @@ GEM
cucumber (>= 0.8.0) cucumber (>= 0.8.0)
culerity (0.2.14) culerity (0.2.14)
daemons (1.1.0) daemons (1.1.0)
database_cleaner (0.5.2) database_cleaner (0.6.0)
devise (1.1.3) devise (1.1.3)
bcrypt-ruby (~> 2.1.2) bcrypt-ruby (~> 2.1.2)
warden (~> 0.10.7) warden (~> 0.10.7)
@ -162,6 +162,7 @@ GEM
fastthread (1.0.7) fastthread (1.0.7)
ffi (0.6.3) ffi (0.6.3)
rake (>= 0.8.7) rake (>= 0.8.7)
fixture_builder (0.2.0)
fog (0.3.25) fog (0.3.25)
builder builder
excon (>= 0.2.4) excon (>= 0.2.4)
@ -365,12 +366,13 @@ DEPENDENCIES
chef (= 0.9.12) chef (= 0.9.12)
cloudfiles (= 1.4.10) cloudfiles (= 1.4.10)
cucumber-rails (= 0.3.2) cucumber-rails (= 0.3.2)
database_cleaner (= 0.5.2) database_cleaner (= 0.6.0)
devise (= 1.1.3) devise (= 1.1.3)
devise_invitable (= 0.3.5) devise_invitable (= 0.3.5)
em-websocket! em-websocket!
factory_girl_rails factory_girl_rails
fastercsv (= 1.5.4) fastercsv (= 1.5.4)
fixture_builder (~> 0.2.0)
fog fog
haml (= 3.0.25) haml (= 3.0.25)
http_accept_language! http_accept_language!

View file

@ -9,14 +9,12 @@ describe AspectsController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = alice
@user2 = Factory.create(:user) @user2 = bob
@aspect0 = @user.aspects.create(:name => "lame-os") @aspect0 = @user.aspects.first
@aspect1 = @user.aspects.create(:name => "another aspect") @aspect1 = @user.aspects.create(:name => "another aspect")
@aspect2 = @user2.aspects.create(:name => "party people") @aspect2 = @user2.aspects.first
connect_users(@user, @aspect0, @user2, @aspect2)
@contact = @user.contact_for(@user2.person) @contact = @user.contact_for(@user2.person)
@user.getting_started = false @user.getting_started = false

View file

@ -7,14 +7,14 @@ require 'spec_helper'
describe CommentsController do describe CommentsController do
render_views 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 before do
sign_in :user, user1 @user1 = alice
@user2 = bob
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
sign_in :user, @user1
end end
describe '#create' do describe '#create' do
@ -24,7 +24,7 @@ describe CommentsController do
} }
context "on my own post" do context "on my own post" do
before do before do
@post = user1.post :status_message, :message => 'GIANTS', :to => aspect1.id @post = @user1.post :status_message, :message => 'GIANTS', :to => @aspect1.id
end end
it 'responds to format js' do it 'responds to format js' do
post :create, comment_hash.merge(:format => 'js') post :create, comment_hash.merge(:format => 'js')
@ -35,8 +35,7 @@ describe CommentsController do
context "on a post from a contact" do context "on a post from a contact" do
before do before do
connect_users(user1, aspect1, user2, aspect2) @post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id
@post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id
end end
it 'comments' do it 'comments' do
post :create, comment_hash post :create, comment_hash
@ -46,10 +45,10 @@ describe CommentsController do
new_user = Factory.create(:user) new_user = Factory.create(:user)
comment_hash[:person_id] = new_user.person.id.to_s comment_hash[:person_id] = new_user.person.id.to_s
post :create, comment_hash post :create, comment_hash
Comment.find_by_text(comment_hash[:text]).person_id.should == user1.person.id Comment.find_by_text(comment_hash[:text]).person_id.should == @user1.person.id
end end
it "doesn't overwrite id" do it "doesn't overwrite id" do
old_comment = user1.comment("hello", :on => @post) old_comment = @user1.comment("hello", :on => @post)
comment_hash[:id] = old_comment.id comment_hash[:id] = old_comment.id
post :create, comment_hash post :create, comment_hash
old_comment.reload.text.should == 'hello' old_comment.reload.text.should == 'hello'
@ -57,10 +56,10 @@ describe CommentsController do
end end
context 'on a post from a stranger' do context 'on a post from a stranger' do
before do before do
@post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id @post = eve.post :status_message, :message => 'GIANTS', :to => eve.aspects.first.id
end end
it 'posts no comment' do it 'posts no comment' do
user1.should_not_receive(:comment) @user1.should_not_receive(:comment)
post :create, comment_hash post :create, comment_hash
response.code.should == '406' response.code.should == '406'
end end

View file

@ -9,7 +9,7 @@ describe HomeController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = alice
sign_in @user sign_in @user
sign_out @user sign_out @user
end end
@ -37,7 +37,7 @@ describe HomeController do
describe "custom logging on redirect" do describe "custom logging on redirect" do
before do before do
sign_in :user, Factory(:user) sign_in :user, bob
@action = :show @action = :show
@action_params = {"lasers" => "green"} @action_params = {"lasers" => "green"}
end end

View file

@ -9,22 +9,20 @@ describe InvitationsController do
render_views render_views
let!(:user) { Factory.create(:user) }
let!(:aspect) { user.aspects.create(:name => "WIN!!") }
before do before do
@user = alice
@aspect = @user.aspects.first
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
end end
describe "#create" do describe "#create" do
before 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"}
sign_in :user, user @controller.stub!(:current_user).and_return(@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' request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
end end
@ -54,8 +52,8 @@ describe InvitationsController do
end end
it "doesn't invite anyone if you have 0 invites" do it "doesn't invite anyone if you have 0 invites" do
user.invites = 0 @user.invites = 0
user.save! @user.save!
lambda { lambda {
post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com")
}.should_not change(User, :count) }.should_not change(User, :count)
@ -69,8 +67,8 @@ describe InvitationsController do
describe "#update" do describe "#update" do
before do before do
user.invites = 5 @user.invites = 5
@invited_user = user.invite_user("a@a.com", user.aspects.first.id) @invited_user = @user.invite_user("a@a.com", @aspect.id)
@accept_params = {:user=> @accept_params = {:user=>
{:password_confirmation =>"password", {:password_confirmation =>"password",
:username=>"josh", :username=>"josh",
@ -91,7 +89,6 @@ describe InvitationsController do
end end
it 'adds a pending request' do it 'adds a pending request' do
put :update, @accept_params put :update, @accept_params
Request.where(:recipient_id => invited.person.id).count.should == 1 Request.where(:recipient_id => invited.person.id).count.should == 1
end end
@ -100,7 +97,7 @@ describe InvitationsController do
context 'failure' do context 'failure' do
before do before do
@fail_params = @accept_params @fail_params = @accept_params
@fail_params[:user][:username] = user.username @fail_params[:user][:username] = @user.username
end end
it 'stays on the invitation accept form' do it 'stays on the invitation accept form' do
put :update, @fail_params put :update, @fail_params
@ -115,7 +112,7 @@ describe InvitationsController do
describe '#new' do describe '#new' do
it 'renders' do it 'renders' do
sign_in :user, user sign_in :user, @user
get :new get :new
end end
end end

View file

@ -6,24 +6,24 @@ require 'spec_helper'
describe NotificationsController do describe NotificationsController do
let!(:user) { Factory.create(:user) }
let!(:aspect) { user.aspects.create(:name => "AWESOME!!") }
before do before do
sign_in :user, user @user = alice
@aspect = @user.aspects.first
sign_in :user, @user
end end
describe '#update' do describe '#update' do
it 'marks a notification as read' 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 put :update, :id => note.id
Notification.first.unread.should == false Notification.first.unread.should == false
end end
it 'only lets you read your own notifications' do 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) note = Notification.create(:recipient_id => user2.id)
put :update, :id => note.id put :update, :id => note.id
@ -35,8 +35,8 @@ describe NotificationsController do
describe "#read_all" do describe "#read_all" do
it 'marks all notifications as read' do it 'marks all notifications as read' do
request.env["HTTP_REFERER"] = "I wish I were spelled right" 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 Notification.where(:unread => true).count.should == 2
get :read_all get :read_all
@ -47,7 +47,7 @@ describe NotificationsController do
describe '#index' do describe '#index' do
it 'paginates the notifications' do it 'paginates the notifications' do
35.times do 35.times do
Notification.create(:recipient_id => user.id) Notification.create(:recipient_id => @user.id)
end end
get :index get :index

View file

@ -7,21 +7,20 @@ require 'spec_helper'
describe PeopleController do describe PeopleController do
render_views render_views
let(:user) { Factory.create(:user) }
let!(:aspect) { user.aspects.create(:name => "lame-os") }
before do before do
sign_in :user, user @user = alice
@aspect = @user.aspects.first
sign_in :user, @user
end end
describe '#similar_people' do describe '#similar_people' do
before do before do
@contacts = [] @contacts = []
@aspect1 = user.aspects.create(:name => "foos") @aspect1 = @user.aspects.create(:name => "foos")
@aspect2 = user.aspects.create(:name => "bars") @aspect2 = @user.aspects.create(:name => "bars")
3.times do 3.times do
@contacts << Contact.create(:user => user, :person => Factory.create(:person)) @contacts << Contact.create(:user => @user, :person => Factory.create(:person))
end end
end end
@ -57,7 +56,7 @@ describe PeopleController do
@contacts[0].save @contacts[0].save
20.times do 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.aspects << @aspect1
c.save c.save
@contacts << c @contacts << c
@ -94,14 +93,13 @@ describe PeopleController do
assigns[:people].should =~ [@eugene, eugene2] assigns[:people].should =~ [@eugene, eugene2]
end end
it 'shows a contact' do it 'shows a contact' do
user2 = Factory.create(:user) user2 = bob
connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience'))
get :index, :q => user2.person.profile.first_name.to_s get :index, :q => user2.person.profile.first_name.to_s
response.should redirect_to user2.person response.should redirect_to user2.person
end end
it 'shows a non-contact' do it 'shows a non-contact' do
user2 = Factory.create(:user) user2 = eve
user2.person.profile.searchable = true user2.person.profile.searchable = true
user2.save user2.save
get :index, :q => user2.person.profile.first_name.to_s get :index, :q => user2.person.profile.first_name.to_s
@ -121,20 +119,20 @@ describe PeopleController do
describe '#show' do describe '#show' do
it 'goes to the current_user show page' 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 response.should be_success
end end
it 'renders with a post' do it 'renders with a post' do
user.post :status_message, :message => 'test more', :to => aspect.id @user.post :status_message, :message => 'test more', :to => @aspect.id
get :show, :id => user.person.id get :show, :id => @user.person.id
response.should be_success response.should be_success
end end
it 'renders with a post' do it 'renders with a post' do
message = user.post :status_message, :message => 'test more', :to => aspect.id message = @user.post :status_message, :message => 'test more', :to => @aspect.id
user.comment 'I mean it', :on => message @user.comment 'I mean it', :on => message
get :show, :id => user.person.id get :show, :id => @user.person.id
response.should be_success response.should be_success
end end
@ -144,25 +142,24 @@ describe PeopleController do
end end
it "redirects to #index if no person is found" do 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 response.should redirect_to people_path
end end
it "renders the show page of a contact" do it "renders the show page of a contact" do
user2 = Factory.create(:user) user2 = bob
connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience'))
get :show, :id => user2.person.id get :show, :id => user2.person.id
response.should be_success response.should be_success
end end
it "renders the show page of a non-contact" do it "renders the show page of a non-contact" do
user2 = Factory.create(:user) user2 = eve
get :show, :id => user2.person.id get :show, :id => user2.person.id
response.should be_success response.should be_success
end end
it "renders with public posts of a non-contact" do 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) status_message = user2.post(:status_message, :message => "hey there", :to => 'all', :public => true)
get :show, :id => user2.person.id get :show, :id => user2.person.id
@ -173,14 +170,14 @@ describe PeopleController do
describe '#webfinger' do describe '#webfinger' do
it 'enqueues a webfinger job' do it 'enqueues a webfinger job' do
Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, user.id, user.diaspora_handle, anything).once Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once
get :retrieve_remote, :diaspora_handle => user.diaspora_handle get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
end end
end end
describe '#update' do describe '#update' do
it "sets the flash" do it "sets the flash" do
put :update, :id => user.person.id, put :update, :id => @user.person.id,
:profile => { :profile => {
:image_url => "", :image_url => "",
:first_name => "Will", :first_name => "Will",
@ -191,35 +188,35 @@ describe PeopleController do
context 'with a profile photo set' do context 'with a profile photo set' do
before do before do
@params = { :id => user.person.id, @params = { :id => @user.person.id,
:profile => :profile =>
{:image_url => "", {:image_url => "",
:last_name => user.person.profile.last_name, :last_name => @user.person.profile.last_name,
:first_name => user.person.profile.first_name }} :first_name => @user.person.profile.first_name }}
user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" @user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg"
user.person.profile.save @user.person.profile.save
end end
it "doesn't overwrite the profile photo when an empty string is passed in" do 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 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
end end
it 'does not allow mass assignment' do it 'does not allow mass assignment' do
person = user.person person = @user.person
new_user = Factory.create(:user) new_user = Factory.create(:user)
person.owner_id.should == user.id person.owner_id.should == @user.id
put :update, :id => user.person.id, :owner_id => new_user.id put :update, :id => @user.person.id, :owner_id => new_user.id
Person.find(person.id).owner_id.should == user.id Person.find(person.id).owner_id.should == @user.id
end end
it 'does not overwrite the profile diaspora handle' do 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'} } :profile => {:diaspora_handle => 'abc@a.com'} }
put :update, handle_params 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 end
end end

View file

@ -7,35 +7,31 @@ require 'spec_helper'
describe PhotosController do describe PhotosController do
render_views 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 before do
connect_users(user1, aspect1, user2, aspect2) @user1 = alice
photo1; photo2 @user2 = bob
@controller.stub!(:current_user).and_return(user1)
sign_in :user, user1 @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 end
it 'has working context' do it 'has working context' do
photo1.url.should_not be_nil @photo1.url.should_not be_nil
Photo.find(photo1.id).url.should_not be_nil Photo.find(@photo1.id).url.should_not be_nil
photo2.url.should_not be_nil @photo2.url.should_not be_nil
Photo.find(photo2.id).url.should_not be_nil Photo.find(@photo2.id).url.should_not be_nil
end end
describe '#create' do describe '#create' do
before do before do
@controller.stub!(:file_handler).and_return(File.open(fixture_name)) @controller.stub!(:file_handler).and_return(uploaded_photo)
@params = {:photo => {:user_file => File.open(fixture_name), :aspect_ids => "all"} } @params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} }
end end
it 'can make a photo' do it 'can make a photo' do
@ -44,100 +40,100 @@ describe PhotosController do
}.should change(Photo, :count).by(1) }.should change(Photo, :count).by(1)
end end
it 'can set the photo as the profile photo' do 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 @params[:photo][:set_profile_photo] = true
post :create, @params 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
end end
describe '#index' do describe '#index' do
it "displays the logged in user's pictures" do it "displays the logged in user's pictures" do
get :index, :person_id => user1.person.id.to_s get :index, :person_id => @user1.person.id.to_s
assigns[:person].should == user1.person assigns[:person].should == @user1.person
assigns[:posts].should == [photo1] assigns[:posts].should == [@photo1]
end end
it "displays another person's pictures" do 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[:person].should == @user2.person
assigns[:posts].should == [photo2] assigns[:posts].should == [@photo2]
end end
end end
describe '#show' do describe '#show' do
it 'assigns the photo based on the photo id' 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 response.status.should == 200
assigns[:photo].should == photo1 assigns[:photo].should == @photo1
assigns[:ownership].should be_true assigns[:ownership].should be_true
end end
it "renders a show page for another user's photo" do 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 response.status.should == 200
assigns[:photo].should == photo2 assigns[:photo].should == @photo2
assigns[:ownership].should be_false assigns[:ownership].should be_false
end end
end end
describe '#edit' do describe '#edit' do
it 'lets the user edit a photo' do it 'lets the user edit a photo' do
get :edit, :id => photo1.id get :edit, :id => @photo1.id
response.status.should == 200 response.status.should == 200
end end
it 'does not let the user edit a photo that is not his' do it 'does not let the user edit a photo that is not his' do
get :edit, :id => photo2.id get :edit, :id => @photo2.id
response.should redirect_to(:action => :index, :person_id => user1.person.id.to_s) response.should redirect_to(:action => :index, :person_id => @user1.person.id.to_s)
end end
end end
describe '#destroy' do describe '#destroy' do
it 'allows the user to delete his photos' do it 'allows the user to delete his photos' do
delete :destroy, :id => photo1.id delete :destroy, :id => @photo1.id
Photo.find_by_id(photo1.id).should be_nil Photo.find_by_id(@photo1.id).should be_nil
end end
it 'will not let you destory posts you do not own' do it 'will not let you destory posts you do not own' do
delete :destroy, :id => photo2.id delete :destroy, :id => @photo2.id
Photo.find_by_id(photo2.id).should be_true Photo.find_by_id(@photo2.id).should be_true
end end
end end
describe "#update" do describe "#update" do
it "updates the caption of a photo" do it "updates the caption of a photo" do
put :update, :id => photo1.id, :photo => { :caption => "now with lasers!" } put :update, :id => @photo1.id, :photo => { :caption => "now with lasers!" }
photo1.reload.caption.should == "now with lasers!" @photo1.reload.caption.should == "now with lasers!"
end end
it "doesn't overwrite random attributes" do it "doesn't overwrite random attributes" do
new_user = Factory.create(:user) new_user = Factory.create(:user)
params = { :caption => "now with lasers!", :person_id => new_user.id } params = { :caption => "now with lasers!", :person_id => new_user.id }
put :update, :id => photo1.id, :photo => params put :update, :id => @photo1.id, :photo => params
photo1.reload.person_id.should == user1.person.id @photo1.reload.person_id.should == @user1.person.id
end end
it 'redirects if you do not have access to the post' do it 'redirects if you do not have access to the post' do
params = { :caption => "now with lasers!" } params = { :caption => "now with lasers!" }
put :update, :id => photo2.id, :photo => params put :update, :id => @photo2.id, :photo => params
response.should redirect_to(:action => :index, :person_id => user1.person.id.to_s) response.should redirect_to(:action => :index, :person_id => @user1.person.id.to_s)
end end
end end
describe "#make_profile_photo" do describe "#make_profile_photo" do
it 'should return a 201 on a js success' 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" response.code.should == "201"
end end
it 'should return a 406 on failure' do 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" response.code.should == "406"
end end

View file

@ -6,21 +6,21 @@ require 'spec_helper'
describe PostsController do describe PostsController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = alice
@controller.stub!(:current_user).and_return(nil) @controller.stub!(:current_user).and_return(nil)
end end
describe '#show' do describe '#show' do
it 'shows a public post' 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 get :show, :id => status.id
response.status= 200 response.status= 200
end end
it 'does not show a private post' do 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 get :show, :id => status.id
response.status = 302 response.status = 302
end end

View file

@ -7,60 +7,61 @@ require 'spec_helper'
describe PublicsController do describe PublicsController do
render_views render_views
let(:user) { Factory.create(:user) } before do
let(:person) { Factory.create(:person) } @user = alice
@person = Factory(:person)
end
describe '#receive' do describe '#receive' do
let(:xml) { "<walruses></walruses>" } let(:xml) { "<walruses></walruses>" }
it 'succeeds' do it 'succeeds' do
post :receive, "guid" => user.person.guid.to_s, "xml" => xml post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
response.should be_success response.should be_success
end end
it 'enqueues a receive job' do it 'enqueues a receive job' do
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, xml).once
post :receive, "guid" => user.person.guid.to_s, "xml" => xml post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
end end
it 'unescapes the xml before sending it to receive_salmon' do it 'unescapes the xml before sending it to receive_salmon' do
aspect = user.aspects.create(:name => 'foo') aspect = @user.aspects.create(:name => 'foo')
post1 = user.post(:status_message, :message => 'moms', :to => [aspect.id]) post1 = @user.post(:status_message, :message => 'moms', :to => [aspect.id])
xml2 = post1.to_diaspora_xml xml2 = post1.to_diaspora_xml
user2 = Factory(:user) 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) 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, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
post :receive, "guid" => user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
end end
it 'returns a 422 if no xml is passed' do it 'returns a 422 if no xml is passed' do
post :receive, "guid" => person.guid.to_s post :receive, "guid" => @person.guid.to_s
response.code.should == '422' response.code.should == '422'
end end
it 'returns a 404 if no user is found' do it 'returns a 404 if no user is found' do
post :receive, "guid" => person.guid.to_s, "xml" => xml post :receive, "guid" => @person.guid.to_s, "xml" => xml
response.should be_not_found response.should be_not_found
end end
end end
describe '#hcard' do describe '#hcard' do
it "succeeds" do it "succeeds" do
post :hcard, "guid" => user.person.guid.to_s post :hcard, "guid" => @user.person.guid.to_s
response.should be_success response.should be_success
end end
it 'sets the person' do it 'sets the person' do
post :hcard, "guid" => user.person.guid.to_s post :hcard, "guid" => @user.person.guid.to_s
assigns[:person].should == user.person assigns[:person].should == @user.person
end end
it 'does not query by user id' do it 'does not query by user id' do
post :hcard, "guid" => user.id.to_s post :hcard, "guid" => 90348257609247856.to_s
assigns[:person].should be_nil assigns[:person].should be_nil
response.should be_not_found response.should be_not_found
end end
@ -68,8 +69,7 @@ describe PublicsController do
describe '#webfinger' do describe '#webfinger' do
it "succeeds when the person and user exist locally" 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 response.should be_success
end end
@ -80,8 +80,7 @@ describe PublicsController do
end end
it "404s when the person is local but doesn't have an owner" do 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 response.should be_not_found
end end

View file

@ -7,17 +7,12 @@ require 'spec_helper'
describe RequestsController do describe RequestsController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = alice
@other_user = eve
@controller.stub!(:current_user).and_return(@user) @controller.stub!(:current_user).and_return(@user)
sign_in :user, @user sign_in :user, @user
request.env["HTTP_REFERER"] = "http://test.host" 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 end
describe '#destroy' do describe '#destroy' do

View file

@ -6,10 +6,6 @@ require 'spec_helper'
describe ServicesController do describe ServicesController do
render_views render_views
let(:user) { Factory.create(:user) }
let!(:aspect) { user.aspects.create(:name => "lame-os") }
let(:mock_access_token) { Object.new } let(:mock_access_token) { Object.new }
let(:omniauth_auth) { let(:omniauth_auth) {
@ -21,20 +17,22 @@ describe ServicesController do
} }
before do before do
sign_in :user, user @user = alice
@controller.stub!(:current_user).and_return(user) @aspect = @user.aspects.first
sign_in :user, @user
@controller.stub!(:current_user).and_return(@user)
mock_access_token.stub!(:token => "12345", :secret => "56789") mock_access_token.stub!(:token => "12345", :secret => "56789")
end end
describe '#index' do 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 it 'displays all connected serivices for a user' do
4.times do
@user.services << Factory(:service)
end
get :index get :index
assigns[:services].should == user.services assigns[:services].should == @user.services
end end
end end
@ -43,18 +41,18 @@ describe ServicesController do
request.env['omniauth.auth'] = omniauth_auth request.env['omniauth.auth'] = omniauth_auth
lambda{ lambda{
post :create post :create
}.should change(user.services, :count).by(1) }.should change(@user.services, :count).by(1)
end end
it 'redirects to getting started if the user is getting started' do 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 request.env['omniauth.auth'] = omniauth_auth
post :create post :create
response.should redirect_to getting_started_path(:step => 3) response.should redirect_to getting_started_path(:step => 3)
end end
it 'redirects to services url' do it 'redirects to services url' do
user.getting_started = false @user.getting_started = false
request.env['omniauth.auth'] = omniauth_auth request.env['omniauth.auth'] = omniauth_auth
post :create post :create
response.should redirect_to services_url response.should redirect_to services_url
@ -63,23 +61,22 @@ describe ServicesController do
it 'creates a twitter service' do it 'creates a twitter service' do
Service.delete_all Service.delete_all
user.getting_started = false @user.getting_started = false
request.env['omniauth.auth'] = omniauth_auth request.env['omniauth.auth'] = omniauth_auth
post :create post :create
user.reload @user.reload.services.first.class.name.should == "Services::Twitter"
user.services.first.class.name.should == "Services::Twitter"
end end
end end
describe '#destroy' do describe '#destroy' do
before do before do
@service1 = Factory.create(:service) @service1 = Factory.create(:service)
user.services << @service1 @user.services << @service1
end end
it 'destroys a service selected by id' do it 'destroys a service selected by id' do
lambda{ lambda{
delete :destroy, :id => @service1.id delete :destroy, :id => @service1.id
}.should change(user.services, :count).by(-1) }.should change(@user.services, :count).by(-1)
end end
end end
end end

View file

@ -13,13 +13,13 @@ EOT
describe SocketsController do describe SocketsController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = alice
@controller = SocketsController.new @controller = SocketsController.new
end end
describe 'actionhash' do describe 'actionhash' do
before 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 @message = @user.post :status_message, :message => "post through user for victory", :to => @aspect.id
@fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png' @fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png'
end end

View file

@ -7,26 +7,25 @@ require 'spec_helper'
describe StatusMessagesController do describe StatusMessagesController do
render_views 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 before do
connect_users(user1, aspect1, user2, aspect2) @user1 = alice
@user2 = bob
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
request.env["HTTP_REFERER"] = "" request.env["HTTP_REFERER"] = ""
sign_in :user, user1 sign_in :user, @user1
@controller.stub!(:current_user).and_return(user1) @controller.stub!(:current_user).and_return(@user1)
user1.reload @user1.reload
end end
describe '#show' do describe '#show' do
it 'succeeds' 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! message.save!
user1.add_to_streams(message, [aspect1]) @user1.add_to_streams(message, [@aspect1])
user1.dispatch_post message, :to => aspect1.id @user1.dispatch_post message, :to => @aspect1.id
get :show, "id" => message.id.to_s get :show, "id" => message.id.to_s
response.should be_success response.should be_success
@ -39,7 +38,7 @@ describe StatusMessagesController do
:public => "true", :public => "true",
:message => "facebook, is that you?", :message => "facebook, is that you?",
}, },
:aspect_ids => [aspect1.id.to_s] } :aspect_ids => [@aspect1.id.to_s] }
} }
it 'responds to js requests' do it 'responds to js requests' do
post :create, status_message_hash.merge(:format => 'js') post :create, status_message_hash.merge(:format => 'js')
@ -47,14 +46,14 @@ describe StatusMessagesController do
end end
it "doesn't overwrite person_id" do 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 post :create, status_message_hash
new_message = StatusMessage.find_by_message(status_message_hash[:status_message][:message]) 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 end
it "doesn't overwrite id" do 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 status_message_hash[:status_message][:id] = old_status_message.id
post :create, status_message_hash post :create, status_message_hash
old_status_message.reload.message.should == 'hello' old_status_message.reload.message.should == 'hello'
@ -65,8 +64,8 @@ describe StatusMessagesController do
fixture_filename = 'button.png' fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
@photo1 = 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) @photo2 = @user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => @aspect1.id)
@photo1.save! @photo1.save!
@photo2.save! @photo2.save!
@ -75,7 +74,7 @@ describe StatusMessagesController do
@hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s] @hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s]
end end
it "dispatches all referenced photos" do 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 post :create, @hash
end end
it "sets the pending bit of referenced photos" do it "sets the pending bit of referenced photos" do
@ -87,8 +86,8 @@ describe StatusMessagesController do
end end
describe '#destroy' do describe '#destroy' do
let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)} let!(:message) {@user1.post(:status_message, :message => "hey", :to => @aspect1.id)}
let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)} let!(:message2) {@user2.post(:status_message, :message => "hey", :to => @aspect2.id)}
it 'let a user delete his photos' do it 'let a user delete his photos' do
delete :destroy, :id => message.id delete :destroy, :id => message.id

View file

@ -7,8 +7,8 @@ require 'spec_helper'
describe UsersController do describe UsersController do
render_views render_views
let(:user) { Factory.create(:user) } let(:user) { alice }
let!(:aspect) { user.aspects.create(:name => "lame-os") } let!(:aspect) { user.aspects.first }
let!(:old_password) { user.encrypted_password } let!(:old_password) { user.encrypted_password }
let!(:old_language) { user.language } let!(:old_language) { user.language }

View file

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

View file

@ -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

View file

@ -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

View file

@ -2,12 +2,12 @@ require 'spec_helper'
describe StreamHelper do describe StreamHelper do
before do before do
@user = Factory(:user) @user = alice
@aspect = @user.aspects.create(:name => 'aspect') @aspect = @user.aspects.first
@post = @user.post(:status_message, :message => "hi", :to => @aspect.id) @post = @user.post(:status_message, :message => "hi", :to => @aspect.id)
end end
it 'renders a new comment form' do 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}) @controller.render_to_string(:partial => 'comments/new_comment', :locals => {:post_id => @post.id})
end end
it 'renders it fast the second time' do it 'renders it fast the second time' do

View file

@ -5,15 +5,17 @@ require 'spec_helper'
describe UsersHelper do describe UsersHelper do
describe '#first_name_or_username' 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 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 end
it 'should display the username if the first name is empty' do it 'should display the username if the first name is empty' do
user.person.profile.first_name = "" @user.person.profile.first_name = ""
first_name_or_username(user).should == user.username first_name_or_username(@user).should == @user.username
end end
end end
end end

View file

@ -6,73 +6,72 @@ require 'spec_helper'
describe 'a user receives a post' do 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) def receive_with_zord(user, person, xml)
zord = Postzord::Receiver.new(user, :person => person) zord = Postzord::Receiver.new(user, :person => person)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
end end
before do 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 end
it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do
contact = user.contact_for(user2.person) contact = @user1.contact_for(@user2.person)
user.add_contact_to_aspect(contact, user.aspects.create(:name => "villains")) @user1.add_contact_to_aspect(contact, @user1.aspects.create(:name => "villains"))
status = user2.build_post(:status_message, :message => "Users do things", :to => aspect2.id) status = @user2.build_post(:status_message, :message => "Users do things", :to => @aspect2.id)
Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once) 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 zord.receive_object
end end
it 'should be able to parse and store a status message from xml' do 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 xml = status_message.to_diaspora_xml
user2.delete @user2.delete
status_message.destroy status_message.destroy
lambda { lambda {
receive_with_zord(user, user2.person, xml) receive_with_zord(@user1, @user2.person, xml)
}.should change(Post,:count).by(1) }.should change(Post,:count).by(1)
end end
it 'should not create new aspects on message receive' do it 'should not create new aspects on message receive' do
num_aspects = user.aspects.size num_aspects = @user1.aspects.size
2.times do |n| 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 end
user.aspects.size.should == num_aspects @user1.aspects.size.should == num_aspects
end end
context 'update posts' do context 'update posts' do
it 'does not update posts not marked as mutable' 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' status.message = 'foo'
xml = status.to_diaspora_xml 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!' status.reload.message.should == 'store this!'
end end
it 'updates posts marked as mutable' do 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' photo.caption = 'foo'
xml = photo.to_diaspora_xml 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/) photo.reload.caption.should match(/foo/)
end end
@ -80,115 +79,116 @@ describe 'a user receives a post' do
describe 'post refs' do describe 'post refs' do
before do before do
@status_message = user2.post :status_message, :message => "hi", :to => aspect2.id @status_message = @user2.post :status_message, :message => "hi", :to => @aspect2.id
user.reload @user1.reload
aspect.reload @aspect.reload
end end
it "adds a received post to the aspect and visible_posts array" do it "adds a received post to the aspect and visible_posts array" do
user.raw_visible_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 @aspect.posts.include?(@status_message).should be_true
end end
it 'removes posts upon disconnecting' do it 'removes posts upon disconnecting' do
user.disconnect(user2.person) @user1.disconnect(@user2.person)
user.reload @user1.reload
user.raw_visible_posts.should_not include @status_message @user1.raw_visible_posts.should_not include @status_message
end end
it 'deletes a post if the noone links to it' do it 'deletes a post if the noone links to it' do
person = Factory(:person) person = Factory(:person)
user.activate_contact(person, aspect) @user1.activate_contact(person, @aspect)
post = Factory.create(:status_message, :person => person) post = Factory.create(:status_message, :person => person)
post.post_visibilities.should be_empty post.post_visibilities.should be_empty
receive_with_zord(user, person, post.to_diaspora_xml) receive_with_zord(@user1, person, post.to_diaspora_xml)
aspect.post_visibilities.reset @aspect.post_visibilities.reset
aspect.posts(true).should include(post) @aspect.posts(true).should include(post)
post.post_visibilities.reset post.post_visibilities.reset
post.post_visibilities.length.should == 1 post.post_visibilities.length.should == 1
lambda { lambda {
user.disconnected_by(person) @user1.disconnected_by(person)
}.should change(Post, :count).by(-1) }.should change(Post, :count).by(-1)
end end
it 'deletes post_visibilities on disconnected by' do it 'deletes post_visibilities on disconnected by' do
person = Factory(:person) person = Factory(:person)
user.activate_contact(person, aspect) @user1.activate_contact(person, @aspect)
post = Factory.create(:status_message, :person => person) post = Factory.create(:status_message, :person => person)
post.post_visibilities.should be_empty post.post_visibilities.should be_empty
receive_with_zord(user, person, post.to_diaspora_xml) receive_with_zord(@user1, person, post.to_diaspora_xml)
aspect.post_visibilities.reset @aspect.post_visibilities.reset
aspect.posts(true).should include(post) @aspect.posts(true).should include(post)
post.post_visibilities.reset post.post_visibilities.reset
post.post_visibilities.length.should == 1 post.post_visibilities.length.should == 1
lambda { lambda {
user.disconnected_by(person) @user1.disconnected_by(person)
}.should change{post.post_visibilities(true).count}.by(-1) }.should change{post.post_visibilities(true).count}.by(-1)
end end
it 'should keep track of user references for one person ' do it 'should keep track of user references for one person ' do
@status_message.reload @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.reload
@status_message.user_refs.should == 1 @status_message.user_refs.should == 2
end end
it 'should not override userrefs on receive by another person' do it 'should not override userrefs on receive by another person' do
@status_message.post_visibilities.reset new_user = Factory(:user)
@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)
@status_message.post_visibilities.reset @status_message.post_visibilities.reset
@status_message.user_refs.should == 3 @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.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
end end
describe 'comments' do describe 'comments' do
before do before do
connect_users(user, aspect, user3, aspect3) connect_users(@user1, @aspect, @user3, @aspect3)
@post = user.post :status_message, :message => "hello", :to => aspect.id @post = @user1.post :status_message, :message => "hello", :to => @aspect.id
xml = @post.to_diaspora_xml xml = @post.to_diaspora_xml
receive_with_zord(user2, user.person, xml) receive_with_zord(@user2, @user1.person, xml)
receive_with_zord(user3, user.person, xml) receive_with_zord(@user3, @user1.person, xml)
@comment = user3.comment('tada',:on => @post) @comment = @user3.comment('tada',:on => @post)
@comment.post_creator_signature = @comment.sign_with_key(user.encryption_key) @comment.post_creator_signature = @comment.sign_with_key(@user1.encryption_key)
@xml = @comment.to_diaspora_xml @xml = @comment.to_diaspora_xml
@comment.delete @comment.delete
end end
it 'should correctly attach the user already on the pod' do 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 = StatusMessage.find(@post.id)
post_in_db.comments.should == [] 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 end
it 'should correctly marshal a stranger for the downstream user' do it 'should correctly marshal a stranger for the downstream user' do
remote_person = user3.person.dup remote_person = @user3.person.dup
user3.person.delete @user3.person.delete
user3.delete @user3.delete
remote_person.id = nil remote_person.id = nil
#stubs async webfinger #stubs async webfinger
Person.should_receive(:by_account_identifier).twice.and_return{ |handle| Person.should_receive(:by_account_identifier).twice.and_return{ |handle|
if handle == user.person.diaspora_handle if handle == @user1.person.diaspora_handle
user.person.save @user1.person.save
user.person @user1.person
else else
remote_person.profile = Factory(:profile) remote_person.profile = Factory(:profile)
remote_person.save! remote_person.save!
@ -196,27 +196,27 @@ describe 'a user receives a post' do
end 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 = StatusMessage.find(@post.id)
post_in_db.comments.should == [] 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 post_in_db.comments(true).first.person.should == remote_person
end end
end end
describe 'salmon' do describe 'salmon' do
let(:post){user.post :status_message, :message => "hello", :to => aspect.id} let(:post){@user1.post :status_message, :message => "hello", :to => @aspect.id}
let(:salmon){user.salmon( post )} let(:salmon){@user1.salmon( post )}
it 'processes a salmon for a post' do 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 zord.perform
user2.raw_visible_posts.include?(post).should be_true @user2.raw_visible_posts.include?(post).should be_true
end end
end end
end end

View file

@ -31,15 +31,13 @@ describe DataConversion::ImportToMysql do
@migrator.import_raw_users @migrator.import_raw_users
end end
it "imports data into the users table" do it "imports data into the users table" do
Mongo::User.count.should == 6 lambda {
User.count.should == 0 @migrator.process_raw_users
@migrator.process_raw_users }.should change(User, :count).by(Mongo::User.count)
User.count.should == 6
end end
it "imports all the columns" do it "imports all the columns" do
@migrator.process_raw_users @migrator.process_raw_users
bob = User.first bob = User.where(:mongo_id => "4d2b6eb6cc8cb43cc2000007").first
bob.mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
bob.username.should == "bob1d2f837" bob.username.should == "bob1d2f837"
bob.email.should == "bob1a25dee@pivotallabs.com" bob.email.should == "bob1a25dee@pivotallabs.com"
bob.serialized_private_key.should_not be_nil bob.serialized_private_key.should_not be_nil
@ -64,21 +62,19 @@ describe DataConversion::ImportToMysql do
@migrator.import_raw_aspects @migrator.import_raw_aspects
end end
it "imports data into the aspects table" do it "imports data into the aspects table" do
Mongo::Aspect.count.should == 4 lambda {
Aspect.count.should == 0 @migrator.process_raw_aspects
@migrator.process_raw_aspects }.should change(Aspect, :count).by(Mongo::Aspect.count)
Aspect.count.should == 4
end end
it "imports all the columns" do it "imports all the columns" do
@migrator.process_raw_aspects @migrator.process_raw_aspects
aspect = Aspect.first aspect = Aspect.where(:mongo_id => "4d2b6eb6cc8cb43cc2000008").first
aspect.name.should == "generic" aspect.name.should == "generic"
aspect.mongo_id.should == "4d2b6eb6cc8cb43cc2000008"
aspect.user_mongo_id.should == "4d2b6eb6cc8cb43cc2000007" aspect.user_mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
end end
it "sets the relation column" do it "sets the relation column" do
@migrator.process_raw_aspects @migrator.process_raw_aspects
aspect = Aspect.first aspect = Aspect.where(:mongo_id => "4d2b6eb6cc8cb43cc2000008").first
aspect.user.should == User.where(:mongo_id => aspect.user_mongo_id).first aspect.user.should == User.where(:mongo_id => aspect.user_mongo_id).first
end end
end end
@ -91,18 +87,16 @@ describe DataConversion::ImportToMysql do
end end
it "imports data into the services table" do it "imports data into the services table" do
Mongo::Service.count.should == 2 lambda {
Service.count.should == 0 @migrator.process_raw_services
@migrator.process_raw_services }.should change(Service, :count).by(Mongo::Service.count)
Service.count.should == 2
end end
it "imports all the columns" do it "imports all the columns" do
@migrator.process_raw_services @migrator.process_raw_services
service = Service.first service = Service.where(:mongo_id => "4d2b6ec4cc8cb43cc200003e").first
service.type_before_type_cast.should == "Services::Facebook" service.type_before_type_cast.should == "Services::Facebook"
service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014" service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014"
service.mongo_id.should == "4d2b6ec4cc8cb43cc200003e"
service.provider.should be_nil service.provider.should be_nil
service.uid.should be_nil service.uid.should be_nil
service.access_token.should == "yeah" service.access_token.should == "yeah"
@ -111,7 +105,7 @@ describe DataConversion::ImportToMysql do
end end
it 'sets the relation column' do it 'sets the relation column' do
@migrator.process_raw_services @migrator.process_raw_services
service = Service.first service = Service.where(:mongo_id => "4d2b6ec4cc8cb43cc200003e").first
service.user_id.should == User.where(:mongo_id => service.user_mongo_id).first.id service.user_id.should == User.where(:mongo_id => service.user_mongo_id).first.id
end end
end end
@ -182,18 +176,16 @@ describe DataConversion::ImportToMysql do
end end
it "imports data into the people table" do it "imports data into the people table" do
Mongo::Person.count.should == 10 lambda {
Person.count.should == 0 @migrator.process_raw_people
@migrator.process_raw_people }.should change(Person, :count).by(Mongo::Person.count)
Person.count.should == 10
end end
it "imports all the columns of a non-owned person" do it "imports all the columns of a non-owned person" do
@migrator.process_raw_people @migrator.process_raw_people
mongo_person = Mongo::Person.first mongo_person = Mongo::Person.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
person = Person.first person = Person.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
person.owner_id.should be_nil person.owner_id.should be_nil
person.mongo_id.should == "4d2b6eb6cc8cb43cc2000001"
person.guid.should == person.mongo_id person.guid.should == person.mongo_id
person.url.should == "http://google-1b05052.com/" person.url.should == "http://google-1b05052.com/"
person.diaspora_handle.should == "bob-person-1fe12fb@aol.com" person.diaspora_handle.should == "bob-person-1fe12fb@aol.com"
@ -203,9 +195,8 @@ describe DataConversion::ImportToMysql do
it "imports all the columns of an owned person" do it "imports all the columns of an owned person" do
@migrator.process_raw_people @migrator.process_raw_people
person = Person.where(:owner_id => User.first.id).first mongo_person = Mongo::Person.first
mongo_person = Mongo::Person.where(:mongo_id => person.mongo_id).first person = Person.where(:mongo_id => mongo_person.mongo_id).first
person.mongo_id.should == mongo_person.mongo_id
person.guid.should == mongo_person.mongo_id person.guid.should == mongo_person.mongo_id
person.url.should == mongo_person.url person.url.should == mongo_person.url
person.diaspora_handle.should == mongo_person.diaspora_handle person.diaspora_handle.should == mongo_person.diaspora_handle
@ -214,8 +205,9 @@ describe DataConversion::ImportToMysql do
end end
it 'sets the relational column of an owned person' do it 'sets the relational column of an owned person' do
@migrator.process_raw_people @migrator.process_raw_people
person = Person.where(:owner_id => User.first.id).first mongo_person = Mongo::Person.where("mongo_people.owner_mongo_id IS NOT NULL").first
person.should_not be_nil person = Person.where(:mongo_id => mongo_person.mongo_id).first
person.owner.should_not be_nil
person.diaspora_handle.should include(person.owner.username) person.diaspora_handle.should include(person.owner.username)
end end
end end
@ -229,17 +221,15 @@ describe DataConversion::ImportToMysql do
end end
it "imports data into the mongo_contacts table" do it "imports data into the mongo_contacts table" do
Mongo::Contact.count.should == 6 lambda {
Contact.count.should == 0 @migrator.process_raw_contacts
@migrator.process_raw_contacts }.should change(Contact, :count).by(Mongo::Contact.count)
Contact.count.should == 6
end end
it "imports all the columns" do it "imports all the columns" do
@migrator.process_raw_contacts @migrator.process_raw_contacts
contact = Contact.first mongo_contact = Mongo::Contact.first
mongo_contact = Mongo::Contact.where(:mongo_id => contact.mongo_id).first contact = Contact.where(:mongo_id => mongo_contact.mongo_id).first
contact.mongo_id.should == "4d2b6eb7cc8cb43cc200000f"
contact.user_id.should == User.where(:mongo_id => mongo_contact.user_mongo_id).first.id contact.user_id.should == User.where(:mongo_id => mongo_contact.user_mongo_id).first.id
contact.person_id.should == Person.where(:mongo_id => mongo_contact.person_mongo_id).first.id contact.person_id.should == Person.where(:mongo_id => mongo_contact.person_mongo_id).first.id
contact.pending.should be_false contact.pending.should be_false
@ -257,18 +247,18 @@ describe DataConversion::ImportToMysql do
end end
it "imports data into the mongo_aspect_memberships table" do it "imports data into the mongo_aspect_memberships table" do
Mongo::AspectMembership.count.should == 6 lambda {
AspectMembership.count.should == 0 @migrator.process_raw_aspect_memberships
@migrator.process_raw_aspect_memberships }.should change(AspectMembership, :count).by(Mongo::AspectMembership.count)
AspectMembership.count.should == 6
end end
it "imports all the columns" do it "imports all the columns" do
@migrator.process_raw_aspect_memberships @migrator.process_raw_aspect_memberships
aspectm = AspectMembership.first
mongo_aspectm = Mongo::AspectMembership.first mongo_aspectm = Mongo::AspectMembership.first
aspectm.contact_id.should == Contact.where(:mongo_id => mongo_aspectm.contact_mongo_id).first.id aspectm = AspectMembership.where(
aspectm.aspect_id.should == Aspect.where(:mongo_id => mongo_aspectm.aspect_mongo_id).first.id :contact_id => Contact.where(:mongo_id => mongo_aspectm.contact_mongo_id).first.id,
:aspect_id => Aspect.where(:mongo_id => mongo_aspectm.aspect_mongo_id).first.id).first
aspectm.should_not be_nil
end end
end end
describe "profiles" do describe "profiles" do
@ -280,19 +270,17 @@ describe DataConversion::ImportToMysql do
end end
it "processs data into the mongo_profiles table" do it "processs data into the mongo_profiles table" do
Mongo::Profile.count.should == 10 lambda {
Profile.count.should == 0 @migrator.process_raw_profiles
@migrator.process_raw_profiles }.should change(Profile, :count).by(Mongo::Profile.count)
Profile.count.should == 10
end end
it "processs all the columns" do it "processs all the columns" do
@migrator.process_raw_profiles @migrator.process_raw_profiles
profile = Profile.first profile = Profile.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
profile.image_url_medium.should be_nil profile.image_url_medium.should be_nil
profile.searchable.should == true profile.searchable.should == true
profile.image_url.should be_nil profile.image_url.should be_nil
profile.mongo_id.should == "4d2b6eb6cc8cb43cc2000001"
profile.gender.should be_nil profile.gender.should be_nil
profile.diaspora_handle.should == profile.person.diaspora_handle profile.diaspora_handle.should == profile.person.diaspora_handle
profile.last_name.should == 'weinstien' profile.last_name.should == 'weinstien'
@ -315,10 +303,9 @@ describe DataConversion::ImportToMysql do
end end
it "imports data into the posts table" do it "imports data into the posts table" do
Mongo::Post.count.should == 6 lambda {
Post.count.should == 0 @migrator.process_raw_posts
@migrator.process_raw_posts }.should change(Post, :count).by(Mongo::Post.count)
Post.count.should == 6
end end
it "imports all the columns" do it "imports all the columns" do
@ -374,11 +361,10 @@ describe DataConversion::ImportToMysql do
@migrator.import_raw_comments @migrator.import_raw_comments
end end
it "imports data into the mongo_comments table" do it "imports data into the comments table" do
Mongo::Comment.count.should == 2 lambda {
Comment.count.should == 0 @migrator.process_raw_comments
@migrator.process_raw_comments }.should change(Comment, :count).by(Mongo::Comment.count)
Comment.count.should == 2
end end
it "processes all the columns" do it "processes all the columns" do

View file

@ -8,21 +8,18 @@ require File.join(Rails.root, 'lib/diaspora/exporter')
describe Diaspora::Exporter do describe Diaspora::Exporter do
before do before do
@user1 = Factory.create(:user) @user1 = alice
@user2 = Factory.create(:user) @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") @aspect1 = @user1.aspects.create(:name => "Work")
@aspect2 = @user2.aspects.create(:name => "Family") @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_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_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) @status_message3 = @user2.post(:status_message, :message => "Three", :public => false, :to => @aspect2.id)
@user1.reload
@user2.reload
end end
def exported def exported
@ -50,8 +47,7 @@ describe Diaspora::Exporter do
context '<contacts/>' do context '<contacts/>' do
before do before do
connect_users(@user1, @aspect1, @user3, @aspect3) @user1.add_contact_to_aspect(@user1.contact_for(@user3.person), @aspect1)
@user1.add_contact_to_aspect(@user1.contact_for(@user3.person), @aspect)
@user1.reload @user1.reload
end end
@ -71,10 +67,7 @@ describe Diaspora::Exporter do
context '<people/>' do context '<people/>' do
let(:people_xml) {exported.xpath('//people').to_s} 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 it 'should include persons id' do
people_xml.should include @user3.person.guid people_xml.should include @user3.person.guid
end end

View file

@ -8,8 +8,8 @@ require File.join(Rails.root, 'lib/diaspora/ostatus_builder')
describe Diaspora::OstatusBuilder do describe Diaspora::OstatusBuilder do
let!(:user) { Factory.create(:user) } let!(:user) { alice }
let(:aspect) { user.aspects.create(:name => "Public People") } let(:aspect) { user.aspects.first }
let!(:public_status_messages) { let!(:public_status_messages) {
3.times.inject([]) do |arr,n| 3.times.inject([]) do |arr,n|
s = user.post(:status_message, :message => "hey#{n}", :public => true, :to => aspect.id) s = user.post(:status_message, :message => "hey#{n}", :public => true, :to => aspect.id)

View file

@ -6,15 +6,20 @@ require 'spec_helper'
describe Diaspora::Parser do describe Diaspora::Parser do
before do before do
@user = Factory.create(:user) @user1 = alice
@aspect = @user.aspects.create(:name => 'spies') @user2 = bob
@user2 = Factory.create(:user) @user3 = eve
@aspect2 = @user2.aspects.create(:name => "pandas")
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
@aspect3 = @user3.aspects.first
@person = Factory.create(:person) @person = Factory.create(:person)
end end
describe "parsing compliant XML object" do describe "parsing compliant XML object" do
it 'should be able to correctly parse comment fields' 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 => @aspect1.id
comment = Factory.create(:comment, :post => post, :person => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!") comment = Factory.create(:comment, :post => post, :person => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!")
comment.delete comment.delete
xml = comment.to_diaspora_xml xml = comment.to_diaspora_xml
@ -26,44 +31,41 @@ describe Diaspora::Parser do
end end
it 'should accept retractions' do it 'should accept retractions' do
connect_users(@user, @aspect, @user2, @aspect2)
message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id) message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
retraction = Retraction.for(message) retraction = Retraction.for(message)
xml = retraction.to_diaspora_xml xml = retraction.to_diaspora_xml
lambda { lambda {
zord = Postzord::Receiver.new(@user, :person => @user2.person) zord = Postzord::Receiver.new(@user1, :person => @user2.person)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
}.should change(StatusMessage, :count).by(-1) }.should change(StatusMessage, :count).by(-1)
end end
it "should activate the Person if I initiated a request to that url" do it "should activate the Person if I initiated a request to that url" do
@user.send_contact_request_to(@user2.person, @aspect) @user1.send_contact_request_to(@user3.person, @aspect1)
request = @user2.request_from(@user.person) request = @user3.request_from(@user1.person)
fantasy_resque do fantasy_resque do
@user2.accept_and_respond(request.id, @aspect2.id) @user3.accept_and_respond(request.id, @aspect3.id)
end end
@user.reload @user1.reload
@aspect.reload @aspect1.reload
new_contact = @user.contact_for(@user2.person) new_contact = @user1.contact_for(@user3.person)
@aspect.contacts.include?(new_contact).should be true @aspect1.contacts.include?(new_contact).should be true
@user.contacts.reload.include?(new_contact).should be true @user1.contacts.include?(new_contact).should be true
end end
it 'should process retraction for a person' do it 'should process retraction for a person' do
connect_users(@user, @aspect, @user2, @aspect2)
retraction = Retraction.for(@user2) retraction = Retraction.for(@user2)
retraction_xml = retraction.to_diaspora_xml retraction_xml = retraction.to_diaspora_xml
lambda { lambda {
zord = Postzord::Receiver.new(@user, :person => @user2.person) zord = Postzord::Receiver.new(@user1, :person => @user2.person)
zord.parse_and_receive(retraction_xml) zord.parse_and_receive(retraction_xml)
}.should change { }.should change {
@aspect.contacts(true).size }.by(-1) @aspect1.contacts(true).size }.by(-1)
end end
it 'should marshal a profile for a person' do it 'should marshal a profile for a person' do
connect_users(@user, @aspect, @user2, @aspect2)
#Create person #Create person
person = @user2.person person = @user2.person
id = person.id id = person.id
@ -85,7 +87,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob' old_profile.first_name.should == 'bob'
#Marshal profile #Marshal profile
zord = Postzord::Receiver.new(@user, :person => person) zord = Postzord::Receiver.new(@user1, :person => person)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
#Check that marshaled profile is the same as old profile #Check that marshaled profile is the same as old profile

View file

@ -25,8 +25,8 @@ end
describe Diaspora::Socketable do describe Diaspora::Socketable do
before do before do
@user = Factory.create(:user) @user = alice
@aspect = @user.aspects.create(:name => "losers") @aspect = @user.aspects.first
@post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id)
@post.save @post.save
end end

View file

@ -10,7 +10,7 @@ describe Diaspora::Webhooks do
class Foo class Foo
include Diaspora::Webhooks include Diaspora::Webhooks
end end
f = Foo.new f = Foo.new
proc{ f.subscribers(1)}.should raise_error /override subscribers/ proc{ f.subscribers(1)}.should raise_error /override subscribers/

View file

@ -6,8 +6,8 @@ require 'spec_helper'
describe 'user encryption' do describe 'user encryption' do
before do before do
@user = Factory.create(:user) @user = alice
@aspect = @user.aspects.create(:name => 'dudes') @aspect = @user.aspects.first
end end
describe 'encryption' do describe 'encryption' do

View file

@ -9,7 +9,7 @@ require File.join(Rails.root, 'lib/postzord/dispatch')
describe Postzord::Dispatch do describe Postzord::Dispatch do
before do before do
@user = Factory(:user) @user = alice
@sm = Factory(:status_message, :public => true) @sm = Factory(:status_message, :public => true)
@subscribers = [] @subscribers = []
5.times{@subscribers << Factory(:person)} 5.times{@subscribers << Factory(:person)}

View file

@ -10,17 +10,14 @@ require File.join(Rails.root, 'lib/postzord/receiver')
describe Postzord::Receiver do describe Postzord::Receiver do
before do before do
@user = Factory(:user) @user = alice
@user2 = Factory(:user) @user2 = bob
@person2 = @user2.person @person2 = @user2.person
aspect1 = @user.aspects.create(:name => "hey") aspect1 = @user.aspects.first
aspect2 = @user2.aspects.create(:name => "hey") aspect2 = @user2.aspects.first
connect_users(@user, aspect1, @user2, aspect2)
@original_post = @user2.build_post(:status_message, :message => "hey", :aspect_ids => [aspect2.id]) @original_post = @user2.build_post(:status_message, :message => "hey", :aspect_ids => [aspect2.id])
@salmon_xml = @user2.salmon(@original_post).xml_for(@user.person) @salmon_xml = @user2.salmon(@original_post).xml_for(@user.person)
end end

View file

@ -6,7 +6,7 @@ require 'spec_helper'
require File.join(Rails.root, 'lib', 'pubsubhubbub') require File.join(Rails.root, 'lib', 'pubsubhubbub')
describe Pubsubhubbub do describe Pubsubhubbub do
before do before do
RestClient.unstub!(:post) RestClient.unstub!(:post)
end end
@ -15,9 +15,6 @@ describe Pubsubhubbub do
RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success)) RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success))
end end
describe '#initialize' do
end
describe '#publish' do describe '#publish' do
it 'posts the feed to the given hub' do it 'posts the feed to the given hub' do
hub = "http://hubzord.com/" hub = "http://hubzord.com/"

View file

@ -28,12 +28,11 @@ describe RakeHelpers do
end end
it 'should make a user with 10 invites' do it 'should make a user with 10 invites' do
User.count.should == 0 lambda {
process_emails(@csv, 1, 1, 10, false)
}.should change(User, :count).by(1)
process_emails(@csv, 1, 1, 10, false) User.last.invites.should == 10
User.count.should == 1
User.first.invites.should == 10
end end
end end
end end

View file

@ -5,8 +5,8 @@
require 'spec_helper' require 'spec_helper'
describe Salmon do describe Salmon do
let(:user){Factory.create(:user)} let(:user){alice}
let(:user2) {Factory.create(:user)} let(:user2) {eve}
let(:user3) {Factory.create(:user)} let(:user3) {Factory.create(:user)}
let(:post){ user.post :status_message, :message => "hi", :to => user.aspects.create(:name => "sdg").id } 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 it 'should fail if no author is found' do
parsed_salmon.author_email = 'tom@tom.joindiaspora.com' parsed_salmon.author_email = 'tom@tom.joindiaspora.com'
proc {parsed_salmon.author.public_key}.should raise_error "did you remember to async webfinger?" proc {parsed_salmon.author.public_key}.should raise_error "did you remember to async webfinger?"
end end

View file

@ -7,8 +7,8 @@ require 'spec_helper'
require File.join(Rails.root, 'lib/webfinger') require File.join(Rails.root, 'lib/webfinger')
describe Webfinger do describe Webfinger do
let(:user1) { Factory.create(:user) } let(:user1) { alice }
let(:user2) { Factory.create(:user) } let(:user2) { eve }
let(:account) {"foo@tom.joindiaspora.com"} let(:account) {"foo@tom.joindiaspora.com"}
let(:person){ Factory(:person, :diaspora_handle => account)} let(:person){ Factory(:person, :diaspora_handle => account)}
@ -39,7 +39,7 @@ describe Webfinger do
end end
end end
context 'webfinger query chain processing' do context 'webfinger query chain processing' do
describe '#webfinger_profile_url' do describe '#webfinger_profile_url' do
it 'should parse out the webfinger template' do it 'should parse out the webfinger template' do
finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}" 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) diaspora_finger.stub!(:body).and_return(diaspora_finger)
RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml)
#new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") #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 = Webfinger.new("tom@tom.joindiaspora.com").fetch
f.should be_valid f.should be_valid
end end
it 'should retry with http if https fails' do 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) diaspora_xrd.stub!(:body).and_return(diaspora_xrd)
RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd) RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd)

View file

@ -2,8 +2,8 @@
require 'spec_helper' require 'spec_helper'
describe Notifier do describe Notifier do
let!(:user) {Factory.create(:user)} let!(:user) {alice}
let!(:user2) {Factory.create(:user)} let!(:user2) {eve}
let!(:aspect) {user.aspects.create(:name => "win")} let!(:aspect) {user.aspects.create(:name => "win")}
let!(:aspect2) {user2.aspects.create(:name => "win")} let!(:aspect2) {user2.aspects.create(:name => "win")}

View file

@ -5,30 +5,25 @@
require 'spec_helper' require 'spec_helper'
describe 'making sure the spec runner works' do describe 'making sure the spec runner works' do
it 'factoy creates a user with a person saved' do it 'factory creates a user with a person saved' do
user = Factory.create(:user) user = Factory.create(:user)
loaded_user = User.find(user.id) loaded_user = User.find(user.id)
loaded_user.person.owner_id.should == user.id loaded_user.person.owner_id.should == user.id
end end
describe 'fixtures' do
describe 'factories' do it 'loads fixtures' do
describe 'build' do User.count.should == 3
it 'does not save a built user' do
Factory.build(:user).should_not be_persisted
end
it 'does not save a built person' do
Factory.build(:person).should_not be_persisted
end
end end
end end
describe '#connect_users' do describe '#connect_users' do
before do before do
@user1 = Factory.create(:user) @user1 = User.where(:username => 'alice').first
@aspect1 = @user1.aspects.create(:name => "losers") @user2 = User.where(:username => 'eve').first
@user2 = Factory.create(:user)
@aspect2 = @user2.aspects.create(:name => "bruisers") @aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
connect_users(@user1, @aspect1, @user2, @aspect2) connect_users(@user1, @aspect1, @user2, @aspect2)
end end

View file

@ -5,13 +5,13 @@
require 'spec_helper' require 'spec_helper'
describe Aspect do describe Aspect do
let(:user ) { Factory.create(:user) } let(:user ) { alice }
let(:connected_person) { Factory.create(:person) } let(:connected_person) { Factory.create(:person) }
let(:user2) { Factory.create(:user) } let(:user2) { eve }
let(:connected_person_2) { Factory.create(:person) } let(:connected_person_2) { Factory.create(:person) }
let(:aspect) {user.aspects.create(:name => 'losers')} let(:aspect) {user.aspects.first }
let(:aspect2) {user2.aspects.create(:name => 'failures')} let(:aspect2) {user2.aspects.first }
let(:aspect1) {user.aspects.create(:name => 'cats')} let(:aspect1) {user.aspects.create(:name => 'cats')}
let(:user3) {Factory.create(:user)} let(:user3) {Factory.create(:user)}
let(:aspect3) {user3.aspects.create(:name => "lala")} let(:aspect3) {user3.aspects.create(:name => "lala")}
@ -59,8 +59,9 @@ describe Aspect do
end end
it 'has no uniqueness between users' do it 'has no uniqueness between users' do
aspect = user.aspects.create(:name => "New Aspect")
aspect2 = user2.aspects.create(:name => aspect.name) aspect2 = user2.aspects.create(:name => aspect.name)
aspect2.valid?.should be_true aspect2.should be_valid
end end
end end
@ -76,7 +77,7 @@ describe Aspect do
end end
it 'should have contacts' do it 'should have contacts' do
aspect.contacts.size.should == 1 aspect.contacts.size.should == 2
end end
describe '#aspects_with_person' do describe '#aspects_with_person' do

View file

@ -5,13 +5,11 @@
require 'spec_helper' require 'spec_helper'
describe Comment do describe Comment do
let(:user) {Factory.create(:user)} let(:user) {alice}
let(:aspect) {user.aspects.create(:name => "Doofuses")} let(:aspect) {user.aspects.first}
let(:user2) {Factory.create(:user)} let(:user2) {bob}
let(:aspect2) {user2.aspects.create(:name => "Lame-faces")} let(:aspect2) {user2.aspects.first}
let!(:connecting) { connect_users(user, aspect, user2, aspect2) }
describe 'comment#notification_type' do describe 'comment#notification_type' do

View file

@ -5,9 +5,9 @@
require 'spec_helper' require 'spec_helper'
describe Invitation do describe Invitation do
let(:user) {Factory.create(:user)} let(:user) {alice}
let!(:aspect) {user.aspects.create(:name => "Invitees")} let(:aspect) {user.aspects.first}
let(:user2) {Factory.create(:user)} let(:user2) {eve}
before do before do
user.invites = 20 user.invites = 20
user.save user.save

View file

@ -7,12 +7,12 @@ require 'spec_helper'
describe Jobs::NotifyLocalUsers do describe Jobs::NotifyLocalUsers do
describe '#perfom' do describe '#perfom' do
it 'should call Notification.notify on the object' do it 'should call Notification.notify on the object' do
user = Factory(:user) user = alice
person = Factory :person person = Factory :person
object = Factory :status_message object = Factory :status_message
Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)) 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) Jobs::NotifyLocalUsers.perform(user.id, object.class.to_s, object.id, person.id)
end end
end end
end end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Jobs::PostToService do describe Jobs::PostToService do
it 'calls service#post with the given service' do it 'calls service#post with the given service' do
user = Factory(:user) user = alice
aspect = user.aspects.create(:name => "yeah") aspect = user.aspects.create(:name => "yeah")
post = user.post(:status_message, :message => 'foo', :to => aspect.id) post = user.post(:status_message, :message => 'foo', :to => aspect.id)
User.stub!(:find_by_id).with(user.id.to_s).and_return(user) User.stub!(:find_by_id).with(user.id.to_s).and_return(user)

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Jobs::PostToServices do describe Jobs::PostToServices do
it 'calls post to services from the given user with given post' 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") aspect = user.aspects.create(:name => "yeah")
post = user.post(:status_message, :message => 'foo', :to => aspect.id) post = user.post(:status_message, :message => 'foo', :to => aspect.id)
User.stub!(:find_by_id).with(user.id.to_s).and_return(user) User.stub!(:find_by_id).with(user.id.to_s).and_return(user)

View file

@ -2,8 +2,10 @@ require 'spec_helper'
describe Jobs::ReceiveLocal do describe Jobs::ReceiveLocal do
before do before do
@user1 = Factory.create(:user) @user1 = alice
@user2 = Factory.create(:user) @person1 = @user1.person
@user2 = eve
@person2 = @user2.person
@status = Factory(:status_message) @status = Factory(:status_message)
@status_type = @status.class.to_s @status_type = @status.class.to_s
@ -16,8 +18,8 @@ describe Jobs::ReceiveLocal do
} }
Person.stub(:find){ |id| Person.stub(:find){ |id|
if id == @user2.person.id if id == @person2.id
@user2.person @person2
else else
nil nil
end end
@ -36,6 +38,6 @@ describe Jobs::ReceiveLocal do
m = mock() m = mock()
m.should_receive(:receive_object) m.should_receive(:receive_object)
Postzord::Receiver.should_receive(:new).and_return(m) Postzord::Receiver.should_receive(:new).and_return(m)
Jobs::ReceiveLocal.perform(@user1.id, @user2.person.id, @status_type, @status.id) Jobs::ReceiveLocal.perform(@user1.id, @person2.id, @status_type, @status.id)
end end
end end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Jobs::ReceiveSalmon do describe Jobs::ReceiveSalmon do
before do before do
@user = Factory.create(:user) @user = alice
@xml = '<xml></xml>' @xml = '<xml></xml>'
User.stub(:find){ |id| User.stub(:find){ |id|
if id == @user.id if id == @user.id

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Jobs::Receive do describe Jobs::Receive do
before do before do
@user = Factory.create(:user) @user = alice
@person = Factory(:person) @person = Factory(:person)
@xml = '<xml></xml>' @xml = '<xml></xml>'
User.stub(:find){ |id| User.stub(:find){ |id|

View file

@ -2,7 +2,7 @@ require File.join(Rails.root, 'spec/spec_helper')
describe Jobs::SocketWebfinger do describe Jobs::SocketWebfinger do
before do before do
@user = Factory.create(:user) @user = alice
@account = "tom@tom.joindiaspora.com" @account = "tom@tom.joindiaspora.com"
end end
it 'Makes a Webfinger object' do it 'Makes a Webfinger object' do
@ -30,7 +30,7 @@ describe Jobs::SocketWebfinger do
Webfinger.stub(:new).and_return(finger) Webfinger.stub(:new).and_return(finger)
person = Factory.create(:person) person = Factory.create(:person)
finger.stub(:fetch).and_return(person) finger.stub(:fetch).and_return(person)
opts = {:symbol => true} opts = {:symbol => true}
person.should_receive(:socket_to_user).with(@user, opts) person.should_receive(:socket_to_user).with(@user, opts)
Jobs::SocketWebfinger.perform(@user.id, @account, opts) Jobs::SocketWebfinger.perform(@user.id, @account, opts)
@ -39,10 +39,10 @@ describe Jobs::SocketWebfinger do
finger = mock() finger = mock()
Webfinger.stub(:new).and_return(finger) Webfinger.stub(:new).and_return(finger)
finger.stub(:fetch).and_raise(Webfinger::WebfingerFailedError) finger.stub(:fetch).and_raise(Webfinger::WebfingerFailedError)
opts = {:class => 'people', :status => 'fail', :query => @account, :response => I18n.t('people.webfinger.fail', :handle => @account )}.to_json 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) Diaspora::WebSocket.should_receive(:queue_to_user).with(@user.id, opts)
Jobs::SocketWebfinger.perform(@user.id, @account) Jobs::SocketWebfinger.perform(@user.id, @account)
end end
end end

View file

@ -8,8 +8,8 @@ describe Notification do
before do before do
@sm = Factory(:status_message) @sm = Factory(:status_message)
@person = Factory(:person) @person = Factory(:person)
@user = Factory.create(:user) @user = alice
@user2 = Factory.create(:user) @user2 = eve
@aspect = @user.aspects.create(:name => "dudes") @aspect = @user.aspects.create(:name => "dudes")
@opts = {:target_id => @sm.id, @opts = {:target_id => @sm.id,
:target_type => @sm.class.name, :target_type => @sm.class.name,

View file

@ -6,8 +6,8 @@ require 'spec_helper'
describe Photo do describe Photo do
before do before do
@user = Factory.create(:user) @user = alice
@aspect = @user.aspects.create(:name => "losers") @aspect = @user.aspects.first
@fixture_filename = 'button.png' @fixture_filename = 'button.png'
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)

View file

@ -6,7 +6,7 @@ require 'spec_helper'
describe Post do describe Post do
before do before do
@user = Factory(:user) @user = alice
@aspect = @user.aspects.create(:name => "winners") @aspect = @user.aspects.create(:name => "winners")
end end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe PostVisibility do describe PostVisibility do
before do before do
@user = Factory(:user) @user = alice
@aspect = @user.aspects.create(:name => 'Boozers') @aspect = @user.aspects.create(:name => 'Boozers')
@person = Factory(:person) @person = Factory(:person)

View file

@ -6,7 +6,7 @@ require 'spec_helper'
describe Retraction do describe Retraction do
let(:user) { Factory.create(:user) } let(:user) { alice }
let(:person) { Factory(:person) } let(:person) { Factory(:person) }
let(:aspect) { user.aspects.create(:name => "Bruisers") } let(:aspect) { user.aspects.create(:name => "Bruisers") }
let!(:activation) { user.activate_contact(person, aspect) } let!(:activation) { user.activate_contact(person, aspect) }

View file

@ -1,10 +1,9 @@
require 'spec_helper' require 'spec_helper'
describe Services::Facebook do describe Services::Facebook do
before do before do
@user = Factory.create(:user) @user = alice
@user.aspects.create(:name => "whatever")
@post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id) @post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id)
@service = Services::Facebook.new(:access_token => "yeah") @service = Services::Facebook.new(:access_token => "yeah")
@user.services << @service @user.services << @service
@ -12,7 +11,7 @@ describe Services::Facebook do
describe '#post' do describe '#post' do
it 'posts a status message to facebook' 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) @service.post(@post)
end end
it 'swallows exception raised by facebook always being down' do it 'swallows exception raised by facebook always being down' do

View file

@ -1,10 +1,9 @@
require 'spec_helper' require 'spec_helper'
describe Services::Twitter do describe Services::Twitter do
before do before do
@user = Factory.create(:user) @user = alice
@user.aspects.create(:name => "whatever")
@post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id) @post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id)
@service = Services::Twitter.new(:access_token => "yeah", :access_secret => "foobar") @service = Services::Twitter.new(:access_token => "yeah", :access_secret => "foobar")
@user.services << @service @user.services << @service
@ -12,7 +11,7 @@ describe Services::Twitter do
describe '#post' do describe '#post' do
it 'posts a status message to twitter' 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) @service.post(@post)
end end

View file

@ -7,8 +7,8 @@ require 'spec_helper'
describe StatusMessage do describe StatusMessage do
before do before do
@user = Factory(:user) @user = alice
@aspect = @user.aspects.create(:name => "losers") @aspect = @user.aspects.first
end end
describe '#diaspora_handle=' do describe '#diaspora_handle=' do

View file

@ -6,13 +6,13 @@ require 'spec_helper'
describe "attack vectors" do describe "attack vectors" do
let(:user) { Factory.create(:user) } let(:user) { Factory.create(:user_with_aspect) }
let(:aspect) { user.aspects.create(:name => 'heroes') } let(:aspect) { user.aspects.first }
let(:bad_user) { Factory.create(:user)} let(:bad_user) { Factory.create(:user)}
let(:user2) { Factory.create(:user) } let(:user2) { eve }
let(:aspect2) { user2.aspects.create(:name => 'losers') } let(:aspect2) { user2.aspects.first }
let(:user3) { Factory.create(:user) } let(:user3) { Factory.create(:user) }
let(:aspect3) { user3.aspects.create(:name => 'heroes') } let(:aspect3) { user3.aspects.create(:name => 'heroes') }
@ -207,7 +207,6 @@ describe "attack vectors" do
end end
it 'does not let me update other persons post' do it 'does not let me update other persons post' do
pending "this needs to be a photo"
original_message = user2.post(:photo, :user_file => uploaded_photo, :caption => "store this!", :to => aspect2.id) original_message = user2.post(:photo, :user_file => uploaded_photo, :caption => "store this!", :to => aspect2.id)
salmon_xml = user2.salmon(original_message).xml_for(user.person) salmon_xml = user2.salmon(original_message).xml_for(user.person)

View file

@ -6,13 +6,12 @@ require 'spec_helper'
describe User do describe User do
let!(:user1){Factory.create(:user)} let!(:user1){alice}
let!(:user2){Factory.create(:user)} let!(:user2){bob}
let!(:aspect1){user1.aspects.create(:name => 'heroes')} let!(:aspect1){user1.aspects.first}
let!(:aspect2){user2.aspects.create(:name => 'others')} let!(:aspect2){user2.aspects.first}
before do before do
connect_users(user1, aspect1, user2, aspect2)
@post = user1.build_post(:status_message, :message => "hey", :to => aspect1.id) @post = user1.build_post(:status_message, :message => "hey", :to => aspect1.id)
@post.save @post.save
user1.dispatch_post(@post, :to => "all") user1.dispatch_post(@post, :to => "all")
@ -23,7 +22,7 @@ describe User do
it "doesn't call receive on local users" do it "doesn't call receive on local users" do
user1.should_not_receive(:receive_comment) user1.should_not_receive(:receive_comment)
user2.should_not_receive(:receive_comment) user2.should_not_receive(:receive_comment)
comment = user2.build_comment "why so formal?", :on => @post comment = user2.build_comment "why so formal?", :on => @post
comment.save! comment.save!
user2.dispatch_comment comment user2.dispatch_comment comment
@ -34,7 +33,7 @@ describe User do
it "doesn't call receive on local users" do it "doesn't call receive on local users" do
user1.should_not_receive(:receive_comment) user1.should_not_receive(:receive_comment)
user2.should_not_receive(:receive_comment) user2.should_not_receive(:receive_comment)
comment = user1.build_comment "why so formal?", :on => @post comment = user1.build_comment "why so formal?", :on => @post
comment.save! comment.save!
user1.dispatch_comment comment user1.dispatch_comment comment

View file

@ -5,7 +5,7 @@
require 'spec_helper' require 'spec_helper'
describe Diaspora::UserModules::Connecting do describe Diaspora::UserModules::Connecting do
let(:user) { Factory.create(:user) } let(:user) { alice }
let(:aspect) { user.aspects.create(:name => 'heroes') } let(:aspect) { user.aspects.create(:name => 'heroes') }
let(:aspect1) { user.aspects.create(:name => 'other') } let(:aspect1) { user.aspects.create(:name => 'other') }
let(:person) { Factory.create(:person) } let(:person) { Factory.create(:person) }
@ -14,7 +14,7 @@ describe Diaspora::UserModules::Connecting do
let(:person_two) { Factory.create :person } let(:person_two) { Factory.create :person }
let(:person_three) { 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") } let(:aspect2) { user2.aspects.create(:name => "aspect two") }
describe '#send_contact_request_to' do describe '#send_contact_request_to' do
@ -60,6 +60,12 @@ describe Diaspora::UserModules::Connecting do
Request.where(:recipient_id => user.person.id).all.should include @r Request.where(:recipient_id => user.person.id).all.should include @r
end end
it 'creates no contact' do
lambda {
received_req = @r.receive(user, person_one)
}.should_not change(Contact, :count)
end
it 'enqueues a mail job' do it 'enqueues a mail job' do
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id) Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id)
zord = Postzord::Receiver.new(user, :object => @r, :person => person) zord = Postzord::Receiver.new(user, :object => @r, :person => person)
@ -131,11 +137,6 @@ describe Diaspora::UserModules::Connecting do
describe 'multiple users accepting/rejecting the same person' do describe 'multiple users accepting/rejecting the same person' do
before do before do
Request.where(:recipient_id => user.person.id).count.should == 0
user.contacts.empty?.should be true
Request.where(:recipient_id => user2.person.id).count.should == 0
user2.contacts.empty?.should be true
@request1 = Request.diaspora_initialize(:to => user.person, :from => person_one) @request1 = Request.diaspora_initialize(:to => user.person, :from => person_one)
@request2 = Request.diaspora_initialize(:to => user2.person, :from => person_one) @request2 = Request.diaspora_initialize(:to => user2.person, :from => person_one)
@request3 = Request.diaspora_initialize(:to => user2.person, :from => user.person) @request3 = Request.diaspora_initialize(:to => user2.person, :from => user.person)
@ -214,29 +215,33 @@ describe Diaspora::UserModules::Connecting do
describe 'a user accepting rejecting multiple people' do describe 'a user accepting rejecting multiple people' do
before do before do
@request = Request.diaspora_initialize(:to => user.person, :from => person_one) request = Request.diaspora_initialize(:to => user.person, :from => person_one)
@request_two = Request.diaspora_initialize(:to => user.person, :from => person_two) @received_request = request.receive(user, person_one)
end end
describe '#accept_contact_request' do
it "keeps the right counts of contacts" do it "deletes the received request" do
received_req = @request.receive(user, person_one) lambda {
user.accept_contact_request(@received_request, aspect)
Request.where(:recipient_id => user.person.id).count.should == 1 }.should change(Request, :count).by(-1)
user.reload.contacts.size.should be 0 end
it "creates a new contact" do
received_req2 = @request_two.receive(user, person_two) lambda {
Request.where(:recipient_id => user.person.id).count.should == 2 user.accept_contact_request(@received_request, aspect)
user.reload.contacts.size.should be 0 }.should change(Contact, :count).by(1)
user.contact_for(person_one).should_not be_nil
user.accept_contact_request received_req, aspect end
Request.where(:recipient_id => user.person.id).count.should == 1 end
user.reload.contacts.size.should be 1 describe '#ignore_contact_request' do
user.contact_for(person_one).should_not be_nil it "removes the request" do
lambda {
user.ignore_contact_request received_req2.id user.ignore_contact_request(@received_request.id)
Request.where(:recipient_id => user.person.id).count.should == 0 }.should change(Request, :count).by(-1)
user.reload.contacts.size.should be 1 end
user.contact_for(person_two).should be_nil it "creates no new contact" do
lambda {
user.ignore_contact_request(@received_request)
}.should_not change(Contact, :count)
end
end end
end end

View file

@ -5,9 +5,9 @@
require 'spec_helper' require 'spec_helper'
describe User do 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(: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(: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(: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")} let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")}

View file

@ -6,12 +6,12 @@ require 'spec_helper'
describe User do describe User do
let!(:user) { Factory.create(:user) } let!(:user) { alice }
let!(:user2) { Factory.create(:user) } let!(:user2) { eve }
let!(:aspect) { user.aspects.create(:name => 'heroes') } let!(:aspect) { user.aspects.first }
let!(:aspect1) { user.aspects.create(:name => 'other') } 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!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }

View file

@ -7,9 +7,9 @@ require 'spec_helper'
describe User do describe User do
before do before do
@user = Factory(:user) @user = alice
@aspect = @user.aspects.create(:name => "cats") @aspect = @user.aspects.first
@user2 = Factory(:user_with_aspect) @user2 = eve
@aspect2 = @user2.aspects.first @aspect2 = @user2.aspects.first
@person_one = Factory.create :person @person_one = Factory.create :person

View file

@ -5,9 +5,9 @@
require 'spec_helper' require 'spec_helper'
describe User do describe User do
let(:user) { Factory.create(:user) } let(:user) { alice }
let(:aspect) { user.aspects.create(:name => 'heroes') } let(:aspect) { user.aspects.create(:name => 'heroes') }
let(:user2) { Factory.create(:user) } let(:user2) { eve }
let(:aspect2) { user2.aspects.create(:name => 'stuff') } let(:aspect2) { user2.aspects.create(:name => 'stuff') }
it 'should have a key' do it 'should have a key' do
@ -16,10 +16,9 @@ describe User do
describe 'overwriting people' do describe 'overwriting people' do
it 'does not overwrite old users with factory' do it 'does not overwrite old users with factory' do
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" lambda {
new_user = Factory.create(:user, :id => user.id) new_user = Factory.create(:user, :id => user.id)
new_user.persisted?.should be_true }.should raise_error ActiveRecord::RecordNotUnique
new_user.id.should_not == user.id
end end
it 'does not overwrite old users with create' do it 'does not overwrite old users with create' do
params = {:username => "ohai", params = {:username => "ohai",
@ -267,9 +266,9 @@ describe User do
it "only pushes to non-pending contacts" do it "only pushes to non-pending contacts" do
connect_users(user, aspect, user2, aspect2) connect_users(user, aspect, user2, aspect2)
user.contacts.count.should == 1 lambda {
user.send_contact_request_to(Factory(:user).person, aspect) user.send_contact_request_to(Factory(:user).person, aspect)
user.contacts.count.should == 2 }.should change(user.contacts, :count).by(1)
m = mock() m = mock()
m.should_receive(:post) m.should_receive(:post)
@ -339,7 +338,9 @@ describe User do
it 'should remove all aspects' do it 'should remove all aspects' do
aspect aspect
lambda {user.destroy}.should change{user.aspects.reload.count}.by(-1) lambda {
user.destroy
}.should change{ user.aspects(true).count }.by(-2)
end end
describe '#remove_person' do describe '#remove_person' do
@ -361,9 +362,10 @@ describe User do
describe '#disconnect_everyone' do describe '#disconnect_everyone' do
it 'should send retractions to remote poeple' do it 'should send retractions to remote poeple' do
person = user2.person
user2.delete user2.delete
user2.person.owner_id = nil person.owner_id = nil
user2.person.save person.save
user.activate_contact(user2.person, aspect) user.activate_contact(user2.person, aspect)
user.should_receive(:disconnect).once user.should_receive(:disconnect).once

View file

@ -13,16 +13,18 @@ require 'factory_girl'
include Devise::TestHelpers include Devise::TestHelpers
include WebMock::API include WebMock::API
include HelperMethods
# #
# Requires supporting files with custom matchers and macros, etc, # Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories. # in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
include HelperMethods
RSpec.configure do |config| RSpec.configure do |config|
config.mock_with :mocha config.mock_with :mocha
config.mock_with :rspec config.mock_with :rspec
# config.fixture_path = "#{Rails.root}/spec/fixtures"
# config.global_fixtures = :all
config.use_transactional_fixtures = true config.use_transactional_fixtures = true
config.before(:each) do config.before(:each) do
@ -33,6 +35,20 @@ RSpec.configure do |config|
end end
end 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 module Diaspora::WebSocket
def self.redis def self.redis
FakeRedis.new FakeRedis.new

View file

@ -0,0 +1,16 @@
# I usually put this file in spec/support/fixture_builder.rb
FixtureBuilder.configure do |fbuilder|
# rebuild fixtures automatically when these files change:
fbuilder.files_to_check += Dir["app/models/*.rb", "lib/**/*.rb", "spec/factories/*.rb", "spec/support/fixture_builder.rb"]
# now declare objects
fbuilder.factory do
alice = Factory(:user_with_aspect, :username => "alice")
bob = Factory(:user_with_aspect, :username => "bob")
eve = Factory(:user_with_aspect, :username => "eve")
connect_users(bob, bob.aspects.first, alice, alice.aspects.first)
connect_users(bob, bob.aspects.first, eve, eve.aspects.first)
end
end