Sha256: fcab7d753be2e1cdb1cc28851394b5d9ee50dbee25d4fe6f1d68fd5b6e86c940

Contents?: true

Size: 1.33 KB

Versions: 26

Compression:

Stored size: 1.33 KB

Contents

require "spec_helper"

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

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

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

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

    it do
      should have_many(:context_module_items)
        .with_primary_key(:canvas_assignment_id)
        .with_foreign_key(:content_id)
        .dependent(:destroy)
    end

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

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

      before do
        subject.update_attributes(context_type: "Course", context_id: matching_course.canvas_course_id)
      end

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
canvas_sync-0.9.4 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.9.3 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.9.2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.9.1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.9.0 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.8.4 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.8.3 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.8.2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.8.1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.8.0 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.7.3 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.7.2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.7.1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.7.0 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.6.4 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.6.3 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.6.2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.6.1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.6.0 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.5.4 spec/canvas_sync/models/assignment_spec.rb