From 4f1ab5770d6bd66cbafc573e2ce9d7eac079c32d Mon Sep 17 00:00:00 2001 From: Jeff Parr Date: Fri, 27 May 2022 17:14:31 -0700 Subject: [PATCH] First commit --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ .ruby-version | 1 + README.md | 9 +++++++++ Rakefile | 9 +++++++++ template.rb | 24 ++++++++++++++++++++++++ test/template_test.rb | 19 +++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .ruby-version create mode 100644 README.md create mode 100644 Rakefile create mode 100644 template.rb create mode 100644 test/template_test.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..da9593c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: Tests + +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: '16.x' + + - name: Install dependencies + run: | + npm install -g npm + sudo apt-get -yqq install libsqlite3-dev libpq-dev libmysqlclient-dev + gem install rails + + # Clean up git repo so the new rails template doesn't conflict + - name: Remove git repo + run: | + rm -rf .git + + - name: Run tests + run: | + rake diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..75a22a2 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.0.3 diff --git a/README.md b/README.md new file mode 100644 index 0000000..3558ce5 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +A Rails Application Template for use at Ministry of Velocity + +Reference: [Rails Application Templates](https://guides.rubyonrails.org/rails_application_templates.html) + + +Thank you to the following open source projects for inspiration and setup: + +[Jumpstart](https://github.com/excid3/jumpstart). +[https://github.com/mattbrictson/rails-template](https://github.com/mattbrictson/rails-template) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e0622f8 --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require "rake/testtask" + +Rake::TestTask.new(:test) do |t| + t.libs << "test" + t.libs << "lib" + t.test_files = FileList["test/**/*_test.rb"] +end + +task :default => :test diff --git a/template.rb b/template.rb new file mode 100644 index 0000000..6c6ace6 --- /dev/null +++ b/template.rb @@ -0,0 +1,24 @@ +def rails_version + @rails_version ||= Gem::Version.new(Rails::VERSION::STRING) +end + +def rails_7_or_newer? + Gem::Requirement.new(">= 7.0.0").satisfied_by? rails_version +end + +def add_gems + +end + +unless rails_7_or_newer? + say_error "-----------------------------", :red + say_error "Please use Rails 7.0 or newer", :red + say_error "-----------------------------", :red + # raise 'hell' +end + +add_gems + +after_bundle do + say "App successfully created!", :green +end diff --git a/test/template_test.rb b/test/template_test.rb new file mode 100644 index 0000000..3413265 --- /dev/null +++ b/test/template_test.rb @@ -0,0 +1,19 @@ +require "minitest/autorun" + +class TemplateTest < Minitest::Test + def setup + system("[ -d test_app ] && rm -rf test_app") + end + + def teardown + setup + end + + def test_generator_succeeds + output, error = capture_subprocess_io do + system("rails new test_app -m template.rb") + end + assert_includes output, "App successfully created!" + # puts error + end +end