Skip to content

Instantly share code, notes, and snippets.

@chadb
Created January 31, 2012 13:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadb/1710574 to your computer and use it in GitHub Desktop.
Save chadb/1710574 to your computer and use it in GitHub Desktop.
basic usage of role_group
fast_context "Basic Usage" do
setup do
@sy = Factory :school_year
@pgm = Factory :program
@rgn = Factory :region
@acct = Account.default
@rotation = Role.create! :name => 'Rotational Faculty', :school_year_required => true, :program_required => true, :region_required => true, :account => @acct
@grp = RoleGroup.create! :name => 'Pediatric', :role => @rotation, :account => @acct, :program => @pgm, :school_year => @sy, :region => @rgn
end
should "enforce uniqueness" do
err = assert_raise ActiveRecord::RecordInvalid do
RoleGroup.create! :name => 'Weirdos', :role => @rotation, :account => @acct, :program => @pgm, :school_year => @sy, :region => @rgn
end
assert_match /Account Role group combination has already been taken/, err.message
end
should "be ea@sy and work with ScopeGroups" do
are_valid :user
usr = User.create! :account => @acct
@grp.users << usr
sc = ScopeGroup.new( :account => @acct, :program => @pgm )
assert_equal [usr], sc.users
sc = ScopeGroup.new( :account => @acct, :school_year => @sy )
assert_equal [usr], sc.users
sc = ScopeGroup.new( :account => @acct, :region => @rgn )
assert_equal [usr], sc.users
# not sure why you would do this but...
sc = ScopeGroup.new( :account => @acct, :school_year => @sy, :program => @pgm, :region => @rgn )
assert_equal [usr], sc.users
@grp = RoleGroup.account_id_is( @acct.id ).school_year_id_is( @sy.id ).program_id_is( @pgm.id ).region_id_is( @rgn ).first
assert_equal [usr], @grp.users
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment