How to test rails_admin actions in any ActiveRecord?

495 views Asked by At

I have a hotel.rb file. I used RSpec to test validations, associations and other actions, but how do I test the rails_admin block? Any sample code will be really appreciated.

    class Hotel < ActiveRecord::Base

        belongs_to :city

        validates_uniqueness_of :name, scope: :city_id

        # how do I test this?
        rails_admin do
            visible false
        end

    end
2

There are 2 answers

3
sourcx On

Normally you don't have to test functionality that other gems provide. It's the responsibility of the authors of that Gem.

Is there any specific reason you want to test this?

0
Yury Lebedev On

You can get the abstract model, that the rails admin is using, and read the config from it.

Small example for Rspec:

subject { RailsAdmin::AbstractModel.new('Hotel') }

it 'is invisible for rails admin' do
  expect(subject.config.hidden?).to eql true
end