-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
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,12 @@ | ||
class Resolvers::CreateVote < GraphQL::Function | ||
argument :linkId, !types.ID | ||
|
||
type Types::VoteType | ||
|
||
def call(_obj, args, ctx) | ||
Vote.create!( | ||
user: ctx[:current_user], | ||
link: Link.find_by(id: args[:linkId]), | ||
) | ||
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,7 @@ | ||
Types::VoteType = GraphQL::ObjectType.define do | ||
name 'Vote' | ||
|
||
field :id, !types.ID | ||
field :link, -> { !Types::LinkType } | ||
field :user, -> { !Types::UserType } | ||
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,30 @@ | ||
require 'test_helper' | ||
|
||
class Resolvers::CreateVoteTest < ActiveSupport::TestCase | ||
def perform(args = {}) | ||
Resolvers::CreateVote.new.call(nil, args, { current_user: @user }) | ||
end | ||
|
||
setup do | ||
@user = User.create!( | ||
name: 'test', | ||
email: 'email@example.com', | ||
password: 'something' | ||
) | ||
@link = Link.create!( | ||
url: 'http://google.com', | ||
description: 'description', | ||
user: @user, | ||
) | ||
end | ||
|
||
test 'creating new vote' do | ||
vote = perform( | ||
linkId: @link.id, | ||
) | ||
|
||
assert vote.persisted? | ||
assert_equal vote.link, @link | ||
assert_equal vote.user, @user | ||
end | ||
end |