diff --git a/README.md b/README.md index 5f4fc63..1c148b3 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,10 @@ Question 2.2 : Question 2.3 : * `rails generate controller HomeController` + +Question 3 : + +* `rails generate model Creature name:string health_points:integer` +* La migration n'est pas lancée sur la base +* `rails db:migrate` + diff --git a/app/models/creature.rb b/app/models/creature.rb new file mode 100644 index 0000000..3f60ae6 --- /dev/null +++ b/app/models/creature.rb @@ -0,0 +1,5 @@ +class Creature < ApplicationRecord + def to_label + "#{name} (#{health_points})" + end +end diff --git a/db/migrate/20230326131540_create_creatures.rb b/db/migrate/20230326131540_create_creatures.rb new file mode 100644 index 0000000..a85586f --- /dev/null +++ b/db/migrate/20230326131540_create_creatures.rb @@ -0,0 +1,10 @@ +class CreateCreatures < ActiveRecord::Migration[7.0] + def change + create_table :creatures do |t| + t.string :name + t.integer :health_points + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..d14d4e4 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,21 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 2023_03_26_131540) do + create_table "creatures", force: :cascade do |t| + t.string "name" + t.integer "health_points" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/fixtures/creatures.yml b/test/fixtures/creatures.yml new file mode 100644 index 0000000..45203d7 --- /dev/null +++ b/test/fixtures/creatures.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + health_points: 1 + +two: + name: MyString + health_points: 1 diff --git a/test/models/creature_test.rb b/test/models/creature_test.rb new file mode 100644 index 0000000..509025c --- /dev/null +++ b/test/models/creature_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CreatureTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end