-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(entry): allow to define multiple entries at once
- Loading branch information
Showing
7 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
lib/convenient_service/feature/plugins/can_have_entries/commands.rb
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,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "commands/define_entries" | ||
require_relative "commands/define_entry" |
49 changes: 49 additions & 0 deletions
49
lib/convenient_service/feature/plugins/can_have_entries/commands/define_entries.rb
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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Feature | ||
module Plugins | ||
module CanHaveEntries | ||
module Commands | ||
class DefineEntries < Support::Command | ||
## | ||
# @!attribute [r] feature_class | ||
# @return [Class] | ||
# | ||
attr_reader :feature_class | ||
|
||
## | ||
# @!attribute [r] names | ||
# @return [Array<String, Symbol>] | ||
# | ||
attr_reader :names | ||
|
||
## | ||
# @!attribute [r] body | ||
# @return [Proc, nil] | ||
# | ||
attr_reader :body | ||
|
||
## | ||
# @param feature_class [Class] | ||
# @param names [Array<String, Symbol>] | ||
# @param body [Proc, nil] | ||
# | ||
def initialize(feature_class:, names:, body:) | ||
@feature_class = feature_class | ||
@names = names | ||
@body = body | ||
end | ||
|
||
## | ||
# @return [Array<String, Symbol>] | ||
# | ||
def call | ||
names.map { |name| Commands::DefineEntry.call(feature_class: feature_class, name: name, body: body) } | ||
end | ||
end | ||
end | ||
end | ||
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
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
73 changes: 73 additions & 0 deletions
73
spec/lib/convenient_service/feature/plugins/can_have_entries/commands/define_entries_spec.rb
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::Feature::Plugins::CanHaveEntries::Commands::DefineEntries do | ||
example_group "class methods" do | ||
describe ".call" do | ||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
subject(:command_result) { described_class.call(feature_class: feature_class, names: names, body: body) } | ||
|
||
let(:feature_class) do | ||
Class.new do | ||
include ConvenientService::Feature::Configs::Standard | ||
end | ||
end | ||
|
||
let(:feature_instance) { feature_class.new } | ||
|
||
let(:body) { proc { |*args, **kwargs, &block| [__method__, args, kwargs, block] } } | ||
|
||
context "when NO names are passed" do | ||
let(:names) { [] } | ||
|
||
it "returns empty array" do | ||
expect(command_result).to eq([]) | ||
end | ||
|
||
specify do | ||
expect { command_result }.not_to delegate_to(ConvenientService::Feature::Plugins::CanHaveEntries::Commands::DefineEntry, :call) | ||
end | ||
end | ||
|
||
context "when one name is passed" do | ||
let(:names) { [:foo] } | ||
|
||
it "returns that one name wrapped by array" do | ||
expect(command_result).to eq([:foo]) | ||
end | ||
|
||
specify do | ||
expect { command_result } | ||
.to delegate_to(ConvenientService::Feature::Plugins::CanHaveEntries::Commands::DefineEntry, :call) | ||
.with_arguments(feature_class: feature_class, name: names.first, body: body) | ||
end | ||
end | ||
|
||
context "when multiple names are passed" do | ||
let(:names) { [:foo, :bar] } | ||
|
||
it "returns those multiple names" do | ||
expect(command_result).to eq([:foo, :bar]) | ||
end | ||
|
||
specify do | ||
expect { command_result } | ||
.to delegate_to(ConvenientService::Feature::Plugins::CanHaveEntries::Commands::DefineEntry, :call) | ||
.with_arguments(feature_class: feature_class, name: names.first, body: body) | ||
end | ||
|
||
specify do | ||
expect { command_result } | ||
.to delegate_to(ConvenientService::Feature::Plugins::CanHaveEntries::Commands::DefineEntry, :call) | ||
.with_arguments(feature_class: feature_class, name: names.last, body: body) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |
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