spec/models/journey/resource/where_multiple_spec.rb in embark-journey-0.1.0 vs spec/models/journey/resource/where_multiple_spec.rb in embark-journey-0.1.1

- old
+ new

@@ -14,35 +14,46 @@ before { klass.destroy_all } let!(:candidates) { matchables + unmatchables } + let(:collection) { klass.where_multiple(clauses) } + let(:count) { klass.count_multiple(clauses) } context "when query doesn't contain any key having an array-like value" do + let(:clauses) do + { query: { number: 'A' } } + end + let(:matchables) do [ klass.create(number: 'A') ] end let(:unmatchables) do [ klass.create(number: 'X') ] end - let!(:collection) { klass.where_multiple(query: { number: 'A' }) } it 'returns correct results' do expect(matchables).to be_all do |matchable| collection.include?(matchable) end expect(unmatchables).not_to be_any do |unmatchable| collection.include?(unmatchable) end end + it 'counts correctly' do + expect(count).to eq 1 + end + pending 'performs 1 query' end context "when query contains a key with the value of an array containing a single item" do - + let(:clauses) do + { query: { number: ['A'] }, sort: { number: :desc } } + end let(:matchables) do [ klass.create(number: 'A') ] end @@ -50,28 +61,31 @@ [ klass.create(number: 'B') ] end - let!(:collection) { klass.where_multiple(query: { number: ['A'] }, sort: { number: :desc }) } - it 'returns correct results' do - collection expect(matchables).to be_all do |matchable| collection.include?(matchable) end expect(unmatchables).not_to be_any do |unmatchable| collection.include?(unmatchable) end end + it 'counts correctly' do + expect(count).to eq 1 + end + pending 'performs n queries' end context "when query contains one key having an array-like value" do - + let(:clauses) do + { query: { number: ['A', 'B'] } } + end let(:matchables) do [ klass.create(number: 'A'), klass.create(number: 'B') ] @@ -81,26 +95,31 @@ klass.create(number: 'X'), klass.create(number: 'Y') ] end - let!(:collection) { klass.where_multiple(query: { number: ['A', 'B'] }) } - it 'returns correct results' do expect(matchables).to be_all do |matchable| collection.include?(matchable) end expect(unmatchables).not_to be_any do |unmatchable| collection.include?(unmatchable) end end + it 'counts correctly' do + expect(count).to eq 2 + end + pending 'performs n queries' end context "when query contains two keys having array-like values" do + let(:clauses) do + { query: { number: ['A', 'B'], flash_number: ['1', '2'] } } + end let(:matchables) do [ klass.create(number: 'A', flash_number: '1'), klass.create(number: 'A', flash_number: '2'), klass.create(number: 'B', flash_number: '1'), @@ -115,18 +134,20 @@ klass.create(number: 'C', flash_number: '2'), klass.create(number: 'C', flash_number: '3'), ] end - let!(:collection) { klass.where_multiple(query: { number: ['A', 'B'], flash_number: ['1', '2'] }) } - it 'returns correct results' do expect(matchables).to be_all do |matchable| collection.include?(matchable) end expect(unmatchables).not_to be_any do |unmatchable| collection.include?(unmatchable) end + end + + it 'counts correctly' do + expect(count).to eq 4 end pending 'performs m * n queries' end