require 'spec_helper'

describe ApiCorporateController do
  render_views


  before(:each) do
    CorpMailer.deliveries.clear
  end

  describe "success" do
    it "should work" do
      post :feedback, :email => "seth@jamkazam.com", :body => "Hey could someone help me?"
      response.should be_success
      CorpMailer.deliveries.length.should == 1

    end
  end

  describe "fail" do
    it "should fail due to bad email" do
      post :feedback, :email => "seth", :body => "Hey could someone help me?"
      response.status.should == 422
      CorpMailer.deliveries.length.should == 0
      error = JSON.parse(response.body)
      error["errors"]["email"].should_not be_nil
      error["errors"]["email"][0].include?("invalid").should be_true
    end
  end
  
end
