Created
December 9, 2008 06:30
-
-
Save carpeliam/33803 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
class Group | |
include DataMapper::Resource | |
# ... no need to paste everything, right? | |
has n, :users, :through => Resource | |
end |
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
def leave(grouplink) # grouplink is a permalink | |
@group = Group.first(:grouplink => grouplink) | |
raise NotFound unless @group | |
@group.users.delete session.user | |
redirect resource(@group), :message => (@group.save) ? | |
{:notice => "Sorry to see you go"} : | |
{:warning => "Looks like you're stuck here"} | |
end |
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
context "when logged in as group member", :given => "a group user is logged in" do | |
describe "resource(@group, :leave)" do | |
before(:each) do | |
@response = request(resource(Group.first, :leave), :method => "PUT") | |
end | |
it "should redirect to the group page" do | |
@response.should redirect_to(resource(Group.first), :message => {:notice => "Sorry to see you go"}) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment