2016-12-16 11:21:28 -05:00
|
|
|
module IntegrationHelpers
|
2017-08-31 00:06:56 -04:00
|
|
|
def create_user
|
|
|
|
get "/u/hp.json"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
body = JSON.parse(response.body)
|
|
|
|
honeypot = body["value"]
|
|
|
|
challenge = body["challenge"]
|
|
|
|
user = Fabricate.build(:user)
|
|
|
|
|
|
|
|
post "/u.json", params: {
|
|
|
|
username: user.username,
|
|
|
|
email: user.email,
|
|
|
|
password: 'asdasljdhaiosdjioaeiow',
|
|
|
|
password_confirmation: honeypot,
|
|
|
|
challenge: challenge.reverse
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
body = JSON.parse(response.body)
|
|
|
|
User.find(body["user_id"])
|
|
|
|
end
|
|
|
|
|
2016-12-16 11:21:28 -05:00
|
|
|
def sign_in(user)
|
|
|
|
password = 'somecomplicatedpassword'
|
|
|
|
user.update!(password: password)
|
|
|
|
Fabricate(:email_token, confirmed: true, user: user)
|
2017-08-31 00:06:56 -04:00
|
|
|
post "/session.json", params: { login: user.username, password: password }
|
2016-12-16 11:21:28 -05:00
|
|
|
expect(response).to be_success
|
2017-12-13 21:53:21 -05:00
|
|
|
user
|
2016-12-16 11:21:28 -05:00
|
|
|
end
|
|
|
|
end
|