Sha256: bae41dbe8e7219ad7df636f7a9289560007a24045c1ec8fcef6cc9998c6581b7

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# This is used to wrap the CanCan ORM adapters, that enable convenient 
# 'simple' queries using hashes similar to 'metawhere' gem
require 'spec_helper'
require 'migration_helper'

class Poster < ActiveRecord::Base
  belongs_to :owner, :class_name => "User", :foreign_key => "user_id"
end

class User < ActiveRecord::Base
  has_many :posters
end


module CanTango::Ability
  class Base
    def calculate_rules
      can :read, Poster, :owner => user
    end
  end
end


describe CanTango::Adaptor::ActiveRecord do
  before do
    migrate!

    @user = User.create :name => 'admin', :email => 'admin@mail.ru'
    @stranger = User.create :name => 'stranger', :email => 'strange@mail.ru'
    
    @poster = Poster.create :owner => @user
    @poster.owner = @user
  end

  context 'subject is owner of poster' do
    subject { CanTango::Ability::Executor::Base.new @user }
  
    specify { subject.should be_allowed_to(:read, @poster) }
  end
  
  context 'subject is NOT owner of poster' do
    subject { CanTango::Ability::Executor::Base.new @stranger }

    specify { subject.should_not be_allowed_to(:read, @poster) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cantango-core-0.1.9.2 spec/cantango/adaptor/active_record_spec.rb
cantango-core-0.1.9.1 spec/cantango/adaptor/active_record_spec.rb