File: merge_spec.rb

package info (click to toggle)
ruby-virtus 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: ruby: 4,378; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 996 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'spec_helper'

describe Virtus::AttributeSet, '#merge' do
  subject { object.merge(other) }

  let(:parent) { described_class.new }
  let(:object) { described_class.new(parent, attributes) }
  let(:name)   { :name }
  let(:other)  { [attribute] }

  context 'with a new attribute' do
    let(:attributes) { [] }
    let(:attribute)  { Virtus::Attribute.build(String, :name => name) }

    it { is_expected.to equal(object) }

    it 'adds an attribute' do
      expect { subject }.to change { object.to_a }.from(attributes).to([attribute])
    end
  end

  context 'with a duplicate attribute' do
    let(:attributes) { [Virtus::Attribute.build(String, :name => name)] }
    let(:attribute)  {  Virtus::Attribute.build(String, :name => name) }

    it { is_expected.to equal(object) }

    it "replaces the original attribute object" do
      expect { subject }.to change { object.to_a.map(&:__id__) }.
      from(attributes.map(&:__id__)).
      to([attribute.__id__])
    end
  end
end