require "spec_helper"

describe NewsMailer do
include Rails.application.routes.url_helpers
  pending "add some examples to (or delete) #{__FILE__}"
  describe 'neuigkeit_mail'  do 
    before(:each) do
     
      rubrik = FactoryGirl.create(:rubrik)
      @neuigkeit=FactoryGirl.create(:neuigkeit, author_id: user.id, rubrik_id: rubrik.id)
      NewsMailer.stub(:default_url_options).and_return({host:"localhost", port: 3000})
    end
    let(:user) {User.first || FactoryGirl.create(:user)}
    let(:email) {"test@mail.com"}
    let(:neuigkeit) {@neuigkeit}
    
    let(:mail) {NewsMailer.neuigkeit_mail(email.to_s, neuigkeit.id)}
    it "renders neuigkeit title" do 
      expect(mail.body.to_s).to match(/#{@neuigkeit.title}/)
    end
    it "renders neuigkeit expect" do 
      expect(mail.body.to_s).to match(/#{@neuigkeit.text}/)
    end
    it "is sent to current user" do 
      expect(mail.to).to eq([user.email])
    end
    it "links to web page" do 
      expect(mail.body.to_s).to match(/#{neuigkeit_url(@neuigkeit, locale: nil, theme: nil, host:"localhost", port: 3000)}/)

    end

  end
end
