Class: MigrationValidators::Spec::Matchers::DBMatchers::BaseDbMatcher
- Inherits:
-
Object
- Object
- MigrationValidators::Spec::Matchers::DBMatchers::BaseDbMatcher
- Defined in:
- lib/migration_validators/spec/matchers/db_matchers.rb
Instance Method Summary collapse
- #all(*values) ⇒ Object (also: #for_all_from, #for_all)
- #all? ⇒ Boolean
- #at_least_one(*values) ⇒ Object (also: #for_at_least_one_from, #for_at_least_one)
- #at_least_one? ⇒ Boolean
- #from(*values) ⇒ Object
- #initial(*values) ⇒ Object (also: #from_initial, #with_initial)
-
#initialize(*values) ⇒ BaseDbMatcher
constructor
A new instance of BaseDbMatcher.
- #insert(*values) ⇒ Object
- #insert? ⇒ Boolean
- #matches?(column_wrapper) ⇒ Boolean
- #message ⇒ Object
- #operations_array ⇒ Object
- #update(*values) ⇒ Object
- #update? ⇒ Boolean
- #update_and_insert(*values) ⇒ Object (also: #insert_and_update)
- #values ⇒ Object
- #with_message(message) ⇒ Object (also: #and_message)
Constructor Details
#initialize(*values) ⇒ BaseDbMatcher
Returns a new instance of BaseDbMatcher.
6 7 8 9 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 6 def initialize *values update_and_insert *values @all = true end |
Instance Method Details
#all(*values) ⇒ Object Also known as: for_all_from, for_all
46 47 48 49 50 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 46 def all *values @values = values.flatten @all = true self end |
#all? ⇒ Boolean
63 64 65 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 63 def all? @all end |
#at_least_one(*values) ⇒ Object Also known as: for_at_least_one_from, for_at_least_one
54 55 56 57 58 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 54 def at_least_one *values @values = values.flatten @all = false self end |
#at_least_one? ⇒ Boolean
67 68 69 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 67 def at_least_one? !all? end |
#from(*values) ⇒ Object
32 33 34 35 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 32 def from *values @values = values.flatten self end |
#initial(*values) ⇒ Object Also known as: from_initial, with_initial
11 12 13 14 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 11 def initial *values @initial = values self end |
#insert(*values) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 25 def insert *values @values = values.flatten @update = false @insert = true self end |
#insert? ⇒ Boolean
42 43 44 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 42 def insert? @insert end |
#matches?(column_wrapper) ⇒ Boolean
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 103 def matches? column_wrapper column_wrapper.insert(@initial) if @initial MigrationValidators::Spec::Support::ColumnWrapper.to_array(values).each do |value| passed = true if insert? column_wrapper.insert value passed = check_result(value, column_wrapper.last_exception, :insert) end if update? && passed column_wrapper.update value passed = check_result(value, column_wrapper.last_exception, :update) end return false if all? && !passed return true if passed && at_least_one? end all? end |
#message ⇒ Object
99 100 101 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 99 def @message || "" end |
#operations_array ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 84 def operations_array res = [] res << :update if update? res << :insert if insert? res end |
#update(*values) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 18 def update *values @values = values.flatten @update = true @insert = false self end |
#update? ⇒ Boolean
37 38 39 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 37 def update? @update end |
#update_and_insert(*values) ⇒ Object Also known as: insert_and_update
75 76 77 78 79 80 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 75 def update_and_insert *values @values = values.flatten @update = true @insert = true self end |
#values ⇒ Object
71 72 73 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 71 def values @values end |
#with_message(message) ⇒ Object Also known as: and_message
93 94 95 96 |
# File 'lib/migration_validators/spec/matchers/db_matchers.rb', line 93 def @message = self end |