add spec for raw_email action

This commit is contained in:
Arpit Jalan 2014-10-18 22:32:01 +05:30
parent 72873b8368
commit f8237e2ac0

View file

@ -68,6 +68,36 @@ describe PostsController do
end
end
describe 'raw_email' do
include_examples "action requires login", :get, :raw_email, id: 2
describe "when logged in" do
let(:user) {log_in}
let(:post) {Fabricate(:post, user: user, raw_email: 'email_content')}
it "raises an error if the user doesn't have permission to view raw email" do
Guardian.any_instance.expects(:can_view_raw_email?).returns(false)
xhr :get, :raw_email, id: post.id
response.should be_forbidden
end
it "can view raw email" do
Guardian.any_instance.expects(:can_view_raw_email?).returns(true)
xhr :get, :raw_email, id: post.id
response.should be_success
json = ::JSON.parse(response.body)
json.should be_present
json['raw_email'].should == 'email_content'
end
end
end
describe 'show' do
include_examples 'finding and showing post' do
let(:action) { :show }