require 'rubygems'
require 'require_relative' if RUBY_VERSION < '1.9'
require 'minitest/autorun'
require_relative './common.rb'

describe CIMI::Collections::Volumes do

  before do
    def app; run_frontend(:cimi) end
    authorize 'mockuser', 'mockpassword'
    @collection = CIMI::Collections.collection(:volumes)
  end

  def make_volume_create
    get '/cimi/volume_configurations'
    conf_id = model.entries.first.id
    vt = CIMI::Model::VolumeTemplate.new
    vt.volume_config.href = conf_id
    CIMI::Model::VolumeCreate.new(:name => "new_cimi_volume_#{Time.now.to_i}",
         :volume_template => vt)
  end

  it 'allows creation of a new volume' do
    vc = make_volume_create
    post '/cimi/volumes', vc.to_json,
      "CONTENT_TYPE" => "application/json"
    last_response.status.must_equal 201
    model.name.must_equal vc.name
  end
end
