require 'spec_helper'

describe JamTrackHfaRequest do
  include CarrierWave::Test::Matchers
  include UsesTempFiles

  let(:jamtrack1) {FactoryGirl.create(:jam_track, duration: 90, server_fixation_date: Time.now.to_date ) }

  it "creates request" do


    JamTrackHfaRequest.find_max().should eq(0)
    jamtrack1.touch
    JamTrackHfaRequest.create('request1')

    request = JamTrackHfaRequest.first
    request.request_csv_filename.should_not be_nil
    request.approved_at.should be_nil
    request.received_at.should be_nil

    request_id = JamTrackHfaRequestId.first
    request_id.request_id.should_not be_nil

    # as long as the previous request is not approved, we don't move on with the counter
    JamTrackHfaRequest.find_max().should eq(0)

    request.received_at = Time.now
    request.save!

    # but once it's approved, we move on
    JamTrackHfaRequest.find_max().should eq(1)
  end
end

