我们使用 VCR 来记录 Rails 应用程序中测试的 http 请求。这些磁带目前已提交来源,但 CircleCI 似乎并未使用它们,因为 CircleCI 每次都会提出新的请求。测试正在本地环境中通过。我希望 CircleCI 使用保存在我们的 git 存储库中的磁带。这可能吗 ?
当我在 CircleCI 服务器上执行测试时,测试通过了。
任何指导或建议将不胜感激!
本地环境:mac OS Big sur 11.6.1
gemfile.rb
gem 'rspec-rails', '~> 5.0'
gem 'vcr', '~> 6.1'
Run Code Online (Sandbox Code Playgroud)
录像机
VCR.configure do |config|
config.cassette_library_dir = 'spec/cassettes'
config.hook_into :webmock
config.ignore_localhost = true
config.configure_rspec_metadata!
config.filter_sensitive_data('<BEARER_TOKEN>') do |interaction|
auths = interaction.request.headers['Authorization']&.first
if auths && (match = auths.match(/^Bearer\s+([^,\s]+)/))
match.captures.first
end
end
end
Run Code Online (Sandbox Code Playgroud) 我安装了Rails_admin与设计,我想将/ admin仪表板限制为仅限管理员.目前我的代码看起来像:
config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,用户可以进入仪表板,因此我只希望用户表的admin列中具有布尔值true的用户可以访问仪表板.
你怎么建议我这样做?
我在编辑嵌套属性时遇到问题。我收到此错误:
no implicit conversion of Symbol into Integer
Run Code Online (Sandbox Code Playgroud)
事件.rb:
Class Event < ActiveRecord::Base
has_many :event_joins, :dependent => :destroy
accepts_nested_attributes_for :event_joins
end
Run Code Online (Sandbox Code Playgroud)
events_controller.rb :
private
def event_params
params.require(:event).permit(event_joins_attributes: [:duration])
end
Run Code Online (Sandbox Code Playgroud)
_form.html.erb :
=f.fields_for :event_joins_attributes do |a|
=number_field_tag 'event[event_joins_attributes][duration]'
end
Run Code Online (Sandbox Code Playgroud)
如果我改变了我params之前的许可
params[:event][:event_joins_attributes][:duration] = params[:event][:event_joins_attributes][:duration].to_i
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
no implicit conversion of String into Integer
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多关于大规模分配的嵌套属性的帖子,但没有任何效果。这是我读过的部分帖子。
rails-4-strong-parameters-nested-objects
当然,我不想做
params.require(:event).permit!
Run Code Online (Sandbox Code Playgroud) ruby-on-rails nested-attributes strong-parameters ruby-on-rails-4