Domanda

My code.. :

after_save :handle_test

private

def handle_test
  if parent.try(:is_test)
    Resque.enqueue UnpackTestOnS3, parent.id
  end
end

I'm trying to strategize the best way to test this Model logic.

Do I test that Resque received something? Do I test that parent.try(:is_test) is true? If so, it would be kind of silly because in the test itself I would have to stub that or update_attribute.. Is this too granular to test at all? Should I, instead just be testing that a file appears on S3? I'm not sure that would make sense for a unit test to actually upload something to S3.

All strategies warmly welcomed.

È stato utile?

Soluzione

You can just test the fact that there is a job queued for unpacking when you create or update your model

it "should enqueue job to unpack test on s3 on creating <model_name>" do
  Resque.should_receive(:enqueue).with(UnpackTestOnS3, <parent_id>)
end

it "should enqueue job to unpack test on s3 on updating <model_name>" do
  Resque.should_receive(:enqueue).with(UnpackTestOnS3, <parent_id>)
end

it "should not enqueue job to unpack test on s3 when the <model_name>'s parent is not for test" do
  Resque.should_not_receive(:enqueue).with(UnpackTestOnS3, <parent_id>)
end
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top