Permalink
Browse files

Removed whitespace

  • Loading branch information...
1 parent 1d3a639 commit fac0d7807ead4fc3a342632cec4f47271afddcc3 @bcardarella committed Mar 15, 2011
@@ -18,3 +18,4 @@ module Mongoid
config.include(Remarkable::Mongoid::Matchers)
end
end
+
@@ -49,3 +49,4 @@ def humanized_options
end
end
end
+
@@ -12,7 +12,7 @@ module Matchers
def reference_one(attr)
RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::One)
end
-
+
# Specify the document references many documents
#
# examples:
@@ -36,7 +36,7 @@ def reference_many(attr)
def reference_many_and_be_referenced_in(attr)
RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::ManyToMany)
end
-
+
# Specify the document is referenced in another document
#
# examples:
@@ -60,7 +60,7 @@ def be_referenced_in(attr)
def embed_one(attr)
RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::One)
end
-
+
# Specify the document embeds many documents
#
# examples:
@@ -72,7 +72,7 @@ def embed_one(attr)
def embed_many(attr)
RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::Many)
end
-
+
# Specify the document is embedded in another document
#
# examples:
@@ -84,7 +84,7 @@ def embed_many(attr)
def be_embedded_in(attr)
RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::In)
end
-
+
class RelationMatcher
attr_accessor :attr, :relation_type
@@ -102,16 +102,17 @@ def matches?(subject)
def description
"has #{humanized_relation} relation :#{attr}"
end
-
+
def failure_message_for_should
"\n#{humanized_relation} relation failure\nExpected: '#{attr}'"
end
-
+
private
-
+
def humanized_relation
relation_type.to_s.split('::').last
end
end
end
end
+
@@ -12,14 +12,14 @@ module Matchers
def validate_association(attr)
ValidateAssociationMatcher.new(attr)
end
-
+
class ValidateAssociationMatcher
attr_accessor :attr
def initialize(attr)
self.attr = attr.to_sym
end
-
+
def matches?(subject)
@subject = subject
validations = @subject._validators[attr]
@@ -33,8 +33,9 @@ def description
def failure_message_for_should
"\nAssociation validation failure\nExpected: #{@subject.class} to validate the '#{attr}' association"
end
-
+
end
-
+
end
end
+
@@ -12,19 +12,19 @@ module Matchers
def validate_uniqueness_of(attr)
ValidateUniquenessOfMatcher.new(attr)
end
-
+
class ValidateUniquenessOfMatcher
attr_accessor :attr, :validation_type, :message, :scope
def initialize(attr)
self.attr = attr.to_sym
end
-
+
def with_message(message)
self.message = message
self
end
-
+
def scoped_to(scope)
self.scope = scope.to_sym
self
@@ -48,9 +48,9 @@ def description
def failure_message_for_should
"\nUniqueness validation failure\nExpected: '#{attr}' to be unique"
end
-
+
private
-
+
def check_option(validation, option)
if self.send(option)
validation.options[option] == self.send(option)
@@ -59,6 +59,7 @@ def check_option(validation, option)
end
end
end
-
+
end
end
+
@@ -3,3 +3,4 @@ module Mongoid
VERSION = '0.5.2'
end
end
+
View
@@ -30,7 +30,7 @@ def self.add_dirty_methods(*args); end
matcher.matches?(SingleBook.new).should be_false
end
end
-
+
context 'with given type' do
it 'should be true for a book with field published_on of type Date' do
matcher = @should.have_field :published_on, :type => Date
@@ -74,3 +74,4 @@ def self.add_dirty_methods(*args); end
end
end
end
+
View
@@ -8,7 +8,7 @@ class Should
@should = Should.new
end
-
+
context 'embedding' do
before :all do
class SingleBook
@@ -17,7 +17,7 @@ class SingleBook
embeds_many :pages, :class_name => "SinglePage"
embeds_one :author, :class_name => "SingleAuthor"
end
-
+
class SinglePage
include Mongoid::Document
@@ -30,38 +30,38 @@ class SinglePage
matcher = @should.embed_one :author
matcher.matches?(SingleBook.new).should be_true
end
-
+
it 'should be false for a book embedding one publisher' do
matcher = @should.embed_one :publisher
matcher.matches?(SingleBook.new).should be_false
end
end
-
+
describe 'embed_many' do
it 'should be true for a book embedding many pages' do
matcher = @should.embed_many :pages
matcher.matches?(SingleBook.new).should be_true
end
-
+
it 'should be false for a book embedding many words' do
matcher = @should.embed_many :words
matcher.matches?(SingleBook.new).should be_false
end
end
-
+
describe 'embedded_in' do
it 'should be true for a page embedded in a book' do
matcher = @should.be_embedded_in :book
matcher.matches?(SinglePage.new).should be_true
end
-
+
it 'should be false for a page embedded in a newspaper' do
matcher = @should.be_embedded_in :newspaper
matcher.matches?(SinglePage.new).should be_false
end
end
end
-
+
context 'referencing' do
before :all do
class SingleOwner
@@ -71,7 +71,7 @@ class SingleOwner
references_one :friend, :class_name => "SingleFriend"
references_and_referenced_in_many :turtles, :class_name => "SingleTurtle"
end
-
+
class SingleDog
include Mongoid::Document
@@ -88,19 +88,19 @@ class SingleTurtle
matcher = @should.reference_one :friend
matcher.matches?(SingleOwner.new).should be_true
end
-
+
it 'should be false for an owner having one boss' do
matcher = @should.reference_one :boss
matcher.matches?(SingleOwner.new).should be_false
end
end
-
+
describe 'reference_many' do
it 'should be true for an owner having many dogs' do
matcher = @should.reference_many :dogs
matcher.matches?(SingleOwner.new).should be_true
end
-
+
it 'should be false for an owner having many cats' do
matcher = @should.reference_many :cats
matcher.matches?(SingleOwner.new).should be_false
@@ -121,33 +121,34 @@ class SingleTurtle
matcher.matches?(SingleOwner.new).should be_false
end
end
-
+
describe 'be_referenced_in' do
it 'should be true for a dog belonging to an owner' do
matcher = @should.be_referenced_in :owner
matcher.matches?(SingleDog.new).should be_true
end
-
+
it 'should be false for a dog belonging to a cat' do
matcher = @should.be_referenced_in :stranger
matcher.matches?(SingleDog.new).should be_false
end
end
end
-
+
context 'messages' do
before do
@relation_matcher = Remarkable::Mongoid::Matchers::RelationMatcher.new(:test, "Some::Test")
end
-
+
describe 'description' do
subject { @relation_matcher.description }
it { should == "has Test relation :test" }
end
-
+
describe 'failure_message_for_should' do
subject { @relation_matcher.failure_message_for_should }
it { should == "\nTest relation failure\nExpected: 'test'"}
end
end
end
+
@@ -10,4 +10,5 @@
it 'should include the Remarkable ActiveModel validation matchers' do
defined?(Remarkable::ActiveModel).should be_true
end
-end
+end
+
View
@@ -14,3 +14,4 @@
RSpec.configure do |config|
config.mock_with :mocha
end
+
@@ -5,50 +5,51 @@
class Should
include Remarkable::Mongoid::Matchers
end
-
+
@should = Should.new
end
-
+
describe 'validate_association' do
before do
class SingleBook
include Mongoid::Validations
validates_associated :pages
end
end
-
+
after do
Object.send(:remove_const, :SingleBook)
end
-
+
it 'should be true for a book validating the association :pages' do
matcher = @should.validate_association :pages
matcher.matches?(SingleBook.new).should be_true
end
-
+
it 'should be false for a book validating the association :author' do
matcher = @should.validate_association :author
matcher.matches?(SingleBook.new).should be_false
end
end
-
+
context 'messages' do
before do
matcher_subject = mock('SingleBook')
matcher_subject.stubs(:class).returns('SingleBook')
@association_matcher = Remarkable::Mongoid::Matchers::ValidateAssociationMatcher.new(:test)
@association_matcher.instance_variable_set('@subject', matcher_subject)
end
-
+
describe 'description' do
subject { @association_matcher.description }
it { should == "validates the :test association" }
end
-
+
describe 'failure_message_for_should' do
subject { @association_matcher.failure_message_for_should }
it { should == "\nAssociation validation failure\nExpected: SingleBook to validate the 'test' association" }
end
end
-
+
end
+
Oops, something went wrong.

0 comments on commit fac0d78

Please sign in to comment.