remarkable_mongoid 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ doc/*
6
+ .yardoc/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create default@remarkable_mongoid > /dev/null
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
data/HISTORY.txt ADDED
@@ -0,0 +1,7 @@
1
+ ## 0.5.2
2
+ * Updated README
3
+
4
+ ## 0.5.1
5
+ * Updated for mongoid-2.0.0.rc.6
6
+ * reference_many_as_array Matcher is gone, replaced with the reference_many_and_be_referenced_in Matcher
7
+ * Added YARD documentation
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Brian Cardarella
1
+ Copyright (c) 2010 - 2011 Brian Cardarella
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -1,5 +1,5 @@
1
1
  # remarkable_mongoid
2
- NOTE: This gem is based upon the 2.0 beta of Mongoid and the 4.0 alpha of Remarkable
2
+ NOTE: This gem is based upon the 2.0 Release Candidate of Mongoid and the 4.0 alpha of Remarkable
3
3
 
4
4
  RSpec Matchers for Mongoid
5
5
 
@@ -14,6 +14,7 @@ Associations
14
14
  * reference_one
15
15
  * reference_many
16
16
  * be_referenced_in
17
+ * reference_many_and_be_referenced_in
17
18
  * embed_one
18
19
  * embed_many
19
20
  * be_embedded_in
@@ -38,4 +39,4 @@ Validations
38
39
 
39
40
  ## Copyright
40
41
 
41
- Copyright (c) 2010 Brian Cardarella. See LICENSE for details.
42
+ Copyright (c) 2010 - 2011 Brian Cardarella. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -1,5 +1,17 @@
1
1
  module Remarkable::Mongoid
2
2
  module Matchers
3
+
4
+ # Specify the document should have a field
5
+ #
6
+ # examples:
7
+ # it { should have_field :name }
8
+ # it { should have_field :age, :type => Integer, :default => 0 }
9
+ #
10
+ # @param [Symbol, Hash] options
11
+ # @option options [Class] :type The data type
12
+ # @option options :default The default value for this field
13
+ #
14
+ # @return [Remarkable::Mongoid::Matchers::HasFieldMatcher]
3
15
  def have_field(field, options = {})
4
16
  HasFieldMatcher.new(field, options)
5
17
  end
@@ -9,11 +21,11 @@ module Remarkable::Mongoid
9
21
 
10
22
  def initialize(field, options)
11
23
  self.field = field.to_s
12
- self.options = { :type => String }.merge(options)
24
+ self.options = { :type => Object }.merge(options)
13
25
  end
14
26
 
15
27
  def matches?(subject)
16
- @subject = subject.is_a?(Class) ? subject : subject.class
28
+ @subject = subject.is_a?(Class) ? subject : subject.class
17
29
  @subject.fields.has_key?(field) && (@subject.fields[field].type == options[:type])
18
30
  end
19
31
 
@@ -0,0 +1,117 @@
1
+ module Remarkable::Mongoid
2
+ module Matchers
3
+
4
+ # Specify the document references another document
5
+ #
6
+ # examples:
7
+ # it { should reference_one :dog }
8
+ #
9
+ # @param [Symbol]
10
+ #
11
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
12
+ def reference_one(attr)
13
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::One)
14
+ end
15
+
16
+ # Specify the document references many documents
17
+ #
18
+ # examples:
19
+ # it { should reference_many :dogs }
20
+ #
21
+ # @param [Symbol]
22
+ #
23
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
24
+ def reference_many(attr)
25
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::Many)
26
+ end
27
+
28
+ # Specify the document references many documents and is referenced in many documents
29
+ #
30
+ # examples:
31
+ # it { should reference_many_and_be_referenced_in :dog }
32
+ #
33
+ # @param [Symbol]
34
+ #
35
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
36
+ def reference_many_and_be_referenced_in(attr)
37
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::ManyToMany)
38
+ end
39
+
40
+ # Specify the document is referenced in another document
41
+ #
42
+ # examples:
43
+ # it { should be_referenced_in :dog }
44
+ #
45
+ # @param [Symbol]
46
+ #
47
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
48
+ def be_referenced_in(attr)
49
+ RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::In)
50
+ end
51
+
52
+ # Specify the document embeds another document
53
+ #
54
+ # examples:
55
+ # it { should embed_one :dog }
56
+ #
57
+ # @param [Symbol]
58
+ #
59
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
60
+ def embed_one(attr)
61
+ RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::One)
62
+ end
63
+
64
+ # Specify the document embeds many documents
65
+ #
66
+ # examples:
67
+ # it { should embed_many :dog }
68
+ #
69
+ # @param [Symbol]
70
+ #
71
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
72
+ def embed_many(attr)
73
+ RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::Many)
74
+ end
75
+
76
+ # Specify the document is embedded in another document
77
+ #
78
+ # examples:
79
+ # it { should be_embedded_in :dog }
80
+ #
81
+ # @param [Symbol]
82
+ #
83
+ # @return [Remarkable::Mongoid::Matchers::RelationMatcher]
84
+ def be_embedded_in(attr)
85
+ RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::In)
86
+ end
87
+
88
+ class RelationMatcher
89
+ attr_accessor :attr, :relation_type
90
+
91
+ def initialize(attr, relation_type)
92
+ self.attr = attr.to_s
93
+ self.relation_type = relation_type
94
+ end
95
+
96
+ def matches?(subject)
97
+ @subject = subject
98
+ relations = @subject.relations.select { |k,v| v.relation == relation_type }
99
+ relations.detect { |k| k.first == attr } != nil
100
+ end
101
+
102
+ def description
103
+ "has #{humanized_relation} relation :#{attr}"
104
+ end
105
+
106
+ def failure_message_for_should
107
+ "\n#{humanized_relation} relation failure\nExpected: '#{attr}'"
108
+ end
109
+
110
+ private
111
+
112
+ def humanized_relation
113
+ relation_type.to_s.split('::').last
114
+ end
115
+ end
116
+ end
117
+ end
@@ -1,5 +1,14 @@
1
1
  module Remarkable::Mongoid
2
2
  module Matchers
3
+
4
+ # Specify the document validates the association
5
+ #
6
+ # examples:
7
+ # it { should validate_association :dog }
8
+ #
9
+ # @param [Symbol]
10
+ #
11
+ # @return [Remarkable::Mongoid::Matchers::ValidateAssociationMatcher]
3
12
  def validate_association(attr)
4
13
  ValidateAssociationMatcher.new(attr)
5
14
  end
@@ -28,4 +37,4 @@ module Remarkable::Mongoid
28
37
  end
29
38
 
30
39
  end
31
- end
40
+ end
@@ -1,5 +1,14 @@
1
1
  module Remarkable::Mongoid
2
2
  module Matchers
3
+
4
+ # Specify the document validates the uniqueness of the field's data
5
+ #
6
+ # examples:
7
+ # it { should validate_uniqueness_of :dog }
8
+ #
9
+ # @param [Symbol]
10
+ #
11
+ # @return [Remarkable::Mongoid::Matchers::ValidateUniquenessOfMatcher]
3
12
  def validate_uniqueness_of(attr)
4
13
  ValidateUniquenessOfMatcher.new(attr)
5
14
  end
@@ -52,4 +61,4 @@ module Remarkable::Mongoid
52
61
  end
53
62
 
54
63
  end
55
- end
64
+ end
@@ -0,0 +1,5 @@
1
+ module Remarkable
2
+ module Mongoid
3
+ VERSION = '0.5.2'
4
+ end
5
+ end
@@ -5,7 +5,7 @@ end
5
5
 
6
6
  require 'remarkable/active_model'
7
7
  require 'remarkable/mongoid/fields'
8
- require 'remarkable/mongoid/associations'
8
+ require 'remarkable/mongoid/relations'
9
9
  require 'remarkable/mongoid/validate_uniqueness_of'
10
10
  require 'remarkable/mongoid/validate_association'
11
11
 
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'remarkable/mongoid/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'remarkable_mongoid'
7
+ s.version = Remarkable::Mongoid::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Brian Cardarella']
10
+ s.email = ['bcardarella@gmail.com']
11
+ s.homepage = 'https://github.com/bcardarella/remarkable_mongoid'
12
+ s.description = 'RSpec Matchers for Mongoid'
13
+ s.summary = 'RSpec Matchers for Mongoid'
14
+
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_dependency 'remarkable_activemodel', '~> 4.0.0.alpha4'
22
+
23
+ s.add_development_dependency 'bson_ext'
24
+ s.add_development_dependency 'activesupport', '~> 3.0.0'
25
+ s.add_development_dependency 'mongoid', '~> 2.0.0.rc.6'
26
+ s.add_development_dependency 'rspec'
27
+ s.add_development_dependency 'bourne'
28
+
29
+ ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
30
+ if ruby_minor_version == 8
31
+ s.add_development_dependency 'ruby-debug'
32
+ elsif ruby_minor_version == 9
33
+ s.add_development_dependency 'ruby-debug19'
34
+ end
35
+
36
+ end
data/spec/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --debugger
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mongoid Fields' do
4
+ before :all do
5
+ class Should
6
+ include Remarkable::Mongoid::Matchers
7
+ end
8
+
9
+ @should = Should.new
10
+ end
11
+
12
+ describe 'have_field' do
13
+ before :all do
14
+ class SingleBook
15
+ def self.add_dirty_methods(*args); end
16
+ include Mongoid::Fields
17
+ field :name
18
+ field :published_on, :type => Date
19
+ end
20
+ end
21
+
22
+ context 'without given type' do
23
+ it 'should be true for a book with field name' do
24
+ matcher = @should.have_field :name
25
+ matcher.matches?(SingleBook.new).should be_true
26
+ end
27
+
28
+ it 'should be true for a book without field author' do
29
+ matcher = @should.have_field :author
30
+ matcher.matches?(SingleBook.new).should be_false
31
+ end
32
+ end
33
+
34
+ context 'with given type' do
35
+ it 'should be true for a book with field published_on of type Date' do
36
+ matcher = @should.have_field :published_on, :type => Date
37
+ matcher.matches?(SingleBook.new).should be_true
38
+ end
39
+
40
+ it 'should be true for a book with field published_on of type Array' do
41
+ matcher = @should.have_field :published_on, :type => Array
42
+ matcher.matches?(SingleBook.new).should be_false
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'messages' do
48
+ before :all do
49
+ class Model
50
+ def self.add_dirty_methods(*args); end
51
+ include Mongoid::Fields
52
+ field :test
53
+ end
54
+ end
55
+
56
+ before do
57
+ @association_matcher = Remarkable::Mongoid::Matchers::HasFieldMatcher.new(:test, { :type => Date })
58
+ @association_matcher.matches?(Model)
59
+ end
60
+
61
+ describe 'description' do
62
+ subject { @association_matcher.description }
63
+ it { should == "have field test of type Date" }
64
+ end
65
+
66
+ describe 'failure_message_for_should' do
67
+ subject { @association_matcher.failure_message_for_should }
68
+ it { should == "expected Model to have field test of type Date" }
69
+ end
70
+
71
+ describe 'failure_message_for_should_not' do
72
+ subject { @association_matcher.failure_message_for_should_not }
73
+ it { should == "expected Model to not have field test of type Date" }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mongoid Relations' do
4
+ before :all do
5
+ class Should
6
+ include Remarkable::Mongoid::Matchers
7
+ end
8
+
9
+ @should = Should.new
10
+ end
11
+
12
+ context 'embedding' do
13
+ before :all do
14
+ class SingleBook
15
+ include Mongoid::Document
16
+
17
+ embeds_many :pages, :class_name => "SinglePage"
18
+ embeds_one :author, :class_name => "SingleAuthor"
19
+ end
20
+
21
+ class SinglePage
22
+ include Mongoid::Document
23
+
24
+ embedded_in :book, :clas_name => "SingleBook", :inverse_of => :pages
25
+ end
26
+ end
27
+
28
+ describe 'embeds_one' do
29
+ it 'should be true for a book embedding one author' do
30
+ matcher = @should.embed_one :author
31
+ matcher.matches?(SingleBook.new).should be_true
32
+ end
33
+
34
+ it 'should be false for a book embedding one publisher' do
35
+ matcher = @should.embed_one :publisher
36
+ matcher.matches?(SingleBook.new).should be_false
37
+ end
38
+ end
39
+
40
+ describe 'embed_many' do
41
+ it 'should be true for a book embedding many pages' do
42
+ matcher = @should.embed_many :pages
43
+ matcher.matches?(SingleBook.new).should be_true
44
+ end
45
+
46
+ it 'should be false for a book embedding many words' do
47
+ matcher = @should.embed_many :words
48
+ matcher.matches?(SingleBook.new).should be_false
49
+ end
50
+ end
51
+
52
+ describe 'embedded_in' do
53
+ it 'should be true for a page embedded in a book' do
54
+ matcher = @should.be_embedded_in :book
55
+ matcher.matches?(SinglePage.new).should be_true
56
+ end
57
+
58
+ it 'should be false for a page embedded in a newspaper' do
59
+ matcher = @should.be_embedded_in :newspaper
60
+ matcher.matches?(SinglePage.new).should be_false
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'referencing' do
66
+ before :all do
67
+ class SingleOwner
68
+ include Mongoid::Document
69
+
70
+ references_many :dogs, :class_name => "SingleDog", :inverse_of => :owner
71
+ references_one :friend, :class_name => "SingleFriend"
72
+ references_and_referenced_in_many :turtles, :class_name => "SingleTurtle"
73
+ end
74
+
75
+ class SingleDog
76
+ include Mongoid::Document
77
+
78
+ referenced_in :owner, :class_name => "SingleOwner", :inverse_of => :dogs
79
+ end
80
+
81
+ class SingleTurtle
82
+ include Mongoid::Document
83
+ end
84
+ end
85
+
86
+ describe 'reference_one' do
87
+ it 'should be true for an owner having one friend' do
88
+ matcher = @should.reference_one :friend
89
+ matcher.matches?(SingleOwner.new).should be_true
90
+ end
91
+
92
+ it 'should be false for an owner having one boss' do
93
+ matcher = @should.reference_one :boss
94
+ matcher.matches?(SingleOwner.new).should be_false
95
+ end
96
+ end
97
+
98
+ describe 'reference_many' do
99
+ it 'should be true for an owner having many dogs' do
100
+ matcher = @should.reference_many :dogs
101
+ matcher.matches?(SingleOwner.new).should be_true
102
+ end
103
+
104
+ it 'should be false for an owner having many cats' do
105
+ matcher = @should.reference_many :cats
106
+ matcher.matches?(SingleOwner.new).should be_false
107
+ end
108
+ end
109
+
110
+ describe 'reference_many_and_be_referenced_in' do
111
+ it 'should be true for an owner having many turtles as an array' do
112
+ matcher = @should.reference_many_and_be_referenced_in :turtles
113
+ matcher.matches?(SingleOwner.new).should be_true
114
+ end
115
+ it 'should be false for an owner having many dogs as an array' do
116
+ matcher = @should.reference_many_and_be_referenced_in :dogs
117
+ matcher.matches?(SingleOwner.new).should be_false
118
+ end
119
+ it 'should be false for an owner having many cats as an array' do
120
+ matcher = @should.reference_many_and_be_referenced_in :cats
121
+ matcher.matches?(SingleOwner.new).should be_false
122
+ end
123
+ end
124
+
125
+ describe 'be_referenced_in' do
126
+ it 'should be true for a dog belonging to an owner' do
127
+ matcher = @should.be_referenced_in :owner
128
+ matcher.matches?(SingleDog.new).should be_true
129
+ end
130
+
131
+ it 'should be false for a dog belonging to a cat' do
132
+ matcher = @should.be_referenced_in :stranger
133
+ matcher.matches?(SingleDog.new).should be_false
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'messages' do
139
+ before do
140
+ @relation_matcher = Remarkable::Mongoid::Matchers::RelationMatcher.new(:test, "Some::Test")
141
+ end
142
+
143
+ describe 'description' do
144
+ subject { @relation_matcher.description }
145
+ it { should == "has Test relation :test" }
146
+ end
147
+
148
+ describe 'failure_message_for_should' do
149
+ subject { @relation_matcher.failure_message_for_should }
150
+ it { should == "\nTest relation failure\nExpected: 'test'"}
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Remarkable::Mongoid" do
4
+ it 'should define Remarkable::Mongoid' do
5
+ defined?(Remarkable::Mongoid).should be_true
6
+ end
7
+ end
8
+
9
+ describe 'Remarkable::ActiveModel' do
10
+ it 'should include the Remarkable ActiveModel validation matchers' do
11
+ defined?(Remarkable::ActiveModel).should be_true
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'ruby-debug'
8
+ require 'rubygems'
9
+ require 'remarkable/mongoid'
10
+ require 'mongoid'
11
+ require 'rspec'
12
+ require 'rspec/autorun'
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :mocha
16
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Validates Associated' do
4
+ before :all do
5
+ class Should
6
+ include Remarkable::Mongoid::Matchers
7
+ end
8
+
9
+ @should = Should.new
10
+ end
11
+
12
+ describe 'validate_association' do
13
+ before do
14
+ class SingleBook
15
+ include Mongoid::Validations
16
+ validates_associated :pages
17
+ end
18
+ end
19
+
20
+ after do
21
+ Object.send(:remove_const, :SingleBook)
22
+ end
23
+
24
+ it 'should be true for a book validating the association :pages' do
25
+ matcher = @should.validate_association :pages
26
+ matcher.matches?(SingleBook.new).should be_true
27
+ end
28
+
29
+ it 'should be false for a book validating the association :author' do
30
+ matcher = @should.validate_association :author
31
+ matcher.matches?(SingleBook.new).should be_false
32
+ end
33
+ end
34
+
35
+ context 'messages' do
36
+ before do
37
+ matcher_subject = mock('SingleBook')
38
+ matcher_subject.stubs(:class).returns('SingleBook')
39
+ @association_matcher = Remarkable::Mongoid::Matchers::ValidateAssociationMatcher.new(:test)
40
+ @association_matcher.instance_variable_set('@subject', matcher_subject)
41
+ end
42
+
43
+ describe 'description' do
44
+ subject { @association_matcher.description }
45
+ it { should == "validates the :test association" }
46
+ end
47
+
48
+ describe 'failure_message_for_should' do
49
+ subject { @association_matcher.failure_message_for_should }
50
+ it { should == "\nAssociation validation failure\nExpected: SingleBook to validate the 'test' association" }
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Validates Uniqueness Of' do
4
+ before :all do
5
+ class Should
6
+ include Remarkable::Mongoid::Matchers
7
+ end
8
+
9
+ @should = Should.new
10
+ end
11
+
12
+ describe 'validate_uniqueness_of' do
13
+ before do
14
+ class SingleBook
15
+ include Mongoid::Validations
16
+ validates_uniqueness_of :title, :message => 'Test message', :scope => :author_id
17
+ end
18
+ end
19
+
20
+ after do
21
+ Object.send(:remove_const, :SingleBook)
22
+ end
23
+
24
+ it 'should be true for a book validating the uniqueness of title' do
25
+ matcher = @should.validate_uniqueness_of :title
26
+ matcher.matches?(SingleBook.new).should be_true
27
+ end
28
+
29
+ it 'should be false for a book validating the uniqueness of author' do
30
+ matcher = @should.validate_uniqueness_of :author
31
+ matcher.matches?(SingleBook.new).should be_false
32
+ end
33
+
34
+ context 'with message' do
35
+ it 'should be true for a book validating the uniqueness of title' do
36
+ matcher = @should.validate_uniqueness_of(:title).with_message('Test message')
37
+ matcher.matches?(SingleBook.new).should be_true
38
+ end
39
+
40
+ it 'should be false for a book validating the uniqueness of title with message "Bad message"' do
41
+ matcher = @should.validate_uniqueness_of(:author).with_message('Bad message')
42
+ matcher.matches?(SingleBook.new).should be_false
43
+ end
44
+ end
45
+
46
+ context 'with scope' do
47
+ it 'should be true for a book validating the uniqueness scoped_to author_id' do
48
+ matcher = @should.validate_uniqueness_of(:title).scoped_to(:author_id)
49
+ matcher.matches?(SingleBook.new).should be_true
50
+ end
51
+
52
+ it 'should be false for a book validating the uniqueness scoped_to reader_id' do
53
+ matcher = @should.validate_uniqueness_of(:title).scoped_to(:reader_id)
54
+ matcher.matches?(SingleBook.new).should be_false
55
+ end
56
+ end
57
+
58
+ context 'with scope and message' do
59
+ it 'should be true for a book validating the uniqueness with good scope and message' do
60
+ matcher = @should.validate_uniqueness_of(:title).scoped_to(:author_id).with_message('Test message')
61
+ matcher.matches?(SingleBook.new).should be_true
62
+ end
63
+
64
+ it 'should be false for a book validating the uniqueness with good scope and bad message' do
65
+ matcher = @should.validate_uniqueness_of(:title).scoped_to(:author_id).with_message('Bad message')
66
+ matcher.matches?(SingleBook.new).should be_false
67
+ end
68
+
69
+ it 'should be false for a book validating the uniqueness with bad scope and good message' do
70
+ matcher = @should.validate_uniqueness_of(:title).scoped_to(:reader_id).with_message('Test message')
71
+ matcher.matches?(SingleBook.new).should be_false
72
+ end
73
+
74
+ it 'should be false for a book validating the uniqueness with bad scope and bad message' do
75
+ matcher = @should.validate_uniqueness_of(:title).scoped_to(:reader_id).with_message('Bad message')
76
+ matcher.matches?(SingleBook.new).should be_false
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ context 'messages' do
83
+ before do
84
+ @association_matcher = Remarkable::Mongoid::Matchers::ValidateUniquenessOfMatcher.new(:test)
85
+ end
86
+
87
+ describe 'description' do
88
+ subject { @association_matcher.description }
89
+ it { should == "validates that :test is unique" }
90
+ end
91
+
92
+ describe 'failure_message_for_should' do
93
+ subject { @association_matcher.failure_message_for_should }
94
+ it { should == "\nUniqueness validation failure\nExpected: 'test' to be unique" }
95
+ end
96
+ end
97
+
98
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 5
9
- - 0
10
- version: 0.5.0
8
+ - 2
9
+ version: 0.5.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Brian Cardarella
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-15 00:00:00 -04:00
17
+ date: 2011-01-29 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -24,137 +23,138 @@ dependencies:
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
- - - ">="
26
+ - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: -1710980496
30
28
  segments:
31
29
  - 4
32
30
  - 0
33
31
  - 0
34
- - alpha2
35
- version: 4.0.0.alpha2
32
+ - alpha4
33
+ version: 4.0.0.alpha4
36
34
  type: :runtime
37
35
  version_requirements: *id001
38
36
  - !ruby/object:Gem::Dependency
39
- name: ruby-debug
37
+ name: bson_ext
40
38
  prerelease: false
41
39
  requirement: &id002 !ruby/object:Gem::Requirement
42
40
  none: false
43
41
  requirements:
44
42
  - - ">="
45
43
  - !ruby/object:Gem::Version
46
- hash: 3
47
44
  segments:
48
45
  - 0
49
46
  version: "0"
50
47
  type: :development
51
48
  version_requirements: *id002
52
49
  - !ruby/object:Gem::Dependency
53
- name: bson_ext
50
+ name: activesupport
54
51
  prerelease: false
55
52
  requirement: &id003 !ruby/object:Gem::Requirement
56
53
  none: false
57
54
  requirements:
58
- - - ">="
55
+ - - ~>
59
56
  - !ruby/object:Gem::Version
60
- hash: 3
61
57
  segments:
58
+ - 3
62
59
  - 0
63
- version: "0"
60
+ - 0
61
+ version: 3.0.0
64
62
  type: :development
65
63
  version_requirements: *id003
66
64
  - !ruby/object:Gem::Dependency
67
- name: activesupport
65
+ name: mongoid
68
66
  prerelease: false
69
67
  requirement: &id004 !ruby/object:Gem::Requirement
70
68
  none: false
71
69
  requirements:
72
- - - "="
70
+ - - ~>
73
71
  - !ruby/object:Gem::Version
74
- hash: 7712042
75
72
  segments:
76
- - 3
73
+ - 2
77
74
  - 0
78
75
  - 0
79
76
  - rc
80
- version: 3.0.0.rc
77
+ - 6
78
+ version: 2.0.0.rc.6
81
79
  type: :development
82
80
  version_requirements: *id004
83
81
  - !ruby/object:Gem::Dependency
84
- name: mongoid
82
+ name: rspec
85
83
  prerelease: false
86
84
  requirement: &id005 !ruby/object:Gem::Requirement
87
85
  none: false
88
86
  requirements:
89
- - - "="
87
+ - - ">="
90
88
  - !ruby/object:Gem::Version
91
- hash: 62196477
92
89
  segments:
93
- - 2
94
90
  - 0
95
- - 0
96
- - beta
97
- - 15
98
- version: 2.0.0.beta.15
91
+ version: "0"
99
92
  type: :development
100
93
  version_requirements: *id005
101
94
  - !ruby/object:Gem::Dependency
102
- name: rspec
95
+ name: bourne
103
96
  prerelease: false
104
97
  requirement: &id006 !ruby/object:Gem::Requirement
105
98
  none: false
106
99
  requirements:
107
- - - "="
100
+ - - ">="
108
101
  - !ruby/object:Gem::Version
109
- hash: 62196421
110
102
  segments:
111
- - 2
112
103
  - 0
113
- - 0
114
- - beta
115
- - 19
116
- version: 2.0.0.beta.19
104
+ version: "0"
117
105
  type: :development
118
106
  version_requirements: *id006
119
107
  - !ruby/object:Gem::Dependency
120
- name: bourne
108
+ name: ruby-debug19
121
109
  prerelease: false
122
110
  requirement: &id007 !ruby/object:Gem::Requirement
123
111
  none: false
124
112
  requirements:
125
- - - "="
113
+ - - ">="
126
114
  - !ruby/object:Gem::Version
127
- hash: 15
128
115
  segments:
129
- - 1
130
116
  - 0
131
- version: "1.0"
117
+ version: "0"
132
118
  type: :development
133
119
  version_requirements: *id007
134
120
  description: RSpec Matchers for Mongoid
135
- email: bcardarella@gmail.com
121
+ email:
122
+ - bcardarella@gmail.com
136
123
  executables: []
137
124
 
138
125
  extensions: []
139
126
 
140
- extra_rdoc_files:
141
- - LICENSE
142
- - README.markdown
127
+ extra_rdoc_files: []
128
+
143
129
  files:
130
+ - .gitignore
131
+ - .rvmrc
132
+ - Gemfile
133
+ - HISTORY.txt
144
134
  - LICENSE
145
135
  - README.markdown
136
+ - Rakefile
146
137
  - lib/remarkable/mongoid.rb
147
- - lib/remarkable/mongoid/associations.rb
148
138
  - lib/remarkable/mongoid/fields.rb
139
+ - lib/remarkable/mongoid/relations.rb
149
140
  - lib/remarkable/mongoid/validate_association.rb
150
141
  - lib/remarkable/mongoid/validate_uniqueness_of.rb
142
+ - lib/remarkable/mongoid/version.rb
143
+ - remarkable_mongoid.gemspec
144
+ - spec/.rspec
145
+ - spec/fields_spec.rb
146
+ - spec/relations_spec.rb
147
+ - spec/remarkable-mongoid_spec.rb
148
+ - spec/spec_helper.rb
149
+ - spec/validate_associated_spec.rb
150
+ - spec/validate_uniqueness_of_spec.rb
151
151
  has_rdoc: true
152
- homepage: http://github.com/bcardarella/remarkable_mongoid
152
+ homepage: https://github.com/bcardarella/remarkable_mongoid
153
153
  licenses: []
154
154
 
155
155
  post_install_message:
156
- rdoc_options:
157
- - --charset=UTF-8
156
+ rdoc_options: []
157
+
158
158
  require_paths:
159
159
  - lib
160
160
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -162,7 +162,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - ">="
164
164
  - !ruby/object:Gem::Version
165
- hash: 3
166
165
  segments:
167
166
  - 0
168
167
  version: "0"
@@ -171,7 +170,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
170
  requirements:
172
171
  - - ">="
173
172
  - !ruby/object:Gem::Version
174
- hash: 3
175
173
  segments:
176
174
  - 0
177
175
  version: "0"
@@ -182,5 +180,10 @@ rubygems_version: 1.3.7
182
180
  signing_key:
183
181
  specification_version: 3
184
182
  summary: RSpec Matchers for Mongoid
185
- test_files: []
186
-
183
+ test_files:
184
+ - spec/fields_spec.rb
185
+ - spec/relations_spec.rb
186
+ - spec/remarkable-mongoid_spec.rb
187
+ - spec/spec_helper.rb
188
+ - spec/validate_associated_spec.rb
189
+ - spec/validate_uniqueness_of_spec.rb
@@ -1,60 +0,0 @@
1
- module Remarkable::Mongoid
2
- module Matchers
3
- def reference_one(attr)
4
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesOne)
5
- end
6
-
7
- def reference_many(attr)
8
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesMany)
9
- end
10
-
11
- def reference_many_as_array(attr)
12
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencesManyAsArray)
13
- end
14
-
15
- def be_referenced_in(attr)
16
- AssociationMatcher.new(attr, ::Mongoid::Associations::ReferencedIn)
17
- end
18
-
19
- def embed_one(attr)
20
- AssociationMatcher.new(attr, ::Mongoid::Associations::EmbedsOne)
21
- end
22
-
23
- def embed_many(attr)
24
- AssociationMatcher.new(attr, ::Mongoid::Associations::EmbedsMany)
25
- end
26
-
27
- def be_embedded_in(attr)
28
- AssociationMatcher.new(attr, ::Mongoid::Associations::EmbeddedIn)
29
- end
30
-
31
- class AssociationMatcher
32
- attr_accessor :attr, :association_type
33
-
34
- def initialize(attr, association_type)
35
- self.attr = attr.to_s
36
- self.association_type = association_type
37
- end
38
-
39
- def matches?(subject)
40
- @subject = subject
41
- associations = @subject.associations.select { |k,v| v.association == association_type }
42
- associations.detect { |k| k.first == attr } != nil
43
- end
44
-
45
- def description
46
- "has #{humanized_association} association :#{attr}"
47
- end
48
-
49
- def failure_message_for_should
50
- "\n#{humanized_association} association failure\nExpected: '#{attr}'"
51
- end
52
-
53
- private
54
-
55
- def humanized_association
56
- association_type.to_s.split('::').last
57
- end
58
- end
59
- end
60
- end