Sha256: 9d822fa1dd95dc4a49cd0b63159439ea469bb5def10764d6e855a992f17cc56d

Contents?: true

Size: 1.82 KB

Versions: 56

Compression:

Stored size: 1.82 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_fixtures = 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.unscoped.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.unscoped.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.unscoped.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.unscoped.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.unscoped.count).to eq(0)
  end

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

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
marty-1.0.30 spec/models/promise_spec.rb
marty-1.0.29 spec/models/promise_spec.rb
marty-1.0.28 spec/models/promise_spec.rb
marty-1.0.27 spec/models/promise_spec.rb
marty-1.0.26 spec/models/promise_spec.rb
marty-1.0.25 spec/models/promise_spec.rb
marty-1.0.24 spec/models/promise_spec.rb
marty-1.0.23 spec/models/promise_spec.rb
marty-1.0.22 spec/models/promise_spec.rb
marty-1.0.20 spec/models/promise_spec.rb
marty-1.0.19 spec/models/promise_spec.rb
marty-1.0.18 spec/models/promise_spec.rb
marty-1.0.17 spec/models/promise_spec.rb
marty-1.0.15 spec/models/promise_spec.rb
marty-1.0.14 spec/models/promise_spec.rb
marty-1.0.13 spec/models/promise_spec.rb