如何编写rspec来支持Ruby on Rails中的管理面板功能?

dvtswwa3  于 2023-06-05  发布在  Ruby
关注(0)|答案(1)|浏览(99)

谁能告诉我,如何在ruby on rails中为这个管理面板功能编写rspec。

ActiveAdmin.register BxBlockCfappcoinsmanagement::CoinSetting, as: "Settings" do
  menu false

  permit_params :single_coin_worth, :transaction_type

  index do
    selectable_column
    column :id
    column :transaction_type

# column "Single Coin Worth($)", :single_coin_worth
column "Single Coin Worth($)" do |coin_setting|
  number_with_precision(coin_setting.single_coin_worth, precision: 20, strip_insignificant_zeros: true)
end
# actions defaults: true #for all actions like(edit, show and delete)
actions defaults: false do |coin_setting|
  item "Show", admin_setting_path(coin_setting), class: "member_link"
  item "Edit", edit_admin_setting_path(coin_setting), class: "member_link"
end
  end

  show do
    attributes_table do 

  row "single_coin_worth($)" do |coin_setting|
    number_with_precision(coin_setting.single_coin_worth, precision: 20, strip_insignificant_zeros: true)
  end
  row "created_at"
  row "updated_at"
  row "transaction_type"
end
  end

  form do |f|
    f.semantic_errors *f.object.errors[:base]
    f.inputs do

  f.input :single_coin_worth, required: true, min: 0, max: 100000, input_html: { pattern: '[\d.]+', title: 'Only digits and decimal point are allowed'}
  f.input :transaction_type, as: :select, collection: ['purchase', 'withdrawl']
  f.actions
end
  end
end

这个文件有索引页、显示页和表单域。
我为此编写了rspec,但没有工作。我不知道为什么

fzsnzjdm

fzsnzjdm1#

你可以在各自的控制器下创建一个spec文件。例如spec/controller/admin/your_file_name(即)模型名称
然后开始编写类似于其他控制器的规范
例如

RSpec.describe Admin::BxBlockCfappcoinsmanagement::CoinSettingsController, type: :controller do
  describe "#index" do
    it "should render index" do
      get :index
      expect(response).to render_template(:index)
    end
  end
  .. similarly for other actions
end

相关问题