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

Not copying Folio factories to main app, just add them to lookup #143

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/folio/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true

module Folio
module Console
module SimpleFormComponents
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/folio/belongs_to_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions app/models/folio/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
10 changes: 5 additions & 5 deletions app/models/folio/file_placement/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
10 changes: 5 additions & 5 deletions app/models/folio/file_placement/cover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
10 changes: 5 additions & 5 deletions app/models/folio/file_placement/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
10 changes: 5 additions & 5 deletions app/models/folio/file_placement/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
10 changes: 5 additions & 5 deletions app/models/folio/file_placement/single_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
7 changes: 7 additions & 0 deletions app/models/folio/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

mreq marked this conversation as resolved.
Show resolved Hide resolved
def console_form_tabs_base
%i[
header_message
Expand Down
7 changes: 7 additions & 0 deletions app/models/folio/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

mreq marked this conversation as resolved.
Show resolved Hide resolved
def full_name
if first_name.present? || last_name.present?
"#{first_name} #{last_name}".strip
Expand Down
2 changes: 1 addition & 1 deletion folio.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/folio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions lib/folio/engine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# frozen_string_literal: true

begin
require 'factory_bot_rails'
rescue LoadError
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proc begin/rescue a proc ne jen v test env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ne v každém projektu nutně máme factory_bot_rails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Například Folio mělo do teď jen factory_bot (viz změny v gemspecu)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V kazdem projektu s foliem a s factories ale ano, nebo ne?

module Folio
class Engine < ::Rails::Engine
isolate_namespace Folio
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/generators/folio/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foton Takhle tam ale ten soubor vubec nevznikne. Soubor tam chceme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ano, to je to kopírování,, které se snažím nahradit linkováním.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Takhle to ale zustalo v templates. Radeji nez vyhazovat odsud bych upravil ten soubor. Abych ho nemusel v novem projektu zakladat.

"vendor/assets/bower.json",
].each { |f| template "#{f}.tt", f.gsub("application_namespace_path", application_namespace_path) }
Expand Down
6 changes: 3 additions & 3 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand Down
3 changes: 0 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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