From f4e0ef7eea81577487bc864b3ee57de61dee44ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Miedes=20Garc=C3=A9s?= Date: Mon, 2 Jan 2017 12:00:58 +0100 Subject: [PATCH] Truncate votes api timestamp to hour --- app/models/vote.rb | 4 ++++ config/initializers/graphql.rb | 8 ++++---- spec/models/vote_spec.rb | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/vote.rb b/app/models/vote.rb index f51e67ef2..3f60688d7 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -10,4 +10,8 @@ class Vote < ActsAsVotable::Vote def public_voter User.select("gender, geozone_id, date_of_birth").where(id: self.voter_id).first end + + def public_timestamp + self.created_at.change(min: 0) + end end diff --git a/config/initializers/graphql.rb b/config/initializers/graphql.rb index cc242e722..fdb5975e3 100644 --- a/config/initializers/graphql.rb +++ b/config/initializers/graphql.rb @@ -77,10 +77,10 @@ API_TYPE_DEFINITIONS = { kind: :string }, Vote => { - votable_id: :integer, - votable_type: :string, - created_at: :string, - public_voter: Voter + votable_id: :integer, + votable_type: :string, + public_timestamp: :string, + public_voter: Voter } } diff --git a/spec/models/vote_spec.rb b/spec/models/vote_spec.rb index 14929ef2c..8e5db0ce7 100644 --- a/spec/models/vote_spec.rb +++ b/spec/models/vote_spec.rb @@ -91,4 +91,11 @@ describe 'Vote' do expect(Vote.public_for_api).not_to include(vote) end end + + describe '#public_timestamp' do + it "truncates created_at timestamp up to minutes" do + vote = create(:vote, created_at: Time.zone.parse('2016-02-10 15:30:45')) + expect(vote.public_timestamp).to eq(Time.zone.parse('2016-02-10 15:00:00')) + end + end end