Newer
Older
describe ResharesController, :type => :controller do
danielgrippi
a validé
let(:post_request!) {
post :create, :format => :json, :root_guid => @post_guid
}
before do
@post = FactoryGirl.create(:status_message, :public => true)
@post_guid = @post.guid
danielgrippi
a validé
end
danielgrippi
a validé
post_request!
end
context 'with an authenticated user' do
before do
allow(@controller).to receive(:current_user).and_return(bob)
danielgrippi
a validé
post_request!
end
it 'creates a reshare' do
expect{
danielgrippi
a validé
post_request!
}.to change(Reshare, :count).by(1)
expect(bob).to receive(:dispatch_post)
danielgrippi
a validé
post_request!
context 'resharing a reshared post' do
before do
FactoryGirl.create(:reshare, :root => @post, :author => bob.person)
end
it 'doesn\'t allow the user to reshare the post again' do
post_request!
expect(response.body).to eq(I18n.t("javascripts.failed_to_reshare"))
context 'resharing another user\'s reshare' do
before do
@root = @post
@post = FactoryGirl.create(:reshare, :root => @root, :author => alice.person)
end
it 'reshares the absolute root' do
post_request!
expect(@post.reshares.count).to eq(0)
expect(@root.reshares.count).to eq(2)
end
end
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
describe "#index" do
context "with a private post" do
before do
@alices_aspect = alice.aspects.where(name: "generic").first
@post = alice.post(:status_message, text: "hey", to: @alices_aspect.id)
end
it "returns a 404 for a post not visible to the user" do
sign_in(eve, scope: :user)
expect {
get :index, post_id: @post.id, format: :json
}.to raise_error(ActiveRecord::RecordNotFound)
end
it "returns an empty array for a post visible to the user" do
sign_in(bob, scope: :user)
get :index, post_id: @post.id, format: :json
expect(JSON.parse(response.body)).to eq([])
end
end
context "with a public post" do
before do
sign_in(alice, scope: :user)
@post = alice.post(:status_message, text: "hey", public: true)
end
it "returns an array of reshares for a post" do
bob.reshare!(@post)
get :index, post_id: @post.id, format: :json
expect(JSON.parse(response.body).map {|h| h["id"] }).to eq(@post.reshares.map(&:id))
end
it "returns an empty array for a post with no reshares" do
get :index, post_id: @post.id, format: :json
expect(JSON.parse(response.body)).to eq([])
end
end
end