Sha256: 1224958d264241a92bd9758e18b22b695741887e9a7b2261ee6329e696857b84

Contents?: true

Size: 1.65 KB

Versions: 19

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

module Alchemy
  Config.get(:mailer)['fields'].push('email_of_my_boss')
  Config.get(:mailer)['validate_fields'].push('email_of_my_boss')

  describe Message do
    let(:message) { Message.new }

    describe '.config' do
      it "should return the mailer config" do
        expect(Config).to receive(:get).with(:mailer)
        Message.config
      end
    end

    it "has attributes writers and getters for all fields defined in mailer config" do
      Config.get(:mailer)['fields'].each do |field|
        expect(message).to respond_to(field)
        expect(message).to respond_to("#{field}=")
      end
    end

    context "validation of" do
      context "all fields defined in mailer config" do
        it "adds errors on that fields" do
          Config.get(:mailer)['validate_fields'].each do |field|
            expect(message).to_not be_valid
            expect(message.errors[field].size).to eq(1)
          end
        end
      end

      context 'field containing email in its name' do
        context "when field has a value" do
          before { message.email_of_my_boss = 'wrong email format' }

          it "adds error notice (is invalid) to the field" do
            expect(message).to_not be_valid
            expect(message.errors[:email_of_my_boss]).to include("is invalid")
          end
        end

        context "when field is blank" do
          before { message.email_of_my_boss = '' }

          it "adds error notice (can't be blank) to the field" do
            expect(message).to_not be_valid
            expect(message.errors[:email_of_my_boss]).to include("can't be blank")
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
alchemy_cms-3.3.0.rc1 spec/models/alchemy/message_spec.rb
alchemy_cms-3.2.1 spec/models/message_spec.rb
alchemy_cms-3.1.3 spec/models/message_spec.rb
lc_alchemy_cms-3.2.1 spec/models/message_spec.rb
lc_alchemy_cms-3.2.0 spec/models/message_spec.rb
alchemy_cms-3.2.0 spec/models/message_spec.rb
alchemy_cms-3.2.0.rc1 spec/models/message_spec.rb
alchemy_cms-3.2.0.beta spec/models/message_spec.rb
alchemy_cms-3.1.1 spec/models/message_spec.rb
alchemy_cms-3.1.0 spec/models/message_spec.rb
alchemy_cms-3.1.0.rc3 spec/models/message_spec.rb
alchemy_cms-3.1.0.rc2 spec/models/message_spec.rb
alchemy_cms-3.1.0.rc1 spec/models/message_spec.rb
alchemy_cms-3.1.0.beta6 spec/models/message_spec.rb
alchemy_cms-3.1.0.beta5 spec/models/message_spec.rb
alchemy_cms-3.1.0.beta4 spec/models/message_spec.rb
alchemy_cms-3.1.0.beta3 spec/models/message_spec.rb
alchemy_cms-3.1.0.beta2 spec/models/message_spec.rb
alchemy_cms-3.1.0.beta1 spec/models/message_spec.rb