Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes tests and updates dry validation version #2

Merged
merged 3 commits into from
Jan 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cache: bundler
language: ruby
rvm:
- 2.0
- 2.1
- 2.2
- 2.3.0
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class AuthenticateUser
include Interactor::Contracts

expects do
attr(:email) { |email| email.filled? }
attr(:password) { |password| password.filled? }
required(:email).filled
required(:password).filled
end

assures do
attr(:user) { |user| user.filled? }
attr(:token) { |token| token.filled? }
required(:user).filled
required(:token).filled
end

def call
Expand Down
2 changes: 1 addition & 1 deletion interactor-contracts.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.files += Dir["lib/**/*.rb"]
spec.require_paths = ["lib"]

spec.add_dependency "dry-validation", "~> 0.7", "< 0.8"
spec.add_dependency "dry-validation"
spec.add_dependency "interactor", "~> 3"

spec.add_development_dependency "bundler", "~> 1.11"
Expand Down
10 changes: 5 additions & 5 deletions lib/interactor/contracts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def assurances
# include Interactor::Contracts
#
# assures do
# attr(:person, &:filled?)
# required(:person).filled
# end
#
# def call
Expand Down Expand Up @@ -68,7 +68,7 @@ def default_violation_handler
# include Interactor::Contracts
#
# expects do
# attr(:name, &:filled?)
# required(:name).filled
# end
#
# def call
Expand Down Expand Up @@ -102,7 +102,7 @@ def expectations
# include Interactor::Contracts
#
# expects do
# attr(:name, &:filled?)
# required(:name).filled
# end
#
# on_violation do |violations|
Expand Down Expand Up @@ -164,7 +164,7 @@ def define_assurances_hook

after do
assurances = self.class.assurances.new
result = assurances.call(context)
result = assurances.call(context.to_h)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this throwing an error? Since the Interactor::Context object is based on OpenStruct, it used to be handled automatically by dry-validation. I would rather rely on dry-validation's handling of OpenStructs if possible.

I'm guessing it was due to how the required macro works?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when I started testing it it was raising a NoMethodError: undefined method key?' for, it seems dry-validation started checking for keys using #key?` method which doesn't exist in OpenStruct neither Context.


unless result.success?
violations = result.messages.map do |property, messages|
Expand All @@ -189,7 +189,7 @@ def define_expectations_hook

before do
expectations = self.class.expectations.new
result = expectations.call(context)
result = expectations.call(context.to_h)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above with the other call to #to_h.


unless result.success?
violations = result.messages.map do |property, messages|
Expand Down
28 changes: 14 additions & 14 deletions spec/interactor/contracts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include Interactor::Contracts

assures do
attr(:name).required
required(:name).filled
end

def call
Expand All @@ -36,11 +36,11 @@ def call
include Interactor::Contracts

assures do
attr(:first_name).required
required(:first_name).filled
end

assures do
attr(:last_name).required
required(:last_name).filled
end

def call
Expand All @@ -61,11 +61,11 @@ def call
include Interactor::Contracts

assures do
attr(:first_name).required
required(:first_name).filled
end

assures do
attr(:last_name).required
required(:last_name).filled
end

def call
Expand All @@ -87,7 +87,7 @@ def call
include Interactor::Contracts

expects do
attr(:name).required
required(:name).filled
end
end

Expand All @@ -101,11 +101,11 @@ def call
include Interactor::Contracts

expects do
attr(:first_name).required
required(:first_name).filled
end

expects do
attr(:last_name).required
required(:last_name).filled
end
end

Expand All @@ -124,11 +124,11 @@ def call
include Interactor::Contracts

expects do
attr(:first_name).required
required(:first_name).filled
end

expects do
attr(:last_name).required
required(:last_name).filled
end
end

Expand All @@ -142,7 +142,7 @@ def call
include Interactor
include Interactor::Contracts

expects { attr(:name).required }
expects { required(:name).filled }

on_violation { |_| context[:message] = "Bilbo Baggins!" }
end
Expand All @@ -158,7 +158,7 @@ def call
include Interactor
include Interactor::Contracts

assures { attr(:name).required }
assures { required(:name).filled }

on_violation { |_| context[:message] = "Bilbo Baggins!" }
end
Expand All @@ -174,7 +174,7 @@ def call
include Interactor
include Interactor::Contracts

expects { attr(:name).required }
expects { required(:name).filled }

on_violation { |_| context[:silly] = "You did something silly." }
on_violation { |_| context.fail!(:message => "Bilbo Baggins!") }
Expand All @@ -192,7 +192,7 @@ def call
include Interactor
include Interactor::Contracts

expects { attr(:name).required }
expects { required(:name).filled }

on_violation { |_| context.fail!(:message => "Bilbo Baggins!") }
on_violation { |_| context[:wont_be_set] = "Nope" }
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
require 'simplecov'
SimpleCov.start
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get the codeclimate-test-reporter to work again, but that's outside the scope of this right now.


if ENV["COVERAGE"] || ENV["CI"]
require "simplecov"
Expand Down