Skip to content

Commit

Permalink
fix: issue #68 + chore: annotate models
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Dec 8, 2023
1 parent dcd3d3e commit 6a64d18
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gem 'rails', '~> 7.1'
gem 'image_processing', '~> 1.12.2'

# Use Sprockets to deal with assets in the dummy app
gem "sprockets-rails"
gem 'sprockets-rails'

# Temporary use this branch because it solves a bug
# gem 'maglev-injectable', path: '../injectable'
Expand All @@ -41,6 +41,8 @@ group :development, :test do
gem 'generator_spec'

gem 'nokogiri', '>= 1.13.10'

gem 'annotate'
end

group :test do
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
Expand Down Expand Up @@ -322,6 +325,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
annotate
bcrypt
factory_bot_rails (~> 6.2.0)
generator_spec
Expand Down
14 changes: 14 additions & 0 deletions app/models/maglev/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ def self.search(keyword, type, page = nil, per_page = nil)
end
end
end

# == Schema Information
#
# Table name: maglev_assets
#
# id :bigint not null, primary key
# byte_size :integer
# content_type :string
# filename :string
# height :integer
# width :integer
# created_at :datetime not null
# updated_at :datetime not null
#
18 changes: 18 additions & 0 deletions app/models/maglev/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ def translate_in(locale, source_locale)
end
end
end

# == Schema Information
#
# Table name: maglev_pages
#
# id :bigint not null, primary key
# lock_version :integer
# meta_description_translations :jsonb
# og_description_translations :jsonb
# og_image_url_translations :jsonb
# og_title_translations :jsonb
# sections_translations :jsonb
# seo_title_translations :jsonb
# title_translations :jsonb
# visible :boolean default(TRUE)
# created_at :datetime not null
# updated_at :datetime not null
#
3 changes: 2 additions & 1 deletion app/models/maglev/page/search_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def search_title_clause(query, locale)

def search_path_clause(query, locale)
path = Maglev::PagePath.arel_table[:value]
path.matches(query).and(path.eq(locale))
path_locale = Maglev::PagePath.arel_table[:locale]
path.matches(query).and(path_locale.eq(locale))
end

def search_title_node(locale)
Expand Down
17 changes: 17 additions & 0 deletions app/models/maglev/page_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ def clean_value
end
end
end

# == Schema Information
#
# Table name: maglev_page_paths
#
# id :bigint not null, primary key
# canonical :boolean default(TRUE)
# locale :string not null
# value :string not null
# maglev_page_id :bigint
#
# Indexes
#
# canonical_speed (canonical,locale,value)
# index_maglev_page_paths_on_maglev_page_id (maglev_page_id)
# scoped_canonical_speed (canonical,maglev_page_id,locale)
#
24 changes: 24 additions & 0 deletions app/models/maglev/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ def translate_in(locale, source_locale)
end
end
end

# == Schema Information
#
# Table name: maglev_sites
#
# id :bigint not null, primary key
# domain :string
# handle :string
# locales :jsonb
# lock_version :integer
# name :string
# navigation :jsonb
# sections_translations :jsonb
# siteable_type :string
# style :jsonb
# created_at :datetime not null
# updated_at :datetime not null
# siteable_id :bigint
# theme_id :string
#
# Indexes
#
# index_maglev_sites_on_siteable (siteable_type,siteable_id)
#
61 changes: 61 additions & 0 deletions lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
require 'annotate'
task set_annotation_options: :environment do
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults(
active_admin: 'false',
additional_file_patterns: [],
routes: 'false',
models: 'true',
position_in_routes: 'before',
position_in_class: 'bottom',
position_in_test: 'bottom',
position_in_fixture: 'bottom',
position_in_factory: 'bottom',
position_in_serializer: 'bottom',
show_foreign_keys: 'true',
show_complete_foreign_keys: 'false',
show_indexes: 'true',
simple_indexes: 'false',
model_dir: 'app/models',
root_dir: '',
include_version: 'false',
require: '',
exclude_tests: 'false',
exclude_fixtures: 'false',
exclude_factories: 'false',
exclude_serializers: 'false',
exclude_scaffolds: 'true',
exclude_controllers: 'true',
exclude_helpers: 'true',
exclude_sti_subclasses: 'false',
ignore_model_sub_dir: 'false',
ignore_columns: nil,
ignore_routes: nil,
ignore_unknown_models: 'false',
hide_limit_column_types: 'integer,bigint,boolean',
hide_default_column_types: 'json,jsonb,hstore',
skip_on_db_migrate: 'false',
format_bare: 'true',
format_rdoc: 'false',
format_yard: 'false',
format_markdown: 'false',
sort: 'false',
force: 'false',
frozen: 'false',
classified_sort: 'true',
trace: 'false',
wrapper_open: nil,
wrapper_close: nil,
with_comment: 'true'
)
end

Annotate.load_tasks
end
2 changes: 1 addition & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Application < Rails::Application
else
config.load_defaults 6.0
end

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
10 changes: 5 additions & 5 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
config.cache_store = :null_store

# Raise exceptions instead of rendering exception templates.
if Rails::VERSION::MAJOR > 6
config.action_dispatch.show_exceptions = :none
else
config.action_dispatch.show_exceptions = false
end
config.action_dispatch.show_exceptions = if Rails::VERSION::MAJOR > 6
:none
else
false
end

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
Expand Down
14 changes: 14 additions & 0 deletions spec/factories/maglev/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@
content_type { 'image/jpg' }
end
end

# == Schema Information
#
# Table name: maglev_assets
#
# id :bigint not null, primary key
# byte_size :integer
# content_type :string
# filename :string
# height :integer
# width :integer
# created_at :datetime not null
# updated_at :datetime not null
#
18 changes: 18 additions & 0 deletions spec/factories/maglev/pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,21 @@
end
end
end

# == Schema Information
#
# Table name: maglev_pages
#
# id :bigint not null, primary key
# lock_version :integer
# meta_description_translations :jsonb
# og_description_translations :jsonb
# og_image_url_translations :jsonb
# og_title_translations :jsonb
# sections_translations :jsonb
# seo_title_translations :jsonb
# title_translations :jsonb
# visible :boolean default(TRUE)
# created_at :datetime not null
# updated_at :datetime not null
#
24 changes: 24 additions & 0 deletions spec/factories/maglev/sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,27 @@
end
end
end

# == Schema Information
#
# Table name: maglev_sites
#
# id :bigint not null, primary key
# domain :string
# handle :string
# locales :jsonb
# lock_version :integer
# name :string
# navigation :jsonb
# sections_translations :jsonb
# siteable_type :string
# style :jsonb
# created_at :datetime not null
# updated_at :datetime not null
# siteable_id :bigint
# theme_id :string
#
# Indexes
#
# index_maglev_sites_on_siteable (siteable_type,siteable_id)
#
14 changes: 14 additions & 0 deletions spec/models/maglev/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@
end
end
end

# == Schema Information
#
# Table name: maglev_assets
#
# id :bigint not null, primary key
# byte_size :integer
# content_type :string
# filename :string
# height :integer
# width :integer
# created_at :datetime not null
# updated_at :datetime not null
#
27 changes: 27 additions & 0 deletions spec/models/maglev/page/search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Maglev::Page, type: :model do
describe 'search' do
before do
create(:page, title: 'Chicago', path: 'bands/chicago')
create(:page, title: 'Boston', path: 'bands/boston')
create(:page, title: 'San Francisco', path: 'cities/sf')
end

subject { described_class.search(q, 'en') }

describe 'Given we search from the title' do
let(:q) { 'boston' }

it { expect(subject.all.map(&:title).sort).to eq ['Boston'] }
end

describe 'Given we search from the path' do
let(:q) { 'bands' }

it { expect(subject.all.map(&:title).sort).to eq %w[Boston Chicago] }
end
end
end
17 changes: 17 additions & 0 deletions spec/models/maglev/page_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@
end
end
end

# == Schema Information
#
# Table name: maglev_page_paths
#
# id :bigint not null, primary key
# canonical :boolean default(TRUE)
# locale :string not null
# value :string not null
# maglev_page_id :bigint
#
# Indexes
#
# canonical_speed (canonical,locale,value)
# index_maglev_page_paths_on_maglev_page_id (maglev_page_id)
# scoped_canonical_speed (canonical,maglev_page_id,locale)
#
18 changes: 18 additions & 0 deletions spec/models/maglev/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@
end
end
end

# == Schema Information
#
# Table name: maglev_pages
#
# id :bigint not null, primary key
# lock_version :integer
# meta_description_translations :jsonb
# og_description_translations :jsonb
# og_image_url_translations :jsonb
# og_title_translations :jsonb
# sections_translations :jsonb
# seo_title_translations :jsonb
# title_translations :jsonb
# visible :boolean default(TRUE)
# created_at :datetime not null
# updated_at :datetime not null
#
Loading

0 comments on commit 6a64d18

Please sign in to comment.