diff --git a/spec/models/arabic_transliteration_spec.rb b/spec/models/arabic_transliteration_spec.rb new file mode 100644 index 00000000..5ea58207 --- /dev/null +++ b/spec/models/arabic_transliteration_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe ArabicTransliteration, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:word) } + end +end diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index a98590f6..29474b69 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -18,9 +18,15 @@ context 'with associations' do it { is_expected.to have_many(:translated_names) } it { is_expected.to have_many(:resource_contents) } + + it { is_expected.to have_one(:translated_name) } end context 'with columns and indexes' do it_behaves_like 'modal with column', name: :string, url: :string end + + context 'with modules' do + it { is_expected.to include_module(NameTranslateable) } + end end diff --git a/spec/models/chapter_info_spec.rb b/spec/models/chapter_info_spec.rb index d43d2c27..f6027232 100644 --- a/spec/models/chapter_info_spec.rb +++ b/spec/models/chapter_info_spec.rb @@ -25,6 +25,11 @@ require 'rails_helper' RSpec.describe ChapterInfo do + describe 'modules' do + it { is_expected.to include_module(LanguageFilterable) } + it { is_expected.to include_module(Resourceable) } + end + context 'with associations' do it { is_expected.to belong_to :language } it { is_expected.to belong_to :chapter } diff --git a/spec/models/chapter_spec.rb b/spec/models/chapter_spec.rb index f7b0f76e..927bbcab 100644 --- a/spec/models/chapter_spec.rb +++ b/spec/models/chapter_spec.rb @@ -29,10 +29,13 @@ RSpec.describe Chapter do context 'with associations and scopes' do - it { is_expected.to have_many :verses } - it { is_expected.to have_many :translated_names } it { is_expected.to have_many :chapter_infos } + it { is_expected.to have_many :navigation_search_records } it { is_expected.to have_many :slugs } + it { is_expected.to have_many :translated_names } + it { is_expected.to have_many :verses } + + it { is_expected.to have_one(:default_slug).class_name('Slug') } it { is_expected.to have_one :translated_name } it { is_expected.to serialize :pages } @@ -59,4 +62,10 @@ it_behaves_like 'modal with column', columns it_behaves_like 'modal have indexes on column', ['chapter_number'] end + + context 'with modules' do + [NameTranslateable, QuranNavigationSearchable, Slugable].each do |module_name| + it { is_expected.to include_module module_name } + end + end end diff --git a/spec/models/char_type_spec.rb b/spec/models/char_type_spec.rb index 2ee5ccb0..05cd3b43 100644 --- a/spec/models/char_type_spec.rb +++ b/spec/models/char_type_spec.rb @@ -20,14 +20,9 @@ RSpec.describe CharType do context 'with associations' do - it { expect(subject).to belong_to(:parent) - .class_name('CharType') - } + it { is_expected.to belong_to(:parent).class_name('CharType') } - it { expect(subject).to have_many(:children) - .class_name('CharType') - .with_foreign_key('parent_id') - } + it { is_expected.to have_many(:children).class_name('CharType').with_foreign_key('parent_id') } end context 'with columns and indexes' do diff --git a/spec/models/data_source_spec.rb b/spec/models/data_source_spec.rb index e6ff1b84..7dcafd41 100644 --- a/spec/models/data_source_spec.rb +++ b/spec/models/data_source_spec.rb @@ -15,7 +15,7 @@ RSpec.describe DataSource do context 'with associations' do - it { should have_many(:resource_contents) } + it { is_expected.to have_many(:resource_contents) } end context 'columns and indexes' do diff --git a/spec/models/foot_note_spec.rb b/spec/models/foot_note_spec.rb index 16fcbdfd..2a817245 100644 --- a/spec/models/foot_note_spec.rb +++ b/spec/models/foot_note_spec.rb @@ -24,7 +24,6 @@ RSpec.describe FootNote do context 'with associations' do - it { is_expected.to belong_to :resource } it { is_expected.to belong_to :language } it { is_expected.to belong_to :resource_content } end @@ -42,7 +41,7 @@ indexes = [ ['language_id'], ['resource_content_id'], - ['resource_type', 'resource_id'] + %w[resource_type resource_id] ] it_behaves_like 'modal with column', columns diff --git a/spec/support/matchers/include_module.rb b/spec/support/matchers/include_module.rb new file mode 100644 index 00000000..fc7ed122 --- /dev/null +++ b/spec/support/matchers/include_module.rb @@ -0,0 +1,27 @@ +# Define a custom RSpec matcher called `include_module`. +# This matcher checks if a model includes a specified module. +RSpec::Matchers.define :include_module do |expected_module| + match do |model| + # @param expected_module [Module] The module that should be included in the model. + # @return [Boolean] True if the model's ancestors include the expected module, false otherwise. + model.class.included_modules.include?(expected_module) + end + + # Failure message when the matcher fails. + failure_message do |model| + # @return [String] The failure message to be displayed if the model does not include the expected module. + "expected #{model.class} to include the module #{expected_module}" + end + + # Failure message when the matcher is negated. + failure_message_when_negated do |model| + # @return [String] The failure message to be displayed if the model includes the module unexpectedly. + "expected #{model.class} not to include the module #{expected_module}" + end + + # Provide a description of the matcher for documentation or output. + description do + # @return [String] A description of the matcher. + "include the module #{expected_module}" + end +end