Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Association matchers now support :source option
- Loading branch information
Showing
6 changed files
with
69 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
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
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
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
40 changes: 40 additions & 0 deletions
40
lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Shoulda # :nodoc: | ||
module Matchers | ||
module ActiveRecord # :nodoc: | ||
module AssociationMatchers | ||
class SourceMatcher | ||
attr_accessor :missing_option | ||
|
||
def initialize(source, name) | ||
@source = source | ||
@name = name | ||
@missing_option = '' | ||
end | ||
|
||
def description | ||
"source => #{source}" | ||
end | ||
|
||
def matches?(subject) | ||
self.subject = ModelReflector.new(subject, name) | ||
|
||
if option_verifier.correct_for_string?(:source, source) | ||
true | ||
else | ||
self.missing_option = "#{name} should have #{source} as source option" | ||
false | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_accessor :subject, :source, :name | ||
|
||
def option_verifier | ||
@option_verifier ||= OptionVerifier.new(subject) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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