Module: Rspec::Dunlop::AuthenticationSupport

Included in:
FeatureHelpers
Defined in:
lib/rspec/dunlop/authentication_support.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



32
33
34
# File 'lib/rspec/dunlop/authentication_support.rb', line 32

def current_user
  @user
end

#i_am_logged_in_as(user) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/rspec/dunlop/authentication_support.rb', line 36

def i_am_logged_in_as(user)
  visit new_user_session_path
  fill_in 'Email', with: user.email
  fill_in 'Password', with: user.password
  click_button 'Log in'
  #expect(current_path).to eq root_path
end

#i_am_logged_in_as_adminObject



27
28
29
30
# File 'lib/rspec/dunlop/authentication_support.rb', line 27

def i_am_logged_in_as_admin
  @user = FactoryGirl.create(:admin)
  i_am_logged_in_as(@user)
end

#i_am_logged_in_as_user(*user_args) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rspec/dunlop/authentication_support.rb', line 13

def i_am_logged_in_as_user(*user_args)
  if user_args.last.is_a?(Hash)
    user_args[-1][:role_names] = Array.wrap(user_args[-1][:role_names]) | ['read-class-WorkflowInstance'] if user_args[-1][:role_names].present?
  end
  @user = FactoryGirl.create(:user, *user_args)
  i_am_logged_in_as(@user)
end

#i_am_logged_in_as_user_of_service_providerObject



21
22
23
24
25
# File 'lib/rspec/dunlop/authentication_support.rb', line 21

def i_am_logged_in_as_user_of_service_provider
  @service_provider ||= FactoryGirl.create  :service_provider, :all_scenarios
  @user = FactoryGirl.create(:user, service_provider: @service_provider)
  i_am_logged_in_as(@user)
end

#open_pageObject



48
49
50
# File 'lib/rspec/dunlop/authentication_support.rb', line 48

def open_page
  save_and_open_page
end

#screenshotObject



44
45
46
# File 'lib/rspec/dunlop/authentication_support.rb', line 44

def screenshot
  screenshot_and_open_image
end

#submit_collection_formObject



56
57
58
# File 'lib/rspec/dunlop/authentication_support.rb', line 56

def submit_collection_form
  find('#new_collection input[type="submit"]').click
end

#submit_formObject



52
53
54
# File 'lib/rspec/dunlop/authentication_support.rb', line 52

def submit_form
  find('input[type="submit"]').click
end

#visit(*args) ⇒ Object

Add support for:

visit WorkflowInstance.last


5
6
7
8
9
10
11
# File 'lib/rspec/dunlop/authentication_support.rb', line 5

def visit(*args)
  case args[0]
  when ActiveRecord::Base, Array, Class
    args[0] = polymorphic_path(args[0])
  end
  super *args
end