Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
maxwell
a validé
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe StatusMessagesController, :type => :controller do
maxwell
a validé
before do
Raphael Sofaer
a validé
@aspect1 = alice.aspects.first
maxwell
a validé
request.env["HTTP_REFERER"] = ""
Raphael Sofaer
a validé
sign_in :user, alice
allow(@controller).to receive(:current_user).and_return(alice)
Raphael Sofaer
a validé
alice.reload
maxwell
a validé
end
describe '#bookmarklet' do
it 'succeeds' do
get :bookmarklet
end
it 'contains a complete html document' do
get :bookmarklet
doc = Nokogiri(response.body)
expect(doc.xpath('//head').count).to equal 1
expect(doc.xpath('//body').count).to equal 1
Florian Staudacher
a validé
end
it 'accepts get params' do
get :bookmarklet, { url: 'https://www.youtube.com/watch?v=0Bmhjf0rKe8',
title: 'Surprised Kitty',
notes: 'cute kitty' }
describe '#new' do
it 'succeeds' do
get :new, :person_id => bob.person.id
it 'should redirect on desktop version' do
get :new
expect(response).to redirect_to(stream_path)
maxwell
a validé
describe '#create' do
let(:status_message_hash) {
{ :status_message => {
:public => "true",
:text => "facebook, is that you?",
maxwell
a validé
:aspect_ids => [@aspect1.id.to_s] }
}
danielgrippi
a validé
it 'creates with valid html' do
expect(response.status).to eq(302)
expect(response).to be_redirect
it 'creates with invalid html' do
post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 })
expect(response.status).to eq(302)
expect(response).to be_redirect
it 'creates with valid json' do
post :create, status_message_hash.merge(:format => 'json')
it 'creates with invalid json' do
post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }, :format => 'json')
it 'creates with valid mobile' do
post :create, status_message_hash.merge(:format => 'mobile')
expect(response.status).to eq(302)
expect(response).to be_redirect
it 'creates with invalid mobile' do
post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }, :format => 'mobile')
expect(response.status).to eq(302)
expect(response).to be_redirect
it 'removes getting started from new users' do
expect(@controller).to receive(:remove_getting_started)
post :create, status_message_hash
end
it 'takes public in aspect ids' do
post :create, status_message_hash.merge(:aspect_ids => ['public'])
end
it 'takes all_aspects in aspect ids' do
post :create, status_message_hash.merge(:aspect_ids => ['all_aspects'])
it "dispatches the post to the specified services" do
s1 = Services::Facebook.new
Raphael Sofaer
a validé
alice.services << s1
alice.services << Services::Twitter.new
status_message_hash[:services] = ['facebook']
service_types = Service.titles(status_message_hash[:services])
expect(alice).to receive(:dispatch_post).with(anything(), hash_including(:service_types => service_types))
it "works if services is a string" do
s1 = Services::Facebook.new
alice.services << s1
status_message_hash[:services] = "facebook"
expect(alice).to receive(:dispatch_post).with(anything(), hash_including(:service_types => ["Services::Facebook"]))
post :create, status_message_hash
end
it "doesn't overwrite author_id" do
Raphael Sofaer
a validé
status_message_hash[:status_message][:author_id] = bob.person.id
maxwell
a validé
post :create, status_message_hash
new_message = StatusMessage.find_by_text(status_message_hash[:status_message][:text])
expect(new_message.author_id).to eq(alice.person.id)
maxwell
a validé
end
it "doesn't overwrite id" do
Raphael Sofaer
a validé
old_status_message = alice.post(:status_message, :text => "hello", :to => @aspect1.id)
maxwell
a validé
status_message_hash[:status_message][:id] = old_status_message.id
post :create, status_message_hash
expect(old_status_message.reload.text).to eq('hello')
maxwell
a validé
end
it 'calls dispatch post once subscribers is set' do
expect(alice).to receive(:dispatch_post){|post, opts|
expect(post.subscribers(alice)).to eq([bob.person])
}
post :create, status_message_hash
end
it 'respsects provider_display_name' do
status_message_hash.merge!(:aspect_ids => ['public'])
status_message_hash[:status_message].merge!(:provider_display_name => "mobile")
post :create, status_message_hash
expect(StatusMessage.first.provider_display_name).to eq('mobile')
end
# disabled to fix federation
# it 'sends the errors in the body on js' do
# post :create, status_message_hash.merge!(:format => 'js', :status_message => {:text => ''})
# response.body.should include('Status message requires a message or at least one photo')
# end
maxwell
a validé
context 'with photos' do
before do
Raphael Sofaer
a validé
@photo1 = alice.build_post(:photo, :pending => true, :user_file=> File.open(photo_fixture_name), :to => @aspect1.id)
@photo2 = alice.build_post(:photo, :pending => true, :user_file=> File.open(photo_fixture_name), :to => @aspect1.id)
maxwell
a validé
@photo1.save!
@photo2.save!
@hash = status_message_hash
@hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s]
end
@hash.delete :text
Raphael Sofaer
a validé
it "attaches all referenced photos" do
maxwell
a validé
post :create, @hash
expect(assigns[:status_message].photos.map(&:id)).to match_array([@photo1, @photo2].map(&:id))
maxwell
a validé
end
maxwell
a validé
it "sets the pending bit of referenced photos" do
post :create, @hash
end
expect(@photo1.reload.pending).to be false
expect(@photo2.reload.pending).to be false
maxwell
a validé
end
end
end
describe '#remove_getting_started' do
it 'removes the getting started flag from new users' do
alice.getting_started = true
alice.save
expect {
@controller.send(:remove_getting_started)
}.to change {
alice.reload.getting_started
}.from(true).to(false)
end
it 'does nothing for returning users' do
expect {
@controller.send(:remove_getting_started)
}.to_not change {
alice.reload.getting_started
}
end
end