|
32 | 32 | size_window(:small, :portrait) |
33 | 33 | end |
34 | 34 |
|
35 | | - [:count, :empty?, :any?].each do |method| |
| 35 | + %i[count empty? any? none?].each do |method| |
36 | 36 | it "will not retrieve the entire collection when using #{method}" do |
37 | 37 | FactoryBot.create(:test_model) |
38 | 38 |
|
39 | | - expect_promise(<<-RUBY |
40 | | - Hyperstack::Model |
41 | | - .load { TestModel.#{method} } |
42 | | - .then do |val| |
43 | | - if TestModel.all.instance_variable_get('@collection') |
44 | | - "unnecessary fetch of all" |
45 | | - else |
46 | | - val |
| 39 | + expect_promise( |
| 40 | + <<~RUBY |
| 41 | + Hyperstack::Model |
| 42 | + .load { TestModel.#{method} } |
| 43 | + .then do |val| |
| 44 | + if TestModel.all.instance_variable_get('@collection') |
| 45 | + "unnecessary fetch of all" |
| 46 | + else |
| 47 | + val |
| 48 | + end |
47 | 49 | end |
48 | | - end |
49 | | - RUBY |
50 | | - ).to eq(TestModel.all.send(method)) |
| 50 | + RUBY |
| 51 | + ).to eq(TestModel.all.send(method)) |
51 | 52 | end |
52 | 53 | end |
53 | 54 |
|
54 | | - it 'will retrieve the entire collection when using any? if an arg is passed in' do |
55 | | - FactoryBot.create(:test_model) |
| 55 | + %i[any? none?].each do |method| |
| 56 | + it 'will retrieve the entire collection when using any? if an arg is passed in' do |
| 57 | + FactoryBot.create(:test_model) |
56 | 58 |
|
57 | | - expect_promise( |
58 | | - <<~RUBY |
59 | | - Hyperstack::Model.load do |
60 | | - TestModel.any?(TestModel) |
61 | | - end.then do |val| |
62 | | - if TestModel.all.instance_variable_get('@collection') |
63 | | - 'necessary fetch of all' |
64 | | - else |
65 | | - val |
| 59 | + expect_promise( |
| 60 | + <<~RUBY |
| 61 | + Hyperstack::Model.load do |
| 62 | + TestModel.#{method}(TestModel) |
| 63 | + end.then do |val| |
| 64 | + if TestModel.all.instance_variable_get('@collection') |
| 65 | + 'necessary fetch of all' |
| 66 | + else |
| 67 | + val |
| 68 | + end |
66 | 69 | end |
67 | | - end |
68 | | - RUBY |
69 | | - ).to eq('necessary fetch of all') |
70 | | - end |
| 70 | + RUBY |
| 71 | + ).to eq('necessary fetch of all') |
| 72 | + end |
71 | 73 |
|
72 | | - it 'will retrieve the entire collection when using any? if a block is passed in' do |
73 | | - FactoryBot.create(:test_model) |
| 74 | + it 'will retrieve the entire collection when using any? if a block is passed in' do |
| 75 | + FactoryBot.create(:test_model) |
74 | 76 |
|
75 | | - expect_promise( |
76 | | - <<~RUBY |
77 | | - Hyperstack::Model.load do |
78 | | - TestModel.any? { |test_model| test_model } |
79 | | - end.then do |val| |
80 | | - if TestModel.all.instance_variable_get('@collection') |
81 | | - 'necessary fetch of all' |
82 | | - else |
83 | | - val |
| 77 | + expect_promise( |
| 78 | + <<~RUBY |
| 79 | + Hyperstack::Model.load do |
| 80 | + TestModel.#{method} { |test_model| test_model } |
| 81 | + end.then do |val| |
| 82 | + if TestModel.all.instance_variable_get('@collection') |
| 83 | + 'necessary fetch of all' |
| 84 | + else |
| 85 | + val |
| 86 | + end |
84 | 87 | end |
85 | | - end |
86 | | - RUBY |
87 | | - ).to eq('necessary fetch of all') |
| 88 | + RUBY |
| 89 | + ).to eq('necessary fetch of all') |
| 90 | + end |
88 | 91 | end |
89 | 92 | end |
0 commit comments