使用RSpec编写ActiveAdmin的控制器和功能规格? [英] Write controller and feature specs for ActiveAdmin using RSpec?

查看:85
本文介绍了使用RSpec编写ActiveAdmin的控制器和功能规格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为以下ActiveAdmin代码编写控制器和功能规范:

How does one write a controller and feature spec for the following ActiveAdmin code:

# app/admin/organization.rb
ActiveAdmin.register Organization do
  batch_action :approve do |selection|
    Organization.find(selection).each {|organization| organization.approve }
    redirect_to collection_path, notice: 'Organizations approved.'
  end
end

这是我的功能规格。它无法在弹出菜单中找到ActiveAdmin加载的批量操作。

Here is my feature spec. It cannot find 'Batch Actions' which ActiveAdmin loads in the pop-up menu.

# spec/features/admin/organization_feature_spec.rb
require 'spec_helper'
include Devise::TestHelpers

describe 'Admin Organization' do
  before(:each) do
    @user = FactoryGirl.create(:admin_user)
    login('admin@company.com', 'password1')
  end

  it 'approves in batch' do
    organization = FactoryGirl.create(:organization)
    visit admin_organizations_path
    check 'collection_selection_toggle_all'
    click_link 'Batch Actions'
    click_link 'Approve Selected'
    organization.reload
    organization.state.should eq 'approved'
  end
end

版本


  • Rails 3.2.14

  • ActiveAdmin 0.6.0

推荐答案

我想出了如何构造控制器规范。

I figured out how to construct a controller spec.

# spec/controllers/admin/organizations_controller_spec.rb
require 'spec_helper'
include Devise::TestHelpers

describe Admin::OrganizationsController do
  render_views

  before(:each) do
    @user = FactoryGirl.create(:admin_user)
   sign_in @user
  end

  it 'approve organization' do
    @organization = FactoryGirl.create(:organization, state: 'pending')
    post :batch_action, batch_action: 'approve', collection_selection_toggle_all: 'on', collection_selection: [@organization.id]
    @organization.reload
    @organization.pending?.should be_false
  end
end

如果有人知道如何编写功能说明,请分享该信息。

If anyone knows how to write the feature spec, please share that info.

这篇关于使用RSpec编写ActiveAdmin的控制器和功能规格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆