Class: CmQuiz::Factory::User
- Inherits:
-
Object
- Object
- CmQuiz::Factory::User
- Defined in:
- lib/cm_quiz/factory/user.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(project_api:, name: nil, email: nil, password: nil) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(project_api:, name: nil, email: nil, password: nil) ⇒ User
Returns a new instance of User.
6 7 8 9 10 11 |
# File 'lib/cm_quiz/factory/user.rb', line 6 def initialize(project_api:, name: nil, email: nil, password: nil) @project_api = project_api @name = name || "codementor-test-#{SecureRandom.hex(5)}" @email = email || "#{@name}@codementor.io" @password = password || "pAssw0rd!" end |
Instance Method Details
#create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cm_quiz/factory/user.rb', line 13 def create = { body: { email: @email, name: @name, password: @password } } res = @project_api.request(:post, '/users', ) payload = JSON.parse(res.body) [payload['jwt'], payload['refresh_token']] rescue => e raise StandardError, "Create test user failed, reason: #{e.message}" end |