Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provided basic tests for active admin resources. #128

Merged
merged 2 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions spec/controllers/active_admin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'rails_helper'

ActiveAdmin.application.namespaces[:admin].resources.each do |resource|
resource_name = resource.resource_name.singular

describe resource.controller, type: :controller do
let(:admin) { create(:admin) }
let!(:model) { create(resource_name) if FactoryBot.factories.registered?(resource_name) }

render_views

before(:each) do
sign_in(admin)
end

if resource.is_a?(ActiveAdmin::Page) || resource.defined_actions.include?(:index)
describe "GET index" do
it "returns http success" do
get :index

expect(response.status).to eq(200)
expect(response).to have_http_status(:success)
end
end
end

if resource.is_a?(ActiveAdmin::Page) || resource.defined_actions.include?(:show)
describe "GET index" do
it "returns http success" do
get :index

expect(response.status).to eq(200)
expect(response).to be_success
end
end
end
end
end
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# Add additional requires below this line. Rails is not loaded until this point!
require 'factory_bot_rails'
require 'shoulda/matchers'
require 'devise'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
Expand Down Expand Up @@ -114,4 +115,5 @@

config.include FactoryBot::Syntax::Methods
config.order = 'random'
config.include Devise::Test::ControllerHelpers, :type => :controller
end