gpt4 book ai didi

rspec - 使用 rspec 测试 ActiveAdmin

转载 作者:行者123 更新时间:2023-12-04 00:22:20 25 4
gpt4 key购买 nike

我正在尝试开始测试 ActiveAdmin,特别是我需要测试来自 ActiveAdmin Controller 之一的 member_action。

你们知道关于这个主题的任何好的教程吗?

谢谢,

最佳答案

这就是我做的对我有用的方式:-

应用程序/管理员/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

规范/ Controller /管理员/posts_controller_spec.rb
require 'spec_helper'
include Devise::TestHelpers


describe Admin::PostsController do
render_views

before(:each) do
@user = mock_model(User, :email => "tester@localspecs.com")
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

关于rspec - 使用 rspec 测试 ActiveAdmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10813663/

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