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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync TeSS 1.4.1 changes #905

Merged
merged 3 commits into from
Nov 20, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Event < ApplicationRecord
include WithTimezone

before_validation :fix_keywords, on: :create, if: :scraper_record
before_validation :presence_default
before_save :check_country_name # :set_default_times
before_save :geocoding_cache_lookup, if: :address_will_change?
after_save :enqueue_geocoding_worker, if: :address_changed?
Expand Down Expand Up @@ -124,6 +125,7 @@ class Event < ApplicationRecord
validates :latitude, numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90, allow_nil: true }
validates :longitude, numericality: { greater_than_or_equal_to: -180, less_than_or_equal_to: 180, allow_nil: true }
# validates :duration, format: { with: /\A[0-9][0-9]:[0-5][0-9]\z/, message: "must be in format HH:MM" }, allow_blank: true
validates :presence, inclusion: { in: presences.keys, allow_blank: true }
validate :allowed_url
clean_array_fields(:keywords, :fields, :event_types, :target_audience,
:eligibility, :host_institutions, :sponsors)
Expand Down Expand Up @@ -495,4 +497,8 @@ def fix_keywords
end
end
end

def presence_default
self.presence = :onsite if presence.blank?
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def merge(*others)
other.activities.update_all(trackable_id: id, trackable_type: self.class.name)
other.subscriptions.update_all(user_id: id)
new_collaborations += other.collaborations
new_editable_ids = other.editable_ids
new_editable_ids |= other.editable_ids
attrs.reverse_merge!(other.attributes)
end
self.editable_ids = self.editable_ids | new_editable_ids
Expand Down
2 changes: 1 addition & 1 deletion app/views/materials/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ json.partial! 'common/ontology_terms', type: 'operations', resource: @material

json.nodes @material.associated_nodes.collect { |x| { name: x[:name], node_id: x[:id] } }
json.collections @material.collections.collect { |x| { title: x[:title], id: x[:id] } }
json.materials @material.events.collect { |x| { title: x[:title], id: x[:id] } }
json.events @material.events.collect { |x| { title: x[:title], id: x[:id] } }

json.external_resources do
@material.external_resources.each do |external_resource|
Expand Down
67 changes: 67 additions & 0 deletions test/models/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,87 @@ class EventTest < ActiveSupport::TestCase
end

test 'can still set presence through online setter' do
assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?

@event.online = true

assert @event.valid?
refute @event.onsite?
assert @event.online?
refute @event.hybrid?

@event.online = false

assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?

@event.online = ''

assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?
end

test 'validates presence' do
@event.presence = 'onsite'

assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?

@event.presence = 0

assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?

@event.presence = :online

assert @event.valid?
refute @event.onsite?
assert @event.online?
refute @event.hybrid?

@event.presence = 1

assert @event.valid?
refute @event.onsite?
assert @event.online?
refute @event.hybrid?

@event.presence = 'hybrid'

assert @event.valid?
refute @event.onsite?
refute @event.online?
assert @event.hybrid?

@event.presence = nil

assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?

@event.presence = ''

assert @event.valid?
assert @event.onsite?
refute @event.online?
refute @event.hybrid?

# TODO: Use enum validation in Rails 7.1 https://github.com/rails/rails/pull/49100
assert_raises(ArgumentError) do
@event.presence = 'xyz'
refute @event.valid?
end
end
end
13 changes: 11 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ class UserTest < ActiveSupport::TestCase
provider = content_providers(:goblet)
provider.add_editor(user1)
provider.add_editor(user2)
provider2 = content_providers(:iann)
provider2.add_editor(user2)
provider3 = content_providers(:two)
provider3.add_editor(user3)

# Collaborations
workflow1 = workflows(:one)
Expand All @@ -348,12 +352,13 @@ class UserTest < ActiveSupport::TestCase
workflow1.collaborators << user2
workflow2.collaborators << user3


# Test
assert_no_difference('Event.count') do
assert_no_difference('Material.count') do
assert_no_difference('Subscription.count') do
assert_difference('provider.editors.count', -1) do
assert_no_difference('provider2.editors.count') do
assert_no_difference('provider3.editors.count') do
assert_difference('Collaboration.count', -1) do
assert_difference('User.count', -2) do
assert user1.merge(user2, user3)
Expand All @@ -365,6 +370,8 @@ class UserTest < ActiveSupport::TestCase
end
end
end
end
end

assert_equal 'base_user', user1.username
assert_equal user1_id, user1.id
Expand All @@ -387,7 +394,9 @@ class UserTest < ActiveSupport::TestCase
assert_equal user1, subscription1.reload.user
assert_equal user1, subscription2.reload.user

assert_includes provider.reload.editors, user1
assert_equal [user1], provider.reload.editors
assert_equal [user1], provider2.reload.editors
assert_equal [user1], provider3.reload.editors

assert_equal [user1], workflow1.reload.collaborators.to_a
assert_equal [user1], workflow2.reload.collaborators.to_a
Expand Down