Sha256: acfc36a55f936b7c0721668119dee654e4907f5df8e7c4fb221f25a3e91f57a1

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

module Pose
  describe Assignment do

    describe :delete_class_index do

      before :each do
        create :assignment, posable_id: 1, posable_type: 'PosableOne'
        create :assignment, posable_id: 2, posable_type: 'PosableTwo'
        Assignment.delete_class_index PosableOne
      end

      it "deletes all Assignments for the given class" do
        expect(Assignment.where(posable_type: 'PosableOne')).to have(0).items
      end

      it "doesn't delete Assignments for other classes" do
        expect(Assignment.where(posable_type: 'PosableTwo')).to have(1).items
      end
    end


    describe :cleanup_orphaned_pose_assignments do

      it "deletes the assignment if the posable object doesn't exist" do
        create :assignment, posable_id: 2, posable_type: 'PosableOne'
        expect(Assignment.count).to be > 0
        Assignment.cleanup_orphaned_pose_assignments
        expect(Assignment.count).to eql 0
      end

      it "deletes the assignment if the word doesn't exist" do
        assignment = create :assignment, word: nil, word_id: 27
        Assignment.cleanup_orphaned_pose_assignments
        expect(Assignment.find_by_id(assignment.id)).to be_nil
      end

      it "doesn't delete the assignment if it is still used" do
        assignment = create :assignment
        Assignment.cleanup_orphaned_pose_assignments
        expect(Assignment.find_by_id(assignment.id)).to_not be_nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pose-3.2.0 spec/lib/pose/assignment_spec.rb
pose-3.1.1 spec/lib/pose/assignment_spec.rb