Sha256: c8ce74a38694b191b2455bde17492b2fd1a63876c40d25fc398b1aabd83d6399

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe PoseAssignment do

  before :each do
    PoseAssignment.delete_all
  end
  
  describe "delete_class_index" do
    
    before :each do
      FactoryGirl.create :pose_assignment, posable_id: 1, posable_type: 'PosableOne'
      FactoryGirl.create :pose_assignment, posable_id: 2, posable_type: 'PosableTwo'
      PoseAssignment.delete_class_index PosableOne
    end
    
    it "deletes all PoseAssignments for the given class" do
      PoseAssignment.where(posable_type: 'PosableOne').should have(0).items
    end
    
    it "doesn't delete PoseAssignments for other classes" do
      PoseAssignment.where(posable_type: 'PosableTwo').should have(1).items
    end
  end
    
  describe "cleanup_orphaned_pose_assignments" do
    
    it "deletes the assignment if the posable object doesn't exist" do
      FactoryGirl.create :pose_assignment, posable_id: 2, posable_type: 'PosableOne'
      PoseAssignment.count.should > 0
      PoseAssignment.cleanup_orphaned_pose_assignments
      PoseAssignment.should have(0).items
    end
    
    it "deletes the assignment if the pose_word doesn't exist" do
      assignment = FactoryGirl.create :pose_assignment, pose_word: nil, pose_word_id: 27
      PoseAssignment.cleanup_orphaned_pose_assignments
      PoseAssignment.find_by_id(assignment.id).should be_nil
    end
    
    it "doesn't delete the assignment if it is still used" do
      assignment = FactoryGirl.create :pose_assignment
      PoseAssignment.cleanup_orphaned_pose_assignments
      PoseAssignment.find_by_id(assignment.id).should_not be_nil
    end
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pose-1.2.0 spec/pose_assignment_spec.rb
pose-1.1.3 spec/pose_assignment_spec.rb
pose-1.1.2 spec/pose_assignment_spec.rb
pose-1.1.1 spec/pose_assignment_spec.rb