From 47abba7b68e7134cf793ba9f2a9dc523bbeaf562 Mon Sep 17 00:00:00 2001 From: hk Date: Tue, 12 Nov 2024 03:47:19 +0500 Subject: [PATCH 1/6] add include module specs for chapter info spec model --- spec/models/chapter_info_spec.rb | 4 ++++ spec/support/matchers/include_module.rb | 27 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spec/support/matchers/include_module.rb diff --git a/spec/models/chapter_info_spec.rb b/spec/models/chapter_info_spec.rb index d43d2c27..37784439 100644 --- a/spec/models/chapter_info_spec.rb +++ b/spec/models/chapter_info_spec.rb @@ -25,6 +25,10 @@ require 'rails_helper' RSpec.describe ChapterInfo do + describe 'modules' do + it { is_expected.to include_module(ActionView::Helpers::NumberHelper) } + end + context 'with associations' do it { is_expected.to belong_to :language } it { is_expected.to belong_to :chapter } 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 From 4b879fb8f31ebaadcdb28418bdd98e9ad60a1758 Mon Sep 17 00:00:00 2001 From: hk Date: Tue, 12 Nov 2024 20:56:31 +0500 Subject: [PATCH 2/6] Add modules inclusion specs for Chapter Info model --- spec/models/chapter_info_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/models/chapter_info_spec.rb b/spec/models/chapter_info_spec.rb index 37784439..f6027232 100644 --- a/spec/models/chapter_info_spec.rb +++ b/spec/models/chapter_info_spec.rb @@ -26,7 +26,8 @@ RSpec.describe ChapterInfo do describe 'modules' do - it { is_expected.to include_module(ActionView::Helpers::NumberHelper) } + it { is_expected.to include_module(LanguageFilterable) } + it { is_expected.to include_module(Resourceable) } end context 'with associations' do From f2f8dc22cc9c881661bc761059d4db6f145fdf2e Mon Sep 17 00:00:00 2001 From: hk Date: Wed, 13 Nov 2024 03:11:19 +0500 Subject: [PATCH 3/6] add associations specs for arabic transliteration model --- spec/models/arabic_transliteration_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/models/arabic_transliteration_spec.rb 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 From 1b2f8ce081ee597be03435cbed00be76c2c8fad9 Mon Sep 17 00:00:00 2001 From: hk Date: Wed, 13 Nov 2024 03:22:36 +0500 Subject: [PATCH 4/6] add module and associations specs for author model --- spec/models/author_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) 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 From c92246dea97256556ca6ed73a155909c33248247 Mon Sep 17 00:00:00 2001 From: hk Date: Wed, 13 Nov 2024 03:29:43 +0500 Subject: [PATCH 5/6] add specs for Chapter model --- spec/models/chapter_spec.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 From e31c6e97d9f67b90969a4dbd3a988c8c008ba911 Mon Sep 17 00:00:00 2001 From: hk Date: Wed, 13 Nov 2024 03:42:20 +0500 Subject: [PATCH 6/6] char type specs, foot note specs and data source specs code refactor --- spec/models/char_type_spec.rb | 9 ++------- spec/models/data_source_spec.rb | 2 +- spec/models/foot_note_spec.rb | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) 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