carpeliam (owner)

Revisions

gist: 33803 Download_button fork
public
Public Clone URL: git://gist.github.com/33803.git
Embed All Files: show embed
group.rb #
1
2
3
4
5
6
class Group
  include DataMapper::Resource
  # ... no need to paste everything, right?
 
  has n, :users, :through => Resource
end
groups.rb #
1
2
3
4
5
6
7
8
9
  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
 
groups_spec.rb #
1
2
3
4
5
6
7
8
9
10
11
12
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