Skip to content

Commit

Permalink
added #empty? to MySql2::Result
Browse files Browse the repository at this point in the history
  • Loading branch information
walf443 committed Sep 17, 2018
1 parent c578718 commit bdb3949
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mysql2/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module Mysql2
class Result
attr_reader :server_flags

def empty?
count.zero?
end

include Enumerable
end
end
13 changes: 13 additions & 0 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
r = @client.query "SELECT 1"
expect(r.count).to eql(1)
expect(r.size).to eql(1)
expect(r.empty?).to eq(false)
end

context "metadata queries" do
Expand All @@ -53,6 +54,18 @@
end
end

context "#empty?" do
it "should return true when result is not exists" do
r = @client.query "SELECT * FROM mysql2_test WHERE 0 = 1"
expect(r).to be_empty
end

it "should return false when result exists" do
r = @client.query "SELECT 1"
expect(r).not_to be_empty
end
end

context "#each" do
it "should yield rows as hash's" do
@result.each do |row|
Expand Down

0 comments on commit bdb3949

Please sign in to comment.