profile_completed = true

This commit is contained in:
qyzh 2021-12-15 19:06:34 +08:00
parent 6571db8a3c
commit c9b1e30583
3 changed files with 38 additions and 9 deletions

View File

@ -146,6 +146,7 @@ class AccountsController < ApplicationController
@user.password = params[:password]
# 现在因为是验证码,所以在注册的时候就可以激活
@user.activate
@user.profile_completed = true
# 必须要用save操作密码的保存是在users中
interactor = Gitea::RegisterInteractor.call({username: login, email: email, password: params[:password]})

View File

@ -22,15 +22,43 @@ RSpec.describe 'Sponsorships', type: :request do
describe 'create sponsorship' do
context 'success' do
it 'works! (now write some real specs)' do
it 'create a new sponsorship' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
# expect(response.body).to eq('[{"id":5,"amount":10,"visible":1,"sponsor_id":5,"developer_id":4,"created_at":"2021-06-09T10:02:53.000+08:00","updated_at":"2021-06-09T10:02:53.000+08:00","accumulate":10,"url":"http://www.example.com/api/sponsorships/5.json"},{"id":6,"amount":10,"visible":1,"sponsor_id":5,"developer_id":1,"created_at":"2021-06-09T10:42:32.000+08:00","updated_at":"2021-09-22T14:48:09.000+08:00","accumulate":5,"url":"http://www.example.com/api/sponsorships/6.json"}]')
# expect {
# post '/api/sponsorships.json', params: {developer_id: 1, single: false, amount: 5}
# }.to change(Sponsorship, :count).by(1)
expect {
post '/api/sponsorships.json', params: {"amount"=>5, "visible"=>1, single: false, "developer_id"=>1, "sponsorship"=>{"amount"=>5, "visible"=>1, "developer_id"=>1}}, as: :json
}.to change(Sponsorship, :count).by(1)
end
end
context 'single success' do
it 'create a stopped_sponsorship' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
expect {
post '/api/sponsorships.json', params: {"amount"=>5, "visible"=>1, single: true, "developer_id"=>1, "sponsorship"=>{"amount"=>5, "visible"=>1, "developer_id"=>1}}, as: :json
}.to change(StoppedSponsorship, :count).by(1)
end
end
context 'fail to repeat sponsorship' do
it 'returns fail' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
post '/api/sponsorships.json', params: {"amount"=>5, "visible"=>1, single: false, "developer_id"=>4, "sponsorship"=>{"amount"=>5, "visible"=>1, "developer_id"=>4}}, as: :json
expect(JSON.parse(response.body)['message']).to eq('您已经赞助了TA')
end
end
context 'balance not enough' do
it 'returns fail' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
expect {
post '/api/sponsorships.json', params: {"amount"=>500000, "visible"=>1, single: false, "developer_id"=>1, "sponsorship"=>{"amount"=>500000, "visible"=>1, "developer_id"=>1}}, as: :json
}.to change(Sponsorship, :count).by(0)
end
end
end
describe 'create sponsorship' do
end
end

View File

@ -9,7 +9,7 @@ RSpec.describe 'Wallet', type: :request do
describe 'GET /wallets/balance.json' do
it 'success' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/balance.json', params: { id: 6 }
get '/api/wallets/balance.json', params: { id: 6 }, as: :json
expect(JSON.parse(response.body)['balance']).to eq(100)
end
end
@ -18,7 +18,7 @@ RSpec.describe 'Wallet', type: :request do
context 'category all' do
it 'return 2 records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'all' }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'all' }, as: :json
expect(JSON.parse(response.body)['coin_changes'].length).to eq(2)
# expect(JSON.parse(response.body)).to eq('')
end
@ -27,7 +27,7 @@ RSpec.describe 'Wallet', type: :request do
context 'category outcome' do
it 'return 1 outcome records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'outcome' }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'outcome' }, as: :json
expect(JSON.parse(response.body)['coin_changes'][0]['amount']).to eq(5)
expect(JSON.parse(response.body)['coin_changes'].length).to eq(1)
end
@ -36,7 +36,7 @@ RSpec.describe 'Wallet', type: :request do
context 'category outcome' do
it 'return 1 income records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'income' }
get '/api/wallets/coin_changes.json', params: { id: 6, category: 'income' }, as: :json
expect(JSON.parse(response.body)['coin_changes'][0]['amount']).to eq(10)
expect(JSON.parse(response.body)['coin_changes'].length).to eq(1)
end