-
-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix have_db_column.with_options misspelled options
have_db_column().with_options() should raise an ArgumentError if receives a misspelled argument
- Loading branch information
1 parent
e19ebf2
commit 63b6321
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,8 @@ def have_db_column(column) | |
|
||
# @private | ||
class HaveDbColumnMatcher | ||
OPTIONS = %i(precision limit default null scale primary) | ||
|
||
def initialize(column) | ||
@column = column | ||
@options = {} | ||
|
@@ -95,7 +97,8 @@ def of_type(column_type) | |
end | ||
|
||
def with_options(opts = {}) | ||
%w(precision limit default null scale primary).each do |attribute| | ||
validate_options(opts) | ||
OPTIONS.each do |attribute| | ||
if opts.key?(attribute.to_sym) | ||
@options[attribute.to_sym] = opts[attribute.to_sym] | ||
end | ||
|
@@ -141,6 +144,13 @@ def description | |
|
||
protected | ||
|
||
def validate_options(opts) | ||
invalid_options = opts.keys.map(&:to_sym) - OPTIONS | ||
if invalid_options.any? | ||
raise ArgumentError, "Unknown option(s): #{invalid_options.map(&:inspect).join(", ")}" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mcmire
Collaborator
|
||
end | ||
end | ||
|
||
def column_exists? | ||
if model_class.column_names.include?(@column.to_s) | ||
true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rodriggochaves this broke a test I have