Skip to content

Commit

Permalink
WIP: specs + fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Flink committed Mar 14, 2024
1 parent 0ed492b commit 99bc6ef
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@
end
end

describe ".deactivate!" do
subject(:deactivate!) { described_class.deactivate!(topic: topic) }

let!(:assignment1) { Fabricate(:topic_assignment) }
let!(:assignment2) { Fabricate(:post_assignment, topic: topic) }
let!(:assignment3) { Fabricate(:post_assignment) }
let(:topic) { assignment1.topic }

it "deactivates each assignment of the provided topic" do
deactivate!
expect([assignment1, assignment2].map(&:reload).map(&:active?)).to all eq false
expect(assignment3.reload).to be_active
end
end

describe ".reactivate!" do
subject(:reactivate!) { described_class.reactivate!(topic: topic) }

let!(:assignment1) { Fabricate(:topic_assignment, active: false) }
let!(:assignment2) { Fabricate(:post_assignment, topic: topic, active: false) }
let!(:assignment3) { Fabricate(:post_assignment, active: false) }
let(:topic) { assignment1.topic }

it "reactivates each assignment of the provided topic" do
reactivate!
expect([assignment1, assignment2].map(&:reload)).to all be_active
expect(assignment3.reload).not_to be_active
end
end

describe "#assigned_users" do
subject(:assigned_users) { assignment.assigned_users }

Expand Down Expand Up @@ -190,8 +220,8 @@
end

it "enqueues a job to create notifications" do
Jobs.expects(:enqueue).with(:assign_notification, assignment_id: assignment.id)
reactivate!
expect_job_enqueued(job: Jobs::AssignNotification, args: { assignment_id: assignment.id })
end
end
end
Expand All @@ -206,14 +236,16 @@
end

it "enqueues a job to delete notifications" do
Jobs.expects(:enqueue).with(
:unassign_notification,
topic_id: assignment.topic_id,
assigned_to_id: assignment.assigned_to_id,
assigned_to_type: assignment.assigned_to_type,
assignment_id: assignment.id,
)
deactivate!
expect_job_enqueued(
job: Jobs::UnassignNotification,
args: {
topic_id: assignment.topic_id,
assigned_to_id: assignment.assigned_to_id,
assigned_to_type: assignment.assigned_to_type,
assignment_id: assignment.id,
},
)
end
end
end

0 comments on commit 99bc6ef

Please sign in to comment.