parent
75f95faebe
commit
9bca03d5e9
3 changed files with 28 additions and 20 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
* Force jasmine fails on syntax errors [#7185](https://github.com/diaspora/diaspora/pull/7185)
|
* Force jasmine fails on syntax errors [#7185](https://github.com/diaspora/diaspora/pull/7185)
|
||||||
* Don't display mail-related view content if it is disabled in the pod's config [#7190](https://github.com/diaspora/diaspora/pull/7190)
|
* Don't display mail-related view content if it is disabled in the pod's config [#7190](https://github.com/diaspora/diaspora/pull/7190)
|
||||||
* Use typeahead.js from rails-assets.org [#7192](https://github.com/diaspora/diaspora/pull/7192)
|
* Use typeahead.js from rails-assets.org [#7192](https://github.com/diaspora/diaspora/pull/7192)
|
||||||
|
* Refactor ShareVisibilitesController to use PostService [#7196](https://github.com/diaspora/diaspora/pull/7196)
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
* Fix fetching comments after fetching likes [#7167](https://github.com/diaspora/diaspora/pull/7167)
|
* Fix fetching comments after fetching likes [#7167](https://github.com/diaspora/diaspora/pull/7167)
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,14 @@ class ShareVisibilitiesController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def update
|
def update
|
||||||
#note :id references a postvisibility
|
post = post_service.find!(params[:post_id])
|
||||||
params[:shareable_id] ||= params[:post_id]
|
current_user.toggle_hidden_shareable(post)
|
||||||
params[:shareable_type] ||= 'Post'
|
head :ok
|
||||||
|
|
||||||
vis = current_user.toggle_hidden_shareable(accessible_post)
|
|
||||||
render :nothing => true, :status => 200
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def accessible_post
|
def post_service
|
||||||
@post ||= params[:shareable_type].constantize.where(:id => params[:post_id]).select("id, guid, author_id, created_at").first
|
@post_service ||= PostService.new(current_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,32 +7,42 @@ require 'spec_helper'
|
||||||
describe ShareVisibilitiesController, :type => :controller do
|
describe ShareVisibilitiesController, :type => :controller do
|
||||||
before do
|
before do
|
||||||
@status = alice.post(:status_message, :text => "hello", :to => alice.aspects.first)
|
@status = alice.post(:status_message, :text => "hello", :to => alice.aspects.first)
|
||||||
sign_in(bob, scope: :user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#update' do
|
describe '#update' do
|
||||||
context "on a post you can see" do
|
context "on a post you can see" do
|
||||||
|
before do
|
||||||
|
sign_in(bob, scope: :user)
|
||||||
|
end
|
||||||
|
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'it calls toggle_hidden_shareable' do
|
it 'it calls toggle_hidden_shareable' do
|
||||||
expect(@controller.current_user).to receive(:toggle_hidden_shareable).with(an_instance_of(Post))
|
expect(@controller.current_user).to receive(:toggle_hidden_shareable).with(an_instance_of(StatusMessage))
|
||||||
put :update, :format => :js, :id => 42, :post_id => @status.id
|
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe "#accessible_post" do
|
|
||||||
it "memoizes a query for a post given a post_id param" do
|
|
||||||
id = 1
|
|
||||||
@controller.params[:post_id] = id
|
|
||||||
@controller.params[:shareable_type] = 'Post'
|
|
||||||
|
|
||||||
expect(Post).to receive(:where).with(hash_including(:id => id)).once.and_return(double.as_null_object)
|
context "on a post you can't see" do
|
||||||
2.times do |n|
|
before do
|
||||||
@controller.send(:accessible_post)
|
sign_in(eve, scope: :user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an error" do
|
||||||
|
expect {
|
||||||
|
put :update, format: :js, id: 42, post_id: @status.id
|
||||||
|
}.to raise_error ActiveRecord::RecordNotFound
|
||||||
|
end
|
||||||
|
|
||||||
|
it "it doesn't call toggle_hidden_shareable" do
|
||||||
|
expect(@controller.current_user).not_to receive(:toggle_hidden_shareable).with(an_instance_of(StatusMessage))
|
||||||
|
begin
|
||||||
|
put :update, format: :js, id: 42, post_id: @status.id
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue