Local Testing
Important: These docs are for the outdated Jets 5 versions and below. For the latest Jets docs: docs.rubyonjets.com
DB Migration
Let’s run the create the database and run the migration.
jets db:create db:migrate
Seeding Data
Let’s create some seed data to help with first. Create this file:
db/seeds.rb
2.times do |i|
i += 1
Post.find_or_create_by(title: "Post #{i}", body: "Body #{i}", published: true)
end
puts "Posts created"
Run jets db:seed
❯ jets db:seed
Posts created
Run jets runner
to confirm that the records were created.
❯ jets runner 'puts Post.count'
2
Start Server
You can test locally with jets server
.
Example:
❯ jets server
=> Booting Puma
=> Jets 5.0.0 application starting in development
=> Run `jets server --help` for more startup options
Puma starting in single mode...
* Listening on http://127.0.0.1:8888
Use Ctrl-C to stop
A puma web server allows you to test locally just like a normal rack app.
Testing Index Listing
Test by opening localhost:8888/posts in a browser:
On the jets server side, you’ll see the request:
Started GET "/posts" for 127.0.0.1 at 2023-10-28 14:09:35 +0000
Processing PostsController#index
Completed Status Code 200 in 0.015s
Started GET "/posts" for 127.0.0.1 at 2023-10-28 14:09:36 +0000
Test Create
Click on new and create a new post.
On the jets server side:
Started POST "/posts" for 127.0.0.1 at 2023-10-28 14:17:22 +0000
Processing PostsController#create
Parameters: {"post":{"title":"Post 3","body":"Body 3","published":true}}
Completed Status Code 201 in 0.017s
Test Update
Click on edit and edit an existing post.
On the jets server side
Processing PostsController#update
Parameters: {"post":{"title":"Post 3 Edit 1","body":"Body 3","published":true},"id":"3"}
Completed Status Code 200 in 0.010s
Test Delete
Last, let’s delete the post.
On the jets server side
Started DELETE "/posts/3" for 127.0.0.1 at 2023-10-28 14:44:20 +0000
Processing PostsController#destroy
Parameters: {"id":"3"}
Completed Status Code 200 in 0.015s
Next, we’ll deploy the project to AWS Lambda.