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

- old
+ new

@@ -13,21 +13,21 @@ end before { klass.destroy_all } - let(:candidates) { matchables + unmatchables } + let!(:candidates) { matchables + unmatchables } context "when query doesn't contain any key having an array-like value" do let(:matchables) do [ klass.create(number: 'A') ] end let(:unmatchables) do [ klass.create(number: 'X') ] end - let(:collection) { klass.where_multiple(query: { number: 'A' }) } + let!(:collection) { klass.where_multiple(query: { number: 'A' }) } it 'returns correct results' do expect(matchables).to be_all do |matchable| collection.include?(matchable) end @@ -37,10 +37,39 @@ end pending 'performs 1 query' end + context "when query contains a key with the value of an array containing a single item" do + + let(:matchables) do + [ + klass.create(number: 'A') + ] + end + let(:unmatchables) do + [ + 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 + + pending 'performs n queries' + + end + context "when query contains one key having an array-like value" do let(:matchables) do [ klass.create(number: 'A'), @@ -52,11 +81,11 @@ klass.create(number: 'X'), klass.create(number: 'Y') ] end - let(:collection) { klass.where_multiple(query: { number: ['A', 'B'] }) } + 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 @@ -86,10 +115,10 @@ 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'] }) } + 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