Sha256: 0bdc4811c6c558429bef6cd809e1244fa3cc98dd557bf261debf81fab5d14bbb

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe "Cistern::Collection" do
  class SampleCollectionModel < Cistern::Model
    identity :id
    attribute :name
  end
  class SampleCollection < Cistern::Collection
    model SampleCollectionModel

    def all
      self.load([{id: 1}, {id: 3, name: "tom"}, {id: 2}])
    end
  end

  it "should give to_s" do
    collection = SampleCollection.new
    collection.to_s.should_not eq "[]"
    collection.to_s.gsub(/:[^>]*/,'').should == collection.all.to_s.gsub(/:[^>]*/,'')
  end

  it "should give size and count" do
    SampleCollection.new.size.should == 3
    SampleCollection.new.count.should == 3
  end

  it "should give first" do
    SampleCollection.new.first.should == SampleCollectionModel.new(id: 1)
  end

  it "should give last" do
    SampleCollection.new.last.should == SampleCollectionModel.new(id: 2)
  end

  it "should reject" do
    SampleCollection.new.reject{|m| m.id == 2}.should == [SampleCollectionModel.new(id: 1), SampleCollectionModel.new(id: 3)]
  end

  it "should select" do
    SampleCollection.new.select{|m| m.id == 2}.should == [SampleCollectionModel.new(id: 2)]
  end

  it "should slice" do
    SampleCollection.new.slice(0,2).should == [SampleCollectionModel.new(id: 1), SampleCollectionModel.new(id: 3, name: "tom")]
  end

  it "should ==" do
    SampleCollection.new.all == SampleCollection.new.all
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cistern-0.6.0 spec/collection_spec.rb
cistern-0.5.10 spec/collection_spec.rb
cistern-0.5.9 spec/collection_spec.rb
cistern-0.5.8 spec/collection_spec.rb
cistern-0.5.7 spec/collection_spec.rb
cistern-0.5.6 spec/collection_spec.rb
cistern-0.5.4 spec/collection_spec.rb
cistern-0.3.2 spec/collection_spec.rb
cistern-0.3.1 spec/collection_spec.rb
cistern-0.3.0 spec/collection_spec.rb
cistern-0.2.3 spec/collection_spec.rb