require 'spec_helper'

describe InvitedUser do

  subject { page }

  # create an administrative user
  let(:user) { FactoryGirl.create(:admin) }

  before { sign_in user }

  describe "enduser management" do

    # let's go the management page for users
    before { visit  admin_invited_users_path }
    it { should have_selector('h2', text: "Invited Users") }

    describe "create service invite" do

      before do

        # create a new user
        UserMailer.deliveries.clear
        visit new_admin_invited_user_path
        fill_in "invited_users_email",    with: "some_silly_guy@jamkazam.com"
        click_button "Create Invited user"

      end

      it { should have_selector('#main_content .panel:first-child h3', text: "Invited Users Details" ); }
      it { UserMailer.deliveries.length.should == 1 }
    end
  end
end
