summaryrefslogtreecommitdiff
path: root/spec/support/login.rb
blob: 462647ab8563cf1e8a233d3e9125a2a4b9162b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module LoginMacros
  def login_as role
    @user = User.create(:email => "user#{User.count}@mail.com", 
                        :name => "John Smith",
                        :password => "123456",
                        :password_confirmation => "123456",
                        :skype => 'user_skype')
 
    if role == :admin 
      @user.admin = true
      @user.save!
    end

    visit new_user_session_path
    fill_in "Email", :with => @user.email
    fill_in "Password", :with => "123456"
    click_button "Sign in"
  end

  def login_with(user)
    visit new_user_session_path
    fill_in "Email", :with => user.email
    fill_in "Password", :with => "123456"
    click_button "Sign in"
  end
  
  def logout
    click_link "Logout" rescue nil
  end
end