model_base_generators 0.2.0 → 0.2.1

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 (27) hide show
  1. checksums.yaml +4 -4
  2. data/example/app/controllers/project_assignments_controller.rb +62 -0
  3. data/example/app/models/project.rb +1 -0
  4. data/example/app/models/project_assignment.rb +4 -0
  5. data/example/app/models/user.rb +2 -0
  6. data/example/app/validations/project_assignment_validation.rb +8 -0
  7. data/example/app/views/project_assignments/_form.html.erb +48 -0
  8. data/example/app/views/project_assignments/_table.html.erb +31 -0
  9. data/example/app/views/project_assignments/edit.html.erb +5 -0
  10. data/example/app/views/project_assignments/index.html.erb +9 -0
  11. data/example/app/views/project_assignments/new.html.erb +5 -0
  12. data/example/app/views/project_assignments/show.html.erb +25 -0
  13. data/example/config/routes.rb +1 -0
  14. data/example/db/schema.rb +6 -0
  15. data/example/spec/controllers/project_assignments_controller_spec.rb +165 -0
  16. data/example/spec/factories/project_assignments.rb +6 -0
  17. data/example/spec/routing/project_assignments_routing_spec.rb +39 -0
  18. data/example/spec/views/project_assignments/edit.html.erb_spec.rb +19 -0
  19. data/example/spec/views/project_assignments/index.html.erb_spec.rb +18 -0
  20. data/example/spec/views/project_assignments/new.html.erb_spec.rb +19 -0
  21. data/example/spec/views/project_assignments/show.html.erb_spec.rb +15 -0
  22. data/lib/model_base/meta_model.rb +6 -6
  23. data/lib/model_base/version.rb +1 -1
  24. data/lib/templates/factory_girl/factory.rb +3 -3
  25. data/lib/templates/rspec/scaffold/controller_spec.rb +0 -8
  26. data/lib/templates/rspec/scaffold/index_spec.rb +1 -1
  27. metadata +17 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c53033fec333226f20bbcf75ae02b4da95a1b5b2
4
- data.tar.gz: 81090f4cfcd9fe923bcaa6249f75c4787bff9959
3
+ metadata.gz: 65fb2cefa6cc166f62ba47b20ccf5df5b2bf5687
4
+ data.tar.gz: 27276688d944fb3c4c21b8eda9de168780f29882
5
5
  SHA512:
6
- metadata.gz: 7db5951847a6ad2d167b669409ca2fa749f4da4858442af7b89398fb9eb5faae6c34bf4ae4aaaa667f020d855995d74da05c5ecb9abea8fa4d2b60043504c2b3
7
- data.tar.gz: 6f5410fa88de13cc0081cd40807bf96bded9105ae87f02812ce3d33ca75b15d851bcdba57284c5e13ce29f35ccf60129e9e432e892bdf4690183d57ccc1b3b02
6
+ metadata.gz: bf568ccd463e4b74f7ab9eb29e7b0468ae68a222e617e151f8ba6e47ecb5f7866bd72da091b1fc58499a3ba21041d29d16feb7015a08f219aba368965bd03816
7
+ data.tar.gz: d29d93ff17c153ef31f642bda1267466e191a49ee5045cf0ba4781f37a04f9472c7e1e6a24b7841ed636b05d1a8b7f10d678f3c85d52bc185b3b7b31100be0b0
@@ -0,0 +1,62 @@
1
+ class ProjectAssignmentsController < ApplicationController
2
+ include Authentication
3
+ load_and_authorize_resource except: [:index]
4
+
5
+ before_action :set_project_assignment, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /project_assignments
8
+ def index
9
+ @project_assignments = ProjectAssignment.all
10
+ end
11
+
12
+ # GET /project_assignments/1
13
+ def show
14
+ end
15
+
16
+ # GET /project_assignments/new
17
+ def new
18
+ @project_assignment = ProjectAssignment.new
19
+ end
20
+
21
+ # GET /project_assignments/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /project_assignments
26
+ def create
27
+ @project_assignment = ProjectAssignment.new(project_assignment_params)
28
+
29
+ if @project_assignment.save
30
+ redirect_to @project_assignment, notice: 'Project assignment was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /project_assignments/1
37
+ def update
38
+ if @project_assignment.update(project_assignment_params)
39
+ redirect_to @project_assignment, notice: 'Project assignment was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /project_assignments/1
46
+ def destroy
47
+ @project_assignment.destroy
48
+ redirect_to project_assignments_url, notice: 'Project assignment was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+
53
+ # Use callbacks to share common setup or constraints between actions.
54
+ def set_project_assignment
55
+ @project_assignment = ProjectAssignment.find(params[:id])
56
+ end
57
+
58
+ # Only allow a trusted parameter "white list" through.
59
+ def project_assignment_params
60
+ params.require(:project_assignment).permit(:project_id, :user_id)
61
+ end
62
+ end
@@ -1,6 +1,7 @@
1
1
  class Project < ApplicationRecord
2
2
  belongs_to :owner, class_name: 'User'
3
3
  has_many :issues
4
+ has_many :assignments, class_name: 'ProjectAssignment'
4
5
 
5
6
  validates :name, presence: true
6
7
  end
@@ -0,0 +1,4 @@
1
+ class ProjectAssignment < ApplicationRecord
2
+ belongs_to :project
3
+ belongs_to :user
4
+ end
@@ -4,6 +4,8 @@ class User < ApplicationRecord
4
4
  devise :database_authenticatable, :registerable,
5
5
  :recoverable, :rememberable, :trackable, :validatable
6
6
 
7
+ has_many :project_assignments
8
+
7
9
  class << self
8
10
  def current_user=(user)
9
11
  Thread.current[:current_user] = user
@@ -0,0 +1,8 @@
1
+ module ProjectAssignmentValidation
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ validates :project_id, presence: true, numericality: true
6
+ validates :user_id, presence: true, numericality: true
7
+ end
8
+ end
@@ -0,0 +1,48 @@
1
+ <%= form_for project_assignment, :html => { :class => "form-horizontal project_assignment" } do |f| %>
2
+
3
+ <% if project_assignment.errors.any? %>
4
+ <div id="error_expl" class="panel panel-danger">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= pluralize(project_assignment.errors.count, "error") %> prohibited this project_assignment from being saved:</h3>
7
+ </div>
8
+ <div class="panel-body">
9
+ <ul>
10
+ <% project_assignment.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 :project_id, :class => 'control-label col-lg-2' %>
27
+ <div class="col-lg-10">
28
+ <%= f.collection_select :project_id, Project.all, :id, :name, {}, :class=>"form-control" %>
29
+ </div>
30
+ <%=f.error_span(:project_id) %>
31
+ </div>
32
+ <div class="form-group">
33
+ <%= f.label :user_id, :class => 'control-label col-lg-2' %>
34
+ <div class="col-lg-10">
35
+ <%= f.collection_select :user_id, User.all, :id, :email, {}, :class=>"form-control" %>
36
+ </div>
37
+ <%=f.error_span(:user_id) %>
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
+ project_assignments_path, :class => 'btn btn-default' %>
45
+ </div>
46
+ </div>
47
+
48
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <%- model_class = ProjectAssignment -%>
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(:project_id) %></th>
7
+ <th><%= model_class.human_attribute_name(:user_id) %></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
+ <% @project_assignments.each do |project_assignment| %>
14
+ <tr>
15
+ <td><%= project_assignment.id %></td>
16
+ <td><%= project_assignment.project.name %></td>
17
+ <td><%= project_assignment.user.email %></td>
18
+ <td><%=l project_assignment.created_at %></td>
19
+ <td>
20
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
21
+ edit_project_assignment_path(project_assignment), :class => 'btn btn-default btn-xs' %>
22
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
23
+ project_assignment_path(project_assignment),
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 = ProjectAssignment -%>
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 'project_assignments/form', project_assignment: @project_assignment %>
@@ -0,0 +1,9 @@
1
+ <%- model_class = ProjectAssignment -%>
2
+ <div class="page-header">
3
+ <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
4
+ </div>
5
+ <%= render 'project_assignments/table' %>
6
+
7
+ <%= link_to t('.new', :default => t("helpers.links.new")),
8
+ new_project_assignment_path,
9
+ :class => 'btn btn-primary' %>
@@ -0,0 +1,5 @@
1
+ <%- model_class = ProjectAssignment -%>
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 'project_assignments/form', project_assignment: @project_assignment %>
@@ -0,0 +1,25 @@
1
+ <%- model_class = ProjectAssignment -%>
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><%= @project_assignment.id %></dd>
9
+ <dt><strong><%= model_class.human_attribute_name(:project_id) %>:</strong></dt>
10
+ <dd><%= @project_assignment.project.name %></dd>
11
+ <dt><strong><%= model_class.human_attribute_name(:user_id) %>:</strong></dt>
12
+ <dd><%= @project_assignment.user.email %></dd>
13
+ <dt><strong><%= model_class.human_attribute_name(:created_at) %>:</strong></dt>
14
+ <dd><%=l @project_assignment.created_at %></dd>
15
+ </dl>
16
+
17
+ <%= link_to t('.back', :default => t("helpers.links.back")),
18
+ project_assignments_path, :class => 'btn btn-default' %>
19
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
20
+ edit_project_assignment_path(@project_assignment), :class => 'btn btn-default' %>
21
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
22
+ project_assignment_path(@project_assignment),
23
+ :method => 'delete',
24
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
25
+ :class => 'btn btn-danger' %>
@@ -1,6 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  devise_for :users
3
3
  resources :projects
4
+ resources :project_assignments
4
5
  resources :issues
5
6
  root to: 'projects#index'
6
7
  end
data/example/db/schema.rb CHANGED
@@ -22,6 +22,12 @@ ActiveRecord::Schema.define(version: 20161013025452) do
22
22
  end
23
23
  add_foreign_key :projects, :users, column: 'owner_id'
24
24
 
25
+ create_table :project_assignments do |t|
26
+ t.references :project, null: false, foreign_key: true
27
+ t.references :user , null: false, foreign_key: true
28
+ t.datetime :created_at, null: false
29
+ end
30
+
25
31
  create_table :issues do |t|
26
32
  t.references :project, null: false, foreign_key: true
27
33
  t.string :title, null: false
@@ -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 ProjectAssignmentsController, type: :controller do
22
+
23
+ let(:project){ FactoryGirl.create(:project, owner: user) }
24
+ let(:user){ FactoryGirl.create(:user) }
25
+ before{ devise_user_login(user) }
26
+
27
+ let(:project_assignment){ FactoryGirl.create(:project_assignment, project: project, user: user) }
28
+
29
+ # This should return the minimal set of attributes required to create a valid
30
+ # ProjectAssignment. As you add validations to ProjectAssignment, be sure to
31
+ # adjust the attributes here as well.
32
+ let(:valid_parameters) {
33
+ FactoryGirl.attributes_for(:project_assignment).merge(project_id: project.id, user_id: user.id)
34
+ }
35
+
36
+ let(:invalid_parameters) {
37
+ skip("Add a hash of attributes invalid for your model")
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
+ # ProjectAssignmentsController. Be sure to keep this updated too.
43
+ let(:valid_session) { {} }
44
+
45
+ describe "GET #index" do
46
+ it "assigns all project_assignments as @project_assignments" do
47
+ get :index, params: {}, session: valid_session
48
+ expect(assigns(:project_assignments)).to eq([project_assignment])
49
+ end
50
+ end
51
+
52
+ describe "GET #show" do
53
+ it "assigns the requested project_assignment as @project_assignment" do
54
+ project_assignment # To create project_assignment
55
+ get :show, params: {:id => project_assignment.to_param}, session: valid_session
56
+ expect(assigns(:project_assignment)).to eq(project_assignment)
57
+ end
58
+ end
59
+
60
+ describe "GET #new" do
61
+ it "assigns a new project_assignment as @project_assignment" do
62
+ get :new, params: {}, session: valid_session
63
+ expect(assigns(:project_assignment)).to be_a_new(ProjectAssignment)
64
+ end
65
+ end
66
+
67
+ describe "GET #edit" do
68
+ it "assigns the requested project_assignment as @project_assignment" do
69
+ project_assignment # To create project_assignment
70
+ get :edit, params: {:id => project_assignment.to_param}, session: valid_session
71
+ expect(assigns(:project_assignment)).to eq(project_assignment)
72
+ end
73
+ end
74
+
75
+ describe "POST #create" do
76
+ context "with valid params" do
77
+ it "creates a new ProjectAssignment" do
78
+ expect {
79
+ post :create, params: {:project_assignment => valid_parameters}, session: valid_session
80
+ }.to change(ProjectAssignment, :count).by(1)
81
+ end
82
+
83
+ it "assigns a newly created project_assignment as @project_assignment" do
84
+ post :create, params: {:project_assignment => valid_parameters}, session: valid_session
85
+ expect(assigns(:project_assignment)).to be_a(ProjectAssignment)
86
+ expect(assigns(:project_assignment)).to be_persisted
87
+ end
88
+
89
+ it "redirects to the created project_assignment" do
90
+ post :create, params: {:project_assignment => valid_parameters}, session: valid_session
91
+ expect(response).to redirect_to(ProjectAssignment.last)
92
+ end
93
+ end
94
+
95
+ context "with invalid params" do
96
+ it "assigns a newly created but unsaved project_assignment as @project_assignment" do
97
+ post :create, params: {:project_assignment => invalid_parameters}, session: valid_session
98
+ expect(assigns(:project_assignment)).to be_a_new(ProjectAssignment)
99
+ end
100
+
101
+ it "re-renders the 'new' template" do
102
+ post :create, params: {:project_assignment => 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
+
111
+ let(:new_parameters) {
112
+ skip("Add a hash of attributes valid for your model")
113
+ }
114
+
115
+ it "updates the requested project_assignment" do
116
+ project_assignment # To create project_assignment
117
+ put :update, params: {:id => project_assignment.to_param, :project_assignment => new_parameters}, session: valid_session
118
+ project_assignment.reload
119
+ skip("Add assertions for updated state")
120
+ end
121
+
122
+ it "assigns the requested project_assignment as @project_assignment" do
123
+ project_assignment # To create project_assignment
124
+ put :update, params: {:id => project_assignment.to_param, :project_assignment => new_parameters}, session: valid_session
125
+ expect(assigns(:project_assignment)).to eq(project_assignment)
126
+ end
127
+
128
+ it "redirects to the project_assignment" do
129
+ project_assignment # To create project_assignment
130
+ put :update, params: {:id => project_assignment.to_param, :project_assignment => new_parameters}, session: valid_session
131
+ expect(response).to redirect_to(project_assignment)
132
+ end
133
+ end
134
+
135
+ context "with invalid params" do
136
+ it "assigns the project_assignment as @project_assignment" do
137
+ project_assignment # To create project_assignment
138
+ put :update, params: {:id => project_assignment.to_param, :project_assignment => invalid_parameters}, session: valid_session
139
+ expect(assigns(:project_assignment)).to eq(project_assignment)
140
+ end
141
+
142
+ it "re-renders the 'edit' template" do
143
+ project_assignment # To create project_assignment
144
+ put :update, params: {:id => project_assignment.to_param, :project_assignment => 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_assignment" do
152
+ project_assignment # To create project_assignment
153
+ expect {
154
+ delete :destroy, params: {:id => project_assignment.to_param}, session: valid_session
155
+ }.to change(ProjectAssignment, :count).by(-1)
156
+ end
157
+
158
+ it "redirects to the project_assignments list" do
159
+ project_assignment # To create project_assignment
160
+ delete :destroy, params: {:id => project_assignment.to_param}, session: valid_session
161
+ expect(response).to redirect_to(project_assignments_url)
162
+ end
163
+ end
164
+
165
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :project_assignment do
3
+ association :project, factory: :project
4
+ association :user, factory: :user
5
+ end
6
+ end
@@ -0,0 +1,39 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe ProjectAssignmentsController, type: :routing do
4
+ describe "routing" do
5
+
6
+ it "routes to #index" do
7
+ expect(:get => "/project_assignments").to route_to("project_assignments#index")
8
+ end
9
+
10
+ it "routes to #new" do
11
+ expect(:get => "/project_assignments/new").to route_to("project_assignments#new")
12
+ end
13
+
14
+ it "routes to #show" do
15
+ expect(:get => "/project_assignments/1").to route_to("project_assignments#show", :id => "1")
16
+ end
17
+
18
+ it "routes to #edit" do
19
+ expect(:get => "/project_assignments/1/edit").to route_to("project_assignments#edit", :id => "1")
20
+ end
21
+
22
+ it "routes to #create" do
23
+ expect(:post => "/project_assignments").to route_to("project_assignments#create")
24
+ end
25
+
26
+ it "routes to #update via PUT" do
27
+ expect(:put => "/project_assignments/1").to route_to("project_assignments#update", :id => "1")
28
+ end
29
+
30
+ it "routes to #update via PATCH" do
31
+ expect(:patch => "/project_assignments/1").to route_to("project_assignments#update", :id => "1")
32
+ end
33
+
34
+ it "routes to #destroy" do
35
+ expect(:delete => "/project_assignments/1").to route_to("project_assignments#destroy", :id => "1")
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "project_assignments/edit", type: :view do
4
+ let(:project){ FactoryGirl.create(:project, owner: user) }
5
+ let(:user){ FactoryGirl.create(:user) }
6
+ before(:each) do
7
+ @project_assignment = assign(:project_assignment, FactoryGirl.create(:project_assignment, project: project, user: user))
8
+ end
9
+
10
+ it "renders the edit project_assignment form" do
11
+ render
12
+
13
+ assert_select "form[action=?][method=?]", project_assignment_path(@project_assignment), "post" do
14
+ assert_select "input#project_assignment_id[name=?]", "project_assignment[id]"
15
+ assert_select "select#project_assignment_project_id[name=?]", "project_assignment[project_id]"
16
+ assert_select "select#project_assignment_user_id[name=?]", "project_assignment[user_id]"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "project_assignments/index", type: :view do
4
+ let(:project){ FactoryGirl.create(:project, owner: user) }
5
+ let(:user){ FactoryGirl.create(:user) }
6
+ before(:each) do
7
+ assign(:project_assignments, [
8
+ FactoryGirl.create(:project_assignment, project: project, user: user),
9
+ FactoryGirl.create(:project_assignment, project: project, user: user),
10
+ ])
11
+ end
12
+
13
+ it "renders a list of project_assignments" do
14
+ render
15
+ assert_select "tr>td", :text => 'project1', :count => 2
16
+ assert_select "tr>td", :text => 'user1@example.com', :count => 2
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "project_assignments/new", type: :view do
4
+ let(:project){ FactoryGirl.create(:project, owner: user) }
5
+ let(:user){ FactoryGirl.create(:user) }
6
+ before(:each) do
7
+ assign(:project_assignment, FactoryGirl.build(:project_assignment, project: project, user: user))
8
+ end
9
+
10
+ it "renders new project_assignment form" do
11
+ render
12
+
13
+ assert_select "form[action=?][method=?]", project_assignments_path, "post" do
14
+ assert_select "input#project_assignment_id[name=?]", "project_assignment[id]"
15
+ assert_select "select#project_assignment_project_id[name=?]", "project_assignment[project_id]"
16
+ assert_select "select#project_assignment_user_id[name=?]", "project_assignment[user_id]"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "project_assignments/show", type: :view do
4
+ let(:project){ FactoryGirl.create(:project, owner: user) }
5
+ let(:user){ FactoryGirl.create(:user) }
6
+ before(:each) do
7
+ @project_assignment = assign(:project_assignment, FactoryGirl.create(:project_assignment, project: project, user: user))
8
+ end
9
+
10
+ it "renders attributes in <p>" do
11
+ render
12
+ expect(rendered).to match(/project1/)
13
+ expect(rendered).to match(/user1@example.com/)
14
+ end
15
+ end
@@ -68,15 +68,15 @@ module ModelBase
68
68
 
69
69
  def columns
70
70
  @columns ||=
71
- title_column ? raw_columns : [ColumnAttribute.new(self, :id, :integer, title: true)] + raw_columns
71
+ title_column ? raw_columns : [ColumnAttribute.new(self, 'id', :integer, title: true)] + raw_columns
72
72
  end
73
73
 
74
- SPEC_EXCLUSED_COLS = %w[created_at updated_at]
74
+ SPEC_EXCLUSED_COLS = %w[id created_at updated_at]
75
75
  def columns_for(type)
76
76
  case type
77
77
  when :form, :index, :show
78
78
  columns.reject{|c| exclude_for?(type, c) }
79
- when :params then columns_for(:form).reject{|c| c.name == 'id'}
79
+ when :params then columns_for(:form).reject{|c| c.name.to_s == 'id'}
80
80
  when :spec_index then columns_for(:index).reject{|c| SPEC_EXCLUSED_COLS.include?(c.name)}
81
81
  when :spec_show then columns_for(:show ).reject{|c| SPEC_EXCLUSED_COLS.include?(c.name)}
82
82
  when :factory then columns_for(:params).reject{|c| SPEC_EXCLUSED_COLS.include?(c.name)}
@@ -99,8 +99,8 @@ module ModelBase
99
99
  # | true | true | true |
100
100
  # | false | false | true |
101
101
  raw_columns.select{|c| !required || c.required? }.
102
- select(&:ref_model).
103
- each_with_object({}){|c,d| d[c.name] = c.ref_model}
102
+ select(&:reference).
103
+ each_with_object({}){|c,d| d[c.reference.name] = c.ref_model }
104
104
  end
105
105
 
106
106
  def all_dependencies(required = true)
@@ -108,7 +108,7 @@ module ModelBase
108
108
  end
109
109
 
110
110
  def factory_girl_options
111
- dependencies.map{|attr, model| "#{attr.sub(/_id\z/, '')}: #{model.full_resource_name}"}
111
+ dependencies.map{|attr, model| "#{attr}: #{model.full_resource_name}" }
112
112
  end
113
113
 
114
114
  def factory_girl_create(extra = {})
@@ -1,3 +1,3 @@
1
1
  module ModelBase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  FactoryGirl.define do
2
2
  factory :<%= model.full_resource_name %> do
3
3
  <%- model.columns_for(:factory).each do |col| -%>
4
- <%- if col.ref_model -%>
5
- association :<%= col.name.sub(/_id\z/, '') %>, factory: :<%= col.ref_model.full_resource_name %>
4
+ <%- if col.reference -%>
5
+ association :<%= col.reference.name %>, factory: :<%= col.ref_model.full_resource_name %>
6
6
  <%- else -%>
7
- <%= col.name.sub(/_id\z/, '') %> <%= col.sample_value(context: :factory).inspect %>
7
+ <%= col.name %> <%= col.sample_value(context: :factory).inspect %>
8
8
  <%- end -%>
9
9
  <%- end -%>
10
10
  end
@@ -51,8 +51,6 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
51
51
  let(:invalid_parameters) {
52
52
  <%- if !required_data_attrs.empty? -%>
53
53
  valid_parameters.symbolize_keys.merge(<%= required_data_attrs.first.name %>: '')
54
- <%- elsif !required_ref_attrs.empty? -%>
55
- valid_parameters.symbolize_keys.merge(<%= required_ref_attrs.first.name %>_id: '')
56
54
  <%- else -%>
57
55
  skip("Add a hash of attributes invalid for your model")
58
56
  <%- end -%>
@@ -134,15 +132,11 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
134
132
  <%- required_data_attrs.each do |required_data_attr| -%>
135
133
  let(:new_<%= required_data_attr.name %>){ <%= required_data_attr.new_attribute_exp %> }
136
134
  <%- end -%>
137
- <%- elsif !required_ref_attrs.empty? -%>
138
- let(:another_<%= required_ref_attrs.last.name %>){ FactoryGirl.create(:<%= required_ref_attrs.last.name %><%= extra_attributes_for_factory %>) }
139
135
  <%- end -%>
140
136
 
141
137
  let(:new_parameters) {
142
138
  <%- if !required_data_attrs.empty? -%>
143
139
  valid_parameters.merge(<%= required_data_attrs.map{|attr| "#{attr.name}: new_#{attr.name}"}.join(', ') %>)
144
- <%- elsif !required_ref_attrs.empty? -%>
145
- valid_parameters.merge(<%= required_ref_attrs.last.name %>_id: another_<%= required_ref_attrs.last.name %>.id)
146
140
  <%- else required_data_attrs.empty? -%>
147
141
  skip("Add a hash of attributes valid for your model")
148
142
  <%- end -%>
@@ -156,8 +150,6 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
156
150
  <%- required_data_attrs.each do |attr| -%>
157
151
  expect(<%= file_name %>.<%= attr.name %>).to eq new_<%= attr.name %>
158
152
  <%- end -%>
159
- <%- elsif !required_ref_attrs.empty? -%>
160
- expect(<%= file_name %>.<%= required_ref_attrs.last.name %>_id).to eq another_<%= required_ref_attrs.last.name %>.id
161
153
  <%- else -%>
162
154
  skip("Add assertions for updated state")
163
155
  <%- end -%>
@@ -9,7 +9,7 @@ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
9
9
  <%- if tc = model.title_column -%>
10
10
  <%= model.factory_girl_create(tc.name.to_sym => tc.sample_value(model_index + 1)) %>,
11
11
  <%- else -%>
12
- <%= model.factory_girl_create %>
12
+ <%= model.factory_girl_create %>,
13
13
  <%- end -%>
14
14
  <% end -%>
15
15
  ])
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
@@ -142,6 +142,7 @@ files:
142
142
  - example/app/controllers/concerns/.keep
143
143
  - example/app/controllers/concerns/authentication.rb
144
144
  - example/app/controllers/issues_controller.rb
145
+ - example/app/controllers/project_assignments_controller.rb
145
146
  - example/app/controllers/projects_controller.rb
146
147
  - example/app/helpers/application_helper.rb
147
148
  - example/app/helpers/issues_helper.rb
@@ -153,9 +154,11 @@ files:
153
154
  - example/app/models/concerns/.keep
154
155
  - example/app/models/issue.rb
155
156
  - example/app/models/project.rb
157
+ - example/app/models/project_assignment.rb
156
158
  - example/app/models/user.rb
157
159
  - example/app/validations/ar_internal_metadatum_validation.rb
158
160
  - example/app/validations/issue_validation.rb
161
+ - example/app/validations/project_assignment_validation.rb
159
162
  - example/app/validations/project_validation.rb
160
163
  - example/app/validations/user_validation.rb
161
164
  - example/app/views/issues/_form.html.erb
@@ -167,6 +170,12 @@ files:
167
170
  - example/app/views/layouts/application.html.erb
168
171
  - example/app/views/layouts/mailer.html.erb
169
172
  - example/app/views/layouts/mailer.text.erb
173
+ - example/app/views/project_assignments/_form.html.erb
174
+ - example/app/views/project_assignments/_table.html.erb
175
+ - example/app/views/project_assignments/edit.html.erb
176
+ - example/app/views/project_assignments/index.html.erb
177
+ - example/app/views/project_assignments/new.html.erb
178
+ - example/app/views/project_assignments/show.html.erb
170
179
  - example/app/views/projects/_form.html.erb
171
180
  - example/app/views/projects/_table.html.erb
172
181
  - example/app/views/projects/edit.html.erb
@@ -215,12 +224,15 @@ files:
215
224
  - example/public/apple-touch-icon.png
216
225
  - example/public/favicon.ico
217
226
  - example/spec/controllers/issues_controller_spec.rb
227
+ - example/spec/controllers/project_assignments_controller_spec.rb
218
228
  - example/spec/controllers/projects_controller_spec.rb
219
229
  - example/spec/factories/issues.rb
230
+ - example/spec/factories/project_assignments.rb
220
231
  - example/spec/factories/projects.rb
221
232
  - example/spec/factories/users.rb
222
233
  - example/spec/rails_helper.rb
223
234
  - example/spec/routing/issues_routing_spec.rb
235
+ - example/spec/routing/project_assignments_routing_spec.rb
224
236
  - example/spec/routing/projects_routing_spec.rb
225
237
  - example/spec/spec_helper.rb
226
238
  - example/spec/support/controller_macros.rb
@@ -229,6 +241,10 @@ files:
229
241
  - example/spec/views/issues/index.html.erb_spec.rb
230
242
  - example/spec/views/issues/new.html.erb_spec.rb
231
243
  - example/spec/views/issues/show.html.erb_spec.rb
244
+ - example/spec/views/project_assignments/edit.html.erb_spec.rb
245
+ - example/spec/views/project_assignments/index.html.erb_spec.rb
246
+ - example/spec/views/project_assignments/new.html.erb_spec.rb
247
+ - example/spec/views/project_assignments/show.html.erb_spec.rb
232
248
  - example/spec/views/projects/edit.html.erb_spec.rb
233
249
  - example/spec/views/projects/index.html.erb_spec.rb
234
250
  - example/spec/views/projects/new.html.erb_spec.rb