model_base_generators 0.1.1 → 0.1.2

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/examples/app/controllers/issues_controller.rb +62 -0
  3. data/examples/app/views/issues/_form.html.erb +48 -0
  4. data/examples/app/views/issues/edit.html.erb +5 -0
  5. data/examples/app/views/issues/index.html.erb +38 -0
  6. data/examples/app/views/issues/new.html.erb +5 -0
  7. data/examples/app/views/issues/show.html.erb +23 -0
  8. data/examples/app/views/projects/_form.html.erb +34 -0
  9. data/examples/app/views/projects/edit.html.erb +5 -0
  10. data/examples/app/views/projects/index.html.erb +34 -0
  11. data/examples/app/views/projects/new.html.erb +5 -0
  12. data/examples/app/views/projects/show.html.erb +19 -0
  13. data/examples/spec/controllers/issues_controller_spec.rb +168 -0
  14. data/examples/spec/controllers/projects_controller_spec.rb +165 -0
  15. data/examples/spec/routing/issues_routing_spec.rb +39 -0
  16. data/examples/spec/routing/projects_routing_spec.rb +39 -0
  17. data/examples/spec/views/issues/edit.html.erb_spec.rb +17 -0
  18. data/examples/spec/views/issues/index.html.erb_spec.rb +17 -0
  19. data/examples/spec/views/issues/new.html.erb_spec.rb +17 -0
  20. data/examples/spec/views/issues/show.html.erb_spec.rb +14 -0
  21. data/examples/spec/views/projects/edit.html.erb_spec.rb +15 -0
  22. data/examples/spec/views/projects/index.html.erb_spec.rb +15 -0
  23. data/examples/spec/views/projects/new.html.erb_spec.rb +15 -0
  24. data/examples/spec/views/projects/show.html.erb_spec.rb +12 -0
  25. data/lib/model_base/column_attribute.rb +4 -0
  26. data/lib/model_base/version.rb +1 -1
  27. data/lib/templates/rspec/scaffold/controller_spec.rb +3 -3
  28. data/lib/templates/rspec/scaffold/edit_spec.rb +2 -2
  29. data/lib/templates/rspec/scaffold/index_spec.rb +1 -1
  30. data/lib/templates/rspec/scaffold/new_spec.rb +2 -2
  31. data/lib/templates/rspec/scaffold/show_spec.rb +1 -1
  32. metadata +24 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae5bd67cc2bfeaf2373e6f6dda5af7074564db3e
4
- data.tar.gz: 4b9a4d3a5eb3c64179eab64446e76ac5c0f3ca6b
3
+ metadata.gz: eb84b8f69e4c5c2e1a2250905a19c610f8e192d3
4
+ data.tar.gz: 11d43d65609f8e5e52dc9806dda0a32539fad7de
5
5
  SHA512:
6
- metadata.gz: 62f3b62063ed1f57d10b489f3f7c9c307309e6c98373004ac3b8f314d3573ce20fd1bdbde67320dd071a31529a20739bcf3a59681d03a7b3c9b822a48416587b
7
- data.tar.gz: 95f35227c950762c8e794e61e8f30a61abece1fbd0be689dc1ecbac69a8f361c1c25ab79b448622749da93bdf7be3e69be79f2406fbe5cdca77f9d3758ae85cc
6
+ metadata.gz: 7eda2a0b8df381f193a27e02d75882acca1b68f7653319af3affa4e3649aa12133dcb51b23f415874cce131a345bfb40ad77674523dbda3e0205c8e4ea7c3d6c
7
+ data.tar.gz: cb4eb57b0bc73b04125ba9aecf0debc5ac0156983f8004637608c0ab0e0f5c5d6bb2992069070fd67b3031d1bf3ace9ba83bca3fc54dafc142ecaee9f2f67518
@@ -0,0 +1,62 @@
1
+ class IssuesController < ApplicationController
2
+ include Authentication
3
+ load_and_authorize_resource except: [:index]
4
+
5
+ before_action :set_issue, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /issues
8
+ def index
9
+ @issues = Issue.all
10
+ end
11
+
12
+ # GET /issues/1
13
+ def show
14
+ end
15
+
16
+ # GET /issues/new
17
+ def new
18
+ @issue = Issue.new
19
+ end
20
+
21
+ # GET /issues/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /issues
26
+ def create
27
+ @issue = Issue.new(issue_params)
28
+
29
+ if @issue.save
30
+ redirect_to @issue, notice: 'Issue was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /issues/1
37
+ def update
38
+ if @issue.update(issue_params)
39
+ redirect_to @issue, notice: 'Issue was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /issues/1
46
+ def destroy
47
+ @issue.destroy
48
+ redirect_to issues_url, notice: 'Issue was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+
53
+ # Use callbacks to share common setup or constraints between actions.
54
+ def set_issue
55
+ @issue = Issue.find(params[:id])
56
+ end
57
+
58
+ # Only allow a trusted parameter "white list" through.
59
+ def issue_params
60
+ params.require(:issue).permit(:project_id, :title, :status)
61
+ end
62
+ end
@@ -0,0 +1,48 @@
1
+ <%= form_for issue, :html => { :class => "form-horizontal issue" } do |f| %>
2
+
3
+ <% if issue.errors.any? %>
4
+ <div id="error_expl" class="panel panel-danger">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= pluralize(issue.errors.count, "error") %> prohibited this issue from being saved:</h3>
7
+ </div>
8
+ <div class="panel-body">
9
+ <ul>
10
+ <% issue.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 :project_id, :class => 'control-label col-lg-2' %>
20
+ <div class="col-lg-10">
21
+ <%= f.collection_select :project_id, Project.all, :id, :name, {}, :class=>"form-control" %>
22
+ </div>
23
+ <%=f.error_span(:project_id) %>
24
+ </div>
25
+ <div class="form-group">
26
+ <%= f.label :title, :class => 'control-label col-lg-2' %>
27
+ <div class="col-lg-10">
28
+ <%= f.text_field :title, :class => 'form-control' %>
29
+ </div>
30
+ <%=f.error_span(:title) %>
31
+ </div>
32
+ <div class="form-group">
33
+ <%= f.label :status, :class => 'control-label col-lg-2' %>
34
+ <div class="col-lg-10">
35
+ <%= f.select :status, Issue.status.optoins, {}, :class=>"form-control" %>
36
+ </div>
37
+ <%=f.error_span(:status) %>
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
+ issues_path, :class => 'btn btn-default' %>
45
+ </div>
46
+ </div>
47
+
48
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <%- model_class = Issue -%>
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 'issues/form', issue: @issue %>
@@ -0,0 +1,38 @@
1
+ <%- model_class = Issue -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
4
+ </div>
5
+ <table class="table table-striped">
6
+ <thead>
7
+ <tr>
8
+ <th><%= model_class.human_attribute_name(:project_id) %></th>
9
+ <th><%= model_class.human_attribute_name(:title) %></th>
10
+ <th><%= model_class.human_attribute_name(:status) %></th>
11
+ <th><%= model_class.human_attribute_name(:created_at) %></th>
12
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% @issues.each do |issue| %>
17
+ <tr>
18
+ <td><%= issue.project.name %></td>
19
+ <td><%= link_to issue.title, issue_path(issue) %></td>
20
+ <td><%= issue.status_text %></td>
21
+ <td><%=l issue.created_at %></td>
22
+ <td>
23
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
24
+ edit_issue_path(issue), :class => 'btn btn-default btn-xs' %>
25
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
26
+ issue_path(issue),
27
+ :method => :delete,
28
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
29
+ :class => 'btn btn-xs btn-danger' %>
30
+ </td>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+
36
+ <%= link_to t('.new', :default => t("helpers.links.new")),
37
+ new_issue_path,
38
+ :class => 'btn btn-primary' %>
@@ -0,0 +1,5 @@
1
+ <%- model_class = Issue -%>
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 'issues/form', issue: @issue %>
@@ -0,0 +1,23 @@
1
+ <%- model_class = Issue -%>
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(:project_id) %>:</strong></dt>
8
+ <dd><%= @issue.project.name %></dd>
9
+ <dt><strong><%= model_class.human_attribute_name(:title) %>:</strong></dt>
10
+ <dd><%= @issue.title %></dd>
11
+ <dt><strong><%= model_class.human_attribute_name(:status) %>:</strong></dt>
12
+ <dd><%= @issue.status_text %></dd>
13
+ </dl>
14
+
15
+ <%= link_to t('.back', :default => t("helpers.links.back")),
16
+ issues_path, :class => 'btn btn-default' %>
17
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
18
+ edit_issue_path(@issue), :class => 'btn btn-default' %>
19
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
20
+ issue_path(@issue),
21
+ :method => 'delete',
22
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
23
+ :class => 'btn btn-danger' %>
@@ -0,0 +1,34 @@
1
+ <%= form_for project, :html => { :class => "form-horizontal project" } do |f| %>
2
+
3
+ <% if project.errors.any? %>
4
+ <div id="error_expl" class="panel panel-danger">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= pluralize(project.errors.count, "error") %> prohibited this project from being saved:</h3>
7
+ </div>
8
+ <div class="panel-body">
9
+ <ul>
10
+ <% project.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 :name, :class => 'control-label col-lg-2' %>
20
+ <div class="col-lg-10">
21
+ <%= f.text_field :name, :class => 'form-control' %>
22
+ </div>
23
+ <%=f.error_span(:name) %>
24
+ </div>
25
+
26
+ <div class="form-group">
27
+ <div class="col-lg-offset-2 col-lg-10">
28
+ <%= f.submit nil, :class => 'btn btn-primary' %>
29
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
30
+ projects_path, :class => 'btn btn-default' %>
31
+ </div>
32
+ </div>
33
+
34
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <%- model_class = Project -%>
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 'projects/form', project: @project %>
@@ -0,0 +1,34 @@
1
+ <%- model_class = Project -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
4
+ </div>
5
+ <table class="table table-striped">
6
+ <thead>
7
+ <tr>
8
+ <th><%= model_class.human_attribute_name(:name) %></th>
9
+ <th><%= model_class.human_attribute_name(:created_at) %></th>
10
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <% @projects.each do |project| %>
15
+ <tr>
16
+ <td><%= link_to project.name, project_path(project) %></td>
17
+ <td><%=l project.created_at %></td>
18
+ <td>
19
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
20
+ edit_project_path(project), :class => 'btn btn-default btn-xs' %>
21
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
22
+ project_path(project),
23
+ :method => :delete,
24
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
25
+ :class => 'btn btn-xs btn-danger' %>
26
+ </td>
27
+ </tr>
28
+ <% end %>
29
+ </tbody>
30
+ </table>
31
+
32
+ <%= link_to t('.new', :default => t("helpers.links.new")),
33
+ new_project_path,
34
+ :class => 'btn btn-primary' %>
@@ -0,0 +1,5 @@
1
+ <%- model_class = Project -%>
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 'projects/form', project: @project %>
@@ -0,0 +1,19 @@
1
+ <%- model_class = Project -%>
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(:name) %>:</strong></dt>
8
+ <dd><%= @project.name %></dd>
9
+ </dl>
10
+
11
+ <%= link_to t('.back', :default => t("helpers.links.back")),
12
+ projects_path, :class => 'btn btn-default' %>
13
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
14
+ edit_project_path(@project), :class => 'btn btn-default' %>
15
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
16
+ project_path(@project),
17
+ :method => 'delete',
18
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
19
+ :class => 'btn btn-danger' %>
@@ -0,0 +1,168 @@
1
+ require 'rails_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ RSpec.describe IssuesController, type: :controller do
22
+
23
+ let(:project){ FactoryGirl.create(:project) }
24
+ let(:user){ FactoryGirl.create(:user) }
25
+ before{ devise_user_login(user) }
26
+
27
+ let(:issue){ FactoryGirl.create(:issue, project: project) }
28
+
29
+ # This should return the minimal set of attributes required to create a valid
30
+ # Issue. As you add validations to Issue, be sure to
31
+ # adjust the attributes here as well.
32
+ let(:valid_parameters) {
33
+ FactoryGirl.attributes_for(:issue).merge(project_id: project.id)
34
+ }
35
+
36
+ let(:invalid_parameters) {
37
+ valid_parameters.symbolize_keys.merge(title: '')
38
+ }
39
+
40
+ # This should return the minimal set of values that should be in the session
41
+ # in order to pass any filters (e.g. authentication) defined in
42
+ # IssuesController. Be sure to keep this updated too.
43
+ let(:valid_session) { {} }
44
+
45
+ describe "GET #index" do
46
+ it "assigns all issues as @issues" do
47
+ get :index, params: {}, session: valid_session
48
+ expect(assigns(:issues)).to eq([issue])
49
+ end
50
+ end
51
+
52
+ describe "GET #show" do
53
+ it "assigns the requested issue as @issue" do
54
+ issue # To create issue
55
+ get :show, params: {:id => issue.to_param}, session: valid_session
56
+ expect(assigns(:issue)).to eq(issue)
57
+ end
58
+ end
59
+
60
+ describe "GET #new" do
61
+ it "assigns a new issue as @issue" do
62
+ get :new, params: {}, session: valid_session
63
+ expect(assigns(:issue)).to be_a_new(Issue)
64
+ end
65
+ end
66
+
67
+ describe "GET #edit" do
68
+ it "assigns the requested issue as @issue" do
69
+ issue # To create issue
70
+ get :edit, params: {:id => issue.to_param}, session: valid_session
71
+ expect(assigns(:issue)).to eq(issue)
72
+ end
73
+ end
74
+
75
+ describe "POST #create" do
76
+ context "with valid params" do
77
+ it "creates a new Issue" do
78
+ expect {
79
+ post :create, params: {:issue => valid_parameters}, session: valid_session
80
+ }.to change(Issue, :count).by(1)
81
+ end
82
+
83
+ it "assigns a newly created issue as @issue" do
84
+ post :create, params: {:issue => valid_parameters}, session: valid_session
85
+ expect(assigns(:issue)).to be_a(Issue)
86
+ expect(assigns(:issue)).to be_persisted
87
+ end
88
+
89
+ it "redirects to the created issue" do
90
+ post :create, params: {:issue => valid_parameters}, session: valid_session
91
+ expect(response).to redirect_to(Issue.last)
92
+ end
93
+ end
94
+
95
+ context "with invalid params" do
96
+ it "assigns a newly created but unsaved issue as @issue" do
97
+ post :create, params: {:issue => invalid_parameters}, session: valid_session
98
+ expect(assigns(:issue)).to be_a_new(Issue)
99
+ end
100
+
101
+ it "re-renders the 'new' template" do
102
+ post :create, params: {:issue => invalid_parameters}, session: valid_session
103
+ expect(response).to render_template("new")
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "PUT #update" do
109
+ context "with valid params" do
110
+ let(:new_title){ valid_parameters[:title].succ }
111
+ let(:new_status){ valid_parameters[:status].succ }
112
+
113
+ let(:new_parameters) {
114
+ valid_parameters.merge(title: new_title, status: new_status)
115
+ }
116
+
117
+ it "updates the requested issue" do
118
+ issue # To create issue
119
+ put :update, params: {:id => issue.to_param, :issue => new_parameters}, session: valid_session
120
+ issue.reload
121
+ expect(issue.title).to eq new_title
122
+ expect(issue.status).to eq new_status
123
+ end
124
+
125
+ it "assigns the requested issue as @issue" do
126
+ issue # To create issue
127
+ put :update, params: {:id => issue.to_param, :issue => valid_parameters}, session: valid_session
128
+ expect(assigns(:issue)).to eq(issue)
129
+ end
130
+
131
+ it "redirects to the issue" do
132
+ issue # To create issue
133
+ put :update, params: {:id => issue.to_param, :issue => valid_parameters}, session: valid_session
134
+ expect(response).to redirect_to(issue)
135
+ end
136
+ end
137
+
138
+ context "with invalid params" do
139
+ it "assigns the issue as @issue" do
140
+ issue # To create issue
141
+ put :update, params: {:id => issue.to_param, :issue => invalid_parameters}, session: valid_session
142
+ expect(assigns(:issue)).to eq(issue)
143
+ end
144
+
145
+ it "re-renders the 'edit' template" do
146
+ issue # To create issue
147
+ put :update, params: {:id => issue.to_param, :issue => invalid_parameters}, session: valid_session
148
+ expect(response).to render_template("edit")
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "DELETE #destroy" do
154
+ it "destroys the requested issue" do
155
+ issue # To create issue
156
+ expect {
157
+ delete :destroy, params: {:id => issue.to_param}, session: valid_session
158
+ }.to change(Issue, :count).by(-1)
159
+ end
160
+
161
+ it "redirects to the issues list" do
162
+ issue # To create issue
163
+ delete :destroy, params: {:id => issue.to_param}, session: valid_session
164
+ expect(response).to redirect_to(issues_url)
165
+ end
166
+ end
167
+
168
+ end
@@ -0,0 +1,165 @@
1
+ require 'rails_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ RSpec.describe ProjectsController, type: :controller do
22
+
23
+ let(:user){ FactoryGirl.create(:user) }
24
+ before{ devise_user_login(user) }
25
+
26
+ let(:project){ FactoryGirl.create(:project) }
27
+
28
+ # This should return the minimal set of attributes required to create a valid
29
+ # Project. As you add validations to Project, be sure to
30
+ # adjust the attributes here as well.
31
+ let(:valid_parameters) {
32
+ FactoryGirl.attributes_for(:project)
33
+ }
34
+
35
+ let(:invalid_parameters) {
36
+ valid_parameters.symbolize_keys.merge(name: '')
37
+ }
38
+
39
+ # This should return the minimal set of values that should be in the session
40
+ # in order to pass any filters (e.g. authentication) defined in
41
+ # ProjectsController. Be sure to keep this updated too.
42
+ let(:valid_session) { {} }
43
+
44
+ describe "GET #index" do
45
+ it "assigns all projects as @projects" do
46
+ get :index, params: {}, session: valid_session
47
+ expect(assigns(:projects)).to eq([project])
48
+ end
49
+ end
50
+
51
+ describe "GET #show" do
52
+ it "assigns the requested project as @project" do
53
+ project # To create project
54
+ get :show, params: {:id => project.to_param}, session: valid_session
55
+ expect(assigns(:project)).to eq(project)
56
+ end
57
+ end
58
+
59
+ describe "GET #new" do
60
+ it "assigns a new project as @project" do
61
+ get :new, params: {}, session: valid_session
62
+ expect(assigns(:project)).to be_a_new(Project)
63
+ end
64
+ end
65
+
66
+ describe "GET #edit" do
67
+ it "assigns the requested project as @project" do
68
+ project # To create project
69
+ get :edit, params: {:id => project.to_param}, session: valid_session
70
+ expect(assigns(:project)).to eq(project)
71
+ end
72
+ end
73
+
74
+ describe "POST #create" do
75
+ context "with valid params" do
76
+ it "creates a new Project" do
77
+ expect {
78
+ post :create, params: {:project => valid_parameters}, session: valid_session
79
+ }.to change(Project, :count).by(1)
80
+ end
81
+
82
+ it "assigns a newly created project as @project" do
83
+ post :create, params: {:project => valid_parameters}, session: valid_session
84
+ expect(assigns(:project)).to be_a(Project)
85
+ expect(assigns(:project)).to be_persisted
86
+ end
87
+
88
+ it "redirects to the created project" do
89
+ post :create, params: {:project => valid_parameters}, session: valid_session
90
+ expect(response).to redirect_to(Project.last)
91
+ end
92
+ end
93
+
94
+ context "with invalid params" do
95
+ it "assigns a newly created but unsaved project as @project" do
96
+ post :create, params: {:project => invalid_parameters}, session: valid_session
97
+ expect(assigns(:project)).to be_a_new(Project)
98
+ end
99
+
100
+ it "re-renders the 'new' template" do
101
+ post :create, params: {:project => invalid_parameters}, session: valid_session
102
+ expect(response).to render_template("new")
103
+ end
104
+ end
105
+ end
106
+
107
+ describe "PUT #update" do
108
+ context "with valid params" do
109
+ let(:new_name){ valid_parameters[:name].succ }
110
+
111
+ let(:new_parameters) {
112
+ valid_parameters.merge(name: new_name)
113
+ }
114
+
115
+ it "updates the requested project" do
116
+ project # To create project
117
+ put :update, params: {:id => project.to_param, :project => new_parameters}, session: valid_session
118
+ project.reload
119
+ expect(project.name).to eq new_name
120
+ end
121
+
122
+ it "assigns the requested project as @project" do
123
+ project # To create project
124
+ put :update, params: {:id => project.to_param, :project => valid_parameters}, session: valid_session
125
+ expect(assigns(:project)).to eq(project)
126
+ end
127
+
128
+ it "redirects to the project" do
129
+ project # To create project
130
+ put :update, params: {:id => project.to_param, :project => valid_parameters}, session: valid_session
131
+ expect(response).to redirect_to(project)
132
+ end
133
+ end
134
+
135
+ context "with invalid params" do
136
+ it "assigns the project as @project" do
137
+ project # To create project
138
+ put :update, params: {:id => project.to_param, :project => invalid_parameters}, session: valid_session
139
+ expect(assigns(:project)).to eq(project)
140
+ end
141
+
142
+ it "re-renders the 'edit' template" do
143
+ project # To create project
144
+ put :update, params: {:id => project.to_param, :project => invalid_parameters}, session: valid_session
145
+ expect(response).to render_template("edit")
146
+ end
147
+ end
148
+ end
149
+
150
+ describe "DELETE #destroy" do
151
+ it "destroys the requested project" do
152
+ project # To create project
153
+ expect {
154
+ delete :destroy, params: {:id => project.to_param}, session: valid_session
155
+ }.to change(Project, :count).by(-1)
156
+ end
157
+
158
+ it "redirects to the projects list" do
159
+ project # To create project
160
+ delete :destroy, params: {:id => project.to_param}, session: valid_session
161
+ expect(response).to redirect_to(projects_url)
162
+ end
163
+ end
164
+
165
+ end
@@ -0,0 +1,39 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe IssuesController, type: :routing do
4
+ describe "routing" do
5
+
6
+ it "routes to #index" do
7
+ expect(:get => "/issues").to route_to("issues#index")
8
+ end
9
+
10
+ it "routes to #new" do
11
+ expect(:get => "/issues/new").to route_to("issues#new")
12
+ end
13
+
14
+ it "routes to #show" do
15
+ expect(:get => "/issues/1").to route_to("issues#show", :id => "1")
16
+ end
17
+
18
+ it "routes to #edit" do
19
+ expect(:get => "/issues/1/edit").to route_to("issues#edit", :id => "1")
20
+ end
21
+
22
+ it "routes to #create" do
23
+ expect(:post => "/issues").to route_to("issues#create")
24
+ end
25
+
26
+ it "routes to #update via PUT" do
27
+ expect(:put => "/issues/1").to route_to("issues#update", :id => "1")
28
+ end
29
+
30
+ it "routes to #update via PATCH" do
31
+ expect(:patch => "/issues/1").to route_to("issues#update", :id => "1")
32
+ end
33
+
34
+ it "routes to #destroy" do
35
+ expect(:delete => "/issues/1").to route_to("issues#destroy", :id => "1")
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ProjectsController, type: :routing do
4
+ describe "routing" do
5
+
6
+ it "routes to #index" do
7
+ expect(:get => "/projects").to route_to("projects#index")
8
+ end
9
+
10
+ it "routes to #new" do
11
+ expect(:get => "/projects/new").to route_to("projects#new")
12
+ end
13
+
14
+ it "routes to #show" do
15
+ expect(:get => "/projects/1").to route_to("projects#show", :id => "1")
16
+ end
17
+
18
+ it "routes to #edit" do
19
+ expect(:get => "/projects/1/edit").to route_to("projects#edit", :id => "1")
20
+ end
21
+
22
+ it "routes to #create" do
23
+ expect(:post => "/projects").to route_to("projects#create")
24
+ end
25
+
26
+ it "routes to #update via PUT" do
27
+ expect(:put => "/projects/1").to route_to("projects#update", :id => "1")
28
+ end
29
+
30
+ it "routes to #update via PATCH" do
31
+ expect(:patch => "/projects/1").to route_to("projects#update", :id => "1")
32
+ end
33
+
34
+ it "routes to #destroy" do
35
+ expect(:delete => "/projects/1").to route_to("projects#destroy", :id => "1")
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "issues/edit", type: :view do
4
+ before(:each) do
5
+ @issue = assign(:issue, FactoryGirl.create(:issue))
6
+ end
7
+
8
+ it "renders the edit issue form" do
9
+ render
10
+
11
+ assert_select "form[action=?][method=?]", issue_path(@issue), "post" do
12
+ assert_select "select#issue_project_id[name=?]", "issue[project_id]"
13
+ assert_select "input#issue_title[name=?]", "issue[title]"
14
+ assert_select "select#issue_status[name=?]", "issue[status]"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "issues/index", type: :view do
4
+ before(:each) do
5
+ assign(:issues, [
6
+ FactoryGirl.create(:issue),
7
+ FactoryGirl.create(:issue),
8
+ ])
9
+ end
10
+
11
+ it "renders a list of issues" do
12
+ render
13
+ assert_select "tr>td", :text => 2.to_s, :count => 2
14
+ assert_select "tr>td", :text => "Title".to_s, :count => 2
15
+ assert_select "tr>td", :text => 3.to_s, :count => 2
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "issues/new", type: :view do
4
+ before(:each) do
5
+ assign(:issue, FactoryGirl.build(:issue))
6
+ end
7
+
8
+ it "renders new issue form" do
9
+ render
10
+
11
+ assert_select "form[action=?][method=?]", issues_path, "post" do
12
+ assert_select "select#issue_project_id[name=?]", "issue[project_id]"
13
+ assert_select "input#issue_title[name=?]", "issue[title]"
14
+ assert_select "select#issue_status[name=?]", "issue[status]"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "issues/show", type: :view do
4
+ before(:each) do
5
+ @issue = assign(:issue, FactoryGirl.create(:issue))
6
+ end
7
+
8
+ it "renders attributes in <p>" do
9
+ render
10
+ expect(rendered).to match(/2/)
11
+ expect(rendered).to match(/Title/)
12
+ expect(rendered).to match(/3/)
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "projects/edit", type: :view do
4
+ before(:each) do
5
+ @project = assign(:project, FactoryGirl.create(:project))
6
+ end
7
+
8
+ it "renders the edit project form" do
9
+ render
10
+
11
+ assert_select "form[action=?][method=?]", project_path(@project), "post" do
12
+ assert_select "input#project_name[name=?]", "project[name]"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "projects/index", type: :view do
4
+ before(:each) do
5
+ assign(:projects, [
6
+ FactoryGirl.create(:project),
7
+ FactoryGirl.create(:project),
8
+ ])
9
+ end
10
+
11
+ it "renders a list of projects" do
12
+ render
13
+ assert_select "tr>td", :text => "Name".to_s, :count => 2
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "projects/new", type: :view do
4
+ before(:each) do
5
+ assign(:project, FactoryGirl.build(:project))
6
+ end
7
+
8
+ it "renders new project form" do
9
+ render
10
+
11
+ assert_select "form[action=?][method=?]", projects_path, "post" do
12
+ assert_select "input#project_name[name=?]", "project[name]"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "projects/show", type: :view do
4
+ before(:each) do
5
+ @project = assign(:project, FactoryGirl.create(:project))
6
+ end
7
+
8
+ it "renders attributes in <p>" do
9
+ render
10
+ expect(rendered).to match(/Name/)
11
+ end
12
+ end
@@ -38,6 +38,10 @@ module ModelBase
38
38
  enumerized? ? EnumerizedSelectRenderer.new(self) : nil
39
39
  end
40
40
 
41
+ def input_type
42
+ select_renderer ? :select : super
43
+ end
44
+
41
45
  class AbstractSelectRenderer
42
46
  attr_reader :column_attr
43
47
  def initialize(column_attr)
@@ -1,3 +1,3 @@
1
1
  module ModelBase
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -31,7 +31,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
31
31
  required_data_attrs = model.columns.select{|attr| !attr.reference && attr.required? }
32
32
  -%>
33
33
  <%- required_ref_attrs.each do |attr| -%>
34
- let(:<%= attr.name %>){ FactoryGirl.create(:<%= attr.ref_model.full_resource_name %>) }
34
+ let(:<%= attr.reference.name %>){ FactoryGirl.create(:<%= attr.ref_model.full_resource_name %>) }
35
35
  <%- end -%>
36
36
  <%- unless required_ref_attrs.any?{|attr| attr.ref_model.name == 'User' }-%>
37
37
  let(:user){ FactoryGirl.create(:user) }
@@ -40,8 +40,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
40
40
 
41
41
  <%-
42
42
  unless required_ref_attrs.empty?
43
- extra_attributes_to_merge = ".merge(%s)" % required_ref_attrs.map{|attr| "#{attr.name}_id: #{attr.name}.id"}.join(', ')
44
- extra_attributes_for_factory = ", %s" % required_ref_attrs.map{|attr| "#{attr.name}: #{attr.name}"}.join(', ')
43
+ extra_attributes_to_merge = ".merge(%s)" % required_ref_attrs.map{|attr| "#{attr.name}: #{attr.reference.name}.id"}.join(', ')
44
+ extra_attributes_for_factory = ", %s" % required_ref_attrs.map{|attr| "#{attr.reference.name}: #{attr.reference.name}"}.join(', ')
45
45
  end
46
46
  -%>
47
47
  let(:<%= file_name %>){ FactoryGirl.create(:<%= file_name %><%= extra_attributes_for_factory %>) }
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
+ <% output_attributes = model.columns.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
6
  @<%= ns_file_name %> = assign(:<%= ns_file_name %>, FactoryGirl.create(:<%= ns_file_name %>))
@@ -11,7 +11,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
11
11
 
12
12
  assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
13
13
  <% for attribute in output_attributes -%>
14
- <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
14
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
15
15
  assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
16
16
  <% end -%>
17
17
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
+ <% output_attributes = model.columns.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
6
  assign(:<%= table_name %>, [
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
+ <% output_attributes = model.columns.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
6
  assign(:<%= ns_file_name %>, FactoryGirl.build(:<%= ns_file_name %>))
@@ -11,7 +11,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
11
11
 
12
12
  assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
13
13
  <% for attribute in output_attributes -%>
14
- <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
14
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
15
15
  assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
16
16
  <% end -%>
17
17
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
3
+ <% output_attributes = model.columns.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
6
  @<%= ns_file_name %> = assign(:<%= ns_file_name %>, FactoryGirl.create(:<%= ns_file_name %>))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_base_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
@@ -125,6 +125,29 @@ files:
125
125
  - Rakefile
126
126
  - bin/console
127
127
  - bin/setup
128
+ - examples/app/controllers/issues_controller.rb
129
+ - examples/app/views/issues/_form.html.erb
130
+ - examples/app/views/issues/edit.html.erb
131
+ - examples/app/views/issues/index.html.erb
132
+ - examples/app/views/issues/new.html.erb
133
+ - examples/app/views/issues/show.html.erb
134
+ - examples/app/views/projects/_form.html.erb
135
+ - examples/app/views/projects/edit.html.erb
136
+ - examples/app/views/projects/index.html.erb
137
+ - examples/app/views/projects/new.html.erb
138
+ - examples/app/views/projects/show.html.erb
139
+ - examples/spec/controllers/issues_controller_spec.rb
140
+ - examples/spec/controllers/projects_controller_spec.rb
141
+ - examples/spec/routing/issues_routing_spec.rb
142
+ - examples/spec/routing/projects_routing_spec.rb
143
+ - examples/spec/views/issues/edit.html.erb_spec.rb
144
+ - examples/spec/views/issues/index.html.erb_spec.rb
145
+ - examples/spec/views/issues/new.html.erb_spec.rb
146
+ - examples/spec/views/issues/show.html.erb_spec.rb
147
+ - examples/spec/views/projects/edit.html.erb_spec.rb
148
+ - examples/spec/views/projects/index.html.erb_spec.rb
149
+ - examples/spec/views/projects/new.html.erb_spec.rb
150
+ - examples/spec/views/projects/show.html.erb_spec.rb
128
151
  - lib/model_base.rb
129
152
  - lib/model_base/column_attribute.rb
130
153
  - lib/model_base/config.rb