Skip to content

Commit

Permalink
Added a basic Post model (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
yatish27 authored Jun 5, 2024
1 parent bd77906 commit bfda66a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ group :development, :test do
gem "debug", "~> 1.9", ">= 1.9.2", platforms: %i[mri windows]
gem "dotenv", "~> 3.1", ">= 3.1.2"
gem "factory_bot_rails", "~> 6.4", ">= 6.4.3"
gem "faker", "~> 3.4"
gem "rubocop-rails-omakase", "~> 1.0", require: false, group: [:development]
gem "minitest-reporters", "~> 1.6", ">= 1.6.1"
end
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ GEM
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.4.1)
i18n (>= 1.8.11, < 2)
foreman (0.88.1)
fugit (1.10.1)
et-orbi (~> 1, >= 1.2.7)
Expand Down Expand Up @@ -337,6 +339,7 @@ DEPENDENCIES
dotenv (~> 3.1, >= 3.1.2)
erb_lint (~> 0.5)
factory_bot_rails (~> 6.4, >= 6.4.3)
faker (~> 3.4)
foreman (~> 0.87, >= 0.87.2)
jbuilder (~> 2.12)
letter_opener (~> 1.10)
Expand Down
2 changes: 2 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Post < ApplicationRecord
end
11 changes: 11 additions & 0 deletions db/migrate/20240605180804_create_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePosts < ActiveRecord::Migration[7.1]
def change
create_table :posts, id: :uuid do |t|
t.string :title, null: false
t.string :summary
t.text :content
t.datetime :published_at
t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ CREATE TABLE public.ar_internal_metadata (
);


--
-- Name: posts; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.posts (
id uuid DEFAULT gen_random_uuid() NOT NULL,
title character varying NOT NULL,
summary character varying,
content text,
published_at timestamp(6) without time zone,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);


--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -195,6 +210,14 @@ ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);


--
-- Name: posts posts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.posts
ADD CONSTRAINT posts_pkey PRIMARY KEY (id);


--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -506,6 +529,7 @@ ALTER TABLE ONLY public.solid_queue_scheduled_executions
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20240605180804'),
('20240419132661'),
('20240419132660'),
('20240419132659'),
Expand Down
7 changes: 7 additions & 0 deletions test/factories/posts_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :post do
title { Faker::Book.title }
content { Faker::Markdown.sandwich(sentences: 5) }
published_at { Faker::Time.between(from: DateTime.now - 1, to: DateTime.now) }
end
end
8 changes: 8 additions & 0 deletions test/models/post_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "test_helper"

class PostTest < ActiveSupport::TestCase
test "valid" do
post = FactoryBot.create(:post)
assert post.valid?
end
end

0 comments on commit bfda66a

Please sign in to comment.