зеркало из
https://github.com/rs-pro/activeadmin-quill_editor.git
synced 2026-09-05 03:05:50 +03:00
Add specs configuration
Этот коммит содержится в:
7
spec/dummy/app/models/application_record.rb
Обычный файл
7
spec/dummy/app/models/application_record.rb
Обычный файл
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
|
||||
scope :published, -> {}
|
||||
end
|
||||
25
spec/dummy/app/models/author.rb
Обычный файл
25
spec/dummy/app/models/author.rb
Обычный файл
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Author < ApplicationRecord
|
||||
has_many :posts
|
||||
has_many :published_posts, -> { published }, class_name: 'Post'
|
||||
has_many :recent_posts, -> { recents }, class_name: 'Post'
|
||||
|
||||
has_many :tags, through: :posts
|
||||
|
||||
has_one :profile, inverse_of: :author, dependent: :destroy
|
||||
|
||||
has_one_attached :avatar
|
||||
|
||||
accepts_nested_attributes_for :profile, allow_destroy: true
|
||||
|
||||
validates :email, format: { with: /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\z/i, message: 'Invalid email' }
|
||||
|
||||
validate -> {
|
||||
errors.add( :base, 'Invalid age' ) if !age || age.to_i % 3 == 1
|
||||
}
|
||||
|
||||
def to_s
|
||||
"#{name} (#{age})"
|
||||
end
|
||||
end
|
||||
0
spec/dummy/app/models/concerns/.keep
Обычный файл
0
spec/dummy/app/models/concerns/.keep
Обычный файл
25
spec/dummy/app/models/post.rb
Обычный файл
25
spec/dummy/app/models/post.rb
Обычный файл
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Post < ApplicationRecord
|
||||
enum state: %i[available unavailable arriving]
|
||||
|
||||
belongs_to :author, inverse_of: :posts, autosave: true
|
||||
|
||||
has_one :author_profile, through: :author, source: :profile
|
||||
|
||||
has_many :post_tags, inverse_of: :post, dependent: :destroy
|
||||
has_many :tags, through: :post_tags
|
||||
|
||||
validates :title, allow_blank: false, presence: true
|
||||
|
||||
scope :published, -> { where(published: true) }
|
||||
scope :recents, -> { where('created_at > ?', Date.today - 8.month) }
|
||||
|
||||
def short_title
|
||||
title.truncate 10
|
||||
end
|
||||
|
||||
def upper_title
|
||||
title.upcase
|
||||
end
|
||||
end
|
||||
9
spec/dummy/app/models/post_tag.rb
Обычный файл
9
spec/dummy/app/models/post_tag.rb
Обычный файл
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PostTag < ApplicationRecord
|
||||
belongs_to :post, inverse_of: :post_tags
|
||||
belongs_to :tag, inverse_of: :post_tags
|
||||
|
||||
validates :post, presence: true
|
||||
validates :tag, presence: true
|
||||
end
|
||||
9
spec/dummy/app/models/profile.rb
Обычный файл
9
spec/dummy/app/models/profile.rb
Обычный файл
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Profile < ApplicationRecord
|
||||
belongs_to :author, inverse_of: :profile, touch: true
|
||||
|
||||
def to_s
|
||||
description
|
||||
end
|
||||
end
|
||||
6
spec/dummy/app/models/tag.rb
Обычный файл
6
spec/dummy/app/models/tag.rb
Обычный файл
@@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Tag < ApplicationRecord
|
||||
has_many :post_tags, inverse_of: :tag, dependent: :destroy
|
||||
has_many :posts, through: :post_tags
|
||||
end
|
||||
Ссылка в новой задаче
Block a user