From ae885e82f49f1bc8a47ab632a81216e42971065e Mon Sep 17 00:00:00 2001 From: Alexander Karmes Date: Sun, 25 Jan 2015 02:38:23 +0100 Subject: [PATCH] Add be_dynamic_document matcher class Log include Mongoid::Document include Mongoid::Attributes::Dynamic end RSpec.describe Log do it { is_expected.to be_dynamic_document } end --- README.md | 1 + lib/matchers/document.rb | 10 ++++++++++ spec/models/log.rb | 4 +++- spec/unit/document_spec.rb | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 42c3166..44b4397 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,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 1325b76..ebb3727 100644 --- a/spec/models/log.rb +++ b/spec/models/log.rb @@ -1,4 +1,6 @@ class Log include Mongoid::Document + include Mongoid::Attributes::Dynamic + store_in collection: "logs" -end \ No newline at end of file +end 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