Skip to content

Commit

Permalink
Annotate models (#32)
Browse files Browse the repository at this point in the history
Add annotate gem and annotate models
  • Loading branch information
LeozMaxwellJilliams authored Jan 13, 2020
1 parent 9b947a6 commit bb032fc
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ group :development do
gem 'rubocop'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
# annotate
gem 'annotate'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.1, >= 2.1.8)
annotate (3.0.3)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 14.0)
ast (2.4.0)
bcrypt (3.1.13)
bootsnap (1.4.5)
Expand Down Expand Up @@ -225,6 +228,7 @@ PLATFORMS
ruby

DEPENDENCIES
annotate
bootsnap (>= 1.4.2)
byebug
database_cleaner
Expand Down
14 changes: 14 additions & 0 deletions app/models/flowchart.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: flowcharts
#
# id :bigint not null, primary key
# title :string not null
# description :string not null
# height :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# root_id :bigint
# deleted :boolean default(FALSE), not null
#

class Flowchart < ApplicationRecord
validates :title, presence: true
validates :description, presence: true
Expand Down
18 changes: 18 additions & 0 deletions app/models/flowchart_node.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: flowchart_nodes
#
# id :bigint not null, primary key
# text :string not null
# header :string not null
# button_text :string
# next_question :string
# child_id :bigint
# sibling_id :bigint
# is_root :boolean not null
# flowchart_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
# deleted :boolean default(FALSE), not null
#

class FlowchartNode < ApplicationRecord
belongs_to :flowchart
validates :text, presence: true
Expand Down
9 changes: 9 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: questions
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

class Question < ApplicationRecord
end
12 changes: 12 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# jti :string not null
#

class User < ApplicationRecord
include Devise::JWT::RevocationStrategies::JTIMatcher
devise :database_authenticatable, :validatable, :rememberable,
Expand Down
59 changes: 59 additions & 0 deletions lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
require 'annotate'
task :set_annotation_options do
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults(
'additional_file_patterns' => [],
'routes' => 'false',
'models' => 'true',
'position_in_routes' => 'before',
'position_in_class' => 'before',
'position_in_test' => 'before',
'position_in_fixture' => 'before',
'position_in_factory' => 'before',
'position_in_serializer' => 'before',
'show_foreign_keys' => 'true',
'show_complete_foreign_keys' => 'false',
'show_indexes' => 'true',
'simple_indexes' => 'false',
'model_dir' => 'app/models',
'root_dir' => '',
'include_version' => 'false',
'require' => '',
'exclude_tests' => 'false',
'exclude_fixtures' => 'false',
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'true',
'exclude_controllers' => 'true',
'exclude_helpers' => 'true',
'exclude_sti_subclasses' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_routes' => nil,
'ignore_unknown_models' => 'false',
'hide_limit_column_types' => 'integer,bigint,boolean',
'hide_default_column_types' => 'json,jsonb,hstore',
'skip_on_db_migrate' => 'false',
'format_bare' => 'true',
'format_rdoc' => 'false',
'format_markdown' => 'false',
'sort' => 'false',
'force' => 'false',
'frozen' => 'false',
'classified_sort' => 'true',
'trace' => 'false',
'wrapper_open' => nil,
'wrapper_close' => nil,
'with_comment' => 'true'
)
end

Annotate.load_tasks
end
12 changes: 12 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# jti :string not null
#

FactoryBot.define do
factory :user do
end
Expand Down
14 changes: 14 additions & 0 deletions spec/models/flowchart_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: flowcharts
#
# id :bigint not null, primary key
# title :string not null
# description :string not null
# height :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# root_id :bigint
# deleted :boolean default(FALSE), not null
#

require 'rails_helper'

RSpec.describe Flowchart, type: :model do
Expand Down
12 changes: 12 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# jti :string not null
#

require 'rails_helper'

RSpec.describe User, type: :model do
Expand Down
9 changes: 9 additions & 0 deletions test/models/question_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: questions
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#

require 'test_helper'

class QuestionTest < ActiveSupport::TestCase
Expand Down

0 comments on commit bb032fc

Please sign in to comment.