Skip to content

Commit f1b3377

Browse files
committed
Merge branch 'deprecate-dashboards'
Conflicts: features/support/env.rb
2 parents 749763e + 17373d5 commit f1b3377

24 files changed

+259
-172
lines changed

cucumber.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
default: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags ~@requires-reloading
1+
default: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags ~@requires-reloading --tags ~@wip
22
wip: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @wip:3 --wip features
33
class-reloading: RAILS_ENV=cucumber_with_reloading --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @requires-reloading

features/dashboard.feature

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
Feature: Dashboard
22

3-
Background:
3+
@dashboard
4+
Scenario: With default configuration
5+
Given a configuration of:
6+
"""
7+
ActiveAdmin.register_page "Dashboard" do
8+
content do
9+
para "Hello world from the dashboard page"
10+
end
11+
end
12+
"""
413
Given I am logged in
14+
When I go to the dashboard
15+
Then I should see the Active Admin layout
16+
And I should not see the default welcome message
17+
And I should see "Hello world from the dashboard page"
518

6-
7-
Scenario: With no configuration
19+
@dashboard
20+
Scenario: DEPRECATED - With default configuration
821
Given a configuration of:
922
"""
23+
ActiveAdmin::Dashboards.build do
24+
end
1025
"""
26+
Given I am logged in
1127
When I go to the dashboard
12-
Then I should see the default welcome message
28+
Then I should see the Active Admin layout
29+
And I should see the default welcome message
1330

14-
Scenario: Displaying a dashboard widget
31+
@dashboard
32+
Scenario: DEPRECATED - Displaying a dashboard widget
1533
Given a configuration of:
1634
"""
1735
ActiveAdmin::Dashboards.build do
@@ -20,12 +38,15 @@ Feature: Dashboard
2038
end
2139
end
2240
"""
41+
Given I am logged in
2342
When I go to the dashboard
24-
Then I should not see the default welcome message
43+
Then I should see the Active Admin layout
44+
And I should not see the default welcome message
2545
And I should see a dashboard widget "Hello World"
2646
And I should see "Hello world from the content"
2747

28-
Scenario: Displaying a dashboard widget using the ':if' option
48+
@dashboard
49+
Scenario: DEPRECATED - Displaying a dashboard widget using the ':if' option
2950
Given a configuration of:
3051
"""
3152
ActiveAdmin::Dashboards.build do
@@ -38,7 +59,9 @@ Feature: Dashboard
3859
end
3960
end
4061
"""
62+
Given I am logged in
4163
When I go to the dashboard
42-
Then I should not see the default welcome message
64+
Then I should see the Active Admin layout
65+
And I should not see the default welcome message
4366
And I should see a dashboard widget "Hello World"
4467
And I should not see a dashboard widget "Hidden by If"

features/i18n.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Feature: Internationalization
2727
When I set my locale to "fr"
2828
And I go to the dashboard
2929
Then I should see "Store"
30-
And I should see "Tableau de Bord"
30+
Then I should see "Déconnexion"
3131

3232
When I set my locale to "en"
3333
And I go to the dashboard
3434
Then I should see "Bookstore"
35-
And I should see "Dashboard"
35+
Then I should see "Logout"

features/root_to.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Namespace root
2+
3+
As a developer
4+
In order to customize the welcome page
5+
I want to set it in the configuration
6+
7+
Scenario: Default root is the Dashboard
8+
Given I am logged in
9+
Then I should be on the dashboard
10+
11+
Scenario: Set root to "stores#index"
12+
Given a configuration of:
13+
"""
14+
ActiveAdmin.application.root_to = 'stores#index'
15+
"""
16+
Given I am logged in
17+
Then I should see the page title "Bookstores"

features/support/env.rb

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
55
# files.
66

7+
ENV["RAILS_ENV"] ||= "cucumber"
78
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __FILE__)
9+
require "rubygems"
10+
require "bundler"
11+
Bundler.setup
812

913
require File.expand_path('../../../spec/support/detect_rails_version', __FILE__)
1014
ENV["RAILS"] = detect_rails_version
1115

12-
ENV["RAILS_ENV"] ||= "cucumber"
1316
ENV['RAILS_ROOT'] = File.expand_path("../../../spec/rails/rails-#{ENV["RAILS"]}", __FILE__)
1417

1518

16-
require 'rubygems'
17-
require "bundler"
18-
Bundler.setup
19-
2019
# Create the test app if it doesn't exists
2120
unless File.exists?(ENV['RAILS_ROOT'])
2221
system 'rake setup'
@@ -79,30 +78,58 @@
7978
end
8079
end
8180

82-
# Create the test app if it doesn't exists
83-
unless File.exists?(ENV['RAILS_ROOT'])
84-
system 'rake setup'
81+
def add_default_dashboard
82+
begin
83+
dashboard_file = ENV['RAILS_ROOT'] + "/app/admin/dashboard.rb"
84+
dashboard_template = File.expand_path('../../../lib/generators/active_admin/install/templates/dashboard.rb', __FILE__)
85+
cmd = "cp #{dashboard_template} #{dashboard_file}"
86+
system cmd
87+
rescue
88+
p $!
89+
raise $!
90+
end
8591
end
8692

87-
# Remove all our constants
88-
Before do
89-
# We are cachine classes, but need to manually clear references to
90-
# the controllers. If they aren't clear, the router stores references
91-
ActiveSupport::Dependencies.clear
92-
93-
# Reload Active Admin
94-
ActiveAdmin.unload!
95-
ActiveAdmin.load!
93+
def delete_default_dashboard
94+
begin
95+
dashboard_file = ENV['RAILS_ROOT'] + "/app/admin/dashboard.rb"
96+
File.delete(dashboard_file) if File.exists?(dashboard_file)
97+
rescue
98+
p $!
99+
raise $!
100+
end
96101
end
97102

98103
# Warden helpers to speed up login
99104
# See https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
100105
include Warden::Test::Helpers
101106

102107
After do
108+
add_default_dashboard
103109
Warden.test_reset!
104110
end
105111

112+
Before '@dashboard' do
113+
delete_default_dashboard
114+
end
115+
116+
Before do
117+
add_default_dashboard
118+
119+
begin
120+
# We are caching classes, but need to manually clear references to
121+
# the controllers. If they aren't clear, the router stores references
122+
ActiveSupport::Dependencies.clear
123+
124+
# Reload Active Admin
125+
ActiveAdmin.unload!
126+
ActiveAdmin.load!
127+
rescue
128+
p $!
129+
raise $!
130+
end
131+
end
132+
106133
# improve the performance of the specs suite by not logging anything
107134
# see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
108135
Rails.logger.level = 4

features/users/logging_out.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Feature: User Logging out
2121
"""
2222
And I am logged in
2323
When I go to the dashboard
24-
Then I should see the default welcome message
24+
And I follow "Logout"
25+
Then I should see "Login"

lib/active_admin/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def self.inheritable_setting(name, default)
6060
# Whether the batch actions are enabled or not
6161
inheritable_setting :batch_actions, true
6262

63+
# The namespace root.
64+
inheritable_setting :root_to, 'dashboard#index'
65+
6366
# Active Admin makes educated guesses when displaying objects, this is
6467
# the list of methods it tries calling in order
6568
setting :display_name_methods, [ :display_name,

lib/active_admin/dashboards.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
require 'active_admin/dashboards/dashboard_controller'
2+
require 'active_admin/dashboards/section'
3+
14
module ActiveAdmin
25
module Dashboards
36

4-
autoload :DashboardController, 'active_admin/dashboards/dashboard_controller'
5-
autoload :Section, 'active_admin/dashboards/section'
6-
77
@@sections = {}
88
mattr_accessor :sections
99

@@ -21,9 +21,15 @@ class << self
2121
# end
2222
#
2323
def build(&block)
24+
warn "DEPRECATION WARNING: ActiveAdmin::Dashboard is deprecated and will be removed in the next version"
25+
@built = true
2426
module_eval(&block)
2527
end
2628

29+
def built?
30+
!!@built
31+
end
32+
2733
# Add a new dashboard section to a namespace. If no namespace is given
2834
# it will be added to the default namespace.
2935
#
@@ -46,7 +52,18 @@ def clear_all_sections!
4652
@@sections = {}
4753
end
4854

49-
end
55+
# Called from MenuBuilder to register dashboard to menu.
56+
def add_to_menu(namespace, menu)
57+
return unless ActiveAdmin::Dashboards.built?
58+
59+
dashboard_path = namespace.root? ? :dashboard_path : "#{namespace.name}_dashboard_path".to_sym
5060

61+
item = MenuItem.new :id => "dashboard",
62+
:label => proc{ I18n.t("active_admin.dashboard") },
63+
:url => dashboard_path,
64+
:priority => 1
65+
menu.add item
66+
end
67+
end
5168
end
5269
end

lib/active_admin/dashboards/dashboard_controller.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
module ActiveAdmin
22
module Dashboards
3-
class DashboardController < ResourceController
4-
5-
actions :index
6-
3+
module DashboardController
74
def index
85
@dashboard_sections = find_sections
96
render 'active_admin/dashboard/index'
@@ -48,7 +45,6 @@ def current_menu
4845
def active_admin_namespace
4946
ActiveAdmin.application.namespace(namespace)
5047
end
51-
5248
end
5349
end
5450
end

lib/active_admin/menu_builder.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def namespace
2525
def build_menu
2626
menu = Menu.new
2727

28-
add_dashboard_to_menu(menu)
28+
Dashboards.add_to_menu(namespace, menu)
2929

3030
namespace.resources.each do |resource|
3131
register_with_menu(menu, resource) if resource.include_in_menu?
@@ -34,16 +34,6 @@ def build_menu
3434
menu
3535
end
3636

37-
def add_dashboard_to_menu(menu)
38-
dashboard_path = namespace.root? ? :dashboard_path : "#{@namespace.name}_dashboard_path".to_sym
39-
40-
item = MenuItem.new :id => "dashboard",
41-
:label => proc{ I18n.t("active_admin.dashboard") },
42-
:url => dashboard_path,
43-
:priority => 1
44-
menu.add item
45-
end
46-
4737
# Does all the work of registernig a config with the menu system
4838
def register_with_menu(menu, resource)
4939
# The menu we're going to add this resource to

0 commit comments

Comments
 (0)