eikes_scaffolding 0.0.1 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 748f10d1a65024e4c8f10b3dcf214249c754c0d8
4
- data.tar.gz: 42fb6b1363888025ddee104e09f5ef554f9edc04
3
+ metadata.gz: 521c24ce06ee6e0fb82d25da8450c33e9e9b3a84
4
+ data.tar.gz: c441f604baa32dd1ba885f78525c57863d2b4722
5
5
  SHA512:
6
- metadata.gz: f879a44640b0dd218ba9eb29b39c57448a7c528887596c1bfcda9a26b335230cfec076efa4063d973baadf921c1fc9eccd1315340134076d22300300764d4440
7
- data.tar.gz: d6b9f7265c7d4586ddc90cac319faa0660464b00dd0fee548cc9273e50589fbbb027b89f82bee7a6b5c2c24b65628c2d6cef7d648c427da1db702c2e77b95569
6
+ metadata.gz: 24e157d72798f122ae3fb4c1b6cb7b3c606b3226bc811d51cfb726550142e186c185f9618f73700f43f1e69112c082a537d0a1a03f2e7784206374f54b28d633
7
+ data.tar.gz: 2ff927ef485b4afee47b58944b1ab0c551dcbb10da2a69a1ec7f51aeb53f0ece5d191c0ea0ebe833ea7dc8a4747a7f015ea535f1daa7151d1f6ec557fec54957
@@ -0,0 +1,11 @@
1
+ namespace :eikes do
2
+ namespace :templates do
3
+ desc 'Copy eikes scaffolding templates to /lib/templates'
4
+ task :copy do
5
+ source_dir = File.join(Gem.loaded_specs['eikes_scaffolding'].full_gem_path, 'lib', 'templates')
6
+ destination_dir = Rails.root.join 'lib'
7
+ FileUtils.mkdir_p destination_dir
8
+ FileUtils.cp_r source_dir, destination_dir
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%- attributes.each do |attribute| -%>
6
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
+ <%- end -%>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,13 @@
1
+ <div class="page-header">
2
+ <%%= link_to <%= index_helper %>_path, class: 'btn btn-default' do %>
3
+ <span class="fa fa-list"></span>
4
+ Back
5
+ <%% end %>
6
+ <%%= link_to @<%= singular_table_name %>, class: 'btn btn-primary' do %>
7
+ <span class="fa fa-info-circle"></span>
8
+ Show
9
+ <%% end %>
10
+ <h1>Editing <%= human_name %></h1>
11
+ </div>
12
+
13
+ <%%= render 'form' %>
@@ -0,0 +1,35 @@
1
+ <div class="page-header">
2
+ <%%= link_to new_<%= singular_table_name %>_path, class: 'btn btn-primary' do %>
3
+ <span class="fa fa-plus-circle"></span>
4
+ New <%= human_name %>
5
+ <%% end %>
6
+ <h1>Listing <%= plural_name.humanize %></h1>
7
+ </div>
8
+
9
+ <div class="table-responsive">
10
+ <table class="table table-striped table-bordered table-hover">
11
+ <thead>
12
+ <tr>
13
+ <% attributes.each do |attribute| -%>
14
+ <th><%= attribute.human_name %></th>
15
+ <% end -%>
16
+ <th></th>
17
+ <th></th>
18
+ <th></th>
19
+ </tr>
20
+ </thead>
21
+
22
+ <tbody>
23
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
24
+ <tr>
25
+ <% attributes.each do |attribute| -%>
26
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
27
+ <% end -%>
28
+ <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
29
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
30
+ <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
31
+ </tr>
32
+ <%% end %>
33
+ </tbody>
34
+ </table>
35
+ </div>
@@ -0,0 +1,9 @@
1
+ <div class="page-header">
2
+ <%%= link_to <%= index_helper %>_path, class: 'btn btn-default' do %>
3
+ <span class="fa fa-list"></span>
4
+ Back
5
+ <%% end %>
6
+ <h1>New <%= human_name %></h1>
7
+ </div>
8
+
9
+ <%%= render 'form' %>
@@ -0,0 +1,19 @@
1
+ <div class="page-header">
2
+ <%%= link_to <%= index_helper %>_path, class: 'btn btn-default' do %>
3
+ <span class="fa fa-list"></span>
4
+ Back
5
+ <%% end %>
6
+ <%%= link_to edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'btn btn-primary' do %>
7
+ <span class="fa fa-pencil-square-o"></span>
8
+ Edit
9
+ <%% end %>
10
+ <h1>Show <%= human_name %></h1>
11
+ </div>
12
+
13
+ <dl class="dl-horizontal">
14
+ <%- attributes.each do |attribute| -%>
15
+ <dt><%= attribute.human_name %>:</dt>
16
+ <dd><%%= @<%= singular_table_name %>.<%= attribute.name %> %></dd>
17
+
18
+ <%- end -%>
19
+ </dl>
@@ -0,0 +1,150 @@
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
+ <% module_namespacing do -%>
22
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
23
+
24
+ let!(:<%= file_name %>) { Fabricate(:<%= file_name %>) }
25
+
26
+ let(:valid_attributes) { Fabricate.attributes_for(:<%= file_name %>) }
27
+
28
+ let(:invalid_attributes) {
29
+ skip("Add a hash of attributes invalid for your model")
30
+ }
31
+
32
+ # This should return the minimal set of values that should be in the session
33
+ # in order to pass any filters (e.g. authentication) defined in
34
+ # <%= controller_class_name %>Controller. Be sure to keep this updated too.
35
+ let(:valid_session) { {} }
36
+
37
+ <% unless options[:singleton] -%>
38
+ describe "GET #index" do
39
+ it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
40
+ get :index, {}, valid_session
41
+ expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
42
+ end
43
+ end
44
+
45
+ <% end -%>
46
+ describe "GET #show" do
47
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
48
+ get :show, { id: <%= file_name %>.to_param }, valid_session
49
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
50
+ end
51
+ end
52
+
53
+ describe "GET #new" do
54
+ it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
55
+ get :new, {}, valid_session
56
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
57
+ end
58
+ end
59
+
60
+ describe "GET #edit" do
61
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
62
+ get :edit, { id: <%= file_name %>.to_param }, valid_session
63
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
64
+ end
65
+ end
66
+
67
+ describe "POST #create" do
68
+ context "with valid params" do
69
+ it "creates a new <%= class_name %>" do
70
+ expect {
71
+ post :create, {<%= ns_file_name %>: valid_attributes }, valid_session
72
+ }.to change(<%= class_name %>, :count).by(1)
73
+ end
74
+
75
+ it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
76
+ post :create, {<%= ns_file_name %>: valid_attributes }, valid_session
77
+ expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
78
+ expect(assigns(:<%= ns_file_name %>)).to be_persisted
79
+ end
80
+
81
+ it "redirects to the created <%= ns_file_name %>" do
82
+ post :create, {<%= ns_file_name %>: valid_attributes }, valid_session
83
+ expect(response).to redirect_to(<%= class_name %>.last)
84
+ end
85
+ end
86
+
87
+ context "with invalid params" do
88
+ it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
89
+ post :create, {<%= ns_file_name %>: invalid_attributes }, valid_session
90
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
91
+ end
92
+
93
+ it "re-renders the 'new' template" do
94
+ post :create, {<%= ns_file_name %>: invalid_attributes }, valid_session
95
+ expect(response).to render_template("new")
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "PUT #update" do
101
+ context "with valid params" do
102
+ let(:new_attributes) {
103
+ skip("Add a hash of attributes valid for your model")
104
+ }
105
+
106
+ it "updates the requested <%= ns_file_name %>" do
107
+ put :update, { id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes }, valid_session
108
+ <%= file_name %>.reload
109
+ skip("Add assertions for updated state")
110
+ end
111
+
112
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
113
+ put :update, { id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes }, valid_session
114
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
115
+ end
116
+
117
+ it "redirects to the <%= ns_file_name %>" do
118
+ put :update, { id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes }, valid_session
119
+ expect(response).to redirect_to(<%= file_name %>)
120
+ end
121
+ end
122
+
123
+ context "with invalid params" do
124
+ it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
125
+ put :update, { id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes }, valid_session
126
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
127
+ end
128
+
129
+ it "re-renders the 'edit' template" do
130
+ put :update, { id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes }, valid_session
131
+ expect(response).to render_template("edit")
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "DELETE #destroy" do
137
+ it "destroys the requested <%= ns_file_name %>" do
138
+ expect {
139
+ delete :destroy, { id: <%= file_name %>.to_param }, valid_session
140
+ }.to change(<%= class_name %>, :count).by(-1)
141
+ end
142
+
143
+ it "redirects to the <%= table_name %> list" do
144
+ delete :destroy, { id: <%= file_name %>.to_param }, valid_session
145
+ expect(response).to redirect_to(<%= index_helper %>_url)
146
+ end
147
+ end
148
+
149
+ end
150
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, Fabricate(:<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders the edit <%= ns_file_name %> form" do
10
+ render
11
+
12
+ assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
13
+ <% for attribute in output_attributes -%>
14
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
15
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
16
+ <% end -%>
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ assign(:<%= table_name %>, Fabricate.times(2, :<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders a list of <%= ns_table_name %>" do
10
+ render
11
+ <% for attribute in output_attributes -%>
12
+ assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, :count => 2
13
+ <% end -%>
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, Fabricate.build(:<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders new <%= ns_file_name %> form" do
10
+ render
11
+
12
+ assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
13
+ <% for attribute in output_attributes -%>
14
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
15
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
16
+ <% end -%>
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require "rails_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
5
+ describe "routing" do
6
+
7
+ <% unless options[:singleton] -%>
8
+ it "routes to #index" do
9
+ expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
10
+ end
11
+
12
+ <% end -%>
13
+ it "routes to #new" do
14
+ expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
15
+ end
16
+
17
+ it "routes to #show" do
18
+ expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
19
+ end
20
+
21
+ it "routes to #edit" do
22
+ expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
23
+ end
24
+
25
+ it "routes to #create" do
26
+ expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
27
+ end
28
+
29
+ it "routes to #update via PUT" do
30
+ expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
31
+ end
32
+
33
+ <% if Rails::VERSION::STRING > '4' -%>
34
+ it "routes to #update via PATCH" do
35
+ expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
36
+ end
37
+
38
+ <% end -%>
39
+ it "routes to #destroy" do
40
+ expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
41
+ end
42
+
43
+ end
44
+ end
45
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, Fabricate(:<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders attributes in <p>" do
10
+ render
11
+ <% for attribute in output_attributes -%>
12
+ expect(rendered).to match(/<%= raw_value_for(attribute) %>/)
13
+ <% end -%>
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eikes_scaffolding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eike Send
@@ -18,6 +18,18 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/eikes_scaffolding.rb
20
20
  - lib/eikes_scaffolding/railtie.rb
21
+ - lib/tasks/copy_templates.rake
22
+ - lib/templates/erb/scaffold/_form.html.erb
23
+ - lib/templates/erb/scaffold/edit.html.erb
24
+ - lib/templates/erb/scaffold/index.html.erb
25
+ - lib/templates/erb/scaffold/new.html.erb
26
+ - lib/templates/erb/scaffold/show.html.erb
27
+ - lib/templates/rspec/scaffold/controller_spec.rb
28
+ - lib/templates/rspec/scaffold/edit_spec.rb
29
+ - lib/templates/rspec/scaffold/index_spec.rb
30
+ - lib/templates/rspec/scaffold/new_spec.rb
31
+ - lib/templates/rspec/scaffold/routing_spec.rb
32
+ - lib/templates/rspec/scaffold/show_spec.rb
21
33
  homepage: http://github.com/eikes/eikes_scaffolding
22
34
  licenses:
23
35
  - MIT
@@ -41,5 +53,5 @@ rubyforge_project:
41
53
  rubygems_version: 2.4.6
42
54
  signing_key:
43
55
  specification_version: 4
44
- summary: An opionionated set rails scaffolding templates
56
+ summary: An opionionated set of rails scaffolding templates
45
57
  test_files: []