describe PetsController, type: :controller do

  # This should return the minimal set of attributes required to create a valid
  # Pet. As you add validations to Pet, be sure to
  # adjust the attributes here as well.
  let(:valid_attributes) {
    skip("Add a hash of attributes valid for your model")
  }

  let(:invalid_attributes) {
    skip("Add a hash of attributes invalid for your model")
  }

  # This should return the minimal set of values that should be in the session
  # in order to pass any filters (e.g. authentication) defined in
  # PetsController. Be sure to keep this updated too.
  let(:valid_session) { {} }

  describe "GET #index" do
    it "assigns all pets as @pets" do
      pet = Pet.create! valid_attributes
      get :index, {}, valid_session
      expect(assigns(:pets)).to eq([pet])
    end
  end

  describe "GET #show" do
    it "assigns the requested pet as @pet" do
      pet = Pet.create! valid_attributes
      get :show, {:id => pet.to_param}, valid_session
      expect(assigns(:pet)).to eq(pet)
    end
  end

  describe "GET #new" do
    it "assigns a new pet as @pet" do
      get :new, {}, valid_session
      expect(assigns(:pet)).to be_a_new(Pet)
    end
  end

  describe "GET #edit" do
    it "assigns the requested pet as @pet" do
      pet = Pet.create! valid_attributes
      get :edit, {:id => pet.to_param}, valid_session
      expect(assigns(:pet)).to eq(pet)
    end
  end

  describe "POST #create" do
    context "with valid params" do
      it "creates a new Pet" do
        expect {
          post :create, {:pet => valid_attributes}, valid_session
        }.to change(Pet, :count).by(1)
      end

      it "assigns a newly created pet as @pet" do
        post :create, {:pet => valid_attributes}, valid_session
        expect(assigns(:pet)).to be_a(Pet)
        expect(assigns(:pet)).to be_persisted
      end

      it "redirects to the created pet" do
        post :create, {:pet => valid_attributes}, valid_session
        expect(response).to redirect_to(Pet.last)
      end
    end

    context "with invalid params" do
      it "assigns a newly created but unsaved pet as @pet" do
        post :create, {:pet => invalid_attributes}, valid_session
        expect(assigns(:pet)).to be_a_new(Pet)
      end

      it "re-renders the 'new' template" do
        post :create, {:pet => invalid_attributes}, valid_session
        expect(response).to render_template("new")
      end
    end
  end

  describe "PUT #update" do
    context "with valid params" do
      let(:new_attributes) {
        skip("Add a hash of attributes valid for your model")
      }

      it "updates the requested pet" do
        pet = Pet.create! valid_attributes
        put :update, {:id => pet.to_param, :pet => new_attributes}, valid_session
        pet.reload
        skip("Add assertions for updated state")
      end

      it "assigns the requested pet as @pet" do
        pet = Pet.create! valid_attributes
        put :update, {:id => pet.to_param, :pet => valid_attributes}, valid_session
        expect(assigns(:pet)).to eq(pet)
      end

      it "redirects to the pet" do
        pet = Pet.create! valid_attributes
        put :update, {:id => pet.to_param, :pet => valid_attributes}, valid_session
        expect(response).to redirect_to(pet)
      end
    end

    context "with invalid params" do
      it "assigns the pet as @pet" do
        pet = Pet.create! valid_attributes
        put :update, {:id => pet.to_param, :pet => invalid_attributes}, valid_session
        expect(assigns(:pet)).to eq(pet)
      end

      it "re-renders the 'edit' template" do
        pet = Pet.create! valid_attributes
        put :update, {:id => pet.to_param, :pet => invalid_attributes}, valid_session
        expect(response).to render_template("edit")
      end
    end
  end

  describe "DELETE #destroy" do
    it "destroys the requested pet" do
      pet = Pet.create! valid_attributes
      expect {
        delete :destroy, {:id => pet.to_param}, valid_session
      }.to change(Pet, :count).by(-1)
    end

    it "redirects to the pets list" do
      pet = Pet.create! valid_attributes
      delete :destroy, {:id => pet.to_param}, valid_session
      expect(response).to redirect_to(pets_url)
    end
  end

end
