mongomodel 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +23 -11
  3. data/gemfiles/rails-3.2.gemfile +2 -2
  4. data/gemfiles/rails-4-observers.gemfile +1 -1
  5. data/gemfiles/rails-4.1.gemfile +2 -2
  6. data/gemfiles/{mongoid.gemfile → rails-4.2.gemfile} +2 -3
  7. data/gemfiles/{mongo_mapper.gemfile → rails-5.0.gemfile} +2 -3
  8. data/gemfiles/rails-5.1.gemfile +10 -0
  9. data/gemfiles/rails-5.2.gemfile +10 -0
  10. data/lib/mongomodel.rb +15 -15
  11. data/lib/mongomodel/attributes/mongo.rb +7 -7
  12. data/lib/mongomodel/attributes/store.rb +4 -4
  13. data/lib/mongomodel/attributes/typecasting.rb +7 -7
  14. data/lib/mongomodel/compatibility/mongo_mapper.rb +3 -3
  15. data/lib/mongomodel/compatibility/mongoid.rb +3 -3
  16. data/lib/mongomodel/concerns/abstract_class.rb +3 -3
  17. data/lib/mongomodel/concerns/activemodel.rb +4 -4
  18. data/lib/mongomodel/concerns/associations.rb +8 -8
  19. data/lib/mongomodel/concerns/associations/base/association.rb +5 -5
  20. data/lib/mongomodel/concerns/associations/base/definition.rb +4 -4
  21. data/lib/mongomodel/concerns/associations/base/proxy.rb +1 -1
  22. data/lib/mongomodel/concerns/associations/belongs_to.rb +19 -19
  23. data/lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb +36 -36
  24. data/lib/mongomodel/concerns/associations/has_many_by_ids.rb +34 -34
  25. data/lib/mongomodel/concerns/attribute_methods.rb +10 -10
  26. data/lib/mongomodel/concerns/attribute_methods/before_type_cast.rb +4 -4
  27. data/lib/mongomodel/concerns/attribute_methods/dirty.rb +95 -13
  28. data/lib/mongomodel/concerns/attribute_methods/forbidden.rb +1 -1
  29. data/lib/mongomodel/concerns/attribute_methods/multi_parameter_assignment.rb +6 -6
  30. data/lib/mongomodel/concerns/attribute_methods/nested.rb +18 -18
  31. data/lib/mongomodel/concerns/attribute_methods/protected.rb +3 -3
  32. data/lib/mongomodel/concerns/attribute_methods/query.rb +3 -3
  33. data/lib/mongomodel/concerns/attribute_methods/read.rb +4 -4
  34. data/lib/mongomodel/concerns/attribute_methods/write.rb +4 -4
  35. data/lib/mongomodel/concerns/attributes.rb +18 -18
  36. data/lib/mongomodel/concerns/callbacks.rb +7 -7
  37. data/lib/mongomodel/concerns/document_parent.rb +2 -2
  38. data/lib/mongomodel/concerns/logging.rb +2 -2
  39. data/lib/mongomodel/concerns/map_reduce.rb +11 -11
  40. data/lib/mongomodel/concerns/pretty_inspect.rb +3 -3
  41. data/lib/mongomodel/concerns/properties.rb +18 -18
  42. data/lib/mongomodel/concerns/record_status.rb +9 -13
  43. data/lib/mongomodel/concerns/serialization.rb +4 -4
  44. data/lib/mongomodel/concerns/timestamps.rb +4 -4
  45. data/lib/mongomodel/concerns/translation.rb +2 -2
  46. data/lib/mongomodel/concerns/validations.rb +5 -5
  47. data/lib/mongomodel/concerns/validations/associated.rb +1 -1
  48. data/lib/mongomodel/document.rb +6 -6
  49. data/lib/mongomodel/document/callbacks.rb +15 -21
  50. data/lib/mongomodel/document/collection_modifiers.rb +5 -5
  51. data/lib/mongomodel/document/dynamic_finders.rb +1 -1
  52. data/lib/mongomodel/document/indexes.rb +19 -19
  53. data/lib/mongomodel/document/optimistic_locking.rb +7 -7
  54. data/lib/mongomodel/document/persistence.rb +23 -23
  55. data/lib/mongomodel/document/scopes.rb +20 -20
  56. data/lib/mongomodel/document/validations.rb +6 -6
  57. data/lib/mongomodel/document/validations/uniqueness.rb +11 -11
  58. data/lib/mongomodel/embedded_document.rb +11 -11
  59. data/lib/mongomodel/locale/en.yml +0 -1
  60. data/lib/mongomodel/log_subscriber.rb +5 -5
  61. data/lib/mongomodel/railtie.rb +13 -13
  62. data/lib/mongomodel/support/collection.rb +31 -31
  63. data/lib/mongomodel/support/configuration.rb +11 -11
  64. data/lib/mongomodel/support/core_extensions.rb +1 -1
  65. data/lib/mongomodel/support/dynamic_finder.rb +12 -12
  66. data/lib/mongomodel/support/exceptions.rb +6 -6
  67. data/lib/mongomodel/support/instrumented_collection.rb +20 -20
  68. data/lib/mongomodel/support/map.rb +33 -33
  69. data/lib/mongomodel/support/mongo_operator.rb +6 -6
  70. data/lib/mongomodel/support/mongo_options.rb +18 -18
  71. data/lib/mongomodel/support/mongo_order.rb +16 -16
  72. data/lib/mongomodel/support/paginator.rb +8 -8
  73. data/lib/mongomodel/support/reference.rb +10 -10
  74. data/lib/mongomodel/support/scope.rb +37 -37
  75. data/lib/mongomodel/support/scope/array_methods.rb +1 -1
  76. data/lib/mongomodel/support/scope/batches.rb +1 -1
  77. data/lib/mongomodel/support/scope/dynamic_finders.rb +1 -1
  78. data/lib/mongomodel/support/scope/finder_methods.rb +7 -7
  79. data/lib/mongomodel/support/scope/load_methods.rb +1 -1
  80. data/lib/mongomodel/support/scope/pagination.rb +1 -1
  81. data/lib/mongomodel/support/scope/query_methods.rb +6 -6
  82. data/lib/mongomodel/support/scope/spawn_methods.rb +8 -8
  83. data/lib/mongomodel/support/types.rb +2 -2
  84. data/lib/mongomodel/support/types/array.rb +1 -1
  85. data/lib/mongomodel/support/types/boolean.rb +3 -3
  86. data/lib/mongomodel/support/types/custom.rb +3 -3
  87. data/lib/mongomodel/support/types/date.rb +2 -2
  88. data/lib/mongomodel/support/types/date_time.rb +6 -16
  89. data/lib/mongomodel/support/types/float.rb +1 -1
  90. data/lib/mongomodel/support/types/hash.rb +1 -1
  91. data/lib/mongomodel/support/types/integer.rb +13 -10
  92. data/lib/mongomodel/support/types/object.rb +5 -5
  93. data/lib/mongomodel/support/types/rational.rb +3 -3
  94. data/lib/mongomodel/support/types/time.rb +2 -2
  95. data/lib/mongomodel/version.rb +1 -1
  96. data/lib/rails/generators/mongo_model/config/templates/mongomodel.yml +3 -4
  97. data/lib/rails/generators/mongo_model/model/model_generator.rb +3 -3
  98. data/mongomodel.gemspec +5 -4
  99. data/spec/mongomodel/attributes/store_spec.rb +21 -21
  100. data/spec/mongomodel/concerns/activemodel_spec.rb +4 -4
  101. data/spec/mongomodel/concerns/associations/base/association_spec.rb +12 -12
  102. data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +34 -21
  103. data/spec/mongomodel/concerns/associations/has_many_by_foreign_key_spec.rb +53 -53
  104. data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +30 -30
  105. data/spec/mongomodel/concerns/attribute_methods/before_type_cast_spec.rb +7 -7
  106. data/spec/mongomodel/concerns/attribute_methods/dirty_spec.rb +45 -41
  107. data/spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb +7 -7
  108. data/spec/mongomodel/concerns/attribute_methods/nested_spec.rb +31 -31
  109. data/spec/mongomodel/concerns/attribute_methods/protected_spec.rb +15 -15
  110. data/spec/mongomodel/concerns/attribute_methods/query_spec.rb +19 -19
  111. data/spec/mongomodel/concerns/attribute_methods/read_spec.rb +9 -9
  112. data/spec/mongomodel/concerns/attribute_methods/write_spec.rb +6 -6
  113. data/spec/mongomodel/concerns/attribute_methods_spec.rb +13 -13
  114. data/spec/mongomodel/concerns/attributes_spec.rb +34 -34
  115. data/spec/mongomodel/concerns/callbacks_spec.rb +25 -21
  116. data/spec/mongomodel/concerns/logging_spec.rb +5 -3
  117. data/spec/mongomodel/concerns/map_reduce_spec.rb +19 -19
  118. data/spec/mongomodel/concerns/observing_spec.rb +3 -3
  119. data/spec/mongomodel/concerns/pretty_inspect_spec.rb +10 -10
  120. data/spec/mongomodel/concerns/properties_spec.rb +11 -11
  121. data/spec/mongomodel/concerns/serialization/json_serialization_spec.rb +13 -13
  122. data/spec/mongomodel/concerns/timestamps_spec.rb +39 -39
  123. data/spec/mongomodel/concerns/validations_spec.rb +41 -38
  124. data/spec/mongomodel/document/callbacks_spec.rb +20 -16
  125. data/spec/mongomodel/document/collection_modifiers_spec.rb +16 -16
  126. data/spec/mongomodel/document/dynamic_finders_spec.rb +46 -46
  127. data/spec/mongomodel/document/finders_spec.rb +15 -15
  128. data/spec/mongomodel/document/indexes_spec.rb +29 -29
  129. data/spec/mongomodel/document/optimistic_locking_spec.rb +16 -16
  130. data/spec/mongomodel/document/persistence_spec.rb +39 -39
  131. data/spec/mongomodel/document/scopes_spec.rb +17 -17
  132. data/spec/mongomodel/document/validations/uniqueness_spec.rb +46 -46
  133. data/spec/mongomodel/document/validations_spec.rb +35 -35
  134. data/spec/mongomodel/document_spec.rb +19 -19
  135. data/spec/mongomodel/embedded_document_spec.rb +19 -19
  136. data/spec/mongomodel/mongomodel_spec.rb +7 -6
  137. data/spec/mongomodel/support/collection_spec.rb +54 -54
  138. data/spec/mongomodel/support/configuration_spec.rb +1 -1
  139. data/spec/mongomodel/support/map_spec.rb +66 -66
  140. data/spec/mongomodel/support/mongo_operator_spec.rb +5 -5
  141. data/spec/mongomodel/support/mongo_options_spec.rb +42 -42
  142. data/spec/mongomodel/support/mongo_order_spec.rb +24 -24
  143. data/spec/mongomodel/support/paginator_spec.rb +15 -15
  144. data/spec/mongomodel/support/property_spec.rb +29 -23
  145. data/spec/mongomodel/support/scope_spec.rb +205 -204
  146. data/spec/spec_helper.rb +13 -2
  147. data/spec/support/callbacks.rb +3 -8
  148. data/spec/support/helpers/define_class.rb +7 -7
  149. data/spec/support/helpers/document_finder_stubs.rb +6 -6
  150. data/spec/support/helpers/specs_for.rb +1 -1
  151. data/spec/support/helpers/validations.rb +1 -1
  152. data/spec/support/matchers/find_with.rb +8 -8
  153. data/spec/support/matchers/respond_to_boolean.rb +3 -3
  154. data/spec/support/matchers/run_callbacks.rb +6 -9
  155. data/spec/support/models.rb +5 -5
  156. metadata +23 -7
@@ -3,6 +3,7 @@ require 'bundler/setup'
3
3
  Bundler.setup
4
4
 
5
5
  require 'rspec'
6
+ require 'rspec/its'
6
7
 
7
8
  require 'mongomodel'
8
9
 
@@ -21,12 +22,22 @@ end
21
22
  RSpec.configure do |config|
22
23
  include SpecsFor
23
24
  include DefineClass
24
-
25
+
25
26
  config.before(:all) do
26
27
  MongoModel.configuration.use_database('mongomodel-specs')
27
28
  end
28
-
29
+
29
30
  config.before(:each) do
30
31
  MongoModel.database.collections.each { |c| c.drop rescue c.remove }
31
32
  end
33
+
34
+ config.expect_with :rspec do |c|
35
+ c.syntax = [:should, :expect]
36
+ end
37
+
38
+ config.mock_with :rspec do |c|
39
+ c.syntax = :should
40
+ end
41
+
42
+ config.raise_errors_for_deprecations!
32
43
  end
@@ -1,23 +1,18 @@
1
1
  module MongoModel
2
2
  module CallbackHelpers
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  MongoModel::Callbacks::CALLBACKS.each do |callback_method|
7
7
  next if callback_method.to_s =~ /^around_/
8
8
  define_callback_method(callback_method)
9
- send(callback_method, callback_string(callback_method))
10
9
  send(callback_method, callback_proc(callback_method))
11
10
  send(callback_method, callback_object(callback_method))
12
11
  send(callback_method) { |model| model.history << [callback_method, :block] }
13
12
  end
14
13
  end
15
-
16
- module ClassMethods
17
- def callback_string(callback_method)
18
- "history << [#{callback_method.to_sym.inspect}, :string]"
19
- end
20
14
 
15
+ module ClassMethods
21
16
  def callback_proc(callback_method)
22
17
  Proc.new { |model| model.history << [callback_method, :proc] }
23
18
  end
@@ -36,7 +31,7 @@ module MongoModel
36
31
  klass.new
37
32
  end
38
33
  end
39
-
34
+
40
35
  def history
41
36
  @history ||= []
42
37
  end
@@ -5,7 +5,7 @@ module DefineClass
5
5
  before(:each) do
6
6
  Thread.current[:"#{name}_scopes"] = nil
7
7
  Object.send(:remove_const, name) if Object.const_defined?(name)
8
-
8
+
9
9
  case parent_class
10
10
  when Class
11
11
  klass = Class.new(parent_class)
@@ -14,22 +14,22 @@ module DefineClass
14
14
  when nil
15
15
  klass = Class.new
16
16
  end
17
-
17
+
18
18
  Object.const_set(name, klass)
19
-
19
+
20
20
  klass.class_eval(&block) if block_given?
21
21
  klass
22
22
  end
23
23
  end
24
-
24
+
25
25
  def define_module(name, &block)
26
26
  before(:each) do
27
27
  Object.send(:remove_const, name) if Object.const_defined?(name)
28
-
28
+
29
29
  mod = Module.new
30
-
30
+
31
31
  Object.const_set(name, mod)
32
-
32
+
33
33
  mod.class_eval(&block) if block_given?
34
34
  mod
35
35
  end
@@ -2,12 +2,12 @@ require 'rspec/mocks'
2
2
 
3
3
  module DocumentFinderStubs
4
4
  include RSpec::Mocks::ExampleMethods
5
-
5
+
6
6
  def stub_find(result)
7
7
  find_result = double('find result', :to_a => result.map { |doc| doc.to_mongo }, :count => result.size).as_null_object
8
8
  collection.stub(:find).and_return(find_result)
9
9
  end
10
-
10
+
11
11
  def should_find(expected={}, result=[])
12
12
  selector, options = MongoModel::MongoOptions.new(self, expected).to_a
13
13
  find_result = double('find result', :to_a => result.map { |doc| doc.to_mongo }).as_null_object
@@ -26,22 +26,22 @@ module DocumentFinderStubs
26
26
  collection.should_receive(:find).once.with(selector, options).and_return(find_result)
27
27
  yield if block_given?
28
28
  end
29
-
29
+
30
30
  def should_not_count
31
31
  collection.should_not_receive(:find)
32
32
  yield if block_given?
33
33
  end
34
-
34
+
35
35
  def stub_delete
36
36
  collection.stub(:remove)
37
37
  end
38
-
38
+
39
39
  def should_delete(conditions={})
40
40
  selector, options = MongoModel::MongoOptions.new(self, :conditions => conditions).to_a
41
41
  collection.should_receive(:remove).once.with(selector, options)
42
42
  yield if block_given?
43
43
  end
44
-
44
+
45
45
  def should_update(conditions={}, updates={})
46
46
  selector, options = MongoModel::MongoOptions.new(self, :conditions => conditions).to_a
47
47
  collection.should_receive(:update).once.with(selector, { "$set" => updates }, { :multi => true })
@@ -4,7 +4,7 @@ module SpecsFor
4
4
  describe(klass, &block)
5
5
  end
6
6
  end
7
-
7
+
8
8
  def specing?(klass)
9
9
  described_class == klass
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module ValidationHelpers
2
- def clear_validations!
2
+ def clear_validations!
3
3
  reset_callbacks(:validate)
4
4
  end
5
5
  end
@@ -1,15 +1,15 @@
1
1
  RSpec::Matchers.define(:find_with) do |find_options|
2
2
  extend RSpec::Mocks::ExampleMethods
3
-
3
+
4
4
  match do |klass|
5
5
  selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
6
-
6
+
7
7
  result = double('find result', :to_a => (@result || []).map { |d| d.to_mongo })
8
8
  klass.collection.should_receive(:find).once.with(selector, options).and_return(result)
9
-
9
+
10
10
  true
11
11
  end
12
-
12
+
13
13
  def and_return(result)
14
14
  @result = result
15
15
  self
@@ -18,17 +18,17 @@ end
18
18
 
19
19
  RSpec::Matchers.define(:count_with) do |find_options|
20
20
  extend RSpec::Mocks::ExampleMethods
21
-
21
+
22
22
  match do |klass|
23
23
  selector, options = MongoModel::MongoOptions.new(klass, find_options).to_a
24
24
  result = double('find result')
25
-
25
+
26
26
  klass.collection.should_receive(:find).once.with(selector, options).and_return(result)
27
27
  result.should_receive(:count).once.and_return(@count || 5)
28
-
28
+
29
29
  true
30
30
  end
31
-
31
+
32
32
  def and_return(count)
33
33
  @count = count
34
34
  self
@@ -2,15 +2,15 @@ RSpec::Matchers.define(:respond_to_boolean) do |method|
2
2
  match do |instance|
3
3
  instance.respond_to?(method) && is_boolean?(instance.send(method))
4
4
  end
5
-
5
+
6
6
  description do
7
7
  "should respond to #{method} and return boolean"
8
8
  end
9
-
9
+
10
10
  failure_message_for_should do |instance|
11
11
  "expected #{instance.inspect} to respond to #{method} and return boolean"
12
12
  end
13
-
13
+
14
14
  def is_boolean?(value)
15
15
  value == true || value == false
16
16
  end
@@ -2,19 +2,16 @@ RSpec::Matchers.define(:run_callbacks) do |*callbacks|
2
2
  match do |instance|
3
3
  instance.history == expand_callbacks(callbacks)
4
4
  end
5
-
6
- failure_message_for_should do |instance|
5
+
6
+ failure_message do |instance|
7
7
  "expected #{instance.inspect} to run callbacks #{callbacks.inspect} but got #{compress_callbacks(instance.history).inspect}"
8
8
  end
9
-
9
+
10
10
  def compress_callbacks(callbacks)
11
- callbacks.inject([]) { |result, (callback, type)|
12
- result << callback if type == :string
13
- result
14
- }
11
+ callbacks.inject([]) { |result, (callback, type)| result }
15
12
  end
16
-
13
+
17
14
  def expand_callbacks(callbacks)
18
- callbacks.map { |c| [ [c, :string], [c, :proc], [c, :object], [c, :block] ] }.inject([]) { |result, c| result + c }
15
+ callbacks.map { |c| [ [c, :proc], [c, :object], [c, :block] ] }.inject([]) { |result, c| result + c }
19
16
  end
20
17
  end
@@ -1,22 +1,22 @@
1
1
  class CustomClass
2
2
  attr_reader :name
3
-
3
+
4
4
  def initialize(name)
5
5
  @name = name
6
6
  end
7
-
7
+
8
8
  def ==(other)
9
9
  other.is_a?(self.class) && name == other.name
10
10
  end
11
-
11
+
12
12
  def to_mongo
13
13
  { :name => name }
14
14
  end
15
-
15
+
16
16
  def self.from_mongo(hash)
17
17
  new(hash[:name])
18
18
  end
19
-
19
+
20
20
  def self.cast(value)
21
21
  new(value.to_s)
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pohlenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,14 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.8'
75
+ version: '3.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.8'
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: minitest
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -110,13 +124,15 @@ files:
110
124
  - README.md
111
125
  - Rakefile
112
126
  - bin/console
113
- - gemfiles/mongo_mapper.gemfile
114
- - gemfiles/mongoid.gemfile
115
127
  - gemfiles/rails-3.1.gemfile
116
128
  - gemfiles/rails-3.2.gemfile
117
129
  - gemfiles/rails-4-observers.gemfile
118
130
  - gemfiles/rails-4.0.gemfile
119
131
  - gemfiles/rails-4.1.gemfile
132
+ - gemfiles/rails-4.2.gemfile
133
+ - gemfiles/rails-5.0.gemfile
134
+ - gemfiles/rails-5.1.gemfile
135
+ - gemfiles/rails-5.2.gemfile
120
136
  - lib/mongomodel.rb
121
137
  - lib/mongomodel/attributes/mongo.rb
122
138
  - lib/mongomodel/attributes/store.rb
@@ -301,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
317
  version: 1.3.6
302
318
  requirements: []
303
319
  rubyforge_project: mongomodel
304
- rubygems_version: 2.4.7
320
+ rubygems_version: 2.7.3
305
321
  signing_key:
306
322
  specification_version: 4
307
323
  summary: MongoDB ORM for Ruby/Rails