Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing ActiveAdmin with rspec

I am trying to get started in testing ActiveAdmin, in particular I need to test a member_action from one of the ActiveAdmin controllers.

Do you guys know any good tutorials on this topic?

Thank you,

like image 696
Calin Avatar asked May 30 '12 09:05

Calin


2 Answers

This is the way I did it that worked for me:-

app/admin/posts.rb

ActiveAdmin.register Post do

  menu :parent => "Admin"


  #path = /admin/posts/:id/comments
  member_action :comments do
   @post = Post.find(params[:id])
  end 
end

spec/controllers/admin/posts_controller_spec.rb

require 'spec_helper'
include Devise::TestHelpers


describe Admin::PostsController do
  render_views

  before(:each) do
    @user = mock_model(User, :email => "[email protected]")
    request.env['tester'] = mock(Tester, :authenticate => @user, :authenticate! => @user)
  end

  describe "Get comments" do
    before(:each) do
      @post = Post.create! valid_attributes
      Post.should_receive(:find).at_least(:once).and_return(@post)
      get :comments, :id => @post.id
    end

    after(:each) do
      @post.destroy
    end

    it "gets the proper record to update" do
      assigns(:post).should eq(@post)
    end

    it "should render the actual template" do
      response.should contain("Comments")
      response.body.should =~ /Comments/m
    end
  end
end
like image 79
Kiali Avatar answered Oct 22 '22 17:10

Kiali


# app/admin/post.rb
ActiveAdmin.register Post do
end

# spec/controller/admin/posts_controller_spec.rb
describe Admin::PostsController do
  subject { get :index }
  its(:status) { should eq 200 }
end
like image 43
Dorian Avatar answered Oct 22 '22 16:10

Dorian