Permalink
Browse files

Meetings can take a location.

  • Loading branch information...
dblock committed Sep 23, 2018
1 parent 2093187 commit c1fb0098348d1833d9acc00c3c5a4347db1e2ebe
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-07-23 09:03:00 +0200 using RuboCop version 0.57.2.
# on 2018-09-23 11:27:53 -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
@@ -9,6 +9,7 @@ gem 'email_validator'
gem 'graphql'
gem 'graphql-errors'
gem 'mongoid'
gem 'mongoid-geospatial'
gem 'newrelic_rpm'
gem 'puma', '~> 3.11'
gem 'rack-cors'
@@ -100,6 +100,8 @@ GEM
mongoid (7.0.1)
activemodel (>= 5.1, < 6.0.0)
mongo (>= 2.5.1, < 3.0.0)
mongoid-geospatial (5.0.0)
mongoid (>= 5.0.0.beta)
msgpack (1.2.4)
multipart-post (2.0.0)
newrelic_rpm (5.2.0.345)
@@ -210,6 +212,7 @@ DEPENDENCIES
graphql-errors
listen (>= 3.0.5, < 3.2)
mongoid
mongoid-geospatial
newrelic_rpm
puma (~> 3.11)
rack-cors
@@ -225,4 +228,4 @@ RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.2
1.16.3
@@ -4,19 +4,24 @@
input_field :title, types.String
input_field :started, !Types::DateTimeType
input_field :finished, !Types::DateTimeType
input_field :location, Types::InputLocationType

return_field :meeting, Types::MeetingType
return_field :meetingsConnection, Types::MeetingType.connection_type
return_field :meetingEdge, Types::MeetingType.edge_type

resolve ->(_object, inputs, ctx) {
user = ctx[:current_user]

if user
meeting = user.meetings.create!(
title: inputs[:title],
started_at: inputs[:started],
finished_at: inputs[:finished]
)
data = {}

data[:title] = inputs[:title]
data[:started_at] = inputs[:started]
data[:finished_at] = inputs[:finished]
data[:location] = inputs[:location].to_h if inputs[:location]

meeting = user.meetings.create!(data)

range_add = GraphQL::Relay::RangeAdd.new(
parent: user,
@@ -0,0 +1,7 @@
Types::InputLocationType = GraphQL::InputObjectType.define do
name 'InputLocation'
description 'A geo location.'

argument :latitude, !types.Float, 'Lat.'
argument :longitude, !types.Float, 'Lon.'
end
@@ -0,0 +1,7 @@
Types::LocationType = GraphQL::ObjectType.define do
name 'Location'
description 'A geo location.'

field :latitude, !types.Float, 'Lat.', property: :x
field :longitude, !types.Float, 'Lon.', property: :y
end
@@ -7,4 +7,5 @@
field :started, Types::DateTimeType, 'The time at which this meeting started.', property: :started_at
field :finished, Types::DateTimeType, 'The time at which this meeting ended.', property: :finished_at
field :user, Types::UserType, 'Owner of this meeting.'
field :location, Types::LocationType, 'Geo-location of meeting.'
end
@@ -1,11 +1,13 @@
class Meeting
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Geospatial
include ActionView::Helpers::DateHelper

field :title, type: String
field :started_at, type: DateTime
field :finished_at, type: DateTime
field :location, type: Point

validates_presence_of :started_at
validates_presence_of :finished_at
@@ -3,4 +3,5 @@
started_at { Faker::Time.backward(1) }
finished_at { Time.now }
user { Fabricate(:user) }
location { { latitude: 22.3407, longitude: 114.2054 } }
end
@@ -12,6 +12,7 @@
title
started
finished
location
},
meetingEdge {
node {
@@ -26,14 +27,16 @@
let(:title) { Faker::Company.buzzword }
let(:started_at) { Faker::Time.backward(1) }
let(:finished_at) { Time.now }
let(:location) { { latitude: 22.3407, longitude: 114.2054 } }

it 'returns an meeting' do
expect do
response = client.execute(
query, input: {
title: title,
started: started_at,
finished: finished_at
finished: finished_at,
location: location
}
)
meeting = response.data.create_meeting.meeting
@@ -12,6 +12,10 @@
title
started
finished
location {
latitude
longitude
}
}
}
}
@@ -22,7 +26,12 @@

it 'returns the meeting' do
response = client.execute(query, id: meeting.id.to_s)
meeting = response.data.user.meeting
expect(meeting.id).to eq meeting.id.to_s
returned_meeting = response.data.user.meeting
expect(returned_meeting.id).to eq meeting.id.to_s
expect(returned_meeting.title).to eq meeting.title
expect(returned_meeting.started).to eq meeting.started_at.utc.iso8601
expect(returned_meeting.finished).to eq meeting.finished_at.utc.iso8601
expect(returned_meeting.location.latitude).to eq meeting.location.x
expect(returned_meeting.location.longitude).to eq meeting.location.y
end
end

0 comments on commit c1fb009

Please sign in to comment.