Permalink
Browse files

change parameter list for Application.create_user

  • Loading branch information...
theganyo committed Sep 26, 2012
1 parent 6ba1410 commit f81c61d2129f192e29a1811e9563af290a0bce57
Showing with 17 additions and 12 deletions.
  1. +7 −7 lib/usergrid/core/application.rb
  2. +2 −2 spec/spec_helper.rb
  3. +8 −3 spec/usergrid/core/application_spec.rb
@@ -7,13 +7,13 @@ def initialize(url, options={})
super url, api_url, options
end
- def create_user(username, name, email, password, invite=false)
- data = { username: username,
- name: name,
- email: email,
- password: password,
- invite: invite }
- create_entity 'users', data
+ def create_user(username, password, email=nil, name=nil, invite=false)
+ user_hash = { username: username,
+ password: password,
+ email: email,
+ name: name,
+ invite: invite }
+ create_entity 'users', user_hash
end
# note: collection_name s/b plural!
View
@@ -62,9 +62,9 @@ def delete_application(application)
def create_random_user(application, login=false)
random = SecureRandom.hex
user_hash = {username: "username_#{random}",
- name: "#{random} name",
+ password: random,
email: "#{random}@email.com",
- password: random}
+ name: "#{random} name" }
entity = application['users'].post(user_hash).entity
application.login user_hash[:username], user_hash[:password] if login
entity
@@ -10,18 +10,23 @@
delete_application @application
end
- it "should be able to create and delete a user" do
+ it "should be able to create, login, and delete a user" do
random = SecureRandom.hex
- response = @application.create_user("username_#{random}", "#{random} name", "#{random}@email.com", random)
+ application = Usergrid::Application.new @application.url # create application resource that's not logged in
+ response = application.create_user "username_#{random}", 'password'
entity = response.entity
+ application.login "username_#{random}", 'password'
begin
response.code.should eq 200
response.entities.size.should eq 1
entity.uuid.should_not be_nil
- response = @application["users/#{entity.uuid}"].get
+ response = application["users/#{entity.uuid}"].get
response.code.should eq 200
ensure
entity.delete
+ # deleted user shouldn't be able to access anything now
+ expect { application["users/#{entity.uuid}"].get }.to raise_error(RestClient::Unauthorized)
+ # use original application - logged in under existing user
expect { @application["users/#{entity.uuid}"].get }.to raise_error(RestClient::ResourceNotFound)
end
end

0 comments on commit f81c61d

Please sign in to comment.