require 'spec_helper'

describe "StatusTypePages" do

  subject { page }

  describe "new status_type page" do
    before { visit new_status_type_path }

    it { should have_h1('New Status Type') }
    it { should have_title('New Status Type') }
  end

  describe "creation" do
    before { visit new_status_type_path }
    let (:submit) { "Create Type" }

    describe "with invalid information" do
      it "should not create a status" do
        expect { click_button submit }.not_to change(StatusType, :count)
      end

      describe "after submission" do
        before { click_button submit }

        it { should have_title("New Status Type") }
        it { should have_content('error') }
      end
    end

    describe "with valid information" do
      before do
        fill_in :name, with: "Test Status Type"
      end

      it "should create a status type" do
        expect { click_button submit }.to change(StatusType, :count).by(1)
      end

      describe "after saving the status" do
        before { click_button submit }
        let(:status_type) { StatusType.find_by_name("Test Status Type") }

        it { should have_title('New Status Type') }
        it { should have_success_message('Status Type Created') }
      end
    end
  end
end
