Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for testing the :conditions option on associations
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
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 |
---|---|---|
|
@@ -72,6 +72,11 @@ def order(order) | |
@order = order | ||
self | ||
end | ||
|
||
def conditions(conditions) | ||
@conditions = conditions | ||
self | ||
end | ||
|
||
def matches?(subject) | ||
@subject = subject | ||
|
@@ -81,6 +86,7 @@ def matches?(subject) | |
through_association_valid? && | ||
dependent_correct? && | ||
order_correct? && | ||
conditions_correct? && | ||
join_table_exists? | ||
end | ||
|
||
|
@@ -175,6 +181,15 @@ def order_correct? | |
end | ||
end | ||
|
||
def conditions_correct? | ||
if @conditions.nil? || @conditions.to_s == reflection.options[:conditions].to_s | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Hakon
Author
Contributor
|
||
true | ||
else | ||
@missing = "#{@name} should have the following conditions: #{@conditions}" | ||
false | ||
end | ||
end | ||
|
||
def join_table_exists? | ||
if @macro != :has_and_belongs_to_many || | ||
::ActiveRecord::Base.connection.tables.include?(join_table.to_s) | ||
|
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
Need casting to string?