From a257e98eb6b050b6fff4a55831223285675c9f14 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sun, 17 Sep 2023 12:45:24 +0100 Subject: [PATCH] Add microposts These will have tags etc. in the future, this is it for now. --- app/models/micropost.rb | 9 +++++++++ db/migrate/20230917114037_create_microposts.rb | 9 +++++++++ test/fixtures/action_text/rich_texts.yml | 8 ++++---- test/fixtures/microposts.yml | 2 ++ test/models/micropost_test.rb | 7 +++++++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 app/models/micropost.rb create mode 100644 db/migrate/20230917114037_create_microposts.rb create mode 100644 test/fixtures/microposts.yml create mode 100644 test/models/micropost_test.rb diff --git a/app/models/micropost.rb b/app/models/micropost.rb new file mode 100644 index 0000000..788f81d --- /dev/null +++ b/app/models/micropost.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Micropost < ApplicationRecord + belongs_to :user + has_rich_text :content + + validates :user, presence: true + validates :content, presence: true +end diff --git a/db/migrate/20230917114037_create_microposts.rb b/db/migrate/20230917114037_create_microposts.rb new file mode 100644 index 0000000..e43f36b --- /dev/null +++ b/db/migrate/20230917114037_create_microposts.rb @@ -0,0 +1,9 @@ +class CreateMicroposts < ActiveRecord::Migration[7.0] + def change + create_table :microposts do |t| + t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml index 8b371ea..a751005 100644 --- a/test/fixtures/action_text/rich_texts.yml +++ b/test/fixtures/action_text/rich_texts.yml @@ -1,4 +1,4 @@ -# one: -# record: name_of_fixture (ClassOfFixture) -# name: content -# body:

In a million stars!

+one: + record: some_text (Micropost) + name: content + body:

Just some text

diff --git a/test/fixtures/microposts.yml b/test/fixtures/microposts.yml new file mode 100644 index 0000000..26c2649 --- /dev/null +++ b/test/fixtures/microposts.yml @@ -0,0 +1,2 @@ +some_text: + user: gimli diff --git a/test/models/micropost_test.rb b/test/models/micropost_test.rb new file mode 100644 index 0000000..9a20fe6 --- /dev/null +++ b/test/models/micropost_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class MicropostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end