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

Add RSpecs Coverage for Models #693

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/models/arabic_transliteration_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/models/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/models/chapter_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 11 additions & 2 deletions spec/models/chapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
9 changes: 2 additions & 7 deletions spec/models/char_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/data_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions spec/models/foot_note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions spec/support/matchers/include_module.rb
Original file line number Diff line number Diff line change
@@ -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