mirror of
https://github.com/czhu12/canine.git
synced 2026-04-29 08:00:12 -05:00
fixed specs
This commit is contained in:
@@ -5,7 +5,7 @@ module Projects
|
||||
extend LightService::Action
|
||||
|
||||
expects :build_configuration, :params
|
||||
promises :build_packs
|
||||
promises :build_packs, optional: true
|
||||
|
||||
def self.fetch_buildpack_details!(build_pack)
|
||||
result = Buildpacks::Details.execute(
|
||||
@@ -20,13 +20,13 @@ module Projects
|
||||
build_configuration = context.build_configuration
|
||||
next context unless build_configuration&.buildpacks?
|
||||
|
||||
build_packs_params = context.params.dig(:project, :build_configuration, :build_packs_attributes)
|
||||
build_packs_params = context.params
|
||||
.dig(:project, :build_configuration, :build_packs_attributes) || []
|
||||
next context unless build_packs_params
|
||||
|
||||
context.build_packs = build_packs_params.map.with_index do |pack_params, build_order|
|
||||
build_pack = build_configuration.build_packs.build(
|
||||
pack_params.permit(:namespace, :name, :version, :reference_type).merge(build_order:)
|
||||
)
|
||||
permitted = pack_params.permit(:namespace, :name, :version, :reference_type)
|
||||
build_pack = build_configuration.build_packs.build(permitted.merge(build_order:))
|
||||
fetch_buildpack_details!(build_pack)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,4 +52,4 @@ class Projects::UpdateBuildPacks
|
||||
|
||||
context
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,8 @@ export default class extends Controller {
|
||||
name: name,
|
||||
version: version || '',
|
||||
image: '/images/languages/buildpack.webp',
|
||||
description: description || ''
|
||||
description: description || '',
|
||||
reference_type: 'registry'
|
||||
}
|
||||
|
||||
// Check if already selected
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Projects::InitializeBuildPacks do
|
||||
include_context 'buildpack details stubbing'
|
||||
|
||||
let(:provider) { create(:provider, :github) }
|
||||
let(:project) { create(:project) }
|
||||
let(:build_configuration) do
|
||||
@@ -17,20 +19,20 @@ RSpec.describe Projects::InitializeBuildPacks do
|
||||
ActionController::Parameters.new({
|
||||
project: {
|
||||
build_configuration: {
|
||||
build_packs_attributes: {
|
||||
'0' => {
|
||||
build_packs_attributes: [
|
||||
{
|
||||
namespace: 'paketo-buildpacks',
|
||||
name: 'ruby',
|
||||
version: '0.47.7',
|
||||
reference_type: 'registry'
|
||||
},
|
||||
'1' => {
|
||||
{
|
||||
namespace: 'paketo-buildpacks',
|
||||
name: 'nodejs',
|
||||
version: '',
|
||||
reference_type: 'registry'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Projects::UpdateBuildPacks do
|
||||
include_context 'buildpack details stubbing'
|
||||
|
||||
let(:provider) { create(:provider, :github) }
|
||||
let(:project) { create(:project) }
|
||||
let(:build_configuration) do
|
||||
@@ -51,7 +53,7 @@ RSpec.describe Projects::UpdateBuildPacks do
|
||||
name: 'ruby',
|
||||
version: '',
|
||||
reference_type: 'registry'
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -65,29 +67,10 @@ RSpec.describe Projects::UpdateBuildPacks do
|
||||
}
|
||||
end
|
||||
|
||||
let(:buildpack_details_result) do
|
||||
double(
|
||||
result: Buildpacks::Details::BuildpackDetailsResult.new(
|
||||
latest: {
|
||||
version: '0.47.7',
|
||||
namespace: 'paketo-buildpacks',
|
||||
name: 'go',
|
||||
description: 'Go buildpack'
|
||||
},
|
||||
versions: []
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
allow(Buildpacks::Details).to receive(:execute).and_return(buildpack_details_result)
|
||||
end
|
||||
|
||||
it 'keeps existing build packs, creates new ones, and deletes missing ones' do
|
||||
expect(build_configuration.build_packs.map(&:key)).to eq(['paketo-buildpacks/ruby', 'paketo-buildpacks/nodejs'])
|
||||
expect(build_configuration.build_packs.map(&:key)).to eq([ 'paketo-buildpacks/ruby', 'paketo-buildpacks/nodejs' ])
|
||||
described_class.execute(context)
|
||||
build_configuration.build_packs.reload
|
||||
expect(build_configuration.build_packs.map(&:key)).to eq(['paketo-buildpacks/go', 'paketo-buildpacks/ruby'])
|
||||
expect(build_configuration.build_packs.map(&:key)).to eq([ 'paketo-buildpacks/go', 'paketo-buildpacks/ruby' ])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ FactoryBot.define do
|
||||
namespace { "paketo-buildpacks" }
|
||||
name { "ruby" }
|
||||
version { "0.47.7" }
|
||||
sequence(:build_order) { |n| n }
|
||||
details do
|
||||
{
|
||||
"description" => "A language family buildpack for building Ruby apps",
|
||||
|
||||
@@ -24,7 +24,7 @@ require 'support/webmock'
|
||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||
# require only the support files necessary.
|
||||
#
|
||||
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
||||
Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
||||
|
||||
# Checks for pending migrations and applies them before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove these lines.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.shared_context 'buildpack details stubbing' do
|
||||
let(:buildpack_details_result) do
|
||||
double(
|
||||
result: Buildpacks::Details::BuildpackDetailsResult.new(
|
||||
latest: {
|
||||
version: '0.47.7',
|
||||
namespace: 'paketo-buildpacks',
|
||||
name: 'go',
|
||||
description: 'Go buildpack'
|
||||
},
|
||||
versions: []
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
allow(Buildpacks::Details).to receive(:execute).and_return(buildpack_details_result)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user