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

[WIP] Operation Refactor Sandbox #369

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d0aca2c
initial refactor of Operations. Specs are moved to their own folder t…
jwoertink May 21, 2020
b3e0b66
callbacks are working on operations now. This includes enabling after…
jwoertink May 21, 2020
c910613
stuck on crystal compilation llvm error...
jwoertink May 22, 2020
e6c878b
renamed save operation errors to just operation errors
jwoertink May 22, 2020
38accb0
Had to comment some stuff out, but individual operation specs are sta…
jwoertink May 22, 2020
822edea
Operations can use validations like normal now. Added new validate_si…
jwoertink May 23, 2020
70c61e0
Adding a bit of documentation
jwoertink May 23, 2020
83c559d
oops
jwoertink May 23, 2020
68d6641
slowly adding SaveOperation stuff back in. All current operation spec…
jwoertink May 23, 2020
c1f1947
still working through getting SaveOperation to compile
jwoertink May 24, 2020
b02502d
commented out the Box stuff so I can get SaveOperation to compile. Cr…
jwoertink May 25, 2020
7b8f34b
more work on trying to get around the crystal Invalid Memory error
jwoertink May 26, 2020
89569d5
resolve merge conflicts.
jwoertink Aug 1, 2020
5fc4b58
Merge master branch. Resolved conflicts
jwoertink Sep 18, 2020
78565a7
Merge master and resolve conflicts
jwoertink Sep 18, 2020
f8affb5
getting the base_spec to pass again
jwoertink Sep 18, 2020
655ce96
define_attribute_spec is now passing again
jwoertink Sep 18, 2020
312ad75
operation callbacks are working
jwoertink Sep 18, 2020
302f824
operation_needs_spec is passing
jwoertink Sep 18, 2020
3c354d8
validation specs are passing
jwoertink Sep 18, 2020
58b90bc
Moving Operation related mixins to it's own directory to avoid me cre…
jwoertink Sep 18, 2020
396711c
A basic SaveOperation runs with passing specs
jwoertink Sep 18, 2020
817b155
All callbacks working on SaveOperation again
jwoertink Sep 18, 2020
9494e87
Splitting Operation and SaveOperation in to different compositions to…
jwoertink Sep 21, 2020
22ba44d
separated callbacks out since each type of operation won't get the sa…
jwoertink Sep 22, 2020
0a7accf
save operations can use needs properly now
jwoertink Sep 22, 2020
5afded4
Adding boxes back in
jwoertink Sep 22, 2020
a0bc40e
SaveOperation validations are passing again
jwoertink Sep 22, 2020
afcbbe0
ran formatter and ameba to clean up some stuff
jwoertink Sep 22, 2020
b4aa4ed
All current save operation specs are now passing
jwoertink Sep 22, 2020
6ebdebf
make ameba happy
jwoertink Sep 22, 2020
6ae227c
all specs run now, but some are still failing
jwoertink Sep 22, 2020
b670f58
Adding nested save operations back in
jwoertink Sep 22, 2020
0dc0aac
Added spec for file_attribute back in
jwoertink Sep 22, 2020
60451d9
Added another missing spec
jwoertink Sep 22, 2020
0b2c29b
Added a way to skip callbacks
jwoertink Sep 23, 2020
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
10 changes: 10 additions & 0 deletions spec/box_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,14 @@ describe Avram::Box do
tags.last.name.should eq "new-tag-2"
end
end

it "allows overriding updated_at and created_at on create" do
user = UserBox.new
.created_at(Time.utc(2018, 1, 1, 10, 20, 30))
.updated_at(Time.utc(2018, 1, 1, 20, 30, 40))
.create

user.created_at.should eq Time.utc(2018, 1, 1, 10, 20, 30)
user.updated_at.should eq Time.utc(2018, 1, 1, 20, 30, 40)
end
end
150 changes: 0 additions & 150 deletions spec/define_attribute_spec.cr

This file was deleted.

51 changes: 0 additions & 51 deletions spec/operation_needs_spec.cr

This file was deleted.

112 changes: 0 additions & 112 deletions spec/operation_spec.cr

This file was deleted.

52 changes: 52 additions & 0 deletions spec/operation_specs/base_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "../spec_helper"

private class TestOperation < Avram::Operation
def run
"Lucky Test"
end
end

private class TestOperationWithParamKey < Avram::Operation
param_key :custom_key

def run
"Custom Key Test"
end
end

describe Avram::Operation do
describe "run" do
it "returns the last statement from the run method" do
TestOperation.run do |_operation, value|
value.should eq "Lucky Test"
end
end

it "has access to the raw params passed in" do
params = Avram::Params.new({"page" => "1", "per" => "50"})
TestOperationWithParamKey.run(params) do |operation, value|
operation.params.should eq params
operation.params.get("page").should eq "1"
value.should eq "Custom Key Test"
end
end
end

describe "param_key" do
it "has a param_key based on the name of the operation" do
TestOperation.param_key.should eq "test_operation"
end

it "sets a custom param key with the param_key macro" do
TestOperationWithParamKey.param_key.should eq "custom_key"
end
end

describe "valid?" do
it "returns true when there's nothing to validate" do
TestOperation.run do |operation, _value|
operation.valid?.should eq true
end
end
end
end
Loading