Skip to content

Commit

Permalink
feat(core): add method_missing_commits_counter
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Mar 15, 2023
1 parent 7438742 commit 9f143a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/convenient_service/core/entities/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ def middlewares(method, scope: :instance, &configuration_block)
@middlewares[scope][method] || Entities::MethodMiddlewares.new(scope: scope, method: method, klass: klass)
end

##
# @return [ConvenientService::Support::ThreadSafeCounter]
#
def method_missing_commits_counter
@method_missing_commits_counter ||= Support::ThreadSafeCounter.new(max_value: Constants::Commits::METHOD_MISSING_MAX_TRIES)
end

##
# @return [Boolean]
#
Expand Down
24 changes: 24 additions & 0 deletions spec/lib/convenient_service/core/entities/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,30 @@ def next(...)
end
end

describe "#method_missing_commits_counter" do
it "returns `ConvenientService::Support::ThreadSafeCounter` instance" do
expect(config.method_missing_commits_counter).to be_instance_of(ConvenientService::Support::ThreadSafeCounter)
end

specify do
expect { config.method_missing_commits_counter }.to cache_its_value
end

example_group "`counter`" do
it "has initial value set to `0`" do
expect(config.method_missing_commits_counter.current_value).to eq(0)
end

it "has current value same as initial value" do
expect(config.method_missing_commits_counter.current_value).to eq(config.method_missing_commits_counter.initial_value)
end

it "has max value set to `ConvenientService::Core::Constants::Commits::METHOD_MISSING_MAX_TRIES`" do
expect(config.method_missing_commits_counter.max_value).to eq(ConvenientService::Core::Constants::Commits::METHOD_MISSING_MAX_TRIES)
end
end
end

describe "#committed?" do
before do
##
Expand Down

0 comments on commit 9f143a0

Please sign in to comment.