From c9b1e30583dc1adce8853256ba34900721565f74 Mon Sep 17 00:00:00 2001 From: qyzh Date: Wed, 15 Dec 2021 19:06:34 +0800 Subject: [PATCH] profile_completed = true --- app/controllers/accounts_controller.rb | 1 + spec/requests/sponsorships_spec.rb | 38 ++++++++++++++++++++++---- spec/requests/wallets_spec.rb | 8 +++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 936e2e6ad..a96af9918 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -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]}) diff --git a/spec/requests/sponsorships_spec.rb b/spec/requests/sponsorships_spec.rb index bacf1da8f..dc57d6a4c 100644 --- a/spec/requests/sponsorships_spec.rb +++ b/spec/requests/sponsorships_spec.rb @@ -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 diff --git a/spec/requests/wallets_spec.rb b/spec/requests/wallets_spec.rb index 8ca130193..e34891c36 100644 --- a/spec/requests/wallets_spec.rb +++ b/spec/requests/wallets_spec.rb @@ -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