Skip to content
This repository was archived by the owner on Aug 21, 2022. It is now read-only.

Commit a0158d5

Browse files
committed
✨ (admin) add administrator model
1 parent 0fd41f9 commit a0158d5

File tree

7 files changed

+169
-2
lines changed

7 files changed

+169
-2
lines changed

app/models/administrator.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: administrators
6+
#
7+
# id :bigint not null, primary key
8+
# name :string not null
9+
# password_digest :string not null
10+
# created_at :datetime not null
11+
# updated_at :datetime not null
12+
#
13+
# Indexes
14+
#
15+
# index_administrators_on_name (name) UNIQUE
16+
#
17+
class Administrator < ApplicationRecord
18+
validates :name, presence: true, uniqueness: true
19+
20+
has_secure_password
21+
end

config/database.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ development:
22
adapter: postgresql
33
host: localhost
44
encoding: unicode
5-
database: ohmyxin_development
5+
database: payin_development
66
pool: 5
77
username: postgres
88
password: postgres
@@ -12,7 +12,7 @@ test:
1212
adapter: postgresql
1313
host: localhost
1414
encoding: unicode
15-
database: ohmyxin_test
15+
database: payin_test
1616
pool: 5
1717
username: postgres
1818
password: postgres
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateAdministrators < ActiveRecord::Migration[6.0]
2+
def change
3+
create_table :administrators do |t|
4+
t.string :name, null: false
5+
t.string :password_digest, null: false
6+
7+
t.timestamps
8+
end
9+
10+
add_index :administrators, :name, unique: true
11+
end
12+
end

db/schema.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# This file is the source Rails uses to define your schema when running `rails
6+
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(version: 2020_03_06_091111) do
14+
15+
# These are extensions that must be enabled in order to support this database
16+
enable_extension "plpgsql"
17+
18+
create_table "administrators", force: :cascade do |t|
19+
t.string "name", null: false
20+
t.string "password_digest", null: false
21+
t.datetime "created_at", precision: 6, null: false
22+
t.datetime "updated_at", precision: 6, null: false
23+
t.index ["name"], name: "index_administrators_on_name", unique: true
24+
end
25+
26+
end

lib/tasks/auto_annotate_models.rake

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
# NOTE: only doing this in development as some production environments (Heroku)
4+
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
5+
# NOTE: to have a dev-mode tool do its thing in production.
6+
if Rails.env.development?
7+
require 'annotate'
8+
task set_annotation_options: :environment do
9+
# You can override any of these by setting an environment variable of the
10+
# same name.
11+
Annotate.set_defaults(
12+
'active_admin' => 'false',
13+
'additional_file_patterns' => [],
14+
'routes' => 'false',
15+
'models' => 'true',
16+
'position_in_routes' => 'before',
17+
'position_in_class' => 'before',
18+
'position_in_test' => 'before',
19+
'position_in_fixture' => 'before',
20+
'position_in_factory' => 'before',
21+
'position_in_serializer' => 'before',
22+
'show_foreign_keys' => 'true',
23+
'show_complete_foreign_keys' => 'false',
24+
'show_indexes' => 'true',
25+
'simple_indexes' => 'false',
26+
'model_dir' => 'app/models',
27+
'root_dir' => '',
28+
'include_version' => 'false',
29+
'require' => '',
30+
'exclude_tests' => 'false',
31+
'exclude_fixtures' => 'false',
32+
'exclude_factories' => 'false',
33+
'exclude_serializers' => 'false',
34+
'exclude_scaffolds' => 'true',
35+
'exclude_controllers' => 'true',
36+
'exclude_helpers' => 'true',
37+
'exclude_sti_subclasses' => 'false',
38+
'ignore_model_sub_dir' => 'false',
39+
'ignore_columns' => nil,
40+
'ignore_routes' => nil,
41+
'ignore_unknown_models' => 'false',
42+
'hide_limit_column_types' => 'integer,bigint,boolean',
43+
'hide_default_column_types' => 'json,jsonb,hstore',
44+
'skip_on_db_migrate' => 'false',
45+
'format_bare' => 'true',
46+
'format_rdoc' => 'false',
47+
'format_yard' => 'false',
48+
'format_markdown' => 'false',
49+
'sort' => 'false',
50+
'force' => 'false',
51+
'frozen' => 'false',
52+
'classified_sort' => 'true',
53+
'trace' => 'false',
54+
'wrapper_open' => nil,
55+
'wrapper_close' => nil,
56+
'with_comment' => 'true'
57+
)
58+
end
59+
60+
Annotate.load_tasks
61+
end

test/fixtures/administrators.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# == Schema Information
2+
#
3+
# Table name: administrators
4+
#
5+
# id :bigint not null, primary key
6+
# name :string not null
7+
# password_digest :string not null
8+
# created_at :datetime not null
9+
# updated_at :datetime not null
10+
#
11+
# Indexes
12+
#
13+
# index_administrators_on_name (name) UNIQUE
14+
#
15+
16+
# This model initially had no columns defined. If you add columns to the
17+
# model remove the '{}' from the fixture names and add the columns immediately
18+
# below each fixture, per the syntax in the comments below
19+
#
20+
one: {}
21+
# column: value
22+
#
23+
two: {}
24+
# column: value

test/models/administrator_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: administrators
6+
#
7+
# id :bigint not null, primary key
8+
# name :string not null
9+
# password_digest :string not null
10+
# created_at :datetime not null
11+
# updated_at :datetime not null
12+
#
13+
# Indexes
14+
#
15+
# index_administrators_on_name (name) UNIQUE
16+
#
17+
require 'test_helper'
18+
19+
class AdministratorTest < ActiveSupport::TestCase
20+
# test "the truth" do
21+
# assert true
22+
# end
23+
end

0 commit comments

Comments
 (0)