Sha256: aa9005d3e18f107ae8434bfb46a1d6d7653c1253a4805d42593d7378b91dddf1

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require "spec_helper"

RSpec.describe Assignment, type: :model do
  let(:subject) { FactoryBot.create(:assignment) }

  describe "validations" do
    it { should validate_presence_of(:canvas_id) }
    it { should validate_uniqueness_of(:canvas_id) }
  end

  describe "associations" do
    it do
      should have_many(:submissions)
        .with_primary_key(:canvas_id)
        .with_foreign_key(:canvas_assignment_id)
    end

    it do
      should belong_to(:assignment_group)
        .with_primary_key(:canvas_id)
        .with_foreign_key(:canvas_assignment_group_id)
    end

    it do
      should have_many(:context_module_items)
        .with_primary_key(:canvas_id)
        .with_foreign_key(:canvas_content_id)
        .dependent(:destroy)
    end

    it { should have_many(:context_modules).through(:context_module_items) }

    describe "context" do
      let!(:other_course) { FactoryBot.create(:course) }
      let!(:matching_course) { FactoryBot.create(:course) }

      before do
        subject.update(canvas_context_type: "Course", canvas_context_id: matching_course.canvas_id)
      end

      it "should belong to courses where the canvas_context_type is Course and canvas_context_id is the canvas_course_id" do
        expect(subject.context).to eq(matching_course)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
canvas_sync-0.22.6 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.22.5 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.22.4 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.22.3 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.22.2 spec/canvas_sync/models/assignment_spec.rb