Skip to content

Commit 93d947d

Browse files
committed
run auto annotate
1 parent 0d8e8ff commit 93d947d

File tree

5 files changed

+172
-0
lines changed

5 files changed

+172
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ The app uses UUID as ids for active record entries in the database. If you want
9898
### 8. Automatic model annotation
9999
Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema. See [annotate_models gem](https://github.com/ctran/annotate_models).
100100

101+
Run `$ annotate` in project root folder to update annotations.
102+
101103
### 9. Abilities with CanCanCan
102104
[CanCanCan](https://github.com/CanCanCommunity/cancancan) is an authorization library for Ruby and Ruby on Rails which restricts what resources a given user is allowed to access. We combine this gem with a `role` field defined on user model.
103105

app/models/user.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: users
6+
#
7+
# id :uuid not null, primary key
8+
# confirmation_sent_at :datetime
9+
# confirmation_token :string
10+
# confirmed_at :datetime
11+
# current_sign_in_at :datetime
12+
# current_sign_in_ip :inet
13+
# email :string default(""), not null
14+
# encrypted_password :string default(""), not null
15+
# failed_attempts :integer default(0), not null
16+
# first_name :string default(""), not null
17+
# last_name :string default(""), not null
18+
# last_sign_in_at :datetime
19+
# last_sign_in_ip :inet
20+
# locked_at :datetime
21+
# refresh_token :string
22+
# remember_created_at :datetime
23+
# reset_password_sent_at :datetime
24+
# reset_password_token :string
25+
# role :integer default("user"), not null
26+
# sign_in_count :integer default(0), not null
27+
# unconfirmed_email :string
28+
# unlock_token :string
29+
# created_at :datetime not null
30+
# updated_at :datetime not null
31+
#
32+
# Indexes
33+
#
34+
# index_users_on_confirmation_token (confirmation_token) UNIQUE
35+
# index_users_on_email (email) UNIQUE
36+
# index_users_on_refresh_token (refresh_token) UNIQUE
37+
# index_users_on_reset_password_token (reset_password_token) UNIQUE
38+
# index_users_on_unlock_token (unlock_token) UNIQUE
39+
#
340
# User model to access application
441
class User < ApplicationRecord
542
# Include default devise modules. Others available are:

lib/tasks/auto_annotate_models.rake

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

spec/factories/users.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: users
6+
#
7+
# id :uuid not null, primary key
8+
# confirmation_sent_at :datetime
9+
# confirmation_token :string
10+
# confirmed_at :datetime
11+
# current_sign_in_at :datetime
12+
# current_sign_in_ip :inet
13+
# email :string default(""), not null
14+
# encrypted_password :string default(""), not null
15+
# failed_attempts :integer default(0), not null
16+
# first_name :string default(""), not null
17+
# last_name :string default(""), not null
18+
# last_sign_in_at :datetime
19+
# last_sign_in_ip :inet
20+
# locked_at :datetime
21+
# refresh_token :string
22+
# remember_created_at :datetime
23+
# reset_password_sent_at :datetime
24+
# reset_password_token :string
25+
# role :integer default("user"), not null
26+
# sign_in_count :integer default(0), not null
27+
# unconfirmed_email :string
28+
# unlock_token :string
29+
# created_at :datetime not null
30+
# updated_at :datetime not null
31+
#
32+
# Indexes
33+
#
34+
# index_users_on_confirmation_token (confirmation_token) UNIQUE
35+
# index_users_on_email (email) UNIQUE
36+
# index_users_on_refresh_token (refresh_token) UNIQUE
37+
# index_users_on_reset_password_token (reset_password_token) UNIQUE
38+
# index_users_on_unlock_token (unlock_token) UNIQUE
39+
#
340
FactoryBot.define do
441
factory :user do
542
first_name { Faker::Name.first_name }

spec/models/user_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: users
6+
#
7+
# id :uuid not null, primary key
8+
# confirmation_sent_at :datetime
9+
# confirmation_token :string
10+
# confirmed_at :datetime
11+
# current_sign_in_at :datetime
12+
# current_sign_in_ip :inet
13+
# email :string default(""), not null
14+
# encrypted_password :string default(""), not null
15+
# failed_attempts :integer default(0), not null
16+
# first_name :string default(""), not null
17+
# last_name :string default(""), not null
18+
# last_sign_in_at :datetime
19+
# last_sign_in_ip :inet
20+
# locked_at :datetime
21+
# refresh_token :string
22+
# remember_created_at :datetime
23+
# reset_password_sent_at :datetime
24+
# reset_password_token :string
25+
# role :integer default("user"), not null
26+
# sign_in_count :integer default(0), not null
27+
# unconfirmed_email :string
28+
# unlock_token :string
29+
# created_at :datetime not null
30+
# updated_at :datetime not null
31+
#
32+
# Indexes
33+
#
34+
# index_users_on_confirmation_token (confirmation_token) UNIQUE
35+
# index_users_on_email (email) UNIQUE
36+
# index_users_on_refresh_token (refresh_token) UNIQUE
37+
# index_users_on_reset_password_token (reset_password_token) UNIQUE
38+
# index_users_on_unlock_token (unlock_token) UNIQUE
39+
#
340
require 'rails_helper'
441

542
RSpec.describe User, type: :model do

0 commit comments

Comments
 (0)