activeadmin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeadmin might be problematic. Click here for more details.
- data/.document +5 -0
- data/.gitignore +25 -0
- data/Gemfile +16 -0
- data/LICENSE +20 -0
- data/README.rdoc +201 -0
- data/Rakefile +71 -0
- data/active_admin.gemspec +22 -0
- data/lib/active_admin.rb +229 -0
- data/lib/active_admin/action_builder.rb +60 -0
- data/lib/active_admin/action_items.rb +48 -0
- data/lib/active_admin/asset_registration.rb +34 -0
- data/lib/active_admin/breadcrumbs.rb +26 -0
- data/lib/active_admin/dashboards.rb +50 -0
- data/lib/active_admin/dashboards/dashboard_controller.rb +40 -0
- data/lib/active_admin/dashboards/renderer.rb +45 -0
- data/lib/active_admin/dashboards/section.rb +43 -0
- data/lib/active_admin/dashboards/section_renderer.rb +28 -0
- data/lib/active_admin/filters.rb +189 -0
- data/lib/active_admin/form_builder.rb +91 -0
- data/lib/active_admin/helpers/optional_display.rb +34 -0
- data/lib/active_admin/menu.rb +42 -0
- data/lib/active_admin/menu_item.rb +67 -0
- data/lib/active_admin/namespace.rb +111 -0
- data/lib/active_admin/page_config.rb +15 -0
- data/lib/active_admin/pages.rb +11 -0
- data/lib/active_admin/pages/base.rb +92 -0
- data/lib/active_admin/pages/edit.rb +21 -0
- data/lib/active_admin/pages/index.rb +58 -0
- data/lib/active_admin/pages/index/blog.rb +65 -0
- data/lib/active_admin/pages/index/table.rb +48 -0
- data/lib/active_admin/pages/index/thumbnails.rb +40 -0
- data/lib/active_admin/pages/new.rb +21 -0
- data/lib/active_admin/pages/show.rb +54 -0
- data/lib/active_admin/renderer.rb +72 -0
- data/lib/active_admin/resource.rb +96 -0
- data/lib/active_admin/resource_controller.rb +325 -0
- data/lib/active_admin/sidebar.rb +78 -0
- data/lib/active_admin/table_builder.rb +162 -0
- data/lib/active_admin/tabs_renderer.rb +39 -0
- data/lib/active_admin/version.rb +3 -0
- data/lib/active_admin/view_helpers.rb +106 -0
- data/lib/active_admin/views/active_admin_dashboard/index.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/edit.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/index.csv.erb +2 -0
- data/lib/active_admin/views/active_admin_default/index.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/new.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/show.html.erb +1 -0
- data/lib/active_admin/views/layouts/active_admin.html.erb +40 -0
- data/lib/activeadmin.rb +1 -0
- data/lib/generators/active_admin/install/install_generator.rb +31 -0
- data/lib/generators/active_admin/install/templates/active_admin.css +325 -0
- data/lib/generators/active_admin/install/templates/active_admin.js +10 -0
- data/lib/generators/active_admin/install/templates/active_admin.rb +47 -0
- data/lib/generators/active_admin/install/templates/active_admin_vendor.js +382 -0
- data/lib/generators/active_admin/install/templates/dashboards.rb +36 -0
- data/lib/generators/active_admin/install/templates/images/orderable.gif +0 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +16 -0
- data/lib/generators/active_admin/resource/templates/admin.rb +3 -0
- data/spec/integration/dashboard_spec.rb +44 -0
- data/spec/integration/index_as_blog_spec.rb +65 -0
- data/spec/integration/index_as_csv_spec.rb +40 -0
- data/spec/integration/index_as_table_spec.rb +160 -0
- data/spec/integration/index_as_thumbnails_spec.rb +43 -0
- data/spec/integration/layout_spec.rb +82 -0
- data/spec/integration/new_view_spec.rb +52 -0
- data/spec/integration/show_view_spec.rb +91 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/support/rails_template.rb +19 -0
- data/spec/unit/action_builder_spec.rb +76 -0
- data/spec/unit/action_items_spec.rb +41 -0
- data/spec/unit/active_admin_spec.rb +52 -0
- data/spec/unit/asset_registration_spec.rb +37 -0
- data/spec/unit/controller_filters_spec.rb +26 -0
- data/spec/unit/dashboard_section_spec.rb +63 -0
- data/spec/unit/dashboards_spec.rb +59 -0
- data/spec/unit/filter_form_builder_spec.rb +157 -0
- data/spec/unit/form_builder_spec.rb +238 -0
- data/spec/unit/menu_item_spec.rb +137 -0
- data/spec/unit/menu_spec.rb +53 -0
- data/spec/unit/namespace_spec.rb +107 -0
- data/spec/unit/registration_spec.rb +46 -0
- data/spec/unit/renderer_spec.rb +100 -0
- data/spec/unit/resource_controller_spec.rb +48 -0
- data/spec/unit/resource_spec.rb +197 -0
- data/spec/unit/routing_spec.rb +12 -0
- data/spec/unit/sidebar_spec.rb +96 -0
- data/spec/unit/table_builder_spec.rb +162 -0
- data/spec/unit/tabs_renderer_spec.rb +34 -0
- metadata +247 -0
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Generators
|
3
|
+
class ResourceGenerator < Rails::Generators::NamedBase
|
4
|
+
desc "Installs ActiveAdmin in a rails 3 application"
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@_active_admin_source_root ||= File.expand_path("../templates", __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_config_file
|
11
|
+
template "admin.rb", "app/admin/#{file_path.gsub('/', '_').pluralize}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ActiveAdmin, "rendering the dashboard" do
|
4
|
+
|
5
|
+
# Setup a controller spec
|
6
|
+
include RSpec::Rails::ControllerExampleGroup
|
7
|
+
render_views
|
8
|
+
metadata[:behaviour][:describes] = Admin::DashboardController
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
load_defaults!
|
12
|
+
reload_routes!
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when no configuration" do
|
16
|
+
before do
|
17
|
+
get :index
|
18
|
+
end
|
19
|
+
it "should render the default message" do
|
20
|
+
response.should have_tag("p", :attributes => { :id => "dashboard_default_message" })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when one configuration" do
|
25
|
+
before do
|
26
|
+
ActiveAdmin.dashboard_section 'Hello World' do
|
27
|
+
content_tag :p, "Hello world from the content"
|
28
|
+
end
|
29
|
+
get :index
|
30
|
+
end
|
31
|
+
it "should render the section's title" do
|
32
|
+
response.should have_tag("h3", "Hello World")
|
33
|
+
end
|
34
|
+
it "should render the section's content" do
|
35
|
+
response.should have_tag("p", "Hello world from the content")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when many configurations" do
|
40
|
+
it "should render each section"
|
41
|
+
it "should render the sections by priority, then alpha"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe_with_render "Index as Blog" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
load_defaults!
|
7
|
+
reload_routes!
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
Admin::PostsController.reset_index_config!
|
12
|
+
@post = Post.create(:title => "Hello World", :body => "This is the hello world post")
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "displaying the index as posts" do
|
16
|
+
|
17
|
+
context "when no configuration block given" do
|
18
|
+
before do
|
19
|
+
Admin::PostsController.index :as => :blog
|
20
|
+
get :index
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have an h3 as the title" do
|
24
|
+
response.should have_tag("h3", "Post #{@post.id}")
|
25
|
+
end
|
26
|
+
it "should generate a title link" do
|
27
|
+
response.should have_tag("a", "Post #{@post.id}", :attributes => {
|
28
|
+
:href => "/admin/posts/#{@post.id}" })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when a simple config given" do
|
33
|
+
before do
|
34
|
+
Admin::PostsController.index :as => :blog do |i|
|
35
|
+
i.title :title
|
36
|
+
i.content :body
|
37
|
+
end
|
38
|
+
get :index
|
39
|
+
end
|
40
|
+
it "should render the title" do
|
41
|
+
response.should have_tag("h3", "Hello World")
|
42
|
+
end
|
43
|
+
it "should render the body as the content" do
|
44
|
+
response.should have_tag("div", @post.body, :attributes => { :class => 'content' } )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when blocks given as config" do
|
49
|
+
before do
|
50
|
+
Admin::PostsController.index :as => :blog do |i|
|
51
|
+
i.title {|post| post.title }
|
52
|
+
i.content {|post| simple_format post.body }
|
53
|
+
end
|
54
|
+
get :index
|
55
|
+
end
|
56
|
+
it "should render the title" do
|
57
|
+
response.should have_tag("h3", "Hello World")
|
58
|
+
end
|
59
|
+
it "should render the body as the content" do
|
60
|
+
response.should have_tag("div", @post.body, :attributes => { :class => 'content' } )
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe_with_render "Index as CSV" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
load_defaults!
|
7
|
+
reload_routes!
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
Admin::PostsController.reset_index_config!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "get index with format csv" do
|
15
|
+
before do
|
16
|
+
Post.create :title => "Hello World"
|
17
|
+
Post.create :title => "Goodbye World"
|
18
|
+
end
|
19
|
+
it "should return csv" do
|
20
|
+
get :index, 'format' => 'csv'
|
21
|
+
response.content_type.should == 'text/csv'
|
22
|
+
end
|
23
|
+
it "should return a header and a line for each item" do
|
24
|
+
get :index, 'format' => 'csv'
|
25
|
+
response.body.split("\n").size.should == 3
|
26
|
+
end
|
27
|
+
Post.columns.each do |column|
|
28
|
+
it "should include a header for #{column.name}" do
|
29
|
+
get :index, 'format' => 'csv'
|
30
|
+
response.body.split("\n").first.should include(column.name.titleize)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
it "should set a much higher per page pagination" do
|
34
|
+
100.times{ Post.create :title => "woot" }
|
35
|
+
get :index, 'format' => 'csv'
|
36
|
+
response.body.split("\n").size.should == 103
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe_with_render "Index as Table" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
load_defaults!
|
7
|
+
reload_routes!
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
Admin::PostsController.reset_index_config!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "GET #index" do
|
15
|
+
before(:each) do
|
16
|
+
@post = Post.create(:title => "Hello World")
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "in general" do
|
20
|
+
it "should have a breadcrumb" do
|
21
|
+
get :index
|
22
|
+
response.should have_tag("a", "Dashboard")
|
23
|
+
end
|
24
|
+
it "should have pagination information" do
|
25
|
+
get :index
|
26
|
+
response.body.should match(/Displaying \<b\>1\<\/b\> Post/)
|
27
|
+
end
|
28
|
+
it "should set the page title" do
|
29
|
+
get :index
|
30
|
+
response.should have_tag("title", "Posts | Rails300")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with default table" do
|
35
|
+
before(:each) do
|
36
|
+
get :index
|
37
|
+
end
|
38
|
+
it "should render a header for the section" do
|
39
|
+
response.should have_tag("h2", "Posts")
|
40
|
+
end
|
41
|
+
it "should render a new link" do
|
42
|
+
response.should have_tag("a", "New Post", :attributes => {:href => "/admin/posts/new"})
|
43
|
+
end
|
44
|
+
it "should render an ID header" do
|
45
|
+
response.should have_tag("th", "ID")
|
46
|
+
end
|
47
|
+
it "should render a table with default sortable headers" do
|
48
|
+
response.should have_tag("a", :content => "Title",
|
49
|
+
:parent => { :tag => "th" })
|
50
|
+
# I should be able to match against the url attribute, but it doesn't want to work
|
51
|
+
# :attributes => { 'href' => "/admin/posts?order=title_desc"})
|
52
|
+
# So instead, we'll check that it exists
|
53
|
+
response.body.should match(/\"\/admin\/posts\?order\=title_desc\"/)
|
54
|
+
end
|
55
|
+
it "should render the sortable header for ascending if we are currently sorted descending" do
|
56
|
+
get :index, 'order' => 'title_desc'
|
57
|
+
response.body.should match(/\"\/admin\/posts\?order\=title_asc\"/)
|
58
|
+
end
|
59
|
+
it "should render a view link" do
|
60
|
+
response.should have_tag("a", "View")
|
61
|
+
end
|
62
|
+
it "should render an edit link" do
|
63
|
+
response.should have_tag("a", "Edit")
|
64
|
+
end
|
65
|
+
it "should render a delete link" do
|
66
|
+
response.should have_tag("a", "Delete")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "with symbol column keys" do
|
71
|
+
before(:each) do
|
72
|
+
Admin::PostsController.index do |i|
|
73
|
+
i.column :title
|
74
|
+
end
|
75
|
+
Post.create(:title => "Hello World", :body => "Woot Woot")
|
76
|
+
get :index
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should show the specified columns" do
|
80
|
+
response.should have_tag("th", "Title")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should show the column data" do
|
84
|
+
response.should have_tag("td", "Hello World")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not show specified columns" do
|
88
|
+
response.should_not have_tag("th", "Body")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "with block column keys" do
|
93
|
+
before(:each) do
|
94
|
+
|
95
|
+
Admin::PostsController.index do |i|
|
96
|
+
i.column('Great Titles'){|post| link_to post.title, [:admin, post] }
|
97
|
+
end
|
98
|
+
Post.create(:title => "Hello World", :body => "Woot Woot")
|
99
|
+
get :index
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should show the specified columns" do
|
103
|
+
response.should have_tag("th", "Great Titles")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should render the block in the view" do
|
107
|
+
response.should have_tag("a", "Hello World")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should show the column data" do
|
111
|
+
response.should have_tag("td", "Hello World")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "hiding columns" do
|
116
|
+
before(:each) do
|
117
|
+
Admin::PostsController.index do |i|
|
118
|
+
i.column :title, :if => proc{ false }
|
119
|
+
i.column :body
|
120
|
+
end
|
121
|
+
get :index
|
122
|
+
end
|
123
|
+
it "should not show columns which conditionals eval to false" do
|
124
|
+
response.should_not have_tag("th", "Title")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "ordering get #index" do
|
130
|
+
before(:each) do
|
131
|
+
@yesterday = Post.create :title => "Yesterday", :created_at => Time.now - 1.day
|
132
|
+
@today = Post.create :title => "Today"
|
133
|
+
end
|
134
|
+
it "should sort ascending" do
|
135
|
+
get :index, 'order' => 'created_at_asc'
|
136
|
+
response.body.scan(/Yesterday|Today/).should == ["Yesterday", "Today"]
|
137
|
+
end
|
138
|
+
it "should sort descending" do
|
139
|
+
get :index, 'order' => 'created_at_desc'
|
140
|
+
response.body.scan(/Yesterday|Today/).should == ["Today", "Yesterday"]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "searching" do
|
145
|
+
before do
|
146
|
+
Post.create :title => "Hello World"
|
147
|
+
Post.create :title => "Goodbye World"
|
148
|
+
get :index, 'q' => { 'title_like' => 'hello' }
|
149
|
+
end
|
150
|
+
it "should find posts based on search" do
|
151
|
+
response.body.should include("Hello World")
|
152
|
+
end
|
153
|
+
it "should not includes posts that don't meet the search" do
|
154
|
+
response.body.should_not include("Goodbye")
|
155
|
+
end
|
156
|
+
it "should set @search for the view" do
|
157
|
+
assigns["search"].should_not be_nil
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe_with_render "Index as Thumbnails" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
load_defaults!
|
7
|
+
reload_routes!
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
Admin::PostsController.reset_index_config!
|
12
|
+
@post = Post.create(:title => "Hello World", :body => "This is the hello world post")
|
13
|
+
|
14
|
+
# Create a method for a fake thumbnail url
|
15
|
+
class Post < ActiveRecord::Base
|
16
|
+
def thumbnail_url
|
17
|
+
title.downcase.gsub(' ', '-') + ".jpg"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "displaying the index as thumbnails" do
|
23
|
+
|
24
|
+
context "when only setting the image path" do
|
25
|
+
before do
|
26
|
+
Admin::PostsController.index :as => :thumbnails do |i|
|
27
|
+
i.image :thumbnail_url
|
28
|
+
end
|
29
|
+
get :index
|
30
|
+
end
|
31
|
+
it "should generate an image" do
|
32
|
+
response.should have_tag("img", :attributes => {
|
33
|
+
:src => "hello-world.jpg",
|
34
|
+
:width => "200", :height => "200"})
|
35
|
+
end
|
36
|
+
it "should create a link to the resource" do
|
37
|
+
response.should have_tag("a", :attributes => {
|
38
|
+
:href => "/admin/posts/#{@post.id}" })
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe_with_render "Layout" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
load_defaults!
|
7
|
+
reload_routes!
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should include the active admin stylesheet" do
|
11
|
+
get :index
|
12
|
+
response.should have_tag("link", :attributes => { :href => '/stylesheets/active_admin.css' })
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should include active admin vendor js" do
|
16
|
+
get :index
|
17
|
+
response.should have_tag("script", :attributes => { :src => '/javascripts/active_admin_vendor.js' })
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should include active admin js" do
|
21
|
+
get :index
|
22
|
+
response.should have_tag("script", :attributes => { :src => '/javascripts/active_admin.js' })
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should display the site title" do
|
26
|
+
get :index
|
27
|
+
response.should have_tag("h1", ActiveAdmin.site_title)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "csrf meta tags" do
|
31
|
+
# Turn on then off protect against forgery so that our tests
|
32
|
+
# will render the required meta tags
|
33
|
+
before(:each) do
|
34
|
+
class Admin::PostsController
|
35
|
+
def protect_against_forgery_with_mock?; true; end
|
36
|
+
alias_method_chain :protect_against_forgery?, :mock
|
37
|
+
end
|
38
|
+
end
|
39
|
+
after(:each) do
|
40
|
+
Admin::PostsController.send :alias_method, :protect_against_forgery?, :protect_against_forgery_without_mock?
|
41
|
+
end
|
42
|
+
it "should include the csrf-param meta tag" do
|
43
|
+
get :index
|
44
|
+
response.should have_tag("meta", :attributes => { :name => "csrf-param" })
|
45
|
+
end
|
46
|
+
it "should include the csrf-token meta tag" do
|
47
|
+
get :index
|
48
|
+
response.should have_tag("meta", :attributes => { :name => "csrf-token" })
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "tabs" do
|
53
|
+
context "when index" do
|
54
|
+
before do
|
55
|
+
get :index
|
56
|
+
end
|
57
|
+
it "should generate an ul for tabs" do
|
58
|
+
response.should have_tag("ul", :attributes => { :id => "tabs" })
|
59
|
+
end
|
60
|
+
it "should generate an li and a for each resource" do
|
61
|
+
ActiveAdmin.namespaces[:admin].resources.values.each do |r|
|
62
|
+
response.should have_tag("a", r.resource_name.pluralize, :parent => {
|
63
|
+
:tag => "li" })
|
64
|
+
end
|
65
|
+
end
|
66
|
+
it "should mark the current tab as current" do
|
67
|
+
response.should have_tag("li", "Posts", :attributes => {
|
68
|
+
:class => "current" })
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "when /new" do
|
72
|
+
before do
|
73
|
+
get :new
|
74
|
+
end
|
75
|
+
it "should mark the current tab section as current" do
|
76
|
+
response.should have_tag("li", "Posts", :attributes => {
|
77
|
+
:class => "current" })
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|