Sha256: 16493a25b37f104259627ad0c84cf51aa3bedd2648117ec11af4c89a4fe8c13b

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

require "spec_helper"

describe Architect4r::Model::Relationship do
  
  let(:person) { Person.create(:name => 'Niobe', :human => true) }
  let(:ship) { Ship.create(:name => 'Logos', :crew_size => 2) }
  
  describe "initialization of new instances" do
    
    it "should accept zero arguments" do
      lambda { CrewMembership.new }.should_not raise_error(ArgumentError)
    end
    
    it "should accept just a hash of properties" do
      ms = CrewMembership.new( :rank => 'Captain' )
      ms.rank.should == 'Captain'
    end
    
    it "should accept the source and destination node" do
      ms = CrewMembership.new(ship, person)
      ms.source.should == ship
      ms.destination.should == person
    end
    
    it "should accept the source node, destination node, and properties" do
      ms = CrewMembership.new(ship, person, { :rank => 'Captain' })
      ms.source.should == ship
      ms.destination.should == person
      ms.rank.should == 'Captain'
    end
    
    it "should always require a source and destination" do
      fs = CrewMembership.new(:member_since => DateTime.new, :rank => 'Captain')
      fs.valid?.should be_false
    end
    
  end
  
  describe "Creating a new relationship" do
    
    it "should create a new relationship" do
      ms = CrewMembership.new(ship, person)
      ms.save.should be_true
      ms.persisted?.should be_true
    end
    
    it "should allow changing relationship properties" do
      ms = CrewMembership.new(ship, person, { :rank => 'Captain' })
      ms.save.should be_true
      
      ms.rank = 'Operator'
      ms.save.should be_true
    end
    
    it "should allow deleting relationships" do
      ms = CrewMembership.new(ship, person, { :rank => 'Captain' })
      ms.save.should be_true
      ms.destroy.should be_true
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
architect4r-0.3.4 spec/model/relationship_spec.rb
architect4r-0.3.3.1 spec/model/relationship_spec.rb
architect4r-0.3.2 spec/model/relationship_spec.rb