Sha256: f24d9007e10235054bf698083e3c6f2414ce1dcb5112a97769694ff87757b087

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'rails_helper'

# Dummy class to test class methods
class Something < ActiveRecord::Base
  include HasVcards::Concerns::HasVcards
end

describe HasVcards::Concerns::HasVcards do
  context 'a new instance of Something' do
    let(:something) { Something.new }

    it 'has a vcards association' do
      expect(something.vcards.build).to be_a HasVcards::Vcard
    end

    it 'has a vcard association' do
      expect(something.build_vcard).to be_a HasVcards::Vcard
    end

    it 'has a vcard autobuilt' do
      expect(something.vcard).to be_a HasVcards::Vcard
    end

    it 'delegates attribute accessors to the main vcard' do
      attributes = [ :full_name, :nickname, :family_name, :given_name, :additional_name, :honorific_prefix, :honorific_suffix ]

      attributes.each do |attr|
        expect(something.vcard).to receive(attr)
        something.vcard.send(attr)

        expect(something.vcard).to receive("#{attr}=")
        something.vcard.send("#{attr}=", 'foo')
      end
    end
  end

  it 'accepts nested attributes for vcard' do
    vcard_attributes = { full_name: 'Full' }

    something = Something.create(vcard_attributes: vcard_attributes)
    expect(something.vcard.full_name).to eq 'Full'
  end

  it 'accepts nested attributes for vcards' do
    vcards_attributes = { '' => { full_name: 'Full' } }

    something = Something.create(vcards_attributes: vcards_attributes)
    expect(something.vcards[0].full_name).to eq 'Full'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
has_vcards-1.1.2 spec/models/has_vcards/concerns/has_vcards_spec.rb
has_vcards-1.1.1 spec/models/has_vcards/concerns/has_vcards_spec.rb
has_vcards-1.1.0 spec/models/has_vcards/concerns/has_vcards_spec.rb
has_vcards-1.0.0 spec/models/has_vcards/concerns/has_vcards_spec.rb
has_vcards-1.0.0.rc0 spec/models/has_vcards/concerns/has_vcards_spec.rb