Skip to content

Commit

Permalink
ShowGroup now validates output correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 30, 2016
1 parent 51b245a commit f1c7aba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/interactors/show_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ def validate_input
end

def execute
context.group = Group.find(context.id)
context.group = Group.find_by(id: context.id)
end

def validate_output
context.fail!(errors: "invalid output") unless context.group
end
end
16 changes: 15 additions & 1 deletion spec/interactors/show_group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe ShowGroup do
describe ".call" do
let(:group) { create(:group) }
let(:group) { create(:group, id: 876) }

context "when successful" do
subject do
Expand Down Expand Up @@ -29,5 +29,19 @@
expect(subject.errors).to eq("invalid input")
end
end

context "when a Group was not found" do
subject do
described_class.call(id: 9999)
end

it "fails" do
is_expected.to be_a_failure
end

it "returns an error" do
expect(subject.errors).to eq("invalid output")
end
end
end
end

0 comments on commit f1c7aba

Please sign in to comment.