-
Notifications
You must be signed in to change notification settings - Fork 88
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
Adding transaction raise methods #232
Merged
robacarp
merged 17 commits into
amberframework:master
from
Thellior:adding-transactions-raise-methods
Jun 21, 2018
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c59aa5c
Added save! method
Thellior 3e09cac
Added destroy! method
Thellior 22ade91
Added create! method
Thellior f5da1f1
Added nil? check on create!
Thellior a2267ce
Changed nil check to errors check
Thellior caaf77b
Review changes
Thellior 8db8810
Update transactions.cr
Thellior c851203
Added custom exceptions and added tests for them
Thellior f8e16f6
Removed Nil type because i fixed an bug than produced Nil values
Thellior 1d83b77
Added update and update! methods
Thellior 75aeaa5
Changed other spec files with persisted? where possible
Thellior 789ade9
Using callback model in the spec_models instead of introducing an new…
Thellior 4952793
Docker does not cleanup callback model properly. abort_at = 'temp' fixes
Thellior e6e64c7
Forgot to change to save! again
Thellior 157eb48
Merge branch 'master' into adding-transactions-raise-methods
faustinoaq 41dc2a7
RecordInvalid to RecordNotSaved and model is now attached to the errors
Thellior 46ca75c
Added new methods to the README.md
Thellior 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 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" | ||
|
||
{% for adapter in GraniteExample::ADAPTERS %} | ||
module {{adapter.capitalize.id}} | ||
describe Granite::RecordNotSaved do | ||
it "should have a message" do | ||
parent = Parent.new | ||
parent.save | ||
|
||
Granite::RecordNotSaved | ||
.new(Parent.name, parent) | ||
.message | ||
.should eq("Could not process {{adapter.capitalize.id}}::Parent") | ||
end | ||
|
||
it "should have a model" do | ||
parent = Parent.new | ||
parent.save | ||
|
||
Granite::RecordNotSaved | ||
.new(Parent.name, parent) | ||
.model | ||
.should eq(parent) | ||
end | ||
end | ||
end | ||
{% end %} |
This file contains 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" | ||
|
||
{% for adapter in GraniteExample::ADAPTERS %} | ||
module {{adapter.capitalize.id}} | ||
describe Granite::RecordNotDestroyed do | ||
it "should have a message" do | ||
parent = Parent.new | ||
parent.save | ||
|
||
Granite::RecordNotDestroyed | ||
.new(Parent.name, parent) | ||
.message | ||
.should eq("Could not destroy {{adapter.capitalize.id}}::Parent") | ||
end | ||
|
||
it "should have a model" do | ||
parent = Parent.new | ||
parent.save | ||
|
||
Granite::RecordNotDestroyed | ||
.new(Parent.name, parent) | ||
.model | ||
.should eq(parent) | ||
end | ||
end | ||
end | ||
{% end %} |
This file contains 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 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 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 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,50 @@ | ||
require "../../spec_helper" | ||
|
||
{% for adapter in GraniteExample::ADAPTERS %} | ||
module {{adapter.capitalize.id}} | ||
describe "{{ adapter.id }} #update" do | ||
it "updates an object" do | ||
parent = Parent.new(name: "New Parent") | ||
parent.save! | ||
|
||
parent.update(name: "Other parent").should be_true | ||
parent.name.should eq "Other parent" | ||
|
||
Parent.find!(parent.id).name.should eq "Other parent" | ||
end | ||
|
||
it "does not update an invalid object" do | ||
parent = Parent.new(name: "New Parent") | ||
parent.save! | ||
|
||
parent.update(name: "").should be_false | ||
parent.name.should eq "" | ||
|
||
Parent.find!(parent.id).name.should eq "New Parent" | ||
end | ||
end | ||
|
||
describe "{{ adapter.id }} #update!" do | ||
it "updates an object" do | ||
parent = Parent.new(name: "New Parent") | ||
parent.save! | ||
|
||
parent.update!(name: "Other parent") | ||
parent.name.should eq "Other parent" | ||
|
||
Parent.find!(parent.id).name.should eq "Other parent" | ||
end | ||
|
||
it "does not update but raises an exception" do | ||
parent = Parent.new(name: "New Parent") | ||
parent.save! | ||
|
||
expect_raises(Granite::RecordNotSaved, "{{adapter.capitalize.id}}::Parent") do | ||
parent.update!(name: "") | ||
end | ||
|
||
Parent.find!(parent.id).name.should eq "New Parent" | ||
end | ||
end | ||
end | ||
{% end %} |
This file contains 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 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 @@ | ||
module Granite | ||
class RecordNotSaved < ::Exception | ||
getter model : Granite::Base | ||
|
||
def initialize(class_name : String, model : Granite::Base) | ||
super("Could not process #{class_name}") | ||
|
||
@model = model | ||
end | ||
end | ||
|
||
class RecordNotDestroyed < ::Exception | ||
getter model : Granite::Base | ||
|
||
def initialize(class_name : String, model : Granite::Base) | ||
super("Could not destroy #{class_name}") | ||
|
||
@model = model | ||
end | ||
end | ||
end |
This file contains 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.
❤️