I have the following definition in my ability.rb file:
can :index, Call, :country_id => user.countries
I am trying to only index Calls whose country_id is in current user's countries array.
This seems to be working when I try it: It only shows me calls that have been tagged by countries that the current_user is a member of.
However, I have the following test which I can't seem to get to pass:
before :each do
# Users
@admin = FactoryGirl.create(:user, admin: true)
end
it "should show the call index page with just calls that have the same country tags as them" do
anotheruser1 = FactoryGirl.create(:user)
anotheruserscall1 = FactoryGirl.create(:call, user_id: anotheruser1.id)
anotheruser2 = FactoryGirl.create(:user)
anotheruserscall2 = FactoryGirl.create(:call, user_id: anotheruser2.id)
@admin.countries << anotheruserscall1.country
ability = Ability.new(@admin)
ability.should be_able_to(:index, anotheruserscall1)
ability.should_not be_able_to(:index, anotheruserscall2)
end
But I get a failure:
Failures:
1) Admin ability should show the call index page with just calls that have the same country tags as them
Failure/Error: ability.should be_able_to(:index, anotheruserscall1)
expected to be able to :index #<Call id: 1, subject: "Natus qui fuga ut.", description: "Consequatur aut veritatis earum dolor. Reprehenderi...", from: "2012-10-25 18:43:23", to: "2012-10-25 19:43:23", user_id: 7, status: "Tentative", created_at: "2012-10-29 13:41:07", updated_at: "2012-10-29 13:41:07", expert_id: nil, country_id: 1>
# ./spec/models/ability_spec.rb:291:in `block (2 levels) in <top (required)>'
Any help greatly appreciated.