From d0583273f1d271c9d2505657abd702a6a87d4624 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:09:42 -0700 Subject: [PATCH 01/11] Rename active_use_case_spec to action_use_case_spec --- .../{active_use_case_spec.rb => action_use_case_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/action_logic/{active_use_case_spec.rb => action_use_case_spec.rb} (100%) diff --git a/spec/action_logic/active_use_case_spec.rb b/spec/action_logic/action_use_case_spec.rb similarity index 100% rename from spec/action_logic/active_use_case_spec.rb rename to spec/action_logic/action_use_case_spec.rb From d946e98ccb21f6ec910f53e5a35b9b93f4f524f5 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:17:20 -0700 Subject: [PATCH 02/11] Update configuration spec to remove no longer valid yield --- spec/action_logic/configuration_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/action_logic/configuration_spec.rb b/spec/action_logic/configuration_spec.rb index e76a2a3..e628469 100644 --- a/spec/action_logic/configuration_spec.rb +++ b/spec/action_logic/configuration_spec.rb @@ -63,7 +63,7 @@ class CustomFormatter; end end it "uses a custom benchmark handler if one is provided" do - custom_benchmark_handler = -> { yield } + custom_benchmark_handler = -> {} described_class.configure do |config| config.benchmark_handler = custom_benchmark_handler From 46bb18f50618bcdbad952c3b29cff63ed3b5e6a0 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:19:08 -0700 Subject: [PATCH 03/11] Move ActionTask test fixtures from spec/fixtures/use_cases -> spec/fixtures/tasks --- spec/fixtures/tasks.rb | 40 ++++++++++++++++++++++++++++++++++++++ spec/fixtures/use_cases.rb | 40 -------------------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/spec/fixtures/tasks.rb b/spec/fixtures/tasks.rb index b858ac5..625a4ad 100644 --- a/spec/fixtures/tasks.rb +++ b/spec/fixtures/tasks.rb @@ -284,4 +284,44 @@ def call context.halt!(Constants::HALT_MESSAGE) end end + +class UseCaseTestTask1 + include ActionLogic::ActionTask + + def call + context.first = "first" + end +end + +class UseCaseTestTask2 + include ActionLogic::ActionTask + + def call + context.second = "second" + end +end + +class UseCaseTestTask3 + include ActionLogic::ActionTask + + def call + context.third = "third" + end +end + +class UseCaseFailureTestTask + include ActionLogic::ActionTask + + def call + context.fail!(Constants::FAILURE_MESSAGE) + end +end + +class UseCaseHaltTestTask + include ActionLogic::ActionTask + + def call + context.halt!(Constants::HALT_MESSAGE) + end +end # :nocov: diff --git a/spec/fixtures/use_cases.rb b/spec/fixtures/use_cases.rb index 2bb0466..7ccb760 100644 --- a/spec/fixtures/use_cases.rb +++ b/spec/fixtures/use_cases.rb @@ -392,44 +392,4 @@ def tasks UseCaseTestTask3] end end - -class UseCaseTestTask1 - include ActionLogic::ActionTask - - def call - context.first = "first" - end -end - -class UseCaseTestTask2 - include ActionLogic::ActionTask - - def call - context.second = "second" - end -end - -class UseCaseTestTask3 - include ActionLogic::ActionTask - - def call - context.third = "third" - end -end - -class UseCaseFailureTestTask - include ActionLogic::ActionTask - - def call - context.fail!(Constants::FAILURE_MESSAGE) - end -end - -class UseCaseHaltTestTask - include ActionLogic::ActionTask - - def call - context.halt!(Constants::HALT_MESSAGE) - end -end # :nocov: From f5fc454199a51f3e0dc1fcd9bc4a13f7644cf3e9 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:38:15 -0700 Subject: [PATCH 04/11] Update mixed custom presence and type spec fixture to exercise failure scenarios --- spec/fixtures/use_cases.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/fixtures/use_cases.rb b/spec/fixtures/use_cases.rb index 7ccb760..67ae44c 100644 --- a/spec/fixtures/use_cases.rb +++ b/spec/fixtures/use_cases.rb @@ -192,8 +192,8 @@ def tasks class ValidateBeforeMixedTypeAndPresenceUseCase include ActionLogic::ActionUseCase - validates_before odd_integer_test: { presence: ->(i) { i % 2 != 0 } }, - string_test: { type: String, presence: true } + validates_before odd_integer_test: { type: Integer, presence: ->(i) { i % 2 != 0 }, type: Integer }, + string_test: { presence: false, type: String } def call end From cca2d086e90b1b5fc947818b27109d59b80b3f29 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:38:36 -0700 Subject: [PATCH 05/11] Update type validation is not satisfied test case --- spec/action_logic/action_use_case_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/action_logic/action_use_case_spec.rb b/spec/action_logic/action_use_case_spec.rb index c5f2081..7a6fd13 100644 --- a/spec/action_logic/action_use_case_spec.rb +++ b/spec/action_logic/action_use_case_spec.rb @@ -164,7 +164,7 @@ module ActionLogic end it "raises error if type validation is not satisfied" do - expect { ValidateBeforeMixedTypeAndPresenceUseCase.execute(odd_integer_test: 1, string_test: 15) }.to \ + expect { ValidateBeforeMixedTypeAndPresenceUseCase.execute(odd_integer_test: "String", string_test: 15) }.to \ raise_error(ActionLogic::AttributeTypeError) end From bcc641854af8683d55a2cd3d69a76e390a22323f Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:40:21 -0700 Subject: [PATCH 06/11] Bump all dev dependencies --- Gemfile.lock | 65 +++++++++++++++++++++----------------------- action_logic.gemspec | 10 +++---- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a1f72a8..ad0cef5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,49 +6,46 @@ PATH GEM remote: https://rubygems.org/ specs: - codecov (0.1.14) - json - simplecov - url - coderay (1.1.2) - diff-lcs (1.3) - docile (1.3.1) - json (2.1.0) - method_source (0.9.2) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rake (13.0.1) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + codecov (0.6.0) + simplecov (>= 0.15, < 0.22) + coderay (1.1.3) + diff-lcs (1.5.0) + docile (1.4.0) + method_source (1.0.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + rake (13.0.6) + rspec (3.11.0) + rspec-core (~> 3.11.0) + rspec-expectations (~> 3.11.0) + rspec-mocks (~> 3.11.0) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - simplecov (0.16.1) + rspec-support (~> 3.11.0) + rspec-support (3.11.0) + simplecov (0.21.2) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - url (0.3.2) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) PLATFORMS ruby DEPENDENCIES action_logic! - codecov (~> 0.1.14) - pry (~> 0.12.2) - rake (~> 13.0.1) - rspec (~> 3.8) - simplecov (~> 0.16.1) + codecov (~> 0.6.0) + pry (~> 0.14.1) + rake (~> 13.0.6) + rspec (~> 3.11) + simplecov (~> 0.21.2) BUNDLED WITH 1.17.2 diff --git a/action_logic.gemspec b/action_logic.gemspec index a56f698..b4cb35f 100644 --- a/action_logic.gemspec +++ b/action_logic.gemspec @@ -17,9 +17,9 @@ Gem::Specification.new do |s| s.date = '2018-12-17' s.description = 'Provides common interfaces for validating and abstracting business logic' - s.add_development_dependency("rspec", "~> 3.8") - s.add_development_dependency("pry", "~> 0.12.2") - s.add_development_dependency("rake", "~> 13.0.1") - s.add_development_dependency("simplecov", "~> 0.16.1") - s.add_development_dependency("codecov", "~> 0.1.14") + s.add_development_dependency("rspec", "~> 3.11") + s.add_development_dependency("pry", "~> 0.14.1") + s.add_development_dependency("rake", "~> 13.0.6") + s.add_development_dependency("simplecov", "~> 0.21.2") + s.add_development_dependency("codecov", "~> 0.6.0") end From 2fb7d02ad0406a6ea21df6b33626deb69d1086d9 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:40:43 -0700 Subject: [PATCH 07/11] Release version 0.3.3 --- Gemfile.lock | 2 +- lib/action_logic/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ad0cef5..65c9641 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - action_logic (0.3.0) + action_logic (0.3.3) GEM remote: https://rubygems.org/ diff --git a/lib/action_logic/version.rb b/lib/action_logic/version.rb index 8b250d2..6403504 100644 --- a/lib/action_logic/version.rb +++ b/lib/action_logic/version.rb @@ -1,3 +1,3 @@ module ActionLogic - VERSION = '0.3.2' + VERSION = '0.3.3' end From 21d2c059207ba9d8a5bb6f3d16112a4d4c19ca4f Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 22:53:54 -0700 Subject: [PATCH 08/11] Add Test workflow --- .github/workflows/test.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..dcac8bc --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,18 @@ +name: Test +on: [push, pull_request] +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' + ruby: ['2.7', '3.0', '3.1', head] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec rspec spec From 44495b16476b3088d869e753ec76104c07b2e984 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Mon, 6 Jun 2022 23:03:19 -0700 Subject: [PATCH 09/11] Slight tweaks to README --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a544239..9d7931f 100644 --- a/README.md +++ b/README.md @@ -58,12 +58,11 @@ includes an item that your e-commerce store no longer stocks? What happens if an you add more and more logic to that controller action. What once was a simple controller action designed with only the happy path of a successful checkout in mind has now become 100 lines long with 5 to 10 levels -of nested if statements. The voice of Uncle Bob starts ringing in your ears and you know there must be a better way. You think on it for awhile and consider not only -the technical challenges of refactoring this code, but you'd also like to make this code reusable and modular. You want this code to be easy to test and easy to maintain. -You want to honor the SOLID principles by writing classes that are singularly focused and easy to extend. You reason these new classes should only have to change if the -business logic they execute changes. You see that there are relationships between the entities and you see the possibility of abstractions that allow entities of similar types -to interact nicely with each other. You begin thinking about interfaces and the Liskov Substitution Principle, and eventually your mind turns towards domains and data modeling. -Where does it end you wonder? +of nested if statements. You think on it for awhile and consider not only the technical challenges of refactoring this code, but you'd also like to make this code +reusable and modular. You want this code to be easy to test and easy to maintain. You want to honor the SOLID principles by writing classes that are singularly focused +and easy to extend. You reason these new classes should only have to change if the business logic they execute changes. You see that there are relationships between the +entities and you see the possibility of abstractions that allow entities of similar types to interact nicely with each other. You begin thinking about interfaces and the +Liskov Substitution Principle, and eventually your mind turns towards domains and data modeling. Where does it end you wonder? But you remember your team. It's a team of people all wanting to do their best, and represent a variety of backgrounds and experiences. Each person has varying degress of familiarity with different types of abstractions and approaches, and you wonder what abstractions might be as easy to work with for a new developer as they are for an experienced developer? From e22df68662154da461ce1ae118e4baae82b4eb24 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Thu, 9 Jun 2022 09:01:23 -0700 Subject: [PATCH 10/11] Update ActionValidation::PresenceValidation --- lib/action_logic/action_validation/presence_validation.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/action_logic/action_validation/presence_validation.rb b/lib/action_logic/action_validation/presence_validation.rb index d9e8d98..18361ef 100644 --- a/lib/action_logic/action_validation/presence_validation.rb +++ b/lib/action_logic/action_validation/presence_validation.rb @@ -14,9 +14,8 @@ def self.validate!(validation_rules, context) def self.presence_errors(validation_rules, context) validation_rules.reduce([]) do |error_collection, (expected_attribute, expected_validation)| next error_collection unless expected_validation[:presence] - error_collection << error_message(expected_attribute, expected_validation, context) - error_collection - end + error_collection << error_message(expected_attribute, expected_validation, context) + error_collection end || [] end From 660732e840eb30a112656afd05200b5785223670 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Thu, 9 Jun 2022 09:05:28 -0700 Subject: [PATCH 11/11] Update test workflow action to not test against head --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dcac8bc..1e184dd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' - ruby: ['2.7', '3.0', '3.1', head] + ruby: ['2.7', '3.0', '3.1'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3