The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.4 KiB

  1. require 'rails_helper'
  2. RSpec.describe AppSignUpService, type: :service do
  3. let(:app) { Fabricate(:application, scopes: 'read write') }
  4. let(:good_params) { { username: 'alice', password: '12345678', email: 'good@email.com', agreement: true } }
  5. subject { described_class.new }
  6. describe '#call' do
  7. it 'returns nil when registrations are closed' do
  8. Setting.open_registrations = false
  9. expect(subject.call(app, good_params)).to be_nil
  10. end
  11. it 'raises an error when params are missing' do
  12. expect { subject.call(app, {}) }.to raise_error ActiveRecord::RecordInvalid
  13. end
  14. it 'creates an unconfirmed user with access token' do
  15. access_token = subject.call(app, good_params)
  16. expect(access_token).to_not be_nil
  17. user = User.find_by(id: access_token.resource_owner_id)
  18. expect(user).to_not be_nil
  19. expect(user.confirmed?).to be false
  20. end
  21. it 'creates access token with the app\'s scopes' do
  22. access_token = subject.call(app, good_params)
  23. expect(access_token).to_not be_nil
  24. expect(access_token.scopes.to_s).to eq 'read write'
  25. end
  26. it 'creates an account' do
  27. access_token = subject.call(app, good_params)
  28. expect(access_token).to_not be_nil
  29. user = User.find_by(id: access_token.resource_owner_id)
  30. expect(user).to_not be_nil
  31. expect(user.account).to_not be_nil
  32. end
  33. end
  34. end