Back to Repositories

Testing ShowInApp Action Implementation in rails_admin

This test suite validates the ShowInApp action functionality in Rails Admin, focusing on the proper implementation of Turbo attributes in show links. The tests ensure correct rendering and behavior of show links in both index and detail views.

Test Coverage Overview

The test suite covers the ShowInApp action functionality with specific focus on data-turbo attributes.

Key areas tested include:
  • Link presence in index view
  • Turbo attribute configuration
  • Show link behavior verification
  • Integration with Player model

Implementation Analysis

The testing approach utilizes RSpec’s request specs to validate UI elements and link attributes. The implementation leverages Factory Bot for test data generation and employs page object patterns for UI interaction verification.

Framework-specific features include:
  • RSpec expectation matchers
  • Capybara selectors
  • Factory Bot fixtures

Technical Details

Testing tools and configuration:
  • RSpec for test framework
  • Capybara for page interaction
  • Factory Bot for test data
  • Request spec type configuration
  • CSS selector validation

Best Practices Demonstrated

The test suite demonstrates several testing best practices including isolated test scope, clear subject definition, and explicit expectations.

Notable practices:
  • Subject definition for clear context
  • Focused test scenarios
  • Explicit selector verification
  • Factory-based test data management

railsadminteam/rails_admin

spec/integration/actions/show_in_app_spec.rb

            
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'ShowInApp action', type: :request do
  subject { page }

  describe 'link' do
    let!(:player) { FactoryBot.create :player }

    it 'has the data-turbo: false attribute' do
      visit index_path(model_name: 'player')
      is_expected.to have_selector(%(li[title="Show in app"] a[data-turbo="false"]))
      click_link 'Show'
      is_expected.to have_selector(%(a[data-turbo="false"]), text: 'Show in app')
    end
  end
end