Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
960058803a
65 changed files with 551 additions and 581 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -20,7 +20,7 @@ public/stylesheets/sessions.css
|
|||
public/stylesheets/ui.css
|
||||
public/stylesheets/mobile.css
|
||||
public/diaspora
|
||||
spec/fixtures/users.yaml
|
||||
spec/fixtures/*.yml
|
||||
|
||||
# Uploded files and local files
|
||||
public/uploads/*
|
||||
|
|
|
|||
3
Gemfile
3
Gemfile
|
|
@ -56,12 +56,13 @@ end
|
|||
|
||||
group :test do
|
||||
gem 'factory_girl_rails'
|
||||
gem 'fixture_builder', '~> 0.2.0'
|
||||
gem 'capybara', '~> 0.3.9'
|
||||
gem 'cucumber-rails', '0.3.2'
|
||||
gem 'rspec', '>= 2.0.0'
|
||||
gem 'rspec-rails', '>= 2.0.0'
|
||||
gem 'mocha'
|
||||
gem 'database_cleaner', '0.5.2'
|
||||
gem 'database_cleaner', '0.6.0'
|
||||
gem 'webmock', :require => false
|
||||
gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false
|
||||
gem 'mongrel', :require => false if RUBY_VERSION.include? '1.8'
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ GEM
|
|||
cucumber (>= 0.8.0)
|
||||
culerity (0.2.14)
|
||||
daemons (1.1.0)
|
||||
database_cleaner (0.5.2)
|
||||
database_cleaner (0.6.0)
|
||||
devise (1.1.3)
|
||||
bcrypt-ruby (~> 2.1.2)
|
||||
warden (~> 0.10.7)
|
||||
|
|
@ -162,6 +162,7 @@ GEM
|
|||
fastthread (1.0.7)
|
||||
ffi (0.6.3)
|
||||
rake (>= 0.8.7)
|
||||
fixture_builder (0.2.0)
|
||||
fog (0.3.25)
|
||||
builder
|
||||
excon (>= 0.2.4)
|
||||
|
|
@ -365,12 +366,13 @@ DEPENDENCIES
|
|||
chef (= 0.9.12)
|
||||
cloudfiles (= 1.4.10)
|
||||
cucumber-rails (= 0.3.2)
|
||||
database_cleaner (= 0.5.2)
|
||||
database_cleaner (= 0.6.0)
|
||||
devise (= 1.1.3)
|
||||
devise_invitable (= 0.3.5)
|
||||
em-websocket!
|
||||
factory_girl_rails
|
||||
fastercsv (= 1.5.4)
|
||||
fixture_builder (~> 0.2.0)
|
||||
fog
|
||||
haml (= 3.0.25)
|
||||
http_accept_language!
|
||||
|
|
|
|||
|
|
@ -9,14 +9,12 @@ describe AspectsController do
|
|||
render_views
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user2 = Factory.create(:user)
|
||||
@user = alice
|
||||
@user2 = bob
|
||||
|
||||
@aspect0 = @user.aspects.create(:name => "lame-os")
|
||||
@aspect0 = @user.aspects.first
|
||||
@aspect1 = @user.aspects.create(:name => "another aspect")
|
||||
@aspect2 = @user2.aspects.create(:name => "party people")
|
||||
|
||||
connect_users(@user, @aspect0, @user2, @aspect2)
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
@contact = @user.contact_for(@user2.person)
|
||||
@user.getting_started = false
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ require 'spec_helper'
|
|||
describe CommentsController do
|
||||
render_views
|
||||
|
||||
let!(:user1) { Factory.create(:user) }
|
||||
let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") }
|
||||
|
||||
let!(:user2) { Factory.create(:user) }
|
||||
let!(:aspect2) { user2.aspects.create(:name => "WIN!!") }
|
||||
|
||||
before do
|
||||
sign_in :user, user1
|
||||
@user1 = alice
|
||||
@user2 = bob
|
||||
|
||||
@aspect1 = @user1.aspects.first
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
sign_in :user, @user1
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
|
|
@ -24,7 +24,7 @@ describe CommentsController do
|
|||
}
|
||||
context "on my own post" do
|
||||
before do
|
||||
@post = user1.post :status_message, :message => 'GIANTS', :to => aspect1.id
|
||||
@post = @user1.post :status_message, :message => 'GIANTS', :to => @aspect1.id
|
||||
end
|
||||
it 'responds to format js' do
|
||||
post :create, comment_hash.merge(:format => 'js')
|
||||
|
|
@ -35,8 +35,7 @@ describe CommentsController do
|
|||
|
||||
context "on a post from a contact" 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
|
||||
it 'comments' do
|
||||
post :create, comment_hash
|
||||
|
|
@ -46,10 +45,10 @@ describe CommentsController do
|
|||
new_user = Factory.create(:user)
|
||||
comment_hash[:person_id] = new_user.person.id.to_s
|
||||
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
|
||||
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
|
||||
post :create, comment_hash
|
||||
old_comment.reload.text.should == 'hello'
|
||||
|
|
@ -57,10 +56,10 @@ describe CommentsController do
|
|||
end
|
||||
context 'on a post from a stranger' 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
|
||||
it 'posts no comment' do
|
||||
user1.should_not_receive(:comment)
|
||||
@user1.should_not_receive(:comment)
|
||||
post :create, comment_hash
|
||||
response.code.should == '406'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ describe HomeController do
|
|||
render_views
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
sign_in @user
|
||||
sign_out @user
|
||||
end
|
||||
|
|
@ -37,7 +37,7 @@ describe HomeController do
|
|||
|
||||
describe "custom logging on redirect" do
|
||||
before do
|
||||
sign_in :user, Factory(:user)
|
||||
sign_in :user, bob
|
||||
@action = :show
|
||||
@action_params = {"lasers" => "green"}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,22 +9,20 @@ describe InvitationsController do
|
|||
|
||||
render_views
|
||||
|
||||
let!(:user) { Factory.create(:user) }
|
||||
let!(:aspect) { user.aspects.create(:name => "WIN!!") }
|
||||
|
||||
before do
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
before do
|
||||
@user.invites = 5
|
||||
|
||||
user.invites = 5
|
||||
|
||||
sign_in :user, user
|
||||
@invite = {:invite_message=>"test", :aspect_id=> aspect.id.to_s, :email=>"abc@example.com"}
|
||||
@controller.stub!(:current_user).and_return(user)
|
||||
sign_in :user, @user
|
||||
@invite = {:invite_message=>"test", :aspect_id=> @aspect.id.to_s, :email=>"abc@example.com"}
|
||||
@controller.stub!(:current_user).and_return(@user)
|
||||
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
||||
end
|
||||
|
||||
|
|
@ -54,8 +52,8 @@ describe InvitationsController do
|
|||
end
|
||||
|
||||
it "doesn't invite anyone if you have 0 invites" do
|
||||
user.invites = 0
|
||||
user.save!
|
||||
@user.invites = 0
|
||||
@user.save!
|
||||
lambda {
|
||||
post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com")
|
||||
}.should_not change(User, :count)
|
||||
|
|
@ -69,8 +67,8 @@ describe InvitationsController do
|
|||
|
||||
describe "#update" do
|
||||
before do
|
||||
user.invites = 5
|
||||
@invited_user = user.invite_user("a@a.com", user.aspects.first.id)
|
||||
@user.invites = 5
|
||||
@invited_user = @user.invite_user("a@a.com", @aspect.id)
|
||||
@accept_params = {:user=>
|
||||
{:password_confirmation =>"password",
|
||||
:username=>"josh",
|
||||
|
|
@ -91,7 +89,6 @@ describe InvitationsController do
|
|||
end
|
||||
|
||||
it 'adds a pending request' do
|
||||
|
||||
put :update, @accept_params
|
||||
Request.where(:recipient_id => invited.person.id).count.should == 1
|
||||
end
|
||||
|
|
@ -100,7 +97,7 @@ describe InvitationsController do
|
|||
context 'failure' do
|
||||
before do
|
||||
@fail_params = @accept_params
|
||||
@fail_params[:user][:username] = user.username
|
||||
@fail_params[:user][:username] = @user.username
|
||||
end
|
||||
it 'stays on the invitation accept form' do
|
||||
put :update, @fail_params
|
||||
|
|
@ -115,7 +112,7 @@ describe InvitationsController do
|
|||
|
||||
describe '#new' do
|
||||
it 'renders' do
|
||||
sign_in :user, user
|
||||
sign_in :user, @user
|
||||
get :new
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,24 +6,24 @@ require 'spec_helper'
|
|||
|
||||
describe NotificationsController do
|
||||
|
||||
let!(:user) { Factory.create(:user) }
|
||||
let!(:aspect) { user.aspects.create(:name => "AWESOME!!") }
|
||||
|
||||
before do
|
||||
sign_in :user, user
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
sign_in :user, @user
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
it 'marks a notification as read' do
|
||||
note = Notification.create(:recipient_id => user.id)
|
||||
note = Notification.create(:recipient_id => @user.id)
|
||||
put :update, :id => note.id
|
||||
Notification.first.unread.should == false
|
||||
end
|
||||
|
||||
it 'only lets you read your own notifications' do
|
||||
user2 = Factory.create(:user)
|
||||
user2 = bob
|
||||
|
||||
Notification.create(:recipient_id => user.id)
|
||||
Notification.create(:recipient_id => @user.id)
|
||||
note = Notification.create(:recipient_id => user2.id)
|
||||
|
||||
put :update, :id => note.id
|
||||
|
|
@ -35,8 +35,8 @@ describe NotificationsController do
|
|||
describe "#read_all" do
|
||||
it 'marks all notifications as read' do
|
||||
request.env["HTTP_REFERER"] = "I wish I were spelled right"
|
||||
Notification.create(:recipient_id => user.id)
|
||||
Notification.create(:recipient_id => user.id)
|
||||
Notification.create(:recipient_id => @user.id)
|
||||
Notification.create(:recipient_id => @user.id)
|
||||
|
||||
Notification.where(:unread => true).count.should == 2
|
||||
get :read_all
|
||||
|
|
@ -47,7 +47,7 @@ describe NotificationsController do
|
|||
describe '#index' do
|
||||
it 'paginates the notifications' do
|
||||
35.times do
|
||||
Notification.create(:recipient_id => user.id)
|
||||
Notification.create(:recipient_id => @user.id)
|
||||
end
|
||||
|
||||
get :index
|
||||
|
|
|
|||
|
|
@ -7,21 +7,20 @@ require 'spec_helper'
|
|||
describe PeopleController do
|
||||
render_views
|
||||
|
||||
let(:user) { Factory.create(:user) }
|
||||
let!(:aspect) { user.aspects.create(:name => "lame-os") }
|
||||
|
||||
before do
|
||||
sign_in :user, user
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
sign_in :user, @user
|
||||
end
|
||||
|
||||
describe '#similar_people' do
|
||||
before do
|
||||
@contacts = []
|
||||
@aspect1 = user.aspects.create(:name => "foos")
|
||||
@aspect2 = user.aspects.create(:name => "bars")
|
||||
@aspect1 = @user.aspects.create(:name => "foos")
|
||||
@aspect2 = @user.aspects.create(:name => "bars")
|
||||
|
||||
3.times do
|
||||
@contacts << Contact.create(:user => user, :person => Factory.create(:person))
|
||||
@contacts << Contact.create(:user => @user, :person => Factory.create(:person))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -57,7 +56,7 @@ describe PeopleController do
|
|||
@contacts[0].save
|
||||
|
||||
20.times do
|
||||
c = Contact.create(:user => user, :person => Factory.create(:person))
|
||||
c = Contact.create(:user => @user, :person => Factory.create(:person))
|
||||
c.aspects << @aspect1
|
||||
c.save
|
||||
@contacts << c
|
||||
|
|
@ -94,14 +93,13 @@ describe PeopleController do
|
|||
assigns[:people].should =~ [@eugene, eugene2]
|
||||
end
|
||||
it 'shows a contact' do
|
||||
user2 = Factory.create(:user)
|
||||
connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience'))
|
||||
user2 = bob
|
||||
get :index, :q => user2.person.profile.first_name.to_s
|
||||
response.should redirect_to user2.person
|
||||
end
|
||||
|
||||
it 'shows a non-contact' do
|
||||
user2 = Factory.create(:user)
|
||||
user2 = eve
|
||||
user2.person.profile.searchable = true
|
||||
user2.save
|
||||
get :index, :q => user2.person.profile.first_name.to_s
|
||||
|
|
@ -121,20 +119,20 @@ describe PeopleController do
|
|||
|
||||
describe '#show' do
|
||||
it 'goes to the current_user show page' do
|
||||
get :show, :id => user.person.id
|
||||
get :show, :id => @user.person.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'renders with a post' do
|
||||
user.post :status_message, :message => 'test more', :to => aspect.id
|
||||
get :show, :id => user.person.id
|
||||
@user.post :status_message, :message => 'test more', :to => @aspect.id
|
||||
get :show, :id => @user.person.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'renders with a post' do
|
||||
message = user.post :status_message, :message => 'test more', :to => aspect.id
|
||||
user.comment 'I mean it', :on => message
|
||||
get :show, :id => user.person.id
|
||||
message = @user.post :status_message, :message => 'test more', :to => @aspect.id
|
||||
@user.comment 'I mean it', :on => message
|
||||
get :show, :id => @user.person.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
|
@ -144,25 +142,24 @@ describe PeopleController do
|
|||
end
|
||||
|
||||
it "redirects to #index if no person is found" do
|
||||
get :show, :id => user.id
|
||||
get :show, :id => 3920397846
|
||||
response.should redirect_to people_path
|
||||
end
|
||||
|
||||
it "renders the show page of a contact" do
|
||||
user2 = Factory.create(:user)
|
||||
connect_users(user, aspect, user2, user2.aspects.create(:name => 'Neuroscience'))
|
||||
user2 = bob
|
||||
get :show, :id => user2.person.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "renders the show page of a non-contact" do
|
||||
user2 = Factory.create(:user)
|
||||
user2 = eve
|
||||
get :show, :id => user2.person.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "renders with public posts of a non-contact" do
|
||||
user2 = Factory.create(:user)
|
||||
user2 = eve
|
||||
status_message = user2.post(:status_message, :message => "hey there", :to => 'all', :public => true)
|
||||
|
||||
get :show, :id => user2.person.id
|
||||
|
|
@ -173,14 +170,14 @@ describe PeopleController do
|
|||
|
||||
describe '#webfinger' do
|
||||
it 'enqueues a webfinger job' do
|
||||
Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, user.id, user.diaspora_handle, anything).once
|
||||
get :retrieve_remote, :diaspora_handle => user.diaspora_handle
|
||||
Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once
|
||||
get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
it "sets the flash" do
|
||||
put :update, :id => user.person.id,
|
||||
put :update, :id => @user.person.id,
|
||||
:profile => {
|
||||
:image_url => "",
|
||||
:first_name => "Will",
|
||||
|
|
@ -191,35 +188,35 @@ describe PeopleController do
|
|||
|
||||
context 'with a profile photo set' do
|
||||
before do
|
||||
@params = { :id => user.person.id,
|
||||
@params = { :id => @user.person.id,
|
||||
:profile =>
|
||||
{:image_url => "",
|
||||
:last_name => user.person.profile.last_name,
|
||||
:first_name => user.person.profile.first_name }}
|
||||
:last_name => @user.person.profile.last_name,
|
||||
:first_name => @user.person.profile.first_name }}
|
||||
|
||||
user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg"
|
||||
user.person.profile.save
|
||||
@user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg"
|
||||
@user.person.profile.save
|
||||
end
|
||||
it "doesn't overwrite the profile photo when an empty string is passed in" do
|
||||
image_url = user.person.profile.image_url
|
||||
image_url = @user.person.profile.image_url
|
||||
put :update, @params
|
||||
|
||||
Person.find(user.person.id).profile.image_url.should == image_url
|
||||
Person.find(@user.person.id).profile.image_url.should == image_url
|
||||
end
|
||||
end
|
||||
it 'does not allow mass assignment' do
|
||||
person = user.person
|
||||
person = @user.person
|
||||
new_user = Factory.create(:user)
|
||||
person.owner_id.should == user.id
|
||||
put :update, :id => user.person.id, :owner_id => new_user.id
|
||||
Person.find(person.id).owner_id.should == user.id
|
||||
person.owner_id.should == @user.id
|
||||
put :update, :id => @user.person.id, :owner_id => new_user.id
|
||||
Person.find(person.id).owner_id.should == @user.id
|
||||
end
|
||||
|
||||
it 'does not overwrite the profile diaspora handle' do
|
||||
handle_params = {:id => user.person.id,
|
||||
handle_params = {:id => @user.person.id,
|
||||
:profile => {:diaspora_handle => 'abc@a.com'} }
|
||||
put :update, handle_params
|
||||
Person.find(user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com'
|
||||
Person.find(@user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,35 +7,31 @@ require 'spec_helper'
|
|||
describe PhotosController do
|
||||
render_views
|
||||
|
||||
let(:user1) {Factory.create(:user)}
|
||||
let(:user2) {Factory.create(:user)}
|
||||
|
||||
let(:aspect1) { user1.aspects.create(:name => 'winners') }
|
||||
let(:aspect2) { user2.aspects.create(:name => 'winners') }
|
||||
|
||||
let(:filename) { 'button.png' }
|
||||
let(:fixture_name) { File.join(File.dirname(__FILE__), '..', 'fixtures', filename) }
|
||||
let(:photo1) { user1.post(:photo, :user_file => File.open(fixture_name), :to => aspect1.id) }
|
||||
let(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) }
|
||||
|
||||
before do
|
||||
connect_users(user1, aspect1, user2, aspect2)
|
||||
photo1; photo2
|
||||
@controller.stub!(:current_user).and_return(user1)
|
||||
sign_in :user, user1
|
||||
@user1 = alice
|
||||
@user2 = bob
|
||||
|
||||
@aspect1 = @user1.aspects.first
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
@photo1 = @user1.post(:photo, :user_file => uploaded_photo, :to => @aspect1.id)
|
||||
@photo2 = @user2.post(:photo, :user_file => uploaded_photo, :to => @aspect2.id)
|
||||
|
||||
@controller.stub!(:current_user).and_return(@user1)
|
||||
sign_in :user, @user1
|
||||
end
|
||||
|
||||
it 'has working context' do
|
||||
photo1.url.should_not be_nil
|
||||
Photo.find(photo1.id).url.should_not be_nil
|
||||
photo2.url.should_not be_nil
|
||||
Photo.find(photo2.id).url.should_not be_nil
|
||||
@photo1.url.should_not be_nil
|
||||
Photo.find(@photo1.id).url.should_not be_nil
|
||||
@photo2.url.should_not be_nil
|
||||
Photo.find(@photo2.id).url.should_not be_nil
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before do
|
||||
@controller.stub!(:file_handler).and_return(File.open(fixture_name))
|
||||
@params = {:photo => {:user_file => File.open(fixture_name), :aspect_ids => "all"} }
|
||||
@controller.stub!(:file_handler).and_return(uploaded_photo)
|
||||
@params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} }
|
||||
end
|
||||
|
||||
it 'can make a photo' do
|
||||
|
|
@ -44,100 +40,100 @@ describe PhotosController do
|
|||
}.should change(Photo, :count).by(1)
|
||||
end
|
||||
it 'can set the photo as the profile photo' do
|
||||
old_url = user1.person.profile.image_url
|
||||
old_url = @user1.person.profile.image_url
|
||||
@params[:photo][:set_profile_photo] = true
|
||||
post :create, @params
|
||||
user1.reload.person.profile.image_url.should_not == old_url
|
||||
@user1.reload.person.profile.image_url.should_not == old_url
|
||||
end
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
it "displays the logged in user's pictures" do
|
||||
get :index, :person_id => user1.person.id.to_s
|
||||
assigns[:person].should == user1.person
|
||||
assigns[:posts].should == [photo1]
|
||||
get :index, :person_id => @user1.person.id.to_s
|
||||
assigns[:person].should == @user1.person
|
||||
assigns[:posts].should == [@photo1]
|
||||
end
|
||||
|
||||
it "displays another person's pictures" do
|
||||
get :index, :person_id => user2.person.id.to_s
|
||||
get :index, :person_id => @user2.person.id.to_s
|
||||
|
||||
assigns[:person].should == user2.person
|
||||
assigns[:posts].should == [photo2]
|
||||
assigns[:person].should == @user2.person
|
||||
assigns[:posts].should == [@photo2]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
it 'assigns the photo based on the photo id' do
|
||||
get :show, :id => photo1.id
|
||||
get :show, :id => @photo1.id
|
||||
response.status.should == 200
|
||||
|
||||
assigns[:photo].should == photo1
|
||||
assigns[:photo].should == @photo1
|
||||
assigns[:ownership].should be_true
|
||||
end
|
||||
|
||||
it "renders a show page for another user's photo" do
|
||||
get :show, :id => photo2.id
|
||||
get :show, :id => @photo2.id
|
||||
response.status.should == 200
|
||||
|
||||
assigns[:photo].should == photo2
|
||||
assigns[:photo].should == @photo2
|
||||
assigns[:ownership].should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#edit' do
|
||||
it 'lets the user edit a photo' do
|
||||
get :edit, :id => photo1.id
|
||||
get :edit, :id => @photo1.id
|
||||
response.status.should == 200
|
||||
end
|
||||
|
||||
it 'does not let the user edit a photo that is not his' do
|
||||
get :edit, :id => photo2.id
|
||||
response.should redirect_to(:action => :index, :person_id => user1.person.id.to_s)
|
||||
get :edit, :id => @photo2.id
|
||||
response.should redirect_to(:action => :index, :person_id => @user1.person.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '#destroy' do
|
||||
it 'allows the user to delete his photos' do
|
||||
delete :destroy, :id => photo1.id
|
||||
Photo.find_by_id(photo1.id).should be_nil
|
||||
delete :destroy, :id => @photo1.id
|
||||
Photo.find_by_id(@photo1.id).should be_nil
|
||||
end
|
||||
|
||||
it 'will not let you destory posts you do not own' do
|
||||
delete :destroy, :id => photo2.id
|
||||
Photo.find_by_id(photo2.id).should be_true
|
||||
delete :destroy, :id => @photo2.id
|
||||
Photo.find_by_id(@photo2.id).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
it "updates the caption of a photo" do
|
||||
put :update, :id => photo1.id, :photo => { :caption => "now with lasers!" }
|
||||
photo1.reload.caption.should == "now with lasers!"
|
||||
put :update, :id => @photo1.id, :photo => { :caption => "now with lasers!" }
|
||||
@photo1.reload.caption.should == "now with lasers!"
|
||||
end
|
||||
|
||||
it "doesn't overwrite random attributes" do
|
||||
new_user = Factory.create(:user)
|
||||
params = { :caption => "now with lasers!", :person_id => new_user.id }
|
||||
put :update, :id => photo1.id, :photo => params
|
||||
photo1.reload.person_id.should == user1.person.id
|
||||
put :update, :id => @photo1.id, :photo => params
|
||||
@photo1.reload.person_id.should == @user1.person.id
|
||||
end
|
||||
|
||||
it 'redirects if you do not have access to the post' do
|
||||
params = { :caption => "now with lasers!" }
|
||||
put :update, :id => photo2.id, :photo => params
|
||||
response.should redirect_to(:action => :index, :person_id => user1.person.id.to_s)
|
||||
put :update, :id => @photo2.id, :photo => params
|
||||
response.should redirect_to(:action => :index, :person_id => @user1.person.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#make_profile_photo" do
|
||||
|
||||
it 'should return a 201 on a js success' do
|
||||
get :make_profile_photo, :photo_id => photo1.id, :format => 'js'
|
||||
get :make_profile_photo, :photo_id => @photo1.id, :format => 'js'
|
||||
response.code.should == "201"
|
||||
end
|
||||
|
||||
it 'should return a 406 on failure' do
|
||||
get :make_profile_photo, :photo_id => photo2.id
|
||||
get :make_profile_photo, :photo_id => @photo2.id
|
||||
response.code.should == "406"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,21 +6,21 @@ require 'spec_helper'
|
|||
|
||||
describe PostsController do
|
||||
render_views
|
||||
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
@controller.stub!(:current_user).and_return(nil)
|
||||
end
|
||||
describe '#show' do
|
||||
it 'shows a public post' do
|
||||
status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
|
||||
status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
|
||||
|
||||
get :show, :id => status.id
|
||||
response.status= 200
|
||||
end
|
||||
|
||||
it 'does not show a private post' do
|
||||
status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all')
|
||||
status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all')
|
||||
get :show, :id => status.id
|
||||
response.status = 302
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,60 +7,61 @@ require 'spec_helper'
|
|||
describe PublicsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:person) { Factory.create(:person) }
|
||||
before do
|
||||
@user = alice
|
||||
@person = Factory(:person)
|
||||
end
|
||||
|
||||
describe '#receive' do
|
||||
let(:xml) { "<walruses></walruses>" }
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
it 'enqueues a receive job' do
|
||||
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once
|
||||
post :receive, "guid" => user.person.guid.to_s, "xml" => xml
|
||||
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, xml).once
|
||||
post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
|
||||
end
|
||||
|
||||
it 'unescapes the xml before sending it to receive_salmon' do
|
||||
aspect = user.aspects.create(:name => 'foo')
|
||||
post1 = user.post(:status_message, :message => 'moms', :to => [aspect.id])
|
||||
aspect = @user.aspects.create(:name => 'foo')
|
||||
post1 = @user.post(:status_message, :message => 'moms', :to => [aspect.id])
|
||||
xml2 = post1.to_diaspora_xml
|
||||
user2 = Factory(:user)
|
||||
|
||||
salmon_factory = Salmon::SalmonSlap.create(user, xml2)
|
||||
salmon_factory = Salmon::SalmonSlap.create(@user, xml2)
|
||||
enc_xml = salmon_factory.xml_for(user2.person)
|
||||
|
||||
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, enc_xml).once
|
||||
|
||||
post :receive, "guid" => user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
|
||||
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)
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
describe '#hcard' do
|
||||
it "succeeds" do
|
||||
post :hcard, "guid" => user.person.guid.to_s
|
||||
post :hcard, "guid" => @user.person.guid.to_s
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'sets the person' do
|
||||
post :hcard, "guid" => user.person.guid.to_s
|
||||
assigns[:person].should == user.person
|
||||
post :hcard, "guid" => @user.person.guid.to_s
|
||||
assigns[:person].should == @user.person
|
||||
end
|
||||
|
||||
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
|
||||
response.should be_not_found
|
||||
end
|
||||
|
|
@ -68,8 +69,7 @@ describe PublicsController do
|
|||
|
||||
describe '#webfinger' do
|
||||
it "succeeds when the person and user exist locally" do
|
||||
user = Factory.create(:user)
|
||||
post :webfinger, 'q' => user.person.diaspora_handle
|
||||
post :webfinger, 'q' => @user.person.diaspora_handle
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
|
@ -80,8 +80,7 @@ describe PublicsController do
|
|||
end
|
||||
|
||||
it "404s when the person is local but doesn't have an owner" do
|
||||
person = Factory(:person)
|
||||
post :webfinger, 'q' => person.diaspora_handle
|
||||
post :webfinger, 'q' => @person.diaspora_handle
|
||||
response.should be_not_found
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,17 +7,12 @@ require 'spec_helper'
|
|||
describe RequestsController do
|
||||
render_views
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
@other_user = eve
|
||||
|
||||
@controller.stub!(:current_user).and_return(@user)
|
||||
sign_in :user, @user
|
||||
request.env["HTTP_REFERER"] = "http://test.host"
|
||||
|
||||
@user.aspects.create!(:name => "lame-os")
|
||||
@user.reload
|
||||
|
||||
@other_user = Factory.create(:user)
|
||||
@other_user.aspects.create!(:name => "meh")
|
||||
@other_user.reload
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
|
|
|
|||
|
|
@ -6,10 +6,6 @@ require 'spec_helper'
|
|||
|
||||
describe ServicesController do
|
||||
render_views
|
||||
let(:user) { Factory.create(:user) }
|
||||
let!(:aspect) { user.aspects.create(:name => "lame-os") }
|
||||
|
||||
|
||||
let(:mock_access_token) { Object.new }
|
||||
|
||||
let(:omniauth_auth) {
|
||||
|
|
@ -21,20 +17,22 @@ describe ServicesController do
|
|||
}
|
||||
|
||||
before do
|
||||
sign_in :user, user
|
||||
@controller.stub!(:current_user).and_return(user)
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
|
||||
sign_in :user, @user
|
||||
@controller.stub!(:current_user).and_return(@user)
|
||||
mock_access_token.stub!(:token => "12345", :secret => "56789")
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
let!(:service1) {a = Factory(:service); user.services << a; a}
|
||||
let!(:service2) {a = Factory(:service); user.services << a; a}
|
||||
let!(:service3) {a = Factory(:service); user.services << a; a}
|
||||
let!(:service4) {a = Factory(:service); user.services << a; a}
|
||||
|
||||
it 'displays all connected serivices for a user' do
|
||||
4.times do
|
||||
@user.services << Factory(:service)
|
||||
end
|
||||
|
||||
get :index
|
||||
assigns[:services].should == user.services
|
||||
assigns[:services].should == @user.services
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -43,18 +41,18 @@ describe ServicesController do
|
|||
request.env['omniauth.auth'] = omniauth_auth
|
||||
lambda{
|
||||
post :create
|
||||
}.should change(user.services, :count).by(1)
|
||||
}.should change(@user.services, :count).by(1)
|
||||
end
|
||||
|
||||
it 'redirects to getting started if the user is getting started' do
|
||||
user.getting_started = true
|
||||
@user.getting_started = true
|
||||
request.env['omniauth.auth'] = omniauth_auth
|
||||
post :create
|
||||
response.should redirect_to getting_started_path(:step => 3)
|
||||
end
|
||||
|
||||
it 'redirects to services url' do
|
||||
user.getting_started = false
|
||||
@user.getting_started = false
|
||||
request.env['omniauth.auth'] = omniauth_auth
|
||||
post :create
|
||||
response.should redirect_to services_url
|
||||
|
|
@ -63,23 +61,22 @@ describe ServicesController do
|
|||
|
||||
it 'creates a twitter service' do
|
||||
Service.delete_all
|
||||
user.getting_started = false
|
||||
@user.getting_started = false
|
||||
request.env['omniauth.auth'] = omniauth_auth
|
||||
post :create
|
||||
user.reload
|
||||
user.services.first.class.name.should == "Services::Twitter"
|
||||
@user.reload.services.first.class.name.should == "Services::Twitter"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
before do
|
||||
@service1 = Factory.create(:service)
|
||||
user.services << @service1
|
||||
@user.services << @service1
|
||||
end
|
||||
it 'destroys a service selected by id' do
|
||||
lambda{
|
||||
delete :destroy, :id => @service1.id
|
||||
}.should change(user.services, :count).by(-1)
|
||||
}.should change(@user.services, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ EOT
|
|||
describe SocketsController do
|
||||
render_views
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
@controller = SocketsController.new
|
||||
end
|
||||
|
||||
describe 'actionhash' do
|
||||
before do
|
||||
@aspect = @user.aspects.create(:name => "losers")
|
||||
@aspect = @user.aspects.first
|
||||
@message = @user.post :status_message, :message => "post through user for victory", :to => @aspect.id
|
||||
@fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,26 +7,25 @@ require 'spec_helper'
|
|||
describe StatusMessagesController do
|
||||
render_views
|
||||
|
||||
let!(:user1) { Factory.create(:user) }
|
||||
let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") }
|
||||
|
||||
let!(:user2) { Factory.create(:user) }
|
||||
let!(:aspect2) { user2.aspects.create(:name => "WIN!!") }
|
||||
|
||||
before do
|
||||
connect_users(user1, aspect1, user2, aspect2)
|
||||
@user1 = alice
|
||||
@user2 = bob
|
||||
|
||||
@aspect1 = @user1.aspects.first
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
request.env["HTTP_REFERER"] = ""
|
||||
sign_in :user, user1
|
||||
@controller.stub!(:current_user).and_return(user1)
|
||||
user1.reload
|
||||
sign_in :user, @user1
|
||||
@controller.stub!(:current_user).and_return(@user1)
|
||||
@user1.reload
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
it 'succeeds' do
|
||||
message = user1.build_post :status_message, :message => "ohai", :to => aspect1.id
|
||||
message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id
|
||||
message.save!
|
||||
user1.add_to_streams(message, [aspect1])
|
||||
user1.dispatch_post message, :to => aspect1.id
|
||||
@user1.add_to_streams(message, [@aspect1])
|
||||
@user1.dispatch_post message, :to => @aspect1.id
|
||||
|
||||
get :show, "id" => message.id.to_s
|
||||
response.should be_success
|
||||
|
|
@ -39,7 +38,7 @@ describe StatusMessagesController do
|
|||
:public => "true",
|
||||
:message => "facebook, is that you?",
|
||||
},
|
||||
:aspect_ids => [aspect1.id.to_s] }
|
||||
:aspect_ids => [@aspect1.id.to_s] }
|
||||
}
|
||||
it 'responds to js requests' do
|
||||
post :create, status_message_hash.merge(:format => 'js')
|
||||
|
|
@ -47,14 +46,14 @@ describe StatusMessagesController do
|
|||
end
|
||||
|
||||
it "doesn't overwrite person_id" do
|
||||
status_message_hash[:status_message][:person_id] = user2.person.id
|
||||
status_message_hash[:status_message][:person_id] = @user2.person.id
|
||||
post :create, status_message_hash
|
||||
new_message = StatusMessage.find_by_message(status_message_hash[:status_message][:message])
|
||||
new_message.person_id.should == user1.person.id
|
||||
new_message.person_id.should == @user1.person.id
|
||||
end
|
||||
|
||||
it "doesn't overwrite id" do
|
||||
old_status_message = user1.post(:status_message, :message => "hello", :to => aspect1.id)
|
||||
old_status_message = @user1.post(:status_message, :message => "hello", :to => @aspect1.id)
|
||||
status_message_hash[:status_message][:id] = old_status_message.id
|
||||
post :create, status_message_hash
|
||||
old_status_message.reload.message.should == 'hello'
|
||||
|
|
@ -65,8 +64,8 @@ describe StatusMessagesController do
|
|||
fixture_filename = 'button.png'
|
||||
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
|
||||
|
||||
@photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
|
||||
@photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
|
||||
@photo1 = @user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => @aspect1.id)
|
||||
@photo2 = @user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => @aspect1.id)
|
||||
|
||||
@photo1.save!
|
||||
@photo2.save!
|
||||
|
|
@ -75,7 +74,7 @@ describe StatusMessagesController do
|
|||
@hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s]
|
||||
end
|
||||
it "dispatches all referenced photos" do
|
||||
user1.should_receive(:dispatch_post).exactly(3).times
|
||||
@user1.should_receive(:dispatch_post).exactly(3).times
|
||||
post :create, @hash
|
||||
end
|
||||
it "sets the pending bit of referenced photos" do
|
||||
|
|
@ -87,8 +86,8 @@ describe StatusMessagesController do
|
|||
end
|
||||
|
||||
describe '#destroy' do
|
||||
let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)}
|
||||
let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)}
|
||||
let!(:message) {@user1.post(:status_message, :message => "hey", :to => @aspect1.id)}
|
||||
let!(:message2) {@user2.post(:status_message, :message => "hey", :to => @aspect2.id)}
|
||||
|
||||
it 'let a user delete his photos' do
|
||||
delete :destroy, :id => message.id
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ require 'spec_helper'
|
|||
describe UsersController do
|
||||
render_views
|
||||
|
||||
let(:user) { Factory.create(:user) }
|
||||
let!(:aspect) { user.aspects.create(:name => "lame-os") }
|
||||
let(:user) { alice }
|
||||
let!(:aspect) { user.aspects.first }
|
||||
|
||||
let!(:old_password) { user.encrypted_password }
|
||||
let!(:old_language) { user.language }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ require 'spec_helper'
|
|||
|
||||
describe ApplicationHelper do
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@user = alice
|
||||
@person = Factory.create(:person)
|
||||
end
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ describe ApplicationHelper do
|
|||
person_image_link(@person).should include(person_path(@person))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "#person_image_tag" do
|
||||
it "should not allow basic XSS/HTML" do
|
||||
@person.profile.first_name = "I'm <h1>Evil"
|
||||
|
|
@ -176,7 +176,7 @@ describe ApplicationHelper do
|
|||
message = '[link text](http://someurl.com "some title") [link text](http://someurl.com "some title")'
|
||||
markdownify(message).should == '<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
|
||||
|
||||
|
||||
it "should have a robust link parsing" do
|
||||
message = "This [*text*](http://en.wikipedia.org/wiki/Text_(literary_theory)) with many [links](google.com) tests [_http_](http://google.com/search?q=with_multiple__underscores*and**asterisks), [___FTP___](ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4 \"File Transfer Protocol\"), [**any protocol**](foo://bar.example.org/yes_it*makes*no_sense)"
|
||||
markdownify(message).should == 'This <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
|
||||
message = "These\nare\n\some\nnew\lines"
|
||||
res = markdownify(message, :newlines => false)
|
||||
res.should == message
|
||||
res.should == message
|
||||
end
|
||||
|
||||
it 'generates breaklines' do
|
||||
|
|
@ -207,7 +207,7 @@ describe ApplicationHelper do
|
|||
res = markdownify(message)
|
||||
res.should == "These<br /\>are<br /\>some<br /\>new<br /\>lines"
|
||||
end
|
||||
|
||||
|
||||
it 'should render newlines and basic http links correctly' do
|
||||
message = "Some text, then a line break and a link\nhttp://joindiaspora.com\nsome more text"
|
||||
res = markdownify(message)
|
||||
|
|
@ -229,19 +229,19 @@ describe ApplicationHelper do
|
|||
|
||||
person_link(@person).should include @person.diaspora_handle
|
||||
end
|
||||
|
||||
|
||||
it 'uses diaspora handle if first name and first name are rails#blank?' do
|
||||
@person.profile.first_name = " "
|
||||
@person.profile.first_name = " "
|
||||
@person.profile.last_name = " "
|
||||
|
||||
person_link(@person).should include @person.diaspora_handle
|
||||
end
|
||||
|
||||
|
||||
it "should not allow basic XSS/HTML" do
|
||||
@person.profile.first_name = "I'm <h1>Evil"
|
||||
@person.profile.last_name = "I'm <h1>Evil"
|
||||
person_link(@person).should_not include("<h1>")
|
||||
end
|
||||
end
|
||||
end
|
||||
context 'performance' do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -2,12 +2,12 @@ require 'spec_helper'
|
|||
|
||||
describe StreamHelper do
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@aspect = @user.aspects.create(:name => 'aspect')
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
@post = @user.post(:status_message, :message => "hi", :to => @aspect.id)
|
||||
end
|
||||
it 'renders a new comment form' do
|
||||
new_comment_form(@post.id).should ==
|
||||
new_comment_form(@post.id).should ==
|
||||
@controller.render_to_string(:partial => 'comments/new_comment', :locals => {:post_id => @post.id})
|
||||
end
|
||||
it 'renders it fast the second time' do
|
||||
|
|
|
|||
|
|
@ -5,15 +5,17 @@ require 'spec_helper'
|
|||
|
||||
describe UsersHelper do
|
||||
describe '#first_name_or_username' do
|
||||
let(:user){ Factory(:user) }
|
||||
before do
|
||||
@user = alice
|
||||
end
|
||||
|
||||
it 'should display the first name if it is set' do
|
||||
first_name_or_username(user).should == user.person.profile.first_name
|
||||
first_name_or_username(@user).should == @user.person.profile.first_name
|
||||
end
|
||||
|
||||
it 'should display the username if the first name is empty' do
|
||||
user.person.profile.first_name = ""
|
||||
first_name_or_username(user).should == user.username
|
||||
@user.person.profile.first_name = ""
|
||||
first_name_or_username(@user).should == @user.username
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,73 +6,72 @@ require 'spec_helper'
|
|||
|
||||
describe 'a user receives a post' do
|
||||
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:aspect) { user.aspects.create(:name => 'heroes') }
|
||||
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:aspect2) { user2.aspects.create(:name => 'losers') }
|
||||
|
||||
let(:user3) { Factory.create(:user) }
|
||||
let(:aspect3) { user3.aspects.create(:name => 'heroes') }
|
||||
|
||||
def receive_with_zord(user, person, xml)
|
||||
zord = Postzord::Receiver.new(user, :person => person)
|
||||
zord.parse_and_receive(xml)
|
||||
end
|
||||
|
||||
before do
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
@user1 = alice
|
||||
@aspect = @user1.aspects.first
|
||||
|
||||
@user2 = bob
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
@user3 = eve
|
||||
@aspect3 = @user3.aspects.first
|
||||
|
||||
end
|
||||
|
||||
it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do
|
||||
contact = user.contact_for(user2.person)
|
||||
user.add_contact_to_aspect(contact, user.aspects.create(:name => "villains"))
|
||||
status = user2.build_post(:status_message, :message => "Users do things", :to => aspect2.id)
|
||||
contact = @user1.contact_for(@user2.person)
|
||||
@user1.add_contact_to_aspect(contact, @user1.aspects.create(:name => "villains"))
|
||||
status = @user2.build_post(:status_message, :message => "Users do things", :to => @aspect2.id)
|
||||
Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once)
|
||||
zord = Postzord::Receiver.new(user, :object => status, :person => user2.person)
|
||||
zord = Postzord::Receiver.new(@user1, :object => status, :person => @user2.person)
|
||||
zord.receive_object
|
||||
end
|
||||
|
||||
it 'should be able to parse and store a status message from xml' do
|
||||
status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
status_message = @user2.post :status_message, :message => 'store this!', :to => @aspect2.id
|
||||
|
||||
xml = status_message.to_diaspora_xml
|
||||
user2.delete
|
||||
@user2.delete
|
||||
status_message.destroy
|
||||
|
||||
lambda {
|
||||
receive_with_zord(user, user2.person, xml)
|
||||
receive_with_zord(@user1, @user2.person, xml)
|
||||
}.should change(Post,:count).by(1)
|
||||
end
|
||||
|
||||
it 'should not create new aspects on message receive' do
|
||||
num_aspects = user.aspects.size
|
||||
num_aspects = @user1.aspects.size
|
||||
|
||||
2.times do |n|
|
||||
status_message = user2.post :status_message, :message => "store this #{n}!", :to => aspect2.id
|
||||
status_message = @user2.post :status_message, :message => "store this #{n}!", :to => @aspect2.id
|
||||
end
|
||||
|
||||
user.aspects.size.should == num_aspects
|
||||
@user1.aspects.size.should == num_aspects
|
||||
end
|
||||
|
||||
context 'update posts' do
|
||||
it 'does not update posts not marked as mutable' do
|
||||
status = user.post :status_message, :message => "store this!", :to => aspect.id
|
||||
status = @user1.post :status_message, :message => "store this!", :to => @aspect.id
|
||||
status.message = 'foo'
|
||||
xml = status.to_diaspora_xml
|
||||
|
||||
receive_with_zord(user2, user.person, xml)
|
||||
receive_with_zord(@user2, @user1.person, xml)
|
||||
|
||||
status.reload.message.should == 'store this!'
|
||||
end
|
||||
|
||||
it 'updates posts marked as mutable' do
|
||||
photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)
|
||||
photo = @user1.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => @aspect.id)
|
||||
photo.caption = 'foo'
|
||||
xml = photo.to_diaspora_xml
|
||||
user2.reload
|
||||
@user2.reload
|
||||
|
||||
receive_with_zord(user2, user.person, xml)
|
||||
receive_with_zord(@user2, @user1.person, xml)
|
||||
|
||||
photo.reload.caption.should match(/foo/)
|
||||
end
|
||||
|
|
@ -80,115 +79,116 @@ describe 'a user receives a post' do
|
|||
|
||||
describe 'post refs' do
|
||||
before do
|
||||
@status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
|
||||
user.reload
|
||||
aspect.reload
|
||||
@status_message = @user2.post :status_message, :message => "hi", :to => @aspect2.id
|
||||
@user1.reload
|
||||
@aspect.reload
|
||||
end
|
||||
|
||||
it "adds a received post to the aspect and visible_posts array" do
|
||||
user.raw_visible_posts.include?(@status_message).should be_true
|
||||
aspect.posts.include?(@status_message).should be_true
|
||||
@user1.raw_visible_posts.include?(@status_message).should be_true
|
||||
@aspect.posts.include?(@status_message).should be_true
|
||||
end
|
||||
|
||||
it 'removes posts upon disconnecting' do
|
||||
user.disconnect(user2.person)
|
||||
user.reload
|
||||
user.raw_visible_posts.should_not include @status_message
|
||||
@user1.disconnect(@user2.person)
|
||||
@user1.reload
|
||||
@user1.raw_visible_posts.should_not include @status_message
|
||||
end
|
||||
|
||||
it 'deletes a post if the noone links to it' do
|
||||
person = Factory(:person)
|
||||
user.activate_contact(person, aspect)
|
||||
@user1.activate_contact(person, @aspect)
|
||||
post = Factory.create(:status_message, :person => person)
|
||||
post.post_visibilities.should be_empty
|
||||
receive_with_zord(user, person, post.to_diaspora_xml)
|
||||
aspect.post_visibilities.reset
|
||||
aspect.posts(true).should include(post)
|
||||
receive_with_zord(@user1, person, post.to_diaspora_xml)
|
||||
@aspect.post_visibilities.reset
|
||||
@aspect.posts(true).should include(post)
|
||||
post.post_visibilities.reset
|
||||
post.post_visibilities.length.should == 1
|
||||
|
||||
lambda {
|
||||
user.disconnected_by(person)
|
||||
@user1.disconnected_by(person)
|
||||
}.should change(Post, :count).by(-1)
|
||||
end
|
||||
it 'deletes post_visibilities on disconnected by' do
|
||||
person = Factory(:person)
|
||||
user.activate_contact(person, aspect)
|
||||
@user1.activate_contact(person, @aspect)
|
||||
post = Factory.create(:status_message, :person => person)
|
||||
post.post_visibilities.should be_empty
|
||||
receive_with_zord(user, person, post.to_diaspora_xml)
|
||||
aspect.post_visibilities.reset
|
||||
aspect.posts(true).should include(post)
|
||||
receive_with_zord(@user1, person, post.to_diaspora_xml)
|
||||
@aspect.post_visibilities.reset
|
||||
@aspect.posts(true).should include(post)
|
||||
post.post_visibilities.reset
|
||||
post.post_visibilities.length.should == 1
|
||||
|
||||
lambda {
|
||||
user.disconnected_by(person)
|
||||
@user1.disconnected_by(person)
|
||||
}.should change{post.post_visibilities(true).count}.by(-1)
|
||||
end
|
||||
it 'should keep track of user references for one person ' do
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 2
|
||||
@status_message.user_refs.should == 3
|
||||
|
||||
user.disconnect(user2.person)
|
||||
@user1.disconnect(@user2.person)
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 1
|
||||
@status_message.user_refs.should == 2
|
||||
end
|
||||
|
||||
it 'should not override userrefs on receive by another person' do
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 2
|
||||
|
||||
user3.activate_contact(user2.person, aspect3)
|
||||
xml = @status_message.to_diaspora_xml
|
||||
|
||||
receive_with_zord(user3, user2.person, xml)
|
||||
|
||||
new_user = Factory(:user)
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 3
|
||||
|
||||
user.disconnect(user2.person)
|
||||
new_user.activate_contact(@user2.person, @aspect3)
|
||||
xml = @status_message.to_diaspora_xml
|
||||
|
||||
receive_with_zord(new_user, @user2.person, xml)
|
||||
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 2
|
||||
@status_message.user_refs.should == 4
|
||||
|
||||
@user1.disconnect(@user2.person)
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe 'comments' do
|
||||
before do
|
||||
connect_users(user, aspect, user3, aspect3)
|
||||
@post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||
connect_users(@user1, @aspect, @user3, @aspect3)
|
||||
@post = @user1.post :status_message, :message => "hello", :to => @aspect.id
|
||||
|
||||
xml = @post.to_diaspora_xml
|
||||
|
||||
receive_with_zord(user2, user.person, xml)
|
||||
receive_with_zord(user3, user.person, xml)
|
||||
receive_with_zord(@user2, @user1.person, xml)
|
||||
receive_with_zord(@user3, @user1.person, xml)
|
||||
|
||||
@comment = user3.comment('tada',:on => @post)
|
||||
@comment.post_creator_signature = @comment.sign_with_key(user.encryption_key)
|
||||
@comment = @user3.comment('tada',:on => @post)
|
||||
@comment.post_creator_signature = @comment.sign_with_key(@user1.encryption_key)
|
||||
@xml = @comment.to_diaspora_xml
|
||||
@comment.delete
|
||||
end
|
||||
|
||||
it 'should correctly attach the user already on the pod' do
|
||||
user2.reload.raw_visible_posts.size.should == 1
|
||||
@user2.reload.raw_visible_posts.size.should == 1
|
||||
post_in_db = StatusMessage.find(@post.id)
|
||||
post_in_db.comments.should == []
|
||||
receive_with_zord(user2, user.person, @xml)
|
||||
receive_with_zord(@user2, @user1.person, @xml)
|
||||
|
||||
post_in_db.comments(true).first.person.should == user3.person
|
||||
post_in_db.comments(true).first.person.should == @user3.person
|
||||
end
|
||||
|
||||
it 'should correctly marshal a stranger for the downstream user' do
|
||||
remote_person = user3.person.dup
|
||||
user3.person.delete
|
||||
user3.delete
|
||||
remote_person = @user3.person.dup
|
||||
@user3.person.delete
|
||||
@user3.delete
|
||||
remote_person.id = nil
|
||||
|
||||
#stubs async webfinger
|
||||
Person.should_receive(:by_account_identifier).twice.and_return{ |handle|
|
||||
if handle == user.person.diaspora_handle
|
||||
user.person.save
|
||||
user.person
|
||||
if handle == @user1.person.diaspora_handle
|
||||
@user1.person.save
|
||||
@user1.person
|
||||
else
|
||||
remote_person.profile = Factory(:profile)
|
||||
remote_person.save!
|
||||
|
|
@ -196,27 +196,27 @@ describe 'a user receives a post' do
|
|||
end
|
||||
}
|
||||
|
||||
user2.reload.raw_visible_posts.size.should == 1
|
||||
@user2.reload.raw_visible_posts.size.should == 1
|
||||
post_in_db = StatusMessage.find(@post.id)
|
||||
post_in_db.comments.should == []
|
||||
|
||||
receive_with_zord(user2, user.person, @xml)
|
||||
receive_with_zord(@user2, @user1.person, @xml)
|
||||
|
||||
post_in_db.comments(true).first.person.should == remote_person
|
||||
end
|
||||
end
|
||||
|
||||
describe 'salmon' do
|
||||
let(:post){user.post :status_message, :message => "hello", :to => aspect.id}
|
||||
let(:salmon){user.salmon( post )}
|
||||
let(:post){@user1.post :status_message, :message => "hello", :to => @aspect.id}
|
||||
let(:salmon){@user1.salmon( post )}
|
||||
|
||||
it 'processes a salmon for a post' do
|
||||
salmon_xml = salmon.xml_for(user2.person)
|
||||
salmon_xml = salmon.xml_for(@user2.person)
|
||||
|
||||
zord = Postzord::Receiver.new(user2, :salmon_xml => salmon_xml)
|
||||
zord = Postzord::Receiver.new(@user2, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
|
||||
user2.raw_visible_posts.include?(post).should be_true
|
||||
@user2.raw_visible_posts.include?(post).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,15 +31,13 @@ describe DataConversion::ImportToMysql do
|
|||
@migrator.import_raw_users
|
||||
end
|
||||
it "imports data into the users table" do
|
||||
Mongo::User.count.should == 6
|
||||
User.count.should == 0
|
||||
@migrator.process_raw_users
|
||||
User.count.should == 6
|
||||
lambda {
|
||||
@migrator.process_raw_users
|
||||
}.should change(User, :count).by(Mongo::User.count)
|
||||
end
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_users
|
||||
bob = User.first
|
||||
bob.mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
|
||||
bob = User.where(:mongo_id => "4d2b6eb6cc8cb43cc2000007").first
|
||||
bob.username.should == "bob1d2f837"
|
||||
bob.email.should == "bob1a25dee@pivotallabs.com"
|
||||
bob.serialized_private_key.should_not be_nil
|
||||
|
|
@ -64,21 +62,19 @@ describe DataConversion::ImportToMysql do
|
|||
@migrator.import_raw_aspects
|
||||
end
|
||||
it "imports data into the aspects table" do
|
||||
Mongo::Aspect.count.should == 4
|
||||
Aspect.count.should == 0
|
||||
@migrator.process_raw_aspects
|
||||
Aspect.count.should == 4
|
||||
lambda {
|
||||
@migrator.process_raw_aspects
|
||||
}.should change(Aspect, :count).by(Mongo::Aspect.count)
|
||||
end
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_aspects
|
||||
aspect = Aspect.first
|
||||
aspect = Aspect.where(:mongo_id => "4d2b6eb6cc8cb43cc2000008").first
|
||||
aspect.name.should == "generic"
|
||||
aspect.mongo_id.should == "4d2b6eb6cc8cb43cc2000008"
|
||||
aspect.user_mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
|
||||
end
|
||||
it "sets the relation column" do
|
||||
@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
|
||||
end
|
||||
end
|
||||
|
|
@ -91,18 +87,16 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
|
||||
it "imports data into the services table" do
|
||||
Mongo::Service.count.should == 2
|
||||
Service.count.should == 0
|
||||
@migrator.process_raw_services
|
||||
Service.count.should == 2
|
||||
lambda {
|
||||
@migrator.process_raw_services
|
||||
}.should change(Service, :count).by(Mongo::Service.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_services
|
||||
service = Service.first
|
||||
service = Service.where(:mongo_id => "4d2b6ec4cc8cb43cc200003e").first
|
||||
service.type_before_type_cast.should == "Services::Facebook"
|
||||
service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014"
|
||||
service.mongo_id.should == "4d2b6ec4cc8cb43cc200003e"
|
||||
service.provider.should be_nil
|
||||
service.uid.should be_nil
|
||||
service.access_token.should == "yeah"
|
||||
|
|
@ -111,7 +105,7 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
it 'sets the relation column' do
|
||||
@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
|
||||
end
|
||||
end
|
||||
|
|
@ -182,18 +176,16 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
|
||||
it "imports data into the people table" do
|
||||
Mongo::Person.count.should == 10
|
||||
Person.count.should == 0
|
||||
@migrator.process_raw_people
|
||||
Person.count.should == 10
|
||||
lambda {
|
||||
@migrator.process_raw_people
|
||||
}.should change(Person, :count).by(Mongo::Person.count)
|
||||
end
|
||||
|
||||
it "imports all the columns of a non-owned person" do
|
||||
@migrator.process_raw_people
|
||||
mongo_person = Mongo::Person.first
|
||||
person = Person.first
|
||||
mongo_person = Mongo::Person.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
|
||||
person = Person.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
|
||||
person.owner_id.should be_nil
|
||||
person.mongo_id.should == "4d2b6eb6cc8cb43cc2000001"
|
||||
person.guid.should == person.mongo_id
|
||||
person.url.should == "http://google-1b05052.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
|
||||
@migrator.process_raw_people
|
||||
person = Person.where(:owner_id => User.first.id).first
|
||||
mongo_person = Mongo::Person.where(:mongo_id => person.mongo_id).first
|
||||
person.mongo_id.should == mongo_person.mongo_id
|
||||
mongo_person = Mongo::Person.first
|
||||
person = Person.where(:mongo_id => mongo_person.mongo_id).first
|
||||
person.guid.should == mongo_person.mongo_id
|
||||
person.url.should == mongo_person.url
|
||||
person.diaspora_handle.should == mongo_person.diaspora_handle
|
||||
|
|
@ -214,8 +205,9 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
it 'sets the relational column of an owned person' do
|
||||
@migrator.process_raw_people
|
||||
person = Person.where(:owner_id => User.first.id).first
|
||||
person.should_not be_nil
|
||||
mongo_person = Mongo::Person.where("mongo_people.owner_mongo_id IS NOT NULL").first
|
||||
person = Person.where(:mongo_id => mongo_person.mongo_id).first
|
||||
person.owner.should_not be_nil
|
||||
person.diaspora_handle.should include(person.owner.username)
|
||||
end
|
||||
end
|
||||
|
|
@ -229,17 +221,15 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
|
||||
it "imports data into the mongo_contacts table" do
|
||||
Mongo::Contact.count.should == 6
|
||||
Contact.count.should == 0
|
||||
@migrator.process_raw_contacts
|
||||
Contact.count.should == 6
|
||||
lambda {
|
||||
@migrator.process_raw_contacts
|
||||
}.should change(Contact, :count).by(Mongo::Contact.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_contacts
|
||||
contact = Contact.first
|
||||
mongo_contact = Mongo::Contact.where(:mongo_id => contact.mongo_id).first
|
||||
contact.mongo_id.should == "4d2b6eb7cc8cb43cc200000f"
|
||||
mongo_contact = Mongo::Contact.first
|
||||
contact = Contact.where(:mongo_id => mongo_contact.mongo_id).first
|
||||
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.pending.should be_false
|
||||
|
|
@ -257,18 +247,18 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
|
||||
it "imports data into the mongo_aspect_memberships table" do
|
||||
Mongo::AspectMembership.count.should == 6
|
||||
AspectMembership.count.should == 0
|
||||
@migrator.process_raw_aspect_memberships
|
||||
AspectMembership.count.should == 6
|
||||
lambda {
|
||||
@migrator.process_raw_aspect_memberships
|
||||
}.should change(AspectMembership, :count).by(Mongo::AspectMembership.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_aspect_memberships
|
||||
aspectm = AspectMembership.first
|
||||
mongo_aspectm = Mongo::AspectMembership.first
|
||||
aspectm.contact_id.should == Contact.where(:mongo_id => mongo_aspectm.contact_mongo_id).first.id
|
||||
aspectm.aspect_id.should == Aspect.where(:mongo_id => mongo_aspectm.aspect_mongo_id).first.id
|
||||
aspectm = AspectMembership.where(
|
||||
: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
|
||||
describe "profiles" do
|
||||
|
|
@ -280,19 +270,17 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
|
||||
it "processs data into the mongo_profiles table" do
|
||||
Mongo::Profile.count.should == 10
|
||||
Profile.count.should == 0
|
||||
@migrator.process_raw_profiles
|
||||
Profile.count.should == 10
|
||||
lambda {
|
||||
@migrator.process_raw_profiles
|
||||
}.should change(Profile, :count).by(Mongo::Profile.count)
|
||||
end
|
||||
|
||||
it "processs all the columns" do
|
||||
@migrator.process_raw_profiles
|
||||
profile = Profile.first
|
||||
profile = Profile.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
|
||||
profile.image_url_medium.should be_nil
|
||||
profile.searchable.should == true
|
||||
profile.image_url.should be_nil
|
||||
profile.mongo_id.should == "4d2b6eb6cc8cb43cc2000001"
|
||||
profile.gender.should be_nil
|
||||
profile.diaspora_handle.should == profile.person.diaspora_handle
|
||||
profile.last_name.should == 'weinstien'
|
||||
|
|
@ -315,10 +303,9 @@ describe DataConversion::ImportToMysql do
|
|||
end
|
||||
|
||||
it "imports data into the posts table" do
|
||||
Mongo::Post.count.should == 6
|
||||
Post.count.should == 0
|
||||
@migrator.process_raw_posts
|
||||
Post.count.should == 6
|
||||
lambda {
|
||||
@migrator.process_raw_posts
|
||||
}.should change(Post, :count).by(Mongo::Post.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
|
|
@ -374,11 +361,10 @@ describe DataConversion::ImportToMysql do
|
|||
@migrator.import_raw_comments
|
||||
end
|
||||
|
||||
it "imports data into the mongo_comments table" do
|
||||
Mongo::Comment.count.should == 2
|
||||
Comment.count.should == 0
|
||||
@migrator.process_raw_comments
|
||||
Comment.count.should == 2
|
||||
it "imports data into the comments table" do
|
||||
lambda {
|
||||
@migrator.process_raw_comments
|
||||
}.should change(Comment, :count).by(Mongo::Comment.count)
|
||||
end
|
||||
|
||||
it "processes all the columns" do
|
||||
|
|
|
|||
|
|
@ -8,21 +8,18 @@ require File.join(Rails.root, 'lib/diaspora/exporter')
|
|||
describe Diaspora::Exporter do
|
||||
|
||||
before do
|
||||
@user1 = Factory.create(:user)
|
||||
@user1 = alice
|
||||
@user2 = Factory.create(:user)
|
||||
@user3 = Factory.create(:user)
|
||||
@user3 = bob
|
||||
|
||||
@aspect = @user1.aspects.create(:name => "Old Work")
|
||||
@aspect = @user1.aspects.first
|
||||
@aspect1 = @user1.aspects.create(:name => "Work")
|
||||
@aspect2 = @user2.aspects.create(:name => "Family")
|
||||
@aspect3 = @user3.aspects.create(:name => "Pivots")
|
||||
@aspect3 = @user3.aspects.first
|
||||
|
||||
@status_message1 = @user1.post(:status_message, :message => "One", :public => true, :to => @aspect1.id)
|
||||
@status_message2 = @user1.post(:status_message, :message => "Two", :public => true, :to => @aspect1.id)
|
||||
@status_message3 = @user2.post(:status_message, :message => "Three", :public => false, :to => @aspect2.id)
|
||||
|
||||
@user1.reload
|
||||
@user2.reload
|
||||
end
|
||||
|
||||
def exported
|
||||
|
|
@ -50,8 +47,7 @@ describe Diaspora::Exporter do
|
|||
context '<contacts/>' do
|
||||
|
||||
before do
|
||||
connect_users(@user1, @aspect1, @user3, @aspect3)
|
||||
@user1.add_contact_to_aspect(@user1.contact_for(@user3.person), @aspect)
|
||||
@user1.add_contact_to_aspect(@user1.contact_for(@user3.person), @aspect1)
|
||||
@user1.reload
|
||||
end
|
||||
|
||||
|
|
@ -71,10 +67,7 @@ describe Diaspora::Exporter do
|
|||
|
||||
context '<people/>' do
|
||||
let(:people_xml) {exported.xpath('//people').to_s}
|
||||
before do
|
||||
connect_users(@user1, @aspect1, @user3, @aspect3)
|
||||
@user1.reload
|
||||
end
|
||||
|
||||
it 'should include persons id' do
|
||||
people_xml.should include @user3.person.guid
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ require File.join(Rails.root, 'lib/diaspora/ostatus_builder')
|
|||
|
||||
describe Diaspora::OstatusBuilder do
|
||||
|
||||
let!(:user) { Factory.create(:user) }
|
||||
let(:aspect) { user.aspects.create(:name => "Public People") }
|
||||
let!(:user) { alice }
|
||||
let(:aspect) { user.aspects.first }
|
||||
let!(:public_status_messages) {
|
||||
3.times.inject([]) do |arr,n|
|
||||
s = user.post(:status_message, :message => "hey#{n}", :public => true, :to => aspect.id)
|
||||
|
|
|
|||
|
|
@ -6,15 +6,20 @@ require 'spec_helper'
|
|||
|
||||
describe Diaspora::Parser do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspects.create(:name => 'spies')
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspects.create(:name => "pandas")
|
||||
@user1 = alice
|
||||
@user2 = bob
|
||||
@user3 = eve
|
||||
|
||||
@aspect1 = @user1.aspects.first
|
||||
@aspect2 = @user2.aspects.first
|
||||
@aspect3 = @user3.aspects.first
|
||||
|
||||
@person = Factory.create(:person)
|
||||
end
|
||||
|
||||
describe "parsing compliant XML object" do
|
||||
it 'should be able to correctly parse comment fields' do
|
||||
post = @user.post :status_message, :message => "hello", :to => @aspect.id
|
||||
post = @user1.post :status_message, :message => "hello", :to => @aspect1.id
|
||||
comment = Factory.create(:comment, :post => post, :person => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!")
|
||||
comment.delete
|
||||
xml = comment.to_diaspora_xml
|
||||
|
|
@ -26,44 +31,41 @@ describe Diaspora::Parser do
|
|||
end
|
||||
|
||||
it 'should accept retractions' do
|
||||
connect_users(@user, @aspect, @user2, @aspect2)
|
||||
message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
|
||||
retraction = Retraction.for(message)
|
||||
xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
zord = Postzord::Receiver.new(@user, :person => @user2.person)
|
||||
zord = Postzord::Receiver.new(@user1, :person => @user2.person)
|
||||
zord.parse_and_receive(xml)
|
||||
}.should change(StatusMessage, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
@user.send_contact_request_to(@user2.person, @aspect)
|
||||
request = @user2.request_from(@user.person)
|
||||
@user1.send_contact_request_to(@user3.person, @aspect1)
|
||||
request = @user3.request_from(@user1.person)
|
||||
fantasy_resque do
|
||||
@user2.accept_and_respond(request.id, @aspect2.id)
|
||||
@user3.accept_and_respond(request.id, @aspect3.id)
|
||||
end
|
||||
@user.reload
|
||||
@aspect.reload
|
||||
new_contact = @user.contact_for(@user2.person)
|
||||
@aspect.contacts.include?(new_contact).should be true
|
||||
@user.contacts.reload.include?(new_contact).should be true
|
||||
@user1.reload
|
||||
@aspect1.reload
|
||||
new_contact = @user1.contact_for(@user3.person)
|
||||
@aspect1.contacts.include?(new_contact).should be true
|
||||
@user1.contacts.include?(new_contact).should be true
|
||||
end
|
||||
|
||||
it 'should process retraction for a person' do
|
||||
connect_users(@user, @aspect, @user2, @aspect2)
|
||||
retraction = Retraction.for(@user2)
|
||||
retraction_xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
zord = Postzord::Receiver.new(@user, :person => @user2.person)
|
||||
zord = Postzord::Receiver.new(@user1, :person => @user2.person)
|
||||
zord.parse_and_receive(retraction_xml)
|
||||
}.should change {
|
||||
@aspect.contacts(true).size }.by(-1)
|
||||
@aspect1.contacts(true).size }.by(-1)
|
||||
end
|
||||
|
||||
it 'should marshal a profile for a person' do
|
||||
connect_users(@user, @aspect, @user2, @aspect2)
|
||||
#Create person
|
||||
person = @user2.person
|
||||
id = person.id
|
||||
|
|
@ -85,7 +87,7 @@ describe Diaspora::Parser do
|
|||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Marshal profile
|
||||
zord = Postzord::Receiver.new(@user, :person => person)
|
||||
zord = Postzord::Receiver.new(@user1, :person => person)
|
||||
zord.parse_and_receive(xml)
|
||||
|
||||
#Check that marshaled profile is the same as old profile
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ end
|
|||
|
||||
describe Diaspora::Socketable do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspects.create(:name => "losers")
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
@post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id)
|
||||
@post.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe Diaspora::Webhooks do
|
|||
class Foo
|
||||
include Diaspora::Webhooks
|
||||
end
|
||||
|
||||
|
||||
f = Foo.new
|
||||
|
||||
proc{ f.subscribers(1)}.should raise_error /override subscribers/
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ require 'spec_helper'
|
|||
|
||||
describe 'user encryption' do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspects.create(:name => 'dudes')
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
end
|
||||
|
||||
describe 'encryption' do
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ require File.join(Rails.root, 'lib/postzord/dispatch')
|
|||
|
||||
describe Postzord::Dispatch do
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@user = alice
|
||||
@sm = Factory(:status_message, :public => true)
|
||||
@subscribers = []
|
||||
5.times{@subscribers << Factory(:person)}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,14 @@ require File.join(Rails.root, 'lib/postzord/receiver')
|
|||
describe Postzord::Receiver do
|
||||
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@user2 = Factory(:user)
|
||||
@user = alice
|
||||
@user2 = bob
|
||||
@person2 = @user2.person
|
||||
|
||||
aspect1 = @user.aspects.create(:name => "hey")
|
||||
aspect2 = @user2.aspects.create(:name => "hey")
|
||||
|
||||
connect_users(@user, aspect1, @user2, aspect2)
|
||||
aspect1 = @user.aspects.first
|
||||
aspect2 = @user2.aspects.first
|
||||
|
||||
@original_post = @user2.build_post(:status_message, :message => "hey", :aspect_ids => [aspect2.id])
|
||||
|
||||
@salmon_xml = @user2.salmon(@original_post).xml_for(@user.person)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ require 'spec_helper'
|
|||
require File.join(Rails.root, 'lib', 'pubsubhubbub')
|
||||
|
||||
describe Pubsubhubbub do
|
||||
|
||||
|
||||
before do
|
||||
RestClient.unstub!(:post)
|
||||
end
|
||||
|
|
@ -15,9 +15,6 @@ describe Pubsubhubbub do
|
|||
RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success))
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
end
|
||||
|
||||
describe '#publish' do
|
||||
it 'posts the feed to the given hub' do
|
||||
hub = "http://hubzord.com/"
|
||||
|
|
|
|||
|
|
@ -28,12 +28,11 @@ describe RakeHelpers do
|
|||
end
|
||||
|
||||
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.count.should == 1
|
||||
User.first.invites.should == 10
|
||||
User.last.invites.should == 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Salmon do
|
||||
let(:user){Factory.create(:user)}
|
||||
let(:user2) {Factory.create(:user)}
|
||||
let(:user){alice}
|
||||
let(:user2) {eve}
|
||||
let(:user3) {Factory.create(:user)}
|
||||
let(:post){ user.post :status_message, :message => "hi", :to => user.aspects.create(:name => "sdg").id }
|
||||
|
||||
|
|
@ -71,8 +71,8 @@ describe Salmon do
|
|||
|
||||
it 'should fail if no author is found' do
|
||||
parsed_salmon.author_email = 'tom@tom.joindiaspora.com'
|
||||
|
||||
|
||||
|
||||
|
||||
proc {parsed_salmon.author.public_key}.should raise_error "did you remember to async webfinger?"
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ require 'spec_helper'
|
|||
require File.join(Rails.root, 'lib/webfinger')
|
||||
|
||||
describe Webfinger do
|
||||
let(:user1) { Factory.create(:user) }
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:user1) { alice }
|
||||
let(:user2) { eve }
|
||||
|
||||
let(:account) {"foo@tom.joindiaspora.com"}
|
||||
let(:person){ Factory(:person, :diaspora_handle => account)}
|
||||
|
|
@ -39,7 +39,7 @@ describe Webfinger do
|
|||
end
|
||||
end
|
||||
|
||||
context 'webfinger query chain processing' do
|
||||
context 'webfinger query chain processing' do
|
||||
describe '#webfinger_profile_url' do
|
||||
it 'should parse out the webfinger template' do
|
||||
finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}"
|
||||
|
|
@ -79,14 +79,14 @@ describe Webfinger do
|
|||
diaspora_finger.stub!(:body).and_return(diaspora_finger)
|
||||
RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml)
|
||||
#new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com")
|
||||
# http://tom.joindiaspora.com/.well-known/host-meta
|
||||
# http://tom.joindiaspora.com/.well-known/host-meta
|
||||
f = Webfinger.new("tom@tom.joindiaspora.com").fetch
|
||||
|
||||
f.should be_valid
|
||||
end
|
||||
|
||||
|
||||
it 'should retry with http if https fails' do
|
||||
f = Webfinger.new("tom@tom.joindiaspora.com")
|
||||
f = Webfinger.new("tom@tom.joindiaspora.com")
|
||||
|
||||
diaspora_xrd.stub!(:body).and_return(diaspora_xrd)
|
||||
RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Notifier do
|
||||
let!(:user) {Factory.create(:user)}
|
||||
let!(:user2) {Factory.create(:user)}
|
||||
let!(:user) {alice}
|
||||
let!(:user2) {eve}
|
||||
|
||||
let!(:aspect) {user.aspects.create(:name => "win")}
|
||||
let!(:aspect2) {user2.aspects.create(:name => "win")}
|
||||
|
|
|
|||
|
|
@ -5,30 +5,25 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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)
|
||||
loaded_user = User.find(user.id)
|
||||
loaded_user.person.owner_id.should == user.id
|
||||
end
|
||||
|
||||
describe 'factories' do
|
||||
describe 'build' do
|
||||
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
|
||||
describe 'fixtures' do
|
||||
it 'loads fixtures' do
|
||||
User.count.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe '#connect_users' do
|
||||
before do
|
||||
@user1 = Factory.create(:user)
|
||||
@aspect1 = @user1.aspects.create(:name => "losers")
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspects.create(:name => "bruisers")
|
||||
@user1 = User.where(:username => 'alice').first
|
||||
@user2 = User.where(:username => 'eve').first
|
||||
|
||||
@aspect1 = @user1.aspects.first
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
connect_users(@user1, @aspect1, @user2, @aspect2)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Aspect do
|
||||
let(:user ) { Factory.create(:user) }
|
||||
let(:user ) { alice }
|
||||
let(:connected_person) { Factory.create(:person) }
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:user2) { eve }
|
||||
let(:connected_person_2) { Factory.create(:person) }
|
||||
|
||||
let(:aspect) {user.aspects.create(:name => 'losers')}
|
||||
let(:aspect2) {user2.aspects.create(:name => 'failures')}
|
||||
let(:aspect) {user.aspects.first }
|
||||
let(:aspect2) {user2.aspects.first }
|
||||
let(:aspect1) {user.aspects.create(:name => 'cats')}
|
||||
let(:user3) {Factory.create(:user)}
|
||||
let(:aspect3) {user3.aspects.create(:name => "lala")}
|
||||
|
|
@ -59,8 +59,9 @@ describe Aspect do
|
|||
end
|
||||
|
||||
it 'has no uniqueness between users' do
|
||||
aspect = user.aspects.create(:name => "New Aspect")
|
||||
aspect2 = user2.aspects.create(:name => aspect.name)
|
||||
aspect2.valid?.should be_true
|
||||
aspect2.should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ describe Aspect do
|
|||
end
|
||||
|
||||
it 'should have contacts' do
|
||||
aspect.contacts.size.should == 1
|
||||
aspect.contacts.size.should == 2
|
||||
end
|
||||
|
||||
describe '#aspects_with_person' do
|
||||
|
|
|
|||
|
|
@ -5,13 +5,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Comment do
|
||||
let(:user) {Factory.create(:user)}
|
||||
let(:aspect) {user.aspects.create(:name => "Doofuses")}
|
||||
let(:user) {alice}
|
||||
let(:aspect) {user.aspects.first}
|
||||
|
||||
let(:user2) {Factory.create(:user)}
|
||||
let(:aspect2) {user2.aspects.create(:name => "Lame-faces")}
|
||||
|
||||
let!(:connecting) { connect_users(user, aspect, user2, aspect2) }
|
||||
let(:user2) {bob}
|
||||
let(:aspect2) {user2.aspects.first}
|
||||
|
||||
|
||||
describe 'comment#notification_type' do
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Invitation do
|
||||
let(:user) {Factory.create(:user)}
|
||||
let!(:aspect) {user.aspects.create(:name => "Invitees")}
|
||||
let(:user2) {Factory.create(:user)}
|
||||
let(:user) {alice}
|
||||
let(:aspect) {user.aspects.first}
|
||||
let(:user2) {eve}
|
||||
before do
|
||||
user.invites = 20
|
||||
user.save
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ require 'spec_helper'
|
|||
describe Jobs::NotifyLocalUsers do
|
||||
describe '#perfom' do
|
||||
it 'should call Notification.notify on the object' do
|
||||
user = Factory(:user)
|
||||
user = alice
|
||||
person = Factory :person
|
||||
object = Factory :status_message
|
||||
|
||||
Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person))
|
||||
Jobs::NotifyLocalUsers.perform(user.id, object.class.to_s, object.id, person.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Jobs::PostToService do
|
||||
it 'calls service#post with the given service' do
|
||||
user = Factory(:user)
|
||||
user = alice
|
||||
aspect = user.aspects.create(:name => "yeah")
|
||||
post = user.post(:status_message, :message => 'foo', :to => aspect.id)
|
||||
User.stub!(:find_by_id).with(user.id.to_s).and_return(user)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Jobs::PostToServices do
|
||||
it 'calls post to services from the given user with given post' do
|
||||
user = Factory.create(:user)
|
||||
user = alice
|
||||
aspect = user.aspects.create(:name => "yeah")
|
||||
post = user.post(:status_message, :message => 'foo', :to => aspect.id)
|
||||
User.stub!(:find_by_id).with(user.id.to_s).and_return(user)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ require 'spec_helper'
|
|||
|
||||
describe Jobs::ReceiveLocal do
|
||||
before do
|
||||
@user1 = Factory.create(:user)
|
||||
@user2 = Factory.create(:user)
|
||||
@user1 = alice
|
||||
@person1 = @user1.person
|
||||
@user2 = eve
|
||||
@person2 = @user2.person
|
||||
@status = Factory(:status_message)
|
||||
@status_type = @status.class.to_s
|
||||
|
||||
|
|
@ -16,8 +18,8 @@ describe Jobs::ReceiveLocal do
|
|||
}
|
||||
|
||||
Person.stub(:find){ |id|
|
||||
if id == @user2.person.id
|
||||
@user2.person
|
||||
if id == @person2.id
|
||||
@person2
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
|
@ -36,6 +38,6 @@ describe Jobs::ReceiveLocal do
|
|||
m = mock()
|
||||
m.should_receive(:receive_object)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Jobs::ReceiveSalmon do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
@xml = '<xml></xml>'
|
||||
User.stub(:find){ |id|
|
||||
if id == @user.id
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Jobs::Receive do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
@person = Factory(:person)
|
||||
@xml = '<xml></xml>'
|
||||
User.stub(:find){ |id|
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require File.join(Rails.root, 'spec/spec_helper')
|
|||
|
||||
describe Jobs::SocketWebfinger do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user = alice
|
||||
@account = "tom@tom.joindiaspora.com"
|
||||
end
|
||||
it 'Makes a Webfinger object' do
|
||||
|
|
@ -30,7 +30,7 @@ describe Jobs::SocketWebfinger do
|
|||
Webfinger.stub(:new).and_return(finger)
|
||||
person = Factory.create(:person)
|
||||
finger.stub(:fetch).and_return(person)
|
||||
|
||||
|
||||
opts = {:symbol => true}
|
||||
person.should_receive(:socket_to_user).with(@user, opts)
|
||||
Jobs::SocketWebfinger.perform(@user.id, @account, opts)
|
||||
|
|
@ -39,10 +39,10 @@ describe Jobs::SocketWebfinger do
|
|||
finger = mock()
|
||||
Webfinger.stub(:new).and_return(finger)
|
||||
finger.stub(:fetch).and_raise(Webfinger::WebfingerFailedError)
|
||||
|
||||
|
||||
opts = {:class => 'people', :status => 'fail', :query => @account, :response => I18n.t('people.webfinger.fail', :handle => @account )}.to_json
|
||||
Diaspora::WebSocket.should_receive(:queue_to_user).with(@user.id, opts)
|
||||
Jobs::SocketWebfinger.perform(@user.id, @account)
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ describe Notification do
|
|||
before do
|
||||
@sm = Factory(:status_message)
|
||||
@person = Factory(:person)
|
||||
@user = Factory.create(:user)
|
||||
@user2 = Factory.create(:user)
|
||||
@user = alice
|
||||
@user2 = eve
|
||||
@aspect = @user.aspects.create(:name => "dudes")
|
||||
@opts = {:target_id => @sm.id,
|
||||
:target_type => @sm.class.name,
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ require 'spec_helper'
|
|||
|
||||
describe Photo do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspects.create(:name => "losers")
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
|
||||
@fixture_filename = 'button.png'
|
||||
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ require 'spec_helper'
|
|||
|
||||
describe Post do
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@user = alice
|
||||
@aspect = @user.aspects.create(:name => "winners")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe PostVisibility do
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@user = alice
|
||||
@aspect = @user.aspects.create(:name => 'Boozers')
|
||||
|
||||
@person = Factory(:person)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ require 'spec_helper'
|
|||
|
||||
describe Retraction do
|
||||
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:user) { alice }
|
||||
let(:person) { Factory(:person) }
|
||||
let(:aspect) { user.aspects.create(:name => "Bruisers") }
|
||||
let!(:activation) { user.activate_contact(person, aspect) }
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Services::Facebook do
|
||||
describe Services::Facebook do
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user.aspects.create(:name => "whatever")
|
||||
@user = alice
|
||||
@post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id)
|
||||
@service = Services::Facebook.new(:access_token => "yeah")
|
||||
@user.services << @service
|
||||
|
|
@ -12,7 +11,7 @@ describe Services::Facebook do
|
|||
|
||||
describe '#post' do
|
||||
it 'posts a status message to facebook' do
|
||||
RestClient.should_receive(:post).with("https://graph.facebook.com/me/feed", :message => @post.message, :access_token => @service.access_token)
|
||||
RestClient.should_receive(:post).with("https://graph.facebook.com/me/feed", :message => @post.message, :access_token => @service.access_token)
|
||||
@service.post(@post)
|
||||
end
|
||||
it 'swallows exception raised by facebook always being down' do
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Services::Twitter do
|
||||
describe Services::Twitter do
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user.aspects.create(:name => "whatever")
|
||||
@user = alice
|
||||
@post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id)
|
||||
@service = Services::Twitter.new(:access_token => "yeah", :access_secret => "foobar")
|
||||
@user.services << @service
|
||||
|
|
@ -12,7 +11,7 @@ describe Services::Twitter do
|
|||
|
||||
describe '#post' do
|
||||
it 'posts a status message to twitter' do
|
||||
Twitter.should_receive(:update).with(@post.message)
|
||||
Twitter.should_receive(:update).with(@post.message)
|
||||
@service.post(@post)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ require 'spec_helper'
|
|||
describe StatusMessage do
|
||||
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@aspect = @user.aspects.create(:name => "losers")
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
end
|
||||
|
||||
describe '#diaspora_handle=' do
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ require 'spec_helper'
|
|||
|
||||
describe "attack vectors" do
|
||||
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:aspect) { user.aspects.create(:name => 'heroes') }
|
||||
let(:user) { Factory.create(:user_with_aspect) }
|
||||
let(:aspect) { user.aspects.first }
|
||||
|
||||
let(:bad_user) { Factory.create(:user)}
|
||||
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:aspect2) { user2.aspects.create(:name => 'losers') }
|
||||
let(:user2) { eve }
|
||||
let(:aspect2) { user2.aspects.first }
|
||||
|
||||
let(:user3) { Factory.create(:user) }
|
||||
let(:aspect3) { user3.aspects.create(:name => 'heroes') }
|
||||
|
|
@ -207,7 +207,6 @@ describe "attack vectors" do
|
|||
end
|
||||
|
||||
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)
|
||||
|
||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ require 'spec_helper'
|
|||
|
||||
describe User do
|
||||
|
||||
let!(:user1){Factory.create(:user)}
|
||||
let!(:user2){Factory.create(:user)}
|
||||
let!(:aspect1){user1.aspects.create(:name => 'heroes')}
|
||||
let!(:aspect2){user2.aspects.create(:name => 'others')}
|
||||
let!(:user1){alice}
|
||||
let!(:user2){bob}
|
||||
let!(:aspect1){user1.aspects.first}
|
||||
let!(:aspect2){user2.aspects.first}
|
||||
|
||||
before do
|
||||
connect_users(user1, aspect1, user2, aspect2)
|
||||
@post = user1.build_post(:status_message, :message => "hey", :to => aspect1.id)
|
||||
@post.save
|
||||
user1.dispatch_post(@post, :to => "all")
|
||||
|
|
@ -23,7 +22,7 @@ describe User do
|
|||
it "doesn't call receive on local users" do
|
||||
user1.should_not_receive(:receive_comment)
|
||||
user2.should_not_receive(:receive_comment)
|
||||
|
||||
|
||||
comment = user2.build_comment "why so formal?", :on => @post
|
||||
comment.save!
|
||||
user2.dispatch_comment comment
|
||||
|
|
@ -34,7 +33,7 @@ describe User do
|
|||
it "doesn't call receive on local users" do
|
||||
user1.should_not_receive(:receive_comment)
|
||||
user2.should_not_receive(:receive_comment)
|
||||
|
||||
|
||||
comment = user1.build_comment "why so formal?", :on => @post
|
||||
comment.save!
|
||||
user1.dispatch_comment comment
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Diaspora::UserModules::Connecting do
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:user) { alice }
|
||||
let(:aspect) { user.aspects.create(:name => 'heroes') }
|
||||
let(:aspect1) { user.aspects.create(:name => 'other') }
|
||||
let(:person) { Factory.create(:person) }
|
||||
|
|
@ -14,7 +14,7 @@ describe Diaspora::UserModules::Connecting do
|
|||
let(:person_two) { Factory.create :person }
|
||||
let(:person_three) { Factory.create :person }
|
||||
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:user2) { eve }
|
||||
let(:aspect2) { user2.aspects.create(:name => "aspect two") }
|
||||
|
||||
describe '#send_contact_request_to' do
|
||||
|
|
@ -60,6 +60,12 @@ describe Diaspora::UserModules::Connecting do
|
|||
Request.where(:recipient_id => user.person.id).all.should include @r
|
||||
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
|
||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id)
|
||||
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
|
||||
|
||||
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)
|
||||
@request2 = Request.diaspora_initialize(:to => user2.person, :from => person_one)
|
||||
@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
|
||||
before do
|
||||
@request = Request.diaspora_initialize(:to => user.person, :from => person_one)
|
||||
@request_two = Request.diaspora_initialize(:to => user.person, :from => person_two)
|
||||
request = Request.diaspora_initialize(:to => user.person, :from => person_one)
|
||||
@received_request = request.receive(user, person_one)
|
||||
end
|
||||
|
||||
it "keeps the right counts of contacts" do
|
||||
received_req = @request.receive(user, person_one)
|
||||
|
||||
Request.where(:recipient_id => user.person.id).count.should == 1
|
||||
user.reload.contacts.size.should be 0
|
||||
|
||||
received_req2 = @request_two.receive(user, person_two)
|
||||
Request.where(:recipient_id => user.person.id).count.should == 2
|
||||
user.reload.contacts.size.should be 0
|
||||
|
||||
user.accept_contact_request received_req, aspect
|
||||
Request.where(:recipient_id => user.person.id).count.should == 1
|
||||
user.reload.contacts.size.should be 1
|
||||
user.contact_for(person_one).should_not be_nil
|
||||
|
||||
user.ignore_contact_request received_req2.id
|
||||
Request.where(:recipient_id => user.person.id).count.should == 0
|
||||
user.reload.contacts.size.should be 1
|
||||
user.contact_for(person_two).should be_nil
|
||||
describe '#accept_contact_request' do
|
||||
it "deletes the received request" do
|
||||
lambda {
|
||||
user.accept_contact_request(@received_request, aspect)
|
||||
}.should change(Request, :count).by(-1)
|
||||
end
|
||||
it "creates a new contact" do
|
||||
lambda {
|
||||
user.accept_contact_request(@received_request, aspect)
|
||||
}.should change(Contact, :count).by(1)
|
||||
user.contact_for(person_one).should_not be_nil
|
||||
end
|
||||
end
|
||||
describe '#ignore_contact_request' do
|
||||
it "removes the request" do
|
||||
lambda {
|
||||
user.ignore_contact_request(@received_request.id)
|
||||
}.should change(Request, :count).by(-1)
|
||||
end
|
||||
it "creates no new contact" do
|
||||
lambda {
|
||||
user.ignore_contact_request(@received_request)
|
||||
}.should_not change(Contact, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
let(:inviter) {new_user = Factory.create(:user); new_user.invites = 5; new_user.save; new_user;}
|
||||
let(:inviter) {new_user = eve; new_user.invites = 5; new_user.save; new_user;}
|
||||
let(:aspect) {inviter.aspects.create(:name => "awesome")}
|
||||
let(:another_user) {Factory.create(:user)}
|
||||
let(:another_user) {alice}
|
||||
let(:wrong_aspect) {another_user.aspects.create(:name => "super")}
|
||||
let(:inviter_with_3_invites) { new_user = Factory.create(:user); new_user.invites = 3; new_user.save; new_user;}
|
||||
let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ require 'spec_helper'
|
|||
|
||||
describe User do
|
||||
|
||||
let!(:user) { Factory.create(:user) }
|
||||
let!(:user2) { Factory.create(:user) }
|
||||
let!(:user) { alice }
|
||||
let!(:user2) { eve }
|
||||
|
||||
let!(:aspect) { user.aspects.create(:name => 'heroes') }
|
||||
let!(:aspect) { user.aspects.first }
|
||||
let!(:aspect1) { user.aspects.create(:name => 'other') }
|
||||
let!(:aspect2) { user2.aspects.create(:name => 'losers') }
|
||||
let!(:aspect2) { user2.aspects.first }
|
||||
|
||||
let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
|
||||
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ require 'spec_helper'
|
|||
describe User do
|
||||
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
@aspect = @user.aspects.create(:name => "cats")
|
||||
@user2 = Factory(:user_with_aspect)
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
@user2 = eve
|
||||
@aspect2 = @user2.aspects.first
|
||||
|
||||
@person_one = Factory.create :person
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:user) { alice }
|
||||
let(:aspect) { user.aspects.create(:name => 'heroes') }
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:user2) { eve }
|
||||
let(:aspect2) { user2.aspects.create(:name => 'stuff') }
|
||||
|
||||
it 'should have a key' do
|
||||
|
|
@ -16,10 +16,9 @@ describe User do
|
|||
|
||||
describe 'overwriting people' do
|
||||
it 'does not overwrite old users with factory' do
|
||||
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"
|
||||
new_user = Factory.create(:user, :id => user.id)
|
||||
new_user.persisted?.should be_true
|
||||
new_user.id.should_not == user.id
|
||||
lambda {
|
||||
new_user = Factory.create(:user, :id => user.id)
|
||||
}.should raise_error ActiveRecord::RecordNotUnique
|
||||
end
|
||||
it 'does not overwrite old users with create' do
|
||||
params = {:username => "ohai",
|
||||
|
|
@ -267,9 +266,9 @@ describe User do
|
|||
|
||||
it "only pushes to non-pending contacts" do
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
user.contacts.count.should == 1
|
||||
user.send_contact_request_to(Factory(:user).person, aspect)
|
||||
user.contacts.count.should == 2
|
||||
lambda {
|
||||
user.send_contact_request_to(Factory(:user).person, aspect)
|
||||
}.should change(user.contacts, :count).by(1)
|
||||
|
||||
m = mock()
|
||||
m.should_receive(:post)
|
||||
|
|
@ -339,7 +338,9 @@ describe User do
|
|||
|
||||
it 'should remove all aspects' do
|
||||
aspect
|
||||
lambda {user.destroy}.should change{user.aspects.reload.count}.by(-1)
|
||||
lambda {
|
||||
user.destroy
|
||||
}.should change{ user.aspects(true).count }.by(-2)
|
||||
end
|
||||
|
||||
describe '#remove_person' do
|
||||
|
|
@ -361,9 +362,10 @@ describe User do
|
|||
describe '#disconnect_everyone' do
|
||||
|
||||
it 'should send retractions to remote poeple' do
|
||||
person = user2.person
|
||||
user2.delete
|
||||
user2.person.owner_id = nil
|
||||
user2.person.save
|
||||
person.owner_id = nil
|
||||
person.save
|
||||
user.activate_contact(user2.person, aspect)
|
||||
|
||||
user.should_receive(:disconnect).once
|
||||
|
|
|
|||
|
|
@ -13,16 +13,18 @@ require 'factory_girl'
|
|||
|
||||
include Devise::TestHelpers
|
||||
include WebMock::API
|
||||
include HelperMethods
|
||||
#
|
||||
# Requires supporting files with custom matchers and macros, etc,
|
||||
# in ./support/ and its subdirectories.
|
||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
||||
include HelperMethods
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
config.mock_with :rspec
|
||||
|
||||
# config.fixture_path = "#{Rails.root}/spec/fixtures"
|
||||
# config.global_fixtures = :all
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
config.before(:each) do
|
||||
|
|
@ -33,6 +35,20 @@ RSpec.configure do |config|
|
|||
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
|
||||
def self.redis
|
||||
FakeRedis.new
|
||||
|
|
|
|||
16
spec/support/fixture_builder.rb
Normal file
16
spec/support/fixture_builder.rb
Normal 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
|
||||
|
||||
Loading…
Reference in a new issue