-
Notifications
You must be signed in to change notification settings - Fork 1
Add Dry Types gem and apply to Job.add #21
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| require_relative "../../types" | ||
|
|
||
| module XpmRuby | ||
| module Schema | ||
| module Job | ||
| Add = Types::Hash.schema( | ||
| "Name" => Types::String, | ||
| "Description" => Types::String, | ||
| "ClientID" => Types::Coercible::String, | ||
| "ContactID?" => Types::Coercible::String, | ||
| "StartDate" => Types::Coercible::String, | ||
| "DueDate" => Types::Coercible::String, | ||
| "ClientNumber?" => Types::Coercible::String, | ||
| "ID?" => Types::Coercible::String, | ||
| "TemplateID?" => Types::Coercible::String, | ||
| "CategoryID?" => Types::Coercible::String, | ||
| "Budget?" => Types::Coercible::String | ||
| ) | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,7 @@ | ||
| require "dry-types" | ||
|
|
||
| module XpmRuby | ||
| module Types | ||
| include Dry.Types() | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,27 @@ | ||
| require "spec_helper" | ||
|
|
||
| module XpmRuby | ||
| module Schema | ||
| RSpec.describe(Job) do | ||
| context "with a valid Add schema" do | ||
| it "should not raise an error" do | ||
| hash = { "Name" => "Joe Bloggs", "Description" => "New Job", "ClientID" => 1234, "StartDate" => 20091023, "DueDate" => 20091023 } | ||
| expect { Job::Add[hash] }.not_to raise_error | ||
| end | ||
|
|
||
| it "should coerce the types" do | ||
| hash = { "Name" => "Joe Bloggs", "Description" => "New Job", "ClientID" => 1234, "StartDate" => 20091023, "DueDate" => 20091023 } | ||
| add = Job::Add[hash] | ||
| expect(add["ClientID"]).to eql("1234") | ||
| end | ||
| end | ||
|
|
||
| context "with an invalid Add schema" do | ||
| it "should raise an error" do | ||
| hash = { "Name" => "Joe Bloggs" } | ||
| expect { Job::Add[hash] }.to raise_error(Dry::Types::ConstraintError, '{"Name"=>"Joe Bloggs"} violates constraints (:Description is missing in Hash input failed)') | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder how we could drop all the
::operations? Maybe something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I will have a think about it. I was following the structure from the client success gem. I think if we keep them in the same relative place in all our gems it might make it easier for our devs to work across gems.
But then again I am not 100% why the client success gem was structured this way.
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose one argument for a dedicated schema directory is that theoretically a data structure could be independent of the actions? So xpm_ruby/job.rb is a module containing job related functions, but it is not a class per se. Theoretically any module could access any schema (so one of the calls on client, might use the job schema).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this for now, we can always move it later (pending a discussion).