model_base_generators 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/example/.model_base/controllers +1 -0
  4. data/example/app/controllers/attached_files_controller.rb +63 -0
  5. data/example/app/helpers/attached_files_helper.rb +3 -0
  6. data/example/app/models/attached_file.rb +4 -0
  7. data/example/app/models/issue_comment.rb +4 -0
  8. data/example/app/validations/attached_file_validation.rb +8 -0
  9. data/example/app/validations/issue_comment_validation.rb +8 -0
  10. data/example/app/views/attached_files/_attached_file.json.jbuilder +2 -0
  11. data/example/app/views/attached_files/_form.html.erb +48 -0
  12. data/example/app/views/attached_files/_table.html.erb +31 -0
  13. data/example/app/views/attached_files/edit.html.erb +5 -0
  14. data/example/app/views/attached_files/index.html.erb +9 -0
  15. data/example/app/views/attached_files/index.json.jbuilder +1 -0
  16. data/example/app/views/attached_files/new.html.erb +5 -0
  17. data/example/app/views/attached_files/show.html.erb +27 -0
  18. data/example/app/views/attached_files/show.json.jbuilder +1 -0
  19. data/example/config/routes.rb +1 -0
  20. data/example/db/schema.rb +7 -0
  21. data/example/spec/controllers/attached_files_controller_spec.rb +181 -0
  22. data/example/spec/factories/attached_files.rb +7 -0
  23. data/example/spec/helpers/attached_files_helper_spec.rb +15 -0
  24. data/example/spec/requests/attached_files_spec.rb +14 -0
  25. data/example/spec/routing/attached_files_routing_spec.rb +38 -0
  26. data/example/spec/views/attached_files/edit.html.erb_spec.rb +23 -0
  27. data/example/spec/views/attached_files/index.html.erb_spec.rb +22 -0
  28. data/example/spec/views/attached_files/new.html.erb_spec.rb +23 -0
  29. data/example/spec/views/attached_files/show.html.erb_spec.rb +19 -0
  30. data/lib/generators/model_base/templates/app/controllers/concerns/authentication.rb +3 -0
  31. data/lib/generators/model_base/templates/spec/factories/users.rb +3 -0
  32. data/lib/generators/model_base/templates/spec/support/controller_macros.rb +3 -0
  33. data/lib/generators/model_base/templates/spec/support/devise.rb +3 -0
  34. data/lib/generators/model_base/templates/spec/support/field_assertions.rb +3 -0
  35. data/lib/generators/model_base/templates/spec/support/time_match_support.rb +3 -0
  36. data/lib/model_base/column_attribute.rb +8 -3
  37. data/lib/model_base/meta_model.rb +1 -1
  38. data/lib/model_base/version.rb +1 -1
  39. data/lib/templates/erb/scaffold/_table.html.erb +7 -3
  40. metadata +25 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fd512a5112649126c0f9452cb89c065afba0496
4
- data.tar.gz: ec37a9808b638e47d3ecea810aa5fa4506dee1b3
3
+ metadata.gz: 12bc2ae6438e288406a11f289b337ddb2c73fc73
4
+ data.tar.gz: 6ea1fa31940044e0e5dba22387f260192c67d80e
5
5
  SHA512:
6
- metadata.gz: 7cd324983e86897c7fef5bb43685e0376ca2866b6b8cfe1bf45ce6163a11673cf7f07ee0d3cab7a79e62ba2b5679e8d0ae58d03a173896f826672f1235ce8093
7
- data.tar.gz: 48c9e80dd18de4a78c022658b9b4478dc4be34e4754801f410f2d4ba2539d2697edd2ae2ba5382d78a83644f9c1d1732768cd3ce0280e8cca256583108c43da1
6
+ metadata.gz: 66a87abc8fb944a33794a7df483607b63f00bd0ba93740a6a860403fdb9eb3e90e3cfa4b297ecfab973ee01b34f2c876418e9f9639fd870037f40e265f83e787
7
+ data.tar.gz: e59829fe201033895a7a937a5aed790045c6734b452d2fc95721275b26b5405f764d3b470fdb538c9bfe317267a43f1288a8826a24d876c795de5cd84e3b8681
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ namespace :example do
7
7
  desc "Run spec in example"
8
8
  task :spec do
9
9
  Bundler.with_clean_env do
10
- cmd = 'cd example && bundle && bundle exec rake spec'
10
+ cmd = 'cd example && bundle && rm -f db/*.sqlite3 && bundle exec rake db:create db:schema:load spec'
11
11
  unless system(cmd)
12
12
  raise "Failure: #{cmd}"
13
13
  end
@@ -3,3 +3,4 @@ project_assignments
3
3
  phases
4
4
  issues
5
5
  issue_comments
6
+ attached_files
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+ class AttachedFilesController < ApplicationController
3
+ include Authentication
4
+ load_and_authorize_resource except: [:index]
5
+
6
+ before_action :set_attached_file, only: [:show, :edit, :update, :destroy]
7
+
8
+ # GET /attached_files
9
+ def index
10
+ @attached_files = AttachedFile.all
11
+ end
12
+
13
+ # GET /attached_files/1
14
+ def show
15
+ end
16
+
17
+ # GET /attached_files/new
18
+ def new
19
+ @attached_file = AttachedFile.new
20
+ end
21
+
22
+ # GET /attached_files/1/edit
23
+ def edit
24
+ end
25
+
26
+ # POST /attached_files
27
+ def create
28
+ @attached_file = AttachedFile.new(attached_file_params)
29
+
30
+ if @attached_file.save
31
+ redirect_to @attached_file, notice: 'Attached file was successfully created.'
32
+ else
33
+ render :new
34
+ end
35
+ end
36
+
37
+ # PATCH/PUT /attached_files/1
38
+ def update
39
+ if @attached_file.update(attached_file_params)
40
+ redirect_to @attached_file, notice: 'Attached file was successfully updated.'
41
+ else
42
+ render :edit
43
+ end
44
+ end
45
+
46
+ # DELETE /attached_files/1
47
+ def destroy
48
+ @attached_file.destroy
49
+ redirect_to attached_files_url, notice: 'Attached file was successfully destroyed.'
50
+ end
51
+
52
+ private
53
+
54
+ # Use callbacks to share common setup or constraints between actions.
55
+ def set_attached_file
56
+ @attached_file = AttachedFile.find(params[:id])
57
+ end
58
+
59
+ # Only allow a trusted parameter "white list" through.
60
+ def attached_file_params
61
+ params.require(:attached_file).permit(:issue_comment_id, :url)
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+ module AttachedFilesHelper
3
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ class AttachedFile < ApplicationRecord
3
+ belongs_to :issue_comment
4
+ end
@@ -2,4 +2,8 @@
2
2
  class IssueComment < ApplicationRecord
3
3
  belongs_to :issue
4
4
  belongs_to :user
5
+
6
+ def title
7
+ description.truncate(50)
8
+ end
5
9
  end
@@ -0,0 +1,8 @@
1
+ module AttachedFileValidation
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ validates :issue_comment_id, presence: true, numericality: true
6
+ validates :url, presence: true
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module IssueCommentValidation
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ validates :issue_id, presence: true, numericality: true
6
+ validates :user_id, presence: true, numericality: true
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ json.extract! attached_file, :id, :created_at, :updated_at
2
+ json.url attached_file_url(attached_file, format: :json)
@@ -0,0 +1,48 @@
1
+ <%= form_for attached_file, :html => { :class => "form-horizontal attached_file" } do |f| %>
2
+
3
+ <% if attached_file.errors.any? %>
4
+ <div id="error_expl" class="panel panel-danger">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= pluralize(attached_file.errors.count, "error") %> prohibited this attached_file from being saved:</h3>
7
+ </div>
8
+ <div class="panel-body">
9
+ <ul>
10
+ <% attached_file.errors.full_messages.each do |msg| %>
11
+ <li><%= msg %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+ </div>
16
+ <% end %>
17
+
18
+ <div class="form-group">
19
+ <%= f.label :id, :class => 'control-label col-lg-2' %>
20
+ <div class="col-lg-10">
21
+ <%= f.number_field :id, :class => 'form-control' %>
22
+ </div>
23
+ <%=f.error_span(:id) %>
24
+ </div>
25
+ <div class="form-group">
26
+ <%= f.label :issue_comment_id, :class => 'control-label col-lg-2' %>
27
+ <div class="col-lg-10">
28
+ <%= f.collection_select :issue_comment_id, IssueComment.all, :id, :title, {}, :class=>"form-control" %>
29
+ </div>
30
+ <%=f.error_span(:issue_comment_id) %>
31
+ </div>
32
+ <div class="form-group">
33
+ <%= f.label :url, :class => 'control-label col-lg-2' %>
34
+ <div class="col-lg-10">
35
+ <%= f.text_field :url, :class => 'form-control' %>
36
+ </div>
37
+ <%=f.error_span(:url) %>
38
+ </div>
39
+
40
+ <div class="form-group">
41
+ <div class="col-lg-offset-2 col-lg-10">
42
+ <%= f.submit nil, :class => 'btn btn-primary' %>
43
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
44
+ attached_files_path, :class => 'btn btn-default' %>
45
+ </div>
46
+ </div>
47
+
48
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <%- model_class = AttachedFile -%>
2
+ <table class="table table-striped">
3
+ <thead>
4
+ <tr>
5
+ <th><%= model_class.human_attribute_name(:id) %></th>
6
+ <th><%= model_class.human_attribute_name(:issue_comment_id) %></th>
7
+ <th><%= model_class.human_attribute_name(:url) %></th>
8
+ <th><%= model_class.human_attribute_name(:created_at) %></th>
9
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% attached_files.each do |attached_file| %>
14
+ <tr>
15
+ <td><%= attached_file.id %></td>
16
+ <td><%= attached_file.issue_comment.title %></td>
17
+ <td><%= attached_file.url %></td>
18
+ <td><%=l attached_file.created_at %></td>
19
+ <td>
20
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
21
+ edit_attached_file_path(attached_file), :class => 'btn btn-default btn-xs' %>
22
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
23
+ attached_file_path(attached_file),
24
+ :method => :delete,
25
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
26
+ :class => 'btn btn-xs btn-danger' %>
27
+ </td>
28
+ </tr>
29
+ <% end %>
30
+ </tbody>
31
+ </table>
@@ -0,0 +1,5 @@
1
+ <%- model_class = AttachedFile -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize %></h1>
4
+ </div>
5
+ <%= render 'attached_files/form', attached_file: @attached_file %>
@@ -0,0 +1,9 @@
1
+ <%- model_class = AttachedFile -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
4
+ </div>
5
+ <%= render 'attached_files/table', attached_files: @attached_files %>
6
+
7
+ <%= link_to t('.new', :default => t("helpers.links.new")),
8
+ new_attached_file_path,
9
+ :class => 'btn btn-primary' %>
@@ -0,0 +1 @@
1
+ json.array! @attached_files, partial: 'attached_files/attached_file', as: :attached_file
@@ -0,0 +1,5 @@
1
+ <%- model_class = AttachedFile -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize %></h1>
4
+ </div>
5
+ <%= render 'attached_files/form', attached_file: @attached_file %>
@@ -0,0 +1,27 @@
1
+ <%- model_class = AttachedFile -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => model_class.model_name.human.titleize %></h1>
4
+ </div>
5
+
6
+ <dl class="dl-horizontal">
7
+ <dt><strong><%= model_class.human_attribute_name(:id) %>:</strong></dt>
8
+ <dd><%= @attached_file.id %></dd>
9
+ <dt><strong><%= model_class.human_attribute_name(:issue_comment_id) %>:</strong></dt>
10
+ <dd><%= @attached_file.issue_comment_id %></dd>
11
+ <dt><strong><%= model_class.human_attribute_name(:url) %>:</strong></dt>
12
+ <dd><%= @attached_file.url %></dd>
13
+ <dt><strong><%= model_class.human_attribute_name(:created_at) %>:</strong></dt>
14
+ <dd><%=l @attached_file.created_at %></dd>
15
+ <dt><strong><%= model_class.human_attribute_name(:updated_at) %>:</strong></dt>
16
+ <dd><%=l @attached_file.updated_at %></dd>
17
+ </dl>
18
+
19
+ <%= link_to t('.back', :default => t("helpers.links.back")),
20
+ attached_files_path, :class => 'btn btn-default' %>
21
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
22
+ edit_attached_file_path(@attached_file), :class => 'btn btn-default' %>
23
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
24
+ attached_file_path(@attached_file),
25
+ :method => 'delete',
26
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
27
+ :class => 'btn btn-danger' %>
@@ -0,0 +1 @@
1
+ json.partial! "attached_files/attached_file", attached_file: @attached_file
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+ resources :attached_files
2
3
  resources :issue_comments
3
4
  devise_for :users
4
5
  resources :projects
data/example/db/schema.rb CHANGED
@@ -57,4 +57,11 @@ ActiveRecord::Schema.define(version: 20_161_013_025_452) do
57
57
  t.datetime :created_at, null: false
58
58
  t.datetime :updated_at, null: false
59
59
  end
60
+
61
+ create_table :attached_files do |t|
62
+ t.references :issue_comment, null: false, foreign_key: true
63
+ t.string :url, limit: 4096, null: false, foreign_key: true
64
+ t.datetime :created_at, null: false
65
+ t.datetime :updated_at, null: false
66
+ end
60
67
  end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
5
+ # It demonstrates how one might use RSpec to specify the controller code that
6
+ # was generated by Rails when you ran the scaffold generator.
7
+ #
8
+ # It assumes that the implementation code is generated by the rails scaffold
9
+ # generator. If you are using any extension libraries to generate different
10
+ # controller code, this generated spec may or may not pass.
11
+ #
12
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
13
+ # of tools you can use to make these specs even more expressive, but we're
14
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
15
+ #
16
+ # Compared to earlier versions of this generator, there is very limited use of
17
+ # stubs and message expectations in this spec. Stubs are only used when there
18
+ # is no simpler way to get a handle on the object needed for the example.
19
+ # Message expectations are only used when there is no simpler way to specify
20
+ # that an instance is receiving a specific message.
21
+
22
+ RSpec.describe AttachedFilesController, type: :controller do
23
+ let(:user) { FactoryGirl.create(:user) }
24
+ let(:project) { FactoryGirl.create(:project, owner: user) }
25
+ let(:issue) { FactoryGirl.create(:issue, project: project, creator: user) }
26
+ let(:issue_comment) { FactoryGirl.create(:issue_comment, issue: issue, user: user) }
27
+ let(:attached_file) { FactoryGirl.create(:attached_file, issue_comment: issue_comment) }
28
+ before { devise_user_login(user) }
29
+
30
+ # This should return the minimal set of attributes required to create a valid
31
+ # AttachedFile. As you add validations to AttachedFile, be sure to
32
+ # adjust the attributes here as well.
33
+ let(:valid_parameters) do
34
+ FactoryGirl.attributes_for(:attached_file).merge(issue_comment_id: issue_comment.id)
35
+ end
36
+
37
+ let(:invalid_parameters) do
38
+ valid_parameters.symbolize_keys.merge(url: '')
39
+ end
40
+
41
+ # This should return the minimal set of values that should be in the session
42
+ # in order to pass any filters (e.g. authentication) defined in
43
+ # AttachedFilesController. Be sure to keep this updated too.
44
+ let(:valid_session) { {} }
45
+
46
+ describe 'GET #index' do
47
+ it 'assigns all attached_files as @attached_files' do
48
+ get :index, session: valid_session,
49
+ params: {}
50
+ expect(assigns(:attached_files)).to eq([attached_file])
51
+ end
52
+ end
53
+
54
+ describe 'GET #show' do
55
+ it 'assigns the requested attached_file as @attached_file' do
56
+ attached_file # To create attached_file
57
+ get :show, session: valid_session,
58
+ params: { id: attached_file.to_param }
59
+ expect(assigns(:attached_file)).to eq(attached_file)
60
+ end
61
+ end
62
+
63
+ describe 'GET #new' do
64
+ it 'assigns a new attached_file as @attached_file' do
65
+ get :new, session: valid_session,
66
+ params: {}
67
+ expect(assigns(:attached_file)).to be_a_new(AttachedFile)
68
+ end
69
+ end
70
+
71
+ describe 'GET #edit' do
72
+ it 'assigns the requested attached_file as @attached_file' do
73
+ attached_file # To create attached_file
74
+ get :edit, session: valid_session,
75
+ params: { id: attached_file.to_param }
76
+ expect(assigns(:attached_file)).to eq(attached_file)
77
+ end
78
+ end
79
+
80
+ describe 'POST #create' do
81
+ context 'with valid params' do
82
+ it 'creates a new AttachedFile' do
83
+ expect {
84
+ post :create, session: valid_session,
85
+ params: { attached_file: valid_parameters }
86
+ }.to change(AttachedFile, :count).by(1)
87
+ end
88
+
89
+ it 'assigns a newly created attached_file as @attached_file' do
90
+ post :create, session: valid_session,
91
+ params: { attached_file: valid_parameters }
92
+ expect(assigns(:attached_file)).to be_a(AttachedFile)
93
+ expect(assigns(:attached_file)).to be_persisted
94
+ end
95
+
96
+ it 'redirects to the created attached_file' do
97
+ post :create, session: valid_session,
98
+ params: { attached_file: valid_parameters }
99
+ expect(response).to redirect_to(AttachedFile.last)
100
+ end
101
+ end
102
+
103
+ context 'with invalid params' do
104
+ it 'assigns a newly created but unsaved attached_file as @attached_file' do
105
+ post :create, session: valid_session,
106
+ params: { attached_file: invalid_parameters }
107
+ expect(assigns(:attached_file)).to be_a_new(AttachedFile)
108
+ end
109
+
110
+ it "re-renders the 'new' template" do
111
+ post :create, session: valid_session,
112
+ params: { attached_file: invalid_parameters }
113
+ expect(response).to render_template('new')
114
+ end
115
+ end
116
+ end
117
+
118
+ describe 'PUT #update' do
119
+ context 'with valid params' do
120
+ let(:new_url) { valid_parameters[:url].succ }
121
+ let(:new_parameters) do
122
+ valid_parameters.merge(url: new_url)
123
+ end
124
+
125
+ it 'updates the requested attached_file' do
126
+ attached_file # To create attached_file
127
+ put :update, session: valid_session,
128
+ params: { id: attached_file.to_param, attached_file: new_parameters }
129
+ attached_file.reload
130
+ expect(attached_file.url).to eq new_url
131
+ end
132
+
133
+ it 'assigns the requested attached_file as @attached_file' do
134
+ attached_file # To create attached_file
135
+ put :update, session: valid_session,
136
+ params: { id: attached_file.to_param, attached_file: new_parameters }
137
+ expect(assigns(:attached_file)).to eq(attached_file)
138
+ end
139
+
140
+ it 'redirects to the attached_file' do
141
+ attached_file # To create attached_file
142
+ put :update, session: valid_session,
143
+ params: { id: attached_file.to_param, attached_file: new_parameters }
144
+ expect(response).to redirect_to(attached_file)
145
+ end
146
+ end
147
+
148
+ context 'with invalid params' do
149
+ it 'assigns the attached_file as @attached_file' do
150
+ attached_file # To create attached_file
151
+ put :update, session: valid_session,
152
+ params: { id: attached_file.to_param, attached_file: invalid_parameters }
153
+ expect(assigns(:attached_file)).to eq(attached_file)
154
+ end
155
+
156
+ it "re-renders the 'edit' template" do
157
+ attached_file # To create attached_file
158
+ put :update, session: valid_session,
159
+ params: { id: attached_file.to_param, attached_file: invalid_parameters }
160
+ expect(response).to render_template('edit')
161
+ end
162
+ end
163
+ end
164
+
165
+ describe 'DELETE #destroy' do
166
+ it 'destroys the requested attached_file' do
167
+ attached_file # To create attached_file
168
+ expect {
169
+ delete :destroy, session: valid_session,
170
+ params: { id: attached_file.to_param }
171
+ }.to change(AttachedFile, :count).by(-1)
172
+ end
173
+
174
+ it 'redirects to the attached_files list' do
175
+ attached_file # To create attached_file
176
+ delete :destroy, session: valid_session,
177
+ params: { id: attached_file.to_param }
178
+ expect(response).to redirect_to(attached_files_url)
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ FactoryGirl.define do
3
+ factory :attached_file do
4
+ association :issue_comment, factory: :issue_comment
5
+ url 'attached_file_url_1'
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ # Specs in this file have access to a helper object that includes
5
+ # the AttachedFilesHelper. For example:
6
+ #
7
+ # describe AttachedFilesHelper do
8
+ # describe "string concat" do
9
+ # it "concats two strings with spaces" do
10
+ # expect(helper.concat_strings("this","that")).to eq("this that")
11
+ # end
12
+ # end
13
+ # end
14
+ RSpec.describe AttachedFilesHelper, type: :helper do
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe 'AttachedFiles', type: :request do
5
+ let(:user) { FactoryGirl.create(:user) }
6
+ before { login_as(user, scope: :user) }
7
+
8
+ describe 'GET /attached_files' do
9
+ it 'works! (now write some real specs)' do
10
+ get attached_files_path
11
+ expect(response).to have_http_status(200)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe AttachedFilesController, type: :routing do
5
+ describe 'routing' do
6
+ it 'routes to #index' do
7
+ expect(get: '/attached_files').to route_to('attached_files#index')
8
+ end
9
+
10
+ it 'routes to #new' do
11
+ expect(get: '/attached_files/new').to route_to('attached_files#new')
12
+ end
13
+
14
+ it 'routes to #show' do
15
+ expect(get: '/attached_files/1').to route_to('attached_files#show', id: '1')
16
+ end
17
+
18
+ it 'routes to #edit' do
19
+ expect(get: '/attached_files/1/edit').to route_to('attached_files#edit', id: '1')
20
+ end
21
+
22
+ it 'routes to #create' do
23
+ expect(post: '/attached_files').to route_to('attached_files#create')
24
+ end
25
+
26
+ it 'routes to #update via PUT' do
27
+ expect(put: '/attached_files/1').to route_to('attached_files#update', id: '1')
28
+ end
29
+
30
+ it 'routes to #update via PATCH' do
31
+ expect(patch: '/attached_files/1').to route_to('attached_files#update', id: '1')
32
+ end
33
+
34
+ it 'routes to #destroy' do
35
+ expect(delete: '/attached_files/1').to route_to('attached_files#destroy', id: '1')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe 'attached_files/edit', type: :view do
5
+ let(:user) { FactoryGirl.create(:user) }
6
+ let(:project) { FactoryGirl.create(:project, owner: user) }
7
+ let(:issue) { FactoryGirl.create(:issue, project: project, creator: user) }
8
+ let(:issue_comment) { FactoryGirl.create(:issue_comment, issue: issue, user: user) }
9
+ let(:attached_file) { FactoryGirl.create(:attached_file, issue_comment: issue_comment) }
10
+ before(:each) do
11
+ assign(:attached_file, attached_file)
12
+ end
13
+
14
+ it 'renders the edit attached_file form' do
15
+ render
16
+
17
+ assert_select 'form[action=?][method=?]', attached_file_path(attached_file), 'post' do
18
+ assert_select 'input#attached_file_id[name=?]', 'attached_file[id]'
19
+ assert_select 'select#attached_file_issue_comment_id[name=?]', 'attached_file[issue_comment_id]'
20
+ assert_select 'input#attached_file_url[name=?]', 'attached_file[url]'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe 'attached_files/index', type: :view do
5
+ let(:user) { FactoryGirl.create(:user) }
6
+ let(:project) { FactoryGirl.create(:project, owner: user) }
7
+ let(:issue) { FactoryGirl.create(:issue, project: project, creator: user) }
8
+ let(:issue_comment) { FactoryGirl.create(:issue_comment, issue: issue, user: user) }
9
+ before(:each) do
10
+ assign(:attached_files, [
11
+ FactoryGirl.create(:attached_file, issue_comment: issue_comment, url: 'attached_file_url_1'),
12
+ FactoryGirl.create(:attached_file, issue_comment: issue_comment, url: 'attached_file_url_2'),
13
+ ])
14
+ end
15
+
16
+ it 'renders a list of attached_files' do
17
+ render
18
+ assert_select 'tr>td', text: issue_comment.title, count: 2
19
+ assert_select 'tr>td', text: 'attached_file_url_1', count: 1
20
+ assert_select 'tr>td', text: 'attached_file_url_2', count: 1
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe 'attached_files/new', type: :view do
5
+ let(:user) { FactoryGirl.create(:user) }
6
+ let(:project) { FactoryGirl.create(:project, owner: user) }
7
+ let(:issue) { FactoryGirl.create(:issue, project: project, creator: user) }
8
+ let(:issue_comment) { FactoryGirl.create(:issue_comment, issue: issue, user: user) }
9
+ let(:attached_file) { FactoryGirl.build(:attached_file, issue_comment: issue_comment) }
10
+ before(:each) do
11
+ assign(:attached_file, attached_file)
12
+ end
13
+
14
+ it 'renders new attached_file form' do
15
+ render
16
+
17
+ assert_select 'form[action=?][method=?]', attached_files_path, 'post' do
18
+ assert_select 'input#attached_file_id[name=?]', 'attached_file[id]'
19
+ assert_select 'select#attached_file_issue_comment_id[name=?]', 'attached_file[issue_comment_id]'
20
+ assert_select 'input#attached_file_url[name=?]', 'attached_file[url]'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe 'attached_files/show', type: :view do
5
+ let(:user) { FactoryGirl.create(:user) }
6
+ let(:project) { FactoryGirl.create(:project, owner: user) }
7
+ let(:issue) { FactoryGirl.create(:issue, project: project, creator: user) }
8
+ let(:issue_comment) { FactoryGirl.create(:issue_comment, issue: issue, user: user) }
9
+ let(:attached_file) { FactoryGirl.create(:attached_file, issue_comment: issue_comment) }
10
+ before(:each) do
11
+ assign(:attached_file, attached_file)
12
+ end
13
+
14
+ it 'renders attributes in <p>' do
15
+ render
16
+ expect(rendered).to match(/1/)
17
+ expect(rendered).to match(/attached_file_url_1/)
18
+ end
19
+ end
@@ -1,3 +1,6 @@
1
+ <%- unless ModelBase.config.frozen_string_literal.nil? -%>
2
+ # frozen_string_literal: <%= ModelBase.config.frozen_string_literal.inspect %>
3
+ <%- end -%>
1
4
  module Authentication
2
5
  def self.included(klass)
3
6
  klass.class_eval do
@@ -1,3 +1,6 @@
1
+ <%- unless ModelBase.config.frozen_string_literal.nil? -%>
2
+ # frozen_string_literal: <%= ModelBase.config.frozen_string_literal.inspect %>
3
+ <%- end -%>
1
4
  FactoryGirl.define do
2
5
  factory :user do
3
6
  email "user1@example.com"
@@ -1,3 +1,6 @@
1
+ <%- unless ModelBase.config.frozen_string_literal.nil? -%>
2
+ # frozen_string_literal: <%= ModelBase.config.frozen_string_literal.inspect %>
3
+ <%- end -%>
1
4
  module ControllerMacros
2
5
  def devise_login(key, user)
3
6
  @request.env["devise.mapping"] = Devise.mappings[key]
@@ -1,3 +1,6 @@
1
+ <%- unless ModelBase.config.frozen_string_literal.nil? -%>
2
+ # frozen_string_literal: <%= ModelBase.config.frozen_string_literal.inspect %>
3
+ <%- end -%>
1
4
  # https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-(and-RSpec)
2
5
  RSpec.configure do |config|
3
6
  config.with_options(:type => :controller) do |c|
@@ -1,3 +1,6 @@
1
+ <%- unless ModelBase.config.frozen_string_literal.nil? -%>
2
+ # frozen_string_literal: <%= ModelBase.config.frozen_string_literal.inspect %>
3
+ <%- end -%>
1
4
  def assert_select_datetime_field(object, field, n = 5)
2
5
  (1..n).each do |i|
3
6
  assert_select "select##{object}_#{field}_#{i}i[name=?]", "#{object}[#{field}(#{i}i)]"
@@ -1,3 +1,6 @@
1
+ <%- unless ModelBase.config.frozen_string_literal.nil? -%>
2
+ # frozen_string_literal: <%= ModelBase.config.frozen_string_literal.inspect %>
3
+ <%- end -%>
1
4
  module TimeMatchSupport
2
5
  def localized_time_re(time_str)
3
6
  Regexp.new(Regexp.escape(localize(Time.zone.parse(time_str))))
@@ -72,7 +72,7 @@ module ModelBase
72
72
  if tc = ref_model.title_column
73
73
  tc.sample_value(idx)
74
74
  else
75
- 1
75
+ block_given? ? yield : 1
76
76
  end
77
77
  elsif enumerized?
78
78
  enum = model.model_class.send(name)
@@ -133,7 +133,11 @@ module ModelBase
133
133
  when :datetime, :timestamp, :time
134
134
  'localize(Time.zone.parse(\'%s\'))' % sample_value(idx)
135
135
  else
136
- "'%s'" % sample_value(idx)
136
+ if !title? && ref_model && !ref_model.title_column
137
+ "#{ref_model.full_resource_name}.title"
138
+ else
139
+ "'%s'" % sample_value(idx)
140
+ end
137
141
  end
138
142
  end
139
143
 
@@ -172,7 +176,8 @@ module ModelBase
172
176
  ref_model.respond_to?(:choices_for) ?
173
177
  "#{ref_model.name}.choices_for(#{taregt_name})" :
174
178
  "#{ref_model.name}.all"
175
- "#{form_name}.collection_select :#{column_attr.name}, #{query}, :id, :#{ref_model.title_column.name}"
179
+ tc = ref_model.title_column
180
+ "#{form_name}.collection_select :#{column_attr.name}, #{query}, :id, :#{tc ? tc.name : 'title'}"
176
181
  end
177
182
  end
178
183
 
@@ -108,7 +108,7 @@ module ModelBase
108
108
  end
109
109
 
110
110
  def all_dependencies(required = true)
111
- dependencies.values.map{|m| [m] + m.dependencies(required).values}.flatten.uniq(&:name)
111
+ dependencies.values.map{|m| [m] + m.all_dependencies(required)}.flatten.uniq(&:name)
112
112
  end
113
113
 
114
114
  def factory_girl_options
@@ -1,3 +1,3 @@
1
1
  module ModelBase
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -14,11 +14,15 @@
14
14
  <%- model.columns_for(:index).each do |column| -%>
15
15
  <%- if column.linkable? -%>
16
16
  <td><%%= link_to <%= model.full_resource_name %>.<%= column.name %>, <%= singular_controller_routing_path %>_path(<%= model.full_resource_name %>) %></td>
17
- <%- elsif tcol = column.ref_model.try(:title_column) -%>
18
- <%- if column.required? -%>
17
+ <%- elsif column.ref_model -%>
18
+ <%- if tcol = column.ref_model.try(:title_column) -%>
19
+ <%- if column.required? -%>
19
20
  <td><%%= <%= model.full_resource_name %>.<%= column.reference.name %>.<%= tcol.name %> %></td>
20
- <%- else -%>
21
+ <%- else -%>
21
22
  <td><%%= <%= model.full_resource_name %>.<%= column.reference.name %>.try(:<%= tcol.name %>) %></td>
23
+ <%- end -%>
24
+ <%- else -%>
25
+ <td><%%= <%= model.full_resource_name %>.<%= column.reference.name %>.title %></td>
22
26
  <%- end -%>
23
27
  <%- elsif column.enumerized? -%>
24
28
  <td><%%= <%= model.full_resource_name %>.<%= column.name %>_text %></td>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_base_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-04 00:00:00.000000000 Z
11
+ date: 2016-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -142,6 +142,7 @@ files:
142
142
  - example/app/channels/application_cable/channel.rb
143
143
  - example/app/channels/application_cable/connection.rb
144
144
  - example/app/controllers/application_controller.rb
145
+ - example/app/controllers/attached_files_controller.rb
145
146
  - example/app/controllers/concerns/.keep
146
147
  - example/app/controllers/concerns/authentication.rb
147
148
  - example/app/controllers/issue_comments_controller.rb
@@ -150,6 +151,7 @@ files:
150
151
  - example/app/controllers/project_assignments_controller.rb
151
152
  - example/app/controllers/projects_controller.rb
152
153
  - example/app/helpers/application_helper.rb
154
+ - example/app/helpers/attached_files_helper.rb
153
155
  - example/app/helpers/issue_comments_helper.rb
154
156
  - example/app/helpers/issues_helper.rb
155
157
  - example/app/helpers/phases_helper.rb
@@ -159,6 +161,7 @@ files:
159
161
  - example/app/mailers/application_mailer.rb
160
162
  - example/app/models/ability.rb
161
163
  - example/app/models/application_record.rb
164
+ - example/app/models/attached_file.rb
162
165
  - example/app/models/concerns/.keep
163
166
  - example/app/models/issue.rb
164
167
  - example/app/models/issue_comment.rb
@@ -167,11 +170,22 @@ files:
167
170
  - example/app/models/project_assignment.rb
168
171
  - example/app/models/user.rb
169
172
  - example/app/validations/ar_internal_metadatum_validation.rb
173
+ - example/app/validations/attached_file_validation.rb
174
+ - example/app/validations/issue_comment_validation.rb
170
175
  - example/app/validations/issue_validation.rb
171
176
  - example/app/validations/phase_validation.rb
172
177
  - example/app/validations/project_assignment_validation.rb
173
178
  - example/app/validations/project_validation.rb
174
179
  - example/app/validations/user_validation.rb
180
+ - example/app/views/attached_files/_attached_file.json.jbuilder
181
+ - example/app/views/attached_files/_form.html.erb
182
+ - example/app/views/attached_files/_table.html.erb
183
+ - example/app/views/attached_files/edit.html.erb
184
+ - example/app/views/attached_files/index.html.erb
185
+ - example/app/views/attached_files/index.json.jbuilder
186
+ - example/app/views/attached_files/new.html.erb
187
+ - example/app/views/attached_files/show.html.erb
188
+ - example/app/views/attached_files/show.json.jbuilder
175
189
  - example/app/views/issue_comments/_form.html.erb
176
190
  - example/app/views/issue_comments/_issue_comment.json.jbuilder
177
191
  - example/app/views/issue_comments/_table.html.erb
@@ -251,28 +265,33 @@ files:
251
265
  - example/public/apple-touch-icon-precomposed.png
252
266
  - example/public/apple-touch-icon.png
253
267
  - example/public/favicon.ico
268
+ - example/spec/controllers/attached_files_controller_spec.rb
254
269
  - example/spec/controllers/issue_comments_controller_spec.rb
255
270
  - example/spec/controllers/issues_controller_spec.rb
256
271
  - example/spec/controllers/phases_controller_spec.rb
257
272
  - example/spec/controllers/project_assignments_controller_spec.rb
258
273
  - example/spec/controllers/projects_controller_spec.rb
274
+ - example/spec/factories/attached_files.rb
259
275
  - example/spec/factories/issue_comments.rb
260
276
  - example/spec/factories/issues.rb
261
277
  - example/spec/factories/phases.rb
262
278
  - example/spec/factories/project_assignments.rb
263
279
  - example/spec/factories/projects.rb
264
280
  - example/spec/factories/users.rb
281
+ - example/spec/helpers/attached_files_helper_spec.rb
265
282
  - example/spec/helpers/issue_comments_helper_spec.rb
266
283
  - example/spec/helpers/issues_helper_spec.rb
267
284
  - example/spec/helpers/phases_helper_spec.rb
268
285
  - example/spec/helpers/project_assignments_helper_spec.rb
269
286
  - example/spec/helpers/projects_helper_spec.rb
270
287
  - example/spec/rails_helper.rb
288
+ - example/spec/requests/attached_files_spec.rb
271
289
  - example/spec/requests/issue_comments_spec.rb
272
290
  - example/spec/requests/issues_spec.rb
273
291
  - example/spec/requests/phases_spec.rb
274
292
  - example/spec/requests/project_assignments_spec.rb
275
293
  - example/spec/requests/projects_spec.rb
294
+ - example/spec/routing/attached_files_routing_spec.rb
276
295
  - example/spec/routing/issue_comments_routing_spec.rb
277
296
  - example/spec/routing/issues_routing_spec.rb
278
297
  - example/spec/routing/phases_routing_spec.rb
@@ -283,6 +302,10 @@ files:
283
302
  - example/spec/support/devise.rb
284
303
  - example/spec/support/field_assertions.rb
285
304
  - example/spec/support/time_match_support.rb
305
+ - example/spec/views/attached_files/edit.html.erb_spec.rb
306
+ - example/spec/views/attached_files/index.html.erb_spec.rb
307
+ - example/spec/views/attached_files/new.html.erb_spec.rb
308
+ - example/spec/views/attached_files/show.html.erb_spec.rb
286
309
  - example/spec/views/issue_comments/edit.html.erb_spec.rb
287
310
  - example/spec/views/issue_comments/index.html.erb_spec.rb
288
311
  - example/spec/views/issue_comments/new.html.erb_spec.rb