share_visibilities_controller_spec.rb 1.45 KB
Newer Older
danielgrippi's avatar
danielgrippi committed
1
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
2 3 4 5 6
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require 'spec_helper'

7
describe ShareVisibilitiesController, :type => :controller do
8
  before do
9
    @status = alice.post(:status_message, :text => "hello", :to => alice.aspects.first)
10 11
  end

12
  describe '#update' do
zhitomirskiyi's avatar
zhitomirskiyi committed
13
    context "on a post you can see" do
14 15 16 17
      before do
        sign_in(bob, scope: :user)
      end

zhitomirskiyi's avatar
zhitomirskiyi committed
18
      it 'succeeds' do
19
        put :update, :format => :js, :id => 42, :post_id => @status.id
20
        expect(response).to be_success
zhitomirskiyi's avatar
zhitomirskiyi committed
21
      end
22

23
      it 'it calls toggle_hidden_shareable' do
24
        expect(@controller.current_user).to receive(:toggle_hidden_shareable).with(an_instance_of(StatusMessage))
25
        put :update, :format => :js, :id => 42, :post_id => @status.id
zhitomirskiyi's avatar
zhitomirskiyi committed
26
      end
27
    end
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

    context "on a post you can't see" do
      before do
        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
46 47 48
      end
    end
  end
49
end