require 'spec_helper'

describe Web::Admin::UsersController 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 :user
      post :create, user: attrs
      expect(response).to be_redirect
    end
  end

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

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

  describe "PUT 'update'" do
    it "returns http redirect" do
      user = create :user
      attrs = user.attributes
      attrs[:first_name] = Faker::Name.first_name
      put :update, id: user.id, user: attrs

      expect(response).to be_redirect

      user.reload
      expect(user.first_name).to eq(attrs[:first_name])
    end
  end

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