diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fc0454a2..77b4bcc5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,6 @@ All notable changes to this project will be documented in this file. ## 2021-03-24 ### Added - added `Rails.application.config.folio_site_is_a_singleton` and `Folio::Site` STI support ->>>>>>> petr/dragonfly-libvips-multi-site-rails-7 ## 2021-03-21 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index 826837451..c974525c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -267,6 +267,9 @@ GEM execjs (2.8.1) factory_bot (6.2.1) activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) faker (2.21.0) i18n (>= 1.8.11, < 2) faraday (2.3.0) @@ -624,7 +627,7 @@ DEPENDENCIES cells-rails (~> 0.1.5) cells-slim (~> 0.0.6) dragonfly_libvips! - factory_bot + factory_bot_rails faker folio! guard-rubocop diff --git a/app/controllers/folio/users/registrations_controller.rb b/app/controllers/folio/users/registrations_controller.rb index b56d2daf2..6c52374a8 100644 --- a/app/controllers/folio/users/registrations_controller.rb +++ b/app/controllers/folio/users/registrations_controller.rb @@ -6,7 +6,7 @@ class Folio::Users::RegistrationsController < Devise::RegistrationsController include Folio::Users::DeviseControllerBase def new - fail ActionController::MethodNotAllowed, "" + fail ActionController::MethodNotAllowed, "Registrations are created by inviting user, not directly" end def edit @@ -20,7 +20,7 @@ def edit end def create - fail ActionController::MethodNotAllowed, "" + fail ActionController::MethodNotAllowed, "Registrations are created by inviting user, not directly" build_resource(sign_up_params) diff --git a/app/lib/folio/console/simple_form_components/flag_component.rb b/app/lib/folio/console/simple_form_components/flag_component.rb index 7d88a6d2d..049be2a1e 100644 --- a/app/lib/folio/console/simple_form_components/flag_component.rb +++ b/app/lib/folio/console/simple_form_components/flag_component.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true - module Folio module Console module SimpleFormComponents diff --git a/app/models/concerns/folio/belongs_to_site.rb b/app/models/concerns/folio/belongs_to_site.rb index 0efcb625c..70e40e220 100644 --- a/app/models/concerns/folio/belongs_to_site.rb +++ b/app/models/concerns/folio/belongs_to_site.rb @@ -10,6 +10,8 @@ module Folio::BelongsToSite validate :validate_belongs_to_site scope :by_atom_setting_site_id, -> (site_id) { where(site_id:) } + scope :by_site, ->(site) { where(site: site) } + scope :by_site_id, ->(site_id) { where(site_id: site_id) } end class_methods do diff --git a/app/models/folio/account.rb b/app/models/folio/account.rb index c701c40be..b0d7b46b6 100644 --- a/app/models/folio/account.rb +++ b/app/models/folio/account.rb @@ -164,11 +164,11 @@ def validate_role # # Indexes # -# index_folio_accounts_on_crossdomain_devise_token (crossdomain_devise_token) -# index_folio_accounts_on_email (email) UNIQUE -# index_folio_accounts_on_invitation_token (invitation_token) UNIQUE -# index_folio_accounts_on_invitations_count (invitations_count) -# index_folio_accounts_on_invited_by (invited_by_type,invited_by_id) -# index_folio_accounts_on_invited_by_id (invited_by_id) -# index_folio_accounts_on_reset_password_token (reset_password_token) UNIQUE +# index_folio_accounts_on_crossdomain_devise_token (crossdomain_devise_token) +# index_folio_accounts_on_email (email) UNIQUE +# index_folio_accounts_on_invitation_token (invitation_token) UNIQUE +# index_folio_accounts_on_invitations_count (invitations_count) +# index_folio_accounts_on_invited_by_id (invited_by_id) +# index_folio_accounts_on_invited_by_type_and_invited_by_id (invited_by_type,invited_by_id) +# index_folio_accounts_on_reset_password_token (reset_password_token) UNIQUE # diff --git a/app/models/folio/file_placement/base.rb b/app/models/folio/file_placement/base.rb index d0dd99144..74f382786 100644 --- a/app/models/folio/file_placement/base.rb +++ b/app/models/folio/file_placement/base.rb @@ -69,9 +69,9 @@ def run_file_after_save_job! # # Indexes # -# index_folio_file_placements_on_file_id (file_id) -# index_folio_file_placements_on_placement (placement_type,placement_id) -# index_folio_file_placements_on_placement_title (placement_title) -# index_folio_file_placements_on_placement_title_type (placement_title_type) -# index_folio_file_placements_on_type (type) +# index_folio_file_placements_on_file_id (file_id) +# index_folio_file_placements_on_placement_title (placement_title) +# index_folio_file_placements_on_placement_title_type (placement_title_type) +# index_folio_file_placements_on_placement_type_and_placement_id (placement_type,placement_id) +# index_folio_file_placements_on_type (type) # diff --git a/app/models/folio/file_placement/cover.rb b/app/models/folio/file_placement/cover.rb index 54e5d8396..ac11208a2 100644 --- a/app/models/folio/file_placement/cover.rb +++ b/app/models/folio/file_placement/cover.rb @@ -25,9 +25,9 @@ class Folio::FilePlacement::Cover < Folio::FilePlacement::Base # # Indexes # -# index_folio_file_placements_on_file_id (file_id) -# index_folio_file_placements_on_placement (placement_type,placement_id) -# index_folio_file_placements_on_placement_title (placement_title) -# index_folio_file_placements_on_placement_title_type (placement_title_type) -# index_folio_file_placements_on_type (type) +# index_folio_file_placements_on_file_id (file_id) +# index_folio_file_placements_on_placement_title (placement_title) +# index_folio_file_placements_on_placement_title_type (placement_title_type) +# index_folio_file_placements_on_placement_type_and_placement_id (placement_type,placement_id) +# index_folio_file_placements_on_type (type) # diff --git a/app/models/folio/file_placement/document.rb b/app/models/folio/file_placement/document.rb index c886448c5..55d9280cf 100644 --- a/app/models/folio/file_placement/document.rb +++ b/app/models/folio/file_placement/document.rb @@ -23,9 +23,9 @@ class Folio::FilePlacement::Document < Folio::FilePlacement::Base # # Indexes # -# index_folio_file_placements_on_file_id (file_id) -# index_folio_file_placements_on_placement (placement_type,placement_id) -# index_folio_file_placements_on_placement_title (placement_title) -# index_folio_file_placements_on_placement_title_type (placement_title_type) -# index_folio_file_placements_on_type (type) +# index_folio_file_placements_on_file_id (file_id) +# index_folio_file_placements_on_placement_title (placement_title) +# index_folio_file_placements_on_placement_title_type (placement_title_type) +# index_folio_file_placements_on_placement_type_and_placement_id (placement_type,placement_id) +# index_folio_file_placements_on_type (type) # diff --git a/app/models/folio/file_placement/image.rb b/app/models/folio/file_placement/image.rb index 5237c33b8..ab0511f2e 100644 --- a/app/models/folio/file_placement/image.rb +++ b/app/models/folio/file_placement/image.rb @@ -25,9 +25,9 @@ class Folio::FilePlacement::Image < Folio::FilePlacement::Base # # Indexes # -# index_folio_file_placements_on_file_id (file_id) -# index_folio_file_placements_on_placement (placement_type,placement_id) -# index_folio_file_placements_on_placement_title (placement_title) -# index_folio_file_placements_on_placement_title_type (placement_title_type) -# index_folio_file_placements_on_type (type) +# index_folio_file_placements_on_file_id (file_id) +# index_folio_file_placements_on_placement_title (placement_title) +# index_folio_file_placements_on_placement_title_type (placement_title_type) +# index_folio_file_placements_on_placement_type_and_placement_id (placement_type,placement_id) +# index_folio_file_placements_on_type (type) # diff --git a/app/models/folio/file_placement/single_document.rb b/app/models/folio/file_placement/single_document.rb index 667bf4799..68315816f 100644 --- a/app/models/folio/file_placement/single_document.rb +++ b/app/models/folio/file_placement/single_document.rb @@ -23,9 +23,9 @@ class Folio::FilePlacement::SingleDocument < Folio::FilePlacement::Base # # Indexes # -# index_folio_file_placements_on_file_id (file_id) -# index_folio_file_placements_on_placement (placement_type,placement_id) -# index_folio_file_placements_on_placement_title (placement_title) -# index_folio_file_placements_on_placement_title_type (placement_title_type) -# index_folio_file_placements_on_type (type) +# index_folio_file_placements_on_file_id (file_id) +# index_folio_file_placements_on_placement_title (placement_title) +# index_folio_file_placements_on_placement_title_type (placement_title_type) +# index_folio_file_placements_on_placement_type_and_placement_id (placement_type,placement_id) +# index_folio_file_placements_on_type (type) # diff --git a/app/models/folio/site.rb b/app/models/folio/site.rb index a3f6b1e25..3df44ac95 100644 --- a/app/models/folio/site.rb +++ b/app/models/folio/site.rb @@ -101,6 +101,13 @@ def layout_twitter_meta } end + def <=>(other) + res = self.title <=> other.title + return res unless res.zero? + + self.id <=> other.id + end + def console_form_tabs_base %i[ header_message diff --git a/app/models/folio/user.rb b/app/models/folio/user.rb index 3b1bc59c2..7a8d1674f 100644 --- a/app/models/folio/user.rb +++ b/app/models/folio/user.rb @@ -58,6 +58,13 @@ class Folio::User < Folio::ApplicationRecord before_update :update_has_generated_password + def <=>(other) + res = self.full_name <=> other.full_name + return res unless res.zero? + + self.id <=> other.id + end + def full_name if first_name.present? || last_name.present? "#{first_name} #{last_name}".strip diff --git a/folio.gemspec b/folio.gemspec index 9735f59ea..09e69de85 100644 --- a/folio.gemspec +++ b/folio.gemspec @@ -82,7 +82,7 @@ Gem::Specification.new do |s| s.add_development_dependency "better_errors" s.add_development_dependency "binding_of_caller" # used by BetterErrors s.add_development_dependency "capybara" - s.add_development_dependency "factory_bot" + s.add_development_dependency "factory_bot_rails" s.add_development_dependency "guard-rubocop" s.add_development_dependency "guard-slimlint" s.add_development_dependency "letter_opener" diff --git a/lib/folio.rb b/lib/folio.rb index 13b60e5ac..d2025efe1 100644 --- a/lib/folio.rb +++ b/lib/folio.rb @@ -66,7 +66,7 @@ def self.current_site(request: nil) if Rails.application.config.folio_site_is_a_singleton Folio::Site.instance else - fail "You must implement this yourself" + fail "You must implement :current_site yourself" end end diff --git a/lib/folio/engine.rb b/lib/folio/engine.rb index 75f226b91..d1e71cc92 100644 --- a/lib/folio/engine.rb +++ b/lib/folio/engine.rb @@ -1,5 +1,10 @@ # frozen_string_literal: true +begin + require 'factory_bot_rails' +rescue LoadError +end + module Folio class Engine < ::Rails::Engine isolate_namespace Folio @@ -86,6 +91,8 @@ class Engine < ::Rails::Engine } } + config.factory_bot.definition_file_paths += [self.root.join('test/factories')] if defined?(FactoryBotRails) + initializer :append_folio_assets_paths do |app| app.config.assets.paths << self.root.join("app/cells") app.config.assets.paths << self.root.join("vendor/assets/javascripts") @@ -99,7 +106,7 @@ class Engine < ::Rails::Engine end initializer :append_migrations do |app| - unless app.root.to_s.include? root.to_s + unless app.root.to_s.include?(root.to_s + "/") config.paths["db/migrate"].expanded.each do |expanded_path| app.config.paths["db/migrate"] << expanded_path end @@ -123,7 +130,7 @@ class Engine < ::Rails::Engine deprecations << "Missing index_folio_pages_on_by_query index on folio_pages. That is probably caused by using traco title_* attributes. Add a custom one." end - if !Rails.env.test? && ActiveRecord::Base.connection.exec_query("SELECT id FROM folio_email_templates LIMIT 1;").rows.size == 0 + if !Rails.env.test? && ActiveRecord::Base.connection.exec_query("SELECT id FROM folio_email_templates WHERE mailer ='Folio::DeviseMailer' LIMIT 1;").rows.size == 0 deprecations << "There are no email templates present. Seed them via rake folio:email_templates:idp_seed" end rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished, ActiveRecord::StatementInvalid diff --git a/lib/generators/folio/install_generator.rb b/lib/generators/folio/install_generator.rb index 64bab9e01..58f4e5a71 100644 --- a/lib/generators/folio/install_generator.rb +++ b/lib/generators/folio/install_generator.rb @@ -87,7 +87,6 @@ def copy_templates "db/migrate/20220214083648_rm_private_attachments_mime_type_column.rb", "lib/tasks/developer_tools.rake", "public/maintenance.html", - "test/factories.rb", "test/test_helper.rb", "vendor/assets/bower.json", ].each { |f| template "#{f}.tt", f.gsub("application_namespace_path", application_namespace_path) } diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index c4235dc9c..30a61104b 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -123,7 +123,7 @@ t.index ["invitation_token"], name: "index_folio_accounts_on_invitation_token", unique: true t.index ["invitations_count"], name: "index_folio_accounts_on_invitations_count" t.index ["invited_by_id"], name: "index_folio_accounts_on_invited_by_id" - t.index ["invited_by_type", "invited_by_id"], name: "index_folio_accounts_on_invited_by" + t.index ["invited_by_type", "invited_by_id"], name: "index_folio_accounts_on_invited_by_type_and_invited_by_id" t.index ["reset_password_token"], name: "index_folio_accounts_on_reset_password_token", unique: true end @@ -221,7 +221,7 @@ t.index ["file_id"], name: "index_folio_file_placements_on_file_id" t.index ["placement_title"], name: "index_folio_file_placements_on_placement_title" t.index ["placement_title_type"], name: "index_folio_file_placements_on_placement_title_type" - t.index ["placement_type", "placement_id"], name: "index_folio_file_placements_on_placement" + t.index ["placement_type", "placement_id"], name: "index_folio_file_placements_on_placement_type_and_placement_id" t.index ["type"], name: "index_folio_file_placements_on_type" end @@ -501,7 +501,7 @@ t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.index "to_tsvector('simple'::regconfig, folio_unaccent(COALESCE(content, ''::text)))", name: "index_pg_search_documents_on_public_search", using: :gin - t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable" + t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable_type_and_searchable_id" end create_table "taggings", id: :serial, force: :cascade do |t| diff --git a/test/test_helper.rb b/test/test_helper.rb index 65f915c05..09e68b1f6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,6 +5,3 @@ ActiveRecord::Migrator.migrations_paths << File.expand_path("../../db/migrate", __FILE__) require "test_helper_base" - -FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), "factories") -FactoryBot.find_definitions