Skip to content
Merged
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
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby-version: ['3.2', '3.3', '3.4', '4.0']
rails-version: ['7.0', '7.1', '7.2', '8.1']

name: Ruby ${{ matrix.ruby-version }} / Rails ${{ matrix.rails-version }}

env:
RAILS_VERSION: ${{ matrix.rails-version }}

steps:
- uses: actions/checkout@v4

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
cache-version: rails-${{ matrix.rails-version }}

- name: Fix default gem directory permissions
run: |
gem_dir=$(ruby -e 'puts Gem.default_dir')
if [ -d "$gem_dir/gems" ]; then
chmod +t "$gem_dir/gems" 2>/dev/null || true
fi

- name: Run tests
run: bundle exec rspec
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
.rspec_status

Gemfile.lock
/**/CLAUDE.md
mise.toml
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in bankai.gemspec
gemspec

if ENV['RAILS_VERSION']
gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
end
4 changes: 2 additions & 2 deletions lib/bankai/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def setup_dotfiles

def generate_default
run('bundle binstubs bundler')
Bundler.with_unbundled_env do
Bundler.with_original_env do
generate('bankai:testing') unless options[:skip_rspec]
generate('bankai:ci', options.api? ? '--api' : '')
generate('bankai:json')
Expand All @@ -109,7 +109,7 @@ def self.banner
protected

def rails_command(command, command_options = {})
Bundler.with_unbundled_env { super }
Bundler.with_original_env { super }
end

# rubocop:disable Naming/AccessorMethodName
Expand Down
2 changes: 1 addition & 1 deletion lib/bankai/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def pg?
end

def mysql?
gemfile.match?(/gem .mysql2./)
gemfile.match?(/gem .(mysql2|trilogy)./)
end

def capistrano?
Expand Down
3 changes: 1 addition & 2 deletions lib/bankai/version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Bankai
VERSION = '0.13.4'
RUBY_VERSION = '2.6.7'
VERSION = '0.14.0'
RAILS_VERSION = '7.0.0'
RUBOCOP_VERSION = '1.24.1'
CAPISTRANO_VERSION = '3.16.0'
Expand Down
138 changes: 138 additions & 0 deletions spec/bankai/generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# frozen_string_literal: true

require 'tmpdir'
require 'fileutils'
require 'open3'

RSpec.describe Bankai::Generator, :slow do
before(:all) do
@tmpdir = Dir.mktmpdir('bankai_test_')
@project_path = File.join(@tmpdir, 'testapp')

gem_root = File.expand_path('../..', __dir__)
bankai_bin = File.join(gem_root, 'exe', 'bankai')

output, status = Open3.capture2e(
'ruby', bankai_bin, 'testapp',
'--database=sqlite3',
'--skip-rspec',
"--path=#{gem_root}",
chdir: @tmpdir
)
unless status.success?
diag = "Ruby: #{RUBY_VERSION}, Bundler: #{Bundler::VERSION}\n"
diag += "GEM_HOME: #{ENV['GEM_HOME']}\n"
diag += "Gem.default_dir: #{Gem.default_dir}\n"
diag += "BUNDLE_GEMFILE: #{ENV['BUNDLE_GEMFILE']}\n"
diag += "Gemfile.lock exists: #{File.exist?(File.join(@project_path, 'Gemfile.lock'))}\n"
diag += ".bundle/config exists: #{File.exist?(File.join(@project_path, '.bundle', 'config'))}\n"
raise "Generator failed (exit #{status.exitstatus}):\n\n--- Diagnostics ---\n#{diag}\n--- Output (last 80 lines) ---\n#{output.lines.last(80).join}"
end
end

after(:all) do
FileUtils.remove_entry(@tmpdir) if @tmpdir
end

def project_file(*path)
File.join(@project_path, *path)
end

def read_project_file(*path)
File.read(project_file(*path))
end

describe 'Gemfile' do
subject(:gemfile) { read_project_file('Gemfile') }

it 'includes rails' do
expect(gemfile).to match(/gem ['"]rails['"]/)
end

it 'includes database adapter' do
expect(gemfile).to match(/gem ['"]sqlite3['"]/)
end

it 'includes bankai' do
expect(gemfile).to match(/gem ['"]bankai['"]/)
end
end

describe 'static files' do
it 'generates README.md' do
expect(File).to exist(project_file('README.md'))
end

it 'generates .gitignore' do
expect(File).to exist(project_file('.gitignore'))
end

it 'generates .env.example' do
expect(File).to exist(project_file('.env.example'))
end

it 'generates .ctags' do
expect(File).to exist(project_file('.ctags'))
end

it 'generates .gitlab-ci.yml' do
expect(File).to exist(project_file('.gitlab-ci.yml'))
end

it 'generates .overcommit.yml' do
expect(File).to exist(project_file('.overcommit.yml'))
end

it 'generates rack_mini_profiler initializer' do
expect(File).to exist(project_file('config', 'initializers', 'rack_mini_profiler.rb'))
end

it 'generates oj initializer' do
expect(File).to exist(project_file('config', 'initializers', 'oj.rb'))
end
end

describe 'configuration injection' do
it 'configures generators with rspec in application.rb' do
content = read_project_file('config', 'application.rb')
expect(content).to include('test_framework :rspec')
end

it 'configures quiet assets in application.rb' do
content = read_project_file('config', 'application.rb')
expect(content).to include('config.assets.quiet = true')
end

it 'configures puma-dev host in development.rb' do
content = read_project_file('config', 'environments', 'development.rb')
expect(content).to include('.test')
end

it 'configures Bullet in development.rb' do
content = read_project_file('config', 'environments', 'development.rb')
expect(content).to include('Bullet.enable')
end

it 'configures letter_opener in development.rb' do
content = read_project_file('config', 'environments', 'development.rb')
expect(content).to include('letter_opener')
end

it 'clears db/seeds.rb' do
expect(read_project_file('db', 'seeds.rb')).to be_empty
end
end

describe 'directory structure' do
%w[
spec/lib/.keep
spec/controllers/.keep
spec/helpers/.keep
spec/support/matchers/.keep
].each do |path|
it "creates #{path}" do
expect(File).to exist(project_file(path))
end
end
end
end
59 changes: 59 additions & 0 deletions spec/bankai/helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

RSpec.describe Bankai::Helper do
let(:test_instance) do
klass = Class.new do
include Bankai::Helper

attr_accessor :destination_root

public :pg?, :mysql?, :capistrano?
end
klass.new
end

before do
test_instance.destination_root = '/tmp/fake_app'
end

describe '#pg?' do
it 'returns true when Gemfile contains pg' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'pg'")
expect(test_instance.pg?).to be true
end

it 'returns false when Gemfile contains mysql2' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'mysql2'")
expect(test_instance.pg?).to be false
end
end

describe '#mysql?' do
it 'returns true when Gemfile contains mysql2' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'mysql2'")
expect(test_instance.mysql?).to be true
end

it 'returns true when Gemfile contains trilogy' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'trilogy'")
expect(test_instance.mysql?).to be true
end

it 'returns false when Gemfile contains pg' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'pg'")
expect(test_instance.mysql?).to be false
end
end

describe '#capistrano?' do
it 'returns true when Gemfile contains capistrano' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'capistrano'")
expect(test_instance.capistrano?).to be true
end

it 'returns false when Gemfile does not contain capistrano' do
allow(File).to receive(:read).with('/tmp/fake_app/Gemfile').and_return("gem 'pg'")
expect(test_instance.capistrano?).to be false
end
end
end
43 changes: 43 additions & 0 deletions spec/bankai/version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

RSpec.describe Bankai do
describe 'VERSION' do
it 'is defined' do
expect(Bankai::VERSION).not_to be_nil
end

it 'follows semver format' do
expect(Bankai::VERSION).to match(/\A\d+\.\d+\.\d+\z/)
end
end

describe 'RAILS_VERSION' do
it 'is defined' do
expect(Bankai::RAILS_VERSION).not_to be_nil
end

it 'follows semver format' do
expect(Bankai::RAILS_VERSION).to match(/\A\d+\.\d+\.\d+\z/)
end
end

describe 'RUBOCOP_VERSION' do
it 'is defined' do
expect(Bankai::RUBOCOP_VERSION).not_to be_nil
end

it 'follows semver format' do
expect(Bankai::RUBOCOP_VERSION).to match(/\A\d+\.\d+\.\d+\z/)
end
end

describe 'CAPISTRANO_VERSION' do
it 'is defined' do
expect(Bankai::CAPISTRANO_VERSION).not_to be_nil
end

it 'follows semver format' do
expect(Bankai::CAPISTRANO_VERSION).to match(/\A\d+\.\d+\.\d+\z/)
end
end
end
7 changes: 0 additions & 7 deletions spec/bankai_spec.rb

This file was deleted.

Loading