diff --git a/Gemfile.lock b/Gemfile.lock index 054148de5..cbd9c69ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,80 +1,83 @@ GEM remote: https://rubygems.org/ specs: - activesupport (7.1.3.3) + activesupport (8.0.0) base64 + benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) ast (2.4.2) base64 (0.2.0) + benchmark (0.4.0) bigdecimal (3.1.8) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) drb (2.2.1) - i18n (1.14.5) + i18n (1.14.6) concurrent-ruby (~> 1.0) - json (2.7.2) + json (2.8.2) language_server-protocol (3.17.0.3) - minitest (5.23.1) - mutex_m (0.2.0) - parallel (1.24.0) - parser (3.3.1.0) + logger (1.6.1) + minitest (5.25.1) + parallel (1.26.3) + parser (3.3.6.0) ast (~> 2.4.1) racc prettier_print (1.2.1) - racc (1.8.0) - rack (3.0.11) + racc (1.8.1) + rack (3.1.8) rainbow (3.1.1) regexp_parser (2.9.2) - rexml (3.3.9) - rubocop (1.64.0) + rubocop (1.68.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.31.1, < 2.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.31.3) + rubocop-ast (1.36.1) parser (>= 3.3.1.0) - rubocop-capybara (2.20.0) + rubocop-capybara (2.21.0) rubocop (~> 1.41) - rubocop-discourse (3.8.0) + rubocop-discourse (3.8.6) activesupport (>= 6.1) rubocop (>= 1.59.0) rubocop-capybara (>= 2.0.0) rubocop-factory_bot (>= 2.0.0) rubocop-rails (>= 2.25.0) - rubocop-rspec (>= 2.25.0) - rubocop-factory_bot (2.25.1) - rubocop (~> 1.41) - rubocop-rails (2.25.0) + rubocop-rspec (>= 3.0.1) + rubocop-rspec_rails (>= 2.30.0) + rubocop-factory_bot (2.26.1) + rubocop (~> 1.61) + rubocop-rails (2.27.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (2.29.2) - rubocop (~> 1.40) - rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) - rubocop-rspec_rails (~> 2.28) - rubocop-rspec_rails (2.28.3) - rubocop (~> 1.40) + rubocop-rspec (3.2.0) + rubocop (~> 1.61) + rubocop-rspec_rails (2.30.0) + rubocop (~> 1.61) + rubocop-rspec (~> 3, >= 3.0.1) ruby-progressbar (1.13.0) + securerandom (0.3.2) syntax_tree (6.2.0) prettier_print (>= 1.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.5.0) + unicode-display_width (2.6.0) + uri (1.0.2) PLATFORMS ruby @@ -84,4 +87,4 @@ DEPENDENCIES syntax_tree BUNDLED WITH - 2.5.10 + 2.5.18 diff --git a/lib/calendar.rb b/lib/calendar.rb index 876acc11a..cde41ddb5 100644 --- a/lib/calendar.rb +++ b/lib/calendar.rb @@ -2,7 +2,7 @@ module DiscourseCalendar class Calendar - DATA_PREFIX ||= "data-calendar-" + DATA_PREFIX = "data-calendar-" def self.extract(post) cooked = PrettyText.cook(post.raw, topic_id: post.topic_id, user_id: post.user_id) diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake index 6a28b73aa..28f3f2cd4 100644 --- a/lib/tasks/javascript.rake +++ b/lib/tasks/javascript.rake @@ -2,31 +2,34 @@ require "open-uri" -TIMEZONES_DEFINITIONS ||= - "https://raw.githubusercontent.com/moment/moment-timezone/develop/data/meta/latest.json" -UNUSED_REGIONS ||= %w[ - ecbtarget - federalreserve - federalreservebanks - fedex - nerc - unitednations - ups - nyse -] -HOLIDAYS_COUNTRY_OVERRIDES ||= { "gr" => "el" } - task "javascript:update_constants" => :environment do + timezone_definitions = + "https://raw.githubusercontent.com/moment/moment-timezone/develop/data/meta/latest.json" + + unused_regions = %w[ + ecbtarget + federalreserve + federalreservebanks + fedex + nerc + unitednations + ups + nyse + ] + + holidays_country_overrides = { "gr" => "el" } + require "holidays" if !defined?(Holidays) - holiday_regions = Holidays.available_regions.map(&:to_s) - UNUSED_REGIONS + holiday_regions = Holidays.available_regions.map(&:to_s) - unused_regions time_zone_to_region = {} - data = JSON.parse(URI.parse(TIMEZONES_DEFINITIONS).open.read) + data = JSON.parse(URI.parse(timezone_definitions).open.read) data["zones"].sort.each do |timezone, timezone_data| country_code = timezone_data["countries"].first.downcase - if HOLIDAYS_COUNTRY_OVERRIDES.include?(country_code) - country_code = HOLIDAYS_COUNTRY_OVERRIDES[country_code] + + if holidays_country_overrides.include?(country_code) + country_code = holidays_country_overrides[country_code] end next if !holiday_regions.include?(country_code) diff --git a/spec/integration/topic_spec.rb b/spec/integration/topic_spec.rb index 6d7823c4f..e71ac4b49 100644 --- a/spec/integration/topic_spec.rb +++ b/spec/integration/topic_spec.rb @@ -3,8 +3,6 @@ require "rails_helper" describe Topic do - Event ||= DiscoursePostEvent::Event - before do freeze_time Jobs.run_immediately! @@ -24,7 +22,7 @@ raw: "The boat market is quite active lately.", ) - expect(Event).to_not exist(id: post_with_date.id) + expect(DiscoursePostEvent::Event).to_not exist(id: post_with_date.id) end end end diff --git a/spec/models/discourse_post_event/event_spec.rb b/spec/models/discourse_post_event/event_spec.rb index 4620deedb..ef5bebc39 100644 --- a/spec/models/discourse_post_event/event_spec.rb +++ b/spec/models/discourse_post_event/event_spec.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true describe DiscoursePostEvent::Event do - Event ||= DiscoursePostEvent::Event - Invitee ||= DiscoursePostEvent::Invitee - StartsAtField ||= DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT - EndsAtField ||= DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT - before do freeze_time DateTime.parse("2020-04-24 14:10") Jobs.run_immediately! @@ -24,14 +19,14 @@ let!(:alt_starts_at) { "2020-04-24 14:14:25" } let!(:alt_ends_at) { "2020-04-24 19:15:25" } let(:event) do - Event.create!( + DiscoursePostEvent::Event.create!( id: first_post.id, original_starts_at: Time.now + 1.hours, original_ends_at: Time.now + 2.hours, ) end let(:late_event) do - Event.create!( + DiscoursePostEvent::Event.create!( id: first_post.id, original_starts_at: Time.now - 10.hours, original_ends_at: Time.now - 8.hours, @@ -46,7 +41,7 @@ expect(first_post.topic.custom_fields).to be_blank expect { - Event.create!( + DiscoursePostEvent::Event.create!( id: first_post.id, original_starts_at: starts_at, original_ends_at: ends_at, @@ -54,8 +49,12 @@ }.to change { DiscoursePostEvent::EventDate.count } first_post.topic.reload - expect(first_post.topic.custom_fields[StartsAtField]).to eq(starts_at) - expect(first_post.topic.custom_fields[EndsAtField]).to eq(ends_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to eq(starts_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to eq(ends_at) expect(DiscoursePostEvent::EventDate.last.starts_at).to eq_time( DateTime.parse(starts_at), ) @@ -68,9 +67,9 @@ expect(second_post.is_first_post?).to be(false) expect(second_post.topic.custom_fields).to be_blank - expect { Event.create!(id: second_post.id, original_starts_at: starts_at) }.to change { - DiscoursePostEvent::EventDate.count - } + expect { + DiscoursePostEvent::Event.create!(id: second_post.id, original_starts_at: starts_at) + }.to change { DiscoursePostEvent::EventDate.count } second_post.topic.reload expect(second_post.topic.custom_fields).to be_blank @@ -109,8 +108,12 @@ first_post.topic.reload expect(first_post.is_first_post?).to be(true) - expect(first_post.topic.custom_fields[StartsAtField]).to eq(starts_at) - expect(first_post.topic.custom_fields[EndsAtField]).to eq(ends_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to eq(starts_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to eq(ends_at) first_event_date = post_event.event_dates.last expect(first_event_date.starts_at).to eq_time(DateTime.parse(starts_at)) @@ -125,8 +128,12 @@ second_event_date = post_event.event_dates.last - expect(first_post.topic.custom_fields[StartsAtField]).to eq(alt_starts_at) - expect(first_post.topic.custom_fields[EndsAtField]).to eq(alt_ends_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to eq(alt_starts_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to eq(alt_ends_at) expect(first_event_date.finished_at).not_to be nil expect(second_event_date.starts_at).to eq_time(DateTime.parse(alt_starts_at)) @@ -142,12 +149,16 @@ it "doesn’t set the topic custom field" do expect(second_post.is_first_post?).to be(false) - expect(second_post.topic.custom_fields[StartsAtField]).to be_blank + expect( + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to be_blank post_event.update_with_params!(original_starts_at: alt_starts_at) second_post.topic.reload - expect(second_post.topic.custom_fields[StartsAtField]).to be_blank + expect( + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to be_blank second_event_date = post_event.event_dates.last expect(second_event_date.starts_at).to eq_time(DateTime.parse(alt_starts_at)) @@ -172,14 +183,22 @@ first_post.topic.reload expect(first_post.is_first_post?).to be(true) - expect(first_post.topic.custom_fields[StartsAtField]).to eq(starts_at) - expect(first_post.topic.custom_fields[EndsAtField]).to eq(ends_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to eq(starts_at) + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to eq(ends_at) post_event.destroy! first_post.topic.reload - expect(first_post.topic.custom_fields[StartsAtField]).to be_blank - expect(first_post.topic.custom_fields[EndsAtField]).to be_blank + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to be_blank + expect( + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to be_blank end end @@ -205,15 +224,23 @@ second_post.topic.reload expect(first_post.is_first_post?).to be(true) - expect(second_post.topic.custom_fields[StartsAtField]).to eq(starts_at) - expect(second_post.topic.custom_fields[EndsAtField]).to eq(ends_at) + expect( + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to eq(starts_at) + expect( + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to eq(ends_at) expect(second_post.is_first_post?).to be(false) second_post_event.destroy! second_post.topic.reload - expect(second_post.topic.custom_fields[StartsAtField]).to eq(starts_at) - expect(second_post.topic.custom_fields[EndsAtField]).to eq(ends_at) + expect( + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], + ).to eq(starts_at) + expect( + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], + ).to eq(ends_at) end end end @@ -230,7 +257,7 @@ context "with ends_at < current date" do it "is ongoing" do post_event = - Event.create!( + DiscoursePostEvent::Event.create!( original_starts_at: 2.hours.ago, original_ends_at: 1.hours.ago, post: first_post, @@ -243,7 +270,7 @@ context "with ends_at > current date" do it "is not ongoing" do post_event = - Event.create!( + DiscoursePostEvent::Event.create!( original_starts_at: 2.hours.ago, original_ends_at: 3.hours.from_now, post: first_post, @@ -258,7 +285,7 @@ context "when ends_at > current date" do it "is not ongoing" do post_event = - Event.create!( + DiscoursePostEvent::Event.create!( original_starts_at: 1.hour.from_now, original_ends_at: 2.hours.from_now, post: first_post, @@ -273,7 +300,8 @@ context "without ends_at date" do context "when starts_at < current date" do it "is ongoing" do - post_event = Event.create!(original_starts_at: 2.hours.ago, post: first_post) + post_event = + DiscoursePostEvent::Event.create!(original_starts_at: 2.hours.ago, post: first_post) expect(post_event.ongoing?).to be(true) end @@ -281,7 +309,8 @@ context "when starts_at == current date" do it "is ongoing" do - post_event = Event.create!(original_starts_at: Time.now, post: first_post) + post_event = + DiscoursePostEvent::Event.create!(original_starts_at: Time.now, post: first_post) expect(post_event.ongoing?).to be(true) end @@ -289,7 +318,11 @@ context "when starts_at > current date" do it "is not ongoing" do - post_event = Event.create!(original_starts_at: 1.hours.from_now, post: first_post) + post_event = + DiscoursePostEvent::Event.create!( + original_starts_at: 1.hours.from_now, + post: first_post, + ) expect(post_event.ongoing?).to be(false) end @@ -307,7 +340,7 @@ context "when ends_at < current date" do it "is expired" do post_event = - Event.create!( + DiscoursePostEvent::Event.create!( original_starts_at: DateTime.parse("2020-04-22 14:05"), original_ends_at: DateTime.parse("2020-04-23 14:05"), post: first_post, @@ -320,7 +353,7 @@ context "when ends_at > current date" do it "is not expired" do post_event = - Event.create!( + DiscoursePostEvent::Event.create!( original_starts_at: DateTime.parse("2020-04-24 14:15"), original_ends_at: DateTime.parse("2020-04-25 11:05"), post: first_post, @@ -334,7 +367,7 @@ context "when starts_at > current date" do it "is not expired" do post_event = - Event.create!( + DiscoursePostEvent::Event.create!( original_starts_at: DateTime.parse("2020-04-25 14:05"), original_ends_at: DateTime.parse("2020-04-26 14:05"), post: first_post, @@ -349,7 +382,10 @@ context "when starts_at < current date" do it "is expired" do post_event = - Event.create!(original_starts_at: DateTime.parse("2020-04-24 14:05"), post: first_post) + DiscoursePostEvent::Event.create!( + original_starts_at: DateTime.parse("2020-04-24 14:05"), + post: first_post, + ) expect(post_event.expired?).to be(false) end @@ -358,7 +394,10 @@ context "when starts_at == current date" do it "is expired" do post_event = - Event.create!(original_starts_at: DateTime.parse("2020-04-24 14:10"), post: first_post) + DiscoursePostEvent::Event.create!( + original_starts_at: DateTime.parse("2020-04-24 14:10"), + post: first_post, + ) expect(post_event.expired?).to be(false) end @@ -367,7 +406,10 @@ context "when starts_at > current date" do it "is not expired" do post_event = - Event.create!(original_starts_at: DateTime.parse("2020-04-24 14:15"), post: first_post) + DiscoursePostEvent::Event.create!( + original_starts_at: DateTime.parse("2020-04-24 14:15"), + post: first_post, + ) expect(post_event.expired?).to be(false) end @@ -392,7 +434,7 @@ Fabricate( :event, post: post_1, - status: Event.statuses[:private], + status: DiscoursePostEvent::Event.statuses[:private], raw_invitees: [group_1.name], ) end @@ -438,12 +480,12 @@ Fabricate( :event, post: post_1, - status: Event.statuses[:private], + status: DiscoursePostEvent::Event.statuses[:private], raw_invitees: [group_1.name, group_2.name], ) end - before { Invitee.create_attendance!(user_3.id, post_1.id, :going) } + before { DiscoursePostEvent::Invitee.create_attendance!(user_3.id, post_1.id, :going) } it "doesn’t return already attending user" do expect(event_1.missing_users.pluck(:id)).to_not include(user_3.id) diff --git a/spec/models/discourse_post_event/user_spec.rb b/spec/models/discourse_post_event/user_spec.rb index 8ff8b4d2a..ef5ddf6b8 100644 --- a/spec/models/discourse_post_event/user_spec.rb +++ b/spec/models/discourse_post_event/user_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe User do - Event ||= DiscoursePostEvent::Event + Event = DiscoursePostEvent::Event before do freeze_time DateTime.parse("2020-04-24 14:10") diff --git a/spec/serializers/discourse_post_event/event_serializer_spec.rb b/spec/serializers/discourse_post_event/event_serializer_spec.rb index 5ffe0ce75..dbb11273e 100644 --- a/spec/serializers/discourse_post_event/event_serializer_spec.rb +++ b/spec/serializers/discourse_post_event/event_serializer_spec.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true describe DiscoursePostEvent::EventSerializer do - Event ||= DiscoursePostEvent::Event - Invitee ||= DiscoursePostEvent::Invitee - EventSerializer ||= DiscoursePostEvent::EventSerializer - before do Jobs.run_immediately! SiteSetting.calendar_enabled = true @@ -16,7 +12,10 @@ fab!(:post) { Fabricate(:post, topic: topic) } context "with a private event" do - fab!(:private_event) { Fabricate(:event, post: post, status: Event.statuses[:private]) } + fab!(:private_event) do + Fabricate(:event, post: post, status: DiscoursePostEvent::Event.statuses[:private]) + end + fab!(:invitee_1) { Fabricate(:user) } fab!(:invitee_2) { Fabricate(:user) } fab!(:group_1) do @@ -30,12 +29,12 @@ context "when some invited users have not rsvp-ed yet" do before do private_event.update_with_params!(raw_invitees: [group_1.name]) - Invitee.create_attendance!(invitee_1.id, private_event.id, :going) + DiscoursePostEvent::Invitee.create_attendance!(invitee_1.id, private_event.id, :going) private_event.reload end it "returns the correct stats" do - json = EventSerializer.new(private_event, scope: Guardian.new).as_json + json = DiscoursePostEvent::EventSerializer.new(private_event, scope: Guardian.new).as_json expect(json[:event][:stats]).to eq(going: 1, interested: 0, invited: 2, not_going: 0) end end @@ -45,7 +44,7 @@ fab!(:event) { Fabricate(:event, post: post) } it "returns the event category's id" do - json = EventSerializer.new(event, scope: Guardian.new).as_json + json = DiscoursePostEvent::EventSerializer.new(event, scope: Guardian.new).as_json expect(json[:event][:category_id]).to eq(category.id) end end