remarkable_mongoid 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ ## 0.6.0
2
+ * Allow arrays as scopes for validates_uniqueness_of (benedikt & negonicrac)
1
3
  ## 0.5.2
2
4
  * Updated README
3
5
 
@@ -36,7 +36,7 @@ Validations
36
36
  describe Book do
37
37
  it { should reference_one :author }
38
38
  end
39
-
39
+
40
40
  ## Copyright
41
41
 
42
42
  Copyright (c) 2010 - 2011 Brian Cardarella. See LICENSE for details.
@@ -18,3 +18,4 @@ elsif defined?(Spec) # RSpec 1.x
18
18
  config.include(Remarkable::Mongoid::Matchers)
19
19
  end
20
20
  end
21
+
@@ -49,3 +49,4 @@ module Remarkable::Mongoid
49
49
  end
50
50
  end
51
51
  end
52
+
@@ -12,7 +12,7 @@ module Remarkable::Mongoid
12
12
  def reference_one(attr)
13
13
  RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::One)
14
14
  end
15
-
15
+
16
16
  # Specify the document references many documents
17
17
  #
18
18
  # examples:
@@ -36,7 +36,7 @@ module Remarkable::Mongoid
36
36
  def reference_many_and_be_referenced_in(attr)
37
37
  RelationMatcher.new(attr, ::Mongoid::Relations::Referenced::ManyToMany)
38
38
  end
39
-
39
+
40
40
  # Specify the document is referenced in another document
41
41
  #
42
42
  # examples:
@@ -60,7 +60,7 @@ module Remarkable::Mongoid
60
60
  def embed_one(attr)
61
61
  RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::One)
62
62
  end
63
-
63
+
64
64
  # Specify the document embeds many documents
65
65
  #
66
66
  # examples:
@@ -72,7 +72,7 @@ module Remarkable::Mongoid
72
72
  def embed_many(attr)
73
73
  RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::Many)
74
74
  end
75
-
75
+
76
76
  # Specify the document is embedded in another document
77
77
  #
78
78
  # examples:
@@ -84,7 +84,7 @@ module Remarkable::Mongoid
84
84
  def be_embedded_in(attr)
85
85
  RelationMatcher.new(attr, ::Mongoid::Relations::Embedded::In)
86
86
  end
87
-
87
+
88
88
  class RelationMatcher
89
89
  attr_accessor :attr, :relation_type
90
90
 
@@ -102,16 +102,17 @@ module Remarkable::Mongoid
102
102
  def description
103
103
  "has #{humanized_relation} relation :#{attr}"
104
104
  end
105
-
105
+
106
106
  def failure_message_for_should
107
107
  "\n#{humanized_relation} relation failure\nExpected: '#{attr}'"
108
108
  end
109
-
109
+
110
110
  private
111
-
111
+
112
112
  def humanized_relation
113
113
  relation_type.to_s.split('::').last
114
114
  end
115
115
  end
116
116
  end
117
117
  end
118
+
@@ -12,14 +12,14 @@ module Remarkable::Mongoid
12
12
  def validate_association(attr)
13
13
  ValidateAssociationMatcher.new(attr)
14
14
  end
15
-
15
+
16
16
  class ValidateAssociationMatcher
17
17
  attr_accessor :attr
18
18
 
19
19
  def initialize(attr)
20
20
  self.attr = attr.to_sym
21
21
  end
22
-
22
+
23
23
  def matches?(subject)
24
24
  @subject = subject
25
25
  validations = @subject._validators[attr]
@@ -33,8 +33,9 @@ module Remarkable::Mongoid
33
33
  def failure_message_for_should
34
34
  "\nAssociation validation failure\nExpected: #{@subject.class} to validate the '#{attr}' association"
35
35
  end
36
-
36
+
37
37
  end
38
-
38
+
39
39
  end
40
40
  end
41
+
@@ -12,21 +12,21 @@ module Remarkable::Mongoid
12
12
  def validate_uniqueness_of(attr)
13
13
  ValidateUniquenessOfMatcher.new(attr)
14
14
  end
15
-
15
+
16
16
  class ValidateUniquenessOfMatcher
17
17
  attr_accessor :attr, :validation_type, :message, :scope
18
18
 
19
19
  def initialize(attr)
20
20
  self.attr = attr.to_sym
21
21
  end
22
-
22
+
23
23
  def with_message(message)
24
24
  self.message = message
25
25
  self
26
26
  end
27
-
27
+
28
28
  def scoped_to(scope)
29
- self.scope = scope.to_sym
29
+ self.scope = scope.is_a?(Array) ? scope.map(&:to_sym) : scope.to_sym
30
30
  self
31
31
  end
32
32
 
@@ -48,9 +48,9 @@ module Remarkable::Mongoid
48
48
  def failure_message_for_should
49
49
  "\nUniqueness validation failure\nExpected: '#{attr}' to be unique"
50
50
  end
51
-
51
+
52
52
  private
53
-
53
+
54
54
  def check_option(validation, option)
55
55
  if self.send(option)
56
56
  validation.options[option] == self.send(option)
@@ -59,6 +59,7 @@ module Remarkable::Mongoid
59
59
  end
60
60
  end
61
61
  end
62
-
62
+
63
63
  end
64
64
  end
65
+
@@ -1,5 +1,6 @@
1
1
  module Remarkable
2
2
  module Mongoid
3
- VERSION = '0.5.2'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
6
+
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_development_dependency 'bson_ext'
24
24
  s.add_development_dependency 'activesupport', '~> 3.0.0'
25
- s.add_development_dependency 'mongoid', '~> 2.0.0.rc.6'
25
+ s.add_development_dependency 'mongoid', '~> 2.0.0.rc.7'
26
26
  s.add_development_dependency 'rspec'
27
27
  s.add_development_dependency 'bourne'
28
28
 
@@ -30,7 +30,7 @@ describe 'Mongoid Fields' do
30
30
  matcher.matches?(SingleBook.new).should be_false
31
31
  end
32
32
  end
33
-
33
+
34
34
  context 'with given type' do
35
35
  it 'should be true for a book with field published_on of type Date' do
36
36
  matcher = @should.have_field :published_on, :type => Date
@@ -74,3 +74,4 @@ describe 'Mongoid Fields' do
74
74
  end
75
75
  end
76
76
  end
77
+
@@ -8,7 +8,7 @@ describe 'Mongoid Relations' do
8
8
 
9
9
  @should = Should.new
10
10
  end
11
-
11
+
12
12
  context 'embedding' do
13
13
  before :all do
14
14
  class SingleBook
@@ -17,7 +17,7 @@ describe 'Mongoid Relations' do
17
17
  embeds_many :pages, :class_name => "SinglePage"
18
18
  embeds_one :author, :class_name => "SingleAuthor"
19
19
  end
20
-
20
+
21
21
  class SinglePage
22
22
  include Mongoid::Document
23
23
 
@@ -30,38 +30,38 @@ describe 'Mongoid Relations' do
30
30
  matcher = @should.embed_one :author
31
31
  matcher.matches?(SingleBook.new).should be_true
32
32
  end
33
-
33
+
34
34
  it 'should be false for a book embedding one publisher' do
35
35
  matcher = @should.embed_one :publisher
36
36
  matcher.matches?(SingleBook.new).should be_false
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe 'embed_many' do
41
41
  it 'should be true for a book embedding many pages' do
42
42
  matcher = @should.embed_many :pages
43
43
  matcher.matches?(SingleBook.new).should be_true
44
44
  end
45
-
45
+
46
46
  it 'should be false for a book embedding many words' do
47
47
  matcher = @should.embed_many :words
48
48
  matcher.matches?(SingleBook.new).should be_false
49
49
  end
50
50
  end
51
-
51
+
52
52
  describe 'embedded_in' do
53
53
  it 'should be true for a page embedded in a book' do
54
54
  matcher = @should.be_embedded_in :book
55
55
  matcher.matches?(SinglePage.new).should be_true
56
56
  end
57
-
57
+
58
58
  it 'should be false for a page embedded in a newspaper' do
59
59
  matcher = @should.be_embedded_in :newspaper
60
60
  matcher.matches?(SinglePage.new).should be_false
61
61
  end
62
62
  end
63
63
  end
64
-
64
+
65
65
  context 'referencing' do
66
66
  before :all do
67
67
  class SingleOwner
@@ -71,7 +71,7 @@ describe 'Mongoid Relations' do
71
71
  references_one :friend, :class_name => "SingleFriend"
72
72
  references_and_referenced_in_many :turtles, :class_name => "SingleTurtle"
73
73
  end
74
-
74
+
75
75
  class SingleDog
76
76
  include Mongoid::Document
77
77
 
@@ -88,19 +88,19 @@ describe 'Mongoid Relations' do
88
88
  matcher = @should.reference_one :friend
89
89
  matcher.matches?(SingleOwner.new).should be_true
90
90
  end
91
-
91
+
92
92
  it 'should be false for an owner having one boss' do
93
93
  matcher = @should.reference_one :boss
94
94
  matcher.matches?(SingleOwner.new).should be_false
95
95
  end
96
96
  end
97
-
97
+
98
98
  describe 'reference_many' do
99
99
  it 'should be true for an owner having many dogs' do
100
100
  matcher = @should.reference_many :dogs
101
101
  matcher.matches?(SingleOwner.new).should be_true
102
102
  end
103
-
103
+
104
104
  it 'should be false for an owner having many cats' do
105
105
  matcher = @should.reference_many :cats
106
106
  matcher.matches?(SingleOwner.new).should be_false
@@ -121,33 +121,34 @@ describe 'Mongoid Relations' do
121
121
  matcher.matches?(SingleOwner.new).should be_false
122
122
  end
123
123
  end
124
-
124
+
125
125
  describe 'be_referenced_in' do
126
126
  it 'should be true for a dog belonging to an owner' do
127
127
  matcher = @should.be_referenced_in :owner
128
128
  matcher.matches?(SingleDog.new).should be_true
129
129
  end
130
-
130
+
131
131
  it 'should be false for a dog belonging to a cat' do
132
132
  matcher = @should.be_referenced_in :stranger
133
133
  matcher.matches?(SingleDog.new).should be_false
134
134
  end
135
135
  end
136
136
  end
137
-
137
+
138
138
  context 'messages' do
139
139
  before do
140
140
  @relation_matcher = Remarkable::Mongoid::Matchers::RelationMatcher.new(:test, "Some::Test")
141
141
  end
142
-
142
+
143
143
  describe 'description' do
144
144
  subject { @relation_matcher.description }
145
145
  it { should == "has Test relation :test" }
146
146
  end
147
-
147
+
148
148
  describe 'failure_message_for_should' do
149
149
  subject { @relation_matcher.failure_message_for_should }
150
150
  it { should == "\nTest relation failure\nExpected: 'test'"}
151
151
  end
152
152
  end
153
153
  end
154
+
@@ -10,4 +10,5 @@ describe 'Remarkable::ActiveModel' do
10
10
  it 'should include the Remarkable ActiveModel validation matchers' do
11
11
  defined?(Remarkable::ActiveModel).should be_true
12
12
  end
13
- end
13
+ end
14
+
@@ -14,3 +14,4 @@ require 'rspec/autorun'
14
14
  RSpec.configure do |config|
15
15
  config.mock_with :mocha
16
16
  end
17
+
@@ -5,10 +5,10 @@ describe 'Validates Associated' do
5
5
  class Should
6
6
  include Remarkable::Mongoid::Matchers
7
7
  end
8
-
8
+
9
9
  @should = Should.new
10
10
  end
11
-
11
+
12
12
  describe 'validate_association' do
13
13
  before do
14
14
  class SingleBook
@@ -16,22 +16,22 @@ describe 'Validates Associated' do
16
16
  validates_associated :pages
17
17
  end
18
18
  end
19
-
19
+
20
20
  after do
21
21
  Object.send(:remove_const, :SingleBook)
22
22
  end
23
-
23
+
24
24
  it 'should be true for a book validating the association :pages' do
25
25
  matcher = @should.validate_association :pages
26
26
  matcher.matches?(SingleBook.new).should be_true
27
27
  end
28
-
28
+
29
29
  it 'should be false for a book validating the association :author' do
30
30
  matcher = @should.validate_association :author
31
31
  matcher.matches?(SingleBook.new).should be_false
32
32
  end
33
33
  end
34
-
34
+
35
35
  context 'messages' do
36
36
  before do
37
37
  matcher_subject = mock('SingleBook')
@@ -39,16 +39,17 @@ describe 'Validates Associated' do
39
39
  @association_matcher = Remarkable::Mongoid::Matchers::ValidateAssociationMatcher.new(:test)
40
40
  @association_matcher.instance_variable_set('@subject', matcher_subject)
41
41
  end
42
-
42
+
43
43
  describe 'description' do
44
44
  subject { @association_matcher.description }
45
45
  it { should == "validates the :test association" }
46
46
  end
47
-
47
+
48
48
  describe 'failure_message_for_should' do
49
49
  subject { @association_matcher.failure_message_for_should }
50
50
  it { should == "\nAssociation validation failure\nExpected: SingleBook to validate the 'test' association" }
51
51
  end
52
52
  end
53
-
53
+
54
54
  end
55
+
@@ -5,18 +5,19 @@ describe 'Validates Uniqueness Of' do
5
5
  class Should
6
6
  include Remarkable::Mongoid::Matchers
7
7
  end
8
-
8
+
9
9
  @should = Should.new
10
10
  end
11
-
11
+
12
12
  describe 'validate_uniqueness_of' do
13
13
  before do
14
14
  class SingleBook
15
15
  include Mongoid::Validations
16
16
  validates_uniqueness_of :title, :message => 'Test message', :scope => :author_id
17
+ validates_uniqueness_of :price, :scope => [:store_id, :shelf_id]
17
18
  end
18
19
  end
19
-
20
+
20
21
  after do
21
22
  Object.send(:remove_const, :SingleBook)
22
23
  end
@@ -25,12 +26,12 @@ describe 'Validates Uniqueness Of' do
25
26
  matcher = @should.validate_uniqueness_of :title
26
27
  matcher.matches?(SingleBook.new).should be_true
27
28
  end
28
-
29
+
29
30
  it 'should be false for a book validating the uniqueness of author' do
30
31
  matcher = @should.validate_uniqueness_of :author
31
32
  matcher.matches?(SingleBook.new).should be_false
32
33
  end
33
-
34
+
34
35
  context 'with message' do
35
36
  it 'should be true for a book validating the uniqueness of title' do
36
37
  matcher = @should.validate_uniqueness_of(:title).with_message('Test message')
@@ -42,17 +43,22 @@ describe 'Validates Uniqueness Of' do
42
43
  matcher.matches?(SingleBook.new).should be_false
43
44
  end
44
45
  end
45
-
46
+
46
47
  context 'with scope' do
47
48
  it 'should be true for a book validating the uniqueness scoped_to author_id' do
48
49
  matcher = @should.validate_uniqueness_of(:title).scoped_to(:author_id)
49
50
  matcher.matches?(SingleBook.new).should be_true
50
51
  end
51
-
52
+
52
53
  it 'should be false for a book validating the uniqueness scoped_to reader_id' do
53
54
  matcher = @should.validate_uniqueness_of(:title).scoped_to(:reader_id)
54
55
  matcher.matches?(SingleBook.new).should be_false
55
56
  end
57
+
58
+ it 'should be true for a book validating the uniqueness scoped_to [:store_id, :shelf_id]' do
59
+ matcher = @should.validate_uniqueness_of(:price).scoped_to([:store_id, :shelf_id])
60
+ matcher.matches?(SingleBook.new).should be_true
61
+ end
56
62
  end
57
63
 
58
64
  context 'with scope and message' do
@@ -60,7 +66,7 @@ describe 'Validates Uniqueness Of' do
60
66
  matcher = @should.validate_uniqueness_of(:title).scoped_to(:author_id).with_message('Test message')
61
67
  matcher.matches?(SingleBook.new).should be_true
62
68
  end
63
-
69
+
64
70
  it 'should be false for a book validating the uniqueness with good scope and bad message' do
65
71
  matcher = @should.validate_uniqueness_of(:title).scoped_to(:author_id).with_message('Bad message')
66
72
  matcher.matches?(SingleBook.new).should be_false
@@ -78,21 +84,22 @@ describe 'Validates Uniqueness Of' do
78
84
  end
79
85
 
80
86
  end
81
-
87
+
82
88
  context 'messages' do
83
89
  before do
84
90
  @association_matcher = Remarkable::Mongoid::Matchers::ValidateUniquenessOfMatcher.new(:test)
85
91
  end
86
-
92
+
87
93
  describe 'description' do
88
94
  subject { @association_matcher.description }
89
95
  it { should == "validates that :test is unique" }
90
96
  end
91
-
97
+
92
98
  describe 'failure_message_for_should' do
93
99
  subject { @association_matcher.failure_message_for_should }
94
100
  it { should == "\nUniqueness validation failure\nExpected: 'test' to be unique" }
95
101
  end
96
102
  end
97
-
98
- end
103
+
104
+ end
105
+
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 5
8
- - 2
9
- version: 0.5.2
4
+ prerelease:
5
+ version: 0.6.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Brian Cardarella
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-29 00:00:00 -05:00
13
+ date: 2011-03-18 00:00:00 -04:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,11 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ~>
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 4
30
- - 0
31
- - 0
32
- - alpha4
33
24
  version: 4.0.0.alpha4
34
25
  type: :runtime
35
26
  version_requirements: *id001
@@ -41,8 +32,6 @@ dependencies:
41
32
  requirements:
42
33
  - - ">="
43
34
  - !ruby/object:Gem::Version
44
- segments:
45
- - 0
46
35
  version: "0"
47
36
  type: :development
48
37
  version_requirements: *id002
@@ -54,10 +43,6 @@ dependencies:
54
43
  requirements:
55
44
  - - ~>
56
45
  - !ruby/object:Gem::Version
57
- segments:
58
- - 3
59
- - 0
60
- - 0
61
46
  version: 3.0.0
62
47
  type: :development
63
48
  version_requirements: *id003
@@ -69,13 +54,7 @@ dependencies:
69
54
  requirements:
70
55
  - - ~>
71
56
  - !ruby/object:Gem::Version
72
- segments:
73
- - 2
74
- - 0
75
- - 0
76
- - rc
77
- - 6
78
- version: 2.0.0.rc.6
57
+ version: 2.0.0.rc.7
79
58
  type: :development
80
59
  version_requirements: *id004
81
60
  - !ruby/object:Gem::Dependency
@@ -86,8 +65,6 @@ dependencies:
86
65
  requirements:
87
66
  - - ">="
88
67
  - !ruby/object:Gem::Version
89
- segments:
90
- - 0
91
68
  version: "0"
92
69
  type: :development
93
70
  version_requirements: *id005
@@ -99,8 +76,6 @@ dependencies:
99
76
  requirements:
100
77
  - - ">="
101
78
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
79
  version: "0"
105
80
  type: :development
106
81
  version_requirements: *id006
@@ -112,8 +87,6 @@ dependencies:
112
87
  requirements:
113
88
  - - ">="
114
89
  - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
90
  version: "0"
118
91
  type: :development
119
92
  version_requirements: *id007
@@ -162,21 +135,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
135
  requirements:
163
136
  - - ">="
164
137
  - !ruby/object:Gem::Version
165
- segments:
166
- - 0
167
138
  version: "0"
168
139
  required_rubygems_version: !ruby/object:Gem::Requirement
169
140
  none: false
170
141
  requirements:
171
142
  - - ">="
172
143
  - !ruby/object:Gem::Version
173
- segments:
174
- - 0
175
144
  version: "0"
176
145
  requirements: []
177
146
 
178
147
  rubyforge_project:
179
- rubygems_version: 1.3.7
148
+ rubygems_version: 1.5.3
180
149
  signing_key:
181
150
  specification_version: 3
182
151
  summary: RSpec Matchers for Mongoid