Sha256: 42becfb6d26bbaa3d1324f7e1ee7a4ef14e2456e89ffc9926b45cb4974562da5

Contents?: true

Size: 1.78 KB

Versions: 14

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'
require 'job_helper'

describe Marty::Promise, slow: true do
  before(:all) do
    @clean_file = "/tmp/clean_#{Process.pid}.psql"
    save_clean_db(@clean_file)
    # transactional fixtures interfere with queueing jobs
    self.use_transactional_tests = false

    # Needed here because shutting transactional fixtures off
    # means we lose the globally set user
    Mcfly.whodunnit = UserHelpers.system_user

    Marty::Script.load_script_bodies(promise_bodies, Date.today)

    start_delayed_job
  end

  before(:each) do
    @time = DateTime.now
    expect(Marty::Promise.count).to eq(0)
    engine = Marty::ScriptSet.new.get_engine(NAME_A)
    engine.background_eval("Y", {"p_title" => NAME_A}, ["d"])
    sleep 5
    Marty::Promise.cleanup
    expect(Marty::Promise.count).to eq(10)
  end

  after(:each) do
    Marty::Promise.where('parent_id IS NULL').destroy_all
    Timecop.return
  end

  after(:all) do
    restore_clean_db(@clean_file)
    stop_delayed_job
  end

  it "should retain jobs that were run less than 4 hours ago" do
    Timecop.freeze(@time + 4.hours)
    Marty::Promise.cleanup
    expect(Marty::Promise.count).to eq(10)
  end

  it "should cleanup jobs that are older than 4 hours" do
    Timecop.freeze(@time + 4.hours + 1.minute)
    Marty::Promise.cleanup
    expect(Marty::Promise.count).to eq(0)
  end

  it "should allow cleanup of all jobs when forced by admin" do
    Timecop.freeze(@time + 4.hours)
    Marty::Promise.cleanup(true)
    expect(Marty::Promise.count).to eq(0)
  end

  it "should provide a live search scope for filtering by user or role" do
    expect(Marty::VwPromise.live_search('XXX').size).to eq(0)
    expect(Marty::VwPromise.live_search('marty').size).to eq(10)
    expect(Marty::VwPromise.live_search('Admin').size).to eq(10)
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
marty-2.4.0 spec/models/promise_spec.rb
marty-2.3.14 spec/models/promise_spec.rb
marty-2.3.13 spec/models/promise_spec.rb
marty-2.3.12 spec/models/promise_spec.rb
marty-2.3.11 spec/models/promise_spec.rb
marty-2.3.10 spec/models/promise_spec.rb
marty-2.3.9 spec/models/promise_spec.rb
marty-2.3.8 spec/models/promise_spec.rb
marty-2.3.7 spec/models/promise_spec.rb
marty-2.3.5 spec/models/promise_spec.rb
marty-2.3.4 spec/models/promise_spec.rb
marty-2.3.2 spec/models/promise_spec.rb
marty-2.3.1 spec/models/promise_spec.rb
marty-2.3.0 spec/models/promise_spec.rb