Skip to content

Commit

Permalink
modify CreateGroup to also create the appropriate join table
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 27, 2016
1 parent d929efb commit 51b245a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class GroupsController < AuthenticationController
def create
result = CreateGroup.call(group_params: group_params)
result = CreateGroup.call(user: current_user, group_params: group_params)

if result.success?
render json: result.group, status: :created
Expand Down
2 changes: 1 addition & 1 deletion app/interactors/create_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def validate_input
end

def execute
context.group = Group.create(context.group_params)
context.group = context.user.groups.create(context.group_params)
end

def validate_output
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:params) { { group: create_group_input.fetch(:group_params) } }

let(:create_group_input) do
{ group_params: { name: group.name } }
{ user: user, group_params: { name: group.name } }
end

let(:create_group_context) do
Expand Down
6 changes: 5 additions & 1 deletion spec/interactors/create_group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
RSpec.describe CreateGroup do
describe ".call" do
let(:user) do
create(:confirmed_user)
end

let(:group_params) do
{
name: "Weasley's Kneesleys",
Expand All @@ -12,7 +16,7 @@
end

subject do
described_class.call(group_params: group_params)
described_class.call(user: user, group_params: group_params)
end

context "when successful" do
Expand Down

0 comments on commit 51b245a

Please sign in to comment.