require 'rails_helper'

RSpec.describe ScheduledTask, type: :model do

  context "#process!" do

    context "when the action is publish" do
      let(:executable_task) { create(:executable_task, action: :publish) }

      it "activates the schedulable" do
        executable_task.process!
        expect(executable_task.schedulable.active).to eq true
        expect(executable_task.status).to eq "successful"
      end
    end

    context "when the action is unpublish" do
      let(:executable_task) { create(:executable_task, action: :unpublish) }

      it "deactivates the schedulable" do
        executable_task.schedulable.update(active: true)
        executable_task.process!
        expect(executable_task.schedulable.active).to eq false
        expect(executable_task.status).to eq "successful"
      end
    end

  end
end
