Sha256: 2d9160dac58be265b64cea55d779ffc537ae2f239d0cc860263ab7c491a05ac7

Contents?: true

Size: 1.1 KB

Versions: 61

Compression:

Stored size: 1.1 KB

Contents

require './spec/spec_helper'

class PrimaryModel
  include SparkApi::Primary
  attr_accessor :Primary, :id, :attributes
  def initialize(id, prime = false)
    @id = id
    @Primary = prime
    @attributes = {"Primary" => prime }
  end
end

describe SparkApi::PrimaryArray do
  it "should give me the primary element" do
    a = PrimaryModel.new(1)
    b = PrimaryModel.new(2)
    c = PrimaryModel.new(3)
    d = PrimaryModel.new(4, true)
    e = PrimaryModel.new(5)
    tester = subject.class.new([d,e])
    tester.primary.should eq(d)
    tester = subject.class.new([a,b,c,d,e])
    tester.primary.should eq(d)
    # Note, it doesn't care if there is more than one primary, just returns first in the list.
    b.Primary = true
    tester.primary.should eq(b)
  end
  it "should return nil when there is no primary element" do
    a = PrimaryModel.new(1)
    b = PrimaryModel.new(2)
    c = PrimaryModel.new(3)
    d = PrimaryModel.new(4)
    e = PrimaryModel.new(5)
    tester = subject.class.new([])
    tester.primary.should be(nil)
    tester = subject.class.new([a,b,c,d,e])
    tester.primary.should be(nil)
  end
end


Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spark_api-1.4.34 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.32 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.31 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.29 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.28 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.27 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.26 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.25 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.24 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.23 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.22 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.21 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.20 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.19 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.18 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.17 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.16 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.15 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.14 spec/unit/spark_api/primary_array_spec.rb
spark_api-1.4.13 spec/unit/spark_api/primary_array_spec.rb