-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
228 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ | |
|
||
.byebug_history | ||
/.yardoc/ | ||
/coverage/ | ||
|
||
/doc/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
class SpinCandidate < ApplicationRecord | ||
belongs_to :user | ||
validates :full_name, :validation_log, presence: true | ||
|
||
def is_candidate?(client:) | ||
begin | ||
raise Octokit::NotFound if client.github_access.nil? | ||
if client.github_access.contents(full_name, path: '/.manageiq-spin') | ||
true | ||
end | ||
rescue Octokit::NotFound | ||
false | ||
end | ||
def is_candidate? user: | ||
client = Providers::BaseManager.new(user.authentication_tokens.first.provider).get_connector | ||
client.candidate_spin? full_name | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module V1 | ||
class SpinCandidateSerializer < ApplicationSerializer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module V1 | ||
class SpinSerializer < ApplicationSerializer | ||
class SpinSerializer < ApplicationSerializer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
FactoryBot.define do | ||
factory :spin_candidate do | ||
|
||
user | ||
full_name { "#{user.github_login}/#{Faker::App.name.parameterize}" } | ||
validation_log 'Pending validation' | ||
|
||
trait :validation_log_full do | ||
validation_log { Faker::Lorem.sentence } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,60 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe SpinCandidate, type: :model do | ||
context "when not authenticated " do | ||
pending "index" | ||
pending "show" | ||
pending "refresh" | ||
let(:spin_candidate) { FactoryBot.build(:spin_candidate) } | ||
let!(:user) { FactoryBot.create(:user) } | ||
let(:non_valid_repo) { 'ManageIQ-Exchange/manageiq-exchange' } | ||
let(:nonexisting_repo) { 'ManageIQ-Exchange/i_do-not_exist' } | ||
let(:valid_repo) { 'ManageIQ-Exchange/manageiq-exchange-spin-template' } | ||
it 'has a valid factory' do | ||
spin_candidate.valid? | ||
expect(spin_candidate).to be_valid | ||
end | ||
context "when authenticated" do | ||
pending "index" | ||
pending "show when valid id" | ||
pending "show when invalid id" | ||
pending "refresh when same repos" | ||
pending "refresh when deleted repos" | ||
pending "refresh when new repos" | ||
pending "refresh when updated repos" | ||
|
||
it 'is not valid without a user' do | ||
spin_candidate.user = nil | ||
spin_candidate.valid? | ||
expect(spin_candidate.errors.details[:user]).to include(error: :blank) | ||
end | ||
|
||
it 'is not valid without a full name' do | ||
spin_candidate.full_name = nil | ||
spin_candidate.valid? | ||
expect(spin_candidate.errors.details[:full_name]).to include(error: :blank) | ||
end | ||
|
||
it 'is not valid without a validation_log' do | ||
spin_candidate.validation_log = nil | ||
spin_candidate.valid? | ||
expect(spin_candidate.errors.details[:validation_log]).to include(error: :blank) | ||
end | ||
|
||
it 'verifies a non-valid repo' do | ||
spin_candidate.full_name = non_valid_repo | ||
@user = user | ||
api_basic_authorize | ||
VCR.use_cassette('providers/github/spin_candidates/get-non-valid-repo') do | ||
expect(spin_candidate.is_candidate?(user: user)).to be_falsy | ||
end | ||
|
||
end | ||
|
||
it 'verifies a non-existing repo' do | ||
spin_candidate.full_name = nonexisting_repo | ||
@user = user | ||
api_basic_authorize | ||
VCR.use_cassette('providers/github/spin_candidates/get-non-existing-repo') do | ||
expect(spin_candidate.is_candidate?(user: user)).to be_falsy | ||
end | ||
|
||
end | ||
|
||
it 'verifies a valid repo' do | ||
spin_candidate.full_name = valid_repo | ||
@user = user | ||
api_basic_authorize | ||
VCR.use_cassette('providers/github/spin_candidates/get-valid-repo') do | ||
expect(spin_candidate.is_candidate?(user: user)).to be_truthy | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'V1::SpinCandidates', type: :request do | ||
let!(:prefix) { 'v1' } | ||
|
||
context 'when not authenticated' do | ||
it '#index returns 401' do | ||
get "/#{prefix}/spin_candidates" | ||
expect(response).to have_http_status(401) | ||
end | ||
|
||
it '#show returns 401' do | ||
get "/#{prefix}/spin_candidates/1" | ||
expect(response).to have_http_status(401) | ||
end | ||
|
||
it '#publish returns 401' do | ||
post "/#{prefix}/spin_candidates/1/publish" | ||
expect(response).to have_http_status(401) | ||
end | ||
|
||
it '#refresh returns 401' do | ||
post "/#{prefix}/spin_candidates/refresh" | ||
expect(response).to have_http_status(401) | ||
end | ||
end | ||
context 'when authenticated' do | ||
let!(:user) { FactoryBot.create(:user) } | ||
let!(:spin_candidate) { FactoryBot.create(:spin_candidate, user: user) } | ||
let!(:spin_candidate1) { FactoryBot.create(:spin_candidate, user: user) } | ||
|
||
it '#index' do | ||
@user = user | ||
api_basic_authorize | ||
get "/#{prefix}/spin_candidates" | ||
expect(response).to have_http_status(:ok) | ||
data = JSON.parse(response.body)["data"] | ||
expect(data).to include ({"id" => spin_candidate.id, "full_name" => spin_candidate.full_name, "validation_log" => spin_candidate.validation_log}) | ||
expect(data).to include ({"id" => spin_candidate1.id, "full_name" => spin_candidate1.full_name, "validation_log" => spin_candidate1.validation_log}) | ||
end | ||
|
||
|
||
it "show when valid id" do | ||
@user = user | ||
api_basic_authorize | ||
get "/#{prefix}/spin_candidates/#{spin_candidate.id}" | ||
expect(response).to have_http_status(:ok) | ||
data = JSON.parse(response.body)["data"] | ||
expect(data).to include ({"id" => spin_candidate.id, "full_name" => spin_candidate.full_name, "validation_log" => spin_candidate.validation_log}) | ||
end | ||
|
||
it 'show when invalid id' do | ||
@user = user | ||
api_basic_authorize | ||
get "/#{prefix}/spin_candidates/error" | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
pending "refresh when same repos" | ||
pending "refresh when deleted repos" | ||
pending "refresh when new repos" | ||
pending "refresh when updated repos" | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
spec/vcr_cassettes/providers/github/spins_candidates/get-index.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.