Skip to content

Commit

Permalink
adding failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
runemadsen committed Dec 4, 2012
1 parent 4dcd544 commit 98446bb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/cancan/model_adapters/active_record_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")

describe CanCan::ModelAdapters::ActiveRecordAdapter do

with_model :category do
table do |t|
t.boolean "visible"
Expand All @@ -25,6 +26,7 @@
model do
belongs_to :category
has_many :comments
has_many :tags
belongs_to :user
end
end
Expand All @@ -39,6 +41,16 @@
end
end

with_model :tag do
table do |t|
t.string "tag"
t.integer "article_id"
end
model do
belongs_to :article
end
end

with_model :user do
table do |t|

Expand Down Expand Up @@ -96,6 +108,20 @@
Article.accessible_by(@ability).should == [article1, article2, article3]
end

it "should merge multiple nested conditions" do
@ability.can :read, Article, :comments => {:spam => true}
@ability.can :read, Article, :tags => {:tag => "awesome"}
article1 = Article.create!(:published => true, :secret => false)
article2 = Article.create!(:published => true, :secret => true)
article3 = Article.create!(:published => false, :secret => true)
article4 = Article.create!(:published => false, :secret => false)
comment1 = Comment.create!(:article => article1, :spam => true)
comment2 = Comment.create!(:article => article2, :spam => false)
tag1 = Tag.create!(:article => article3, :tag => "awesome")
tag2 = Tag.create!(:article => article4, :tag => "terrible")
Article.accessible_by(@ability).should == [article1, article3]
end

it "should fetch only the articles that are published and not secret" do
@ability.can :read, Article, :published => true
@ability.cannot :read, Article, :secret => true
Expand Down

0 comments on commit 98446bb

Please sign in to comment.