Truncate votes api timestamp to hour

This commit is contained in:
Alberto Miedes Garcés
2017-01-02 12:00:58 +01:00
parent 508360cfa5
commit f4e0ef7eea
3 changed files with 15 additions and 4 deletions

View File

@@ -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

View File

@@ -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
}
}

View File

@@ -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