Sha256: 7caf9c1b55b27f778b895e3efb603fcc7d864d0e12e8e715d2e2229e1cd391e6

Contents?: true

Size: 991 Bytes

Versions: 6

Compression:

Stored size: 991 Bytes

Contents

require 'spec_helper'

describe Beespew::Model do

  subject { klass.new }

  describe 'honeypot accessor' do
    it { is_expected.to respond_to honeypot }
    it { is_expected.to respond_to "#{honeypot}=" }
  end

  context 'with validations' do
    it 'is valid if honeypot is blank' do
      subject.valid?
      expect(subject.errors[:base]).to be_blank
    end

    it 'is invalid if honeypot is set' do
      fill_honeypot!
      subject.valid?
      expect(subject.errors[:base]).to be_present
    end
  end

  describe '#spam?' do
    it 'returns false if honeypot is blank' do
      expect(subject).not_to be_spam
    end

    it 'returns true if honeypot is blank' do
      fill_honeypot!
      expect(subject).to be_spam
    end
  end

  def klass
    @klass ||= Class.new do
      include ActiveModel::Validations
      include Beespew::Model
    end
  end

  def fill_honeypot!
    subject.send("#{honeypot}=", 'some data')
  end

  def honeypot
    Beespew.attribute
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
beespew-2.1.0 spec/model_spec.rb
beespew-2.0.0 spec/model_spec.rb
beespew-1.0.1 spec/model_spec.rb
beespew-1.0.0 spec/model_spec.rb
beespew-0.2.0 spec/model_spec.rb
beespew-0.1.0 spec/model_spec.rb