Skip to content

Commit

Permalink
users
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed Feb 20, 2012
1 parent 7b06349 commit 858bea1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/rollout_rest_api.rb
@@ -1,6 +1,8 @@
require "sinatra"

class RolloutRestAPI < Sinatra::Base
class FakeUser < Struct.new(:id); end

class << self
attr_accessor :rollout
end
Expand All @@ -19,6 +21,16 @@ class << self
"ok"
end

put "/:feature/users" do
rollout.activate_user(params[:feature], FakeUser.new(params[:user]))
"ok"
end

delete "/:feature/users" do
rollout.deactivate_user(params[:feature], FakeUser.new(params[:user]))
"ok"
end

private
def rollout
self.class.rollout
Expand Down
17 changes: 17 additions & 0 deletions spec/rollout_rest_api_spec.rb
Expand Up @@ -4,6 +4,8 @@
require "yajl"

describe "RolloutRestApi" do
class FakeUser < Struct.new(:id); end

def app
RolloutRestAPI
end
Expand Down Expand Up @@ -36,4 +38,19 @@ def app
last_response.should be_ok
@rollout.info(:chat)[:groups].should == [:greeters]
end

it "adds a user" do
put "/chat/users", :user => 129315
last_response.should be_ok
@rollout.info(:chat)[:users].should include(129315)
end

it "removes a user" do
@rollout.activate_user(:chat, FakeUser.new(1))
@rollout.activate_user(:chat, FakeUser.new(129315))

delete "/chat/users", :user => 129315
last_response.should be_ok
@rollout.info(:chat)[:users].should == [1]
end
end

0 comments on commit 858bea1

Please sign in to comment.