Hi and thanks for developing this gem under open source license.
Consider the following model of a rails 3.2 with mongoid 3.0.6:
class Product
include Mongoid::Document
include ModelSubsets
field :name, type: String
field :description, type: String
end
Here are the steps to reproduce the error
DefineI a fieldset on Product
using
fieldset = Product.fieldset :shipping_fields, :length
Create a subset (not really sure what the conceptual difference between fieldset and subset is, guessing from the code that fieldset is more like a class while subset is more like a class instance):
Product.subset :shipping, add: fieldset
create new product instances:
p1 = Product.create! name: 'My Product'
p2 = Product.create! name: 'My Product', length: 20
Query for length on p2 returns 20 (as expected), while query for length on p1 fails with an error:
p1.length
NoMethodError: undefined method `length' for #<Product:0x007fb7848b9640>
from /Users/cblock/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-
3.0.6/lib/mongoid/attributes.rb:225:in `method_missing'
Also p1.subset_fields fails with an error (code comments say it returns the current subsets fields list
p1.subset_fields
NameError: undefined local variable or method `subset' for #<Product:0x007fb7848b9640>
from /Users/cblock/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-
3.0.6/lib/mongoid/attributes.rb:225:in `method_missing'
Question: Is it me using the gem in a wrong way or is it a bug?
Add-On: How can I restrict subset fields to a certain type or add validations to them?