module ViewMacros

  def foreach_theme 
    RSpec.configuration.themes.each do |theme|
      context " with theme #{theme}" do 
        before(:each) do
          view.view_paths=[ "app/views/themes/#{theme}", "app/views"]
        end
        
        yield
      end
    end
  end
  def login_fet_user
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      user = FactoryGirl.build(:user)
      user = User.find_by_email(user.email) || user
      user.save
      user.add_role(:fetuser)
     # user.confirm! 
      @user=user
      @ability= Ability.new(@user)
      # controller.stub(:current_ability) { @ability }
      allow(view).to receive(:current_ability).and_return(@ability)
      sign_in user
    end
  end
  def login_fetadmin_user
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      user = FactoryGirl.build(:user)
      user = User.find_by_email(user.email) || user
      user.save
      user.add_role(:fetadmin)
     # user.confirm! 
      @user=user
      @ability= Ability.new(@user)
      # controller.stub(:current_ability) { @ability }
      allow(view).to receive(:current_ability).and_return(@ability)
      sign_in user
    end
  end

end
