Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 'Use UTC in the serializers for the date fields' to v0.27 #11925

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions decidim-elections/lib/decidim/votings/voting_serializer.rb
Expand Up @@ -21,8 +21,8 @@ def serialize
url: url,
title: voting.title,
description: voting.description,
start_time: voting.start_time.to_s(:db),
end_time: voting.end_time.to_s(:db),
start_time: voting.start_time,
end_time: voting.end_time,
voting_type: translated_voting_type,
scope: {
id: voting.scope.try(:id),
Expand Down
2 changes: 1 addition & 1 deletion decidim-forms/lib/decidim/forms/user_answers_serializer.rb
Expand Up @@ -32,7 +32,7 @@ def serialize
def hash_for(answer)
{
answer_translated_attribute_name(:id) => answer&.session_token,
answer_translated_attribute_name(:created_at) => answer&.created_at&.to_s(:db),
answer_translated_attribute_name(:created_at) => answer&.created_at,
answer_translated_attribute_name(:ip_hash) => answer&.ip_hash,
answer_translated_attribute_name(:user_status) => answer_translated_attribute_name(answer&.decidim_user_id.present? ? "registered" : "unregistered")
}
Expand Down
Expand Up @@ -114,7 +114,7 @@ module Forms

it "the creation of the answer" do
key = I18n.t(:created_at, scope: "decidim.forms.user_answers_serializer")
expect(serialized[key]).to eq an_answer.created_at.to_s(:db)
expect(serialized[key]).to be_within(1.second).of an_answer.created_at
end

it "the IP hash of the user" do
Expand Down Expand Up @@ -147,6 +147,36 @@ module Forms
end
end

context "when time zone is UTC" do
let(:time_zone) { "UTC" }
let(:created_at) { Time.new(2000, 1, 2, 3, 4, 5, 0) }

before do
questionable.organization.update!(time_zone: time_zone)
answers.first.update!(created_at: created_at)
end

it "Time uses UTC time zone in exported data" do
key = I18n.t(:created_at, scope: "decidim.forms.user_answers_serializer")
expect(serialized[key].to_s).to include "UTC"
end
end

context "when time zone is non-UTC" do
let(:time_zone) { "Hawaii" }
let(:created_at) { Time.new(2000, 1, 2, 3, 4, 5, 0) }

before do
questionable.organization.update!(time_zone: time_zone)
answers.first.update!(created_at: created_at)
end

it "Time uses UTC time zone in exported data" do
key = I18n.t(:created_at, scope: "decidim.forms.user_answers_serializer")
expect(serialized[key].to_s).to include "UTC"
end
end

context "when the questionnaire body is very long" do
let!(:questionnaire) { create(:questionnaire, questionnaire_for: questionable, description: questionnaire_description) }
let(:questionnaire_description) do
Expand Down
4 changes: 2 additions & 2 deletions decidim-meetings/lib/decidim/meetings/meeting_serializer.rb
Expand Up @@ -32,8 +32,8 @@ def serialize
component: { id: component.id },
title: meeting.title,
description: meeting.description,
start_time: meeting.start_time.to_s(:db),
end_time: meeting.end_time.to_s(:db),
start_time: meeting.start_time,
end_time: meeting.end_time,
attendees: meeting.attendees_count.to_i,
contributions: meeting.contributions_count.to_i,
organizations: meeting.attending_organizations,
Expand Down
Expand Up @@ -17,7 +17,7 @@ def serialize
@answers.each_with_index.inject({}) do |serialized, (answer, idx)|
serialized.update(
answer_translated_attribute_name(:id) => [answer.id, answer.user.id].join("_"),
answer_translated_attribute_name(:created_at) => answer.created_at.to_s(:db),
answer_translated_attribute_name(:created_at) => answer.created_at,
answer_translated_attribute_name(:user_status) => answer_translated_attribute_name(answer.decidim_user_id.present? ? "registered" : "unregistered"),
"#{idx + 1}. #{translated_attribute(answer.question.body)}" => normalize_body(answer)
)
Expand Down
Expand Up @@ -57,11 +57,11 @@ module Meetings
end

it "serializes the start time" do
expect(serialized).to include(start_time: meeting.start_time.to_s(:db))
expect(serialized).to include(start_time: meeting.start_time)
end

it "serializes the end time" do
expect(serialized).to include(end_time: meeting.end_time.to_s(:db))
expect(serialized).to include(end_time: meeting.end_time)
end

it "serializes the amount of attendees" do
Expand Down