I am querying a set of data using a custom model Stat based on ActiveRecord, using sqlite3. It is obvious that the total amount of data is more than 100, but when I do my querying of all data, it always returns 11 records, no more of other data, and I did not set any limit to the statement, but in console it just add a limit of 11. limit Below is my code:
2.5.1 001 > Stat.all …Run Code Online (Sandbox Code Playgroud) 我正在编写Rspec requests spec,在此之前我想使用构建一些测试数据FactoryBot.
现在我有一个模型Game:
class Game < ApplicationRecord
has_many :game_levels
Run Code Online (Sandbox Code Playgroud)
和模型GameLevel:
class GameLevel < ApplicationRecord
belongs_to :game
Run Code Online (Sandbox Code Playgroud)
在我的/spec/factories/game.rb:
FactoryBot.define do
factory :game do
name { :Mario }
end
end
Run Code Online (Sandbox Code Playgroud)
在我的spec/factories/game_level.rb:
FactoryBot.define do
factory :game_level do
name { :default }
min_level { 0 }
max_level { 100 }
game
end
end
Run Code Online (Sandbox Code Playgroud)
在我spec/requests/user_plays_game_spec.rb,我只是编写代码来创建游戏和game_level,并打印game.id,game_level.game_id.我发现它们不一样.此外,game.game_levels回报nil.
before(:all) do
@game = create(:game)
@game_level = create(:game_level) …Run Code Online (Sandbox Code Playgroud)