-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(can_be_negated): introduce Result#negated?
- Loading branch information
Showing
9 changed files
with
104 additions
and
0 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
1 change: 1 addition & 0 deletions
1
lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.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
3 changes: 3 additions & 0 deletions
3
...nient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_negated.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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "can_be_negated/concern" |
30 changes: 30 additions & 0 deletions
30
...rvice/service/plugins/has_j_send_result/entities/result/plugins/can_be_negated/concern.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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasJSendResult | ||
module Entities | ||
class Result | ||
module Plugins | ||
module CanBeNegated | ||
module Concern | ||
include Support::Concern | ||
|
||
instance_methods do | ||
## | ||
# @return [Boolean] | ||
# | ||
def negated? | ||
Utils.to_bool(extra_kwargs[:negated]) | ||
end | ||
end | ||
end | ||
end | ||
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
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
65 changes: 65 additions & 0 deletions
65
.../service/plugins/has_j_send_result/entities/result/plugins/can_be_negated/concern_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,65 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeNegated::Concern do | ||
include ConvenientService::RSpec::PrimitiveMatchers::CacheItsValue | ||
|
||
example_group "modules" do | ||
include ConvenientService::RSpec::Matchers::IncludeModule | ||
|
||
subject { described_class } | ||
|
||
it { is_expected.to include_module(ConvenientService::Support::Concern) } | ||
|
||
context "when included" do | ||
subject { result_class } | ||
|
||
let(:result_class) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
it { is_expected.to include_module(described_class::InstanceMethods) } | ||
end | ||
end | ||
|
||
example_group "instance methods" do | ||
describe "#negated?" do | ||
let(:result) { service.result } | ||
|
||
let(:service) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Standard | ||
|
||
def result | ||
success | ||
end | ||
end | ||
end | ||
|
||
context "when result is NOT from `negated_result` method" do | ||
let(:result) { service.result } | ||
|
||
it "returns `false`" do | ||
expect(result.negated_result?).to eq(false) | ||
end | ||
end | ||
|
||
context "when result is from `negated_result` method" do | ||
let(:result) { service.negated_result } | ||
|
||
it "returns `true`" do | ||
expect(result.negated_result?).to eq(true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |