admin_view 0.3.0 → 0.4.0
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.
- data/README.md +4 -0
- data/lib/admin_view/version.rb +1 -1
- data/lib/generators/admin_view_generator.rb +1 -0
- data/lib/generators/templates/base_controller_spec.rb +12 -6
- data/lib/generators/templates/controller.rb +11 -2
- data/lib/generators/templates/controller_spec.rb +34 -32
- data/lib/generators/templates/views/index.html.erb +2 -2
- data/lib/generators/templates/views/show.html.erb +4 -4
- metadata +26 -16
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -33,6 +33,10 @@ Yes! Feel free to fork the repo, make your changes in a topic branch and send us
|
|
33
33
|
|
34
34
|
If you're having a problem or found a bug, please open an issue in the GitHub [issue tracker](https://github.com/renderedtext/admin_view/issues).
|
35
35
|
|
36
|
+
## Credits
|
37
|
+
|
38
|
+
Big thank you to all [the contributors](https://github.com/renderedtext/admin_view/graphs/contributors)!
|
39
|
+
|
36
40
|
## License
|
37
41
|
|
38
42
|
Copyright © 2011-2014 [Rendered Text](http://renderedtext.com). admin_view is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/lib/admin_view/version.rb
CHANGED
@@ -26,6 +26,7 @@ class AdminViewGenerator < Rails::Generators::NamedBase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def create_controller
|
29
|
+
@attributes_symbols = get_model_columns.dup.delete_if {|attribute| ['id', 'created_at', 'updated_at'].include? attribute.name }.collect {|attribute| ":#{attribute.name}" }
|
29
30
|
template "controller.rb", File.join("app/controllers/admin", "#{controller_file_name}_controller.rb")
|
30
31
|
end
|
31
32
|
|
@@ -8,8 +8,10 @@ describe Admin::BaseController do
|
|
8
8
|
|
9
9
|
it "renders index page" do
|
10
10
|
controller.stub_chain(:current_user, :admin?).and_return(true)
|
11
|
+
|
11
12
|
get :index
|
12
|
-
|
13
|
+
|
14
|
+
expect(response).to render_template('index')
|
13
15
|
end
|
14
16
|
|
15
17
|
end
|
@@ -18,9 +20,11 @@ describe Admin::BaseController do
|
|
18
20
|
|
19
21
|
it "renders 404" do
|
20
22
|
controller.stub_chain(:current_user, :admin?).and_return(false)
|
23
|
+
|
21
24
|
get :index
|
22
|
-
|
23
|
-
response.
|
25
|
+
|
26
|
+
expect(response).to render_template('404.html')
|
27
|
+
expect(response.response_code).to eql(404)
|
24
28
|
end
|
25
29
|
|
26
30
|
end
|
@@ -28,10 +32,12 @@ describe Admin::BaseController do
|
|
28
32
|
context "not logged in" do
|
29
33
|
|
30
34
|
it "renders 404" do
|
31
|
-
controller.
|
35
|
+
allow(controller).to receive(:current_user).and_return(nil)
|
36
|
+
|
32
37
|
get :index
|
33
|
-
|
34
|
-
response.
|
38
|
+
|
39
|
+
expect(response).to render_template('404.html')
|
40
|
+
expect(response.response_code).to eql(404)
|
35
41
|
end
|
36
42
|
|
37
43
|
end
|
@@ -15,7 +15,7 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def create
|
18
|
-
@<%= singular_table_name %> = <%= class_name %>.new(
|
18
|
+
@<%= singular_table_name %> = <%= class_name %>.new(<%= singular_table_name %>_params)
|
19
19
|
if @<%= singular_table_name %>.save
|
20
20
|
redirect_to admin_<%= plural_table_name %>_path, :notice => "Successfully created <%= human_name.downcase %>."
|
21
21
|
else
|
@@ -32,7 +32,7 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def update
|
35
|
-
if @<%= singular_table_name %>.update_attributes(
|
35
|
+
if @<%= singular_table_name %>.update_attributes(<%= singular_table_name %>_params)
|
36
36
|
redirect_to admin_<%= plural_table_name %>_path, :notice => "Successfully updated <%= human_name.downcase %>."
|
37
37
|
else
|
38
38
|
render :edit
|
@@ -64,4 +64,13 @@ class Admin::<%= controller_class_name %>Controller < Admin::BaseController
|
|
64
64
|
%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
|
65
65
|
end
|
66
66
|
|
67
|
+
<% unless options[:read_only] -%>
|
68
|
+
private
|
69
|
+
|
70
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
71
|
+
def <%= singular_table_name %>_params
|
72
|
+
params.require(:<%= singular_table_name %>).permit(<%= @attributes_symbols.join(",") %>)
|
73
|
+
end
|
74
|
+
<% end -%>
|
75
|
+
|
67
76
|
end
|
@@ -4,34 +4,36 @@ describe Admin::<%= controller_class_name %>Controller do
|
|
4
4
|
|
5
5
|
def mock_<%= singular_table_name %>(stubs={})
|
6
6
|
(@mock_<%= singular_table_name %> ||= mock_model(<%= class_name %>).as_null_object).tap do |<%= singular_table_name %>|
|
7
|
-
|
7
|
+
stubs.each_key do |method_name|
|
8
|
+
allow(<%= singular_table_name %>).to receive(method_name).and_return(stubs[method_name])
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
|
-
before { controller.
|
13
|
+
before { allow(controller).to receive(:require_admin) }
|
12
14
|
|
13
15
|
describe "GET index" do
|
14
16
|
it "assigns all <%= plural_table_name %> as @<%= plural_table_name %>" do
|
15
|
-
controller.
|
17
|
+
allow(controller).to receive(:find_<%= plural_table_name %>).and_return([mock_<%= singular_table_name %>])
|
16
18
|
get :index
|
17
|
-
assigns(:<%= plural_table_name %>).
|
19
|
+
expect(assigns(:<%= plural_table_name %>)).to eq([mock_<%= singular_table_name %>])
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
describe "GET show" do
|
22
24
|
it "assigns the requested <%= singular_table_name %> as @<%=singular_table_name %>" do
|
23
|
-
<%= class_name
|
25
|
+
allow(<%= class_name %>).to receive(:find).with("37") { mock_<%= singular_table_name %> }
|
24
26
|
get :show, :id => "37"
|
25
|
-
assigns(:<%= singular_table_name %>).
|
27
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
<% unless options[:no_create] or options[:read_only] %>
|
30
32
|
describe "GET new" do
|
31
33
|
it "assigns a new <%= singular_table_name %> as @<%= singular_table_name %>" do
|
32
|
-
<%= class_name
|
34
|
+
allow(<%= class_name %>).to receive(:new) { mock_<%= singular_table_name %> }
|
33
35
|
get :new
|
34
|
-
assigns(:<%= singular_table_name %>).
|
36
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -39,29 +41,29 @@ describe Admin::<%= controller_class_name %>Controller do
|
|
39
41
|
|
40
42
|
describe "with valid params" do
|
41
43
|
it "assigns a newly created <%= singular_table_name %> as @<%= singular_table_name %>" do
|
42
|
-
<%= class_name
|
44
|
+
allow(<%= class_name %>).to receive(:new).with({'these' => 'params'}) { mock_<%= singular_table_name %>(:save => true) }
|
43
45
|
post :create, :<%= singular_table_name %> => {'these' => 'params'}
|
44
|
-
assigns(:<%= singular_table_name %>).
|
46
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
45
47
|
end
|
46
48
|
|
47
49
|
it "redirects to the created <%= singular_table_name %>" do
|
48
|
-
<%= class_name
|
50
|
+
allow(<%= class_name %>).to receive(:new) { mock_<%= singular_table_name %>(:save => true) }
|
49
51
|
post :create, :<%= singular_table_name %> => {}
|
50
|
-
response.
|
52
|
+
expect(response).to redirect_to(admin_<%= plural_table_name %>_url)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
56
|
describe "with invalid params" do
|
55
57
|
it "assigns a newly created but unsaved <%= singular_table_name %> as @<%= singular_table_name %>" do
|
56
|
-
<%= class_name
|
58
|
+
allow(<%= class_name %>).to receive(:new).with({'these' => 'params'}) { mock_<%= singular_table_name %>(:save => false) }
|
57
59
|
post :create, :<%= singular_table_name %> => {'these' => 'params'}
|
58
|
-
assigns(:<%= singular_table_name %>).
|
60
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
59
61
|
end
|
60
62
|
|
61
63
|
it "re-renders the 'new' template" do
|
62
|
-
<%= class_name
|
64
|
+
allow(<%= class_name %>).to receive(:new) { mock_<%= singular_table_name %>(:save => false) }
|
63
65
|
post :create, :<%= singular_table_name %> => {}
|
64
|
-
response.
|
66
|
+
expect(response).to render_template("new")
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
@@ -71,9 +73,9 @@ describe Admin::<%= controller_class_name %>Controller do
|
|
71
73
|
<% unless options[:read_only] %>
|
72
74
|
describe "GET edit" do
|
73
75
|
it "assigns the requested <%= singular_table_name %> as @<%= singular_table_name %>" do
|
74
|
-
<%= class_name
|
76
|
+
allow(<%= class_name %>).to receive(:find).with("37") { mock_<%= singular_table_name %> }
|
75
77
|
get :edit, :id => "37"
|
76
|
-
assigns(:<%= singular_table_name %>).
|
78
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -81,35 +83,35 @@ describe Admin::<%= controller_class_name %>Controller do
|
|
81
83
|
|
82
84
|
describe "with valid params" do
|
83
85
|
it "updates the requested <%= singular_table_name %>" do
|
84
|
-
<%= class_name
|
85
|
-
mock_<%= singular_table_name
|
86
|
+
expect(<%= class_name %>).to receive(:find).with("37") { mock_<%= singular_table_name %> }
|
87
|
+
expect(mock_<%= singular_table_name %>).to receive(:update_attributes).with({'these' => 'params'})
|
86
88
|
put :update, :id => "37", :<%= singular_table_name %> => {'these' => 'params'}
|
87
89
|
end
|
88
90
|
|
89
91
|
it "assigns the requested <%= singular_table_name %> as @<%= singular_table_name %>" do
|
90
|
-
<%= class_name
|
92
|
+
allow(<%= class_name %>).to receive(:find) { mock_<%= singular_table_name %>(:update_attributes => true) }
|
91
93
|
put :update, :id => "1"
|
92
|
-
assigns(:<%= singular_table_name %>).
|
94
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
93
95
|
end
|
94
96
|
|
95
97
|
it "redirects to the <%= singular_table_name %>" do
|
96
|
-
<%= class_name
|
98
|
+
allow(<%= class_name %>).to receive(:find) { mock_<%= singular_table_name %>(:update_attributes => true) }
|
97
99
|
put :update, :id => "1"
|
98
|
-
response.
|
100
|
+
expect(response).to redirect_to(admin_<%= plural_table_name %>_url)
|
99
101
|
end
|
100
102
|
end
|
101
103
|
|
102
104
|
describe "with invalid params" do
|
103
105
|
it "assigns the <%= singular_table_name %> as @<%= singular_table_name %>" do
|
104
|
-
<%= class_name
|
106
|
+
allow(<%= class_name %>).to receive(:find) { mock_<%= singular_table_name %>(:update_attributes => false) }
|
105
107
|
put :update, :id => "1"
|
106
|
-
assigns(:<%= singular_table_name %>).
|
108
|
+
expect(assigns(:<%= singular_table_name %>)).to be(mock_<%= singular_table_name %>)
|
107
109
|
end
|
108
110
|
|
109
111
|
it "re-renders the 'edit' template" do
|
110
|
-
<%= class_name
|
112
|
+
allow(<%= class_name %>).to receive(:find) { mock_<%= singular_table_name %>(:update_attributes => false) }
|
111
113
|
put :update, :id => "1"
|
112
|
-
response.
|
114
|
+
expect(response).to render_template("edit")
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
@@ -118,15 +120,15 @@ describe Admin::<%= controller_class_name %>Controller do
|
|
118
120
|
|
119
121
|
describe "DELETE destroy" do
|
120
122
|
it "destroys the requested <%= singular_table_name %>" do
|
121
|
-
<%= class_name
|
122
|
-
mock_<%= singular_table_name
|
123
|
+
expect(<%= class_name %>).to receive(:find).with("37") { mock_<%= singular_table_name %> }
|
124
|
+
expect(mock_<%= singular_table_name %>).to receive(:destroy)
|
123
125
|
delete :destroy, :id => "37"
|
124
126
|
end
|
125
127
|
|
126
128
|
it "redirects to the <%= plural_table_name %> list" do
|
127
|
-
<%= class_name
|
129
|
+
allow(<%= class_name %>).to receive(:find) { mock_<%= singular_table_name %> }
|
128
130
|
delete :destroy, :id => "1"
|
129
|
-
response.
|
131
|
+
expect(response).to redirect_to(admin_<%= plural_table_name %>_url)
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
@@ -24,8 +24,8 @@
|
|
24
24
|
<% end -%>
|
25
25
|
<% unless options[:read_only] -%>
|
26
26
|
<th>Edit</th>
|
27
|
-
<% end -%>
|
28
27
|
<th>Delete</th>
|
28
|
+
<% end -%>
|
29
29
|
</tr>
|
30
30
|
</thead>
|
31
31
|
<tbody>
|
@@ -38,8 +38,8 @@
|
|
38
38
|
<% end -%>
|
39
39
|
<% unless options[:read_only] -%>
|
40
40
|
<td><%%= link_to('Edit', edit_admin_<%= singular_table_name %>_path(<%= singular_table_name %>)) %></td>
|
41
|
-
<% end -%>
|
42
41
|
<td><%%= link_to('Delete', admin_<%= singular_table_name %>_path(<%= singular_table_name %>), :confirm => "Are you sure?", :method => :delete) %></td>
|
42
|
+
<% end -%>
|
43
43
|
</tr>
|
44
44
|
<%% end %>
|
45
45
|
</tbody>
|
@@ -11,14 +11,14 @@
|
|
11
11
|
<td><%%= @<%= singular_table_name %>.<%= attribute.name %> %></td>
|
12
12
|
</tr>
|
13
13
|
<% end -%>
|
14
|
+
|
15
|
+
<% unless options[:read_only] -%>
|
14
16
|
<tr>
|
15
17
|
<td>Actions</td>
|
16
18
|
<td>
|
17
|
-
<% unless options[:read_only] -%>
|
18
19
|
<%%= link_to "Edit", edit_admin_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => "btn btn-default" %>
|
19
|
-
|
20
|
-
<%%= link_to("Delete", admin_user_path(@user), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => "btn btn-danger btn-xs") %>
|
20
|
+
<%%= link_to("Delete", admin_<%= singular_table_name %>_path(@<%= singular_table_name %>), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => "btn btn-danger") %>
|
21
21
|
</td>
|
22
22
|
</tr>
|
23
|
+
<% end -%>
|
23
24
|
</table>
|
24
|
-
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: admin_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Marko Anastasov
|
@@ -9,62 +10,70 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rails
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - ~>
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '4.0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - ~>
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '4.0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: ransack
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- -
|
36
|
+
- - ~>
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '1.2'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- -
|
44
|
+
- - ~>
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '1.2'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: kaminari
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
|
-
- -
|
52
|
+
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
48
54
|
version: '0.15'
|
49
55
|
type: :runtime
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
|
-
- -
|
60
|
+
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
55
62
|
version: '0.15'
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: rspec-rails
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- -
|
68
|
+
- - ~>
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '2.4'
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- -
|
76
|
+
- - ~>
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '2.4'
|
70
79
|
description: Code generator of admin views and controllers for ActiveRecord models.
|
@@ -74,7 +83,7 @@ executables: []
|
|
74
83
|
extensions: []
|
75
84
|
extra_rdoc_files: []
|
76
85
|
files:
|
77
|
-
-
|
86
|
+
- .gitignore
|
78
87
|
- Gemfile
|
79
88
|
- MIT-LICENSE
|
80
89
|
- README.md
|
@@ -97,25 +106,26 @@ files:
|
|
97
106
|
- test/test_helper.rb
|
98
107
|
homepage: http://github.com/renderedtext/admin_view
|
99
108
|
licenses: []
|
100
|
-
metadata: {}
|
101
109
|
post_install_message:
|
102
110
|
rdoc_options: []
|
103
111
|
require_paths:
|
104
112
|
- lib
|
105
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
106
115
|
requirements:
|
107
|
-
- -
|
116
|
+
- - ! '>='
|
108
117
|
- !ruby/object:Gem::Version
|
109
118
|
version: '0'
|
110
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
111
121
|
requirements:
|
112
|
-
- -
|
122
|
+
- - ! '>='
|
113
123
|
- !ruby/object:Gem::Version
|
114
124
|
version: '0'
|
115
125
|
requirements: []
|
116
126
|
rubyforge_project: admin_view
|
117
|
-
rubygems_version:
|
127
|
+
rubygems_version: 1.8.23
|
118
128
|
signing_key:
|
119
|
-
specification_version:
|
129
|
+
specification_version: 3
|
120
130
|
summary: Admin view code generator for Rails.
|
121
131
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 75c33648b3776e0a936f358a9927a43dff397524
|
4
|
-
data.tar.gz: e12dee840643c2bfbcf07e3fa7faedcb9d1b263c
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 2f5ad171e3c5d6e60d543d6f02cfd4fefde17abecaba6a8ac6e677c496ae51f456a9ce272232f2df8b679fe5a2679d419b2d723a4b6f64796d3c843604487d39
|
7
|
-
data.tar.gz: b02916d24b92c1dfcb5b16a38b81ca127313bbb1a318512508236f82a777b42a8770a450458546f2509e8984cc6027af10f9940beed9e3637321bd3bab8972ef
|