Permalink
Browse files

Accept array for Geo Location.

  • Loading branch information...
dblock committed Sep 27, 2018
1 parent 098ff17 commit cc159bf87f0157c2f9cb0423ba51017fd2476174
Showing with 45 additions and 19 deletions.
  1. +3 −2 .rubocop_todo.yml
  2. +9 −1 app/graphql/types/geo_coordinates.rb
  3. +33 −16 spec/graphql/mutations/update_meeting_mutation_spec.rb
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-09-23 11:27:53 -0400 using RuboCop version 0.57.2.
# on 2018-09-27 08:43:34 -0400 using RuboCop version 0.57.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -16,7 +16,7 @@ Style/DateTime:
Exclude:
- 'spec/graphql/mutations/create_meeting_mutation_spec.rb'

# Offense count: 12
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: line_count_dependent, lambda, literal
@@ -30,6 +30,7 @@ Style/Lambda:
- 'app/graphql/mutations/logout_mutation.rb'
- 'app/graphql/mutations/update_meeting_mutation.rb'
- 'app/graphql/mutations/update_user_mutation.rb'
- 'app/graphql/types/geo_coordinates.rb'
- 'app/graphql/types/query_type.rb'
- 'app/graphql/types/user_type.rb'

@@ -2,6 +2,14 @@
name 'GeoCoordinates'
description 'Geo coordinate, latitude followed by longitude.'

coerce_input ->(value, _ctx) { Geo::Coord.parse(value) }
coerce_input ->(value, _ctx) {
case value
when Array
Geo::Coord.new(value[0], value[1])
else
Geo::Coord.parse(value)
end
}

coerce_result ->(value, _ctx) { [value.y, value.x] }
end
@@ -35,26 +35,43 @@
expect(meeting.reload.title).to eq title
end

it 'updates location' do
response = client.execute(
query, input: {
id: meeting.id.to_s,
location: '50.004444, 36.231389'
}
)
update_meeting = response.data.update_meeting.meeting
expect(update_meeting.location).to eq [50.004444, 36.231389]
expect(meeting.reload.location.to_a).to eq [50.004444, 36.231389]
end

it 'fails with an invalid location' do
expect do
context 'updates location' do
let(:response) do
client.execute(
query, input: {
id: meeting.id.to_s,
location: 'invalid'
location: location
}
)
end.to raise_error Graphlient::Errors::GraphQLError, /location: Could not coerce value "invalid" to GeoCoordinates/
end

let(:updated_meeting) { response.data.update_meeting.meeting }

context 'string' do
let(:location) { '50.004444, 36.231389' }

it 'updates location' do
expect(updated_meeting.location).to eq [50.004444, 36.231389]
expect(meeting.reload.location.to_a).to eq [50.004444, 36.231389]
end
end

context 'array' do
let(:location) { [50.004444, 36.231389] }

it 'updates location' do
expect(updated_meeting.location).to eq [50.004444, 36.231389]
expect(meeting.reload.location.to_a).to eq [50.004444, 36.231389]
end
end

context 'invalid' do
let(:location) { 'invalid' }
it 'fails with an invalid location' do
expect do
updated_meeting
end.to raise_error Graphlient::Errors::GraphQLError, /location: Could not coerce value "invalid" to GeoCoordinates/
end
end
end
end

0 comments on commit cc159bf

Please sign in to comment.