Skip to content

Commit

Permalink
Prepare for 7.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
blowmage committed Oct 27, 2023
1 parent c870f2e commit f174389
Show file tree
Hide file tree
Showing 39 changed files with 184 additions and 162 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ jobs:
- '2.7'
- '3.0'
- '3.1'
- '3.2'
gemfile:
- gemfiles/rails-7.0.0.gemfile
- gemfiles/rails-7.1.0.gemfile

env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
AllCops:
TargetRubyVersion: 2.7
SuggestExtensions: false
NewCops: enable

Gemspec/DevelopmentDependencies:
Enabled: false

Layout/LineLength:
Max: 100
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ source "http://rubygems.org"
gemspec

gem "irb"
gem "rails", "~> 7.0.0"
gem "rails", "~> 7.1.0"
gem "rake"
gem "sqlite3"
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# minitest-rails

Minitest integration for Rails 7.0
Minitest integration for Rails 7.1

[![CI](https://github.com/blowmage/minitest-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/blowmage/minitest-rails/actions/workflows/ci.yml)
[![Code Climate](https://codeclimate.com/github/blowmage/minitest-rails.png)](https://codeclimate.com/github/blowmage/minitest-rails)
Expand All @@ -22,9 +22,16 @@ Create a new rails app:
### Choosing a version

This gem follows the versioning of Rails.
If you are running Rails 7.0, specify the corresponding 7.0 release in the Gemfile.
If you are running Rails 7.1, specify the corresponding 7.1 release in the Gemfile.
For example:

```ruby
gem "minitest-rails", "~> 7.1.0"
```

If you are running Rails 7.0, specify the corresponding 7.0 release in the Gemfile.
For example, if you are using Rails 6.1 you will specify:

```ruby
gem "minitest-rails", "~> 7.0.0"
```
Expand Down
8 changes: 4 additions & 4 deletions gemfiles/rails-7.0.0.gemfile → gemfiles/rails-7.1.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source "http://rubygems.org"

gem "minitest-rails", path: "../"
gem "rails", "~> 7.0.0"
gem "rails", "~> 7.1.0"
gem "rake"
gem "sqlite3"

gem "minitest-autotest", "~> 1.1"
gem "minitest-focus", "~> 1.3"
gem "minitest-focus", "~> 1.4"
gem "minitest-rg", "~> 5.2"
gem "rdoc", "~> 6.4"
gem "rubocop", "~> 1.28.0"
gem "rdoc", "~> 6.5"
gem "rubocop", "~> 1.57.0"
2 changes: 2 additions & 0 deletions lib/generators/minitest/controller/controller_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Minitest # :nodoc:
module Generators # :nodoc:
class ControllerGenerator < Base # :nodoc:
argument :actions, type: :array, default: [], banner: "action action"
class_option :skip_routes, type: :boolean

check_class_collision suffix: "ControllerTest"

def create_test_files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ describe <%= class_name %>Controller do
# end
<% else -%>
<% actions.each do |action| -%>
it "must get <%= action %>" do
it "gets <%= action %>" do
get <%= url_helper_prefix %>_<%= action %>_url
must_respond_with :success
end

<%= "\n" unless action == actions.last -%>
<% end -%>
<% end -%>
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
get <%= url_helper_prefix %>_<%= action %>_url
assert_response :success
end

<%= "\n" unless action == actions.last -%>
<% end -%>
<% end -%>
end
Expand Down
6 changes: 4 additions & 2 deletions lib/generators/minitest/generator/generator_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

require "generators/minitest"

module Minitest
module Generators
module Minitest # :nodoc:
module Generators # :nodoc:
class GeneratorGenerator < Base # :nodoc:
check_class_collision suffix: "GeneratorTest"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ require "test_helper"
require "<%= generator_path %>"

<% module_namespacing do -%>
describe <%= class_name %>Generator do
#tests <%= class_name %>Generator
describe <%= class_name %>Generator, :generator do
tests <%= class_name %>Generator
destination Rails.root.join("tmp/generators")
setup :prepare_destination

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ describe "ApplicationCable Connection", :connection do
# end
end
<%- else -%>
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
# def test_connects_with_cookies
# cookies.signed[:user_id] = 42
#
# connect
#
# assert_equal connection.user_id, "42"
# end
module ApplicationCable
class ConnectionTest < ActionCable::Connection::TestCase
# test "connects with cookies" do
# cookies.signed[:user_id] = 42
#
# connect
#
# assert_equal connection.user_id, "42"
# end
end
end
<%- end -%>
18 changes: 10 additions & 8 deletions lib/generators/minitest/install/templates/test/test_helper.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ require_relative "../config/environment"
require "rails/test_help"
require "minitest/rails"

class ActiveSupport::TestCase
# Run tests in parallel with specified workers
<% if defined?(JRUBY_VERSION) || Gem.win_platform? -%>
parallelize(workers: :number_of_processors, with: :threads)
module ActiveSupport
class TestCase
# Run tests in parallel with specified workers
<% if Process.respond_to?(:fork) && !Gem.win_platform? -%>
parallelize(workers: :number_of_processors)
<%- else -%>
parallelize(workers: :number_of_processors)
parallelize(workers: :number_of_processors, with: :threads)
<% end -%>

<% unless options[:skip_active_record] -%>
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all

<% end -%>
# Add more helper methods to be used by all tests here...
# Add more helper methods to be used by all tests here...
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<% module_namespacing do -%>
describe "<%= human_name %>", :integration do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<% module_namespacing do -%>
class <%= class_name %>Test < ActionDispatch::IntegrationTest
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/minitest/job/templates/unit_spec.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<% module_namespacing do -%>
describe <%= class_name %>Job do
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/minitest/job/templates/unit_test.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<% module_namespacing do -%>
class <%= class_name %>JobTest < ActiveJob::TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<% module_namespacing do -%>
class <%= class_name %>MailerTest < ActionMailer::TestCase
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/minitest/model/templates/unit_test.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<% module_namespacing do -%>
class <%= class_name %>Test < ActiveSupport::TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"

<%- if options[:spec] -%>
describe <%= class_name %> do
Expand Down
13 changes: 9 additions & 4 deletions lib/generators/minitest/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ScaffoldGenerator < Base # :nodoc:
check_class_collision suffix: "ControllerTest"

class_option :api, type: :boolean,
desc: "Generates API functional tests"
desc: "Generate API functional tests"

class_option :system_tests, type: :string,
desc: "Skip system test files"
Expand Down Expand Up @@ -46,10 +46,10 @@ def attributes_string
def attributes_hash
return {} if attributes_names.empty?

attributes_names.map do |name|
attributes_names.filter_map do |name|
if %w[password password_confirmation].include?(name) && attributes.any?(&:password_digest?)
[name.to_s, "'secret'"]
else
[name.to_s, '"secret"']
elsif !virtual?(name)
[name.to_s, "@#{singular_table_name}.#{name}"]
end
end.sort.to_h
Expand All @@ -59,6 +59,11 @@ def boolean? name
attribute = attributes.find { |attr| attr.name == name }
attribute&.type == :boolean
end

def virtual? name
attribute = attributes.find { |attr| attr.name == name }
attribute&.virtual?
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe <%= controller_class_name %>Controller do
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
end.must_differ "<%= class_name %>.count"

must_respond_with 201
must_respond_with :created
end

it "should show <%= singular_table_name %>" do
Expand All @@ -28,15 +28,15 @@ describe <%= controller_class_name %>Controller do

it "should update <%= singular_table_name %>" do
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
must_respond_with 200
must_respond_with :success
end

it "should destroy <%= singular_table_name %>" do
<%= spec_expectation_monad %> do
delete <%= show_helper %>, as: :json
end.must_differ "<%= class_name %>.count", -1

must_respond_with 204
must_respond_with :no_content
end
end
<% end -%>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
end

assert_response 201
assert_response :created
end

def test_show_<%= singular_table_name %>
Expand All @@ -30,15 +30,15 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe

def test_update_<%= singular_table_name %>
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
assert_response 200
assert_response :success
end

def test_destroy_<%= singular_table_name %>
assert_difference("<%= class_name %>.count", -1) do
delete <%= show_helper %>, as: :json
end

assert_response 204
assert_response :no_content
end
end
<% end -%>
10 changes: 5 additions & 5 deletions lib/generators/minitest/scaffold/templates/functional_spec.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe <%= controller_class_name %>Controller do
let(:<%= singular_table_name %>) { <%= fixture_name %>(:one) }

it "should get index" do
get <%= index_helper %>_url
get <%= index_helper(type: :url) %>
must_respond_with :success
end

Expand All @@ -20,10 +20,10 @@ describe <%= controller_class_name %>Controller do

it "should create <%= singular_table_name %>" do
assert_difference("<%= class_name %>.count") do
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
post <%= index_helper(type: :url) %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
end

must_redirect_to <%= singular_table_name %>_url(<%= class_name %>.last)
must_redirect_to <%= show_helper("#{class_name}.last") %>
end

it "should show <%= singular_table_name %>" do
Expand All @@ -38,15 +38,15 @@ describe <%= controller_class_name %>Controller do

it "should update <%= singular_table_name %>" do
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
must_redirect_to <%= singular_table_name %>_url(<%= "#{singular_table_name}" %>)
must_redirect_to <%= show_helper %>
end

it "should destroy <%= singular_table_name %>" do
assert_difference("<%= class_name %>.count", -1) do
delete <%= show_helper %>
end

must_redirect_to <%= index_helper %>_url
must_redirect_to <%= index_helper(type: :url) %>
end
end
<% end -%>
10 changes: 5 additions & 5 deletions lib/generators/minitest/scaffold/templates/functional_test.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
end

def test_get_index
get <%= index_helper %>_url
get <%= index_helper(type: :url) %>
assert_response :success
end

Expand All @@ -22,10 +22,10 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe

def test_create_<%= singular_table_name %>
assert_difference("<%= class_name %>.count") do
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
post <%= index_helper(type: :url) %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
end

assert_redirected_to <%= singular_table_name %>_url(<%= class_name %>.last)
assert_redirected_to <%= show_helper("#{class_name}.last") %>
end

def test_show_<%= singular_table_name %>
Expand All @@ -40,15 +40,15 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe

def test_update_<%= singular_table_name %>
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
assert_redirected_to <%= singular_table_name %>_url(<%= "@#{singular_table_name}" %>)
assert_redirected_to <%= show_helper %>
end

def test_destroy_<%= singular_table_name %>
assert_difference("<%= class_name %>.count", -1) do
delete <%= show_helper %>
end

assert_redirected_to <%= index_helper %>_url
assert_redirected_to <%= index_helper(type: :url) %>
end
end
<% end -%>
Loading

0 comments on commit f174389

Please sign in to comment.