Browse Source

fix 无法创建PR

pull/317/head
qyzh 4 years ago
parent
commit
ce5b6a67bf
3 changed files with 149 additions and 13 deletions
  1. +6
    -3
      app/controllers/compare_controller.rb
  2. +8
    -3
      spec/requests/sponsor_tiers_spec.rb
  3. +135
    -7
      spec/requests/sponsorships_spec.rb

+ 6
- 3
app/controllers/compare_controller.rb View File

@@ -25,9 +25,12 @@ class CompareController < ApplicationController
end
if @exist_pullrequest.present?
return -2, "在这些分支之间的合并请求已存在:<a href='/projects/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}/Messagecount'>#{@exist_pullrequest.try(:title)}</a>"
else
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
return -2, "分支内容相同,无需创建合并请求"
else
# if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
# return -2, "分支内容相同,无需创建合并请求"
# end
if @base == @head
return -2, "请选择不同分支"
end
end
end


+ 8
- 3
spec/requests/sponsor_tiers_spec.rb View File

@@ -1,10 +1,15 @@
require 'rails_helper'

RSpec.describe "SponsorTiers", type: :request do

let(:developer_session) { {www_user_id: 5} }
let(:visitor_session) { {www_user_id: 4} }
let(:valid_session) { {www_user_id: 6} }

describe "GET /sponsor_tiers" do
it "works! (now write some real specs)" do
get sponsor_tiers_path
expect(response).to have_http_status(200)
it "success" do
get '/api/sponsor_tiers.json', params: {login: '123457qqcom'}, as: :json
expect(JSON.parse(response.body).length).to eq(1)
end
end
end

+ 135
- 7
spec/requests/sponsorships_spec.rb View File

@@ -13,11 +13,11 @@ RSpec.describe 'Sponsorships', type: :request do
let(:invalid_user_attributes) {
{amount: 10, visible: 1, sponsor_id: 4, developer_id: 1}
}

let(:invalid_attributes) {
{amunt: 10, visible: 1, developid: 1, sponsoid: 5}
}

let(:developer_session) { {www_user_id: 5} }
let(:visitor_session) { {www_user_id: 4} }
let(:valid_session) { {www_user_id: 6} }

describe 'create sponsorship' do
@@ -25,7 +25,7 @@ RSpec.describe 'Sponsorships', type: :request do
it 'create a new sponsorship' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
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
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
@@ -34,7 +34,7 @@ RSpec.describe 'Sponsorships', type: :request 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
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
@@ -42,7 +42,7 @@ RSpec.describe 'Sponsorships', type: :request do
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
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
@@ -51,14 +51,142 @@ RSpec.describe 'Sponsorships', type: :request 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
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
describe 'index' do
context 'success' do
it 'returns n records' do
get '/api/sponsorships.json'
expect(JSON.parse(response.body).length).to eq(Sponsorship.count)
end
end
end

describe 'stopped' do
context 'success' do
it 'returns n records' do
get '/api/sponsorships/stopped.json'
expect(JSON.parse(response.body).length).to eq(StoppedSponsorship.count)
end
end
end

describe 'sponsored' do
context 'valid_session' do
it 'returns 2 records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/sponsorships/sponsored.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(2)
end
end

context 'visitor session' do
it 'returns 1 record' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session }
get '/api/sponsorships/sponsored.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(1)
end
end
end

describe 'sponsoring' do
context 'valid_session' do
it 'returns 2 records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/sponsorships/sponsoring.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(2)
end
end

context 'visitor session' do
it 'returns 1 record' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session }
get '/api/sponsorships/sponsoring.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(1)
end
end
end

describe 'stopped_sponsored' do
context 'valid_session' do
it 'returns 2 records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/sponsorships/stopped_sponsored.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(2)
end
end

context 'visitor session' do
it 'returns 1 record' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session }
get '/api/sponsorships/stopped_sponsored.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(1)
end
end
end

describe 'stopped_sponsoring' do
context 'valid_session' do
it 'returns 2 records' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
get '/api/sponsorships/stopped_sponsoring.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(2)
end
end

context 'visitor session' do
it 'returns 1 record' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session }
get '/api/sponsorships/stopped_sponsoring.json', params: {id: 6}
expect(JSON.parse(response.body)['sponsorships'].length).to eq(1)
end
end
end

describe 'update' do
context 'as sponsor' do
it 'update success' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
put '/api/sponsorships/97.json', params: {amount: 50, sponsorship: {amount: 50}}, as: :json
expect(Sponsorship.find(97).amount).to eq(50)
expect(response.body).to eq('{"status":1,"message":"修改成功"}')
end
end

context 'as others' do
it 'fail' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { developer_session }
put '/api/sponsorships/97.json', params: {amount: 50, sponsorship: {amount: 50}}, as: :json
expect(Sponsorship.find(97).amount).to eq(10)
expect(response.body).to eq('{"status":401,"message":"没有权限"}')
end
end
end

describe 'destroy' do
context 'as sponsor' do
it 'success' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session }
expect{ delete '/api/sponsorships/100.json'}.to change(StoppedSponsorship, :count).by(1)
end
end

context 'as developer' do
it 'success' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { developer_session }
expect{ delete '/api/sponsorships/100.json'}.to change(StoppedSponsorship, :count).by(1)
end
end

context 'as others' do
it 'fail' do
allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session }
expect{ delete '/api/sponsorships/100.json'}.to change(StoppedSponsorship, :count).by(0)
end
end
end
end

Loading…
Cancel
Save