require 'spec_helper'

describe "Artifact Update" do

  include UsesTempFiles
  ARTIFACT_FILE='jkclient-0.1.1.exe'

  subject { page }

  let(:user) { FactoryGirl.create(:admin) }
  before { sign_in user }

  describe "crud" do
    before { visit admin_jam_ruby_artifact_updates_path }
    it { should have_selector('h2', text: "Jam Ruby Artifact Updates") }

    describe "upload artifact" do

      in_directory_with_file(ARTIFACT_FILE)

      before do
        visit new_admin_jam_ruby_artifact_update_path
        fill_in "jam_ruby_artifact_update_version",    with: "1"
        fill_in "jam_ruby_artifact_update_environment", with: "public"
        select('JamClient/Win32', from: "jam_ruby_artifact_update_product")
        fill_in "jam_ruby_artifact_update_environment", with: "public"
        attach_file("jam_ruby_artifact_update_uri", ARTIFACT_FILE)
        click_button "Create Artifact update"
      end

      it {
        should have_selector('#main_content .panel:first-child h3', text: "Jam Ruby Artifact Update Details" ) }
    end
  end
end
