Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Article < ApplicationRecord
belongs_to :category
validates_presence_of :title
validates_presence_of :content

scope :active, -> { where('active = ?', true) }
scope :alphabetical, -> { order('title') }
#random comment
end
1 change: 1 addition & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Category < ApplicationRecord
has_many :photos
has_many :articles

scope :active, -> { where('active = ?', true) }
scope :alphabetical, -> { order('name') }
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20220420001355_create_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateArticles < ActiveRecord::Migration[5.1]
def change
create_table :articles do |t|
t.string :title
t.text :content
t.integer :category_id
t.boolean :active

t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170919031503) do
ActiveRecord::Schema.define(version: 20220420001355) do

create_table "articles", force: :cascade do |t|
t.string "title"
t.text "content"
t.integer "category_id"
t.boolean "active"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "categories", force: :cascade do |t|
t.string "name"
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/articles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
title: MyString
content: MyText
category_id: 1
active: false

two:
title: MyString
content: MyText
category_id: 1
active: false
7 changes: 7 additions & 0 deletions test/models/article_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ArticleTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end