spec/models/naf/running_job_spec.rb in naf-1.1.4 vs spec/models/naf/running_job_spec.rb in naf-2.0.0
- old
+ new
@@ -14,11 +14,12 @@
:started_on_machine_id,
:pid,
:request_to_terminate,
:marked_dead_by_machine_id,
:log_level,
- :started_at].each do |a|
+ :started_at,
+ :tags].each do |a|
it { should allow_mass_assignment_of(a) }
end
[:id,
:created_at,
@@ -59,10 +60,26 @@
::Naf::RunningJob.should_receive(:where).and_return([running_job])
::Naf::RunningJob.started_on(machine).should == [running_job]
end
end
+ describe "#started_on_invocation" do
+ let!(:invocation) { FactoryGirl.create(:machine_runner_invocation) }
+ before do
+ running_job.historical_job.machine_runner_invocation = invocation
+ running_job.historical_job.save!
+ end
+
+ it "return the correct job record" do
+ ::Naf::RunningJob.started_on_invocation(invocation.id).should == [running_job]
+ end
+
+ it "return nothing when no running jobs are associated invocation" do
+ ::Naf::RunningJob.started_on_invocation(invocation.id + 1).should == []
+ end
+ end
+
describe "#in_run_group" do
it "return the correct job record" do
::Naf::RunningJob.should_receive(:where).and_return([running_job])
::Naf::RunningJob.in_run_group('test').should == [running_job]
end
@@ -100,8 +117,54 @@
4 => 1.0,
5 => 1.0 }
end
end
+ #-------------------------
+ # *** Instance Methods ***
+ #+++++++++++++++++++++++++
+
+ describe "#add_tags" do
+ before do
+ running_job.tags = "{$pre-work}"
+ end
+
+ it "insert unique tag" do
+ running_job.add_tags([::Naf::HistoricalJob::SYSTEM_TAGS[:work]])
+ running_job.tags.should == "{$pre-work,$work}"
+ end
+
+ it "not insert non-unique tag" do
+ running_job.add_tags([::Naf::HistoricalJob::SYSTEM_TAGS[:pre_work]])
+ running_job.tags.should == "{$pre-work}"
+ end
+ end
+
+ describe "#remove_tags" do
+ before do
+ running_job.tags = "{$pre-work}"
+ end
+
+ it "remove existing tag" do
+ running_job.remove_tags([::Naf::HistoricalJob::SYSTEM_TAGS[:pre_work]])
+ running_job.tags.should == "{}"
+ end
+
+ it "not update tags when removing non-existing tag" do
+ running_job.remove_tags([::Naf::HistoricalJob::SYSTEM_TAGS[:work]])
+ running_job.tags.should == "{$pre-work}"
+ end
+ end
+
+ describe "#remove_all_tags" do
+ before do
+ running_job.tags = "{$pre-work}"
+ end
+
+ it "remove any existing tags" do
+ running_job.remove_all_tags
+ running_job.tags.should == "{}"
+ end
+ end
end
end