spec/models/naf/application_schedule_spec.rb in naf-2.0.4 vs spec/models/naf/application_schedule_spec.rb in naf-2.1.0

- old
+ new

@@ -10,14 +10,14 @@ :application_run_group_name, :run_interval, :priority, :visible, :enabled, - :run_start_minute, :application_run_group_limit, :application_schedule_prerequisites_attributes, - :enqueue_backlogs].each do |a| + :enqueue_backlogs, + :run_interval_style_id].each do |a| it { should allow_mass_assignment_of(a) } end [:id, :created_at, @@ -29,10 +29,11 @@ # *** Associations *** #+++++++++++++++++++++ it { should belong_to(:application) } it { should belong_to(:application_run_group_restriction) } + it { should belong_to(:run_interval_style) } it { should have_many(:application_schedule_affinity_tabs) } it { should have_many(:affinities) } it { should have_many(:application_schedule_prerequisites) } it { should have_many(:prerequisites) } @@ -69,32 +70,54 @@ #---------------------- # *** Class Methods *** #++++++++++++++++++++++ + let!(:time) { Time.zone.now.beginning_of_day } + describe "#exact_schedules" do - it "return schedule when run_start_minute is set" do - schedule.update_attributes!(run_start_minute: 1, run_interval: nil) - ::Naf::ApplicationSchedule.exact_schedules.should == [schedule] + let!(:job) { FactoryGirl.create(:finished_job) } + it "return schedule when it is ready" do + ::Naf::ApplicationSchedule.exact_schedules(time, {}, {}).should == [schedule] end - it "return no schedules when run_start_minute is not set" do - schedule.update_attributes!(run_start_minute: nil, run_interval: nil) - ::Naf::ApplicationSchedule.exact_schedules.should == [] + it "return no schedules when application has not finished running" do + apps = { schedule.id => job } + ::Naf::ApplicationSchedule.exact_schedules(time, apps, {}).should == [] end + + it "return no schedules when interval time has not passed" do + apps = { schedule.id => job } + schedule.run_interval = 20 + ::Naf::ApplicationSchedule.exact_schedules(time, {}, apps).should == [] + end + + it "return no schedules when it is not time to run the application" do + time = Time.zone.now + ::Naf::ApplicationSchedule.exact_schedules(time, {}, {}).should == [] + end end describe "#relative_schedules" do - it "return schedule when run_interval is set" do - schedule.update_attributes!(run_interval: 60) - ::Naf::ApplicationSchedule.relative_schedules.should == [schedule] + let!(:job) { FactoryGirl.create(:finished_job) } + it "return schedule when it is ready" do + schedule.run_interval_style.name = 'after previous run' + schedule.run_interval_style.save + + ::Naf::ApplicationSchedule.relative_schedules(time, {}, {}).should == [schedule] end - it "return no schedules when run_interval is not set" do - schedule.update_attributes!(run_interval: nil) - ::Naf::ApplicationSchedule.relative_schedules.should == [] + it "return no schedules when application has not finished running" do + apps = { schedule.application_id => job } + ::Naf::ApplicationSchedule.relative_schedules(time, apps, {}).should == [] end + + it "return no schedules when interval time has not passed" do + apps = { schedule.application_id => job } + schedule.run_interval = 20 + ::Naf::ApplicationSchedule.relative_schedules(time, {}, apps).should == [] + end end #------------------------- # *** Instance Methods *** #+++++++++++++++++++++++++ @@ -105,11 +128,11 @@ schedule.save! end it "return correct parsing of app" do schedule.to_s.should == "::Naf::ApplicationSchedule<ENABLED, id: #{schedule.id}, " + - "\"App1\", start every: 1 minutes>" + "\"App1\", #{::Logical::Naf::ApplicationSchedule.new(schedule).display}>" end end describe "#visible_enabled_check" do let(:error_messages) { { @@ -118,44 +141,9 @@ } } before do schedule.visible = false schedule.visible_enabled_check - end - - it "add errors to schedule" do - schedule.errors.messages.should == error_messages - end - end - - describe "#enabled_application_id_unique" do - let(:error_message) { { - application_id: ['is enabled and has already been taken'] - } } - - it "return nil if enabled is false" do - schedule.enabled = false - schedule.enabled_application_id_unique.should == nil - end - - it "return nil if enabled is false" do - schedule2 = FactoryGirl.create(:schedule) - schedule2.application_id = schedule.application_id - schedule2.enabled_application_id_unique - - schedule2.errors.messages.should == error_message - end - end - - describe "#run_interval_at_time_check" do - let(:error_messages) { { - run_interval: ['or Run start minute must be nil'], - run_start_minute: ['or Run interval must be nil'] - } } - - before do - schedule.run_start_minute = 1 - schedule.run_interval_at_time_check end it "add errors to schedule" do schedule.errors.messages.should == error_messages end