require 'spec_helper'

describe Web::Admin::EventsController do
  before :each do
    sign_in_as_admin
  end

  describe "GET 'index'" do
    it "returns http success" do
      get :index
      expect(response).to be_success
    end
  end

  describe "GET 'new'" do
    it "returns http success" do
      get :new
      expect(response).to be_success
    end
  end

  describe "POST 'create'" do
    it "returns http redirect" do
      attrs = attributes_for :event
      post :create, event: attrs
      expect(response).to be_redirect
    end
  end

  describe "GET 'show'" do
    it "returns http success" do
      event = create :event
      get :show, id: event.id
      expect(response).to be_success
    end
  end

  describe "GET 'edit'" do
    it "returns http success" do
      event = create :event
      get :edit, id: event.id
      expect(response).to be_success
    end
  end

  describe "PUT 'update'" do
    it "returns http redirect" do
      event = create :event
      attrs = event.attributes
      attrs[:date] = DateTime.current
      put :update, id: event.id, event: attrs

      expect(response).to be_redirect

      event.reload
      expect(event.date.to_i).to eq(attrs[:date].to_i)
    end
  end

  describe "DELETE 'destroy'" do
    it "returns http redirect" do
      event = create :event
      delete :destroy, id: event.id
      expect(response).to be_redirect
    end
  end

end
