model_base_generators 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/example/.gitignore +1 -0
- data/example/.model_base/controllers +5 -0
- data/example/.rubocop.yml +31 -0
- data/example/Gemfile +1 -1
- data/example/Gemfile.lock +14 -1
- data/example/app/controllers/concerns/authentication.rb +2 -2
- data/example/app/models/ability.rb +1 -2
- data/example/app/models/issue.rb +0 -1
- data/example/app/models/user.rb +3 -2
- data/example/app/views/issue_comments/_issue_comment.json.jbuilder +1 -1
- data/example/app/views/issue_comments/_table.html.erb +1 -1
- data/example/app/views/issue_comments/index.html.erb +1 -1
- data/example/app/views/issue_comments/index.json.jbuilder +1 -1
- data/example/app/views/issue_comments/show.json.jbuilder +1 -1
- data/example/app/views/issues/_table.html.erb +1 -1
- data/example/app/views/issues/index.html.erb +1 -1
- data/example/app/views/phases/_table.html.erb +1 -1
- data/example/app/views/phases/index.html.erb +1 -1
- data/example/app/views/project_assignments/_table.html.erb +1 -1
- data/example/app/views/project_assignments/index.html.erb +1 -1
- data/example/app/views/projects/_table.html.erb +1 -1
- data/example/app/views/projects/index.html.erb +1 -1
- data/example/config/application.rb +1 -1
- data/example/config/environments/development.rb +1 -1
- data/example/config/environments/production.rb +2 -2
- data/example/config/environments/test.rb +1 -1
- data/example/config/initializers/pretty_validation.rb +1 -1
- data/example/config/puma.rb +3 -3
- data/example/db/schema.rb +9 -9
- data/example/spec/controllers/issue_comments_controller_spec.rb +73 -61
- data/example/spec/controllers/issues_controller_spec.rb +71 -59
- data/example/spec/controllers/phases_controller_spec.rb +72 -60
- data/example/spec/controllers/project_assignments_controller_spec.rb +72 -60
- data/example/spec/controllers/projects_controller_spec.rb +70 -58
- data/example/spec/factories/issue_comments.rb +1 -1
- data/example/spec/factories/issues.rb +1 -1
- data/example/spec/factories/phases.rb +3 -3
- data/example/spec/factories/project_assignments.rb +2 -2
- data/example/spec/factories/projects.rb +1 -1
- data/example/spec/factories/users.rb +2 -2
- data/example/spec/rails_helper.rb +1 -1
- data/example/spec/requests/issue_comments_spec.rb +4 -4
- data/example/spec/routing/issue_comments_routing_spec.rb +18 -20
- data/example/spec/routing/issues_routing_spec.rb +18 -20
- data/example/spec/routing/phases_routing_spec.rb +18 -20
- data/example/spec/routing/project_assignments_routing_spec.rb +18 -20
- data/example/spec/routing/projects_routing_spec.rb +18 -20
- data/example/spec/spec_helper.rb +47 -49
- data/example/spec/support/controller_macros.rb +3 -3
- data/example/spec/support/devise.rb +2 -2
- data/example/spec/support/time_match_support.rb +9 -0
- data/example/spec/views/issue_comments/edit.html.erb_spec.rb +12 -11
- data/example/spec/views/issue_comments/index.html.erb_spec.rb +12 -12
- data/example/spec/views/issue_comments/new.html.erb_spec.rb +12 -11
- data/example/spec/views/issue_comments/show.html.erb_spec.rb +7 -6
- data/example/spec/views/issues/edit.html.erb_spec.rb +12 -11
- data/example/spec/views/issues/index.html.erb_spec.rb +13 -13
- data/example/spec/views/issues/new.html.erb_spec.rb +12 -11
- data/example/spec/views/issues/show.html.erb_spec.rb +6 -5
- data/example/spec/views/phases/edit.html.erb_spec.rb +9 -8
- data/example/spec/views/phases/index.html.erb_spec.rb +12 -12
- data/example/spec/views/phases/new.html.erb_spec.rb +9 -8
- data/example/spec/views/phases/show.html.erb_spec.rb +8 -7
- data/example/spec/views/project_assignments/edit.html.erb_spec.rb +10 -9
- data/example/spec/views/project_assignments/index.html.erb_spec.rb +11 -11
- data/example/spec/views/project_assignments/new.html.erb_spec.rb +10 -9
- data/example/spec/views/project_assignments/show.html.erb_spec.rb +8 -7
- data/example/spec/views/projects/edit.html.erb_spec.rb +9 -8
- data/example/spec/views/projects/index.html.erb_spec.rb +10 -10
- data/example/spec/views/projects/new.html.erb_spec.rb +9 -8
- data/example/spec/views/projects/show.html.erb_spec.rb +5 -4
- data/exe/model_base +33 -0
- data/lib/generators/model_base/install_generator.rb +1 -0
- data/lib/generators/model_base/templates/app/controllers/concerns/authentication.rb +2 -2
- data/lib/generators/model_base/templates/spec/support/time_match_support.rb +9 -0
- data/lib/model_base/column_attribute.rb +2 -2
- data/lib/model_base/config.rb +6 -0
- data/lib/model_base/generators/model_support.rb +8 -0
- data/lib/model_base/generators/rails/scaffold_controller.rb +25 -0
- data/lib/model_base/generators.rb +33 -0
- data/lib/model_base/meta_model.rb +2 -2
- data/lib/model_base/railtie.rb +1 -1
- data/lib/model_base/version.rb +1 -1
- data/lib/model_base.rb +24 -13
- data/lib/templates/erb/scaffold/_table.html.erb +1 -1
- data/lib/templates/erb/scaffold/index.html.erb +1 -1
- data/lib/templates/factory_girl/factory.rb +1 -1
- data/lib/templates/rspec/scaffold/controller_spec.rb +71 -59
- data/lib/templates/rspec/scaffold/edit_spec.rb +5 -4
- data/lib/templates/rspec/scaffold/index_spec.rb +8 -8
- data/lib/templates/rspec/scaffold/new_spec.rb +5 -4
- data/lib/templates/rspec/scaffold/routing_spec.rb +18 -20
- data/lib/templates/rspec/scaffold/show_spec.rb +4 -3
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49e0e50790434d7d12129f476e7608332f6060e0
|
4
|
+
data.tar.gz: 765a08e5183688dcf746bc44f08d7595fa22db62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dd2c2021adbb1e1e0bd4a53fc3d1288dc921bd332ac9ec055a7aa6ae27fd1a588249b80c0f658f77982afcfb2691702cc3fe3c41070da4cc02fefd4aa2e5ef5
|
7
|
+
data.tar.gz: 7fe0b2352577b699f58ef09bc8e9ca35862f657d48bc18f92327f982651cea551d93af2025650674bcb5b19de7883e3626e65275a22fcec1280f4f82f5a43270
|
data/README.md
CHANGED
@@ -64,6 +64,29 @@ Run scaffold_controller **WITHOUT attributes**!
|
|
64
64
|
|
65
65
|
You can use `rails_template.rb` for `--template` option of `rails new`.
|
66
66
|
|
67
|
+
## Re-generate files
|
68
|
+
|
69
|
+
```bash
|
70
|
+
$ bundle exec model_base each controller rails g scaffold_controller
|
71
|
+
```
|
72
|
+
|
73
|
+
It runs `rails g scaffold_controller CONTROLLER` for each controller
|
74
|
+
|
75
|
+
controllers are loaded from `.model_base/controllers`.
|
76
|
+
|
77
|
+
## Skipped files
|
78
|
+
|
79
|
+
If you want to overwrite the files, you can set the file name or patterns
|
80
|
+
to
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
ModelBase.configure do |config|
|
84
|
+
config.skipped_files = [
|
85
|
+
'app/views/projects/show.html.erb',
|
86
|
+
'spec/views/**/index.html.erb_spec.rb'
|
87
|
+
]
|
88
|
+
end
|
89
|
+
```
|
67
90
|
|
68
91
|
## Development
|
69
92
|
|
data/example/.gitignore
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# https://github.com/bbatsov/rubocop/blob/master/manual/configuration.md
|
2
|
+
# http://blog-ja.sideci.com/entry/2015/03/26/103000
|
3
|
+
# http://rochefort.hatenablog.com/entry/2014/08/14/073000
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Include:
|
7
|
+
- '**/Rakefile'
|
8
|
+
- '**/config.ru'
|
9
|
+
Exclude:
|
10
|
+
- 'db/**/*'
|
11
|
+
- 'config/**/*'
|
12
|
+
DisplayCopNames: true
|
13
|
+
|
14
|
+
Rails:
|
15
|
+
Enabled: true
|
16
|
+
|
17
|
+
LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
# http://qiita.com/tbpgr/items/7f49fdc42e4bfe47e331
|
21
|
+
# https://github.com/bbatsov/rubocop/pull/735/files
|
22
|
+
Style/TrailingCommaInLiteral:
|
23
|
+
EnforcedStyleForMultiline: comma
|
24
|
+
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/BlockDelimiters:
|
29
|
+
Enabled: true
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/*'
|
data/example/Gemfile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
3
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
4
|
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
|
6
5
|
# Use sqlite3 as the database for Active Record
|
@@ -39,6 +38,7 @@ group :development do
|
|
39
38
|
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
|
40
39
|
gem 'web-console'
|
41
40
|
gem 'listen', '~> 3.0.5'
|
41
|
+
gem 'rubocop', '~> 0.44.1', require: false
|
42
42
|
end
|
43
43
|
|
44
44
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
data/example/Gemfile.lock
CHANGED
@@ -49,6 +49,7 @@ GEM
|
|
49
49
|
activerecord (>= 3.2, < 6.0)
|
50
50
|
rake (>= 10.4, < 12.0)
|
51
51
|
arel (7.1.4)
|
52
|
+
ast (2.3.0)
|
52
53
|
bcrypt (3.1.11)
|
53
54
|
binding_of_caller (0.7.2)
|
54
55
|
debug_inspector (>= 0.0.1)
|
@@ -131,6 +132,9 @@ GEM
|
|
131
132
|
nokogiri (1.6.8.1)
|
132
133
|
mini_portile2 (~> 2.1.0)
|
133
134
|
orm_adapter (0.5.0)
|
135
|
+
parser (2.3.1.4)
|
136
|
+
ast (~> 2.2)
|
137
|
+
powerpack (0.1.1)
|
134
138
|
pry (0.10.4)
|
135
139
|
coderay (~> 1.1.0)
|
136
140
|
method_source (~> 0.8.1)
|
@@ -182,6 +186,7 @@ GEM
|
|
182
186
|
method_source
|
183
187
|
rake (>= 0.8.7)
|
184
188
|
thor (>= 0.18.1, < 2.0)
|
189
|
+
rainbow (2.1.0)
|
185
190
|
rake (11.3.0)
|
186
191
|
rb-fsevent (0.9.7)
|
187
192
|
rb-inotify (0.9.7)
|
@@ -210,6 +215,12 @@ GEM
|
|
210
215
|
rspec-mocks (~> 3.5.0)
|
211
216
|
rspec-support (~> 3.5.0)
|
212
217
|
rspec-support (3.5.0)
|
218
|
+
rubocop (0.44.1)
|
219
|
+
parser (>= 2.3.1.1, < 3.0)
|
220
|
+
powerpack (~> 0.1)
|
221
|
+
rainbow (>= 1.99.1, < 3.0)
|
222
|
+
ruby-progressbar (~> 1.7)
|
223
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
213
224
|
ruby-progressbar (1.8.1)
|
214
225
|
sass (3.4.22)
|
215
226
|
sass-rails (5.0.6)
|
@@ -250,6 +261,7 @@ GEM
|
|
250
261
|
thread_safe (~> 0.1)
|
251
262
|
uglifier (3.0.2)
|
252
263
|
execjs (>= 0.3.0, < 3)
|
264
|
+
unicode-display_width (1.1.1)
|
253
265
|
uniform_notifier (1.10.0)
|
254
266
|
warden (1.2.6)
|
255
267
|
rack (>= 1.0)
|
@@ -290,6 +302,7 @@ DEPENDENCIES
|
|
290
302
|
rails_best_practices
|
291
303
|
rspec
|
292
304
|
rspec-rails
|
305
|
+
rubocop (~> 0.44.1)
|
293
306
|
sass-rails (~> 5.0)
|
294
307
|
simplecov
|
295
308
|
simplecov-rcov
|
@@ -301,4 +314,4 @@ DEPENDENCIES
|
|
301
314
|
web-console
|
302
315
|
|
303
316
|
BUNDLED WITH
|
304
|
-
1.13.
|
317
|
+
1.13.6
|
@@ -2,11 +2,11 @@ module Authentication
|
|
2
2
|
def self.included(klass)
|
3
3
|
klass.class_eval do
|
4
4
|
before_action :authenticate_user!
|
5
|
-
around_action :
|
5
|
+
around_action :assign_current_user
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def assign_current_user(&block)
|
10
10
|
User.current(current_user, &block)
|
11
11
|
end
|
12
12
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Ability
|
2
2
|
include CanCan::Ability
|
3
3
|
|
4
|
-
def initialize(
|
4
|
+
def initialize(_user)
|
5
5
|
# Define abilities for the passed in user here. For example:
|
6
6
|
#
|
7
7
|
# user ||= User.new # guest user (not logged in)
|
@@ -30,6 +30,5 @@ class Ability
|
|
30
30
|
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
|
31
31
|
|
32
32
|
can :manage, :all
|
33
|
-
|
34
33
|
end
|
35
34
|
end
|
data/example/app/models/issue.rb
CHANGED
data/example/app/models/user.rb
CHANGED
@@ -5,7 +5,7 @@ class User < ApplicationRecord
|
|
5
5
|
:recoverable, :rememberable, :trackable, :validatable
|
6
6
|
|
7
7
|
has_many :project_assignments
|
8
|
-
|
8
|
+
|
9
9
|
class << self
|
10
10
|
def current_user=(user)
|
11
11
|
Thread.current[:current_user] = user
|
@@ -16,7 +16,8 @@ class User < ApplicationRecord
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def current(user)
|
19
|
-
orig_user
|
19
|
+
orig_user = User.current_user
|
20
|
+
User.current_user = user
|
20
21
|
begin
|
21
22
|
return yield
|
22
23
|
ensure
|
@@ -1,2 +1,2 @@
|
|
1
1
|
json.extract! issue_comment, :id, :created_at, :updated_at
|
2
|
-
json.url issue_comment_url(issue_comment, format: :json)
|
2
|
+
json.url issue_comment_url(issue_comment, format: :json)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="page-header">
|
3
3
|
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
|
4
4
|
</div>
|
5
|
-
<%= render 'issue_comments/table' %>
|
5
|
+
<%= render 'issue_comments/table', issue_comments: @issue_comments %>
|
6
6
|
|
7
7
|
<%= link_to t('.new', :default => t("helpers.links.new")),
|
8
8
|
new_issue_comment_path,
|
@@ -1 +1 @@
|
|
1
|
-
json.array! @issue_comments, partial: 'issue_comments/issue_comment', as: :issue_comment
|
1
|
+
json.array! @issue_comments, partial: 'issue_comments/issue_comment', as: :issue_comment
|
@@ -1 +1 @@
|
|
1
|
-
json.partial!
|
1
|
+
json.partial! 'issue_comments/issue_comment', issue_comment: @issue_comment
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="page-header">
|
3
3
|
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
|
4
4
|
</div>
|
5
|
-
<%= render 'issues/table' %>
|
5
|
+
<%= render 'issues/table', issues: @issues %>
|
6
6
|
|
7
7
|
<%= link_to t('.new', :default => t("helpers.links.new")),
|
8
8
|
new_issue_path,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="page-header">
|
3
3
|
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
|
4
4
|
</div>
|
5
|
-
<%= render 'phases/table' %>
|
5
|
+
<%= render 'phases/table', phases: @phases %>
|
6
6
|
|
7
7
|
<%= link_to t('.new', :default => t("helpers.links.new")),
|
8
8
|
new_phase_path,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="page-header">
|
3
3
|
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
|
4
4
|
</div>
|
5
|
-
<%= render 'project_assignments/table' %>
|
5
|
+
<%= render 'project_assignments/table', project_assignments: @project_assignments %>
|
6
6
|
|
7
7
|
<%= link_to t('.new', :default => t("helpers.links.new")),
|
8
8
|
new_project_assignment_path,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="page-header">
|
3
3
|
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
|
4
4
|
</div>
|
5
|
-
<%= render 'projects/table' %>
|
5
|
+
<%= render 'projects/table', projects: @projects %>
|
6
6
|
|
7
7
|
<%= link_to t('.new', :default => t("helpers.links.new")),
|
8
8
|
new_project_path,
|
@@ -18,7 +18,7 @@ Rails.application.configure do
|
|
18
18
|
|
19
19
|
config.cache_store = :memory_store
|
20
20
|
config.public_file_server.headers = {
|
21
|
-
'Cache-Control' => 'public, max-age=172800'
|
21
|
+
'Cache-Control' => 'public, max-age=172800',
|
22
22
|
}
|
23
23
|
else
|
24
24
|
config.action_controller.perform_caching = false
|
@@ -47,7 +47,7 @@ Rails.application.configure do
|
|
47
47
|
config.log_level = :debug
|
48
48
|
|
49
49
|
# Prepend all log lines with the following tags.
|
50
|
-
config.log_tags = [
|
50
|
+
config.log_tags = [:request_id]
|
51
51
|
|
52
52
|
# Use a different cache store in production.
|
53
53
|
# config.cache_store = :mem_cache_store
|
@@ -75,7 +75,7 @@ Rails.application.configure do
|
|
75
75
|
# require 'syslog/logger'
|
76
76
|
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
77
77
|
|
78
|
-
if ENV[
|
78
|
+
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
79
79
|
logger = ActiveSupport::Logger.new(STDOUT)
|
80
80
|
logger.formatter = config.log_formatter
|
81
81
|
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
@@ -15,7 +15,7 @@ Rails.application.configure do
|
|
15
15
|
# Configure public file server for tests with Cache-Control for performance.
|
16
16
|
config.public_file_server.enabled = true
|
17
17
|
config.public_file_server.headers = {
|
18
|
-
'Cache-Control' => 'public, max-age=3600'
|
18
|
+
'Cache-Control' => 'public, max-age=3600',
|
19
19
|
}
|
20
20
|
|
21
21
|
# Show full error reports and disable caching.
|
data/example/config/puma.rb
CHANGED
@@ -4,16 +4,16 @@
|
|
4
4
|
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
5
5
|
# and maximum, this matches the default thread size of Active Record.
|
6
6
|
#
|
7
|
-
threads_count = ENV.fetch(
|
7
|
+
threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i
|
8
8
|
threads threads_count, threads_count
|
9
9
|
|
10
10
|
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
|
11
11
|
#
|
12
|
-
port ENV.fetch(
|
12
|
+
port ENV.fetch('PORT') { 3000 }
|
13
13
|
|
14
14
|
# Specifies the `environment` that Puma will run in.
|
15
15
|
#
|
16
|
-
environment ENV.fetch(
|
16
|
+
environment ENV.fetch('RAILS_ENV') { 'development' }
|
17
17
|
|
18
18
|
# Specifies the number of `workers` to boot in clustered mode.
|
19
19
|
# Workers are forked webserver processes. If using threads and workers together
|
data/example/db/schema.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
ActiveRecord::Schema.define(version:
|
2
|
+
ActiveRecord::Schema.define(version: 20_161_013_025_452) do
|
3
3
|
create_table :users do |t|
|
4
|
-
t.string :email, default:
|
5
|
-
t.string :encrypted_password, default:
|
4
|
+
t.string :email, default: '', null: false
|
5
|
+
t.string :encrypted_password, default: '', null: false
|
6
6
|
t.string :reset_password_token
|
7
7
|
t.datetime :reset_password_sent_at
|
8
8
|
t.datetime :remember_created_at
|
9
|
-
t.integer :sign_in_count,
|
9
|
+
t.integer :sign_in_count, default: 0, null: false
|
10
10
|
t.datetime :current_sign_in_at
|
11
11
|
t.datetime :last_sign_in_at
|
12
12
|
t.string :current_sign_in_ip
|
@@ -18,21 +18,21 @@ ActiveRecord::Schema.define(version: 20161013025452) do
|
|
18
18
|
|
19
19
|
create_table :projects do |t|
|
20
20
|
t.references :owner, null: false
|
21
|
-
t.string :name
|
21
|
+
t.string :name, null: false
|
22
22
|
t.boolean :closed, null: false, default: false
|
23
23
|
end
|
24
24
|
add_foreign_key :projects, :users, column: 'owner_id'
|
25
25
|
|
26
26
|
create_table :phases do |t|
|
27
|
-
t.references :project
|
28
|
-
t.string :name
|
29
|
-
t.datetime :started_at
|
27
|
+
t.references :project, null: false, foreign_key: true
|
28
|
+
t.string :name, null: false
|
29
|
+
t.datetime :started_at, null: false
|
30
30
|
t.datetime :finished_at, null: false
|
31
31
|
end
|
32
32
|
|
33
33
|
create_table :project_assignments do |t|
|
34
34
|
t.references :project, null: false, foreign_key: true
|
35
|
-
t.references :user
|
35
|
+
t.references :user, null: false, foreign_key: true
|
36
36
|
t.datetime :started_at
|
37
37
|
t.datetime :finished_at
|
38
38
|
t.datetime :created_at, null: false
|