|
73 | 73 | Travis::Github::Sync::Repository.expects(:unpermit_all).with(user, [removed_repo])
|
74 | 74 | sync.run
|
75 | 75 | end
|
| 76 | + |
| 77 | + context "with private forks of organization repositories" do |
| 78 | + let(:user_repositories) {[ |
| 79 | + { 'name' => 'public', 'owner' => { 'login' => 'sven' }, 'permissions' => { 'admin' => true }, 'private' => false }, |
| 80 | + { 'name' => 'private', 'owner' => { 'login' => 'sven' }, 'permissions' => { 'admin' => true }, 'private' => true, 'fork' => true} |
| 81 | + ]} |
| 82 | + let(:duplicate_org_repositories) {[ |
| 83 | + { 'name' => 'private', 'owner' => { 'login' => 'sven' }, 'permissions' => { 'admin' => false }, 'private' => true, 'fork' => true} |
| 84 | + ]} |
| 85 | + let(:org_repositories) {[ |
| 86 | + { 'name' => 'other', 'owner' => { 'login' => 'sven' }, 'permissions' => { 'admin' => false }, 'private' => true, 'fork' => true} |
| 87 | + ]} |
| 88 | + let(:order) {sequence('github-sync')} |
| 89 | + |
| 90 | + before do |
| 91 | + Travis::Github::Sync::Repositories.type = 'private' |
| 92 | + Travis::Github::Sync::Repository.unstub(:new) |
| 93 | + end |
| 94 | + |
| 95 | + it "should not sync the organization's duplicate" do |
| 96 | + Travis::Github::Sync::Repository.expects(:new).once.returns(stub('repository', :run => public_repo)) |
| 97 | + GH.expects(:[]).with('user/repos').returns(user_repositories).in_sequence(order) |
| 98 | + GH.expects(:[]).with('orgs/the-org/repos').returns(duplicate_org_repositories).in_sequence(order) |
| 99 | + sync.run |
| 100 | + end |
| 101 | + |
| 102 | + it "should sync the organization's repository when it's not a duplicate" do |
| 103 | + Travis::Github::Sync::Repository.expects(:new).twice.returns(stub('repository', :run => public_repo)) |
| 104 | + GH.expects(:[]).with('user/repos').returns(user_repositories).in_sequence(order) |
| 105 | + GH.expects(:[]).with('orgs/the-org/repos').returns(org_repositories).in_sequence(order) |
| 106 | + sync.run |
| 107 | + end |
| 108 | + |
| 109 | + it "should sync the organization's repository when it has admin rights" do |
| 110 | + # this is an unlikely scenario, but as the code checks for it, a test is in order |
| 111 | + Travis::Github::Sync::Repository.expects(:new).twice.returns(stub('repository', :run => public_repo)) |
| 112 | + GH.expects(:[]).with('user/repos').returns(duplicate_org_repositories).in_sequence(order) |
| 113 | + GH.expects(:[]).with('orgs/the-org/repos').returns(user_repositories).in_sequence(order) |
| 114 | + sync.run |
| 115 | + end |
| 116 | + end |
76 | 117 | end
|
0 commit comments