Module: Adapter::ActiveModel::CommonHelpers
- Included in:
- Collection, Resource
- Defined in:
- lib/rspec/api_helpers/adapter/active_model/common_helpers.rb
Defined Under Namespace
Classes: ObjectHash
Instance Method Summary collapse
- #modifier_for(key) ⇒ Object
- #object_hash(hash, existing: true) ⇒ Object
- #objectize_collection(collection, root: nil, existing: true) ⇒ Object
- #objectize_resource(resource, root: nil, existing: true) ⇒ Object
- #parse_model(model) ⇒ Object
- #superset_mismatch_error(superset, subset) ⇒ Object
Instance Method Details
#modifier_for(key) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 66 def modifier_for(key) if modifiers_hash[key] return modifiers_hash[key] else return proc{|i| i} end end |
#object_hash(hash, existing: true) ⇒ Object
22 23 24 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 22 def object_hash(hash, existing: true) ObjectHash.new(hash, existing: existing) end |
#objectize_collection(collection, root: nil, existing: true) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 2 def objectize_collection(collection, root: nil, existing: true) if root collection = collection[root] end return collection.map{|resource| object_hash(resource, existing: existing) } end |
#objectize_resource(resource, root: nil, existing: true) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 12 def objectize_resource(resource, root: nil, existing: true) if root obj = object_hash(resource[root], existing: existing) else obj = object_hash(resource, existing: existing) end return obj end |
#parse_model(model) ⇒ Object
60 61 62 63 64 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 60 def parse_model(model) return model unless model.is_a? Hash return object_hash(model) end |
#superset_mismatch_error(superset, subset) ⇒ Object
56 57 58 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 56 def superset_mismatch_error(superset, subset) "Expected \n #{subset.to_a.to_s} \n to be included in \n #{superset.to_a.to_s}" end |