require 'spec_helper'

describe Feedback do

  let(:feedback) { Feedback.new }

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

  describe "empty model" do

    before(:each) do
      feedback.save
    end

    it { feedback.valid?.should be_false }
    it { feedback.errors.keys.length.should == 2}
    it { feedback.errors["email"].length.should == 2}
    it { feedback.errors["email"][0].include?("blank").should be_true}
    it { feedback.errors["email"][1].include?("invalid").should be_true}
    it { feedback.errors["body"].length.should == 1}
    it { feedback.errors["body"][0].include?("blank").should be_true}
    it { CorpMailer.deliveries.length.should == 0}

  end

  describe "bad email" do
    before(:each) do
      feedback.email = "blarg"
      feedback.body = "here's the problem!"
      feedback.save
    end

    it { feedback.valid?.should be_false }
    it { feedback.errors.keys.length.should == 1}
    it { feedback.errors["email"].length.should == 1}
    it { feedback.errors["email"][0].include?("invalid").should be_true}
    it { CorpMailer.deliveries.length.should == 0}
  end

  describe "populated model" do
    before(:each) do
      feedback.email = "seth@jamkazam.com"
      feedback.body = "here's the problem!"
      feedback.save
    end

    it { feedback.valid?.should be_true }
    it { feedback.errors.keys.length.should == 0 }
    it { CorpMailer.deliveries.length.should == 1}
  end
end

