diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 04690e023..dd28e3af0 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -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 }