fix ResharesController / StatusMessage controller spec; remove another js response
This commit is contained in:
parent
719e265b68
commit
4fabbe93a5
4 changed files with 19 additions and 51 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
class ResharesController < ApplicationController
|
class ResharesController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
respond_to :js, :json
|
respond_to :json
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid])
|
@reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid])
|
||||||
|
|
@ -9,9 +9,6 @@ class ResharesController < ApplicationController
|
||||||
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
|
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
render :json => @reshare.as_api_response(:backbone), :status => 201
|
||||||
format.html { respond_with @reshare }
|
|
||||||
format.json{ render :json => @reshare.as_api_response(:backbone), :status => 201 }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<% if @reshare.persisted? %>
|
|
||||||
$('.stream_element#<%=params[:root_guid]%>').addClass('reshared');
|
|
||||||
ContentUpdater.addPostToStream(
|
|
||||||
"<%= escape_javascript(render(:partial => 'shared/stream_element', :locals => {:post => @reshare }))=%>"
|
|
||||||
);
|
|
||||||
<% else %>
|
|
||||||
Diaspora.page.flashMessages.render({success:false,
|
|
||||||
notice: "<%= reshare_error_message(@reshare) %>"});
|
|
||||||
<% end %>
|
|
||||||
|
|
@ -1,38 +1,45 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe ResharesController do
|
|
||||||
|
|
||||||
|
describe ResharesController do
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
|
let(:post_request!) {
|
||||||
|
post :create, :format => :json, :root_guid => @post_guid
|
||||||
|
}
|
||||||
|
|
||||||
|
before do
|
||||||
|
@post_guid = Factory(:status_message, :public => true).guid
|
||||||
|
end
|
||||||
|
|
||||||
it 'requires authentication' do
|
it 'requires authentication' do
|
||||||
post :create, :format => :js
|
post_request!
|
||||||
response.should_not be_success
|
response.should_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with an authenticated user' do
|
context 'with an authenticated user' do
|
||||||
before do
|
before do
|
||||||
sign_in :user, bob
|
sign_in :user, bob
|
||||||
@post_guid = Factory(:status_message, :public => true).guid
|
|
||||||
@controller.stub(:current_user).and_return(bob)
|
@controller.stub(:current_user).and_return(bob)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
post :create, :format => :js, :root_guid => @post_guid
|
|
||||||
response.should be_success
|
response.should be_success
|
||||||
|
post_request!
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a reshare' do
|
it 'creates a reshare' do
|
||||||
expect{
|
expect{
|
||||||
post :create, :format => :js, :root_guid => @post_guid
|
post_request!
|
||||||
}.should change(Reshare, :count).by(1)
|
}.should change(Reshare, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'after save, calls add to streams' do
|
it 'after save, calls add to streams' do
|
||||||
bob.should_receive(:add_to_streams)
|
bob.should_receive(:add_to_streams)
|
||||||
post :create, :format => :js, :root_guid => @post_guid
|
post_request!
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls dispatch' do
|
it 'calls dispatch' do
|
||||||
bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers))
|
bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers))
|
||||||
post :create, :format => :js, :root_guid => @post_guid
|
post_request!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -47,39 +47,12 @@ describe StatusMessagesController do
|
||||||
},
|
},
|
||||||
:aspect_ids => [@aspect1.id.to_s] }
|
:aspect_ids => [@aspect1.id.to_s] }
|
||||||
}
|
}
|
||||||
|
|
||||||
it 'removes getting started from new users' do
|
it 'removes getting started from new users' do
|
||||||
@controller.should_receive(:remove_getting_started)
|
@controller.should_receive(:remove_getting_started)
|
||||||
post :create, status_message_hash
|
post :create, status_message_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'js requests' do
|
|
||||||
it 'responds' do
|
|
||||||
post :create, status_message_hash.merge(:format => 'js')
|
|
||||||
response.status.should == 201
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'responds with json' do
|
|
||||||
post :create, status_message_hash.merge(:format => 'js')
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
json['post_id'].should_not be_nil
|
|
||||||
json['html'].should_not be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'saves the html as a fixture', :fixture => true do
|
|
||||||
post :create, status_message_hash.merge(:format => 'js')
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
save_fixture(json['html'], "created_status_message")
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'escapes XSS' do
|
|
||||||
xss = "<script> alert('hi browser') </script>"
|
|
||||||
post :create, status_message_hash.merge(:format => 'js', :text => xss)
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
json['html'].should_not =~ /<script>/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'takes public in aspect ids' do
|
it 'takes public in aspect ids' do
|
||||||
post :create, status_message_hash.merge(:aspect_ids => ['public'])
|
post :create, status_message_hash.merge(:aspect_ids => ['public'])
|
||||||
response.status.should == 302
|
response.status.should == 302
|
||||||
|
|
@ -166,7 +139,7 @@ describe StatusMessagesController do
|
||||||
alice.getting_started = true
|
alice.getting_started = true
|
||||||
alice.save
|
alice.save
|
||||||
expect{
|
expect{
|
||||||
@controller.remove_getting_started
|
@controller.remove_getting_started
|
||||||
}.should change{
|
}.should change{
|
||||||
alice.reload.getting_started
|
alice.reload.getting_started
|
||||||
}.from(true).to(false)
|
}.from(true).to(false)
|
||||||
|
|
@ -174,7 +147,7 @@ describe StatusMessagesController do
|
||||||
|
|
||||||
it 'does nothing for returning users' do
|
it 'does nothing for returning users' do
|
||||||
expect{
|
expect{
|
||||||
@controller.remove_getting_started
|
@controller.remove_getting_started
|
||||||
}.should_not change{
|
}.should_not change{
|
||||||
alice.reload.getting_started
|
alice.reload.getting_started
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue