Skip to content

Commit

Permalink
Merge pull request #17 from rewinfrey/version-0.3.3
Browse files Browse the repository at this point in the history
Release version 0.3.3
  • Loading branch information
rewinfrey authored Jun 9, 2022
2 parents 41a0fad + 660732e commit 9341e76
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 94 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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']
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
67 changes: 32 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
PATH
remote: .
specs:
action_logic (0.3.0)
action_logic (0.3.3)

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
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 5 additions & 5 deletions action_logic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions lib/action_logic/action_validation/presence_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/action_logic/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActionLogic
VERSION = '0.3.2'
VERSION = '0.3.3'
end
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/action_logic/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions spec/fixtures/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
44 changes: 2 additions & 42 deletions spec/fixtures/use_cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

0 comments on commit 9341e76

Please sign in to comment.