Sha256: bece9e5a293c3b7432dffc7c5b20d9aa9ecfb01baf4bcc922f2535863252e2c8

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 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

    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

8 entries across 8 versions & 1 rubygems

Version Path
canvas_sync-0.3.22 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.21 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.20 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.19 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.18 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.17 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.16 spec/canvas_sync/models/assignment_spec.rb
canvas_sync-0.3.15 spec/canvas_sync/models/assignment_spec.rb