Specs fail when running in a freshly installed environment. #476

Merged
merged 1 commit into from Sep 28, 2011

Conversation

Projects
None yet
3 participants
Contributor

kirkconnell commented Sep 21, 2011

I'm getting the following failure when running rspec on the gem project:

Failures:
  1) CanCan::ModelAdapters::ActiveRecordAdapter should fetch only associated records when using with a scope for conditions
     Failure/Error: category1.articles.accessible_by(@ability).should == [article1]
     expected: [#<Article id: 1, name: nil, published: nil, secret: true, priority: nil, category_id: 1>],
          got: [] (using ==)
     Diff:
     @@ -1,2 +1,2 @@
     -[#<Article id: 1, name: nil, published: nil, secret: true, priority: nil, category_id: 1>]
     +[]
     # ./spec/cancan/model_adapters/active_record_adapter_spec.rb:139

The reason for this error is that with_model version 2.x creates a subclass of the ActiveRecord model you're defining. This results in the Rule.relevant? method having trouble identifying which rules apply to the model.

Version 1.x of with_model doesn't have this issue.

@ryanb ryanb added a commit that referenced this pull request Sep 28, 2011

@ryanb ryanb Merge pull request #476 from kirkconnell/with_model-version-fix
Specs fail when running in a freshly installed environment.
0edd310

@ryanb ryanb merged commit 0edd310 into ryanb:master Sep 28, 2011

Contributor

nertzy commented on 5ab7dea Oct 20, 2011

What were the errors you were seeing? I'm the maintainer of with_model and I'd like to fix them if the problem is on our end.

Thanks!

Contributor

kirkconnell replied Oct 20, 2011

It was a strange thing. Nested models ended up with a different class object id than their original class. To better explain this, supposed you had models Author and Book. In Author we had a has_many :books association. The problem was that the result of author.books.first.class.object_id == Book.object_id was false. This made a couple of specs to fail since they were comparing object arrays.

Contributor

nertzy replied Oct 21, 2011

I ran into something similar earlier. I'm going to work out a minimal test case and see what I can do.

Contributor

nertzy replied Nov 7, 2011

I fixed the issue in with_model. Pull request at #505

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment