Sha256: ca25386686a58fc973ea3c604f9d039f8856249d28e9cc915babdcaca1ccb339

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 KB

Contents

require 'rspec'
$:.unshift File.expand_path('../../', __FILE__)
require 'active_mocker/collection_association'
require 'ostruct'

describe ActiveMocker::CollectionAssociation do

  subject{described_class.new}

  describe '#sum' do


    it 'sum values by attribute name' do

      subject << [OpenStruct.new(value: 1), OpenStruct.new(value: 1)]

      expect(subject.sum(:value)).to eq 2

    end

  end

  describe '#<<' do

    it 'will add a single item to the array' do

      subject << "item"

      expect(subject.count).to eq 1
      expect(subject.first).to eq 'item'

    end

    it 'will add a many item to the array' do

      subject << ['item1', 'item2', 'item3']

      expect(subject.count).to eq 3
      expect(subject).to eq ['item1', 'item2', 'item3']

    end

  end

  describe 'new' do

    it 'take optional item and adds to collection' do

      subject = described_class.new(1)

      expect(subject.first).to eq 1

    end

    it 'can take an array' do

      subject = described_class.new([1])

      expect(subject.first).to eq 1

      subject = described_class.new([1,2])

      expect(subject.last).to eq 2

    end

  end

  describe 'empty?' do

    it 'works' do

      expect(subject.empty?).to eq true

    end


  end


end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_mocker-1.2 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.11 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.10 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.9 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.8 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.7 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.6 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.5 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.4 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.3 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.2 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre.1 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.2.pre spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.1.23 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.1.22 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.1.21 spec/lib/active_mocker/collection_association_spec.rb
active_mocker-1.1.20 spec/lib/active_mocker/collection_association_spec.rb