gpt4 book ai didi

ruby-on-rails-3.2 - 使用 RSpec 为 ActiveAdmin 编写 Controller 和功能规范?

转载 作者:行者123 更新时间:2023-12-04 11:25:55 24 4
gpt4 key购买 nike

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

# 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 加载的“批处理操作”。
# 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

版本
  • 导轨 3.2.14
  • ActiveAdmin 0.6.0
  • 最佳答案

    我想出了如何构建 Controller 规范。

    # 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

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

    关于ruby-on-rails-3.2 - 使用 RSpec 为 ActiveAdmin 编写 Controller 和功能规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18240851/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com