Skip to content

Commit

Permalink
new error scheme for CreateUser and Interactors generally
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 25, 2016
1 parent c964679 commit d7dae23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/interactors/create_user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreateUser < StandardInteraction
def validate_input
context.fail!(errors: "invalid user params") unless context.user_params
def validate_input(input: :user_params)
super
end

def execute
Expand Down
7 changes: 6 additions & 1 deletion lib/standard_interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ def call
def execute
end

def validate_input
def validate_input(input: expected_arguments)
context.fail!(errors: input_error) unless context.send(input)
end

def validate_output
end

def input_error
{ "#{self.class.name}": "invalid Interactor input" }
end
end
2 changes: 1 addition & 1 deletion spec/interactors/create_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
end

it "returns an error" do
expect(subject.errors).to eq("invalid user params")
expect(subject.errors).to eq(CreateUser: "invalid Interactor input")
end
end
end
Expand Down

0 comments on commit d7dae23

Please sign in to comment.