<commit_before>require 'spec_helper'

describe Base::Email do
  describe "validations" do
    before do
      temporary_mailer :TestMailer do
        const_set(:Greeting, Class.new(Base::Email)).class_eval do
          attr_accessible :name
          validates_presence_of :name
        end
      end
    end

    it "should work like ActiveRecord" do
      model = TestMailer.new_email(:greeting, :name => '')
      model.should_not be_valid
      model.errors.on(:name).should_not be_nil
    end

    it "should prevent the email being sent if the email does not validate" do
      model = TestMailer.new_email(:greeting, :name => '')
      model.deliver.should be_false
      model.errors.on(:name).should_not be_nil
      ActionMailer::Base.deliveries.should be_empty
    end
  end

  describe "#before_delivery" do
    before do
      temporary_mailer :TestMailer do
        const_set(:Greeting, Class.new(Base::Email)).class_eval do
          attr_accessor :num_deliveries
          before_delivery :set_num_deliveries
          def set_num_deliveries
            self.num_deliveries = ActionMailer::Base.deliveries.size
          end
        end
      end
      make_template TestMailer, :greeting, ''
      @email = TestMailer.new_email(:greeting, {})
    end

    it "should fire just before calling #deliver" do
      @email.deliver.should be_true
      @email.num_deliveries.should == 0
    end

    it "should not be called if validation fails" do
      @email.stubs(:valid?).returns(false)
      @email.deliver.should be_false
      @email.num_deliveries.should be_nil
    end
  end

  describe "#after_delivery" do
    before do
      temporary_mailer :TestMailer do
        const_set(:Greeting, Class.new(Base::Email)).class_eval do
          attr_accessor :num_deliveries
          after_delivery :set_num_deliveries
          def set_num_deliveries
            self.num_deliveries = ActionMailer::Base.deliveries.size
          end
        end
      end
      make_template TestMailer, :greeting, ''
      @email = TestMailer.new_email(:greeting, {})
    end<commit_msg>Rename some example groups.<commit_after>require 'spec_helper'

describe Base::Email do
  describe "validations" do
    before do
      temporary_mailer :TestMailer do
        const_set(:Greeting, Class.new(Base::Email)).class_eval do
          attr_accessible :name
          validates_presence_of :name
        end
      end
    end

    it "should work like ActiveRecord" do
      model = TestMailer.new_email(:greeting, :name => '')
      model.should_not be_valid
      model.errors.on(:name).should_not be_nil
    end

    it "should prevent the email being sent if the email does not validate" do
      model = TestMailer.new_email(:greeting, :name => '')
      model.deliver.should be_false
      model.errors.on(:name).should_not be_nil
      ActionMailer::Base.deliveries.should be_empty
    end
  end

  describe "before_delivery callback" do
    before do
      temporary_mailer :TestMailer do
        const_set(:Greeting, Class.new(Base::Email)).class_eval do
          attr_accessor :num_deliveries
          before_delivery :set_num_deliveries
          def set_num_deliveries
            self.num_deliveries = ActionMailer::Base.deliveries.size
          end
        end
      end
      make_template TestMailer, :greeting, ''
      @email = TestMailer.new_email(:greeting, {})
    end

    it "should fire just before calling #deliver" do
      @email.deliver.should be_true
      @email.num_deliveries.should == 0
    end

    it "should not be called if validation fails" do
      @email.stubs(:valid?).returns(false)
      @email.deliver.should be_false
      @email.num_deliveries.should be_nil
    end
  end

  describe "after_delivery callback" do
    before do
      temporary_mailer :TestMailer do
        const_set(:Greeting, Class.new(Base::Email)).class_eval do
          attr_accessor :num_deliveries
          after_delivery :set_num_deliveries
          def set_num_deliveries
            self.num_deliveries = ActionMailer::Base.deliveries.size
          end
        end
      end
      make_template TestMailer, :greeting, ''
      @email = TestMailer.new_email(:greeting, {})
    end
{'fraction_non_alphanumeric': 0.07921027592768792, 'fraction_numerical': 0.0004757373929590866, 'mean_word_length': 2.634399308556612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2230410', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1298, 'n_words': 298}