Skip to content

Testing your ActiveAdmin resources with RSpec

Matt Lewis edited this page Apr 3, 2018 · 8 revisions

ActiveAdmin comes with its own tests, so your testing can be limited to verifying the configuration of your application and resources.

This wiki is a work in progress, but can be used as a reference.

Ensuring a resource exists

ActiveAdmin.application.namespaces[:admin].resources.should have_key("AdminUser")


For the items below, assume the following:

let(:resource_class) { YourResource }
let(:all_resources)  { ActiveAdmin.application.namespaces[:admin].resources }
let(:resource)       { all_resources[resource_class] }

Verify resource name

resource.resource_name.should == "YourResource"

Verifying menu display

resource.should be_include_in_menu

Verifying defined actions for a resource

resource.defined_actions.should =~ [:create, :new, :update, :edit, :index, :show, :destroy]

Verifying scope

resource.scope_to.should == :current_user

Verifying page details

subject { get :index }
it { is_expected.to be_success }
let(:partial) { "admin/Your Resource/_index" }
it { is_expected.to render_template(:partial => partial) }
Clone this wiki locally