ceo 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/admin/admin_controller.rb +24 -7
- data/app/views/admin/index.html.erb +16 -11
- data/lib/ceo/version.rb +1 -1
- data/lib/generators/admin/USAGE +11 -0
- data/lib/generators/admin/admin_generator.rb +28 -0
- data/lib/generators/admin/templates/admin_page_controller.rb.erb +5 -0
- data/test/ceo/index_apple_test.rb +59 -5
- data/test/dummy/log/development.log +7 -0
- data/test/dummy/log/test.log +149671 -0
- data/test/test_helper.rb +8 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fe4507acb62425bac279534c26165ad40ea9680
|
4
|
+
data.tar.gz: 81da4b3f285fdfc004af84b2282f41761e0623d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88770460906957b449ee82e101d41872045102dd73eeb6cd2b75fc764eb944eae6de788d99ac0452aea4e0b3cb14d9551d462e3943adae53f8ef7c1e59af1201
|
7
|
+
data.tar.gz: 9bdf1ac39832693cd2fa520ed77aaab8f5d2cd5df92d003bc2d607b0af07bd0374b900719f5ef548582f9f06e50dfce43521e2b1840609028909d32ba4be9510
|
data/README.md
CHANGED
@@ -2,9 +2,9 @@ CEO
|
|
2
2
|
---
|
3
3
|
|
4
4
|
> Your app's chief executive.
|
5
|
+
|
5
6
|
[![Dependency Status](http://img.shields.io/gemnasium/littlelines/ceo.svg)](https://gemnasium.com/littlelines/ceo)
|
6
7
|
[![Gem Version](http://img.shields.io/gem/v/ceo.svg)](https://rubygems.org/gems/ceo)
|
7
8
|
[![License](http://img.shields.io/:license-mit-blue.svg)](http://littlelines.mit-license.org)
|
8
9
|
[![Build Status](https://travis-ci.org/littlelines/ceo.svg?branch=master)](https://travis-ci.org/littlelines/ceo)
|
9
10
|
[![Code Climate](https://codeclimate.com/github/littlelines/ceo/badges/gpa.svg)](https://codeclimate.com/github/littlelines/ceo)
|
10
|
-
|
@@ -166,7 +166,7 @@ class Admin::AdminController < ApplicationController
|
|
166
166
|
# Returns the path of the thing.
|
167
167
|
def thing_path(model, object)
|
168
168
|
id = object['ID'] || object['id']
|
169
|
-
send(:"admin_#{model
|
169
|
+
send(:"admin_#{undersingularize(model)}_path", id: id)
|
170
170
|
end
|
171
171
|
|
172
172
|
# Private: Returns the index path of a model.
|
@@ -176,7 +176,7 @@ class Admin::AdminController < ApplicationController
|
|
176
176
|
# Returns the path of many things.
|
177
177
|
def things_path(object = nil)
|
178
178
|
object ||= @route_name || controller_name
|
179
|
-
send(:"admin_#{object
|
179
|
+
send(:"admin_#{underpluralize(object)}_path")
|
180
180
|
end
|
181
181
|
|
182
182
|
# Private
|
@@ -187,7 +187,7 @@ class Admin::AdminController < ApplicationController
|
|
187
187
|
# Returns the edit path of a model.
|
188
188
|
def edit_thing_path(model, object)
|
189
189
|
id = object['ID'] || object['id']
|
190
|
-
send(:"edit_admin_#{model}_path", id: id)
|
190
|
+
send(:"edit_admin_#{undersingularize(model)}_path", id: id)
|
191
191
|
end
|
192
192
|
|
193
193
|
# Private
|
@@ -196,9 +196,8 @@ class Admin::AdminController < ApplicationController
|
|
196
196
|
# object - An instance of a model.
|
197
197
|
#
|
198
198
|
# Returns the new path of a model.
|
199
|
-
def new_thing_path(model
|
200
|
-
|
201
|
-
send(:"new_admin_#{model}_path", id: id)
|
199
|
+
def new_thing_path(model)
|
200
|
+
send(:"new_admin_#{undersingularize(model)}_path")
|
202
201
|
end
|
203
202
|
|
204
203
|
# Private
|
@@ -208,6 +207,24 @@ class Admin::AdminController < ApplicationController
|
|
208
207
|
#
|
209
208
|
# Returns the paginated path of an object.
|
210
209
|
def thing_page_path(model, page)
|
211
|
-
send(:"page_admin_#{model
|
210
|
+
send(:"page_admin_#{underpluralize(model)}_path", page: page)
|
211
|
+
end
|
212
|
+
|
213
|
+
# Private
|
214
|
+
#
|
215
|
+
# noun - Something to underpluralize. (String)
|
216
|
+
#
|
217
|
+
# Returns an underscored and pluralized string.
|
218
|
+
def underpluralize(noun)
|
219
|
+
noun.to_s.underscore.pluralize.downcase
|
220
|
+
end
|
221
|
+
|
222
|
+
# Private
|
223
|
+
#
|
224
|
+
# noun - Something to undersingularize. (String)
|
225
|
+
#
|
226
|
+
# Returns an underscored and singularized string.
|
227
|
+
def undersingularize(noun)
|
228
|
+
noun.to_s.underscore.singularize.downcase
|
212
229
|
end
|
213
230
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
<h1><%= @title %></h1>
|
2
2
|
|
3
|
+
<div>
|
4
|
+
<p><%= link_to "New #{@title.singularize}", new_thing_path(@model_name), id: "new-#{@model_name}" %></p>
|
5
|
+
<p><%= "There are no #{@human_model.downcase.pluralize} in the database." if @things.blank? %></p>
|
6
|
+
</div>
|
7
|
+
|
3
8
|
<table>
|
4
9
|
<thead>
|
5
10
|
<tr>
|
6
|
-
<%
|
7
|
-
<%= "There are no #{@human_model.downcase.pluralize} in the database." %>
|
8
|
-
<% else %>
|
11
|
+
<% unless @things.blank? %>
|
9
12
|
<% @things.first.each_key do |heading| %>
|
10
13
|
<th>
|
11
14
|
<%= heading %>
|
@@ -17,15 +20,15 @@
|
|
17
20
|
|
18
21
|
<tbody>
|
19
22
|
<% @things.each do |thing| %>
|
20
|
-
<tr>
|
23
|
+
<tr id="#{@controller_name}-#{thing.id}">
|
21
24
|
<% thing.each do |heading, value| %>
|
22
25
|
<td label="<%= heading %>: ">
|
23
26
|
<%= value %>
|
24
27
|
</td>
|
25
28
|
|
26
29
|
<div class="actions">
|
27
|
-
<td><%= link_to("Edit
|
28
|
-
<td><%= link_to("Show
|
30
|
+
<td><%= link_to("Edit", edit_thing_path(@model_name, thing)) %></td>
|
31
|
+
<td><%= link_to("Show", thing_path(@model_name, thing)) %></td>
|
29
32
|
</div>
|
30
33
|
<% end %>
|
31
34
|
</tr>
|
@@ -35,28 +38,30 @@
|
|
35
38
|
|
36
39
|
<nav class="navigation" role="navigation">
|
37
40
|
<ul>
|
38
|
-
<%
|
41
|
+
<% if @page == 1 %>
|
42
|
+
<li><a>1</a></li>
|
43
|
+
<% else %>
|
39
44
|
<!-- First Page -->
|
40
45
|
<li>
|
41
46
|
<%= link_to('1', thing_page_path(@model_name, @page - 1)) %>
|
42
47
|
</li>
|
43
48
|
<% end %>
|
44
49
|
|
45
|
-
<% if @page >
|
50
|
+
<% if @page.to_i > 2 %>
|
46
51
|
<!-- Previous Page -->
|
47
52
|
<li>
|
48
|
-
<%= link_to("#{page - 1}", thing_page_path(@model_name, @page - 1)) %>
|
53
|
+
<%= link_to("#{@page - 1}", thing_page_path(@model_name, @page - 1)) %>
|
49
54
|
</li>
|
50
55
|
<% end %>
|
51
56
|
|
52
|
-
<% unless @
|
57
|
+
<% unless @page == 1 %>
|
53
58
|
<!-- Current Page -->
|
54
59
|
<li>
|
55
60
|
<a><%= @page %></a>
|
56
61
|
</li>
|
57
62
|
<% end %>
|
58
63
|
|
59
|
-
<% if @page < @total_pages %>
|
64
|
+
<% if @page < @total_pages && @page + 1 < @total_pages %>
|
60
65
|
<!-- Next Page -->
|
61
66
|
<li>
|
62
67
|
<%= link_to("#{@page + 1}", thing_page_path(@model_name, @page + 1)) %>
|
data/lib/ceo/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
# Public: Generator for admin page controllers.
|
4
|
+
class AdminGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def create_admin_page_controller
|
8
|
+
@controller = file_name
|
9
|
+
template(
|
10
|
+
'admin_page_controller.rb.erb',
|
11
|
+
"app/controllers/admin/#{@controller.underscore}_controller.rb"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_admin_route
|
16
|
+
route "admin_for :#{@controller.underscore}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_form_view
|
20
|
+
unless Dir.exist?(Rails.root.join('app/views/admin'))
|
21
|
+
Dir.mkdir(Rails.root.join('app/views/admin'))
|
22
|
+
end
|
23
|
+
|
24
|
+
create_file "app/views/admin/#{@controller.underscore}/_form.html.erb", <<VIEW
|
25
|
+
<% # "f" is exposed as a form object %>
|
26
|
+
VIEW
|
27
|
+
end
|
28
|
+
end
|
@@ -1,24 +1,35 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'Apple admin pages' do
|
4
4
|
include TestHelper
|
5
|
+
|
5
6
|
describe 'index' do
|
6
7
|
before do
|
8
|
+
30.times { Apple.create }
|
7
9
|
admin_page '/apples'
|
8
10
|
end
|
9
11
|
|
12
|
+
it 'should not error when there are no apples' do
|
13
|
+
Apple.delete_all
|
14
|
+
admin_page '/apples'
|
15
|
+
|
16
|
+
assert_equal 0, Apple.count
|
17
|
+
expected_text = 'There are no apples in the database.'
|
18
|
+
assert page.has_css?('p', text: expected_text)
|
19
|
+
end
|
20
|
+
|
10
21
|
describe 'correct attributes' do
|
11
22
|
let(:attributes) { Apple.new.attributes.keys }
|
12
|
-
let(:headers) { page.all('table thead th') }
|
13
23
|
|
14
24
|
it 'should have the right number of headers' do
|
25
|
+
headers = page.all('table thead th')
|
15
26
|
assert_equal attributes.size, headers.size
|
16
27
|
end
|
17
28
|
|
18
29
|
it 'should have the right header names' do
|
19
|
-
page.has_css?('table thead tr th', text: 'ID')
|
20
|
-
page.has_css?('table thead tr th', text: 'Name')
|
21
|
-
page.has_css?('table thead tr th', text: 'Fruit')
|
30
|
+
assert page.has_css?('table thead tr th', text: 'ID')
|
31
|
+
assert page.has_css?('table thead tr th', text: 'Name')
|
32
|
+
assert page.has_css?('table thead tr th', text: 'Fruit')
|
22
33
|
end
|
23
34
|
|
24
35
|
it 'should have all IDs shown' do
|
@@ -27,5 +38,48 @@ describe 'apples admin pages' do
|
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|
41
|
+
|
42
|
+
it 'it should include a new button' do
|
43
|
+
el = page.find('a#new-apple')
|
44
|
+
assert_equal '/admin/apples/new', el['href']
|
45
|
+
assert_equal 'New Apple', el.text
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'pagination' do
|
49
|
+
it 'shows 20 apples per page' do
|
50
|
+
assert_equal 20, page.all('table tbody tr').size
|
51
|
+
refute_equal 20, Apple.count
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'pagination links' do
|
55
|
+
describe 'first page' do
|
56
|
+
it 'should have a disabled link' do
|
57
|
+
el = page.find('nav ul li a', text: '1')
|
58
|
+
assert_equal '1', el.text
|
59
|
+
assert el['href'].nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should have a link to the next page' do
|
63
|
+
el = page.find('nav ul li a', text: '2')
|
64
|
+
assert_equal '/admin/apples/page/2', el['href']
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'second page' do
|
69
|
+
before { visit '/admin/apples/page/2' }
|
70
|
+
|
71
|
+
it 'should have a disabled link' do
|
72
|
+
el = page.find('nav ul li a', text: '2')
|
73
|
+
assert_equal '2', el.text
|
74
|
+
assert el['href'].nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should have a first page button' do
|
78
|
+
el = page.find('nav ul li a', text: '1')
|
79
|
+
assert_equal '/admin/apples/page/1', el['href']
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
30
84
|
end
|
31
85
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
[1m[36mApple Load (2.4ms)[0m [1mSELECT "apples".* FROM "apples" ORDER BY "apples"."id" ASC LIMIT 1[0m
|
2
|
+
[1m[35m (0.1ms)[0m BEGIN
|
3
|
+
[1m[36mSQL (8.7ms)[0m [1mINSERT INTO "apples" DEFAULT VALUES RETURNING "id"[0m
|
4
|
+
[1m[35m (0.5ms)[0m COMMIT
|
5
|
+
[1m[36mApple Load (0.5ms)[0m [1mSELECT "apples".* FROM "apples" ORDER BY "apples"."id" ASC LIMIT 1[0m
|
6
|
+
[1m[35mApple Load (0.5ms)[0m SELECT "apples".* FROM "apples" ORDER BY "apples"."id" ASC LIMIT 1
|
7
|
+
[1m[36mApple Load (0.4ms)[0m [1mSELECT "apples".* FROM "apples" ORDER BY "apples"."id" ASC LIMIT 1[0m
|