mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Merge pull request #1978 from velesin/posts_controller__by_number_tests
Adds specs for PostsController#by_number.
This commit is contained in:
commit
ef18e415cf
2 changed files with 52 additions and 36 deletions
|
@ -119,7 +119,9 @@ class PostsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def by_number
|
def by_number
|
||||||
@post = Post.where(topic_id: params[:topic_id], post_number: params[:post_number]).first
|
finder = Post.where(topic_id: params[:topic_id], post_number: params[:post_number])
|
||||||
|
finder = finder.with_deleted if current_user.try(:staff?)
|
||||||
|
@post = finder.first
|
||||||
guardian.ensure_can_see!(@post)
|
guardian.ensure_can_see!(@post)
|
||||||
@post.revert_to(params[:version].to_i) if params[:version].present?
|
@post.revert_to(params[:version].to_i) if params[:version].present?
|
||||||
render_post_json(@post)
|
render_post_json(@post)
|
||||||
|
|
|
@ -1,5 +1,46 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
|
shared_examples 'finding and showing post' do
|
||||||
|
let(:user) { log_in }
|
||||||
|
let(:post) { Fabricate(:post, user: user) }
|
||||||
|
|
||||||
|
it 'ensures the user can see the post' do
|
||||||
|
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
|
||||||
|
xhr :get, action, params
|
||||||
|
response.should be_forbidden
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'succeeds' do
|
||||||
|
xhr :get, action, params
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
|
||||||
|
context "deleted post" do
|
||||||
|
|
||||||
|
before do
|
||||||
|
post.trash!(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can't find deleted posts as an anonymous user" do
|
||||||
|
xhr :get, action, params
|
||||||
|
response.should be_forbidden
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can't find deleted posts as a regular user" do
|
||||||
|
log_in(:user)
|
||||||
|
xhr :get, action, params
|
||||||
|
response.should be_forbidden
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can find posts as a moderator" do
|
||||||
|
log_in(:moderator)
|
||||||
|
xhr :get, action, params
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe PostsController do
|
describe PostsController do
|
||||||
|
|
||||||
describe 'short_link' do
|
describe 'short_link' do
|
||||||
|
@ -12,43 +53,16 @@ describe PostsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'show' do
|
describe 'show' do
|
||||||
let(:user) { log_in }
|
include_examples 'finding and showing post' do
|
||||||
let(:post) { Fabricate(:post, user: user) }
|
let(:action) { :show }
|
||||||
|
let(:params) { {id: post.id} }
|
||||||
it 'ensures the user can see the post' do
|
|
||||||
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
|
|
||||||
xhr :get, :show, id: post.id
|
|
||||||
response.should be_forbidden
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'succeeds' do
|
describe 'by_number' do
|
||||||
xhr :get, :show, id: post.id
|
include_examples 'finding and showing post' do
|
||||||
response.should be_success
|
let(:action) { :by_number }
|
||||||
end
|
let(:params) { {topic_id: post.topic_id, post_number: post.post_number} }
|
||||||
|
|
||||||
context "deleted post" do
|
|
||||||
|
|
||||||
before do
|
|
||||||
post.trash!(user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can't find deleted posts as an anonymous user" do
|
|
||||||
xhr :get, :show, id: post.id
|
|
||||||
response.should be_forbidden
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can't find deleted posts as a regular user" do
|
|
||||||
log_in(:user)
|
|
||||||
xhr :get, :show, id: post.id
|
|
||||||
response.should be_forbidden
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can find posts as a moderator" do
|
|
||||||
log_in(:moderator)
|
|
||||||
xhr :get, :show, id: post.id
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue