Created
June 11, 2014 10:09
-
-
Save aruprakshit/b69c869394943057f40e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "#users" do | |
let(:sub_reporting_group) { FactoryGirl.create(:reporting_group) } | |
let(:reporting_group) { FactoryGirl.create(:reporting_group, reporting_group_ids: [sub_reporting_group.id]) } | |
let(:user) { FactoryGirl.create(:user) } | |
let(:team) { FactoryGirl.create(:team) } | |
let(:workplace) { FactoryGirl.create(:workplace) } | |
context "when user belongs to either team_id or workplace_id of a parent reporting group" do | |
it "shouldn't include user when workplace_id not present" do | |
user.update(team_id: team.id) | |
reporting_group.update_attributes(team_ids: reporting_group.team_ids + [team.id], | |
workplace_ids: reporting_group.workplace_ids + [workplace.id] | |
) | |
expect(reporting_group.users).not_to include(user) | |
end | |
it "shouldn't include user when team_id not prsent" do | |
user.update(workplace_id: workplace.id) | |
reporting_group.update_attributes(team_ids: reporting_group.team_ids + [team.id], | |
workplace_ids: reporting_group.workplace_ids + [workplace.id] | |
) | |
expect(reporting_group.users).not_to include(user) | |
end | |
it "should include user if user belongs to either team_id or workplace in a sub reporting group " do | |
user.update_attributes(workplace_id: workplace.id, team_id: team.id) | |
sub_reporting_group.update_attributes(team_ids: sub_reporting_group.team_ids + [team.id], | |
workplace_ids: sub_reporting_group.workplace_ids + [workplace.id] | |
) | |
expect(reporting_group.users).to include(user) | |
end | |
end | |
context "when user belongs to both team_id and workplace_id of a parent reporting group" do | |
it "should include user" do | |
user.update_attributes(workplace_id: workplace.id, team_id: team.id) | |
reporting_group.update_attributes(team_ids: reporting_group.team_ids + [team.id], | |
workplace_ids: reporting_group.workplace_ids + [workplace.id] | |
) | |
expect(reporting_group.users).to include(user) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment