Sha256: c825fd2dcef862945183da275f4872f705acb489757fb28fc7fc80a079bbf286

Contents?: true

Size: 1.3 KB

Versions: 58

Compression:

Stored size: 1.3 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_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) { FactoryGirl.create(:course) }
      let!(:matching_course) { FactoryGirl.create(:course) }

      before do
        subject.update_attributes(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

58 entries across 58 versions & 1 rubygems

Version Path
canvas_sync-0.17.15 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.14 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.13 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.12 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.10.beta2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.10.beta1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.8 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.8.beta4 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.8.beta3 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.8.beta2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.8.beta1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.7 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.7.beta1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.6 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.6.beta1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.5 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.5.beta2 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.5.beta1 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.4 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.17.3.beta3 spec/canvas_sync/models/assignment_spec.rb