尝试了多种解决方案:
\n\n实际上,在 Apple M1 芯片 macOS Monterey 上无法安装另一个 Ruby 版本(3.1.0 安装没有问题)。
\n以下是已安装版本的详细信息:
\n\xe2\x9e\x9c ~ which openssl\n/opt/homebrew/opt/openssl@3/bin/openssl\n\xe2\x9e\x9c ~ openssl version -a\nOpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)\nbuilt on: Tue Dec 14 16:16:25 2021 UTC\nplatform: darwin64-arm64-cc\noptions: bn(64,64)\ncompiler: clang -fPIC -arch arm64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -D_REENTRANT -DOPENSSL_BUILDING_OPENSSL -DNDEBUG\nOPENSSLDIR: "/opt/homebrew/etc/openssl@3"\nENGINESDIR: "/opt/homebrew/Cellar/openssl@3/3.0.1/lib/engines-3"\nMODULESDIR: "/opt/homebrew/Cellar/openssl@3/3.0.1/lib/ossl-modules"\nSeeding source: os-specific\nCPUINFO: OPENSSL_armcap=0x7f\nRun Code Online (Sandbox Code Playgroud)\n.zshrc以下是设置后添加到文件中的行openssl:
export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"\nexport LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"\nexport CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"\nexport PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"\n\n# Add …Run Code Online (Sandbox Code Playgroud) 任何人都可以指出 - 在 Docker 容器内的 Rails API 应用程序上运行 RSpec 测试的最佳方法是什么(在容器构建/运行期间)?
目的是能够将开发环境与其他环境分开,并且仅在development模式下运行测试,仅在staging, production环境中启动 Puma 服务器。
bundle exec rspec在单独的entrypoint.sh脚本中、直接在Dockerfile、docker-compose.yml文件或其他解决方案中放置命令的正确位置是什么?
所有 Google 的结果以及PragProg 所著的Docker for Rails Developers一书都没有示例,运行它们提供的测试的唯一方法是针对已经运行的容器运行它们。
其实我的Dockerfile样子是这样的:
FROM ruby:2.6.1
RUN apt-get update -yqq
RUN apt-get install -yqq --no-install-recommends build-essential zip unzip libpq-dev libaio1 libaio-dev nodejs
ENV APP_HOME=/usr/src/app
ENV BUNDLE_PATH /gems
COPY . $APP_HOME
RUN echo "gem: --no-rdoc --no-ri" >> ~/.gemrc
WORKDIR $APP_HOME
RUN gem update --system
RUN …Run Code Online (Sandbox Code Playgroud) 我有一个简单的健康控制器定义如下:
@RestController
@RequestMapping("/admin")
public class AdminController {
@Value("${spring.application.name}")
String serviceName;
@GetMapping("/health")
String getHealth() {
return serviceName + " up and running";
}
}
Run Code Online (Sandbox Code Playgroud)
以及测试它的测试类:
@WebMvcTest(RedisController.class)
class AdminControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void healthShouldReturnDefaultMessage() throws Exception {
this.mockMvc.perform(get("/admin/health"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().string(containsString("live-data-service up and running")));
}
}
Run Code Online (Sandbox Code Playgroud)
运行测试时,我收到以下错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field configuration in com.XXXX.LiveDataServiceApplication required a bean of type 'com.XXXXX.AppConfiguration' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true) …Run Code Online (Sandbox Code Playgroud) 使用 Sequel 时,我仍然找不到解决关联工厂问题的解决方案。
我有两个模型依赖于one_to_many,这与has_manyActive Record 中的相同,以及 与 Active Recordmany_to_one中的相同belongs_to。
以下是定义的工厂:
FactoryGirl.define do
to_create { |instance| instance.save }
factory :post do
title "some title"
end
end
FactoryGirl.define do
to_create { |instance| instance.save }
factory :comment do
content "some content"
association :post, strategy: :build
end
end
Run Code Online (Sandbox Code Playgroud)
运行时build(:comment),它失败了:
Associated object does not have a primary key.
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?我总是可以先构建/创建一个帖子,然后在评论中签名,但这很乏味。不仅如此,我还必须删除association :post, strategy: :build并使用一些 Integer 随机值。
我正在使用:
factory_girl_rails 4.8.0ruby 2.4.0sequel-rails 0.9.15sequel 4.45.0我用谷歌搜索了一下,找到了一种适当且易于实现的方法来为现有的 Rails API 应用程序生成Swagger文档。简而言之,有两种实现方式:通过控制器、模型或通过 Rspec 控制器/请求规范。列表不会太长,选择也不是那么容易:
有人知道其他 gems 可以为现有的 Rails API 应用程序生成 Swagger 文档吗?欢迎任何建议!谢谢你。
我按照这篇博客文章尝试实现一个自定义验证器来验证复合主键约束,但它失败了:
javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: com.directory.domain.model.validators.StorePoolValidator.
at com.directory.domain.repositories.StorePoolRepositoryTest.shouldReturnPoolByStore(StorePoolRepositoryTest.java:30)
Caused by: java.lang.NoSuchMethodException: com.directory.domain.model.validators.StorePoolValidator.<init>()
at com.directory.domain.repositories.StorePoolRepositoryTest.shouldReturnPoolByStore(StorePoolRepositoryTest.java:30)
Run Code Online (Sandbox Code Playgroud)
下面是验证器的注解接口的代码:
javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: com.directory.domain.model.validators.StorePoolValidator.
at com.directory.domain.repositories.StorePoolRepositoryTest.shouldReturnPoolByStore(StorePoolRepositoryTest.java:30)
Caused by: java.lang.NoSuchMethodException: com.directory.domain.model.validators.StorePoolValidator.<init>()
at com.directory.domain.repositories.StorePoolRepositoryTest.shouldReturnPoolByStore(StorePoolRepositoryTest.java:30)
Run Code Online (Sandbox Code Playgroud)
这是验证器类:
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
@Target({FIELD})
@Constraint(validatedBy = StorePoolValidator.class)
public @interface UniqueStorePoolConstraint {
String message() default "Store pool validation failed";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Run Code Online (Sandbox Code Playgroud)
这是实体类:
import javax.validation.ConstraintValidator;
import …Run Code Online (Sandbox Code Playgroud) 我正在使用 gemnokogiri来废弃img标签src值。有时url不显示带扩展名的图像文件名。
所以我试图检测图像MIME类型如下:
MIME::Types.type_for("http://web.com/img/12457634").first.content_type # => "image/gif"
Run Code Online (Sandbox Code Playgroud)
但它显示错误:
undefined method `content_type' for nil:NilClass (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?
正如标题所说,我想知道如果produces = MediaType.APPLICATION_JSON_VALUE控制器已经用 注释,我是否还需要在控制器的方法中声明@RestController?我正在开发一个旧的遗留应用程序,其中所有控制器方法都声明了这一点。Spring Boot Initializr 会在没有它的情况下生成默认的 REST 控制器,即使我省略它MediaType.APPLICATION_JSON_VALUE,它仍然可以正常工作。我记得在某个地方看到过应该是默认的。正确与否?
@RestController
@RequestMapping("/posts")
@Slf4j
public class PostsController {
@PutMapping(value = "posts/{post_d}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Post> getPost(@PathVariable Long postId) {
...
}
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释负数除法的以下结果:
2.6.1 :001 > -25/24
=> -2
2.6.1 :002 > 25/24
=> 1
Run Code Online (Sandbox Code Playgroud)
为什么是它-2而不是-1?
更多关于奇怪行为的例子:
2.6.1 :003 > 24/25
=> 0
2.6.1 :004 > -24/25
=> -1
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢你。
我使用asdf安装了 Java 17 版本,它在 Java 项目中运行没有任何问题:
\n\xe2\x9e\x9c ~ asdf list java\n adoptopenjdk-17.0.0+35\nRun Code Online (Sandbox Code Playgroud)\n但是在终端中检查java版本时java -version,显示以下错误:
~ java -version\n/Users/xxx/.asdf/shims/java: line 3: /opt/homebrew/Cellar/asdf/0.8.1_1/libexec/bin/asdf: No such file or directory\n/Users/xxx/.asdf/shims/java: line 3: exec: /opt/homebrew/Cellar/asdf/0.8.1_1/libexec/bin/asdf: cannot execute: No such file or directory\nRun Code Online (Sandbox Code Playgroud)\n我正在使用 Oh My Zsh 终端和以下行:
\n. /opt/homebrew/opt/asdf/libexec/asdf.sh\nRun Code Online (Sandbox Code Playgroud)\n安装后添加 oasdf是文件中的最后一个.zshrc。
这有什么问题吗?谢谢。
\nruby ×3
java ×2
spring-boot ×2
adoptopenjdk ×1
asdf-vm ×1
docker ×1
factory-bot ×1
html ×1
macos ×1
mime ×1
openssl ×1
rails-api ×1
rspec-rails ×1
rvm ×1
sequel ×1
spring-mvc ×1
swagger-2.0 ×1
swagger-ui ×1