Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'spec_helper'
describe ParticipationsController, :type => :controller do
before do
allow(@controller).to receive(:current_user).and_return(alice)
sign_in :user, alice
end
describe '#create' do
let(:stranger) { FactoryGirl.create(:user) }
shared_examples 'on a visible post' do
it 'creates the participation' do
post :create, post_id: @post.id
expect(alice.participations.where(:target_id => @post.id)).to exist
expect(response.code).to eq('201')
end
end
context 'on my own post' do
before do
aspect_to_post = alice.aspects.where(:name => 'generic').first
@post = alice.post :status_message, :text => 'something', :to => aspect_to_post
end
it_behaves_like 'on a visible post'
end
context 'on a post from a contact' do
before do
aspect_to_post = bob.aspects.where(:name => 'generic').first
@post = bob.post :status_message, :text => 'something', :to => aspect_to_post
end
it_behaves_like 'on a visible post'
end
context 'on a public post from a stranger' do
before do
@post = stranger.post :status_message, :text => 'something', :public => true, :to => 'all'
end
it_behaves_like 'on a visible post'
end
context 'on a non visible post' do
before do
@post = stranger.post :status_message, :text => 'something', :public => false, :to => 'all'
end
it 'should not create the participation' do
post :create, post_id: @post.id
expect(alice.participations.where(:target_id => @post.id)).not_to exist
expect(response.code).to eq('403')
end
end
end
describe '#destroy' do
let(:post) { FactoryGirl.create(:status_message) }
context 'on a post you partecipate to' do
before { alice.participate! post }
it 'should remove participation' do
delete :destroy, post_id: post.id
expect(alice.participations.where(:target_id => post.id)).not_to exist
end
end
context 'on a post you do not partecipate to' do
it 'says it is an unprocessable request' do
delete :destroy, post_id: post.id
expect(response.code).to eq('422')
end
end
end
end