Sha256: cb97f78d0ab7243294ad077246cca1e4877fbeebbaf244e60ca7ef0d30f3f778

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

def ensure_user_created(email)
  user = AdminUser.where(email: email).first_or_create(password: 'password', password_confirmation: 'password')

  unless user.persisted?
    raise "Could not create user #{email}: #{user.errors.full_messages}"
  end
  user
end

Given /^(?:I am logged|log) out$/ do
  click_link 'Logout' if page.all(:css, "a", text: 'Logout').any?
end

Given /^I am logged in$/ do
  step 'log out'
  login_as ensure_user_created 'admin@example.com'
end

Given /^I am logged in with capybara$/ do
  ensure_user_created 'admin@example.com'
  step 'log out'

  visit new_admin_user_session_path
  fill_in 'Email',    with: 'admin@example.com'
  fill_in 'Password', with: 'password'
  click_button 'Login'
end

Given /^an admin user "([^"]*)" exists$/ do |email|
  ensure_user_created(email)
end

Given /^"([^"]*)" requests a password reset with token "([^"]*)"( but it expires)?$/ do |email, token, expired|
  visit new_admin_user_password_path
  fill_in 'Email', with: email
  allow(Devise).to receive(:friendly_token).and_return(token)
  click_button "Reset My Password"

  AdminUser.where(email: email).first.update_attribute :reset_password_sent_at, 1.month.ago if expired
end

Given /^override locale "([^"]*)" with "([^"]*)"$/ do |path, value|
  keys_value  = path.split('.') + [value]
  locale_hash = keys_value.reverse.inject{|a, n| {n=>a}}
  I18n.available_locales
  I18n.backend.store_translations(I18n.locale, locale_hash)
end

When /^I fill in the password field with "([^"]*)"$/ do |password|
  fill_in 'admin_user_password', with: password
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/features/step_definitions/user_steps.rb