diff --git a/README.md b/README.md index 5eba528..a311f97 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,7 @@ end RSpec.describe Log do it { is_expected.to be_stored_in :logs } + it { is_expected.to be_dynamic_document } end RSpec.describe Article do diff --git a/lib/matchers/document.rb b/lib/matchers/document.rb index ffce435..e98c815 100644 --- a/lib/matchers/document.rb +++ b/lib/matchers/document.rb @@ -161,3 +161,13 @@ def have_field(*args) "be a multiparameted Mongoid document" end end + +RSpec::Matchers.define :be_dynamic_document do |_| + match do |doc| + doc.class.included_modules.include?(Mongoid::Attributes::Dynamic) + end + + description do + 'be a Mongoid document with dynamic attributes' + end +end diff --git a/spec/models/log.rb b/spec/models/log.rb index 92c38ed..bd7f3e4 100644 --- a/spec/models/log.rb +++ b/spec/models/log.rb @@ -1,6 +1,8 @@ class Log include Mongoid::Document include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + store_in collection: "logs" index({ created_at: 1 }, { bucket_size: 100, expire_after_seconds: 3600 } ) diff --git a/spec/unit/document_spec.rb b/spec/unit/document_spec.rb index 7694792..c0cad38 100644 --- a/spec/unit/document_spec.rb +++ b/spec/unit/document_spec.rb @@ -18,4 +18,9 @@ it { is_expected.to be_mongoid_document } it { is_expected.to be_timestamped_document } end + + describe Log do + it { is_expected.to be_mongoid_document } + it { is_expected.to be_dynamic_document } + end end