Skip to content

Commit

Permalink
feat: replace mainDevelopmentBranches with mainBranch for pacticipant
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 29, 2021
1 parent b2bf144 commit 02d4525
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 26 deletions.
15 changes: 15 additions & 0 deletions db/migrations/20210529_add_main_branch_to_pacticipant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Sequel.migration do
up do
alter_table(:pacticipants) do
add_column(:main_branch, String)
drop_column(:main_development_branches)
end
end

down do
alter_table(:pacticipants) do
drop_column(:main_branch)
add_column(:main_development_branches, String)
end
end
end
2 changes: 1 addition & 1 deletion lib/pact_broker/api/contracts/pacticipant_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PacticipantSchema
end
optional(:name).filled(:str?, :single_line?)
optional(:displayName).maybe(:str?, :single_line?, :not_blank?)
optional(:mainDevelopmentBranches).each(:str?, :single_line?, :no_spaces?)
optional(:mainBranch).maybe(:str?, :single_line?, :no_spaces?)
optional(:repositoryUrl).maybe(:str?, :single_line?)
optional(:repositoryName).maybe(:str?, :single_line?)
optional(:repositoryNamespace).maybe(:str?, :single_line?)
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/decorators/pacticipant_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PacticipantDecorator < BaseDecorator
property :repository_url
property :repository_name
property :repository_namespace
property :main_development_branches if PactBroker.feature_enabled?(:branches)
property :main_branch


property :latest_version, as: :latestVersion, :class => PactBroker::Domain::Version, extend: PactBroker::Api::Decorators::EmbeddedVersionDecorator, embedded: true, writeable: false
Expand Down
10 changes: 2 additions & 8 deletions lib/pact_broker/domain/pacticipant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class Pacticipant < Sequel::Model
include PactBroker::Pacticipants::GenerateDisplayName
using PactBroker::StringRefinements

plugin :serialization
SPACE_DELIMITED_STRING_TO_ARRAY = lambda { |string| string.split(" ") }
ARRAY_TO_SPACE_DELIMITED_STRING = lambda { |array| array.join(" ") }
serialize_attributes [ARRAY_TO_SPACE_DELIMITED_STRING, SPACE_DELIMITED_STRING_TO_ARRAY], :main_development_branches

plugin :insert_ignore, identifying_columns: [:name]
plugin :timestamps, update_on_create: true

Expand Down Expand Up @@ -52,9 +47,8 @@ def before_destroy

def before_save
super
if display_name.nil? || display_name.to_s.blank?
self.display_name = generate_display_name(name)
end
self.display_name = generate_display_name(name) if display_name.blank?
self.main_branch = nil if main_branch.blank?
end

def latest_version
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/pacticipants/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create params
repository_url: params[:repository_url],
repository_name: params[:repository_name],
repository_namespace: params[:repository_namespace],
main_development_branches: params[:main_development_branches] || []
main_branch: params[:main_branch]
).insert_ignore
end

Expand All @@ -76,7 +76,7 @@ def replace(pacticipant_name, open_struct_pacticipant)
repository_url: open_struct_pacticipant.repository_url,
repository_name: open_struct_pacticipant.repository_name,
repository_namespace: open_struct_pacticipant.repository_namespace,
main_development_branches: open_struct_pacticipant.main_development_branches || []
main_branch: open_struct_pacticipant.main_branch
).save
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/create_pacticipant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:pacticipant_hash) do
{
name: 'Foo Thing',
mainDevelopmentBranches: ["main"],
mainBranch: "main",
repositoryUrl: "http://url",
repositoryName: "foo-thing",
repositoryNamespace: "some-group"
Expand Down
4 changes: 2 additions & 2 deletions spec/features/update_pacticipant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
repositoryUrl: "http://foo",
repositoryName: "name",
repositoryNamespace: "org",
mainDevelopmentBranches: ["main"]
mainBranch: "main"
}
end

subject { put(path, request_body_hash.to_json, {'CONTENT_TYPE' => 'application/json' }) }
subject { put(path, request_body_hash.to_json, { 'CONTENT_TYPE' => 'application/json' }) }

context "when the pacticipant exists" do
before do
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/pact_broker/api/contracts/pacticipant_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ module Contracts
{
name: "pact-broker",
displayName: "Pact Broker",
mainDevelopmentBranches: branches,
mainBranch: main_branch,
repositoryUrl: "https://github.com/pact-foundation/pact_broker",
repositoryName: "pact_broker",
repositoryNamespace: "pact-foundation"
}
end

let(:branches) { ["main"] }
let(:main_branch) { "main" }

subject { PacticipantSchema.call(params) }

Expand All @@ -36,9 +36,9 @@ module Contracts
end

context "with branch names that contain spaces" do
let(:branches) { ["main foo"] }
let(:main_branch) { "main foo" }

its([:mainDevelopmentBranches, 0]) { is_expected.to include "cannot contain spaces" }
its([:mainBranch, 0]) { is_expected.to include "cannot contain spaces" }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ module Decorators
let(:hash) do
{
name: "Foo",
mainDevelopmentBranches: ["main"]
mainBranch: "main"
}
end

subject { decorator.from_json(hash.to_json) }

its(:name) { is_expected.to eq "Foo" }
its(:main_development_branches) { is_expected.to eq ["main"] }
its(:main_branch) { is_expected.to eq "main" }
end
describe "to_json" do
let(:pacticipant) do
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/pact_broker/pacticipants/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module Pacticipants

let(:display_name) { "Foo" }

subject { repository.create(name: "foo", display_name: display_name, repository_url: "url", main_development_branches: ["main"]) }
subject { repository.create(name: "foo", display_name: display_name, repository_url: "url", main_branch: "main") }

it "returns the new pacticipant" do
expect(subject).to be_a(PactBroker::Domain::Pacticipant)
expect(subject.name).to eq "foo"
expect(subject.main_development_branches).to eq ["main"]
expect(subject.main_branch).to eq "main"
expect(subject.repository_url).to eq "url"
expect(subject.display_name).to eq "Foo"
end
Expand Down Expand Up @@ -56,14 +56,14 @@ module Pacticipants

describe "replace" do
before do
td.create_pacticipant("Bar", main_development_branches: ["foo"], repository_namespace: "foo")
td.create_pacticipant("Bar", main_branch: "foo", repository_namespace: "foo")
allow_any_instance_of(PactBroker::Domain::Pacticipant).to receive(:generate_display_name).and_return("display_name")
end

subject { Repository.new.replace("Bar", OpenStruct.new(main_development_branches: ["bar"], repository_url: "new_url")) }
subject { Repository.new.replace("Bar", OpenStruct.new(main_branch: "bar", repository_url: "new_url")) }

it "replaces the pacticipant" do
expect(subject.main_development_branches).to eq ["bar"]
expect(subject.main_branch).to eq "bar"
expect(subject.repository_namespace).to eq nil
expect(subject.display_name).to eq "display_name"
end
Expand Down

0 comments on commit 02d4525

Please sign in to comment.