-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract super scaffolding tests into smaller individual units (#1825)
* first stab at extracting a stand alone test * a little polish * better naming * getting started on converting these scripts to ruby * getting closer * maybe we'll need to run migrations in the setup * working on teardown * working on teardown * disable that completely * linter * remove the bash scripts * extract another test * extract another * some cleanup * fix * moar * inching forward * extract another * extract another * comment out more stuff * run migrations automatically * extract another * extract another * extract another * nothing to test there * add a comment * linter * try running these in CI * oops * the workspace is dirty in ci * extract another * fix * linter * clean up * Remove old stuff * some clean up and docs * beef up the readme * try consolidating * Revert "try consolidating" This reverts commit 6c2b436. * clean up * clean up * tweak docs * clean up * don't want to run db:schema:load because that will wipe the current db * Use the source attribute option * this doesn't seem to do anything useful * use source in another spot * another source useage
- Loading branch information
1 parent
9cdb131
commit e6b80f9
Showing
34 changed files
with
1,074 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# About Super Scaffolding Tests | ||
|
||
These tests each require some super scaffolding commands to be run _before_ running the tests. | ||
|
||
Each subdirectory below contains a `setup.rb` file that you can run to generate the necessary scaffolding. | ||
|
||
After running the tests you can run `teardown.rb` from the same directory to remove the super scaffolded code. | ||
|
||
**NOTE** We highly reocmmend that you start with a clean git workspace. The super scaffolding commands generate | ||
a lot of files and the cleanup process is... let's call it "brute force". If you have uncommitted changes in | ||
your repo before running `setup.rb` they're likely to get clobbered when you run `teardown.rb` | ||
|
||
### Example | ||
|
||
To run the `insight` test, you'd run these commands from the main project directory. | ||
|
||
First run the `setup.rb` script to generate the scaffolding and run migrations. | ||
|
||
``` | ||
$ ./test/system/super_scaffolding/insight/setup.rb | ||
Generating Insight model with 'bin/rails generate model Insight team:references name:string description:text' | ||
Writing './app/controllers/account/insights_controller.rb'. | ||
Fixing Standard Ruby on './app/controllers/account/insights_controller.rb'. | ||
Writing './app/views/account/insights/index.html.erb'. | ||
Writing './app/views/account/insights/_menu_item.html.erb'. | ||
# snip | ||
``` | ||
|
||
Then run the test: | ||
|
||
``` | ||
$ rails test test/system/super_scaffolding/insight/ | ||
🌱 Generating global seeds. | ||
🌱 Generating test environment seeds. | ||
Not requiring Knapsack Pro. | ||
If you'd like to use Knapsack Pro make sure that you've set the environment variable KNAPSACK_PRO_CI_NODE_INDEX | ||
Started with run options --seed 45445 | ||
BulletTrain::SuperScaffolding::InsightTest | ||
Puma starting in single mode... | ||
* Puma version: 6.5.0 ("Sky's Version") | ||
* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23] | ||
* Min threads: 5 | ||
* Max threads: 5 | ||
* Environment: test | ||
* PID: 55207 | ||
* Listening on http://127.0.0.1:3001 | ||
Use Ctrl-C to stop | ||
test_developers_can_generate_a_Insight_and_a_nested_Personality::CharacterTrait_model PASS (3.51s) | ||
Finished in 3.51351s | ||
1 tests, 4 assertions, 0 failures, 0 errors, 0 skips | ||
Coverage report generated for test to /Users/jgreen/projects/bullet-train-co/bullet_train/coverage. | ||
Line Coverage: 45.18% (150 / 332) | ||
``` | ||
Then run `teardown.rb` to clean up: | ||
|
||
``` | ||
$ ./test/system/super_scaffolding/insight/teardown.rb | ||
db/schema.rb has changed - we need to rollback | ||
== 20241219204101 CreatePersonalityCharacterTraits: reverting ================= | ||
-- drop_table(:personality_character_traits) | ||
-> 0.0037s | ||
== 20241219204101 CreatePersonalityCharacterTraits: reverted (0.0073s) ======== | ||
== 20241219204056 CreateInsights: reverting =================================== | ||
-- drop_table(:insights) | ||
-> 0.0016s | ||
== 20241219204056 CreateInsights: reverted (0.0017s) ========================== | ||
Updated 8 paths from the index | ||
Removing app/avo/resources/insight.rb | ||
Removing app/avo/resources/personality_character_trait.rb | ||
Removing app/controllers/account/insights_controller.rb | ||
Removing app/controllers/account/personality/ | ||
Removing app/controllers/api/v1/insights_controller.rb | ||
Removing app/controllers/api/v1/personality/ | ||
Removing app/controllers/avo/insights_controller.rb | ||
Removing app/controllers/avo/personality_character_traits_controller.rb | ||
Removing app/models/insight.rb | ||
Removing app/models/personality.rb | ||
Removing app/models/personality/ | ||
Removing app/views/account/insights/ | ||
Removing app/views/account/personality/ | ||
Removing app/views/api/v1/insights/ | ||
Removing app/views/api/v1/personality/ | ||
Removing config/locales/en/insights.en.yml | ||
Removing config/locales/en/personality/ | ||
Removing db/migrate/20241219204056_create_insights.rb | ||
Removing db/migrate/20241219204101_create_personality_character_traits.rb | ||
Removing test/controllers/api/v1/insights_controller_test.rb | ||
Removing test/controllers/api/v1/personality/ | ||
Removing test/factories/insights.rb | ||
Removing test/factories/personality/ | ||
Removing test/models/insight_test.rb | ||
Removing test/models/personality/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "application_system_test_case" | ||
|
||
class BulletTrain::SuperScaffolding::InsightTest < ApplicationSystemTestCase | ||
setup do | ||
@jane = create :onboarded_user, first_name: "Jane", last_name: "Smith" | ||
end | ||
|
||
# NOTE: This test only runs if the `setup.rb` file in this directory has run. | ||
# See ../README.md for details. | ||
|
||
# force autoload. | ||
[ | ||
"Insight", | ||
"Personality::CharacterTrait" | ||
].each do |class_name| | ||
class_name.constantize | ||
rescue | ||
nil | ||
end | ||
|
||
if defined?(Insight) | ||
test "developers can generate a Insight and a nested Personality::CharacterTrait model" do | ||
login_as(@jane, scope: :user) | ||
visit account_team_path(@jane.current_team) | ||
|
||
click_on "Add New Insight" | ||
click_on "Create Insight" | ||
assert_text("Name can't be blank.") | ||
fill_in "Name", with: "Some New Example Insight" | ||
click_on "Create Insight" | ||
|
||
assert_text("Insight was successfully created.") | ||
|
||
click_on "Add New Character Trait" | ||
click_on "Create Character Trait" | ||
assert_text("Name can't be blank.") | ||
fill_in "Name", with: "Some New Example Character Trait" | ||
click_on "Create Character Trait" | ||
assert_text("Character Trait was successfully created.") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require_relative "../super_scaffolding_test_setup" | ||
|
||
class Setup < SuperScaffoldingTestSetup | ||
# This allows us to define helper methods that aren't attached to thor commands | ||
no_commands do | ||
def setup | ||
puts `rails g super_scaffold Insight Team name:text_field description:trix_editor --navbar="ti-world"` | ||
puts `rails g super_scaffold Personality::CharacterTrait Insight,Team name:text_field description:trix_editor` | ||
end | ||
end | ||
end | ||
|
||
# We create our own args array so that we don't have to ask the user to include `scaffolding_setup` on the command line | ||
args = ["scaffolding_setup"] + ARGV | ||
|
||
Setup.start(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require_relative "../super_scaffolding_test_teardown" | ||
|
||
class Teardown < SuperScaffoldingTestTeardown | ||
# This allows us to define helper methods that aren't attached to thor commands | ||
no_commands do | ||
def teardown | ||
# custom teardown goes here | ||
end | ||
end | ||
end | ||
|
||
# We create our own args array so that we don't have to ask the user to include `scaffolding_setup` on the command line | ||
args = ["scaffolding_teardown"] + ARGV | ||
|
||
Teardown.start(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "application_system_test_case" | ||
|
||
# We run this in CI on each super scaffold test node to ensure that the OpenAPI Document | ||
# is still valid after generating super scaffolds. | ||
class SuperScaffoldingOpenAPITest < ApplicationSystemTestCase | ||
test "OpenAPI V3 document is still valid" do | ||
visit "/" # Make sure the test server is running before linting the file. | ||
|
||
puts(output = `yarn exec redocly lint http://127.0.0.1:#{Capybara.server_port}/api/v1/openapi.yaml 1> /dev/stdout 2> /dev/stdout`) | ||
# redocly/openapi-core changed the format of their success message in version 1.2.0. | ||
# https://github.com/Redocly/redocly-cli/pull/1239 | ||
# We use a robust regex here so that we can match both formats. | ||
assert output.match?(/Woohoo! Your (Open)?API (definition|description) is valid./) | ||
end | ||
end |
Oops, something went wrong.