Module: EgovUtils::TestUtils::ControllerHelpers

Defined in:
lib/egov_utils/test_utils/controller_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#signed_userObject (readonly)

Returns the value of attribute signed_user.



5
6
7
# File 'lib/egov_utils/test_utils/controller_helpers.rb', line 5

def signed_user
  @signed_user
end

Instance Method Details

#admin_userObject



12
13
14
# File 'lib/egov_utils/test_utils/controller_helpers.rb', line 12

def admin_user
  default_user(roles: ['admin'])
end

#anonymous_userObject



20
21
22
23
24
# File 'lib/egov_utils/test_utils/controller_helpers.rb', line 20

def anonymous_user
  user = default_user
  allow(user).to receive(:persisted?).and_return(false)
  user
end

#basic_userObject



16
17
18
# File 'lib/egov_utils/test_utils/controller_helpers.rb', line 16

def basic_user
  default_user(roles: ['user'])
end

#default_user(params = {}) ⇒ Object



7
8
9
10
# File 'lib/egov_utils/test_utils/controller_helpers.rb', line 7

def default_user(params={})
  user = FactoryBot.create(:egov_utils_user, params)
  user
end

#sign_in(user = basic_user) ⇒ Object



26
27
28
29
# File 'lib/egov_utils/test_utils/controller_helpers.rb', line 26

def (user = basic_user)
  @signed_user = user
  allow(controller).to receive(:find_current_user).and_return(user)
end