class RSpec::Matchers::Sequel::HavePrimaryKey
Public Class Methods
new(*names)
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 29 def initialize(*names) @names = names @keys = [] end
Public Instance Methods
description()
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 15 def description %(have #{wording(@names)}) end
failure_message()
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 19 def failure_message %(expected #{@table} to #{description} but #{@table} have #{wording(@keys)}) end
failure_message_when_negated()
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 23 def failure_message_when_negated %(did not expect #{@table} to #{description}) end
matches?(subject)
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 7 def matches?(subject) @table = subject get_keys includes_all? end
Private Instance Methods
get_keys()
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 34 def get_keys @keys = DB.schema(@table).reject { |tuple| !tuple.last[:primary_key] }.map(&:first) end
includes_all?()
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 38 def includes_all? @names.reject { |k| @keys.include?(k) }.empty? end
wording(arr)
click to toggle source
# File lib/rspec/sequel_expectations/matchers/have_primary_key.rb, line 42 def wording(arr) case arr.length when 0 %(no primary keys) when 1 %(primary key "#{arr.first}") else %(primary keys #{arr.inspect}) end end