ยง2023-02-27
Chapter 12 Alexandria: Setup Time
12.2. reating the application
(FRUM) alexlai@hc4Bullseye:~/sinatra-proj$ rails new alexandria --api --skip-test-unit
$ cd alexandria && rails server
12.5.1. The Publisher Model
$ rails generate rspec:install
Could not find generator 'rspec:install'. (Rails::Command::Base::CorrectableError)
Run `bin/rails generate --help` for more options.
(FRUM) alexlai@hc4Bullseye:~/sinatra-proj/alexandria$ rails g model Publisher name:string
invoke active_record
create db/migrate/20230227075503_create_publishers.rb
create app/models/publisher.rb
invoke test_unit
create test/models/publisher_test.rb
create test/fixtures/publishers.yml
$ cat db/migrate/20230227075503_create_publishers.rb
class CreatePublishers < ActiveRecord::Migration[7.0]
def change
create_table :publishers do |t|
t.string :name
t.timestamps
end
end
end
$ rails db:migrate && rails db:migrate RAILS_ENV=test
== 20230227075503 CreatePublishers: migrating =================================
-- create_table(:publishers)
-> 0.0084s
== 20230227075503 CreatePublishers: migrated (0.0087s) ========================
== 20230227075503 CreatePublishers: migrating =================================
-- create_table(:publishers)
-> 0.0031s
== 20230227075503 CreatePublishers: migrated (0.0033s) ========================