Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix specs from colliding with each other.

This is not the best solution, but too much work needs to be done to isolate these specs properly so I’ll delegate that to a different PR. In the meantime this keeps them separate and properly tests the functionality.
  • Loading branch information...
commit b588170042fd4b4920b5d92b740642f33af04a5f 1 parent c9f602e
@bryanrite bryanrite authored
Showing with 16 additions and 15 deletions.
  1. +16 −15 spec/cancan/model_adapters/active_record_4_adapter_spec.rb
View
31 spec/cancan/model_adapters/active_record_4_adapter_spec.rb
@@ -6,34 +6,35 @@
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
- create_table(:users) do |t|
+ create_table(:parents) do |t|
t.timestamps
end
- create_table(:articles) do |t|
+ create_table(:children) do |t|
t.timestamps
- t.integer :user_id
+ t.integer :parent_id
end
end
- (@ability = double).extend(CanCan::Ability)
- end
- it "respects scope on included associations" do
- class User < ActiveRecord::Base
- has_many :articles, lambda { order("articles.id DESC") }
+ class Parent < ActiveRecord::Base
+ has_many :children, lambda { order(:id => :desc) }
end
- class Article < ActiveRecord::Base
- belongs_to :user
+ class Child < ActiveRecord::Base
+ belongs_to :parent
end
- @ability.can :read, [User, Article]
+ (@ability = double).extend(CanCan::Ability)
+ end
+
+ it "respects scope on included associations" do
+ @ability.can :read, [Parent, Child]
- user = User.create!
- article1 = Article.create!(:user => user, :created_at => 1.hours.ago)
- article2 = Article.create!(:user => user, :created_at => 2.hours.ago)
+ parent = Parent.create!
+ child1 = Child.create!(:parent => parent, :created_at => 1.hours.ago)
+ child2 = Child.create!(:parent => parent, :created_at => 2.hours.ago)
- expect(User.accessible_by(@ability).order('users.created_at ASC').includes(:articles).first.articles).to eq [article2, article1]
+ expect(Parent.accessible_by(@ability).order(:created_at => :asc).includes(:children).first.children).to eq [child2, child1]
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.