有没有办法改变视图的背景颜色DatePicker?我有以下选择器:
DatePicker(selection: $form.start, in: Date()..., displayedComponents: .date) {}
.padding(.vertical, 6)
.labelsHidden()
.accentColor(.black)
Run Code Online (Sandbox Code Playgroud)
但选择器在日期周围有灰色色调(见下图)。我只想整个背景都是白色的。我尝试过.background(Color.white),但这没有任何作用。如何让整个背景变成白色?
我正在测试我的控制器动作以进行练习。在我的控制器中,我只想从数据库中按名称获取所有不同的产品:
def shop
@products = Product.select('distinct on (name) *').sort_by &:order
end
Run Code Online (Sandbox Code Playgroud)
我已经手动检查过了,效果很好。现在,我使用我的RSpec设置测试,我想测试@products是一个大于0的数组:
RSpec.describe PagesController, type: :controller do
describe 'GET #shop' do
it 'should get all proudcts' do
get :shop
expect(assigns(:products).count).to be > 0
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在,我尝试了期望的几种不同组合...但是它一直告诉我它的值为nil或0,但我知道不是。如何测试一个数组大于0?
如何更改模态表背景?例如,如果我有:
Button(action: showAdditionalOptions) {
Image(systemName: "ellipsis")
.font(.system(size: 20))
.foregroundColor(Color.white)
}
.onTapGesture { showAdditionalOptions() }
.fullScreenCover(isPresented: $isShowingAdditionalOptions) {
AdditionalActions()
.background(Color.black.opacity(0.2))
}
Run Code Online (Sandbox Code Playgroud)
我想要达到的效果是一种模糊效果,当呈现一张纸时,其背景是模糊的并且部分透明。但是我无法更改工作表的背景。我只能修改工作表的内容背景。有没有办法将背景应用到工作表本身?
我是Rspec的新手,我正在尝试测试我的控制器方法的基本功能.我知道我不应该测试基本功能,但我更多的是为了学习而不是为了构建一些东西.
我有一个名为ProtocolsController的控制器.控制器用于基本CRUD功能.我正在尝试测试控制器#create方法.下面是我的#create控制器:
def create
@protocol = Protocol.new(protocol_params)
if @protocol.save
flash[:notice] = 'New protocol added'
redirect_back(fallback_location: 'test_results#index')
else
flash[:notice] = @protocol.errors[:name]
render 'new'
end
end
Run Code Online (Sandbox Code Playgroud)
为了测试悲伤路径,我想向控制器传递一个模拟对象,该对象包含用于创建Protocol类实例的必要参数.为此,我有以下代码:
describe '#create' do
it 'fails to save because the name already exists' do
params = FactoryGirl.attributes_for(:protocol)
post :create, :protocol => params
end
end
Run Code Online (Sandbox Code Playgroud)
现在我知道测试是不完整的,但我一次测试一行,当我运行Rspec时,我收到以下错误:
Failure/Error: post :create, :protocol => params
ArgumentError:
unknown keyword: protocol
Run Code Online (Sandbox Code Playgroud)
但是当我将帖子更改为: expect { post :create, :protocol => params }
有用.这让我想到了我的问题:
post :create, :protocol => params)失败了?任何对问题的见解都将非常感激.我一直在试图解决这个问题,我的猜测是,这是一个明显的答案.
在 5.0 FactoryBot 版本中,静态属性将被弃用,而必须使用动态属性。所以:
factory :product do
name 'Some Product'
end
Run Code Online (Sandbox Code Playgroud)
需要变成:
factory :product do
name { 'Some Product' }
end
Run Code Online (Sandbox Code Playgroud)
但是,在我的代码中,我简化了具有相同名称但使用循环增加计数的属性的分配:
factory :product do
(1..6).each do |n|
send "image_#{n}", "test_image.jpeg"
end
end
Run Code Online (Sandbox Code Playgroud)
基本上,在我的产品模型中,我有 6 个图像(image_1、image_2 等)。在上面的代码中,我遍历每个并为每个分配“test_image.jpeg”。如何使用动态属性执行此操作?
当您使用 SwiftUI 时,Form它会在前缘创建填充,这对Form输入很好,但我想向表单添加其他内容,例如占据整个屏幕宽度的图像,但因为图像在Form, 填充被应用,图像被稍微推离屏幕。如何删除所有Form填充?
struct MyForm: View {
var body: some View {
Form {
Image(uiImage: someImage)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: UIScreen.main.bounds.width)
TextField("Name", text: $name)
// Other fields
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道底层视图Form是UITableView我可以做的事情,比如UITableView.appearance().backgroundColor = .clear改变Form外观,但我不知道如何删除前导填充。
我也知道我可以将Image视图移到外面Form并将所有内容放在堆栈中,但这会产生我想避免的其他滚动问题。
I am using the gibbon gem to connect to MailChimp. I am trying to retrieve a user from my list using their email address. According to: https://github.com/amro/gibbon the way to do this is the following:
gibbon.lists(list_id).members(lower_case_md5_hashed_email_address).retrieve
Run Code Online (Sandbox Code Playgroud)
I can get everything to work e.g. adding a new user
gibbon.lists(list_id).members
.create(body: {email_address: "#{email}", status: 'subscribed'} )
Run Code Online (Sandbox Code Playgroud)
This works fine, but if I try to retrieve one record I get an error: Gibbon::MailChimpError: bad URI
I am 95% sure it's because I am …
我正在使用 运行测试Rspec, Capybara, Cucumber, and Selenium webdriver。对于我的应用程序,如果用户是第一次访问该网站,10 秒后会出现一个弹出窗口,要求用户注册新闻通讯。无论用户是否注册,都会将一个值保存到浏览器中local storage,指定用户已查看弹出窗口(我这样做是为了不会每次访问时都会弹出窗口)。
对于我的一些测试,弹出窗口会妨碍它,因为它会为每个新场景加载。我想要做的是在运行场景之前,在运行测试之前将值保存到本地存储,这样就不会出现弹出窗口。到目前为止,我有一个 before 钩子,它指定哪些场景不应该有弹出窗口:
Before('@no-newsletter') do
page.execute_script "window.localStorage.setItem('subscribed','viewed');"
end
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此命令时,我收到以下错误:
SecurityError: The operation is insecure. (Selenium::WebDriver::Error::JavascriptError)
Run Code Online (Sandbox Code Playgroud)
我不知道如何纠正此问题并将值保存到本地存储。有任何想法吗?
我有一个简单的控制器方法:
products = Product.where(name: name, color: color, size: size, available: true)
Run Code Online (Sandbox Code Playgroud)
它返回一个 Product::ActiveRecord_Relation 对象。我想取出第一个物体并拉出一个字段,例如products.first.product_code
但是这个和我尝试过的其他一些方法重新查询数据库。我试过了:
products[0].product_code
products.take.product_code
Run Code Online (Sandbox Code Playgroud)
所有这些都重新查询数据库,两次命中数据库。一次为哪里和一个上场。有没有一个不会影响数据库的简单解决方案?
有效的是将 ActiveRecord 转换为数组 ( products.to_a.[0].product_code) 但这似乎效率低下。
以下是显示两个单独命中的服务器日志:
这是我的控制器方法供参考:
def update_selection
size = params[:size]
color = params[:color]
name = params[:product_name]
products = Product.where(name: name, color: color, size: size, available: true)
product_code = products.empty? ? 'sold out' : products.first.product_code
respond_to do |format|
format.json { render json: { count: products.length, code: product_code}}
end
end
Run Code Online (Sandbox Code Playgroud) I am looking to create an association where a model can be created and owned by three different entities but also references the other two entities.
For example, I have a performance model where three different types of models can create a performance: venue, artist, band. However, the performance also needs to reference the other two e.g if a venue creates a performance, it needs to list an artist or a band that will be performing. And …
我有以下的Rails型号:Chat和Messages其中一个聊天可以有很多的消息。我有以下 Rails 查询,可以为用户作为收件人的每次聊天提取最后一条消息:
def index
messages = Message.where(recipient_id: id)
.select('DISTINCT ON ("chat_id") *')
.order(:chat_id, created_at)
end
Run Code Online (Sandbox Code Playgroud)
这为我提供了用户所在的每个聊天的用户的最后一条消息。我现在想按消息的创建时间对查询的结果进行排序,以便最新的消息显示在顶部。但是,如果我添加
sorted = messages.order(created_at: :desc)
它不会对第一个查询的结果进行排序,它只是将顺序附加到第一个查询(我知道这是预期的行为),因此我没有按创建日期获得排序列表。如何根据第一个查询的结果进行排序?基本上可以用 Rails 语法模仿以下内容:
SELECT *
FROM (SELECT DISTINCT ON (chat_id) *
FROM messages
ORDER BY chat_id, created_at DESC) last_messages
ORDER BY created_at DESC
Run Code Online (Sandbox Code Playgroud) ruby ×4
swiftui ×3
rspec ×2
rspec-rails ×2
swift ×2
activerecord ×1
associations ×1
capybara ×1
cucumber ×1
factory-bot ×1
gibbon ×1
ios ×1
postgresql ×1
rspec3 ×1
uikit ×1
unit-testing ×1