mirror of
https://github.com/czhu12/canine.git
synced 2025-12-20 10:19:50 -06:00
added spec coverage
This commit is contained in:
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@@ -53,10 +53,19 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
RAILS_ENV: test
|
RAILS_ENV: test
|
||||||
DATABASE_URL: postgres://postgres:postgres@localhost:5432
|
DATABASE_URL: postgres://postgres:postgres@localhost:5432
|
||||||
|
CI: true
|
||||||
run: |
|
run: |
|
||||||
bin/rails db:test:prepare
|
bin/rails db:test:prepare
|
||||||
bin/bundle exec rspec --exclude-pattern spec/system/local/**/*_spec.rb
|
bin/bundle exec rspec --exclude-pattern spec/system/local/**/*_spec.rb
|
||||||
|
|
||||||
|
- name: Upload coverage report
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: coverage-report
|
||||||
|
path: coverage/
|
||||||
|
if-no-files-found: ignore
|
||||||
|
|
||||||
- name: Keep screenshots from failed system tests
|
- name: Keep screenshots from failed system tests
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
if: failure()
|
if: failure()
|
||||||
|
|||||||
12
spec/actions/add_ons/filter_spec.rb
Normal file
12
spec/actions/add_ons/filter_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe AddOns::Filter do
|
||||||
|
it 'filters add_ons by name with case-insensitive ILIKE' do
|
||||||
|
cluster = create(:cluster)
|
||||||
|
redis = create(:add_on, cluster: cluster, name: 'redis-cache')
|
||||||
|
create(:add_on, cluster: cluster, name: 'postgres-db')
|
||||||
|
|
||||||
|
expect(described_class.execute(params: { q: 'REDIS' }, add_ons: AddOn.all).add_ons).to eq([redis])
|
||||||
|
expect(described_class.execute(params: { q: '' }, add_ons: AddOn.all).add_ons.count).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
12
spec/actions/clusters/filter_spec.rb
Normal file
12
spec/actions/clusters/filter_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Clusters::Filter do
|
||||||
|
it 'filters clusters by name with case-insensitive ILIKE' do
|
||||||
|
account = create(:account)
|
||||||
|
prod = create(:cluster, account: account, name: 'production-us')
|
||||||
|
create(:cluster, account: account, name: 'staging-eu')
|
||||||
|
|
||||||
|
expect(described_class.execute(params: { q: 'PROD' }, clusters: Cluster.all).clusters).to eq([prod])
|
||||||
|
expect(described_class.execute(params: { q: '' }, clusters: Cluster.all).clusters.count).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
12
spec/actions/projects/filter_spec.rb
Normal file
12
spec/actions/projects/filter_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Projects::Filter do
|
||||||
|
it 'filters projects by name with case-insensitive ILIKE' do
|
||||||
|
cluster = create(:cluster)
|
||||||
|
api = create(:project, cluster: cluster, account: cluster.account, name: 'api-service')
|
||||||
|
create(:project, cluster: cluster, account: cluster.account, name: 'web-frontend')
|
||||||
|
|
||||||
|
expect(described_class.execute(params: { q: 'API' }, projects: Project.all).projects).to eq([api])
|
||||||
|
expect(described_class.execute(params: { q: '' }, projects: Project.all).projects.count).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
14
spec/actions/services/create_spec.rb
Normal file
14
spec/actions/services/create_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Services::Create do
|
||||||
|
it 'saves the service with associations' do
|
||||||
|
project = create(:project)
|
||||||
|
service = build(:service, :cron_job, project: project)
|
||||||
|
|
||||||
|
result = described_class.call(service, { service: {} })
|
||||||
|
|
||||||
|
expect(result).to be_success
|
||||||
|
expect(service).to be_persisted
|
||||||
|
expect(service.cron_schedule).to be_persisted
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,6 +8,7 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ
|
|||||||
# that will avoid rails generators crashing because migrations haven't been run yet
|
# that will avoid rails generators crashing because migrations haven't been run yet
|
||||||
# return unless Rails.env.test?
|
# return unless Rails.env.test?
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
|
require 'factory_bot_rails'
|
||||||
require 'support/webmock'
|
require 'support/webmock'
|
||||||
# Add additional requires below this line. Rails is not loaded until this point!
|
# Add additional requires below this line. Rails is not loaded until this point!
|
||||||
|
|
||||||
@@ -34,6 +35,8 @@ rescue ActiveRecord::PendingMigrationError => e
|
|||||||
abort e.to_s.strip
|
abort e.to_s.strip
|
||||||
end
|
end
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
config.include FactoryBot::Syntax::Methods
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,23 @@
|
|||||||
require 'factory_bot_rails'
|
|
||||||
require 'simplecov'
|
require 'simplecov'
|
||||||
SimpleCov.start 'rails'
|
|
||||||
|
SimpleCov.start 'rails' do
|
||||||
|
enable_coverage :branch
|
||||||
|
|
||||||
|
add_filter '/spec/'
|
||||||
|
add_filter '/config/'
|
||||||
|
add_filter '/vendor/'
|
||||||
|
|
||||||
|
add_group 'Models', 'app/models'
|
||||||
|
add_group 'Controllers', 'app/controllers'
|
||||||
|
add_group 'Services', 'app/services'
|
||||||
|
add_group 'Actions', 'app/actions'
|
||||||
|
add_group 'Jobs', 'app/jobs'
|
||||||
|
add_group 'Helpers', 'app/helpers'
|
||||||
|
|
||||||
|
if ENV['CI']
|
||||||
|
minimum_coverage line: 5, branch: 5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
||||||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
||||||
@@ -18,7 +35,6 @@ SimpleCov.start 'rails'
|
|||||||
#
|
#
|
||||||
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include FactoryBot::Syntax::Methods
|
|
||||||
# rspec-expectations config goes here. You can use an alternate
|
# rspec-expectations config goes here. You can use an alternate
|
||||||
# assertion/expectation library such as wrong or the stdlib/minitest
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
||||||
# assertions if you prefer.
|
# assertions if you prefer.
|
||||||
|
|||||||
Reference in New Issue
Block a user