locomotivecms/custom_fields — pull request #16 by jansegre (2013-01-29 17:04:39+00:00)
Title: Mongoid 3

I've made a lot of progress torwards porting this gem to use Mongoid 3.

Currently not all tests pass.

unit tests fails with:

```
Failures:

1) CustomFields::Types::HasMany includes a scope named ordered
Failure/Error: @author.posts.ordered.send(:options)[:sort].should == [[:position_in_author, :asc]]
expected: [[:position_in_author, :asc]]
got: {"position_in_author"=>1} (using ==)
Diff:
@@ -1,2 +1,2 @@
-[[:position_in_author, :asc]]
+"position_in_author" => 1
...

Finished in 1.45 seconds
123 examples, 1 failure
```

integration tests fails with:

```
Failures:

1) CustomFieldsFor with a bunch of existing posts destroys a field
Failure/Error: post.respond_to?(:main_author).should be_false
expected: false value
got: true
...

2) CustomFields::Types::HasMany filtering/ordering posts filters and sorts the list
Failure/Error: @author.posts.filtered({ :published => true }, %w(title desc)).map(&:title).should == ['Nude', 'Hello world']
expected: ["Nude", "Hello world"]
got: ["Hello world", "Nude"] (using ==)
...

3) CustomFields::Types::Select group_by is an non empty array
Failure/Error: @groups = klass.group_by_select_option(:main_category)
NoMethodError:
undefined method `[]' for nil:NilClass
...

4) CustomFields::Types::Select group_by is an array of hashes composed of a name
Failure/Error: @groups = klass.group_by_select_option(:main_category)
NoMethodError:
undefined method `[]' for nil:NilClass
...

5) CustomFields::Types::Select group_by is an array of hashes composed of a list of documents
Failure/Error: @groups = klass.group_by_select_option(:main_category)
NoMethodError:
undefined method `[]' for nil:NilClass
...

6) CustomFields::Types::Select group_by can be accessed from the parent document
Failure/Error: @groups = klass.group_by_select_option(:main_category)
NoMethodError:
undefined method `[]' for nil:NilClass
...

Finished in 8.9 seconds
81 examples, 6 failures
```

I bumped the version to 3.0.0.pre because it will be incompatible with 2.x.x

My debugging abilities weren't enough to understand how to fix `NoMethodError` failures.
The farthest I got was noting that `from_db` method is on that cases called with an attribute parameter that is not remotely complete, it probably has something to do with Moped.

I hope that this get merged and eventually locomotive gains compatibility with mongoid 3.