2013-08-14 23 views
7

Làm sao người ta viết một bộ điều khiển và tính năng spec cho mã ActiveAdmin sau:Viết điều khiển và thông số tính năng cho ActiveAdmin bằng RSpec?

# 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 

Dưới đây là tính năng của tôi spec. Nó không thể tìm thấy 'Batch Actions' mà ActiveAdmin tải trong menu pop-up.

# 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('[email protected]', '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 

phiên bản

  • Rails 3.2.14
  • ActiveAdmin 0.6.0

Trả lời

9

tôi đã tìm ra cách xây dựng một spec điều khiển.

# 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 

Nếu có ai biết cách viết đặc điểm tính năng, vui lòng chia sẻ thông tin đó.

Các vấn đề liên quan