spec/unit/registration_spec.rb in activeadmin-0.2.2 vs spec/unit/registration_spec.rb in activeadmin-0.3.0

- old
+ new

@@ -1,68 +1,59 @@ require 'spec_helper' describe "Registering an object to administer" do + let(:application){ ActiveAdmin::Application.new } context "with no configuration" do - let(:namespace) { ActiveAdmin::Namespace.new(:admin) } + let(:namespace) { ActiveAdmin::Namespace.new(application, :admin) } it "should call register on the namespace" do - ActiveAdmin.namespaces[namespace.name] = namespace + application.namespaces[namespace.name] = namespace namespace.should_receive(:register) - ActiveAdmin.register Category + application.register Category end it "should dispatch a Resource::RegisterEvent" do ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Resource::RegisterEvent, an_instance_of(ActiveAdmin::Resource)) - ActiveAdmin.register Category + application.register Category end end context "with a different namespace" do it "should call register on the namespace" do - namespace = ActiveAdmin::Namespace.new(:hello_world) - ActiveAdmin.namespaces[namespace.name] = namespace + namespace = ActiveAdmin::Namespace.new(application, :hello_world) + application.namespaces[namespace.name] = namespace namespace.should_receive(:register) - ActiveAdmin.register Category, :namespace => :hello_world + application.register Category, :namespace => :hello_world end - it "should generate a path to the dashboard" do - ActiveAdmin.register Category, :namespace => :hello_world - reload_routes! - Rails.application.routes.url_helpers.methods.collect(&:to_s).should include("hello_world_dashboard_path") - end it "should generate a menu item for the dashboard" do - ActiveAdmin.register Category, :namespace => :hello_world - ActiveAdmin.namespaces[:hello_world].load_menu! - ActiveAdmin.namespaces[:hello_world].menu['Dashboard'].instance_variable_get("@url").should == :hello_world_dashboard_path + application.register Category, :namespace => :hello_world + application.namespaces[:hello_world].load_menu! + application.namespaces[:hello_world].menu['Dashboard'].instance_variable_get("@url").should == :hello_world_dashboard_path end it "should generate a Namespace::RegisterEvent and a Resource::RegisterEvent" do ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Namespace::RegisterEvent, an_instance_of(ActiveAdmin::Namespace)) ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Resource::RegisterEvent, an_instance_of(ActiveAdmin::Resource)) - ActiveAdmin.register Category, :namespace => :not_yet_created + application.register Category, :namespace => :not_yet_created end end context "with no namespace" do it "should call register on the root namespace" do - namespace = ActiveAdmin::Namespace.new(:root) - ActiveAdmin.namespaces[namespace.name] = namespace + namespace = ActiveAdmin::Namespace.new(application, :root) + application.namespaces[namespace.name] = namespace namespace.should_receive(:register) - ActiveAdmin.register Category, :namespace => false + application.register Category, :namespace => false end it "should generate a menu item for the dashboard" do - ActiveAdmin.register Category, :namespace => false - ActiveAdmin.namespaces[:root].load_menu! - ActiveAdmin.namespaces[:root].menu['Dashboard'].instance_variable_get("@url").should == :dashboard_path + application.register Category, :namespace => false + application.namespaces[:root].load_menu! + application.namespaces[:root].menu['Dashboard'].instance_variable_get("@url").should == :dashboard_path end - it "should generate a path to the dashboard" do - ActiveAdmin.register Category, :namespace => false - reload_routes! - Rails.application.routes.url_helpers.methods.collect(&:to_s).should include("dashboard_path") - end end context "when being registered multiple times" do it "should run the dsl in the same config object" do config_1 = ActiveAdmin.register(Category) { filter :name }