require 'spec_helper'

describe QueuesController, :type => :controller do
  before do
    # TODO shouldn't this use the actual output of the json rendering?
    repository = { 'id' => 8, 'slug' => 'svenfuchs/gem-release' }
    build_3    = { 'id' => 1, 'number' => '3',   'commit' => 'b0a1b69', 'config' => {} }
    build_31   = { 'id' => 2, 'number' => '3.1', 'commit' => 'b0a1b69', 'config' => {} }
  end

  subject do
    get :index, :format => :json
    ActiveSupport::JSON.decode(response.body)
  end

  it 'index lists all jobs on the queue' do
    pending
    should == [
      { 'id' => 1, 'number' => '3',   'commit' => 'b0a1b69', 'repository' => { 'id' => 8, 'slug' => 'svenfuchs/gem-release' } },
      { 'id' => 2, 'number' => '3.1', 'commit' => 'b0a1b69', 'repository' => { 'id' => 8, 'slug' => 'svenfuchs/gem-release' } },
    ]
  end
end

require 'spec_helper'

describe QueuesController, :type => :controller do
  let(:jobs) { [Factory.create(:test, :number => '3'), Factory.create(:test, :number => '3.1') ] }

  it 'index lists all jobs on the queue' do
    get :index, :format => :json

    json = ActiveSupport::JSON.decode(response.body)
    json.should include({ 'id' => jobs.first.id,  'number' => '3',   'commit' => '62aae5f70ceee39123ef', 'repository' => { 'id' => jobs.first.repository.id,  'slug' => 'svenfuchs/repository-1' } })
    json.should include({ 'id' => jobs.second.id, 'number' => '3.1', 'commit' => '62aae5f70ceee39123ef', 'repository' => { 'id' => jobs.second.repository.id, 'slug' => 'svenfuchs/repository-2' } })
  end
end

Use state :created instead of :started for selecting queued jobs
Use state :created instead of :started for selecting queued jobs
