Skip to content

Commit

Permalink
Use 6.1 framework defaults, fix broken associations
Browse files Browse the repository at this point in the history
  • Loading branch information
Dantemss committed Dec 23, 2024
1 parent 916520b commit d8829da
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 95 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ gem 'apipie-rails'
gem 'maruku'

# Retry failed database transactions
gem 'openstax_transaction_retry', github: 'openstax/transaction_retry'
gem 'openstax_transaction_retry', github: 'openstax/transaction_retry', ref: '36e26d0a068756c334b9d1c671d40773bbfc9300'
gem 'openstax_transaction_isolation', github: 'openstax/transaction_isolation', ref: '7387fa091462118704967a7c4b2821cd0f5d9e01'

# Lev framework
gem 'lev'
gem 'lev', github: 'lml/lev', ref: 'a33c93c83afea63c80b5da6317efec4bfd357df5'

# Contract management
gem 'fine_print'
Expand Down
46 changes: 30 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
GIT
remote: https://github.com/lml/lev.git
revision: a33c93c83afea63c80b5da6317efec4bfd357df5
ref: a33c93c83afea63c80b5da6317efec4bfd357df5
specs:
lev (13.0.0)
actionpack (>= 4.2)
active_attr
activejob
activemodel (>= 6.1)
activerecord (>= 4.2)
hashie
openstax_transaction_isolation
openstax_transaction_retry

GIT
remote: https://github.com/openstax/transaction_isolation.git
revision: 7387fa091462118704967a7c4b2821cd0f5d9e01
ref: 7387fa091462118704967a7c4b2821cd0f5d9e01
specs:
openstax_transaction_isolation (2.0.0)
activerecord (>= 6)

GIT
remote: https://github.com/openstax/transaction_retry.git
revision: d283692afb1a06557764e06a59798a207bb1e465
revision: 36e26d0a068756c334b9d1c671d40773bbfc9300
ref: 36e26d0a068756c334b9d1c671d40773bbfc9300
specs:
openstax_transaction_retry (1.2.0)
activerecord (>= 5.1)
transaction_isolation (>= 1.0.5)
openstax_transaction_retry (2.0.0)
activerecord (>= 6)
openstax_transaction_isolation (>= 2)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -229,15 +253,6 @@ GEM
base64
keyword_search (1.5.0)
language_server-protocol (3.17.0.3)
lev (12.1.0)
actionpack (>= 4.2)
active_attr
activejob
activemodel (>= 6.1)
activerecord (>= 4.2)
hashie
openstax_transaction_retry
transaction_isolation
libv8-node (18.19.0.0)
libv8-node (18.19.0.0-x86_64-darwin)
libv8-node (18.19.0.0-x86_64-linux)
Expand Down Expand Up @@ -547,8 +562,6 @@ GEM
timecop (0.9.10)
timeout (0.4.3)
trailblazer-option (0.1.2)
transaction_isolation (1.0.5)
activerecord (>= 3.0.11)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
Expand Down Expand Up @@ -614,7 +627,7 @@ DEPENDENCIES
jquery-rails
jquery-ui-rails
keyword_search
lev
lev!
listen
lograge
maruku
Expand All @@ -628,6 +641,7 @@ DEPENDENCIES
openstax_content
openstax_healthcheck
openstax_rescue_from
openstax_transaction_isolation!
openstax_transaction_retry!
openstax_utilities
parallel_tests
Expand Down
2 changes: 1 addition & 1 deletion app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class Attachment < ApplicationRecord
belongs_to :parent, polymorphic: true, inverse_of: :attachments, touch: true

before_update { raise ActiveRecord::ReadOnlyRecord } # Prevent updates
before_update { raise ActiveRecord::ReadOnlyRecord if changed? } # Prevent updates

validates :asset, presence: true
validate :unique_asset
Expand Down
7 changes: 5 additions & 2 deletions app/models/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,11 @@ def assign_uuid_and_version
self.version ||= (publication_group.publications.maximum(:version) || 0) + 1

publication_group.assign_uuid_and_number
publication_group.new_record? ? publication_group.latest_version = version :
publication_group.update_attribute(:latest_version, version)
if publication_group.new_record?
publication_group.latest_version = version
else
publication_group.update_column(:latest_version, version)
end
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/models/publication_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PublicationGroup < ApplicationRecord

has_many :list_publication_groups, dependent: :destroy

has_many :vocab_distractors
has_many :vocab_distractors, foreign_key: :distractor_publication_group_id

validates :publishable_type, presence: true
validates :uuid, presence: true, uniqueness: true
Expand Down
4 changes: 1 addition & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
module Exercises
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
# TODO: load_defaults 6.1 turns on config.active_record.has_many_inversing
# which breaks VocabDistractor tests
config.load_defaults 6.0
config.load_defaults 6.1

# Configuration for the application, engines, and railties goes here.
#
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE']
67 changes: 0 additions & 67 deletions config/initializers/new_framework_defaults_6_1.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/publishable/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module ActiveRecord
module Base
def publishable(options = {})
class_exec do

has_one :publication, as: :publishable, dependent: :destroy, inverse_of: :publishable
has_one :publication_group, through: :publication

Expand Down Expand Up @@ -129,7 +128,6 @@ def after_publication
def ensure_publication!
raise ::ActiveRecord::RecordInvalid, publication unless publication.persisted?
end

end
end
end
Expand Down

0 comments on commit d8829da

Please sign in to comment.