From f8237e2ac07dc578a10e397ec0caa693d3a341e2 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sat, 18 Oct 2014 22:32:01 +0530 Subject: [PATCH] add spec for raw_email action --- spec/controllers/posts_controller_spec.rb | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 04690e02390..dd28e3af048 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 }