Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #14

Merged
merged 2 commits into from Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Expand Up @@ -7,6 +7,7 @@ AllCops:
- 'db/schema.rb'
- 'bin/setup'
- 'bin/update'
- 'lib/templates/**/*'

Style/Documentation:
Exclude:
Expand All @@ -16,6 +17,7 @@ Style/Documentation:

Metrics/BlockLength:
Exclude:
- 'app/apis/**/*'
- 'config/**/*'
- 'spec/**/*'

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -59,6 +59,7 @@ group :test do
gem 'database_cleaner'
gem 'rspec_junit_formatter'
gem 'selenium-webdriver'
gem 'shoulda-matchers'
end

group :development do
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -319,6 +319,8 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
shoulda-matchers (4.0.1)
activesupport (>= 4.2.0)
sidekiq (5.2.5)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
Expand Down Expand Up @@ -404,6 +406,7 @@ DEPENDENCIES
rubocop
sass-rails (~> 5.0)
selenium-webdriver
shoulda-matchers
sidekiq
sidekiq-scheduler
spring
Expand Down
14 changes: 14 additions & 0 deletions lib/templates/active_record/model/model.rb
@@ -0,0 +1,14 @@
<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
<% attributes.select(&:reference?).each do |attribute| -%>
uuid :<%= attribute.name %>_id
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
<% end -%>
<% attributes.select(&:token?).each do |attribute| -%>
has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
<% end -%>
<% if attributes.any?(&:password_digest?) -%>
has_secure_password
<% end -%>
end
<% end -%>
24 changes: 24 additions & 0 deletions lib/templates/migration/templates/create_table_migration.rb
@@ -0,0 +1,24 @@
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
def change
create_table :<%= table_name %><%= primary_key_type %> do |t|
<% attributes.each do |attribute| -%>
<% if attribute.password_digest? -%>
t.string :password_digest<%= attribute.inject_options %>
<% elsif attribute.token? -%>
t.string :<%= attribute.name %><%= attribute.inject_options %>
<% else -%>
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
<% end -%>
<% end -%>
<% if options[:timestamps] %>
t.datetime :updated_at
<% end -%>
end
<% attributes.select(&:token?).each do |attribute| -%>
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
<% end -%>
<% attributes_with_index.each do |attribute| -%>
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
<% end -%>
end
end
7 changes: 5 additions & 2 deletions spec/rails_helper.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] = 'test'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?
Expand All @@ -23,7 +23,7 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
Expand All @@ -34,6 +34,9 @@
exit 1
end
RSpec.configure do |config|
# Remember to include global test helpers here
include ConcernHelper

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

Expand Down
9 changes: 9 additions & 0 deletions spec/support/constants/example_constants.rb
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# Constants used in tests are put in files in this directory
module ExampleConstants
EMPLOYEE = {
name: 'John Smith',
age: 25
}.freeze
end
12 changes: 12 additions & 0 deletions spec/support/helpers/concern_helper.rb
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module ConcernHelper
def spec_dir
File.dirname metadata[:file_path]
end

def it_has_concern(concern_name)
require Rails.root.join "#{spec_dir}/concerns/#{concern_name.underscore}"
it_behaves_like concern_name
end
end